use of com.cloud.legacymodel.vm.VirtualMachine.State in project cosmic by MissionCriticalCloud.
the class AffinityGroupServiceImpl method postStateTransitionEvent.
@Override
public boolean postStateTransitionEvent(final Transition<State, Event> transition, final VirtualMachine vo, final boolean status, final Object opaque) {
if (!status) {
return false;
}
final State newState = transition.getToState();
if ((newState == State.Expunging) || (newState == State.Error)) {
// cleanup all affinity groups associations of the Expunged VM
final SearchCriteria<AffinityGroupVMMapVO> sc = _affinityGroupVMMapDao.createSearchCriteria();
sc.addAnd("instanceId", SearchCriteria.Op.EQ, vo.getId());
_affinityGroupVMMapDao.expunge(sc);
}
return true;
}
use of com.cloud.legacymodel.vm.VirtualMachine.State in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method detachIso.
@Override
@ActionEvent(eventType = EventTypes.EVENT_ISO_DETACH, eventDescription = "detaching ISO", async = true)
public boolean detachIso(final long vmId) {
final Account caller = CallContext.current().getCallingAccount();
final Long userId = CallContext.current().getCallingUserId();
// Verify input parameters
final UserVmVO vmInstanceCheck = this._userVmDao.findById(vmId);
if (vmInstanceCheck == null) {
throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId);
}
final UserVm userVM = this._userVmDao.findById(vmId);
if (userVM == null) {
throw new InvalidParameterValueException("Please specify a valid VM.");
}
this._accountMgr.checkAccess(caller, null, true, userVM);
final Long isoId = userVM.getIsoId();
if (isoId == null) {
throw new InvalidParameterValueException("The specified VM has no ISO attached to it.");
}
CallContext.current().setEventDetails("Vm Id: " + vmId + " ISO Id: " + isoId);
final State vmState = userVM.getState();
if (vmState != State.Running && vmState != State.Stopped) {
throw new InvalidParameterValueException("Please specify a VM that is either Stopped or Running.");
}
// attach=false
final boolean result = attachISOToVM(vmId, userId, isoId, false);
// => detach
if (result) {
return result;
} else {
throw new CloudRuntimeException("Failed to detach iso");
}
}
use of com.cloud.legacymodel.vm.VirtualMachine.State in project cosmic by MissionCriticalCloud.
the class CapacityManagerImpl method postStateTransitionEvent.
@Override
public boolean postStateTransitionEvent(final Transition<State, Event> transition, final VirtualMachine vm, final boolean status, final Object opaque) {
if (!status) {
return false;
}
final Pair<Long, Long> hosts = (Pair<Long, Long>) opaque;
final Long oldHostId = hosts.first();
final State oldState = transition.getCurrentState();
final State newState = transition.getToState();
final Event event = transition.getEvent();
s_logger.debug("VM state transitted from :" + oldState + " to " + newState + " with event: " + event + "vm's original host id: " + vm.getLastHostId() + " new host id: " + vm.getHostId() + " host id before state transition: " + oldHostId);
if (oldState == State.Starting) {
if (newState != State.Running) {
releaseVmCapacity(vm, false, false, oldHostId);
}
} else if (oldState == State.Running) {
if (event == Event.AgentReportStopped) {
releaseVmCapacity(vm, false, true, oldHostId);
} else if (event == Event.AgentReportMigrated) {
releaseVmCapacity(vm, false, false, oldHostId);
}
} else if (oldState == State.Migrating) {
if (event == Event.AgentReportStopped) {
/* Release capacity from original host */
releaseVmCapacity(vm, false, false, vm.getLastHostId());
releaseVmCapacity(vm, false, false, oldHostId);
} else if (event == Event.OperationFailed) {
/* Release from dest host */
releaseVmCapacity(vm, false, false, oldHostId);
} else if (event == Event.OperationSucceeded) {
releaseVmCapacity(vm, false, false, vm.getLastHostId());
}
} else if (oldState == State.Stopping) {
if (event == Event.OperationSucceeded) {
releaseVmCapacity(vm, false, true, oldHostId);
} else if (event == Event.AgentReportStopped) {
releaseVmCapacity(vm, false, false, oldHostId);
} else if (event == Event.AgentReportMigrated) {
releaseVmCapacity(vm, false, false, oldHostId);
}
} else if (oldState == State.Stopped) {
if (event == Event.DestroyRequested || event == Event.ExpungeOperation) {
releaseVmCapacity(vm, true, false, vm.getLastHostId());
} else if (event == Event.AgentReportMigrated) {
releaseVmCapacity(vm, false, false, oldHostId);
}
}
if ((newState == State.Starting || newState == State.Migrating || event == Event.AgentReportMigrated) && vm.getHostId() != null) {
boolean fromLastHost = false;
if (vm.getHostId().equals(vm.getLastHostId())) {
s_logger.debug("VM starting again on the last host it was stopped on");
fromLastHost = true;
}
allocateVmCapacity(vm, fromLastHost);
}
if (newState == State.Stopped) {
if (vm.getType() == VirtualMachineType.User) {
final UserVmVO userVM = this._userVMDao.findById(vm.getId());
this._userVMDao.loadDetails(userVM);
// free the message sent flag if it exists
userVM.setDetail(MESSAGE_RESERVED_CAPACITY_FREED_FLAG, "false");
this._userVMDao.saveDetails(userVM);
}
}
return true;
}
Aggregations