Search in sources :

Example 11 with RunOptions

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

the class CliFrontendYarnAddressConfigurationTest method testInvalidYarnPropertiesFile.

@Test(expected = IllegalConfigurationException.class)
public void testInvalidYarnPropertiesFile() throws Exception {
    File directoryPath = writeYarnPropertiesFile(invalidPropertiesFile);
    TestCLI frontend = new CustomYarnTestCLI(directoryPath.getAbsolutePath());
    RunOptions options = CliFrontendParser.parseRunCommand(new String[] {});
    frontend.retrieveClient(options);
    Configuration config = frontend.getConfiguration();
    checkJobManagerAddress(config, TEST_JOB_MANAGER_ADDRESS, TEST_JOB_MANAGER_PORT);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) File(java.io.File) RunOptions(org.apache.flink.client.cli.RunOptions) Test(org.junit.Test)

Example 12 with RunOptions

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

the class FlinkYarnSessionCliTest method testCorrectSettingOfMaxSlots.

@Test
public void testCorrectSettingOfMaxSlots() throws Exception {
    File confFile = tmp.newFile("flink-conf.yaml");
    File jarFile = tmp.newFile("test.jar");
    new CliFrontend(tmp.getRoot().getAbsolutePath());
    String[] params = new String[] { "-yn", "2", "-ys", "3", jarFile.getAbsolutePath() };
    RunOptions runOptions = CliFrontendParser.parseRunCommand(params);
    FlinkYarnSessionCli yarnCLI = new TestCLI("y", "yarn");
    AbstractYarnClusterDescriptor descriptor = yarnCLI.createDescriptor("", runOptions.getCommandLine());
    // each task manager has 3 slots but the parallelism is 7. Thus the slots should be increased.
    Assert.assertEquals(3, descriptor.getTaskManagerSlots());
    Assert.assertEquals(2, descriptor.getTaskManagerCount());
    Configuration config = new Configuration();
    CliFrontend.setJobManagerAddressInConfig(config, new InetSocketAddress("test", 9000));
    ClusterClient client = new TestingYarnClusterClient(descriptor, config);
    Assert.assertEquals(6, client.getMaxSlots());
}
Also used : ClusterClient(org.apache.flink.client.program.ClusterClient) Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) CliFrontend(org.apache.flink.client.CliFrontend) File(java.io.File) RunOptions(org.apache.flink.client.cli.RunOptions) FlinkYarnSessionCli(org.apache.flink.yarn.cli.FlinkYarnSessionCli) Test(org.junit.Test)

Example 13 with RunOptions

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

the class CliFrontend method run.

// --------------------------------------------------------------------------------------------
//  Execute Actions
// --------------------------------------------------------------------------------------------
/**
	 * Executions the run action.
	 * 
	 * @param args Command line arguments for the run action.
	 */
protected int run(String[] args) {
    LOG.info("Running 'run' command.");
    RunOptions options;
    try {
        options = CliFrontendParser.parseRunCommand(args);
    } catch (CliArgsException e) {
        return handleArgException(e);
    } catch (Throwable t) {
        return handleError(t);
    }
    // evaluate help flag
    if (options.isPrintHelp()) {
        CliFrontendParser.printHelpForRun();
        return 0;
    }
    if (options.getJarFilePath() == null) {
        return handleArgException(new CliArgsException("The program JAR file was not specified."));
    }
    PackagedProgram program;
    try {
        LOG.info("Building program from JAR file");
        program = buildProgram(options);
    } catch (FileNotFoundException e) {
        return handleArgException(e);
    } catch (Throwable t) {
        return handleError(t);
    }
    ClusterClient client = null;
    try {
        client = createClient(options, program);
        client.setPrintStatusDuringExecution(options.getStdoutLogging());
        client.setDetached(options.getDetachedMode());
        LOG.debug("Client slots is set to {}", client.getMaxSlots());
        LOG.debug(options.getSavepointRestoreSettings().toString());
        int userParallelism = options.getParallelism();
        LOG.debug("User parallelism is set to {}", userParallelism);
        if (client.getMaxSlots() != -1 && userParallelism == -1) {
            logAndSysout("Using the parallelism provided by the remote cluster (" + client.getMaxSlots() + "). " + "To use another parallelism, set it at the ./bin/flink client.");
            userParallelism = client.getMaxSlots();
        }
        return executeProgram(program, client, userParallelism);
    } catch (Throwable t) {
        return handleError(t);
    } finally {
        if (client != null) {
            client.shutdown();
        }
        if (program != null) {
            program.deleteExtractedLibraries();
        }
    }
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) ClusterClient(org.apache.flink.client.program.ClusterClient) FileNotFoundException(java.io.FileNotFoundException) CliArgsException(org.apache.flink.client.cli.CliArgsException) RunOptions(org.apache.flink.client.cli.RunOptions) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) CancelJobWithSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.CancelJobWithSavepoint)

