Search in sources :

Example 16 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, String jobCmd) {
    SearchCriteria<VmWorkJobVO> sc = PendingWorkJobByCommandSearch.create();
    sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
    sc.setParameters("vmType", type);
    sc.setParameters("vmInstanceId", instanceId);
    sc.setParameters("cmd", jobCmd);
    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 17 with VmWorkJobVO

use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.

the class VMSnapshotManagerImpl method deleteAllVMSnapshotsThroughJobQueue.

public Outcome<VirtualMachine> deleteAllVMSnapshotsThroughJobQueue(final Long vmId, final VMSnapshot.Type type) {
    final CallContext context = CallContext.current();
    final User callingUser = context.getCallingUser();
    final Account callingAccount = context.getCallingAccount();
    final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    VmWorkJobVO workJob = new VmWorkJobVO(context.getContextId());
    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
    workJob.setCmd(VmWorkDeleteAllVMSnapshots.class.getName());
    workJob.setAccountId(callingAccount.getId());
    workJob.setUserId(callingUser.getId());
    workJob.setStep(VmWorkJobVO.Step.Starting);
    workJob.setVmType(VirtualMachine.Type.Instance);
    workJob.setVmInstanceId(vm.getId());
    workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
    // save work context info (there are some duplications)
    VmWorkDeleteAllVMSnapshots workInfo = new VmWorkDeleteAllVMSnapshots(callingUser.getId(), callingAccount.getId(), vm.getId(), VMSnapshotManagerImpl.VM_WORK_JOB_HANDLER, type);
    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVirtualMachineOutcome(workJob, vmId);
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) VMInstanceVO(com.cloud.vm.VMInstanceVO) CallContext(org.apache.cloudstack.context.CallContext) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 18 with VmWorkJobVO

use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.

the class VMSnapshotManagerImpl method createVMSnapshot.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_SNAPSHOT_CREATE, eventDescription = "creating VM snapshot", async = true)
public VMSnapshot createVMSnapshot(Long vmId, Long vmSnapshotId, Boolean quiescevm) {
    UserVmVO userVm = _userVMDao.findById(vmId);
    if (userVm == null) {
        throw new InvalidParameterValueException("Create vm to snapshot failed due to vm: " + vmId + " is not found");
    }
    VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId);
    if (vmSnapshot == null) {
        throw new CloudRuntimeException("VM snapshot id: " + vmSnapshotId + " can not be found");
    }
    // serialize VM operation
    AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        placeHolder = createPlaceHolderWork(vmId);
        try {
            return orchestrateCreateVMSnapshot(vmId, vmSnapshotId, quiescevm);
        } finally {
            _workJobDao.expunge(placeHolder.getId());
        }
    } else {
        Outcome<VMSnapshot> outcome = createVMSnapshotThroughJobQueue(vmId, vmSnapshotId, quiescevm);
        VMSnapshot result = null;
        try {
            result = outcome.get();
        } catch (InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution excetion", e);
        }
        Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobResult != null) {
            if (jobResult instanceof ConcurrentOperationException)
                throw (ConcurrentOperationException) jobResult;
            else if (jobResult instanceof Throwable)
                throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
        }
        return result;
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ActionEvent(com.cloud.event.ActionEvent)

Example 19 with VmWorkJobVO

use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.

the class VMSnapshotManagerImpl method deleteAllVMSnapshots.

@Override
public boolean deleteAllVMSnapshots(long vmId, VMSnapshot.Type type) {
    // serialize VM operation
    AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        placeHolder = createPlaceHolderWork(vmId);
        try {
            return orchestrateDeleteAllVMSnapshots(vmId, type);
        } finally {
            if (placeHolder != null)
                _workJobDao.expunge(placeHolder.getId());
        }
    } else {
        Outcome<VirtualMachine> outcome = deleteAllVMSnapshotsThroughJobQueue(vmId, type);
        try {
            outcome.get();
        } catch (InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution excetion", e);
        }
        Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobResult != null) {
            if (jobResult instanceof ConcurrentOperationException)
                throw (ConcurrentOperationException) jobResult;
            else if (jobResult instanceof InvalidParameterValueException)
                throw (InvalidParameterValueException) jobResult;
            else if (jobResult instanceof Throwable)
                throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
        }
        if (jobResult instanceof Boolean)
            return (Boolean) jobResult;
        return false;
    }
}
Also used : AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 20 with VmWorkJobVO

use of org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO in project cloudstack by apache.

the class VMSnapshotManagerImpl method createVMSnapshotThroughJobQueue.

public Outcome<VMSnapshot> createVMSnapshotThroughJobQueue(final Long vmId, final Long vmSnapshotId, final boolean quiesceVm) {
    final CallContext context = CallContext.current();
    final User callingUser = context.getCallingUser();
    final Account callingAccount = context.getCallingAccount();
    final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    VmWorkJobVO workJob = new VmWorkJobVO(context.getContextId());
    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
    workJob.setCmd(VmWorkCreateVMSnapshot.class.getName());
    workJob.setAccountId(callingAccount.getId());
    workJob.setUserId(callingUser.getId());
    workJob.setStep(VmWorkJobVO.Step.Starting);
    workJob.setVmType(VirtualMachine.Type.Instance);
    workJob.setVmInstanceId(vm.getId());
    workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
    // save work context info (there are some duplications)
    VmWorkCreateVMSnapshot workInfo = new VmWorkCreateVMSnapshot(callingUser.getId(), callingAccount.getId(), vm.getId(), VMSnapshotManagerImpl.VM_WORK_JOB_HANDLER, vmSnapshotId, quiesceVm);
    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVMSnapshotOutcome(workJob, vmSnapshotId);
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) VMInstanceVO(com.cloud.vm.VMInstanceVO) CallContext(org.apache.cloudstack.context.CallContext) 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