Skip to content

Commit 8949efe

Browse files
sgoeminnyadvr
authored andcommitted
CLOUDSTACK-10218: Fix for forced network update in a nuage network (#2445)
Fix for forced network update to a nuage network offering with vr fails with IllegalArgumentException. Addressed review comments DaanHoogland.
1 parent 0befb2c commit 8949efe

10 files changed

Lines changed: 269 additions & 189 deletions

File tree

plugins/network-elements/nuage-vsp/src/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/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/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()) {

plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.cloud.network.manager;
2121

22+
import java.net.URI;
2223
import java.util.List;
2324

2425
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -35,6 +36,7 @@
3536
import com.cloud.api.response.NuageVspDeviceResponse;
3637
import com.cloud.dc.Vlan;
3738
import com.cloud.api.response.NuageVspDomainTemplateResponse;
39+
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
3840
import com.cloud.host.HostVO;
3941
import com.cloud.network.Network;
4042
import com.cloud.network.NuageVspDeviceVO;
@@ -119,10 +121,9 @@ public interface NuageVspManager extends PluggableService {
119121

120122
/**
121123
* Associates a Nuage Vsp domain template with a
122-
* @param cmd
123-
* @return
124+
* @param cmd Associate cmd which contains all the data
124125
*/
125-
boolean associateNuageVspDomainTemplate(AssociateNuageVspDomainTemplateCmd cmd);
126+
void associateNuageVspDomainTemplate(AssociateNuageVspDomainTemplateCmd cmd);
126127

127128
/**
128129
* Queries the VSD to check if the entity provided in the entityCmd exists on the VSD
@@ -134,26 +135,41 @@ public interface NuageVspManager extends PluggableService {
134135

135136
/**
136137
* Sets the preconfigured domain template for a given network
137-
* @param network
138-
* @param domainTemplateName
138+
* @param network the network for which we want to set the domain template
139+
* @param domainTemplateName the domain template name we want to use
139140
*/
140141
void setPreConfiguredDomainTemplateName(Network network, String domainTemplateName);
141142

142143
/**
143144
* Returns the current pre configured domain template for a given network
144-
* @param network
145-
* @return
145+
* @param network the network for which we want the domain template name
146+
* @return the domain template name
146147
*/
147148
String getPreConfiguredDomainTemplateName(Network network);
148149

149150
/**
150151
* Checks if a given domain template exists or not on the VSD.
151-
* @param domainId
152+
* @param domainId Id of the domain to search in.
152153
* @param domainTemplate The name of the domain template for which we need to query the VSD.
153154
* @param zoneId zoneId OR PhysicalNetworkId needs to be provided.
154155
* @param physicalNetworkId zoneId OR PhysicalNetworkId needs to be provided.
155156
* @return true if the domain template exists on the VSD else false if it does not exist on the VSD
156157
*/
157-
public boolean checkIfDomainTemplateExist(Long domainId, String domainTemplate, Long zoneId, Long physicalNetworkId);
158+
boolean checkIfDomainTemplateExist(Long domainId, String domainTemplate, Long zoneId, Long physicalNetworkId);
159+
160+
/**
161+
* calculates the new broadcast uri of a network and persists it in the database
162+
* @param network the network for which you want to calculate the broadcast uri
163+
* @throws InsufficientVirtualNetworkCapacityException in case there is no free ip that can be used as the VR ip.
164+
*/
165+
void updateBroadcastUri(Network network) throws InsufficientVirtualNetworkCapacityException;
166+
167+
/**
168+
* Calculates the broadcast uri based on the network and the offering of the given network
169+
* @param network the network for which you want to calculate the broadcast uri
170+
* @return the calculated broadcast uri
171+
* @throws InsufficientVirtualNetworkCapacityException in case there is no free ip that can be used as the VR ip.
172+
*/
173+
URI calculateBroadcastUri(Network network) throws InsufficientVirtualNetworkCapacityException;
158174

159175
}

0 commit comments

Comments
 (0)