Search in sources :

Example 21 with PackagedProgram

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

use of org.apache.flink.client.program.PackagedProgram 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)

Example 23 with PackagedProgram

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

the class CliFrontendPackageProgramTest method testVariantWithExplicitJarAndArgumentsOption.

@Test
public void testVariantWithExplicitJarAndArgumentsOption() {
    try {
        String[] arguments = { "--classpath", "file:///tmp/foo", "--classpath", "file:///tmp/bar", "-j", getTestJarPath(), "-a", "--debug", "true", "arg1", "arg2" };
        URL[] classpath = new URL[] { new URL("file:///tmp/foo"), new URL("file:///tmp/bar") };
        String[] reducedArguments = new String[] { "--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)

Example 24 with PackagedProgram

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

the class PythonProgramOptionsITCase method testConfigurePythonExecution.

/**
 * It requires setting a job jar to build a {@link PackagedProgram}, and the dummy job jar used
 * in this test case is available only after the packaging phase completed, so we make it as an
 * ITCase.
 */
@Test
public void testConfigurePythonExecution() throws Exception {
    final String[] args = { "--python", "xxx.py", "--pyModule", "xxx", "--pyFiles", "/absolute/a.py,relative/b.py,relative/c.py", "--pyRequirements", "d.txt#e_dir", "--pyExecutable", "/usr/bin/python", "--pyArchives", "g.zip,h.zip#data,h.zip#data2", "userarg1", "userarg2" };
    final File[] dummyJobJar = { null };
    Files.walkFileTree(FileSystems.getDefault().getPath(System.getProperty("user.dir") + "/artifacts"), new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            FileVisitResult result = super.visitFile(file, attrs);
            if (file.getFileName().toString().startsWith("dummy")) {
                dummyJobJar[0] = file.toFile();
            }
            return result;
        }
    });
    PackagedProgram packagedProgram = PackagedProgram.newBuilder().setArguments(args).setJarFile(dummyJobJar[0]).build();
    Configuration configuration = new Configuration();
    ProgramOptionsUtils.configurePythonExecution(configuration, packagedProgram);
    assertEquals("/absolute/a.py,relative/b.py,relative/c.py", configuration.get(PythonOptions.PYTHON_FILES));
    assertEquals("d.txt#e_dir", configuration.get(PYTHON_REQUIREMENTS));
    assertEquals("g.zip,h.zip#data,h.zip#data2", configuration.get(PythonOptions.PYTHON_ARCHIVES));
    assertEquals("/usr/bin/python", configuration.get(PYTHON_EXECUTABLE));
    assertArrayEquals(new String[] { "--python", "xxx.py", "--pyModule", "xxx", "userarg1", "userarg2" }, packagedProgram.getArguments());
}
Also used : Path(java.nio.file.Path) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Configuration(org.apache.flink.configuration.Configuration) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 25 with PackagedProgram

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

the class JarRunHandler method handleRequest.

@Override
@VisibleForTesting
public CompletableFuture<JarRunResponseBody> handleRequest(@Nonnull final HandlerRequest<JarRunRequestBody> request, @Nonnull final DispatcherGateway gateway) throws RestHandlerException {
    final Configuration effectiveConfiguration = new Configuration(configuration);
    effectiveConfiguration.set(DeploymentOptions.ATTACHED, false);
    effectiveConfiguration.set(DeploymentOptions.TARGET, EmbeddedExecutor.NAME);
    final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);
    context.applyToConfiguration(effectiveConfiguration);
    SavepointRestoreSettings.toConfiguration(getSavepointRestoreSettings(request), effectiveConfiguration);
    final PackagedProgram program = context.toPackagedProgram(effectiveConfiguration);
    return CompletableFuture.supplyAsync(() -> applicationRunner.run(gateway, program, effectiveConfiguration), executor).handle((jobIds, throwable) -> {
        program.close();
        if (throwable != null) {
            throw new CompletionException(new RestHandlerException("Could not execute application.", HttpResponseStatus.BAD_REQUEST, throwable));
        } else if (jobIds.isEmpty()) {
            throw new CompletionException(new RestHandlerException("No jobs included in application.", HttpResponseStatus.BAD_REQUEST));
        }
        return new JarRunResponseBody(jobIds.get(0));
    });
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) Configuration(org.apache.flink.configuration.Configuration) JarHandlerContext(org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils.JarHandlerContext) CompletionException(java.util.concurrent.CompletionException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

PackagedProgram (org.apache.flink.client.program.PackagedProgram)42 Test (org.junit.Test)25 File (java.io.File)20 Configuration (org.apache.flink.configuration.Configuration)19 URL (java.net.URL)13 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)12 Path (org.apache.flink.core.fs.Path)12 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 CommandLine (org.apache.commons.cli.CommandLine)6 RunOptions (org.apache.flink.client.cli.RunOptions)5 CompilerException (org.apache.flink.optimizer.CompilerException)5 FlinkException (org.apache.flink.util.FlinkException)5 Pipeline (org.apache.flink.api.dag.Pipeline)4 DataStatistics (org.apache.flink.optimizer.DataStatistics)4 Optimizer (org.apache.flink.optimizer.Optimizer)4 DefaultCostEstimator (org.apache.flink.optimizer.costs.DefaultCostEstimator)4 JobID (org.apache.flink.api.common.JobID)3 ApplicationConfiguration (org.apache.flink.client.deployment.application.ApplicationConfiguration)3 MiniClusterResourceConfiguration (org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration)3