Example 14 with RunOptions

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

the class CliFrontendAddressConfigurationTest method testValidConfig.

@Test
public void testValidConfig() {
    try {
        CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
        RunOptions options = CliFrontendParser.parseRunCommand(new String[] {});
        ClusterClient clusterClient = frontend.retrieveClient(options);
        checkJobManagerAddress(clusterClient.getFlinkConfiguration(), CliFrontendTestUtils.TEST_JOB_MANAGER_ADDRESS, CliFrontendTestUtils.TEST_JOB_MANAGER_PORT);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ClusterClient(org.apache.flink.client.program.ClusterClient) RunOptions(org.apache.flink.client.cli.RunOptions) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) Test(org.junit.Test)

Example 15 with RunOptions

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

the class CliFrontendPackageProgramTest method testValidVariantWithNoJarAndNoArgumentsOption.

@Test
public void testValidVariantWithNoJarAndNoArgumentsOption() {
    try {
        String[] arguments = { "--classpath", "file:///tmp/foo", "--classpath", "file:///tmp/bar", getTestJarPath(), "--debug", "true", "arg1", "arg2" };
        URL[] classpath = new URL[] { new URL("file:///tmp/foo"), new URL("file:///tmp/bar") };
        String[] reducedArguments = { "--debug", "true", "arg1", "arg2" };
        RunOptions options = CliFrontendParser.parseRunCommand(arguments);
        assertEquals(getTestJarPath(), options.getJarFilePath());
        assertArrayEquals(classpath, options.getClasspaths().toArray());
        assertArrayEquals(reducedArguments, options.getProgramArgs());
        CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
        PackagedProgram prog = frontend.buildProgram(options);
        Assert.assertArrayEquals(reducedArguments, prog.getArguments());
        Assert.assertEquals(TEST_JAR_MAIN_CLASS, prog.getMainClassName());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) URL(java.net.URL) RunOptions(org.apache.flink.client.cli.RunOptions) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) FileNotFoundException(java.io.FileNotFoundException) CompilerException(org.apache.flink.optimizer.CompilerException) Test(org.junit.Test)

Aggregations

RunOptions (org.apache.flink.client.cli.RunOptions)23 Test (org.junit.Test)22 File (java.io.File)13 FileNotFoundException (java.io.FileNotFoundException)7 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)6 CompilerException (org.apache.flink.optimizer.CompilerException)6 URL (java.net.URL)5 PackagedProgram (org.apache.flink.client.program.PackagedProgram)5 Configuration (org.apache.flink.configuration.Configuration)5 ClusterClient (org.apache.flink.client.program.ClusterClient)4 InetSocketAddress (java.net.InetSocketAddress)3 CliFrontend (org.apache.flink.client.CliFrontend)3 FlinkYarnSessionCli (org.apache.flink.yarn.cli.FlinkYarnSessionCli)3 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)2 CliArgsException (org.apache.flink.client.cli.CliArgsException)1 DataStatistics (org.apache.flink.optimizer.DataStatistics)1 Optimizer (org.apache.flink.optimizer.Optimizer)1 DefaultCostEstimator (org.apache.flink.optimizer.costs.DefaultCostEstimator)1 CancelJobWithSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.CancelJobWithSavepoint)1 DisposeSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint)1