Skip to content

Commit c052d96

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
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
1 parent 856f41b commit c052d96

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
import com.cloud.event.dao.EventDao;
103103
import com.cloud.event.dao.UsageEventDao;
104104
import com.cloud.exception.ConcurrentOperationException;
105-
import com.cloud.exception.InsufficientAddressCapacityException;
106105
import com.cloud.exception.InsufficientCapacityException;
107106
import com.cloud.exception.InvalidParameterValueException;
108107
import com.cloud.exception.ManagementServerException;
@@ -137,14 +136,12 @@
137136
import com.cloud.network.lb.LoadBalancingRulesManager;
138137
import com.cloud.network.router.VirtualNetworkApplianceManager;
139138
import com.cloud.network.rules.FirewallManager;
140-
import com.cloud.network.rules.FirewallRule;
141139
import com.cloud.network.rules.FirewallRuleVO;
142140
import com.cloud.network.rules.PortForwardingRuleVO;
143141
import com.cloud.network.rules.RulesManager;
144142
import com.cloud.network.rules.dao.PortForwardingRulesDao;
145143
import com.cloud.network.security.SecurityGroup;
146144
import com.cloud.network.security.SecurityGroupManager;
147-
import com.cloud.network.security.SecurityGroupVMMapVO;
148145
import com.cloud.network.security.dao.SecurityGroupDao;
149146
import com.cloud.network.security.dao.SecurityGroupVMMapDao;
150147
import com.cloud.offering.NetworkOffering;
@@ -2664,7 +2661,7 @@ public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<User
26642661
}
26652662

26662663
@Override
2667-
public boolean finalizeStart(VirtualMachineProfile<UserVmVO> profile, long hostId, Commands cmds, ReservationContext context) throws InsufficientAddressCapacityException{
2664+
public boolean finalizeStart(VirtualMachineProfile<UserVmVO> profile, long hostId, Commands cmds, ReservationContext context){
26682665
UserVmVO vm = profile.getVirtualMachine();
26692666

26702667
Answer[] answersToCmds = cmds.getAnswers();
@@ -2728,7 +2725,12 @@ public boolean finalizeStart(VirtualMachineProfile<UserVmVO> profile, long hostI
27282725
}
27292726

27302727
//get system ip and create static nat rule for the vm
2731-
_rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
2728+
try {
2729+
_rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
2730+
} catch (Exception ex) {
2731+
s_logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", ex);
2732+
return false;
2733+
}
27322734

27332735
return true;
27342736
}

‎server/src/com/cloud/vm/VirtualMachineGuru.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.cloud.agent.api.StopAnswer;
2121
import com.cloud.agent.manager.Commands;
2222
import com.cloud.deploy.DeployDestination;
23-
import com.cloud.exception.InsufficientAddressCapacityException;
2423
import com.cloud.exception.ResourceUnavailableException;
2524

2625
/**
@@ -56,9 +55,8 @@ public interface VirtualMachineGuru<T extends VirtualMachine> {
5655
* @param profile virtual machine profile.
5756
* @param dest destination it was sent to.
5857
* @return true if deployment was fine; false if it didn't go well.
59-
* @throws InsufficientAddressCapacityException
6058
*/
61-
boolean finalizeStart(VirtualMachineProfile<T> profile, long hostId, Commands cmds, ReservationContext context) throws InsufficientAddressCapacityException;
59+
boolean finalizeStart(VirtualMachineProfile<T> profile, long hostId, Commands cmds, ReservationContext context);
6260

6361
boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<T> profile);
6462

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.P
773773
String host_guid = startAnswer.getHost_guid();
774774
if( host_guid != null ) {
775775
HostVO finalHost = _resourceMgr.findHostByGuid(host_guid);
776-
if ( finalHost == null ) {
776+
if (finalHost == null ) {
777777
throw new CloudRuntimeException("Host Guid " + host_guid + " doesn't exist in DB, something wrong here");
778778
}
779779
destHostId = finalHost.getId();
@@ -788,14 +788,14 @@ public <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.P
788788
}
789789
return startedVm;
790790
} else {
791+
canRetry = false;
791792
if (s_logger.isDebugEnabled()) {
792793
s_logger.info("The guru did not like the answers so stopping " + vm);
793794
}
794795
StopCommand cmd = new StopCommand(vm.getInstanceName());
795796
StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd);
796797
if (answer == null || !answer.getResult()) {
797-
s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers"));
798-
canRetry = false;
798+
s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers"));
799799
_haMgr.scheduleStop(vm, destHostId, WorkType.ForceStop);
800800
throw new ExecutionException("Unable to stop " + vm + " so we are unable to retry the start operation");
801801
}
@@ -899,7 +899,7 @@ protected <T extends VMInstanceVO> boolean cleanup(VirtualMachineGuru<T> guru, V
899899
return false;
900900
}
901901

902-
if (step == Step.Started || step == Step.Starting) {
902+
if (step == Step.Started || step == Step.Starting || step == Step.Release) {
903903
if (vm.getHostId() != null) {
904904
if (!sendStop(guru, profile, force)) {
905905
s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process");

0 commit comments

Comments
 (0)