Search in sources :

Example 1 with PluginManager

use of org.apache.flink.core.plugin.PluginManager in project flink by apache.

the class ClusterEntrypoint method startCluster.

public void startCluster() throws ClusterEntrypointException {
    LOG.info("Starting {}.", getClass().getSimpleName());
    try {
        FlinkSecurityManager.setFromConfiguration(configuration);
        PluginManager pluginManager = PluginUtils.createPluginManagerFromRootFolder(configuration);
        configureFileSystems(configuration, pluginManager);
        SecurityContext securityContext = installSecurityContext(configuration);
        ClusterEntrypointUtils.configureUncaughtExceptionHandler(configuration);
        securityContext.runSecured((Callable<Void>) () -> {
            runCluster(configuration, pluginManager);
            return null;
        });
    } catch (Throwable t) {
        final Throwable strippedThrowable = ExceptionUtils.stripException(t, UndeclaredThrowableException.class);
        try {
            // clean up any partial state
            shutDownAsync(ApplicationStatus.FAILED, ShutdownBehaviour.GRACEFUL_SHUTDOWN, ExceptionUtils.stringifyException(strippedThrowable), false).get(INITIALIZATION_SHUTDOWN_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            strippedThrowable.addSuppressed(e);
        }
        throw new ClusterEntrypointException(String.format("Failed to initialize the cluster entrypoint %s.", getClass().getSimpleName()), strippedThrowable);
    }
}
Also used : PluginManager(org.apache.flink.core.plugin.PluginManager) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SecurityContext(org.apache.flink.runtime.security.contexts.SecurityContext)

Example 2 with PluginManager

use of org.apache.flink.core.plugin.PluginManager in project flink by apache.

the class TaskManagerRunner method runTaskManagerProcessSecurely.

public static void runTaskManagerProcessSecurely(Configuration configuration) {
    FlinkSecurityManager.setFromConfiguration(configuration);
    final PluginManager pluginManager = PluginUtils.createPluginManagerFromRootFolder(configuration);
    FileSystem.initialize(configuration, pluginManager);
    StateChangelogStorageLoader.initialize(pluginManager);
    int exitCode;
    Throwable throwable = null;
    ClusterEntrypointUtils.configureUncaughtExceptionHandler(configuration);
    try {
        SecurityUtils.install(new SecurityConfiguration(configuration));
        exitCode = SecurityUtils.getInstalledContext().runSecured(() -> runTaskManager(configuration, pluginManager));
    } catch (Throwable t) {
        throwable = ExceptionUtils.stripException(t, UndeclaredThrowableException.class);
        exitCode = FAILURE_EXIT_CODE;
    }
    if (throwable != null) {
        LOG.error("Terminating TaskManagerRunner with exit code {}.", exitCode, throwable);
    } else {
        LOG.info("Terminating TaskManagerRunner with exit code {}.", exitCode);
    }
    System.exit(exitCode);
}
Also used : PluginManager(org.apache.flink.core.plugin.PluginManager) SecurityConfiguration(org.apache.flink.runtime.security.SecurityConfiguration)

Example 3 with PluginManager

use of org.apache.flink.core.plugin.PluginManager in project flink by apache.

the class TaskManagerRunner method startTaskManagerRunnerServices.

private void startTaskManagerRunnerServices() throws Exception {
    synchronized (lock) {
        rpcSystem = RpcSystem.load(configuration);
        this.executor = Executors.newScheduledThreadPool(Hardware.getNumberCPUCores(), new ExecutorThreadFactory("taskmanager-future"));
        highAvailabilityServices = HighAvailabilityServicesUtils.createHighAvailabilityServices(configuration, executor, AddressResolution.NO_ADDRESS_RESOLUTION, rpcSystem, this);
        JMXService.startInstance(configuration.getString(JMXServerOptions.JMX_SERVER_PORT));
        rpcService = createRpcService(configuration, highAvailabilityServices, rpcSystem);
        this.resourceId = getTaskManagerResourceID(configuration, rpcService.getAddress(), rpcService.getPort());
        this.workingDirectory = ClusterEntrypointUtils.createTaskManagerWorkingDirectory(configuration, resourceId);
        LOG.info("Using working directory: {}", workingDirectory);
        HeartbeatServices heartbeatServices = HeartbeatServices.fromConfiguration(configuration);
        metricRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(configuration, rpcSystem.getMaximumMessageSizeInBytes(configuration)), ReporterSetup.fromConfiguration(configuration, pluginManager));
        final RpcService metricQueryServiceRpcService = MetricUtils.startRemoteMetricsRpcService(configuration, rpcService.getAddress(), configuration.getString(TaskManagerOptions.BIND_HOST), rpcSystem);
        metricRegistry.startQueryService(metricQueryServiceRpcService, resourceId.unwrap());
        blobCacheService = BlobUtils.createBlobCacheService(configuration, Reference.borrowed(workingDirectory.unwrap().getBlobStorageDirectory()), highAvailabilityServices.createBlobStore(), null);
        final ExternalResourceInfoProvider externalResourceInfoProvider = ExternalResourceUtils.createStaticExternalResourceInfoProviderFromConfig(configuration, pluginManager);
        taskExecutorService = taskExecutorServiceFactory.createTaskExecutor(this.configuration, this.resourceId.unwrap(), rpcService, highAvailabilityServices, heartbeatServices, metricRegistry, blobCacheService, false, externalResourceInfoProvider, workingDirectory.unwrap(), this);
        handleUnexpectedTaskExecutorServiceTermination();
        MemoryLogger.startIfConfigured(LOG, configuration, terminationFuture.thenAccept(ignored -> {
        }));
    }
}
Also used : ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) TaskExecutorBlobService(org.apache.flink.runtime.blob.TaskExecutorBlobService) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Hardware(org.apache.flink.runtime.util.Hardware) RpcSystemUtils(org.apache.flink.runtime.rpc.RpcSystemUtils) LoggerFactory(org.slf4j.LoggerFactory) ExternalResourceUtils(org.apache.flink.runtime.externalresource.ExternalResourceUtils) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) LeaderRetrievalUtils(org.apache.flink.runtime.util.LeaderRetrievalUtils) ReporterSetup(org.apache.flink.runtime.metrics.ReporterSetup) InetAddress(java.net.InetAddress) MemoryLogger(org.apache.flink.runtime.taskmanager.MemoryLogger) StateChangelogStorageLoader(org.apache.flink.runtime.state.changelog.StateChangelogStorageLoader) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) FunctionUtils(org.apache.flink.util.function.FunctionUtils) Duration(java.time.Duration) SecurityUtils(org.apache.flink.runtime.security.SecurityUtils) TaskManagerOptionsInternal(org.apache.flink.configuration.TaskManagerOptionsInternal) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) AkkaOptions(org.apache.flink.configuration.AkkaOptions) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) AbstractID(org.apache.flink.util.AbstractID) Collection(java.util.Collection) JvmShutdownSafeguard(org.apache.flink.runtime.util.JvmShutdownSafeguard) HighAvailabilityServicesUtils(org.apache.flink.runtime.highavailability.HighAvailabilityServicesUtils) MetricUtils(org.apache.flink.runtime.metrics.util.MetricUtils) GuardedBy(javax.annotation.concurrent.GuardedBy) SecurityConfiguration(org.apache.flink.runtime.security.SecurityConfiguration) EnvironmentInformation(org.apache.flink.runtime.util.EnvironmentInformation) StringUtils(org.apache.flink.util.StringUtils) Executors(java.util.concurrent.Executors) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) ExecutorUtils(org.apache.flink.util.ExecutorUtils) JMXService(org.apache.flink.management.jmx.JMXService) MetricGroup(org.apache.flink.metrics.MetricGroup) FileSystem(org.apache.flink.core.fs.FileSystem) PluginManager(org.apache.flink.core.plugin.PluginManager) ConfigurationParserUtils(org.apache.flink.runtime.util.ConfigurationParserUtils) ClusterEntrypointUtils(org.apache.flink.runtime.entrypoint.ClusterEntrypointUtils) Time(org.apache.flink.api.common.time.Time) TaskExecutorPartitionTrackerImpl(org.apache.flink.runtime.io.network.partition.TaskExecutorPartitionTrackerImpl) FlinkException(org.apache.flink.util.FlinkException) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) CompletableFuture(java.util.concurrent.CompletableFuture) ShutdownHookUtil(org.apache.flink.util.ShutdownHookUtil) ArrayList(java.util.ArrayList) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) RpcService(org.apache.flink.runtime.rpc.RpcService) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ExternalResourceInfoProvider(org.apache.flink.runtime.externalresource.ExternalResourceInfoProvider) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) FlinkSecurityManager(org.apache.flink.core.security.FlinkSecurityManager) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ExecutorService(java.util.concurrent.ExecutorService) TaskManagerExceptionUtils(org.apache.flink.util.TaskManagerExceptionUtils) Logger(org.slf4j.Logger) AutoCloseableAsync(org.apache.flink.util.AutoCloseableAsync) Configuration(org.apache.flink.configuration.Configuration) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) IOException(java.io.IOException) Reference(org.apache.flink.util.Reference) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) SignalHandler(org.apache.flink.runtime.util.SignalHandler) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) DeterminismEnvelope(org.apache.flink.runtime.entrypoint.DeterminismEnvelope) RpcSystem(org.apache.flink.runtime.rpc.RpcSystem) PluginUtils(org.apache.flink.core.plugin.PluginUtils) WorkingDirectory(org.apache.flink.runtime.entrypoint.WorkingDirectory) JMXServerOptions(org.apache.flink.configuration.JMXServerOptions) BlobCacheService(org.apache.flink.runtime.blob.BlobCacheService) AddressResolution(org.apache.flink.runtime.rpc.AddressResolution) BlobUtils(org.apache.flink.runtime.blob.BlobUtils) FlinkParseException(org.apache.flink.runtime.entrypoint.FlinkParseException) RpcService(org.apache.flink.runtime.rpc.RpcService) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) ExternalResourceInfoProvider(org.apache.flink.runtime.externalresource.ExternalResourceInfoProvider)

