From 8175e429af2cfa22017dca607b2ee7ac1f532c78 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 23 Feb 2012 15:11:37 -0800 Subject: [PATCH] bug 13966: cleanup the vm (stop it on the backend) when work step is Release. Also never retry when finalizeStart failed status 13966: resolved fixed reviewed-by: Alex Huang --- server/src/com/cloud/vm/UserVmManagerImpl.java | 12 +++++++----- server/src/com/cloud/vm/VirtualMachineGuru.java | 4 +--- .../src/com/cloud/vm/VirtualMachineManagerImpl.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index d31b62d2c27..41129272a37 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -102,7 +102,6 @@ import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ManagementServerException; @@ -137,14 +136,12 @@ import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.rules.FirewallManager; -import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRuleVO; import com.cloud.network.rules.PortForwardingRuleVO; import com.cloud.network.rules.RulesManager; import com.cloud.network.rules.dao.PortForwardingRulesDao; import com.cloud.network.security.SecurityGroup; import com.cloud.network.security.SecurityGroupManager; -import com.cloud.network.security.SecurityGroupVMMapVO; import com.cloud.network.security.dao.SecurityGroupDao; import com.cloud.network.security.dao.SecurityGroupVMMapDao; import com.cloud.offering.NetworkOffering; @@ -2664,7 +2661,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override - public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) throws InsufficientAddressCapacityException{ + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context){ UserVmVO vm = profile.getVirtualMachine(); Answer[] answersToCmds = cmds.getAnswers(); @@ -2728,7 +2725,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } //get system ip and create static nat rule for the vm - _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false); + try { + _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false); + } catch (Exception ex) { + s_logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", ex); + return false; + } return true; } diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index 94981ca1d64..6799bbe392d 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -20,7 +20,6 @@ package com.cloud.vm; import com.cloud.agent.api.StopAnswer; import com.cloud.agent.manager.Commands; import com.cloud.deploy.DeployDestination; -import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.ResourceUnavailableException; /** @@ -56,9 +55,8 @@ public interface VirtualMachineGuru { * @param profile virtual machine profile. * @param dest destination it was sent to. * @return true if deployment was fine; false if it didn't go well. - * @throws InsufficientAddressCapacityException */ - boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) throws InsufficientAddressCapacityException; + boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context); boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index b9c332e9f8b..de751a7b482 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -773,7 +773,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene String host_guid = startAnswer.getHost_guid(); if( host_guid != null ) { HostVO finalHost = _resourceMgr.findHostByGuid(host_guid); - if ( finalHost == null ) { + if (finalHost == null ) { throw new CloudRuntimeException("Host Guid " + host_guid + " doesn't exist in DB, something wrong here"); } destHostId = finalHost.getId(); @@ -788,14 +788,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } return startedVm; } else { + canRetry = false; if (s_logger.isDebugEnabled()) { s_logger.info("The guru did not like the answers so stopping " + vm); } StopCommand cmd = new StopCommand(vm.getInstanceName()); StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd); if (answer == null || !answer.getResult()) { - s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers")); - canRetry = false; + s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers")); _haMgr.scheduleStop(vm, destHostId, WorkType.ForceStop); throw new ExecutionException("Unable to stop " + vm + " so we are unable to retry the start operation"); } @@ -899,7 +899,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene return false; } - if (step == Step.Started || step == Step.Starting) { + if (step == Step.Started || step == Step.Starting || step == Step.Release) { if (vm.getHostId() != null) { if (!sendStop(guru, profile, force)) { s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process");