Search in sources :

Example 1 with JobNotFoundException

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);
}
Also used : JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 2 with JobNotFoundException

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;
    }
}
Also used : JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) Job(com.hazelcast.jet.Job) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException)

Example 3 with JobNotFoundException

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;
    }
}
Also used : JobStatus(com.hazelcast.jet.core.JobStatus) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) JetException(com.hazelcast.jet.JetException)

Example 4 with JobNotFoundException

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);
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) LifecycleService(com.hazelcast.core.LifecycleService) RawJobMetrics(com.hazelcast.jet.impl.metrics.RawJobMetrics) JobConfig(com.hazelcast.jet.config.JobConfig) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) JetException(com.hazelcast.jet.JetException) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) IOException(java.io.IOException)

Example 5 with JobNotFoundException

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;
    }
}
Also used : JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) Job(com.hazelcast.jet.Job) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException)

Aggregations

JobNotFoundException (com.hazelcast.jet.core.JobNotFoundException)5 JetException (com.hazelcast.jet.JetException)2 Job (com.hazelcast.jet.Job)2 JobConfig (com.hazelcast.jet.config.JobConfig)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 LifecycleService (com.hazelcast.core.LifecycleService)1 JobStatus (com.hazelcast.jet.core.JobStatus)1 RawJobMetrics (com.hazelcast.jet.impl.metrics.RawJobMetrics)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1