@Override public String purgeTableAsync(String table, Audit audit) { checkNotNull(audit, "audit"); JobIdentifier<PurgeRequest, PurgeResult> jobId = _jobService.submitJob( new JobRequest<>(PurgeJob.INSTANCE, new PurgeRequest(table, audit))); return jobId.toString(); }
public static <Q, R> JobIdentifier<Q, R> fromString(String id, JobType<Q, R> jobType) { checkNotNull(id, "id"); checkNotNull(jobType, "jobType"); checkArgument(jobType.getName().equals(getJobTypeNameFromId(id)), "Inconsistent type"); return new JobIdentifier<>(id, jobType); }
@Nullable @Override public <Q, R> JobStatus<Q, R> getJobStatus(JobIdentifier<Q, R> jobId) { checkNotNull(jobId, "jobId"); Map<String, Object> result = _dataStore.get(getTableName(), jobId.toString(), ReadConsistency.STRONG); if (Intrinsic.isDeleted(result)) { return null; } Object status = result.get("status"); return narrow(status, jobId.getJobType()); }
public static <Q, R> JobIdentifier<Q, R> createNew(JobType<Q, R> jobType) { checkNotNull(jobType, "jobType"); return new JobIdentifier<>(toId(jobType.getName(), UUID.randomUUID()), jobType); }
@Override public PurgeStatus getPurgeStatus( String table, String jobID) { checkNotNull(table, "table"); JobIdentifier<PurgeRequest, PurgeResult> jobId; try { jobId = JobIdentifier.fromString(jobID, PurgeJob.INSTANCE); } catch (IllegalArgumentException e) { // The tableName is illegal and therefore cannot match any purge jobs. throw new UnknownPurgeException(jobID); } JobStatus<PurgeRequest, PurgeResult> status = _jobService.getJobStatus(jobId); if (status == null) { throw new UnknownPurgeException(jobID); } PurgeRequest request = status.getRequest(); if (request == null) { throw new IllegalStateException("Purge request details not found: " + jobId); } switch (status.getStatus()) { case FINISHED: return new PurgeStatus(request.getTable(), PurgeStatus.Status.COMPLETE); case FAILED: return new PurgeStatus(request.getTable(), PurgeStatus.Status.ERROR); default: return new PurgeStatus(request.getTable(), PurgeStatus.Status.IN_PROGRESS); } }
throw new IllegalArgumentException("No handler found for job type: " + getJobTypeNameFromId(jobIdString)); jobId = fromString(jobIdString, registryEntry.getJobType()); JobStatus<Q, R> initialStatus = _jobStatusDAO.getJobStatus(jobId); jobIdString, getJobTypeNameFromId(jobIdString)); } else { _log.info("Job has already run: [id={}, type={}]", jobIdString, getJobTypeNameFromId(jobIdString)); return true; _log.warn("Unable to execute job: [id={}, type={}]", jobIdString, getJobTypeNameFromId(jobIdString), e); return true; _log.error("Job failed: [id={}, type={}]", jobId, jobId.getJobType(), e); recordFinalStatus(jobId, new JobStatus<Q, R>(JobStatus.Status.FAILED, request, null, e.getMessage()));
@Override public <Q, R> JobIdentifier<Q, R> submitJob(JobRequest<Q, R> jobRequest) { checkNotNull(jobRequest, "jobRequest"); JobType<Q, R> jobType = jobRequest.getType(); // Ensure there is a handler for this job type RegistryEntry<?, ?> entry = _jobHandlerRegistry.getRegistryEntry(jobType.getName()); if (entry == null) { throw new IllegalArgumentException("Cannot handle job of type " + jobType); } // Create a unique job identifier JobIdentifier<Q, R> jobId = createNew(jobType); // Store the job status as "submitted" JobStatus<Q, R> jobStatus = new JobStatus<>(JobStatus.Status.SUBMITTED, jobRequest.getRequest(), null, null); _jobStatusDAO.updateJobStatus(jobId, jobStatus); // Queue the job _queueService.send(_queueName, jobId.toString()); return jobId; }
String jobTypeName = getJobTypeNameFromId(jobIdString); RegistryEntry<?, ?> entry = _jobHandlerRegistry.getRegistryEntry(jobTypeName);
@Nullable @Override public <Q, R> JobStatus<Q, R> getJobStatus(final JobIdentifier<Q, R> jobId) { Object jobStatusJson = _statusMap.get(jobId); if (jobStatusJson == null) { return null; } return narrow(jobStatusJson, jobId.getJobType()); }
@Override public PurgeStatus getPurgeStatus( String table, String jobID) { checkNotNull(table, "table"); JobIdentifier<PurgeRequest, PurgeResult> jobId; try { jobId = JobIdentifier.fromString(jobID, PurgeJob.INSTANCE); } catch (IllegalArgumentException e) { // The tableName is illegal and therefore cannot match any purge jobs. throw new UnknownPurgeException(jobID); } JobStatus<PurgeRequest, PurgeResult> status = _jobService.getJobStatus(jobId); if (status == null) { throw new UnknownPurgeException(jobID); } PurgeRequest request = status.getRequest(); if (request == null) { throw new IllegalStateException("Purge request details not found: " + jobId); } switch (status.getStatus()) { case FINISHED: return new PurgeStatus(request.getTable(), PurgeStatus.Status.COMPLETE); case FAILED: return new PurgeStatus(request.getTable(), PurgeStatus.Status.ERROR); default: return new PurgeStatus(request.getTable(), PurgeStatus.Status.IN_PROGRESS); } }
throw new IllegalArgumentException("No handler found for job type: " + getJobTypeNameFromId(jobIdString)); jobId = fromString(jobIdString, registryEntry.getJobType()); JobStatus<Q, R> initialStatus = _jobStatusDAO.getJobStatus(jobId); jobIdString, getJobTypeNameFromId(jobIdString)); } else { _log.info("Job has already run: [id={}, type={}]", jobIdString, getJobTypeNameFromId(jobIdString)); return true; _log.warn("Unable to execute job: [id={}, type={}]", jobIdString, getJobTypeNameFromId(jobIdString), e); return true; _log.error("Job failed: [id={}, type={}]", jobId, jobId.getJobType(), e); recordFinalStatus(jobId, new JobStatus<Q, R>(JobStatus.Status.FAILED, request, null, e.getMessage()));
@Override public <Q, R> JobIdentifier<Q, R> submitJob(JobRequest<Q, R> jobRequest) { checkNotNull(jobRequest, "jobRequest"); JobType<Q, R> jobType = jobRequest.getType(); // Ensure there is a handler for this job type RegistryEntry<?, ?> entry = _jobHandlerRegistry.getRegistryEntry(jobType.getName()); if (entry == null) { throw new IllegalArgumentException("Cannot handle job of type " + jobType); } // Create a unique job identifier JobIdentifier<Q, R> jobId = createNew(jobType); // Store the job status as "submitted" JobStatus<Q, R> jobStatus = new JobStatus<>(JobStatus.Status.SUBMITTED, jobRequest.getRequest(), null, null); _jobStatusDAO.updateJobStatus(jobId, jobStatus); // Queue the job _queueService.send(_queueName, jobId.toString()); return jobId; }
public static <Q, R> JobIdentifier<Q, R> createNew(JobType<Q, R> jobType) { checkNotNull(jobType, "jobType"); return new JobIdentifier<>(toId(jobType.getName(), UUID.randomUUID()), jobType); }
String jobTypeName = getJobTypeNameFromId(jobIdString); RegistryEntry<?, ?> entry = _jobHandlerRegistry.getRegistryEntry(jobTypeName);
@Nullable @Override public <Q, R> JobStatus<Q, R> getJobStatus(final JobIdentifier<Q, R> jobId) { Object jobStatusJson = _statusMap.get(jobId); if (jobStatusJson == null) { return null; } return narrow(jobStatusJson, jobId.getJobType()); }
@Override public String purgeTableAsync(String table, Audit audit) { checkNotNull(audit, "audit"); JobIdentifier<PurgeRequest, PurgeResult> jobId = _jobService.submitJob( new JobRequest<>(PurgeJob.INSTANCE, new PurgeRequest(table, audit))); return jobId.toString(); }
@Override public ReplaySubscriptionStatus getReplayStatus(String ownerId, String reference) { checkNotNull(reference, "reference"); JobIdentifier<ReplaySubscriptionRequest, ReplaySubscriptionResult> jobId; try { jobId = JobIdentifier.fromString(reference, ReplaySubscriptionJob.INSTANCE); } catch (IllegalArgumentException e) { // The reference is illegal and therefore cannot match any replay jobs. throw new UnknownReplayException(reference); } JobStatus<ReplaySubscriptionRequest, ReplaySubscriptionResult> status = _jobService.getJobStatus(jobId); if (status == null) { throw new UnknownReplayException(reference); } ReplaySubscriptionRequest request = status.getRequest(); if (request == null) { throw new IllegalStateException("Replay request details not found: " + jobId); } checkSubscriptionOwner(ownerId, request.getSubscription()); switch (status.getStatus()) { case FINISHED: return new ReplaySubscriptionStatus(request.getSubscription(), ReplaySubscriptionStatus.Status.COMPLETE); case FAILED: return new ReplaySubscriptionStatus(request.getSubscription(), ReplaySubscriptionStatus.Status.ERROR); default: return new ReplaySubscriptionStatus(request.getSubscription(), ReplaySubscriptionStatus.Status.IN_PROGRESS); } }
@Nullable @Override public <Q, R> JobStatus<Q, R> getJobStatus(JobIdentifier<Q, R> jobId) { checkNotNull(jobId, "jobId"); Map<String, Object> result = _dataStore.get(getTableName(), jobId.toString(), ReadConsistency.STRONG); if (Intrinsic.isDeleted(result)) { return null; } Object status = result.get("status"); return narrow(status, jobId.getJobType()); }
public static <Q, R> JobIdentifier<Q, R> fromString(String id, JobType<Q, R> jobType) { checkNotNull(id, "id"); checkNotNull(jobType, "jobType"); checkArgument(jobType.getName().equals(getJobTypeNameFromId(id)), "Inconsistent type"); return new JobIdentifier<>(id, jobType); }
@Override public <Q, R> JobStatus<Q, R> getJobStatus(JobIdentifier<Q, R> id) { checkNotNull(id); JobStatus<?, ?> jobStatus = _jobStatusDAO.getJobStatus(id); if (jobStatus == null) { return null; } return narrow(jobStatus, id.getJobType()); }