use of com.hazelcast.jet.impl.exception.JobTerminateRequestedException in project hazelcast by hazelcast.
the class MasterJobContext method resolveDagAndCL.
@Nullable
private Tuple2<DAG, ClassLoader> resolveDagAndCL(Supplier<Long> executionIdSupplier) {
mc.lock();
try {
if (isCancelled()) {
logger.fine("Skipping init job '" + mc.jobName() + "': is already cancelled.");
throw new CancellationException();
}
if (mc.jobStatus() != NOT_RUNNING) {
logger.fine("Not starting job '" + mc.jobName() + "': status is " + mc.jobStatus());
return null;
}
if (mc.jobExecutionRecord().isSuspended()) {
mc.jobExecutionRecord().clearSuspended();
mc.writeJobExecutionRecord(false);
mc.setJobStatus(NOT_RUNNING);
}
if (scheduleRestartIfQuorumAbsent() || scheduleRestartIfClusterIsNotSafe()) {
return null;
}
Version jobClusterVersion = mc.jobRecord().getClusterVersion();
Version currentClusterVersion = mc.nodeEngine().getClusterService().getClusterVersion();
if (!jobClusterVersion.equals(currentClusterVersion)) {
throw new JetException("Cancelling job " + mc.jobName() + ": the cluster was upgraded since the job was " + "submitted. Submitted to version: " + jobClusterVersion + ", current cluster version: " + currentClusterVersion);
}
mc.setJobStatus(STARTING);
// ensure JobExecutionRecord exists
mc.writeJobExecutionRecord(true);
if (requestedTerminationMode != null) {
if (requestedTerminationMode.actionAfterTerminate() != RESTART) {
throw new JobTerminateRequestedException(requestedTerminationMode);
}
// requested termination mode is RESTART, ignore it because we are just starting
requestedTerminationMode = null;
}
ClassLoader classLoader = mc.getJetServiceBackend().getJobClassLoaderService().getOrCreateClassLoader(mc.jobConfig(), mc.jobId(), COORDINATOR);
DAG dag;
JobClassLoaderService jobClassLoaderService = mc.getJetServiceBackend().getJobClassLoaderService();
try {
jobClassLoaderService.prepareProcessorClassLoaders(mc.jobId());
dag = deserializeWithCustomClassLoader(mc.nodeEngine().getSerializationService(), classLoader, mc.jobRecord().getDag());
} catch (Exception e) {
throw new JetException("DAG deserialization failed", e);
} finally {
jobClassLoaderService.clearProcessorClassLoaders();
}
// save a copy of the vertex list because it is going to change
vertices = new HashSet<>();
dag.iterator().forEachRemaining(vertices::add);
mc.setExecutionId(executionIdSupplier.get());
mc.snapshotContext().onExecutionStarted();
executionCompletionFuture = new CompletableFuture<>();
return tuple2(dag, classLoader);
} finally {
mc.unlock();
}
}
use of com.hazelcast.jet.impl.exception.JobTerminateRequestedException in project hazelcast by hazelcast.
the class LightMasterContext method finalizeJob.
private void finalizeJob(@Nullable Throwable failure) {
// close ProcessorMetaSuppliers
for (Vertex vertex : vertices) {
try {
vertex.getMetaSupplier().close(failure);
} catch (Throwable e) {
logger.severe(jobIdString + " encountered an exception in ProcessorMetaSupplier.complete(), ignoring it", e);
}
}
if (failure == null) {
jobCompletionFuture.complete(null);
} else {
// translate JobTerminateRequestedException(CANCEL_FORCEFUL) to CancellationException
if (failure instanceof JobTerminateRequestedException && ((JobTerminateRequestedException) failure).mode() == CANCEL_FORCEFUL) {
CancellationException newFailure = new CancellationException();
newFailure.initCause(failure);
failure = newFailure;
}
jobCompletionFuture.completeExceptionally(failure);
}
}
use of com.hazelcast.jet.impl.exception.JobTerminateRequestedException in project hazelcast by hazelcast.
the class ExecutionLifecycleTest method assertPsClosedWithError.
private void assertPsClosedWithError() {
assertEquals(MEMBER_COUNT, MockPS.initCount.get());
// with light jobs the init can be called on not all the members - the execution on one member
// can be cancelled due to the failure on the other member before it was initialized.
int minCount = useLightJob ? 1 : MEMBER_COUNT;
assertBetween("close count", MockPS.closeCount.get(), minCount, MEMBER_COUNT);
assertBetween("received close errors", MockPS.receivedCloseErrors.size(), minCount, MEMBER_COUNT);
for (int i = 0; i < MockPS.receivedCloseErrors.size(); i++) {
assertOneOfExceptionsInCauses(MockPS.receivedCloseErrors.get(i), MOCK_ERROR, new CancellationException(), new JobTerminateRequestedException(CANCEL_FORCEFUL));
}
}
Aggregations