Search in sources :

Example 21 with ExecutionContext

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);
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) Address(com.hazelcast.cluster.Address) CancellationException(java.util.concurrent.CancellationException) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) CancellationException(java.util.concurrent.CancellationException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 22 with ExecutionContext

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);
}
Also used : Address(com.hazelcast.cluster.Address) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) ScheduledFuture(java.util.concurrent.ScheduledFuture) Member(com.hazelcast.cluster.Member) UnaryOperator(java.util.function.UnaryOperator) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MwCounter(com.hazelcast.internal.util.counters.MwCounter) Map(java.util.Map) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) Counter(com.hazelcast.internal.util.counters.Counter) Collectors.toSet(java.util.stream.Collectors.toSet) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) CancellationException(java.util.concurrent.CancellationException) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Objects(java.util.Objects) SenderReceiverKey(com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) MetricNames(com.hazelcast.jet.core.metrics.MetricNames) Entry(java.util.Map.Entry) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException) LoggingUtil(com.hazelcast.jet.impl.util.LoggingUtil) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) MembershipManager(com.hazelcast.internal.cluster.impl.MembershipManager) MetricsCompressor(com.hazelcast.internal.metrics.impl.MetricsCompressor) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader) SenderTasklet(com.hazelcast.jet.impl.execution.SenderTasklet) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Function(java.util.function.Function) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) EXECUTION(com.hazelcast.jet.impl.JobClassLoaderService.JobPhase.EXECUTION) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Collections.newSetFromMap(java.util.Collections.newSetFromMap) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) TaskletExecutionService(com.hazelcast.jet.impl.execution.TaskletExecutionService) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Nonnull(javax.annotation.Nonnull) CheckLightJobsOperation(com.hazelcast.jet.impl.operation.CheckLightJobsOperation) Nullable(javax.annotation.Nullable) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MemberLeftException(com.hazelcast.core.MemberLeftException) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) RawJobMetrics(com.hazelcast.jet.impl.metrics.RawJobMetrics) MetricTags(com.hazelcast.jet.core.metrics.MetricTags) TriggerMemberListPublishOp(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp) ExceptionUtil.peel(com.hazelcast.jet.impl.util.ExceptionUtil.peel) Util.jobIdAndExecutionId(com.hazelcast.jet.impl.util.Util.jobIdAndExecutionId) Util(com.hazelcast.jet.Util) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) Address(com.hazelcast.cluster.Address) CancellationException(java.util.concurrent.CancellationException) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader)

Example 23 with ExecutionContext

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;
    });
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) JetInitDataSerializerHook(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook) TimeUnit(java.util.concurrent.TimeUnit) Util.idToString(com.hazelcast.jet.Util.idToString) LoggingUtil.logFine(com.hazelcast.jet.impl.util.LoggingUtil.logFine) Objects.requireNonNull(java.util.Objects.requireNonNull) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 24 with ExecutionContext

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);
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Example 25 with ExecutionContext

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);
}
Also used : ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Aggregations

ExecutionContext (com.hazelcast.jet.impl.execution.ExecutionContext)29 Address (com.hazelcast.cluster.Address)7 Address (com.hazelcast.nio.Address)7 Map (java.util.Map)7 JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)5 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)5 TopologyChangedException (com.hazelcast.jet.core.TopologyChangedException)5 ExecutionNotFoundException (com.hazelcast.jet.impl.exception.ExecutionNotFoundException)5 ExecutionPlan (com.hazelcast.jet.impl.execution.init.ExecutionPlan)5 HashMap (java.util.HashMap)5 CancellationException (java.util.concurrent.CancellationException)5 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)4 JetInitDataSerializerHook (com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook)4 RetryableHazelcastException (com.hazelcast.spi.exception.RetryableHazelcastException)4 IOException (java.io.IOException)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 MembershipManager (com.hazelcast.internal.cluster.impl.MembershipManager)3 TriggerMemberListPublishOp (com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp)3