use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.
the class VirtualMachineManagerImpl method advanceStart.
@Override
public void advanceStart(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params, final DeploymentPlan planToDeploy, final DeploymentPlanner planner) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("start parameter value of %s == %s during dispatching", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null ? "<very null>" : params.get(VirtualMachineProfile.Param.BootIntoSetup))));
}
final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
VmWorkJobVO placeHolder = createPlaceHolderWork(vm.getId());
try {
orchestrateStart(vmUuid, params, planToDeploy, planner);
} finally {
if (placeHolder != null) {
_workJobDao.expunge(placeHolder.getId());
}
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("start parameter value of %s == %s during processing of queued job", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null ? "<very null>" : params.get(VirtualMachineProfile.Param.BootIntoSetup))));
}
final Outcome<VirtualMachine> outcome = startVmThroughJobQueue(vmUuid, params, planToDeploy, planner);
retrieveVmFromJobOutcome(outcome, vmUuid, "startVm");
retrieveResultFromJobOutcomeAndThrowExceptionIfNeeded(outcome);
}
}
use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.
the class VirtualMachineManagerImpl method reConfigureVm.
@Override
public VMInstanceVO reConfigureVm(final String vmUuid, final ServiceOffering oldServiceOffering, final ServiceOffering newServiceOffering, Map<String, String> customParameters, final boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, InsufficientServerCapacityException, ConcurrentOperationException {
final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
VmWorkJobVO placeHolder = createPlaceHolderWork(vm.getId());
try {
return orchestrateReConfigureVm(vmUuid, oldServiceOffering, newServiceOffering, reconfiguringOnExistingHost);
} finally {
if (placeHolder != null) {
_workJobDao.expunge(placeHolder.getId());
}
}
} else {
final Outcome<VirtualMachine> outcome = reconfigureVmThroughJobQueue(vmUuid, oldServiceOffering, newServiceOffering, customParameters, reconfiguringOnExistingHost);
VirtualMachine vm = retrieveVmFromJobOutcome(outcome, vmUuid, "reconfigureVm");
Object result = null;
try {
result = retrieveResultFromJobOutcomeAndThrowExceptionIfNeeded(outcome);
} catch (Exception ex) {
throw new RuntimeException("Unhandled exception", ex);
}
if (result != null) {
throw new RuntimeException(String.format("Unexpected job execution result [%s]", result));
}
return (VMInstanceVO) vm;
}
}
use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.
the class VirtualMachineManagerImpl method advanceReboot.
@Override
public void advanceReboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
VmWorkJobVO placeHolder = createPlaceHolderWork(vm.getId());
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("reboot parameter value of %s == %s at orchestration", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null ? "<very null>" : params.get(VirtualMachineProfile.Param.BootIntoSetup))));
}
orchestrateReboot(vmUuid, params);
} finally {
if (placeHolder != null) {
_workJobDao.expunge(placeHolder.getId());
}
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("reboot parameter value of %s == %s through job-queue", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null ? "<very null>" : params.get(VirtualMachineProfile.Param.BootIntoSetup))));
}
final Outcome<VirtualMachine> outcome = rebootVmThroughJobQueue(vmUuid, params);
retrieveVmFromJobOutcome(outcome, vmUuid, "rebootVm");
retrieveResultFromJobOutcomeAndThrowExceptionIfNeeded(outcome);
}
}
use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.
the class VirtualMachineManagerImpl method migrateForScale.
@Override
public void migrateForScale(final String vmUuid, final long srcHostId, final DeployDestination dest, final Long oldSvcOfferingId) throws ResourceUnavailableException, ConcurrentOperationException {
final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
VmWorkJobVO placeHolder = createPlaceHolderWork(vm.getId());
try {
orchestrateMigrateForScale(vmUuid, srcHostId, dest, oldSvcOfferingId);
} finally {
if (placeHolder != null) {
_workJobDao.expunge(placeHolder.getId());
}
}
} else {
final Outcome<VirtualMachine> outcome = migrateVmForScaleThroughJobQueue(vmUuid, srcHostId, dest, oldSvcOfferingId);
retrieveVmFromJobOutcome(outcome, vmUuid, "migrateVmForScale");
try {
retrieveResultFromJobOutcomeAndThrowExceptionIfNeeded(outcome);
} catch (InsufficientCapacityException ex) {
throw new RuntimeException("Unexpected exception", ex);
}
}
}
use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.
the class VirtualMachineManagerImpl method advanceStop.
@Override
public void advanceStop(final String vmUuid, final boolean cleanUpEvenIfUnableToStop) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
VmWorkJobVO placeHolder = null;
final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
placeHolder = createPlaceHolderWork(vm.getId());
try {
orchestrateStop(vmUuid, cleanUpEvenIfUnableToStop);
} finally {
if (placeHolder != null) {
_workJobDao.expunge(placeHolder.getId());
}
}
} else {
final Outcome<VirtualMachine> outcome = stopVmThroughJobQueue(vmUuid, cleanUpEvenIfUnableToStop);
retrieveVmFromJobOutcome(outcome, vmUuid, "stopVm");
try {
retrieveResultFromJobOutcomeAndThrowExceptionIfNeeded(outcome);
} catch (ResourceUnavailableException | InsufficientCapacityException ex) {
throw new RuntimeException("Unexpected exception", ex);
}
}
}
Aggregations