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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
Aggregations