Skip to content

Commit

Permalink
Merge pull request #86 from MissionCriticalCloud/fix/force-stop-kvm
Browse files Browse the repository at this point in the history
Improve force stopping VMs
  • Loading branch information
Boris Schrijver authored Oct 1, 2016
2 parents 998740f + 98e88bc commit 9bb2540
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOff

void stop(String vmUuid) throws ResourceUnavailableException;

void stop(String vmUuid, boolean forced) throws ResourceUnavailableException;

void expunge(String vmUuid) throws ResourceUnavailableException;

void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru);
Expand All @@ -93,6 +91,8 @@ void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> pa

void destroy(String vmUuid) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;

void stopForced(String vmUuid) throws ResourceUnavailableException;

void migrateAway(String vmUuid, long hostId) throws InsufficientServerCapacityException;

void migrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ String reserve(DeploymentPlanner plannerToUse, @BeanParam DeploymentPlan plan, E
boolean stop(String caller) throws CloudException;

/**
* Stop the virtual machine, optionally force
* Stop the virtual machine, by force if necessary
*/
boolean stop(String caller, boolean forced) throws ResourceUnavailableException, CloudException;
boolean stopForced(String caller) throws ResourceUnavailableException, CloudException;

/**
* Cleans up after any botched starts. CloudStack Orchestration Platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2608,13 +2608,19 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI

@Override
public void stop(final String vmUuid) throws ResourceUnavailableException {
stop(vmUuid, false);
try {
advanceStop(vmUuid, false);
} catch (final OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to stop vm because the operation to stop timed out", e.getAgentId(), e);
} catch (final ConcurrentOperationException e) {
throw new CloudRuntimeException("Unable to stop vm because of a concurrent operation", e);
}
}

@Override
public void stop(String vmUuid, boolean forced) throws ResourceUnavailableException {
public void stopForced(String vmUuid) throws ResourceUnavailableException {
try {
advanceStop(vmUuid, forced);
advanceStop(vmUuid, true);
} catch (final OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to stop vm because the operation to stop timed out", e.getAgentId(), e);
} catch (final ConcurrentOperationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String ca

boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException;

boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller, boolean forced) throws ResourceUnavailableException;
boolean stopvirtualmachineforced(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException;

boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ public boolean stopvirtualmachine(final VMEntityVO vmEntityVO, final String call
}

@Override
public boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller, boolean forced) throws ResourceUnavailableException {
_itMgr.stop(vmEntityVO.getUuid(), forced);
public boolean stopvirtualmachineforced(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException {
_itMgr.stopForced(vmEntityVO.getUuid());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public boolean stop(final String caller) throws ResourceUnavailableException {
}

@Override
public boolean stop(String caller, boolean forced) throws ResourceUnavailableException {
return manager.stopvirtualmachine(this.vmEntityVO, caller, forced);
public boolean stopForced(String caller) throws ResourceUnavailableException {
return manager.stopvirtualmachineforced(this.vmEntityVO, caller);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,13 @@ public UserVm stopVirtualMachine(final long vmId, final boolean forced) throws C
boolean status = false;
try {
final VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
status = vmEntity.stop(Long.toString(userId), forced);

if(forced) {
status = vmEntity.stopForced(Long.toString(userId));
} else {
status = vmEntity.stop(Long.toString(userId));
}

if (status) {
return _vmDao.findById(vmId);
} else {
Expand Down
1 change: 1 addition & 0 deletions cosmic-core/test/integration/smoke/test_privategw_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def stop_router(self, router):
self.logger.debug('Stopping router %s' % router.id)
cmd = stopRouter.stopRouterCmd()
cmd.id = router.id
cmd.forced = "true"
self.apiclient.stopRouter(cmd)

def start_routers(self, routers):
Expand Down
1 change: 1 addition & 0 deletions cosmic-core/test/integration/smoke/test_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ def test_07_stop_router(self):
# Stop the router
cmd = stopRouter.stopRouterCmd()
cmd.id = router.id
cmd.forced = "true"
self.apiclient.stopRouter(cmd)

# List routers to check state of router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ def destroy_routers(self):
for router in self.routers:
self.stop_router(router)
cmd = destroyRouter.destroyRouterCmd()
cmd.forced = "true"
cmd.id = router.id
self.apiclient.destroyRouter(cmd)
self.routers = []
Expand Down
1 change: 1 addition & 0 deletions cosmic-core/test/integration/smoke/test_ssvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def test_stop_svm(self, svm_type):
self.logger.debug("Stopping System VM: %s" % svm.id)
cmd = stopSystemVm.stopSystemVmCmd()
cmd.id = svm.id
cmd.forced = "true"
self.apiclient.stopSystemVm(cmd)
self.wait_for_svm_state(svm.id, 'Stopped', self.services["timeout"], self.services["sleep"])

Expand Down
1 change: 1 addition & 0 deletions cosmic-core/test/integration/smoke/test_vpc_redundant.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def stop_router(self, router):
self.logger.debug('Stopping router %s' % router.id)
cmd = stopRouter.stopRouterCmd()
cmd.id = router.id
cmd.forced = "true"
self.apiclient.stopRouter(cmd)

def reboot_router(self, router):
Expand Down
1 change: 1 addition & 0 deletions cosmic-core/test/integration/smoke/test_vpc_router_nics.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def stop_router(self, router):
self.logger.debug('Stopping router')
cmd = stopRouter.stopRouterCmd()
cmd.id = router.id
cmd.forced = "true"
self.apiclient.stopRouter(cmd)

def destroy_routers(self):
Expand Down

0 comments on commit 9bb2540

Please sign in to comment.