Search in sources :

Example 1 with AsyncJobJoinMapVO

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

the class AsyncJobExecutionContext method disjoinJob.

// 
// check failure exception before we disjoin the worker job, work job usually fails with exception
// this will help propogate exception between jobs
// TODO : it is ugly and this will become unnecessary after we switch to full-async mode
// 
public void disjoinJob(long joinedJobId) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    assert (_job != null);
    AsyncJobJoinMapVO record = s_joinMapDao.getJoinRecord(_job.getId(), joinedJobId);
    s_jobMgr.disjoinJob(_job.getId(), joinedJobId);
    if (record.getJoinStatus() == JobInfo.Status.FAILED) {
        if (record.getJoinResult() != null) {
            Object exception = JobSerializerHelper.fromObjectSerializedString(record.getJoinResult());
            if (exception != null && exception instanceof Exception) {
                if (exception instanceof InsufficientCapacityException) {
                    s_logger.error("Job " + joinedJobId + " failed with InsufficientCapacityException");
                    throw (InsufficientCapacityException) exception;
                } else if (exception instanceof ConcurrentOperationException) {
                    s_logger.error("Job " + joinedJobId + " failed with ConcurrentOperationException");
                    throw (ConcurrentOperationException) exception;
                } else if (exception instanceof ResourceUnavailableException) {
                    s_logger.error("Job " + joinedJobId + " failed with ResourceUnavailableException");
                    throw (ResourceUnavailableException) exception;
                } else {
                    s_logger.error("Job " + joinedJobId + " failed with exception");
                    throw new RuntimeException((Exception) exception);
                }
            }
        } else {
            s_logger.error("Job " + joinedJobId + " failed without providing an error object");
            throw new RuntimeException("Job " + joinedJobId + " failed without providing an error object");
        }
    }
}
Also used : AsyncJobJoinMapVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 2 with AsyncJobJoinMapVO

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

the class AsyncJobJoinMapDaoImpl method completeJoin.

@Override
public void completeJoin(long joinJobId, JobInfo.Status joinStatus, String joinResult, long completeMsid) {
    AsyncJobJoinMapVO record = createForUpdate();
    record.setJoinStatus(joinStatus);
    record.setJoinResult(joinResult);
    record.setCompleteMsid(completeMsid);
    record.setLastUpdated(DateUtil.currentGMTTime());
    UpdateBuilder ub = getUpdateBuilder(record);
    SearchCriteria<AsyncJobJoinMapVO> sc = CompleteJoinSearch.create();
    sc.setParameters("joinJobId", joinJobId);
    update(ub, sc, null);
}
Also used : AsyncJobJoinMapVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder)

Example 3 with AsyncJobJoinMapVO

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

the class AsyncJobJoinMapDaoImpl method joinJob.

@Override
public Long joinJob(long jobId, long joinJobId, long joinMsid, long wakeupIntervalMs, long expirationMs, Long syncSourceId, String wakeupHandler, String wakeupDispatcher) {
    AsyncJobJoinMapVO record = new AsyncJobJoinMapVO();
    record.setJobId(jobId);
    record.setJoinJobId(joinJobId);
    record.setJoinMsid(joinMsid);
    record.setJoinStatus(JobInfo.Status.IN_PROGRESS);
    record.setSyncSourceId(syncSourceId);
    // convert millisecond to second
    record.setWakeupInterval(wakeupIntervalMs / 1000);
    record.setWakeupHandler(wakeupHandler);
    record.setWakeupDispatcher(wakeupDispatcher);
    if (wakeupHandler != null) {
        record.setNextWakeupTime(new Date(DateUtil.currentGMTTime().getTime() + wakeupIntervalMs));
        record.setExpiration(new Date(DateUtil.currentGMTTime().getTime() + expirationMs));
    }
    persist(record);
    return record.getId();
}
Also used : AsyncJobJoinMapVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO) Date(java.util.Date)

Example 4 with AsyncJobJoinMapVO

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

the class VmWorkJobWakeupDispatcher method runJob.

@Override
public void runJob(AsyncJob job) {
    try {
        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;
        }
        AsyncJobJoinMapVO joinRecord = joinRecords.get(0);
        VmWorkJobVO joinedJob = _workjobDao.findById(joinRecord.getJoinJobId());
        Class<?> workClz = null;
        try {
            workClz = Class.forName(job.getCmd());
        } catch (ClassNotFoundException e) {
            s_logger.error("VM work class " + job.getCmd() + " is not found", e);
            return;
        }
        // get original work context information from joined job
        VmWork work = VmWorkSerializer.deserialize(workClz, joinedJob.getCmdInfo());
        assert (work != null);
        AccountVO account = _accountDao.findById(work.getAccountId());
        assert (account != null);
        VMInstanceVO vm = _instanceDao.findById(work.getVmId());
        assert (vm != null);
        CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated());
        try {
            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());
            }
        } finally {
            CallContext.unregister();
        }
    } catch (Throwable 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);
    }
}
Also used : AsyncJobJoinMapVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO) Method(java.lang.reflect.Method) AccountVO(com.cloud.user.AccountVO) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Aggregations

AsyncJobJoinMapVO (org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 AccountVO (com.cloud.user.AccountVO)1 UpdateBuilder (com.cloud.utils.db.UpdateBuilder)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)1