Search in sources :

Example 6 with AsyncJobExecutionContext

use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.

the class VirtualMachineManagerImpl method migrateAway.

@Override
public void migrateAway(final String vmUuid, final long srcHostId) throws InsufficientServerCapacityException {
    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 {
            try {
                orchestrateMigrateAway(vmUuid, srcHostId, null);
            } catch (final InsufficientServerCapacityException e) {
                s_logger.warn("Failed to deploy vm " + vmUuid + " with original planner, sending HAPlanner");
                orchestrateMigrateAway(vmUuid, srcHostId, _haMgr.getHAPlanner());
            }
        } finally {
            _workJobDao.expunge(placeHolder.getId());
        }
    } else {
        final Outcome<VirtualMachine> outcome = migrateVmAwayThroughJobQueue(vmUuid, srcHostId);
        retrieveVmFromJobOutcome(outcome, vmUuid, "migrateVmAway");
        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) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 7 with AsyncJobExecutionContext

use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.

the class VirtualMachineManagerImpl method migrate.

@Override
public void migrate(final String vmUuid, final long srcHostId, final DeployDestination dest) 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 {
            orchestrateMigrate(vmUuid, srcHostId, dest);
        } finally {
            if (placeHolder != null) {
                _workJobDao.expunge(placeHolder.getId());
            }
        }
    } else {
        final Outcome<VirtualMachine> outcome = migrateVmThroughJobQueue(vmUuid, srcHostId, dest);
        retrieveVmFromJobOutcome(outcome, vmUuid, "migrateVm");
        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 8 with AsyncJobExecutionContext

use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.

the class VirtualMachineManagerImpl method migrateWithStorage.

@Override
public void migrateWithStorage(final String vmUuid, final long srcHostId, final long destHostId, final Map<Long, Long> volumeToPool) 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 {
            orchestrateMigrateWithStorage(vmUuid, srcHostId, destHostId, volumeToPool);
        } finally {
            if (placeHolder != null) {
                _workJobDao.expunge(placeHolder.getId());
            }
        }
    } else {
        final Outcome<VirtualMachine> outcome = migrateVmWithStorageThroughJobQueue(vmUuid, srcHostId, destHostId, volumeToPool);
        retrieveVmFromJobOutcome(outcome, vmUuid, "migrateVmWithStorage");
        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 9 with AsyncJobExecutionContext

use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.

the class AgentManagerImpl method tagCommand.

private static void tagCommand(final Command cmd) {
    final AsyncJobExecutionContext context = AsyncJobExecutionContext.getCurrent();
    if (context != null && context.getJob() != null) {
        final AsyncJob job = context.getJob();
        if (job.getRelated() != null && !job.getRelated().isEmpty()) {
            cmd.setContextParam("job", "job-" + job.getRelated() + "/" + "job-" + job.getId());
        } else {
            cmd.setContextParam("job", "job-" + job.getId());
        }
    }
    String logcontextid = (String) MDC.get("logcontextid");
    if (StringUtils.isNotEmpty(logcontextid)) {
        cmd.setContextParam("logid", logcontextid);
    }
}
Also used : AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) AsyncJob(org.apache.cloudstack.framework.jobs.AsyncJob)

Example 10 with AsyncJobExecutionContext

use of org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext in project cloudstack by apache.

the class VirtualMachineManagerImpl method storageMigration.

@Override
public void storageMigration(final String vmUuid, final Map<Long, Long> volumeToPool) {
    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 {
            orchestrateStorageMigration(vmUuid, volumeToPool);
        } finally {
            if (placeHolder != null) {
                _workJobDao.expunge(placeHolder.getId());
            }
        }
    } else {
        final Outcome<VirtualMachine> outcome = migrateVmStorageThroughJobQueue(vmUuid, volumeToPool);
        retrieveVmFromJobOutcome(outcome, vmUuid, "migrateVmStorage");
        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