use of org.apache.flink.util.FlinkException in project flink by apache.
the class MasterHooks method deserializeState.
private static <T> T deserializeState(MasterState state, MasterTriggerRestoreHook<?> hook) throws FlinkException {
@SuppressWarnings("unchecked") final MasterTriggerRestoreHook<T> typedHook = (MasterTriggerRestoreHook<T>) hook;
final String id = hook.getIdentifier();
try {
final SimpleVersionedSerializer<T> deserializer = typedHook.createCheckpointDataSerializer();
if (deserializer == null) {
throw new FlinkException("null serializer for state of hook " + hook.getIdentifier());
}
return deserializer.deserialize(state.version(), state.bytes());
} catch (Throwable t) {
throw new FlinkException("Cannot deserialize state for master hook '" + id + '\'', t);
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class MasterHooks method triggerHook.
// ------------------------------------------------------------------------
// checkpoint triggering
// ------------------------------------------------------------------------
/**
* Trigger master hook and return a completable future with state.
*
* @param hook The master hook given
* @param checkpointId The checkpoint ID of the triggering checkpoint
* @param timestamp The (informational) timestamp for the triggering checkpoint
* @param executor An executor that can be used for asynchronous I/O calls
* @param <T> The type of data produced by the hook
* @return the completable future with state
*/
public static <T> CompletableFuture<MasterState> triggerHook(MasterTriggerRestoreHook<T> hook, long checkpointId, long timestamp, Executor executor) {
final String id = hook.getIdentifier();
final SimpleVersionedSerializer<T> serializer = hook.createCheckpointDataSerializer();
try {
// call the hook!
final CompletableFuture<T> resultFuture = hook.triggerCheckpoint(checkpointId, timestamp, executor);
if (resultFuture == null) {
return CompletableFuture.completedFuture(null);
}
return resultFuture.thenApply(result -> {
// if the result of the future is not null, return it as state
if (result == null) {
return null;
} else if (serializer != null) {
try {
final int version = serializer.getVersion();
final byte[] bytes = serializer.serialize(result);
return new MasterState(id, bytes, version);
} catch (Throwable t) {
ExceptionUtils.rethrowIfFatalErrorOrOOM(t);
throw new CompletionException(new FlinkException("Failed to serialize state of master hook '" + id + '\'', t));
}
} else {
throw new CompletionException(new FlinkException("Checkpoint hook '" + id + " is stateful but creates no serializer"));
}
}).exceptionally((throwable) -> {
throw new CompletionException(new FlinkException("Checkpoint master hook '" + id + "' produced an exception", throwable.getCause()));
});
} catch (Throwable t) {
return FutureUtils.completedExceptionally(new FlinkException("Error while triggering checkpoint master hook '" + id + '\'', t));
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class MasterHooks method restoreHook.
private static <T> void restoreHook(final Object state, final MasterTriggerRestoreHook<?> hook, final long checkpointId) throws FlinkException {
@SuppressWarnings("unchecked") final T typedState = (T) state;
@SuppressWarnings("unchecked") final MasterTriggerRestoreHook<T> typedHook = (MasterTriggerRestoreHook<T>) hook;
try {
typedHook.restoreCheckpoint(checkpointId, typedState);
} catch (FlinkException e) {
throw e;
} catch (Throwable t) {
// catch all here, including Errors that may come from dependency and classpath issues
ExceptionUtils.rethrowIfFatalError(t);
throw new FlinkException("Error while calling restoreCheckpoint on checkpoint hook '" + hook.getIdentifier() + '\'', t);
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class DispatcherRestEndpoint method initializeWebSubmissionHandlers.
@Override
protected Collection<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeWebSubmissionHandlers(CompletableFuture<String> localAddressFuture) {
if (restConfiguration.isWebSubmitEnabled()) {
try {
final Time timeout = restConfiguration.getTimeout();
webSubmissionExtension = WebMonitorUtils.loadWebSubmissionExtension(leaderRetriever, timeout, responseHeaders, localAddressFuture, uploadDir, executor, clusterConfiguration);
return webSubmissionExtension.getHandlers();
} catch (FlinkException e) {
if (log.isDebugEnabled()) {
log.debug("Failed to load web based job submission extension.", e);
} else {
log.info("Failed to load web based job submission extension. " + "Probable reason: flink-runtime-web is not in the classpath.");
}
}
} else {
log.info("Web-based job submission is not enabled.");
}
return Collections.emptyList();
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class MiniDispatcher method submitJob.
@Override
public CompletableFuture<Acknowledge> submitJob(JobGraph jobGraph, Time timeout) {
final CompletableFuture<Acknowledge> acknowledgeCompletableFuture = super.submitJob(jobGraph, timeout);
acknowledgeCompletableFuture.whenComplete((Acknowledge ignored, Throwable throwable) -> {
if (throwable != null) {
onFatalError(new FlinkException("Failed to submit job " + jobGraph.getJobID() + " in job mode.", throwable));
}
});
return acknowledgeCompletableFuture;
}
Aggregations