Search in sources :

Example 1 with ClusterClient

use of org.apache.flink.client.program.ClusterClient in project flink by apache.

the class JobRetrievalITCase method testNonExistingJobRetrieval.

@Test
public void testNonExistingJobRetrieval() throws Exception {
    final JobID jobID = new JobID();
    ClusterClient client = new StandaloneClusterClient(cluster.configuration());
    try {
        client.retrieveJob(jobID);
        fail();
    } catch (JobRetrievalException e) {
    // this is what we want
    }
}
Also used : StandaloneClusterClient(org.apache.flink.client.program.StandaloneClusterClient) ClusterClient(org.apache.flink.client.program.ClusterClient) JobRetrievalException(org.apache.flink.runtime.client.JobRetrievalException) StandaloneClusterClient(org.apache.flink.client.program.StandaloneClusterClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 2 with ClusterClient

use of org.apache.flink.client.program.ClusterClient 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 3 with ClusterClient

use of org.apache.flink.client.program.ClusterClient in project flink by apache.

the class CliFrontendAddressConfigurationTest method testManualOptionsOverridesConfig.

@Test
public void testManualOptionsOverridesConfig() {
    try {
        CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
        RunOptions options = CliFrontendParser.parseRunCommand(new String[] { "-m", "203.0.113.22:7788" });
        ClusterClient client = frontend.retrieveClient(options);
        Configuration config = client.getFlinkConfiguration();
        InetSocketAddress expectedAddress = new InetSocketAddress("203.0.113.22", 7788);
        checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ClusterClient(org.apache.flink.client.program.ClusterClient) Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) RunOptions(org.apache.flink.client.cli.RunOptions) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) Test(org.junit.Test)

Example 4 with ClusterClient

use of org.apache.flink.client.program.ClusterClient in project flink by apache.

the class AvroExternalJarProgramITCase method testExternalProgram.

@Test
public void testExternalProgram() {
    LocalFlinkMiniCluster testMiniCluster = null;
    try {
        Configuration config = new Configuration();
        config.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, 4);
        testMiniCluster = new LocalFlinkMiniCluster(config, false);
        testMiniCluster.start();
        String jarFile = JAR_FILE;
        String testData = getClass().getResource(TEST_DATA_FILE).toString();
        PackagedProgram program = new PackagedProgram(new File(jarFile), new String[] { testData });
        config.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, "localhost");
        config.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, testMiniCluster.getLeaderRPCPort());
        ClusterClient client = new StandaloneClusterClient(config);
        client.setPrintStatusDuringExecution(false);
        client.run(program, 4);
    } catch (Throwable t) {
        System.err.println(t.getMessage());
        t.printStackTrace();
        Assert.fail("Error during the packaged program execution: " + t.getMessage());
    } finally {
        if (testMiniCluster != null) {
            try {
                testMiniCluster.stop();
            } catch (Throwable t) {
            // ignore
            }
        }
    }
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) ClusterClient(org.apache.flink.client.program.ClusterClient) StandaloneClusterClient(org.apache.flink.client.program.StandaloneClusterClient) Configuration(org.apache.flink.configuration.Configuration) StandaloneClusterClient(org.apache.flink.client.program.StandaloneClusterClient) File(java.io.File) LocalFlinkMiniCluster(org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster) Test(org.junit.Test)

Example 5 with ClusterClient

use of org.apache.flink.client.program.ClusterClient in project flink by apache.

the class FlinkClient method submitTopologyWithOpts.

/**
	 * Parameter {@code uploadedJarLocation} is actually used to point to the local jar, because Flink does not support
	 * uploading a jar file before hand. Jar files are always uploaded directly when a program is submitted.
	 */
public void submitTopologyWithOpts(final String name, final String uploadedJarLocation, final FlinkTopology topology) throws AlreadyAliveException, InvalidTopologyException {
    if (this.getTopologyJobId(name) != null) {
        throw new AlreadyAliveException();
    }
    final URI uploadedJarUri;
    final URL uploadedJarUrl;
    try {
        uploadedJarUri = new File(uploadedJarLocation).getAbsoluteFile().toURI();
        uploadedJarUrl = uploadedJarUri.toURL();
        JobWithJars.checkJarFile(uploadedJarUrl);
    } catch (final IOException e) {
        throw new RuntimeException("Problem with jar file " + uploadedJarLocation, e);
    }
    try {
        FlinkClient.addStormConfigToTopology(topology, conf);
    } catch (ClassNotFoundException e) {
        LOG.error("Could not register class for Kryo serialization.", e);
        throw new InvalidTopologyException("Could not register class for Kryo serialization.");
    }
    final StreamGraph streamGraph = topology.getExecutionEnvironment().getStreamGraph();
    streamGraph.setJobName(name);
    final JobGraph jobGraph = streamGraph.getJobGraph();
    jobGraph.addJar(new Path(uploadedJarUri));
    final Configuration configuration = jobGraph.getJobConfiguration();
    configuration.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, jobManagerHost);
    configuration.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, jobManagerPort);
    final ClusterClient client;
    try {
        client = new StandaloneClusterClient(configuration);
    } catch (final IOException e) {
        throw new RuntimeException("Could not establish a connection to the job manager", e);
    }
    try {
        ClassLoader classLoader = JobWithJars.buildUserCodeClassLoader(Collections.<URL>singletonList(uploadedJarUrl), Collections.<URL>emptyList(), this.getClass().getClassLoader());
        client.runDetached(jobGraph, classLoader);
    } catch (final ProgramInvocationException e) {
        throw new RuntimeException("Cannot execute job due to ProgramInvocationException", e);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) StandaloneClusterClient(org.apache.flink.client.program.StandaloneClusterClient) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StandaloneClusterClient(org.apache.flink.client.program.StandaloneClusterClient) ClusterClient(org.apache.flink.client.program.ClusterClient) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) File(java.io.File)

Aggregations

ClusterClient (org.apache.flink.client.program.ClusterClient)22 Configuration (org.apache.flink.configuration.Configuration)14 Test (org.junit.Test)14 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)10 IOException (java.io.IOException)7 JobID (org.apache.flink.api.common.JobID)7 Arrays (java.util.Arrays)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 ValueState (org.apache.flink.api.common.state.ValueState)6 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)6 StandaloneClusterClient (org.apache.flink.client.program.StandaloneClusterClient)6 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)6 List (java.util.List)5 ListState (org.apache.flink.api.common.state.ListState)5 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)5 DataStream (org.apache.flink.streaming.api.datastream.DataStream)5 Collector (org.apache.flink.util.Collector)5 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 Collection (java.util.Collection)4