Search in sources :

Example 1 with StandaloneClusterId

use of org.apache.flink.client.deployment.StandaloneClusterId 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 StandaloneClusterId

use of org.apache.flink.client.deployment.StandaloneClusterId in project flink by apache.

the class BigUserProgramJobSubmitITCase method bigDataInMap.

/**
 * Use a map function that references a 100MB byte array.
 */
@Test
public void bigDataInMap() throws Exception {
    // 16 MB
    final byte[] data = new byte[16 * 1024 * 1024];
    // use random data so that Java does not optimise it away
    rnd.nextBytes(data);
    data[1] = 0;
    data[3] = 0;
    data[5] = 0;
    CollectingSink resultSink = new CollectingSink();
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    DataStream<Integer> src = env.fromElements(1, 3, 5);
    src.map(new MapFunction<Integer, String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String map(Integer value) throws Exception {
            return "x " + value + " " + data[value];
        }
    }).addSink(resultSink);
    JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph());
    final RestClusterClient<StandaloneClusterId> restClusterClient = new RestClusterClient<>(MINI_CLUSTER_RESOURCE.getClientConfiguration(), StandaloneClusterId.getInstance());
    try {
        submitJobAndWaitForResult(restClusterClient, jobGraph, getClass().getClassLoader());
        List<String> expected = Arrays.asList("x 1 0", "x 3 0", "x 5 0");
        List<String> result = CollectingSink.result;
        Collections.sort(expected);
        Collections.sort(result);
        assertEquals(expected, result);
    } finally {
        restClusterClient.close();
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MapFunction(org.apache.flink.api.common.functions.MapFunction) RestClusterClient(org.apache.flink.client.program.rest.RestClusterClient) StandaloneClusterId(org.apache.flink.client.deployment.StandaloneClusterId) Test(org.junit.Test)

Aggregations

StandaloneClusterId (org.apache.flink.client.deployment.StandaloneClusterId)2 Test (org.junit.Test)2 URL (java.net.URL)1 CommandLine (org.apache.commons.cli.CommandLine)1 MapFunction (org.apache.flink.api.common.functions.MapFunction)1 DefaultCLI (org.apache.flink.client.cli.DefaultCLI)1 ClusterClientServiceLoader (org.apache.flink.client.deployment.ClusterClientServiceLoader)1 DefaultClusterClientServiceLoader (org.apache.flink.client.deployment.DefaultClusterClientServiceLoader)1 RestClusterClient (org.apache.flink.client.program.rest.RestClusterClient)1 Configuration (org.apache.flink.configuration.Configuration)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1