Search in sources :

Example 6 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class JobCoordinationService method joinSubmittedJob.

public CompletableFuture<Void> joinSubmittedJob(long jobId) {
    checkOperationalState();
    CompletableFuture<CompletableFuture<Void>> future = callWithJob(jobId, mc -> mc.jobContext().jobCompletionFuture().handle((r, t) -> {
        if (t == null) {
            return null;
        }
        if (t instanceof CancellationException || t instanceof JetException) {
            throw sneakyThrow(t);
        }
        throw new JetException(t.toString(), t);
    }), JobResult::asCompletableFuture, jobRecord -> {
        JobExecutionRecord jobExecutionRecord = ensureExecutionRecord(jobId, jobRepository.getJobExecutionRecord(jobId));
        return startJobIfNotStartedOrCompleted(jobRecord, jobExecutionRecord, "join request from client");
    }, null);
    return future.thenCompose(// unwrap the inner future
    identity());
}
Also used : Arrays(java.util.Arrays) Clock(com.hazelcast.internal.util.Clock) SecurityContext(com.hazelcast.security.SecurityContext) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ClusterService(com.hazelcast.internal.cluster.ClusterService) NotifyMemberShutdownOperation(com.hazelcast.jet.impl.operation.NotifyMemberShutdownOperation) Future(java.util.concurrent.Future) DATA_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.DATA_MEMBER_SELECTOR) MwCounter(com.hazelcast.internal.util.counters.MwCounter) Map(java.util.Map) Counter(com.hazelcast.internal.util.counters.Counter) DAG(com.hazelcast.jet.core.DAG) JobStatus(com.hazelcast.jet.core.JobStatus) JobSuspensionCause(com.hazelcast.jet.core.JobSuspensionCause) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) CancellationException(java.util.concurrent.CancellationException) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) OverflowPolicy(com.hazelcast.ringbuffer.OverflowPolicy) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) CANCEL_FORCEFUL(com.hazelcast.jet.impl.TerminationMode.CANCEL_FORCEFUL) Util(com.hazelcast.jet.impl.util.Util) Util.idToString(com.hazelcast.jet.Util.idToString) PASSIVE(com.hazelcast.cluster.ClusterState.PASSIVE) Permission(java.security.Permission) MetricNames(com.hazelcast.jet.core.metrics.MetricNames) PipelineImpl(com.hazelcast.jet.impl.pipeline.PipelineImpl) CACHED(com.hazelcast.internal.util.executor.ExecutorType.CACHED) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) COORDINATOR(com.hazelcast.jet.impl.JobClassLoaderService.JobPhase.COORDINATOR) GetJobIdsResult(com.hazelcast.jet.impl.operation.GetJobIdsOperation.GetJobIdsResult) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) StreamSupport(java.util.stream.StreamSupport) IN_TRANSITION(com.hazelcast.cluster.ClusterState.IN_TRANSITION) Version(com.hazelcast.version.Version) Nullable(javax.annotation.Nullable) JetConfig(com.hazelcast.jet.config.JetConfig) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) EnteringPassiveClusterStateException(com.hazelcast.jet.impl.exception.EnteringPassiveClusterStateException) WrappedThrowable(com.hazelcast.jet.impl.observer.WrappedThrowable) ExecutionException(java.util.concurrent.ExecutionException) Vertex(com.hazelcast.jet.core.Vertex) CheckReturnValue(javax.annotation.CheckReturnValue) DoneItem(com.hazelcast.jet.impl.execution.DoneItem) LoggingUtil.logFine(com.hazelcast.jet.impl.util.LoggingUtil.logFine) HOURS(java.util.concurrent.TimeUnit.HOURS) ObservableImpl(com.hazelcast.jet.impl.observer.ObservableImpl) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) ScheduledFuture(java.util.concurrent.ScheduledFuture) NOT_RUNNING(com.hazelcast.jet.core.JobStatus.NOT_RUNNING) Member(com.hazelcast.cluster.Member) Spliterators(java.util.Spliterators) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) JobConfigArguments(com.hazelcast.jet.config.JobConfigArguments) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SUSPENDED(com.hazelcast.jet.core.JobStatus.SUSPENDED) FunctionEx(com.hazelcast.function.FunctionEx) Collections.emptyList(java.util.Collections.emptyList) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JOB_SCAN_PERIOD(com.hazelcast.spi.properties.ClusterProperty.JOB_SCAN_PERIOD) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Node(com.hazelcast.instance.impl.Node) Objects(java.util.Objects) List(java.util.List) JobAlreadyExistsException(com.hazelcast.jet.JobAlreadyExistsException) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) TopologyChangedException(com.hazelcast.jet.core.TopologyChangedException) PartitionServiceState(com.hazelcast.internal.partition.impl.PartitionServiceState) LoggingUtil(com.hazelcast.jet.impl.util.LoggingUtil) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) LoggingUtil.logFinest(com.hazelcast.jet.impl.util.LoggingUtil.logFinest) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) ExceptionUtil.sneakyThrow(com.hazelcast.jet.impl.util.ExceptionUtil.sneakyThrow) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) JetException(com.hazelcast.jet.JetException) COMPLETING(com.hazelcast.jet.core.JobStatus.COMPLETING) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ILogger(com.hazelcast.logging.ILogger) Comparator.comparing(java.util.Comparator.comparing) Nonnull(javax.annotation.Nonnull) Tuple2(com.hazelcast.jet.datamodel.Tuple2) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) Data(com.hazelcast.internal.serialization.Data) ALL_JOBS(com.hazelcast.jet.impl.operation.GetJobIdsOperation.ALL_JOBS) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) RawJobMetrics(com.hazelcast.jet.impl.metrics.RawJobMetrics) MetricTags(com.hazelcast.jet.core.metrics.MetricTags) Subject(javax.security.auth.Subject) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) CustomClassLoadedObject.deserializeWithCustomClassLoader(com.hazelcast.jet.impl.execution.init.CustomClassLoadedObject.deserializeWithCustomClassLoader) ClusterState(com.hazelcast.cluster.ClusterState) Context(com.hazelcast.jet.impl.pipeline.PipelineImpl.Context) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) CompletableFuture(java.util.concurrent.CompletableFuture) CancellationException(java.util.concurrent.CancellationException) JetException(com.hazelcast.jet.JetException)

