use of com.cloud.framework.jobs.impl.AsyncJobVO in project cosmic by MissionCriticalCloud.
the class VolumeOrchestrator method cleanupStorageJobs.
@Override
public void cleanupStorageJobs() {
// clean up failure jobs related to volume
final List<AsyncJobVO> jobs = _jobMgr.findFailureAsyncJobs(VmWorkAttachVolume.class.getName(), VmWorkMigrateVolume.class.getName(), VmWorkTakeVolumeSnapshot.class.getName());
for (final AsyncJobVO job : jobs) {
try {
if (job.getCmd().equalsIgnoreCase(VmWorkAttachVolume.class.getName())) {
final VmWorkAttachVolume work = VmWorkSerializer.deserialize(VmWorkAttachVolume.class, job.getCmdInfo());
cleanupVolumeDuringAttachFailure(work.getVolumeId());
} else if (job.getCmd().equalsIgnoreCase(VmWorkMigrateVolume.class.getName())) {
final VmWorkMigrateVolume work = VmWorkSerializer.deserialize(VmWorkMigrateVolume.class, job.getCmdInfo());
cleanupVolumeDuringMigrationFailure(work.getVolumeId(), work.getDestPoolId());
} else if (job.getCmd().equalsIgnoreCase(VmWorkTakeVolumeSnapshot.class.getName())) {
final VmWorkTakeVolumeSnapshot work = VmWorkSerializer.deserialize(VmWorkTakeVolumeSnapshot.class, job.getCmdInfo());
cleanupVolumeDuringSnapshotFailure(work.getVolumeId(), work.getSnapshotId());
}
} catch (final Exception e) {
s_logger.debug("clean up job failure, will continue", e);
}
}
}
use of com.cloud.framework.jobs.impl.AsyncJobVO in project cosmic by MissionCriticalCloud.
the class AsyncJobDaoImpl method getResetJobs.
@Override
public List<AsyncJobVO> getResetJobs(final long msid) {
final SearchCriteria<AsyncJobVO> sc = pendingAsyncJobSearch.create();
sc.setParameters("status", JobInfo.Status.IN_PROGRESS);
// construct query: (job_executing_msid=msid OR (job_executing_msid IS NULL AND job_init_msid=msid))
final SearchCriteria<AsyncJobVO> msQuery = createSearchCriteria();
msQuery.addOr("executingMsid", SearchCriteria.Op.EQ, msid);
final SearchCriteria<AsyncJobVO> initMsQuery = createSearchCriteria();
initMsQuery.addAnd("executingMsid", SearchCriteria.Op.NULL);
initMsQuery.addAnd("initMsid", SearchCriteria.Op.EQ, msid);
msQuery.addOr("initMsid", SearchCriteria.Op.SC, initMsQuery);
sc.addAnd("executingMsid", SearchCriteria.Op.SC, msQuery);
final Filter filter = new Filter(AsyncJobVO.class, "created", true, null, null);
return listIncludingRemovedBy(sc, filter);
}
use of com.cloud.framework.jobs.impl.AsyncJobVO in project cosmic by MissionCriticalCloud.
the class AsyncJobDaoImpl method getExpiredCompletedJobs.
@Override
public List<AsyncJobVO> getExpiredCompletedJobs(final Date cutTime, final int limit) {
final SearchCriteria<AsyncJobVO> sc = expiringCompletedAsyncJobSearch.create();
sc.setParameters("created", cutTime);
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
final Filter filter = new Filter(AsyncJobVO.class, "created", true, 0L, (long) limit);
return listIncludingRemovedBy(sc, filter);
}
use of com.cloud.framework.jobs.impl.AsyncJobVO in project cosmic by MissionCriticalCloud.
the class AsyncJobDaoImpl method getExpiredUnfinishedJobs.
@Override
public List<AsyncJobVO> getExpiredUnfinishedJobs(final Date cutTime, final int limit) {
final SearchCriteria<AsyncJobVO> sc = expiringUnfinishedAsyncJobSearch.create();
sc.setParameters("jobDispatcher", AsyncJobVO.JOB_DISPATCHER_PSEUDO);
sc.setParameters("created", cutTime);
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
final Filter filter = new Filter(AsyncJobVO.class, "created", true, 0L, (long) limit);
return listIncludingRemovedBy(sc, filter);
}
use of com.cloud.framework.jobs.impl.AsyncJobVO in project cosmic by MissionCriticalCloud.
the class ApiServer method queueCommand.
private String queueCommand(final BaseCmd cmdObj, final Map<String, String> params, final StringBuilder log) throws Exception {
final CallContext ctx = CallContext.current();
final Long callerUserId = ctx.getCallingUserId();
final Account caller = ctx.getCallingAccount();
// BaseAsyncCmd: cmd is processed and submitted as an AsyncJob, job related info is serialized and returned.
if (cmdObj instanceof BaseAsyncCmd) {
Long objectId = null;
final String objectUuid;
if (cmdObj instanceof BaseAsyncCreateCmd) {
final BaseAsyncCreateCmd createCmd = (BaseAsyncCreateCmd) cmdObj;
_dispatcher.dispatchCreateCmd(createCmd, params);
objectId = createCmd.getEntityId();
objectUuid = createCmd.getEntityUuid();
params.put("id", objectId.toString());
final Class entityClass = EventTypes.getEntityClassForEvent(createCmd.getEventType());
if (entityClass != null) {
ctx.putContextParameter(entityClass, objectUuid);
}
} else {
// Extract the uuid before params are processed and id reflects internal db id
objectUuid = params.get(ApiConstants.ID);
dispatchChainFactory.getStandardDispatchChain().dispatch(new DispatchTask(cmdObj, params));
}
final BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmdObj;
if (callerUserId != null) {
params.put("ctxUserId", callerUserId.toString());
}
if (caller != null) {
params.put("ctxAccountId", String.valueOf(caller.getId()));
}
if (objectUuid != null) {
params.put("uuid", objectUuid);
}
long startEventId = ctx.getStartEventId();
asyncCmd.setStartEventId(startEventId);
// save the scheduled event
final Long eventId = ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? (Long) User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(), asyncCmd.isDisplay(), startEventId);
if (startEventId == 0) {
// There was no create event before, set current event id as start eventId
startEventId = eventId;
}
params.put("ctxStartEventId", String.valueOf(startEventId));
params.put("cmdEventType", asyncCmd.getEventType().toString());
params.put("ctxDetails", ApiGsonHelper.getBuilder().create().toJson(ctx.getContextParameters()));
final Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId;
// users can provide the job id they want to use, so log as it is a uuid and is unique
final String injectedJobId = asyncCmd.getInjectedJobId();
_uuidMgr.checkUuidSimple(injectedJobId, AsyncJob.class);
final AsyncJobVO job = new AsyncJobVO("", callerUserId, caller.getId(), cmdObj.getClass().getName(), ApiGsonHelper.getBuilder().create().toJson(params), instanceId, asyncCmd.getInstanceType() != null ? asyncCmd.getInstanceType().toString() : null, injectedJobId);
job.setDispatcher(_asyncDispatcher.getName());
final long jobId = _asyncMgr.submitAsyncJob(job);
if (jobId == 0L) {
final String errorMsg = "Unable to schedule async job for command " + job.getCmd();
s_logger.warn(errorMsg);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg);
}
final String response;
if (objectId != null) {
final String objUuid = (objectUuid == null) ? objectId.toString() : objectUuid;
response = getBaseAsyncCreateResponse(jobId, (BaseAsyncCreateCmd) asyncCmd, objUuid);
} else {
SerializationContext.current().setUuidTranslation(true);
response = getBaseAsyncResponse(jobId, asyncCmd);
}
// Always log response for async for now, I don't think any sensitive data will be in here.
// It might be nice to send this through scrubbing similar to how
// ApiResponseSerializer.toSerializedStringWithSecureLogs works. For now, this gets jobid's
// in the api logs.
log.append(response);
return response;
} else {
_dispatcher.dispatch(cmdObj, params, false);
// For those listXXXCommand which we have already created DB views, this step is not needed since async job is joined in their db views.
if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListVMsCmdByAdmin) && !(cmdObj instanceof ListRoutersCmd) && !(cmdObj instanceof ListTagsCmd) && !(cmdObj instanceof ListEventsCmd) && !(cmdObj instanceof ListVMGroupsCmd) && !(cmdObj instanceof ListProjectsCmd) && !(cmdObj instanceof ListProjectAccountsCmd) && !(cmdObj instanceof ListProjectInvitationsCmd) && !(cmdObj instanceof ListHostsCmd) && !(cmdObj instanceof ListVolumesCmd) && !(cmdObj instanceof ListVolumesCmdByAdmin) && !(cmdObj instanceof ListUsersCmd) && !(cmdObj instanceof ListAccountsCmd) && !(cmdObj instanceof ListAccountsCmdByAdmin) && !(cmdObj instanceof ListStoragePoolsCmd) && !(cmdObj instanceof ListDiskOfferingsCmd) && !(cmdObj instanceof ListServiceOfferingsCmd) && !(cmdObj instanceof ListZonesCmd) && !(cmdObj instanceof ListZonesCmdByAdmin)) {
buildAsyncListResponse((BaseListCmd) cmdObj, caller);
}
SerializationContext.current().setUuidTranslation(true);
return ApiResponseSerializer.toSerializedStringWithSecureLogs((ResponseObject) cmdObj.getResponseObject(), cmdObj.getResponseType(), log);
}
}
Aggregations