Skip to content

Commit b88681d

Browse files
committed
Merge branch '4.11'
2 parents 1c26b2e + b2a19f7 commit b88681d

21 files changed

Lines changed: 447 additions & 235 deletions

File tree

agent/src/main/java/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
import com.cloud.utils.exception.CloudRuntimeException;
2323
import com.cloud.utils.script.Script;
24+
import org.apache.commons.io.IOUtils;
25+
import org.apache.http.HttpEntity;
26+
import org.apache.http.client.methods.CloseableHttpResponse;
2427
import org.apache.http.client.methods.HttpGet;
2528
import org.apache.http.client.methods.HttpUriRequest;
2629
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -33,6 +36,9 @@
3336
import java.io.File;
3437
import java.io.FileInputStream;
3538
import java.io.IOException;
39+
import java.io.InputStream;
40+
import java.io.OutputStream;
41+
import java.io.FileOutputStream;
3642
import java.security.KeyManagementException;
3743
import java.security.KeyStore;
3844
import java.security.KeyStoreException;
@@ -79,11 +85,32 @@ private SSLContext getSSLContext() throws KeyStoreException, NoSuchAlgorithmExce
7985

8086
@Override
8187
public boolean downloadTemplate() {
88+
CloseableHttpResponse response;
8289
try {
83-
httpsClient.execute(req);
90+
response = httpsClient.execute(req);
8491
} catch (IOException e) {
8592
throw new CloudRuntimeException("Error on HTTPS request: " + e.getMessage());
8693
}
87-
return performDownload();
94+
return consumeResponse(response);
8895
}
96+
97+
/**
98+
* Consume response and persist it on getDownloadedFilePath() file
99+
*/
100+
protected boolean consumeResponse(CloseableHttpResponse response) {
101+
if (response.getStatusLine().getStatusCode() != 200) {
102+
throw new CloudRuntimeException("Error on HTTPS response");
103+
}
104+
try {
105+
HttpEntity entity = response.getEntity();
106+
InputStream in = entity.getContent();
107+
OutputStream out = new FileOutputStream(getDownloadedFilePath());
108+
IOUtils.copy(in, out);
109+
} catch (Exception e) {
110+
s_logger.error("Error parsing response for template " + getTemplateId() + " due to: " + e.getMessage());
111+
return false;
112+
}
113+
return true;
114+
}
115+
89116
}

