Search in sources :

Example 41 with VmWorkJobVO

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());
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) CallContext(org.apache.cloudstack.context.CallContext) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 42 with VmWorkJobVO

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;
}
Also used : Filter(com.cloud.utils.db.Filter) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 43 with VmWorkJobVO

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);
}
Also used : Filter(com.cloud.utils.db.Filter) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 44 with VmWorkJobVO

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);
}
Also used : VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 45 with VmWorkJobVO

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());
    }
}
Also used : VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Aggregations

VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)52 Account (com.cloud.user.Account)27 User (com.cloud.user.User)22 CallContext (org.apache.cloudstack.context.CallContext)22 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 AsyncJobExecutionContext (org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext)21 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 VMInstanceVO (com.cloud.vm.VMInstanceVO)13 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)9 ActionEvent (com.cloud.event.ActionEvent)8 ExecutionException (java.util.concurrent.ExecutionException)6 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)6 UserVmVO (com.cloud.vm.UserVmVO)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 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4