Search in sources :

Example 1 with VmWorkAttachVolume

use of com.cloud.vm.VmWorkAttachVolume in project cloudstack by apache.

the class VolumeOrchestrator method cleanupStorageJobs.

@Override
public void cleanupStorageJobs() {
    //clean up failure jobs related to volume
    List<AsyncJobVO> jobs = _jobMgr.findFailureAsyncJobs(VmWorkAttachVolume.class.getName(), VmWorkMigrateVolume.class.getName(), VmWorkTakeVolumeSnapshot.class.getName());
    for (AsyncJobVO job : jobs) {
        try {
            if (job.getCmd().equalsIgnoreCase(VmWorkAttachVolume.class.getName())) {
                VmWorkAttachVolume work = VmWorkSerializer.deserialize(VmWorkAttachVolume.class, job.getCmdInfo());
                cleanupVolumeDuringAttachFailure(work.getVolumeId());
            } else if (job.getCmd().equalsIgnoreCase(VmWorkMigrateVolume.class.getName())) {
                VmWorkMigrateVolume work = VmWorkSerializer.deserialize(VmWorkMigrateVolume.class, job.getCmdInfo());
                cleanupVolumeDuringMigrationFailure(work.getVolumeId(), work.getDestPoolId());
            } else if (job.getCmd().equalsIgnoreCase(VmWorkTakeVolumeSnapshot.class.getName())) {
                VmWorkTakeVolumeSnapshot work = VmWorkSerializer.deserialize(VmWorkTakeVolumeSnapshot.class, job.getCmdInfo());
                cleanupVolumeDuringSnapshotFailure(work.getVolumeId(), work.getSnapshotId());
            }
        } catch (Exception e) {
            s_logger.debug("clean up job failure, will continue", e);
        }
    }
}
Also used : VmWorkTakeVolumeSnapshot(com.cloud.vm.VmWorkTakeVolumeSnapshot) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientStorageCapacityException(com.cloud.exception.InsufficientStorageCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) AsyncJobVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobVO)

Example 2 with VmWorkAttachVolume

use of com.cloud.vm.VmWorkAttachVolume in project cloudstack by apache.

the class VolumeApiServiceImpl method attachVolumeToVmThroughJobQueue.

public Outcome<Volume> attachVolumeToVmThroughJobQueue(final Long vmId, final Long volumeId, final Long deviceId) {
    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(VmWorkAttachVolume.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)
    VmWorkAttachVolume workInfo = new VmWorkAttachVolume(callingUser.getId(), callingAccount.getId(), vm.getId(), VolumeApiServiceImpl.VM_WORK_JOB_HANDLER, volumeId, deviceId);
    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    AsyncJobVO jobVo = _jobMgr.getAsyncJob(workJob.getId());
    s_logger.debug("New job " + workJob.getId() + ", result field: " + jobVo.getResult());
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVolumeOutcome(workJob, volumeId);
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) VMInstanceVO(com.cloud.vm.VMInstanceVO) CallContext(org.apache.cloudstack.context.CallContext) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) AsyncJobVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobVO)

Aggregations

VmWorkAttachVolume (com.cloud.vm.VmWorkAttachVolume)2 AsyncJobVO (org.apache.cloudstack.framework.jobs.impl.AsyncJobVO)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientStorageCapacityException (com.cloud.exception.InsufficientStorageCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 Account (com.cloud.user.Account)1 User (com.cloud.user.User)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VmWorkMigrateVolume (com.cloud.vm.VmWorkMigrateVolume)1 VmWorkTakeVolumeSnapshot (com.cloud.vm.VmWorkTakeVolumeSnapshot)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConfigurationException (javax.naming.ConfigurationException)1 CallContext (org.apache.cloudstack.context.CallContext)1 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)1