Search in sources :

Example 6 with DynamicCodeLoadingException

use of org.apache.flink.util.DynamicCodeLoadingException in project flink by apache.

the class CheckpointStorageLoader method fromConfig.

/**
 * Loads the checkpoint storage from the configuration, from the parameter
 * 'state.checkpoint-storage', as defined in {@link CheckpointingOptions#CHECKPOINT_STORAGE}.
 *
 * <p>The implementation can be specified either via their shortcut name, or via the class name
 * of a {@link CheckpointStorageFactory}. If a CheckpointStorageFactory class name is specified,
 * the factory is instantiated (via its zero-argument constructor) and its {@link
 * CheckpointStorageFactory#createFromConfig(ReadableConfig, ClassLoader)} method is called.
 *
 * <p>Recognized shortcut names are '{@value #JOB_MANAGER_STORAGE_NAME}', and '{@value
 * #FILE_SYSTEM_STORAGE_NAME}'.
 *
 * @param config The configuration to load the checkpoint storage from
 * @param classLoader The class loader that should be used to load the checkpoint storage
 * @param logger Optionally, a logger to log actions to (may be null)
 * @return The instantiated checkpoint storage.
 * @throws DynamicCodeLoadingException Thrown if a checkpoint storage factory is configured and
 *     the factory class was not found or the factory could not be instantiated
 * @throws IllegalConfigurationException May be thrown by the CheckpointStorageFactory when
 *     creating / configuring the checkpoint storage in the factory
 */
public static Optional<CheckpointStorage> fromConfig(ReadableConfig config, ClassLoader classLoader, @Nullable Logger logger) throws IllegalStateException, DynamicCodeLoadingException {
    Preconditions.checkNotNull(config, "config");
    Preconditions.checkNotNull(classLoader, "classLoader");
    final String storageName = config.get(CheckpointingOptions.CHECKPOINT_STORAGE);
    if (storageName == null) {
        if (logger != null) {
            logger.debug("The configuration {} has not be set in the current" + " sessions flink-conf.yaml. Falling back to a default CheckpointStorage" + " type. Users are strongly encouraged explicitly set this configuration" + " so they understand how their applications are checkpointing" + " snapshots for fault-tolerance.", CheckpointingOptions.CHECKPOINT_STORAGE.key());
        }
        return Optional.empty();
    }
    switch(storageName.toLowerCase()) {
        case JOB_MANAGER_STORAGE_NAME:
            return Optional.of(createJobManagerCheckpointStorage(config, classLoader, logger));
        case FILE_SYSTEM_STORAGE_NAME:
            return Optional.of(createFileSystemCheckpointStorage(config, classLoader, logger));
        default:
            if (logger != null) {
                logger.info("Loading state backend via factory '{}'", storageName);
            }
            CheckpointStorageFactory<?> factory;
            try {
                @SuppressWarnings("rawtypes") Class<? extends CheckpointStorageFactory> clazz = Class.forName(storageName, false, classLoader).asSubclass(CheckpointStorageFactory.class);
                factory = clazz.newInstance();
            } catch (ClassNotFoundException e) {
                throw new DynamicCodeLoadingException("Cannot find configured state backend factory class: " + storageName, e);
            } catch (ClassCastException | InstantiationException | IllegalAccessException e) {
                throw new DynamicCodeLoadingException("The class configured under '" + CheckpointingOptions.CHECKPOINT_STORAGE.key() + "' is not a valid checkpoint storage factory (" + storageName + ')', e);
            }
            return Optional.of(factory.createFromConfig(config, classLoader));
    }
}
Also used : DynamicCodeLoadingException(org.apache.flink.util.DynamicCodeLoadingException)

Example 7 with DynamicCodeLoadingException

use of org.apache.flink.util.DynamicCodeLoadingException in project flink by apache.

the class StateBackendLoadingTest method testLoadingFails.

// ------------------------------------------------------------------------
// Failures
// ------------------------------------------------------------------------
/**
 * This test makes sure that failures properly manifest when the state backend could not be
 * loaded.
 */
