From 47d6a64b319ab064c4b855346f2bfdb250fb9ad8 Mon Sep 17 00:00:00 2001 From: Koushik Das Date: Fri, 25 Jul 2014 15:17:35 +0530 Subject: [PATCH] CLOUDSTACK-7182: NPE while trying to deploy VMs in parallel in isolated network The following changes are made: - Check to see if network is implemented changed from 'state == Implementing||Implemented' to 'state == Implemented'. The earlier check was a hack to prevent the issue described below. - At the time of implementing network (using implementNetwork() method), if the VR needs to be deployed then it follows the same path of regular VM deployment. This leads to a nested call to implementNetwork() while preparing VR nics. This flow creates issues in dealing with network state transitions. The original call puts network in "Implementing" state and then the nested call again tries to put it into same state resulting in issues. In order to avoid it, implementNetwork() call for VR is replaced with below code. --- .../orchestration/NetworkOrchestrator.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 025514b529c..265515c50b5 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -925,7 +925,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra boolean isNetworkImplemented(NetworkVO network) { Network.State state = network.getState(); - if (state == Network.State.Implemented || state == Network.State.Implementing) { + if (state == Network.State.Implemented) { return true; } else if (state == Network.State.Setup) { DataCenterVO zone = _dcDao.findById(network.getDataCenterId()); @@ -1277,7 +1277,19 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra }); for (NicVO nic : nics) { - Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); + Pair implemented = null; + if (vmProfile.getVirtualMachine().getType() != Type.DomainRouter) { + implemented = implementNetwork(nic.getNetworkId(), dest, context); + } else { + // At the time of implementing network (using implementNetwork() method), if the VR needs to be deployed then + // it follows the same path of regular VM deployment. This leads to a nested call to implementNetwork() while + // preparing VR nics. This flow creates issues in dealing with network state transitions. The original call + // puts network in "Implementing" state and then the nested call again tries to put it into same state resulting + // in issues. In order to avoid it, implementNetwork() call for VR is replaced with below code. + NetworkVO network = _networksDao.findById(nic.getNetworkId()); + NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); + implemented = new Pair(guru, network); + } if (implemented == null || implemented.first() == null) { s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId());