Search in sources :

Example 26 with VmWorkJobVO

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

Example 27 with VmWorkJobVO

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

Example 28 with VmWorkJobVO

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

Example 29 with VmWorkJobVO

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));
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) JobHelper(com.cloud.vm.VirtualMachineManagerImpl.JobHelper) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO) Test(org.junit.Test)

Example 30 with VmWorkJobVO

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

Aggregations

VmWorkJobVO (com.cloud.framework.jobs.impl.VmWorkJobVO)58 Account (com.cloud.user.Account)27 CallContext (com.cloud.context.CallContext)22 User (com.cloud.user.User)22 AsyncJobExecutionContext (com.cloud.framework.jobs.AsyncJobExecutionContext)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 VMInstanceVO (com.cloud.vm.VMInstanceVO)13 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)10 ExecutionException (java.util.concurrent.ExecutionException)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)9 ActionEvent (com.cloud.event.ActionEvent)8 DataObject (com.cloud.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