Example 4 with PluginManager

use of org.apache.flink.core.plugin.PluginManager in project flink by apache.

the class TaskExecutorProcessEntryPoint method main.

public static void main(String[] args) {
    try {
        final ParameterTool parameterTool = ParameterTool.fromArgs(args);
        Configuration cfg = parameterTool.getConfiguration();
        final PluginManager pluginManager = PluginUtils.createPluginManagerFromRootFolder(cfg);
        TaskExecutorResourceUtils.adjustForLocalExecution(cfg);
        TaskManagerRunner.runTaskManager(cfg, pluginManager);
    } catch (Throwable t) {
        LOG.error("Failed to run the TaskManager process", t);
        System.exit(1);
    }
}
Also used : ParameterTool(org.apache.flink.api.java.utils.ParameterTool) PluginManager(org.apache.flink.core.plugin.PluginManager) Configuration(org.apache.flink.configuration.Configuration)

Example 5 with PluginManager

use of org.apache.flink.core.plugin.PluginManager in project flink by apache.

the class ExternalResourceUtilsTest method testConstructExternalResourceDriversFromConfig.

@Test
public void testConstructExternalResourceDriversFromConfig() {
    final Configuration config = new Configuration();
    final String driverFactoryClassName = TestingExternalResourceDriverFactory.class.getName();
    final Map<Class<?>, Iterator<?>> plugins = new HashMap<>();
    plugins.put(ExternalResourceDriverFactory.class, IteratorUtils.singletonIterator(new TestingExternalResourceDriverFactory()));
    final PluginManager testingPluginManager = new TestingPluginManager(plugins);
    config.set(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST, Collections.singletonList(RESOURCE_NAME_1));
    config.setString(ExternalResourceOptions.getExternalResourceDriverFactoryConfigOptionForResource(RESOURCE_NAME_1), driverFactoryClassName);
    final Map<String, ExternalResourceDriver> externalResourceDrivers = ExternalResourceUtils.externalResourceDriversFromConfig(config, testingPluginManager);
    assertThat(externalResourceDrivers.size(), is(1));
    assertThat(externalResourceDrivers.get(RESOURCE_NAME_1), instanceOf(TestingExternalResourceDriver.class));
}
Also used : TestingPluginManager(org.apache.flink.core.plugin.TestingPluginManager) PluginManager(org.apache.flink.core.plugin.PluginManager) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) Iterator(java.util.Iterator) TestingPluginManager(org.apache.flink.core.plugin.TestingPluginManager) ExternalResourceDriver(org.apache.flink.api.common.externalresource.ExternalResourceDriver) Test(org.junit.Test)

Aggregations

PluginManager (org.apache.flink.core.plugin.PluginManager)12 Configuration (org.apache.flink.configuration.Configuration)8 Test (org.junit.Test)7 ExternalResourceDriver (org.apache.flink.api.common.externalresource.ExternalResourceDriver)4 TestingPluginManager (org.apache.flink.core.plugin.TestingPluginManager)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 Time (org.apache.flink.api.common.time.Time)2 HighAvailabilityServices (org.apache.flink.runtime.highavailability.HighAvailabilityServices)2 RpcService (org.apache.flink.runtime.rpc.RpcService)2 SecurityConfiguration (org.apache.flink.runtime.security.SecurityConfiguration)2 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1