api/src/main/java/org/apache/cloudstack/acl/RoleService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface RoleService {
3131
boolean isEnabled();
3232
Role findRole(final Long id);
3333
Role createRole(final String name, final RoleType roleType, final String description);
34-
boolean updateRole(final Role role, final String name, final RoleType roleType, final String description);
34+
Role updateRole(final Role role, final String name, final RoleType roleType, final String description);
3535
boolean deleteRole(final Role role);
3636

3737
RolePermission findRolePermission(final Long id);

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/CreateRoleCmd.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
3535
since = "4.9.0",
3636
authorized = {RoleType.Admin})
37-
public class CreateRoleCmd extends BaseCmd {
37+
public class CreateRoleCmd extends RoleCmd {
3838
public static final String APINAME = "createRole";
3939

4040
/////////////////////////////////////////////////////
@@ -83,16 +83,6 @@ public long getEntityOwnerId() {
8383
return Account.ACCOUNT_ID_SYSTEM;
8484
}
8585

86-
private void setupResponse(final Role role) {
87-
final RoleResponse response = new RoleResponse();
88-
response.setId(role.getUuid());
89-
response.setRoleName(role.getName());
90-
response.setRoleType(role.getRoleType());
91-
response.setResponseName(getCommandName());
92-
response.setObjectName("role");
93-
setResponseObject(response);
94-
}
95-
9686
@Override
9787
public void execute() {
9888
CallContext.current().setEventDetails("Role: " + getRoleName() + ", type:" + getRoleType() + ", description: " + getRoleDescription());
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.api.command.admin.acl;
19+
20+
import org.apache.cloudstack.acl.Role;
21+
import org.apache.cloudstack.api.BaseCmd;
22+
import org.apache.cloudstack.api.response.RoleResponse;
23+
24+
public abstract class RoleCmd extends BaseCmd {
25+
26+
protected void setupResponse(final Role role) {
27+
final RoleResponse response = new RoleResponse();
28+
response.setId(role.getUuid());
29+
response.setRoleName(role.getName());
30+
response.setRoleType(role.getRoleType());
31+
response.setDescription(role.getDescription());
32+
response.setResponseName(getCommandName());
33+
response.setObjectName("role");
34+
setResponseObject(response);
35+
}
36+
}

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/UpdateRoleCmd.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@
2222
import org.apache.cloudstack.acl.Role;
2323
import org.apache.cloudstack.acl.RoleType;
2424
import org.apache.cloudstack.api.APICommand;
25+
import org.apache.cloudstack.api.ApiArgValidator;
2526
import org.apache.cloudstack.api.ApiConstants;
2627
import org.apache.cloudstack.api.ApiErrorCode;
2728
import org.apache.cloudstack.api.BaseCmd;
2829
import org.apache.cloudstack.api.Parameter;
2930
import org.apache.cloudstack.api.ServerApiException;
30-
import org.apache.cloudstack.api.ApiArgValidator;
3131
import org.apache.cloudstack.api.response.RoleResponse;
32-
import org.apache.cloudstack.api.response.SuccessResponse;
3332
import org.apache.cloudstack.context.CallContext;
3433

35-
@APICommand(name = UpdateRoleCmd.APINAME, description = "Updates a role", responseObject = SuccessResponse.class,
34+
@APICommand(name = UpdateRoleCmd.APINAME, description = "Updates a role", responseObject = RoleResponse.class,
3635
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
3736
since = "4.9.0",
3837
authorized = {RoleType.Admin})
39-
public class UpdateRoleCmd extends BaseCmd {
38+
public class UpdateRoleCmd extends RoleCmd {
4039
public static final String APINAME = "updateRole";
4140

4241
/////////////////////////////////////////////////////
@@ -100,9 +99,7 @@ public void execute() {
10099
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided");
101100
}
102101
CallContext.current().setEventDetails("Role: " + getRoleName() + ", type:" + getRoleType() + ", description: " + getRoleDescription());
103-
boolean result = roleService.updateRole(role, getRoleName(), getRoleType(), getRoleDescription());
104-
SuccessResponse response = new SuccessResponse(getCommandName());
105-
response.setSuccess(result);
106-
setResponseObject(response);
102+
role = roleService.updateRole(role, getRoleName(), getRoleType(), getRoleDescription());
103+
setupResponse(role);
107104
}
108105
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.api.command.test;
19+
20+
import junit.framework.TestCase;
21+
import org.apache.cloudstack.acl.Role;
22+
import org.apache.cloudstack.acl.RoleService;
23+
import org.apache.cloudstack.acl.RoleType;
24+
import org.apache.cloudstack.api.command.admin.acl.UpdateRoleCmd;
25+
import org.apache.cloudstack.api.response.RoleResponse;
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
import org.mockito.Mockito;
29+
import org.springframework.test.util.ReflectionTestUtils;
30+
31+
import static org.mockito.Mockito.when;
32+
33+
34+
public class UpdateRoleCmdTest extends TestCase{
35+
36+
private UpdateRoleCmd updateRoleCmd;
37+
private RoleService roleService;
38+
private Role role;
39+
40+
@Override
41+
@Before
42+
public void setUp() {
43+
roleService = Mockito.spy(RoleService.class);
44+
updateRoleCmd = new UpdateRoleCmd();
45+
ReflectionTestUtils.setField(updateRoleCmd,"roleService",roleService);
46+
ReflectionTestUtils.setField(updateRoleCmd,"roleId",1L);
47+
ReflectionTestUtils.setField(updateRoleCmd,"roleName","user");
48+
ReflectionTestUtils.setField(updateRoleCmd,"roleType", "User");
49+
ReflectionTestUtils.setField(updateRoleCmd,"roleDescription","Description Initial");
50+
role = Mockito.mock(Role.class);
51+
}
52+
53+
@Test
54+
public void testUpdateSuccess() {
55+
when(roleService.findRole(updateRoleCmd.getRoleId())).thenReturn(role);
56+
when(role.getId()).thenReturn(1L);
57+
when(role.getUuid()).thenReturn("12345-abcgdkajd");
58+
when(role.getDescription()).thenReturn("Defualt user");
59+
when(role.getName()).thenReturn("User");
60+
when(role.getRoleType()).thenReturn(RoleType.User);
61+
when(roleService.updateRole(role,updateRoleCmd.getRoleName(),updateRoleCmd.getRoleType(),updateRoleCmd.getRoleDescription())).thenReturn(role);
62+
when(role.getId()).thenReturn(1L);
63+
when(role.getDescription()).thenReturn("Description Initial");
64+
when(role.getName()).thenReturn("User");
65+
updateRoleCmd.execute();
66+
RoleResponse response = (RoleResponse) updateRoleCmd.getResponseObject();
67+
assertEquals((String)ReflectionTestUtils.getField(response, "roleName"),role.getName());
68+
assertEquals((String)ReflectionTestUtils.getField(response, "roleDescription"),role.getDescription());
69+
}
70+
}

plugins/network-elements/nuage-vsp/src/main/java/com/cloud/api/commands/AssociateNuageVspDomainTemplateCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ public Long getVpcId() {
8989
@Override
9090
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
9191
try {
92-
boolean result =_nuageVspManager.associateNuageVspDomainTemplate(this);
92+
_nuageVspManager.associateNuageVspDomainTemplate(this);
9393
SuccessResponse response = new SuccessResponse(getCommandName());
9494
response.setResponseName(getCommandName());
95-
response.setSuccess(result);
95+
response.setSuccess(true);
9696
this.setResponseObject(response);
9797
} catch (InvalidParameterValueException invalidParamExcp) {
9898
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());

plugins/network-elements/nuage-vsp/src/main/java/com/cloud/network/element/NuageVspElement.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
import com.cloud.network.dao.IPAddressVO;
9191
import com.cloud.network.dao.NetworkDao;
9292
import com.cloud.network.dao.NetworkServiceMapDao;
93-
import com.cloud.network.dao.NetworkVO;
9493
import com.cloud.network.dao.PhysicalNetworkDao;
9594
import com.cloud.network.dao.PhysicalNetworkVO;
9695
import com.cloud.network.manager.NuageVspManager;
@@ -276,14 +275,8 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
276275
return false;
277276
}
278277

279-
if (!_nuageVspEntityBuilder.usesVirtualRouter(offering.getId())) {
280-
// Update broadcast uri if VR is no longer used
281-
NetworkVO networkToUpdate = _networkDao.findById(network.getId());
282-
String broadcastUriStr = networkToUpdate.getUuid() + "/null";
283-
networkToUpdate.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
284-
_networkDao.update(network.getId(), networkToUpdate);
285-
}
286-
278+
_nuageVspManager.updateBroadcastUri(network);
279+
network = _networkDao.findById(network.getId());
287280
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
288281
List<VspAclRule> ingressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Ingress);
289282
List<VspAclRule> egressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Egress);

plugins/network-elements/nuage-vsp/src/main/java/com/cloud/network/guru/NuageVspGuestNetworkGuru.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
255255
VpcDetailVO detail = _vpcDetailsDao.findDetail(network.getVpcId(), NuageVspManager.nuageDomainTemplateDetailName);
256256
if (detail != null && network.getNetworkACLId() != null) {
257257
s_logger.error("Pre-configured DT are used in combination with ACL lists. Which is not supported.");
258-
throw new IllegalArgumentException("CloudStack ACLs are not supported with Nuage Preconfigured Domain Template");
258+
throw new IllegalArgumentException("CloudStack ACLs are not supported with Nuage Pre-configured Domain Template");
259259
}
260260

261261
if(detail != null && !_nuageVspManager.checkIfDomainTemplateExist(network.getDomainId(),detail.getValue(),network.getDataCenterId(),null)){
@@ -302,7 +302,9 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
302302
implemented.setCidr(network.getCidr());
303303
}
304304

305-
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(implemented, true);
305+
implemented.setBroadcastUri(_nuageVspManager.calculateBroadcastUri(implemented));
306+
implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
307+
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(implemented);
306308

307309
if (vspNetwork.isShared()) {
308310
Boolean previousUnderlay= null;
@@ -321,11 +323,6 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
321323
}
322324
}
323325

324-
String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
325-
String broadcastUriStr = implemented.getUuid() + "/" + vspNetwork.getVirtualRouterIp();
326-
implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
327-
implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
328-
329326
boolean implementSucceeded = implement(network.getVpcId(), physicalNetworkId, vspNetwork, implemented, _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering));
330327

331328
if (!implementSucceeded) {
@@ -340,6 +337,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
340337
}
341338
}
342339