@Test
public void testLoadingFails() throws Exception {
    final Configuration config = new Configuration();
    // try a value that is neither recognized as a name, nor corresponds to a class
    config.setString(backendKey, "does.not.exist");
    try {
        StateBackendLoader.fromApplicationOrConfigOrDefault(null, TernaryBoolean.UNDEFINED, config, cl, null);
        fail("should fail with an exception");
    } catch (DynamicCodeLoadingException ignored) {
    // expected
    }
    // try a class that is not a factory
    config.setString(backendKey, java.io.File.class.getName());
    try {
        StateBackendLoader.fromApplicationOrConfigOrDefault(null, TernaryBoolean.UNDEFINED, config, cl, null);
        fail("should fail with an exception");
    } catch (DynamicCodeLoadingException ignored) {
    // expected
    }
    // a factory that fails
    config.setString(backendKey, FailingFactory.class.getName());
    try {
        StateBackendLoader.fromApplicationOrConfigOrDefault(null, TernaryBoolean.UNDEFINED, config, cl, null);
        fail("should fail with an exception");
    } catch (IOException ignored) {
    // expected
    }
}
Also used : DynamicCodeLoadingException(org.apache.flink.util.DynamicCodeLoadingException) Configuration(org.apache.flink.configuration.Configuration) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with DynamicCodeLoadingException

use of org.apache.flink.util.DynamicCodeLoadingException in project flink by apache.

the class CheckpointStorageLoaderTest method testLoadingFails.

@Test
public void testLoadingFails() throws Exception {
    final Configuration config = new Configuration();
    config.set(CheckpointingOptions.CHECKPOINT_STORAGE, "does.not.exist");
    try {
        CheckpointStorageLoader.load(null, null, new ModernStateBackend(), config, cl, log);
        Assert.fail("should fail with exception");
    } catch (DynamicCodeLoadingException e) {
    // expected
    }
    // try a class that is not a factory
    config.set(CheckpointingOptions.CHECKPOINT_STORAGE, java.io.File.class.getName());
    try {
        CheckpointStorageLoader.load(null, null, new ModernStateBackend(), config, cl, log);
        Assert.fail("should fail with exception");
    } catch (DynamicCodeLoadingException e) {
    // expected
    }
    // try a factory that fails
    config.set(CheckpointingOptions.CHECKPOINT_STORAGE, FailingFactory.class.getName());
    try {
        CheckpointStorageLoader.load(null, null, new ModernStateBackend(), config, cl, log);
        Assert.fail("should fail with exception");
    } catch (IllegalConfigurationException e) {
    // expected
    }
}
Also used : DynamicCodeLoadingException(org.apache.flink.util.DynamicCodeLoadingException) Configuration(org.apache.flink.configuration.Configuration) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) Test(org.junit.Test)

Aggregations

DynamicCodeLoadingException (org.apache.flink.util.DynamicCodeLoadingException)8 IOException (java.io.IOException)3 Configuration (org.apache.flink.configuration.Configuration)2 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)2 StateBackend (org.apache.flink.runtime.state.StateBackend)2 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 JobID (org.apache.flink.api.common.JobID)1 JobException (org.apache.flink.runtime.JobException)1 CheckpointIDCounter (org.apache.flink.runtime.checkpoint.CheckpointIDCounter)1 CheckpointStatsTracker (org.apache.flink.runtime.checkpoint.CheckpointStatsTracker)1 CompletedCheckpointStore (org.apache.flink.runtime.checkpoint.CompletedCheckpointStore)1 JobExecutionException (org.apache.flink.runtime.client.JobExecutionException)1 JobSubmissionException (org.apache.flink.runtime.client.JobSubmissionException)1 Environment (org.apache.flink.runtime.execution.Environment)1 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)1 JobSnapshottingSettings (org.apache.flink.runtime.jobgraph.tasks.JobSnapshottingSettings)1 AbstractStateBackend (org.apache.flink.runtime.state.AbstractStateBackend)1 DelegatingStateBackend (org.apache.flink.runtime.state.delegate.DelegatingStateBackend)1