Example 7 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class MasterSnapshotContext method onSnapshotPhase2Complete.

/**
 * @param phase1Error error from the phase-1. Null if phase-1 was successful.
 * @param responses collected responses from the members
 * @param snapshotFlags flags of the snapshot
 * @param future future to be completed when the phase-2 is fully completed
 * @param startTime phase-1 start time
 */
private void onSnapshotPhase2Complete(String phase1Error, Collection<Entry<MemberInfo, Object>> responses, long executionId, long snapshotId, int snapshotFlags, @Nullable CompletableFuture<Void> future, long startTime) {
    mc.coordinationService().submitToCoordinatorThread(() -> {
        if (executionId != mc.executionId()) {
            LoggingUtil.logFine(logger, "%s: ignoring responses for snapshot %s phase 2: " + "the responses are from a different execution: %s. Responses: %s", mc.jobIdString(), snapshotId, idToString(executionId), responses);
            return;
        }
        for (Entry<MemberInfo, Object> response : responses) {
            if (response.getValue() instanceof Throwable) {
                logger.log(response.getValue() instanceof ExecutionNotFoundException ? Level.FINE : Level.WARNING, SnapshotPhase2Operation.class.getSimpleName() + " for snapshot " + snapshotId + " in " + mc.jobIdString() + " failed on member: " + response, (Throwable) response.getValue());
            }
        }
        if (future != null) {
            if (phase1Error == null) {
                future.complete(null);
            } else {
                future.completeExceptionally(new JetException(phase1Error));
            }
        }
        mc.lock();
        try {
            // double-check the execution ID after locking
            if (executionId != mc.executionId()) {
                logger.fine("Not completing terminalSnapshotFuture on " + mc.jobIdString() + ", new execution " + "already started, snapshot was for executionId=" + idToString(executionId));
                return;
            }
            assert snapshotInProgress : "snapshot not in progress";
            snapshotInProgress = false;
            if (SnapshotFlags.isTerminal(snapshotFlags)) {
                // after a terminal snapshot, no more snapshots are scheduled in this execution
                boolean completedNow = terminalSnapshotFuture.complete(null);
                assert completedNow : "terminalSnapshotFuture was already completed";
                if (phase1Error != null) {
                    // If the terminal snapshot failed, the executions might not terminate on some members
                    // normally and we don't care if they do - the snapshot is done and we have to bring the
                    // execution down. Let's execute the CompleteExecutionOperation to terminate them.
                    mc.jobContext().cancelExecutionInvocations(mc.jobId(), mc.executionId(), null, null);
                }
            } else if (!SnapshotFlags.isExport(snapshotFlags)) {
                // if this snapshot was an automatic snapshot, schedule the next one
                mc.coordinationService().scheduleSnapshot(mc, executionId);
            }
        } finally {
            mc.unlock();
        }
        if (logger.isFineEnabled()) {
            logger.fine("Snapshot " + snapshotId + " for " + mc.jobIdString() + " completed in " + (System.currentTimeMillis() - startTime) + "ms, status=" + (phase1Error == null ? "success" : "failure: " + phase1Error));
        }
        tryBeginSnapshot();
    });
}
Also used : ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) SnapshotPhase2Operation(com.hazelcast.jet.impl.operation.SnapshotPhase2Operation) JetException(com.hazelcast.jet.JetException)

