Skip to content

Commit 87855d6

Browse files
spark404wilderrodrigues
authored andcommitted
Fix a problem where virtual routers were deployed multiple times in a network
1 parent 6b0c40e commit 87855d6

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

server/src/org/cloud/network/router/deployment/RouterDeploymentDefinition.java

+22-19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
// under the License.
1717
package org.cloud.network.router.deployment;
1818

19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
import org.apache.log4j.Logger;
24+
25+
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
26+
1927
import com.cloud.dc.DataCenter.NetworkType;
2028
import com.cloud.dc.HostPodVO;
2129
import com.cloud.dc.Pod;
@@ -60,12 +68,6 @@
6068
import com.cloud.vm.dao.DomainRouterDao;
6169
import com.cloud.vm.dao.NicDao;
6270
import com.cloud.vm.dao.VMInstanceDao;
63-
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
64-
import org.apache.log4j.Logger;
65-
66-
import java.util.ArrayList;
67-
import java.util.List;
68-
import java.util.Map;
6971

7072
public class RouterDeploymentDefinition {
7173
private static final Logger logger = Logger.getLogger(RouterDeploymentDefinition.class);
@@ -108,7 +110,7 @@ protected RouterDeploymentDefinition(final Network guestNetwork, final DeployDes
108110
}
109111

110112
public Long getServiceOfferingId() {
111-
return this.serviceOfferingId;
113+
return serviceOfferingId;
112114
}
113115

114116
public Vpc getVpc() {
@@ -132,7 +134,7 @@ public Map<Param, Object> getParams() {
132134
}
133135

134136
public boolean isRedundant() {
135-
return this.guestNetwork.isRedundant();
137+
return guestNetwork.isRedundant();
136138
}
137139

138140
public DeploymentPlan getPlan() {
@@ -200,6 +202,7 @@ protected void findOrDeployVirtualRouter() throws ConcurrentOperationException,
200202

201203
for (final DeployDestination destination : destinations) {
202204
dest = destination;
205+
planDeploymentRouters();
203206
generateDeploymentPlan();
204207
executeDeployment();
205208
}
@@ -285,7 +288,7 @@ protected int getNumberOfRoutersToDeploy() {
285288
// If old network is redundant but new is single router, then
286289
// routers.size() = 2 but routerCount = 1
287290
int routersExpected = 1;
288-
if (this.isRedundant()) {
291+
if (isRedundant()) {
289292
routersExpected = 2;
290293
}
291294
return routersExpected < routers.size() ? 0 : routersExpected - routers.size();
@@ -310,7 +313,7 @@ protected boolean prepareDeployment() {
310313
isPublicNetwork = networkModel.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter);
311314

312315
boolean canProceed = true;
313-
if (this.isRedundant() && !this.isPublicNetwork) {
316+
if (isRedundant() && !isPublicNetwork) {
314317
// TODO Shouldn't be this throw an exception instead of log error and empty list of routers
315318
logger.error("Didn't support redundant virtual router without public network!");
316319
routers = new ArrayList<DomainRouterVO>();
@@ -333,13 +336,13 @@ protected void executeDeployment()
333336
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
334337

335338
//Check current redundant routers, if possible(all routers are stopped), reset the priority
336-
this.setupPriorityOfRedundantRouter();
339+
setupPriorityOfRedundantRouter();
337340

338-
if (this.getNumberOfRoutersToDeploy() > 0 && this.prepareDeployment()) {
339-
this.findVirtualProvider();
340-
this.findServiceOfferingId();
341-
this.findSourceNatIP();
342-
this.deployAllVirtualRouters();
341+
if (getNumberOfRoutersToDeploy() > 0 && prepareDeployment()) {
342+
findVirtualProvider();
343+
findServiceOfferingId();
344+
findSourceNatIP();
345+
deployAllVirtualRouters();
343346
}
344347
}
345348

@@ -353,7 +356,7 @@ protected void findSourceNatIP() throws InsufficientAddressCapacityException, Co
353356
protected void findServiceOfferingId() {
354357
Long networkOfferingId = networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId();
355358
if (networkOfferingId != null) {
356-
this.serviceOfferingId = networkOfferingId;
359+
serviceOfferingId = networkOfferingId;
357360
}
358361
}
359362

@@ -443,8 +446,8 @@ protected boolean routersNeedReset() {
443446
* reset all routers priorities
444447
*/
445448
protected void setupPriorityOfRedundantRouter() {
446-
if (this.isRedundant() && this.routersNeedReset()) {
447-
for (final DomainRouterVO router : this.routers) {
449+
if (isRedundant() && routersNeedReset()) {
450+
for (final DomainRouterVO router : routers) {
448451
// getUpdatedPriority() would update the value later
449452
router.setPriority(0);
450453
router.setIsPriorityBumpUp(false);

0 commit comments

Comments
 (0)