340+
String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
343341
s_logger.info("Implemented OK, network " + implemented.getUuid() + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri());
344342
} finally {
345343
_networkDao.releaseFromLockTable(network.getId());
@@ -430,7 +428,7 @@ private static Map<String, String> constructVpcDetails(NetworkRelatedVsdIds netw
430428
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
431429
if (vm.getType() != VirtualMachine.Type.DomainRouter && _nuageVspEntityBuilder.usesVirtualRouter(network.getNetworkOfferingId())) {
432430
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
433-
if (nic != null && nic.getRequestedIPv4() != null && vspNetwork.getVirtualRouterIp().equals(nic.getRequestedIPv4())) {
431+
if (nic != null && nic.getRequestedIPv4() != null && nic.getRequestedIPv4().equals(vspNetwork.getVirtualRouterIp())) {
434432
DataCenter dc = _dcDao.findById(network.getDataCenterId());
435433
s_logger.error("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved for the VR in network " + network);
436434
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved " +
@@ -470,14 +468,13 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D
470468
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
471469
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(vm.getVirtualMachine().getDomainId(), network);
472470

473-
if (vm.getType() == VirtualMachine.Type.DomainRouter && vspNetwork.getVirtualRouterIp().equals("null")) {
474-
//In case of upgrade network offering
475-
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(vm.getVirtualMachine().getDomainId(), network, null, true);
476-
String broadcastUriStr = network.getUuid() + "/" + vspNetwork.getVirtualRouterIp();
477-
NetworkVO updatedNetwork = _networkDao.createForUpdate(network.getId());
478-
updatedNetwork.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
479-
_networkDao.update(updatedNetwork.getId(), updatedNetwork);
471+
boolean vrAddedToNuage = vm.getType() == VirtualMachine.Type.DomainRouter && vspNetwork.getVirtualRouterIp()
472+
.equals("null");
473+
if (vrAddedToNuage) {
474+
//In case a VR is added due to upgrade network offering - recalculate the broadcast uri before using it.
475+
_nuageVspManager.updateBroadcastUri(network);
480476
network = _networkDao.findById(network.getId());
477+
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(vm.getVirtualMachine().getDomainId(), network, null);
481478
}
482479

483480
if (vspNetwork.isShared()) {

0 commit comments

Comments
 (0)