Example 8 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class JobClassLoaderService method createProcessorClassLoaders.

private Map<String, ClassLoader> createProcessorClassLoaders(long jobId, JobConfig jobConfig, ClassLoader parent) {
    logger.fine("Create processor classloader map for job " + idToString(jobId));
    String customLibDir = nodeEngine.getProperties().getString(ClusterProperty.PROCESSOR_CUSTOM_LIB_DIR);
    Map<String, ClassLoader> classLoaderMap = new HashMap<>();
    for (Entry<String, List<String>> entry : jobConfig.getCustomClassPaths().entrySet()) {
        List<URL> list = entry.getValue().stream().map(jar -> {
            try {
                Path path = Paths.get(customLibDir, jar);
                return path.toUri().toURL();
            } catch (MalformedURLException e) {
                throw new JetException(e);
            }
        }).collect(Collectors.toList());
        URL[] urls = list.toArray(new URL[] {});
        classLoaderMap.put(entry.getKey(), new ChildFirstClassLoader(urls, parent));
    }
    return unmodifiableMap(classLoaderMap);
}
Also used : URL(java.net.URL) LoggingUtil.logFinest(com.hazelcast.jet.impl.util.LoggingUtil.logFinest) HashMap(java.util.HashMap) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) JetException(com.hazelcast.jet.JetException) ILogger(com.hazelcast.logging.ILogger) Map(java.util.Map) ChildFirstClassLoader(com.hazelcast.jet.impl.deployment.ChildFirstClassLoader) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) JetConfig(com.hazelcast.jet.config.JetConfig) HazelcastException(com.hazelcast.core.HazelcastException) NodeEngine(com.hazelcast.spi.impl.NodeEngine) MalformedURLException(java.net.MalformedURLException) JobConfig(com.hazelcast.jet.config.JobConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) Paths(java.nio.file.Paths) LoggingUtil.logFine(com.hazelcast.jet.impl.util.LoggingUtil.logFine) Entry(java.util.Map.Entry) JetClassLoader(com.hazelcast.jet.impl.deployment.JetClassLoader) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) AccessController(java.security.AccessController) Collections(java.util.Collections) Util(com.hazelcast.jet.Util) Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Util.idToString(com.hazelcast.jet.Util.idToString) JetException(com.hazelcast.jet.JetException) URL(java.net.URL) ChildFirstClassLoader(com.hazelcast.jet.impl.deployment.ChildFirstClassLoader) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) ChildFirstClassLoader(com.hazelcast.jet.impl.deployment.ChildFirstClassLoader) JetClassLoader(com.hazelcast.jet.impl.deployment.JetClassLoader) List(java.util.List)

