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);
}
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations