Search in sources :

Example 21 with VmWorkJobVO

use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method advanceStop.

@Override
public void advanceStop(final String vmUuid, final boolean cleanUpEvenIfUnableToStop) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
    final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
        placeHolder = createPlaceHolderWork(vm.getId());
        try {
            orchestrateStop(vmUuid, cleanUpEvenIfUnableToStop);
        } finally {
            if (placeHolder != null) {
                _workJobDao.expunge(placeHolder.getId());
            }
        }
    } else {
        final Outcome<VirtualMachine> outcome = stopVmThroughJobQueue(vmUuid, cleanUpEvenIfUnableToStop);
        try {
            final VirtualMachine vm = outcome.get();
        } catch (final InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (final java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution excetion", e);
        }
        final Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobResult != null) {
            if (jobResult instanceof AgentUnavailableException) {
                throw (AgentUnavailableException) jobResult;
            } else if (jobResult instanceof ConcurrentOperationException) {
                throw (ConcurrentOperationException) jobResult;
            } else if (jobResult instanceof OperationTimedoutException) {
                throw (OperationTimedoutException) jobResult;
            } else if (jobResult instanceof RuntimeException) {
                throw (RuntimeException) jobResult;
            } else if (jobResult instanceof Throwable) {
                throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
            }
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AsyncJobExecutionContext(com.cloud.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException)

Example 22 with VmWorkJobVO

use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.

the class JobHelperTest method test_jobIsForSameNetwork_whenJobCmdInfoIsNull.

@Test
public void test_jobIsForSameNetwork_whenJobCmdInfoIsNull() throws Exception {
    final long networkId = 1L;
    final VmWorkJobVO vmWorkJobVO = new VmWorkJobVO("someContext");
    final NetworkVO networkVO = new NetworkVO();
    networkVO.setId(networkId);
    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 23 with VmWorkJobVO

use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.

the class JobHelperTest method test_jobIsForSameNetwork_whenJobIsForNetwork.

@Test
public void test_jobIsForSameNetwork_whenJobIsForNetwork() throws Exception {
    final long networkId = 1L;
    final VmWorkAddVmToNetwork vmWorkAddVmToNetwork = new VmWorkAddVmToNetwork(0, 0, 0, "someHandler", networkId, null);
    final VmWorkJobVO vmWorkJobVO = new VmWorkJobVO("someContext");
    vmWorkJobVO.setCmdInfo(VmWorkSerializer.serialize(vmWorkAddVmToNetwork));
    final NetworkVO networkVO = new NetworkVO();
    networkVO.setId(networkId);
    assertThat(new JobHelper().jobIsForSameNetwork(vmWorkJobVO, networkVO), is(true));
}
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 24 with VmWorkJobVO

use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.

the class JobHelperTest method test_jobIsForSameNetwork_whenJobCmdInfoNetworkIdIsNull.

@Test
public void test_jobIsForSameNetwork_whenJobCmdInfoNetworkIdIsNull() throws Exception {
    final long networkId = 1L;
    final VmWorkAddVmToNetwork vmWorkAddVmToNetwork = new VmWorkAddVmToNetwork(0, 0, 0, "someHandler", null, null);
    final VmWorkJobVO vmWorkJobVO = new VmWorkJobVO("someContext");
    vmWorkJobVO.setCmdInfo(VmWorkSerializer.serialize(vmWorkAddVmToNetwork));
    final NetworkVO networkVO = new NetworkVO();
    networkVO.setId(networkId);
    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 25 with VmWorkJobVO

use of com.cloud.framework.jobs.impl.VmWorkJobVO in project cosmic by MissionCriticalCloud.

the class VmWorkJobWakeupDispatcher method runJob.

@Override
public void runJob(final AsyncJob job) {
    final List<AsyncJobJoinMapVO> joinRecords = _joinMapDao.listJoinRecords(job.getId());
    if (joinRecords.size() != 1) {
        s_logger.warn("AsyncJob-" + job.getId() + " received wakeup call with un-supported joining job number: " + joinRecords.size());
        // if we fail wakeup-execution for any reason, avoid release sync-source if there is any
        job.setSyncSource(null);
        return;
    }
    final AsyncJobJoinMapVO joinRecord = joinRecords.get(0);
    final VmWorkJobVO joinedJob = _workjobDao.findById(joinRecord.getJoinJobId());
    Class<?> workClz = null;
    try {
        workClz = Class.forName(job.getCmd());
    } catch (final ClassNotFoundException e) {
        s_logger.error("VM work class " + job.getCmd() + " is not found", e);
        return;
    }
    // get original work context information from joined job
    final VmWork work = VmWorkSerializer.deserialize(workClz, joinedJob.getCmdInfo());
    assert (work != null);
    final AccountVO account = _accountDao.findById(work.getAccountId());
    assert (account != null);
    final VMInstanceVO vm = _instanceDao.findById(work.getVmId());
    assert (vm != null);
    CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated());
    try {
        final Method handler = getHandler(joinRecord.getWakeupHandler());
        if (handler != null) {
            handler.invoke(_vmMgr);
        } else {
            assert (false);
            s_logger.error("Unable to find wakeup handler " + joinRecord.getWakeupHandler() + " when waking up job-" + job.getId());
        }
    } catch (InvocationTargetException | IllegalAccessException e) {
        s_logger.warn("Unexpected exception in waking up job-" + job.getId());
        // if we fail wakeup-execution for any reason, avoid release sync-source if there is any
        job.setSyncSource(null);
    } finally {
        CallContext.unregister();
    }
}
Also used : AsyncJobJoinMapVO(com.cloud.framework.jobs.impl.AsyncJobJoinMapVO) Method(java.lang.reflect.Method) AccountVO(com.cloud.user.AccountVO) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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