Example 9 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class SlidingWindowP method restoreFromSnapshot.

@Override
@SuppressWarnings("unchecked")
protected void restoreFromSnapshot(@Nonnull Object key, @Nonnull Object value) {
    if (key instanceof BroadcastKey) {
        BroadcastKey bcastKey = (BroadcastKey) key;
        if (!Keys.NEXT_WIN_TO_EMIT.equals(bcastKey.key())) {
            throw new JetException("Unexpected broadcast key: " + bcastKey.key());
        }
        long newNextWinToEmit = (long) value;
        assert processingGuarantee != EXACTLY_ONCE || minRestoredNextWinToEmit == Long.MAX_VALUE || minRestoredNextWinToEmit == newNextWinToEmit : "different values for nextWinToEmit restored, before=" + minRestoredNextWinToEmit + ", new=" + newNextWinToEmit;
        minRestoredNextWinToEmit = Math.min(newNextWinToEmit, minRestoredNextWinToEmit);
        return;
    }
    SnapshotKey k = (SnapshotKey) key;
    // align frame timestamp to our frame - they can be misaligned
    // if the slide step was changed in the updated DAG
    long higherFrameTs = winPolicy.higherFrameTs(k.timestamp - 1);
    if (higherFrameTs != k.timestamp) {
        if (!badFrameRestored) {
            badFrameRestored = true;
            getLogger().warning("Frames in the state do not match the current frame size: they were likely " + "saved for a different window slide step or a different offset. The window results will " + "probably be incorrect until all restored frames are emitted.");
        }
    }
    minRestoredFrameTs = Math.min(higherFrameTs, minRestoredFrameTs);
    tsToKeyToAcc.computeIfAbsent(higherFrameTs, createMapPerTsFunction).merge((K) k.key, (A) value, (o, n) -> {
        if (!badFrameRestored) {
            throw new JetException("Duplicate key in snapshot: " + k);
        }
        if (combineFn == null) {
            throw new JetException("AggregateOperation.combineFn required for merging restored frames");
        }
        combineFn.accept(o, n);
        totalKeysInFrames.inc(-1);
        return o;
    });
    totalKeysInFrames.inc();
    topTs = max(topTs, higherFrameTs);
}
Also used : BroadcastKey(com.hazelcast.jet.core.BroadcastKey) JetException(com.hazelcast.jet.JetException)

Example 10 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class ServiceFactory method clone.

@Override
@SuppressWarnings("unchecked")
protected ServiceFactory<C, S> clone() {
    try {
        ServiceFactory<C, S> copy = (ServiceFactory<C, S>) super.clone();
        copy.attachedFiles = new HashMap<>(attachedFiles);
        return copy;
    } catch (CloneNotSupportedException e) {
        throw new JetException(getClass() + " is not cloneable", e);
    }
}
Also used : JetException(com.hazelcast.jet.JetException)

Aggregations

JetException (com.hazelcast.jet.JetException)52 IOException (java.io.IOException)8 Nonnull (javax.annotation.Nonnull)8 ILogger (com.hazelcast.logging.ILogger)7 List (java.util.List)7 Map (java.util.Map)6 Util.idToString (com.hazelcast.jet.Util.idToString)5 JobConfig (com.hazelcast.jet.config.JobConfig)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 BroadcastKey (com.hazelcast.jet.core.BroadcastKey)4 JobStatus (com.hazelcast.jet.core.JobStatus)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Job (com.hazelcast.jet.Job)3 DAG (com.hazelcast.jet.core.DAG)3 Watermark (com.hazelcast.jet.core.Watermark)3 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3