Search in sources :

Example 21 with FlinkException

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);
    }
}
Also used : MasterTriggerRestoreHook(org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook) FlinkException(org.apache.flink.util.FlinkException)

Example 22 with FlinkException

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));
    }
}
Also used : MasterState(org.apache.flink.runtime.checkpoint.MasterState) FlinkException(org.apache.flink.util.FlinkException) Logger(org.slf4j.Logger) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) Preconditions(org.apache.flink.util.Preconditions) ArrayList(java.util.ArrayList) MasterTriggerRestoreHook(org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook) LinkedHashMap(java.util.LinkedHashMap) LambdaUtil(org.apache.flink.util.LambdaUtil) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) SimpleVersionedSerializer(org.apache.flink.core.io.SimpleVersionedSerializer) Map(java.util.Map) Nullable(javax.annotation.Nullable) MasterState(org.apache.flink.runtime.checkpoint.MasterState) CompletionException(java.util.concurrent.CompletionException) FlinkException(org.apache.flink.util.FlinkException)

Example 23 with FlinkException

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);
    }
}
Also used : MasterTriggerRestoreHook(org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook) FlinkException(org.apache.flink.util.FlinkException)

Example 24 with FlinkException

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();
}
Also used : Time(org.apache.flink.api.common.time.Time) FlinkException(org.apache.flink.util.FlinkException)

Example 25 with FlinkException

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;
}
Also used : Acknowledge(org.apache.flink.runtime.messages.Acknowledge) FlinkException(org.apache.flink.util.FlinkException)

Aggregations

FlinkException (org.apache.flink.util.FlinkException)197 Test (org.junit.Test)91 CompletableFuture (java.util.concurrent.CompletableFuture)59 IOException (java.io.IOException)38 ExecutionException (java.util.concurrent.ExecutionException)26 ArrayList (java.util.ArrayList)25 JobID (org.apache.flink.api.common.JobID)24 Collection (java.util.Collection)22 CompletionException (java.util.concurrent.CompletionException)22 Configuration (org.apache.flink.configuration.Configuration)21 TimeoutException (java.util.concurrent.TimeoutException)19 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)19 Time (org.apache.flink.api.common.time.Time)16 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)16 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)16 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)15 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)14 Collections (java.util.Collections)13 List (java.util.List)13 ExecutorService (java.util.concurrent.ExecutorService)13