use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
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)) {
// avoid re-entrance
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);
try {
final VirtualMachine vm = outcome.get();
} catch (final InterruptedException e) {
throw new RuntimeException("Operation is interrupted", e);
} catch (final java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
final Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
if (jobResult != null) {
if (jobResult instanceof AgentUnavailableException) {
throw (AgentUnavailableException) jobResult;
} else if (jobResult instanceof ConcurrentOperationException) {
throw (ConcurrentOperationException) jobResult;
} else if (jobResult instanceof OperationTimedoutException) {
throw (OperationTimedoutException) jobResult;
} else if (jobResult instanceof RuntimeException) {
throw (RuntimeException) jobResult;
} else if (jobResult instanceof Throwable) {
throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
}
}
}
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class JobHelperTest method test_jobIsForSameNetwork_whenJobCmdInfoIsNull.
@Test
public void test_jobIsForSameNetwork_whenJobCmdInfoIsNull() throws Exception {
final long networkId = 1L;
final VmWorkJobVO vmWorkJobVO = new VmWorkJobVO("someContext");
final NetworkVO networkVO = new NetworkVO();
networkVO.setId(networkId);
assertThat(new JobHelper().jobIsForSameNetwork(vmWorkJobVO, networkVO), is(false));
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class JobHelperTest method test_jobIsForSameNetwork_whenJobIsForNetwork.
@Test
public void test_jobIsForSameNetwork_whenJobIsForNetwork() throws Exception {
final long networkId = 1L;
final VmWorkAddVmToNetwork vmWorkAddVmToNetwork = new VmWorkAddVmToNetwork(0, 0, 0, "someHandler", networkId, null);
final VmWorkJobVO vmWorkJobVO = new VmWorkJobVO("someContext");
vmWorkJobVO.setCmdInfo(VmWorkSerializer.serialize(vmWorkAddVmToNetwork));
final NetworkVO networkVO = new NetworkVO();
networkVO.setId(networkId);
assertThat(new JobHelper().jobIsForSameNetwork(vmWorkJobVO, networkVO), is(true));
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class JobHelperTest method test_jobIsForSameNetwork_whenJobCmdInfoNetworkIdIsNull.
@Test
public void test_jobIsForSameNetwork_whenJobCmdInfoNetworkIdIsNull() throws Exception {
final long networkId = 1L;
final VmWorkAddVmToNetwork vmWorkAddVmToNetwork = new VmWorkAddVmToNetwork(0, 0, 0, "someHandler", null, null);
final VmWorkJobVO vmWorkJobVO = new VmWorkJobVO("someContext");
vmWorkJobVO.setCmdInfo(VmWorkSerializer.serialize(vmWorkAddVmToNetwork));
final NetworkVO networkVO = new NetworkVO();
networkVO.setId(networkId);
assertThat(new JobHelper().jobIsForSameNetwork(vmWorkJobVO, networkVO), is(false));
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class VmWorkJobWakeupDispatcher method runJob.
@Override
public void runJob(final AsyncJob job) {
final List<AsyncJobJoinMapVO> joinRecords = _joinMapDao.listJoinRecords(job.getId());
if (joinRecords.size() != 1) {
s_logger.warn("AsyncJob-" + job.getId() + " received wakeup call with un-supported joining job number: " + joinRecords.size());
// if we fail wakeup-execution for any reason, avoid release sync-source if there is any
job.setSyncSource(null);
return;
}
final AsyncJobJoinMapVO joinRecord = joinRecords.get(0);
final VmWorkJobVO joinedJob = _workjobDao.findById(joinRecord.getJoinJobId());
Class<?> workClz = null;
try {
workClz = Class.forName(job.getCmd());
} catch (final ClassNotFoundException e) {
s_logger.error("VM work class " + job.getCmd() + " is not found", e);
return;
}
// get original work context information from joined job
final VmWork work = VmWorkSerializer.deserialize(workClz, joinedJob.getCmdInfo());
assert (work != null);
final AccountVO account = _accountDao.findById(work.getAccountId());
assert (account != null);
final VMInstanceVO vm = _instanceDao.findById(work.getVmId());
assert (vm != null);
CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated());
try {
final Method handler = getHandler(joinRecord.getWakeupHandler());
if (handler != null) {
handler.invoke(_vmMgr);
} else {
assert (false);
s_logger.error("Unable to find wakeup handler " + joinRecord.getWakeupHandler() + " when waking up job-" + job.getId());
}
} catch (InvocationTargetException | IllegalAccessException e) {
s_logger.warn("Unexpected exception in waking up job-" + job.getId());
// if we fail wakeup-execution for any reason, avoid release sync-source if there is any
job.setSyncSource(null);
} finally {
CallContext.unregister();
}
}
Aggregations