use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JobExecutionService method terminateExecution.
public void terminateExecution(long jobId, long executionId, Address callerAddress, TerminationMode mode) {
failIfNotRunning();
ExecutionContext executionContext = executionContexts.get(executionId);
if (executionContext == null) {
// job. We ignore too and rely on the CheckLightJobsOperation.
return;
}
if (!executionContext.isLightJob()) {
Address masterAddress = nodeEngine.getMasterAddress();
if (!callerAddress.equals(masterAddress)) {
failIfNotRunning();
throw new IllegalStateException(String.format("Caller %s cannot do '%s' for terminateExecution: it is not the master, the master is %s", callerAddress, jobIdAndExecutionId(jobId, executionId), masterAddress));
}
}
Address coordinator = executionContext.coordinator();
if (coordinator == null) {
// It can't happen for normal jobs
assert executionContext.isLightJob() : "null coordinator for non-light job";
} else if (!coordinator.equals(callerAddress)) {
throw new IllegalStateException(String.format("%s, originally from coordinator %s, cannot do 'terminateExecution' by coordinator %s and execution %s", executionContext.jobNameAndExecutionId(), coordinator, callerAddress, idToString(executionId)));
}
Exception cause = mode == null ? new CancellationException() : new JobTerminateRequestedException(mode);
terminateExecution0(executionContext, mode, cause);
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JobExecutionService method runLightJob.
public CompletableFuture<RawJobMetrics> runLightJob(long jobId, long executionId, Address coordinator, int coordinatorMemberListVersion, Set<MemberInfo> participants, ExecutionPlan plan) {
assert executionId == jobId : "executionId(" + idToString(executionId) + ") != jobId(" + idToString(jobId) + ")";
verifyClusterInformation(jobId, executionId, coordinator, coordinatorMemberListVersion, participants);
failIfNotRunning();
ExecutionContext execCtx;
synchronized (mutex) {
addExecutionContextJobId(jobId, executionId, coordinator);
execCtx = executionContexts.computeIfAbsent(executionId, x -> new ExecutionContext(nodeEngine, jobId, executionId, true));
}
try {
Set<Address> addresses = participants.stream().map(MemberInfo::getAddress).collect(toSet());
ClassLoader jobCl = jobClassloaderService.getClassLoader(jobId);
// We don't create the CL for light jobs.
assert jobClassloaderService.getClassLoader(jobId) == null;
doWithClassLoader(jobCl, () -> execCtx.initialize(coordinator, addresses, plan));
} catch (Throwable e) {
completeExecution(execCtx, new CancellationException());
throw e;
}
// initial log entry with all of jobId, jobName, executionId
if (logger.isFineEnabled()) {
logger.fine("Execution plan for light job ID=" + idToString(jobId) + ", jobName=" + (execCtx.jobName() != null ? '\'' + execCtx.jobName() + '\'' : "null") + ", executionId=" + idToString(executionId) + " initialized, will start the execution");
}
return beginExecution0(execCtx, false);
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class SnapshotPhase1Operation method doRun.
@Override
protected CompletableFuture<SnapshotPhase1Result> doRun() {
JetServiceBackend service = getJetServiceBackend();
ExecutionContext ctx = service.getJobExecutionService().assertExecutionContext(getCallerAddress(), jobId(), executionId, getClass().getSimpleName());
assert !ctx.isLightJob() : "snapshot phase 1 started on a light job: " + idToString(executionId);
CompletableFuture<SnapshotPhase1Result> future = ctx.beginSnapshotPhase1(snapshotId, mapName, flags).exceptionally(exc -> new SnapshotPhase1Result(0, 0, 0, exc)).thenApply(result -> {
if (result.getError() == null) {
logFine(getLogger(), "Snapshot %s phase 1 for %s finished successfully on member", snapshotId, ctx.jobNameAndExecutionId());
} else {
getLogger().warning(String.format("Snapshot %d phase 1 for %s finished with an error on member: " + "%s", snapshotId, ctx.jobNameAndExecutionId(), result.getError()));
}
return result;
});
if (!postponeResponses) {
return future;
}
return future.thenCompose(result -> {
CompletableFuture<SnapshotPhase1Result> f2 = new CompletableFuture<>();
tryCompleteLater(result, f2);
return f2;
});
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JetTestSupport method assertJobNotExecuting.
/**
* Asserts that the {@code job} does not have an {@link ExecutionContext}
* on the given {@code instance}.
*/
public static void assertJobNotExecuting(Job job, HazelcastInstance instance) {
ExecutionContext execCtx = getJetServiceBackend(instance).getJobExecutionService().getExecutionContext(job.getId());
assertNull("Job should not be executing on member " + instance + ", but is", execCtx);
}
use of com.hazelcast.jet.impl.execution.ExecutionContext in project hazelcast by hazelcast.
the class JetTestSupport method assertJobExecuting.
/**
* Asserts that the {@code job} has an {@link ExecutionContext} on the
* given {@code instance}.
*/
public static void assertJobExecuting(Job job, HazelcastInstance instance) {
ExecutionContext execCtx = getJetServiceBackend(instance).getJobExecutionService().getExecutionContext(job.getId());
assertNotNull("Job should be executing on member " + instance + ", but is not", execCtx);
}
Aggregations