Search in sources :

Example 1 with CustomCommandLine

use of org.apache.flink.client.cli.CustomCommandLine in project flink by apache.

the class CliFrontend method retrieveClient.

/**
	 * Updates the associated configuration with the given command line options
	 *
	 * @param options Command line options
	 */
protected ClusterClient retrieveClient(CommandLineOptions options) {
    CustomCommandLine customCLI = getActiveCustomCommandLine(options.getCommandLine());
    try {
        ClusterClient client = customCLI.retrieveCluster(options.getCommandLine(), config);
        logAndSysout("Using address " + client.getJobManagerAddress() + " to connect to JobManager.");
        return client;
    } catch (Exception e) {
        LOG.error("Couldn't retrieve {} cluster.", customCLI.getId(), e);
        throw new IllegalConfigurationException("Couldn't retrieve client for cluster", e);
    }
}
Also used : CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) ClusterClient(org.apache.flink.client.program.ClusterClient) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ProgramMissingJobException(org.apache.flink.client.program.ProgramMissingJobException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) CliArgsException(org.apache.flink.client.cli.CliArgsException) IOException(java.io.IOException)

Example 2 with CustomCommandLine

use of org.apache.flink.client.cli.CustomCommandLine in project flink by apache.

the class LocalContextUtils method buildDefaultContext.

public static DefaultContext buildDefaultContext(CliOptions options) {
    final List<URL> jars;
    if (options.getJars() != null) {
        jars = options.getJars();
    } else {
        jars = Collections.emptyList();
    }
    final List<URL> libDirs;
    if (options.getLibraryDirs() != null) {
        libDirs = options.getLibraryDirs();
    } else {
        libDirs = Collections.emptyList();
    }
    // 1. find the configuration directory
    String flinkConfigDir = CliFrontend.getConfigurationDirectoryFromEnv();
    // 2. load the global configuration
    Configuration configuration = GlobalConfiguration.loadConfiguration(flinkConfigDir);
    // 3. load the custom command lines
    List<CustomCommandLine> commandLines = CliFrontend.loadCustomCommandLines(configuration, flinkConfigDir);
    configuration.addAll(options.getPythonConfiguration());
    final List<URL> dependencies = discoverDependencies(jars, libDirs);
    return new DefaultContext(dependencies, configuration, commandLines);
}
Also used : CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) URL(java.net.URL)

Example 3 with CustomCommandLine

use of org.apache.flink.client.cli.CustomCommandLine in project flink by apache.

the class CliFrontend method loadCustomCommandLine.

/**
	 * Loads a class from the classpath that implements the CustomCommandLine interface.
	 * @param className The fully-qualified class name to load.
	 * @param params The constructor parameters
	 */
private static void loadCustomCommandLine(String className, Object... params) {
    try {
        Class<? extends CustomCommandLine> customCliClass = Class.forName(className).asSubclass(CustomCommandLine.class);
        // construct class types from the parameters
        Class<?>[] types = new Class<?>[params.length];
        for (int i = 0; i < params.length; i++) {
            Preconditions.checkNotNull(params[i], "Parameters for custom command-lines may not be null.");
            types[i] = params[i].getClass();
        }
        Constructor<? extends CustomCommandLine> constructor = customCliClass.getConstructor(types);
        final CustomCommandLine cli = constructor.newInstance(params);
        customCommandLine.add(cli);
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
        LOG.warn("Unable to locate custom CLI class {}. " + "Flink is not compiled with support for this class.", className, e);
    }
}
Also used : CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) CancelJobWithSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.CancelJobWithSavepoint) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with CustomCommandLine

use of org.apache.flink.client.cli.CustomCommandLine in project flink by apache.

the class DefaultContext method collectCommandLineOptions.

private Options collectCommandLineOptions(List<CustomCommandLine> commandLines) {
    final Options customOptions = new Options();
    for (CustomCommandLine customCommandLine : commandLines) {
        customCommandLine.addGeneralOptions(customOptions);
        customCommandLine.addRunOptions(customOptions);
    }
    return CliFrontendParser.mergeOptions(CliFrontendParser.getRunCommandOptions(), customOptions);
}
Also used : ProgramOptions(org.apache.flink.client.cli.ProgramOptions) Options(org.apache.commons.cli.Options) CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine)

Example 5 with CustomCommandLine

use of org.apache.flink.client.cli.CustomCommandLine in project flink by apache.

the class DefaultContext method createExecutionConfig.

private static Configuration createExecutionConfig(CommandLine commandLine, Options commandLineOptions, List<CustomCommandLine> availableCommandLines, List<URL> dependencies) throws FlinkException {
    LOG.debug("Available commandline options: {}", commandLineOptions);
    List<String> options = Stream.of(commandLine.getOptions()).map(o -> o.getOpt() + "=" + o.getValue()).collect(Collectors.toList());
    LOG.debug("Instantiated commandline args: {}, options: {}", commandLine.getArgList(), options);
    final CustomCommandLine activeCommandLine = findActiveCommandLine(availableCommandLines, commandLine);
    LOG.debug("Available commandlines: {}, active commandline: {}", availableCommandLines, activeCommandLine);
    Configuration executionConfig = activeCommandLine.toConfiguration(commandLine);
    try {
        final ProgramOptions programOptions = ProgramOptions.create(commandLine);
        final ExecutionConfigAccessor executionConfigAccessor = ExecutionConfigAccessor.fromProgramOptions(programOptions, dependencies);
        executionConfigAccessor.applyToConfiguration(executionConfig);
    } catch (CliArgsException e) {
        throw new SqlExecutionException("Invalid deployment run options.", e);
    }
    LOG.info("Executor config: {}", executionConfig);
    return executionConfig;
}
Also used : Executor(org.apache.flink.table.client.gateway.Executor) FlinkException(org.apache.flink.util.FlinkException) CliFrontendParser(org.apache.flink.client.cli.CliFrontendParser) Logger(org.slf4j.Logger) CliArgsException(org.apache.flink.client.cli.CliArgsException) ProgramOptions(org.apache.flink.client.cli.ProgramOptions) URL(java.net.URL) CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) ExecutionConfigAccessor(org.apache.flink.client.cli.ExecutionConfigAccessor) Configuration(org.apache.flink.configuration.Configuration) Options(org.apache.commons.cli.Options) LoggerFactory(org.slf4j.LoggerFactory) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) FileSystem(org.apache.flink.core.fs.FileSystem) PluginUtils(org.apache.flink.core.plugin.PluginUtils) CommandLine(org.apache.commons.cli.CommandLine) CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Configuration(org.apache.flink.configuration.Configuration) ExecutionConfigAccessor(org.apache.flink.client.cli.ExecutionConfigAccessor) CliArgsException(org.apache.flink.client.cli.CliArgsException) ProgramOptions(org.apache.flink.client.cli.ProgramOptions)

Aggregations

CustomCommandLine (org.apache.flink.client.cli.CustomCommandLine)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 CommandLine (org.apache.commons.cli.CommandLine)2 Options (org.apache.commons.cli.Options)2 CliArgsException (org.apache.flink.client.cli.CliArgsException)2 ProgramOptions (org.apache.flink.client.cli.ProgramOptions)2 Configuration (org.apache.flink.configuration.Configuration)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 CliFrontend (org.apache.flink.client.cli.CliFrontend)1 CliFrontendParser (org.apache.flink.client.cli.CliFrontendParser)1 ExecutionConfigAccessor (org.apache.flink.client.cli.ExecutionConfigAccessor)1 GenericCLI (org.apache.flink.client.cli.GenericCLI)1 ClusterClient (org.apache.flink.client.program.ClusterClient)1 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)1