Search in sources :

Example 1 with DefaultCLI

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

the class RestClusterClientTest method testRESTManualConfigurationOverride.

/**
 * Tests that command line options override the configuration settings.
 */
@Test
public void testRESTManualConfigurationOverride() throws Exception {
    final String configuredHostname = "localhost";
    final int configuredPort = 1234;
    final Configuration configuration = new Configuration();
    configuration.setString(JobManagerOptions.ADDRESS, configuredHostname);
    configuration.setInteger(JobManagerOptions.PORT, configuredPort);
    configuration.setString(RestOptions.ADDRESS, configuredHostname);
    configuration.setInteger(RestOptions.PORT, configuredPort);
    final DefaultCLI defaultCLI = new DefaultCLI();
    final String manualHostname = "123.123.123.123";
    final int manualPort = 4321;
    final String[] args = { "-m", manualHostname + ':' + manualPort };
    CommandLine commandLine = defaultCLI.parseCommandLineOptions(args, false);
    final ClusterClientServiceLoader serviceLoader = new DefaultClusterClientServiceLoader();
    final Configuration executorConfig = defaultCLI.toConfiguration(commandLine);
    final ClusterClientFactory<StandaloneClusterId> clusterFactory = serviceLoader.getClusterClientFactory(executorConfig);
    checkState(clusterFactory != null);
    final ClusterDescriptor<StandaloneClusterId> clusterDescriptor = clusterFactory.createClusterDescriptor(executorConfig);
    final RestClusterClient<?> clusterClient = (RestClusterClient<?>) clusterDescriptor.retrieve(clusterFactory.getClusterId(executorConfig)).getClusterClient();
    URL webMonitorBaseUrl = clusterClient.getWebMonitorBaseUrl().get();
    assertThat(webMonitorBaseUrl.getHost(), equalTo(manualHostname));
    assertThat(webMonitorBaseUrl.getPort(), equalTo(manualPort));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) DefaultClusterClientServiceLoader(org.apache.flink.client.deployment.DefaultClusterClientServiceLoader) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) StandaloneClusterId(org.apache.flink.client.deployment.StandaloneClusterId) URL(java.net.URL) CommandLine(org.apache.commons.cli.CommandLine) DefaultCLI(org.apache.flink.client.cli.DefaultCLI) ClusterClientServiceLoader(org.apache.flink.client.deployment.ClusterClientServiceLoader) DefaultClusterClientServiceLoader(org.apache.flink.client.deployment.DefaultClusterClientServiceLoader) Test(org.junit.Test)

Example 2 with DefaultCLI

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

the class SessionContextTest method createSessionContext.

// --------------------------------------------------------------------------------------------
private SessionContext createSessionContext() {
    Configuration flinkConfig = new Configuration();
    flinkConfig.set(OBJECT_REUSE, true);
    flinkConfig.set(MAX_PARALLELISM, 16);
    DefaultContext defaultContext = new DefaultContext(Collections.emptyList(), flinkConfig, Collections.singletonList(new DefaultCLI()));
    return SessionContext.create(defaultContext, "test-session");
}
Also used : Configuration(org.apache.flink.configuration.Configuration) DefaultCLI(org.apache.flink.client.cli.DefaultCLI)

Example 3 with DefaultCLI

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

the class DependencyTest method createLocalExecutor.

private LocalExecutor createLocalExecutor() throws Exception {
    // create executor with dependencies
    final URL dependency = Paths.get("target", TABLE_FACTORY_JAR_FILE).toUri().toURL();
    // create default context
    DefaultContext defaultContext = new DefaultContext(Collections.singletonList(dependency), new Configuration(), Collections.singletonList(new DefaultCLI()));
    LocalExecutor executor = new LocalExecutor(defaultContext);
    executor.openSession(SESSION_ID);
    for (String line : INIT_SQL) {
        executor.executeOperation(SESSION_ID, executor.parseStatement(SESSION_ID, line));
    }
    return executor;
}
Also used : Configuration(org.apache.flink.configuration.Configuration) DefaultCLI(org.apache.flink.client.cli.DefaultCLI) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) URL(java.net.URL)

Example 4 with DefaultCLI

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

the class CliClientITCase method runSqlStatements.

/**
 * Returns printed results for each ran SQL statements.
 *
 * @param statements the SQL statements to run
 * @return the printed results on SQL Client
 */
private List<Result> runSqlStatements(List<String> statements) throws IOException {
    final String sqlContent = String.join("", statements);
    DefaultContext defaultContext = new DefaultContext(Collections.emptyList(), new Configuration(MINI_CLUSTER_RESOURCE.getClientConfiguration()).set(ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR, ExecutionConfigOptions.LegacyCastBehaviour.DISABLED), Collections.singletonList(new DefaultCLI()));
    final Executor executor = new LocalExecutor(defaultContext);
    InputStream inputStream = new ByteArrayInputStream(sqlContent.getBytes());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
    String sessionId = executor.openSession("test-session");
    try (Terminal terminal = new DumbTerminal(inputStream, outputStream);
        CliClient client = new CliClient(() -> terminal, sessionId, executor, historyPath, HideSqlStatement.INSTANCE)) {
        client.executeInInteractiveMode();
        String output = new String(outputStream.toByteArray());
        return normalizeOutput(output);
    }
}
Also used : LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor) Executor(org.apache.flink.table.client.gateway.Executor) Configuration(org.apache.flink.configuration.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultCLI(org.apache.flink.client.cli.DefaultCLI) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) Terminal(org.jline.terminal.Terminal) DumbTerminal(org.jline.terminal.impl.DumbTerminal) DumbTerminal(org.jline.terminal.impl.DumbTerminal) LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor)

Example 5 with DefaultCLI

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

the class LocalExecutorITCase method createLocalExecutor.

private LocalExecutor createLocalExecutor(List<URL> dependencies, Configuration configuration) {
    configuration.addAll(clusterClient.getFlinkConfiguration());
    DefaultContext defaultContext = new DefaultContext(dependencies, configuration, Collections.singletonList(new DefaultCLI()));
    return new LocalExecutor(defaultContext);
}
Also used : DefaultCLI(org.apache.flink.client.cli.DefaultCLI) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext)

Aggregations

DefaultCLI (org.apache.flink.client.cli.DefaultCLI)5 Configuration (org.apache.flink.configuration.Configuration)4 DefaultContext (org.apache.flink.table.client.gateway.context.DefaultContext)3 URL (java.net.URL)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 CommandLine (org.apache.commons.cli.CommandLine)1 ClusterClientServiceLoader (org.apache.flink.client.deployment.ClusterClientServiceLoader)1 DefaultClusterClientServiceLoader (org.apache.flink.client.deployment.DefaultClusterClientServiceLoader)1 StandaloneClusterId (org.apache.flink.client.deployment.StandaloneClusterId)1 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)1 Executor (org.apache.flink.table.client.gateway.Executor)1 LocalExecutor (org.apache.flink.table.client.gateway.local.LocalExecutor)1 Terminal (org.jline.terminal.Terminal)1 DumbTerminal (org.jline.terminal.impl.DumbTerminal)1 Test (org.junit.Test)1