diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 5096ed4759e..c9322e4e8ca 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -38,6 +38,7 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.network.router.VirtualRouter; import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -609,8 +610,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (InsufficientCapacityException e) { throw new CloudRuntimeException("Unable to start a VM due to insufficient capacity", e).add(VirtualMachine.class, vmUuid); } catch (ResourceUnavailableException e) { - throw new CloudRuntimeException("Unable to start a VM due to concurrent operation", e).add(VirtualMachine.class, vmUuid); + if(e.getScope() != null && e.getScope().equals(VirtualRouter.class)){ + throw new CloudRuntimeException("Network is unavailable. Please contact administrator", e).add(VirtualMachine.class, vmUuid); + } + throw new CloudRuntimeException("Unable to start a VM due to unavailable resources", e).add(VirtualMachine.class, vmUuid); } + } protected boolean checkWorkItems(VMInstanceVO vm, State state) throws ConcurrentOperationException { diff --git a/server/src/com/cloud/network/router/NetworkHelper.java b/server/src/com/cloud/network/router/NetworkHelper.java index 711c02df86e..6c610161267 100644 --- a/server/src/com/cloud/network/router/NetworkHelper.java +++ b/server/src/com/cloud/network/router/NetworkHelper.java @@ -38,7 +38,7 @@ import com.cloud.vm.VirtualMachineProfile.Param; public interface NetworkHelper { public abstract boolean sendCommandsToRouter(VirtualRouter router, - Commands cmds) throws AgentUnavailableException; + Commands cmds) throws AgentUnavailableException, ResourceUnavailableException; public abstract void handleSingleWorkingRedundantRouter( List connectedRouters, diff --git a/server/src/com/cloud/network/router/NetworkHelperImpl.java b/server/src/com/cloud/network/router/NetworkHelperImpl.java index d2b160f7af4..968251cc4a7 100644 --- a/server/src/com/cloud/network/router/NetworkHelperImpl.java +++ b/server/src/com/cloud/network/router/NetworkHelperImpl.java @@ -160,11 +160,11 @@ public class NetworkHelperImpl implements NetworkHelper { } @Override - public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException { + public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException, ResourceUnavailableException { if (!checkRouterVersion(router)) { s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion() + ", minimal required version : " + VirtualNetworkApplianceService.MinVRVersion); - throw new CloudRuntimeException("Unable to send command. Upgrade in progress. Please contact administrator."); + throw new ResourceUnavailableException("Unable to send command. Router requires upgrade", VirtualRouter.class, router.getId()); } Answer[] answers = null; try { diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 8e0aba4a622..9fb47fde4f3 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -91,7 +91,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA boolean removeDhcpSupportForSubnet(Network network, List routers) throws ResourceUnavailableException; - public boolean prepareAggregatedExecution(Network network, List routers) throws AgentUnavailableException; + public boolean prepareAggregatedExecution(Network network, List routers) throws AgentUnavailableException, ResourceUnavailableException; - public boolean completeAggregatedExecution(Network network, List routers) throws AgentUnavailableException; + public boolean completeAggregatedExecution(Network network, List routers) throws AgentUnavailableException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 23ddfb178d9..e56812e89de 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2605,7 +2605,7 @@ Configurable, StateListener { } protected boolean aggregationExecution(final AggregationControlCommand.Action action, final Network network, final List routers) - throws AgentUnavailableException { + throws AgentUnavailableException, ResourceUnavailableException { for (final DomainRouterVO router : routers) { final AggregationControlCommand cmd = new AggregationControlCommand(action, router.getInstanceName(), getRouterControlIp(router.getId()), getRouterIpInNetwork( network.getId(), router.getId())); @@ -2618,12 +2618,12 @@ Configurable, StateListener { } @Override - public boolean prepareAggregatedExecution(final Network network, final List routers) throws AgentUnavailableException { + public boolean prepareAggregatedExecution(final Network network, final List routers) throws AgentUnavailableException, ResourceUnavailableException { return aggregationExecution(Action.Start, network, routers); } @Override - public boolean completeAggregatedExecution(final Network network, final List routers) throws AgentUnavailableException { + public boolean completeAggregatedExecution(final Network network, final List routers) throws AgentUnavailableException, ResourceUnavailableException { return aggregationExecution(Action.Finish, network, routers); } } diff --git a/server/test/com/cloud/network/router/NetworkHelperImplTest.java b/server/test/com/cloud/network/router/NetworkHelperImplTest.java index 74a0a60215a..952818d7aea 100644 --- a/server/test/com/cloud/network/router/NetworkHelperImplTest.java +++ b/server/test/com/cloud/network/router/NetworkHelperImplTest.java @@ -38,7 +38,7 @@ import com.cloud.agent.api.Command; import com.cloud.agent.manager.Commands; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.OperationTimedoutException; -import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.exception.ResourceUnavailableException; @RunWith(MockitoJUnitRunner.class) @@ -52,9 +52,9 @@ public class NetworkHelperImplTest { @InjectMocks protected NetworkHelperImpl nwHelper = new NetworkHelperImpl(); - @Test(expected=CloudRuntimeException.class) + @Test(expected=ResourceUnavailableException.class) public void testSendCommandsToRouterWrongRouterVersion() - throws AgentUnavailableException, OperationTimedoutException { + throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException { // Prepare NetworkHelperImpl nwHelperUT = spy(this.nwHelper); VirtualRouter vr = mock(VirtualRouter.class); @@ -69,7 +69,7 @@ public class NetworkHelperImplTest { @Test public void testSendCommandsToRouter() - throws AgentUnavailableException, OperationTimedoutException { + throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException { // Prepare NetworkHelperImpl nwHelperUT = spy(this.nwHelper); VirtualRouter vr = mock(VirtualRouter.class); @@ -107,7 +107,7 @@ public class NetworkHelperImplTest { */ @Test public void testSendCommandsToRouterWithTrueResult() - throws AgentUnavailableException, OperationTimedoutException { + throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException { // Prepare NetworkHelperImpl nwHelperUT = spy(this.nwHelper); VirtualRouter vr = mock(VirtualRouter.class); @@ -145,7 +145,7 @@ public class NetworkHelperImplTest { */ @Test public void testSendCommandsToRouterWithNoAnswers() - throws AgentUnavailableException, OperationTimedoutException { + throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException { // Prepare NetworkHelperImpl nwHelperUT = spy(this.nwHelper); VirtualRouter vr = mock(VirtualRouter.class);