use of com.hazelcast.jet.core.JobNotFoundException in project hazelcast-jet by hazelcast.
the class JobRepository method completeJob.
/**
* Puts a JobResult for the given job and deletes the JobRecord.
* @throws JobNotFoundException if the JobRecord is not found
* @throws IllegalStateException if the JobResult is already present
*/
void completeJob(long jobId, String coordinator, long completionTime, Throwable error) {
JobRecord jobRecord = getJobRecord(jobId);
if (jobRecord == null) {
throw new JobNotFoundException(jobId);
}
JobConfig config = jobRecord.getConfig();
long creationTime = jobRecord.getCreationTime();
JobResult jobResult = new JobResult(jobId, config, coordinator, creationTime, completionTime, error);
JobResult prev = jobResults.putIfAbsent(jobId, jobResult);
if (prev != null) {
throw new IllegalStateException("Job result already exists in the " + jobResults.getName() + " map:\n" + "previous record: " + prev + "\n" + "new record: " + jobResult);
}
deleteJob(jobId);
}
use of com.hazelcast.jet.core.JobNotFoundException in project hazelcast-jet by hazelcast.
the class JetClientInstanceImpl method getJob.
@Override
public Job getJob(long jobId) {
try {
Job job = new ClientJobProxy(client, jobId);
job.getStatus();
return job;
} catch (Exception e) {
if (peel(e) instanceof JobNotFoundException) {
return null;
}
throw e;
}
}
use of com.hazelcast.jet.core.JobNotFoundException in project hazelcast-jet by hazelcast.
the class JobCoordinationService method getJobStatus.
/**
* Returns the job status or fails with {@link JobNotFoundException}
* if the requested job is not found
*/
public JobStatus getJobStatus(long jobId) {
if (!isMaster()) {
throw new JetException("Cannot query status of Job " + idToString(jobId) + ". Master address: " + nodeEngine.getClusterService().getMasterAddress());
}
// first check if there is a job result present.
// this map is updated first during completion.
JobResult jobResult = jobRepository.getJobResult(jobId);
if (jobResult != null) {
return jobResult.getJobStatus();
}
// check if there a master context for running job
MasterContext currentMasterContext = masterContexts.get(jobId);
if (currentMasterContext != null) {
JobStatus jobStatus = currentMasterContext.jobStatus();
if (jobStatus == JobStatus.RUNNING) {
return currentMasterContext.isCancelled() ? JobStatus.COMPLETING : JobStatus.RUNNING;
}
return jobStatus;
}
// no master context found, job might be just submitted
JobRecord jobRecord = jobRepository.getJobRecord(jobId);
if (jobRecord == null) {
// no job record found, but check job results again
// since job might have been completed meanwhile.
jobResult = jobRepository.getJobResult(jobId);
if (jobResult != null) {
return jobResult.getJobStatus();
}
throw new JobNotFoundException(jobId);
} else {
return NOT_STARTED;
}
}
use of com.hazelcast.jet.core.JobNotFoundException in project hazelcast by hazelcast.
the class JobRepository method completeJob.
/**
* Puts a JobResult for the given job and deletes the JobRecord.
*
* @throws JobNotFoundException if the JobRecord is not found
* @throws IllegalStateException if the JobResult is already present
*/
void completeJob(@Nonnull MasterContext masterContext, @Nullable List<RawJobMetrics> terminalMetrics, @Nullable Throwable error, long completionTime) {
long jobId = masterContext.jobId();
JobConfig config = masterContext.jobRecord().getConfig();
long creationTime = masterContext.jobRecord().getCreationTime();
JobResult jobResult = new JobResult(jobId, config, creationTime, completionTime, toErrorMsg(error));
if (terminalMetrics != null) {
try {
List<RawJobMetrics> prevMetrics = jobMetrics.get().put(jobId, terminalMetrics);
if (prevMetrics != null) {
logger.warning("Overwriting job metrics for job " + jobResult);
}
} catch (Exception e) {
logger.warning("Storing the job metrics failed, ignoring: " + e, e);
}
}
for (; ; ) {
// keep trying to store the JobResult until it succeeds
try {
jobResults.get().set(jobId, jobResult);
break;
} catch (Exception e) {
// if the local instance was shut down, re-throw the error
LifecycleService lifecycleService = instance.getLifecycleService();
if (e instanceof HazelcastInstanceNotActiveException && (!lifecycleService.isRunning())) {
throw e;
}
// retry otherwise, after a delay
long retryTimeoutSeconds = 1;
logger.warning("Failed to store JobResult, will retry in " + retryTimeoutSeconds + " seconds: " + e, e);
LockSupport.parkNanos(SECONDS.toNanos(retryTimeoutSeconds));
}
}
deleteJob(jobId);
}
use of com.hazelcast.jet.core.JobNotFoundException in project hazelcast-jet by hazelcast.
the class JetInstanceImpl method getJob.
@Override
public Job getJob(long jobId) {
try {
Job job = new JobProxy((NodeEngineImpl) nodeEngine, jobId);
job.getStatus();
return job;
} catch (Exception e) {
if (peel(e) instanceof JobNotFoundException) {
return null;
}
throw e;
}
}
Aggregations