use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.
the class VirtualMachineManagerImpl method reconfigureVmThroughJobQueue.
public Outcome<VirtualMachine> reconfigureVmThroughJobQueue(final String vmUuid, final ServiceOffering newServiceOffering, final boolean reconfiguringOnExistingHost) {
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(), VmWorkReconfigure.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(VmWorkReconfigure.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 VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, newServiceOffering.getId(), reconfiguringOnExistingHost);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
return new VmJobVirtualMachineOutcome(workJob, vm.getId());
}
use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.
the class VmWorkJobDaoImpl method findPendingWorkJob.
@Override
public VmWorkJobVO findPendingWorkJob(VirtualMachine.Type type, long instanceId) {
SearchCriteria<VmWorkJobVO> sc = PendingWorkJobSearch.create();
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
sc.setParameters("vmType", type);
sc.setParameters("vmInstanceId", instanceId);
Filter filter = new Filter(VmWorkJobVO.class, "created", true, null, null);
List<VmWorkJobVO> result = this.listBy(sc, filter);
if (result != null && result.size() > 0)
return result.get(0);
return null;
}
use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.
the class VmWorkJobDaoImpl method listPendingWorkJobs.
@Override
public List<VmWorkJobVO> listPendingWorkJobs(VirtualMachine.Type type, long instanceId) {
SearchCriteria<VmWorkJobVO> sc = PendingWorkJobSearch.create();
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
sc.setParameters("vmType", type);
sc.setParameters("vmInstanceId", instanceId);
Filter filter = new Filter(VmWorkJobVO.class, "created", true, null, null);
return this.listBy(sc, filter);
}
use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.
the class VmWorkJobDaoImpl method updateStep.
@Override
public void updateStep(long workJobId, Step step) {
VmWorkJobVO jobVo = findById(workJobId);
jobVo.setStep(step);
jobVo.setLastUpdated(DateUtil.currentGMTTime());
update(workJobId, jobVo);
}
use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.
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
SearchCriteria<VmWorkJobVO> sc = ExpungingWorkJobSearch.create();
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
sc.setParameters("cutDate", cutDate);
sc.setParameters("dispatcher", "VmWorkJobDispatcher");
List<VmWorkJobVO> expungeList = listBy(sc);
for (VmWorkJobVO job : expungeList) {
if (s_logger.isDebugEnabled())
s_logger.debug("Expunge completed work job-" + job.getId());
expunge(job.getId());
_baseJobDao.expunge(job.getId());
}
}
Aggregations