Merge pull request #1956 from myENA/bug/49npe_vmimpl

CLOUDSTACK-9796 - Fix NPE in VirtualMachineManagerImpl.java
This commit is contained in:
Rajani Karuturi 2017-04-22 20:53:27 +05:30 committed by GitHub
commit f2951d9560
1 changed files with 8 additions and 4 deletions

View File

@ -744,14 +744,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
protected <T extends VMInstanceVO> boolean changeState(final T vm, final Event event, final Long hostId, final ItWorkVO work, final Step step) throws NoTransitionException {
// FIXME: We should do this better.
final Step previousStep = work.getStep();
_workDao.updateStep(work, step);
Step previousStep = null;
if (work != null) {
previousStep = work.getStep();
_workDao.updateStep(work, step);
}
boolean result = false;
try {
result = stateTransitTo(vm, event, hostId);
return result;
} finally {
if (!result) {
if (!result && work != null) {
_workDao.updateStep(work, previousStep);
}
}
@ -1507,12 +1510,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (doCleanup) {
if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) {
try {
if (s_logger.isDebugEnabled()) {
if (s_logger.isDebugEnabled() && work != null) {
s_logger.debug("Updating work item to Done, id:" + work.getId());
}
if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) {
throw new CloudRuntimeException("Unable to stop " + vm);
}
} catch (final NoTransitionException e) {
s_logger.warn("Unable to cleanup " + vm);
throw new CloudRuntimeException("Unable to stop " + vm, e);