Search in sources :

Example 21 with AsyncJobExecutionContext

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);
    }
}
Also used : AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 22 with AsyncJobExecutionContext

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;
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ExecutionException(com.cloud.utils.exception.ExecutionException) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageAccessException(com.cloud.exception.StorageAccessException) EntityExistsException(javax.persistence.EntityExistsException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AffinityConflictException(com.cloud.exception.AffinityConflictException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 23 with AsyncJobExecutionContext

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);
    }
}
Also used : AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 24 with AsyncJobExecutionContext

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);
        }
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 25 with AsyncJobExecutionContext

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);
        }
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Aggregations

AsyncJobExecutionContext (org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext)32 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)27 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)13 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)10 ActionEvent (com.cloud.event.ActionEvent)8 Account (com.cloud.user.Account)8 ExecutionException (java.util.concurrent.ExecutionException)8 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)7 UserVmVO (com.cloud.vm.UserVmVO)7 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)7 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5 VMInstanceVO (com.cloud.vm.VMInstanceVO)5 VmWorkAttachVolume (com.cloud.vm.VmWorkAttachVolume)5 VmWorkDetachVolume (com.cloud.vm.VmWorkDetachVolume)5 VmWorkExtractVolume (com.cloud.vm.VmWorkExtractVolume)5 VmWorkMigrateVolume (com.cloud.vm.VmWorkMigrateVolume)5 VmWorkResizeVolume (com.cloud.vm.VmWorkResizeVolume)5