Search in sources :

Example 6 with JobTerminateRequestedException

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();
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) Version(com.hazelcast.version.Version) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader) CustomClassLoadedObject.deserializeWithCustomClassLoader(com.hazelcast.jet.impl.execution.init.CustomClassLoadedObject.deserializeWithCustomClassLoader) JetException(com.hazelcast.jet.JetException) DAG(com.hazelcast.jet.core.DAG) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException) ExceptionUtil.isTopologyException(com.hazelcast.jet.impl.util.ExceptionUtil.isTopologyException) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException) TerminatedWithSnapshotException(com.hazelcast.jet.impl.exception.TerminatedWithSnapshotException) CancellationException(java.util.concurrent.CancellationException) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException) JetDisabledException(com.hazelcast.jet.impl.exception.JetDisabledException) ExceptionUtil.isRestartableException(com.hazelcast.jet.impl.util.ExceptionUtil.isRestartableException) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) JetException(com.hazelcast.jet.JetException) LocalMemberResetException(com.hazelcast.core.LocalMemberResetException) Nullable(javax.annotation.Nullable)

Example 7 with JobTerminateRequestedException

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);
    }
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) CancellationException(java.util.concurrent.CancellationException) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException)

Example 8 with JobTerminateRequestedException

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));
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException)

Aggregations

JobTerminateRequestedException (com.hazelcast.jet.impl.exception.JobTerminateRequestedException)8 CancellationException (java.util.concurrent.CancellationException)8 LocalMemberResetException (com.hazelcast.core.LocalMemberResetException)4 TopologyChangedException (com.hazelcast.jet.core.TopologyChangedException)4 Address (com.hazelcast.cluster.Address)3 JetException (com.hazelcast.jet.JetException)3 DAG (com.hazelcast.jet.core.DAG)3 JobStatus (com.hazelcast.jet.core.JobStatus)3 Vertex (com.hazelcast.jet.core.Vertex)3 ExecutionNotFoundException (com.hazelcast.jet.impl.exception.ExecutionNotFoundException)3 Functions.entryKey (com.hazelcast.function.Functions.entryKey)2 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)2 MembersView (com.hazelcast.internal.cluster.impl.MembersView)2 Job (com.hazelcast.jet.Job)2 Util.entry (com.hazelcast.jet.Util.entry)2 Util.idToString (com.hazelcast.jet.Util.idToString)2 NONE (com.hazelcast.jet.config.ProcessingGuarantee.NONE)2 Edge (com.hazelcast.jet.core.Edge)2 Edge.between (com.hazelcast.jet.core.Edge.between)2 COMPLETED (com.hazelcast.jet.core.JobStatus.COMPLETED)2