use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class VmWorkJobDaoImpl method listPendingWorkJobs.
@Override
public List<VmWorkJobVO> listPendingWorkJobs(final VirtualMachine.Type type, final long instanceId) {
final SearchCriteria<VmWorkJobVO> sc = PendingWorkJobSearch.create();
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
sc.setParameters("vmType", type);
sc.setParameters("vmInstanceId", instanceId);
final Filter filter = new Filter(VmWorkJobVO.class, "created", true, null, null);
return this.listBy(sc, filter);
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class VmWorkJobDaoImpl method findPendingWorkJob.
@Override
public VmWorkJobVO findPendingWorkJob(final VirtualMachine.Type type, final long instanceId) {
final SearchCriteria<VmWorkJobVO> sc = PendingWorkJobSearch.create();
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
sc.setParameters("vmType", type);
sc.setParameters("vmInstanceId", instanceId);
final Filter filter = new Filter(VmWorkJobVO.class, "created", true, null, null);
final List<VmWorkJobVO> result = this.listBy(sc, filter);
if (result != null && result.size() > 0) {
return result.get(0);
}
return null;
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class VmWorkJobDaoImpl method expungeCompletedWorkJobs.
@Override
public void expungeCompletedWorkJobs(final Date cutDate) {
// current DAO machenism does not support following usage
/*
SearchCriteria<VmWorkJobVO> sc = ExpungeWorkJobSearch.create();
sc.setParameters("lastUpdated",cutDate);
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
expunge(sc);
*/
// loop at application level to avoid mysql deadlock issues
final SearchCriteria<VmWorkJobVO> sc = ExpungingWorkJobSearch.create();
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
sc.setParameters("cutDate", cutDate);
sc.setParameters("dispatcher", "VmWorkJobDispatcher");
final List<VmWorkJobVO> expungeList = listBy(sc);
for (final VmWorkJobVO job : expungeList) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Expunge completed work job-" + job.getId());
}
expunge(job.getId());
_baseJobDao.expunge(job.getId());
}
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class JobHelperTest method test_jobIsForSameNetwork_whenJobIsNotForNetwork.
@Test
public void test_jobIsForSameNetwork_whenJobIsNotForNetwork() throws Exception {
final long someNetworkId = 1L;
final long anotherNetworkId = 2L;
final VmWorkAddVmToNetwork vmWorkAddVmToNetwork = new VmWorkAddVmToNetwork(0, 0, 0, "someHandler", someNetworkId, null);
final VmWorkJobVO vmWorkJobVO = new VmWorkJobVO("someContext");
vmWorkJobVO.setCmdInfo(VmWorkSerializer.serialize(vmWorkAddVmToNetwork));
final NetworkVO networkVO = new NetworkVO();
networkVO.setId(anotherNetworkId);
assertThat(new JobHelper().jobIsForSameNetwork(vmWorkJobVO, networkVO), is(false));
}
use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method migrateVmThroughJobQueue.
public Outcome<VirtualMachine> migrateVmThroughJobQueue(final String vmUuid, final long srcHostId, final DeployDestination dest) {
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
final List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(VirtualMachine.Type.Instance, vm.getId(), VmWorkMigrate.class.getName());
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert pendingWorkJobs.size() == 1;
workJob = pendingWorkJobs.get(0);
} else {
workJob = new VmWorkJobVO(context.getContextId());
workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkMigrate.class.getName());
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(VirtualMachine.Type.Instance);
workJob.setVmInstanceId(vm.getId());
workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
// save work context info (there are some duplications)
final VmWorkMigrate workInfo = new VmWorkMigrate(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, dest);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
return new VmStateSyncOutcome(workJob, VirtualMachine.PowerState.PowerOn, vm.getId(), vm.getPowerHostId());
}
Aggregations