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());
}
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();
});
}
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);
}
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);
}
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);
}
}
Aggregations