use of com.cloud.framework.jobs.impl.AsyncJobJoinMapVO 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();
}
}
use of com.cloud.framework.jobs.impl.AsyncJobJoinMapVO in project cosmic by MissionCriticalCloud.
the class AsyncJobJoinMapDaoImpl method completeJoin.
@Override
public void completeJoin(final long joinJobId, final JobInfo.Status joinStatus, final String joinResult, final long completeMsid) {
final AsyncJobJoinMapVO record = createForUpdate();
record.setJoinStatus(joinStatus);
record.setJoinResult(joinResult);
record.setCompleteMsid(completeMsid);
record.setLastUpdated(DateUtil.currentGMTTime());
final UpdateBuilder ub = getUpdateBuilder(record);
final SearchCriteria<AsyncJobJoinMapVO> sc = CompleteJoinSearch.create();
sc.setParameters("joinJobId", joinJobId);
update(ub, sc, null);
}
use of com.cloud.framework.jobs.impl.AsyncJobJoinMapVO in project cosmic by MissionCriticalCloud.
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(final long joinedJobId) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
assert (_job != null);
final AsyncJobJoinMapVO record = s_joinMapDao.getJoinRecord(_job.getId(), joinedJobId);
s_jobMgr.disjoinJob(_job.getId(), joinedJobId);
if (record.getJoinStatus() == JobInfo.Status.FAILED) {
if (record.getJoinResult() != null) {
final 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");
}
}
}
use of com.cloud.framework.jobs.impl.AsyncJobJoinMapVO in project cosmic by MissionCriticalCloud.
the class AsyncJobJoinMapDaoImpl method joinJob.
@Override
public Long joinJob(final long jobId, final long joinJobId, final long joinMsid, final long wakeupIntervalMs, final long expirationMs, final Long syncSourceId, final String wakeupHandler, final String wakeupDispatcher) {
final 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();
}
Aggregations