Search in sources :

Example 6 with PackagedProgram

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

the class ClassLoaderITCase method testJobsWithCustomClassLoader.

@Test
public void testJobsWithCustomClassLoader() {
    try {
        int port = testCluster.getLeaderRPCPort();
        PackagedProgram inputSplitTestProg = new PackagedProgram(new File(INPUT_SPLITS_PROG_JAR_FILE), new String[] { INPUT_SPLITS_PROG_JAR_FILE, // classpath
        "", "localhost", String.valueOf(port), // parallelism
        "4" });
        inputSplitTestProg.invokeInteractiveModeForExecution();
        PackagedProgram streamingInputSplitTestProg = new PackagedProgram(new File(STREAMING_INPUT_SPLITS_PROG_JAR_FILE), new String[] { STREAMING_INPUT_SPLITS_PROG_JAR_FILE, "localhost", String.valueOf(port), // parallelism
        "4" });
        streamingInputSplitTestProg.invokeInteractiveModeForExecution();
        String classpath = new File(INPUT_SPLITS_PROG_JAR_FILE).toURI().toURL().toString();
        PackagedProgram inputSplitTestProg2 = new PackagedProgram(new File(INPUT_SPLITS_PROG_JAR_FILE), new String[] { "", // classpath
        classpath, "localhost", String.valueOf(port), // parallelism
        "4" });
        inputSplitTestProg2.invokeInteractiveModeForExecution();
        // regular streaming job
        PackagedProgram streamingProg = new PackagedProgram(new File(STREAMING_PROG_JAR_FILE), new String[] { STREAMING_PROG_JAR_FILE, "localhost", String.valueOf(port) });
        streamingProg.invokeInteractiveModeForExecution();
        // the test also ensures that user specific exceptions are serializable between JobManager <--> JobClient.
        try {
            PackagedProgram streamingCheckpointedProg = new PackagedProgram(new File(STREAMING_CHECKPOINTED_PROG_JAR_FILE), new String[] { STREAMING_CHECKPOINTED_PROG_JAR_FILE, "localhost", String.valueOf(port) });
            streamingCheckpointedProg.invokeInteractiveModeForExecution();
        } catch (Exception e) {
            // we can not access the SuccessException here when executing the tests with maven, because its not available in the jar.
            assertEquals("Program should terminate with a 'SuccessException'", "org.apache.flink.test.classloading.jar.CheckpointedStreamingProgram.SuccessException", e.getCause().getCause().getClass().getCanonicalName());
        }
        PackagedProgram kMeansProg = new PackagedProgram(new File(KMEANS_JAR_PATH), new String[] { KMEANS_JAR_PATH, "localhost", String.valueOf(port), // parallelism
        "4", KMeansData.DATAPOINTS, KMeansData.INITIAL_CENTERS, "25" });
        kMeansProg.invokeInteractiveModeForExecution();
        // test FLINK-3633
        final PackagedProgram userCodeTypeProg = new PackagedProgram(new File(USERCODETYPE_JAR_PATH), new String[] { USERCODETYPE_JAR_PATH, "localhost", String.valueOf(port) });
        userCodeTypeProg.invokeInteractiveModeForExecution();
        File checkpointDir = FOLDER.newFolder();
        File outputDir = FOLDER.newFolder();
        final PackagedProgram program = new PackagedProgram(new File(CHECKPOINTING_CUSTOM_KV_STATE_JAR_PATH), new String[] { CHECKPOINTING_CUSTOM_KV_STATE_JAR_PATH, "localhost", String.valueOf(port), checkpointDir.toURI().toString(), outputDir.toURI().toString() });
        program.invokeInteractiveModeForExecution();
    } catch (Exception e) {
        if (!(e.getCause().getCause() instanceof SuccessException)) {
            fail(e.getMessage());
        }
    }
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) SuccessException(org.apache.flink.test.util.SuccessException) File(java.io.File) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) SuccessException(org.apache.flink.test.util.SuccessException) Test(org.junit.Test)

Example 7 with PackagedProgram

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

the class AvroExternalJarProgramITCase method testExternalProgram.

@Test
public void testExternalProgram() throws Exception {
    String jarFile = JAR_FILE;
    try {
        JarUtils.checkJarFile(new File(jarFile).getAbsoluteFile().toURI().toURL());
    } catch (IOException e) {
        jarFile = "target/".concat(jarFile);
    }
    TestEnvironment.setAsContext(MINI_CLUSTER, PARALLELISM, Collections.singleton(new Path(jarFile)), Collections.emptyList());
    String testData = getClass().getResource(TEST_DATA_FILE).toString();
    PackagedProgram program = PackagedProgram.newBuilder().setJarFile(new File(jarFile)).setArguments(new String[] { testData }).build();
    program.invokeInteractiveModeForExecution();
}
Also used : Path(org.apache.flink.core.fs.Path) PackagedProgram(org.apache.flink.client.program.PackagedProgram) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 8 with PackagedProgram

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

the class StandaloneApplicationClusterEntryPoint method main.

public static void main(String[] args) {
    // startup checks and logging
    EnvironmentInformation.logEnvironmentInfo(LOG, StandaloneApplicationClusterEntryPoint.class.getSimpleName(), args);
    SignalHandler.register(LOG);
    JvmShutdownSafeguard.installAsShutdownHook(LOG);
    final StandaloneApplicationClusterConfiguration clusterConfiguration = ClusterEntrypointUtils.parseParametersOrExit(args, new StandaloneApplicationClusterConfigurationParserFactory(), StandaloneApplicationClusterEntryPoint.class);
    Configuration configuration = loadConfigurationFromClusterConfig(clusterConfiguration);
    PackagedProgram program = null;
    try {
        program = getPackagedProgram(clusterConfiguration, configuration);
    } catch (Exception e) {
        LOG.error("Could not create application program.", e);
        System.exit(1);
    }
    try {
        configureExecution(configuration, program);
    } catch (Exception e) {
        LOG.error("Could not apply application configuration.", e);
        System.exit(1);
    }
    StandaloneApplicationClusterEntryPoint entrypoint = new StandaloneApplicationClusterEntryPoint(configuration, program);
    ClusterEntrypoint.runClusterEntrypoint(entrypoint);
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) Configuration(org.apache.flink.configuration.Configuration) FlinkException(org.apache.flink.util.FlinkException)

Example 9 with PackagedProgram

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

the class CliFrontendPackageProgramTest method testValidVariantWithNoJarAndNoArgumentsOption.

@Test
public void testValidVariantWithNoJarAndNoArgumentsOption() throws Exception {
    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" };
    CommandLine commandLine = CliFrontendParser.parse(CliFrontendParser.RUN_OPTIONS, arguments, true);
    ProgramOptions programOptions = ProgramOptions.create(commandLine);
    assertEquals(getTestJarPath(), programOptions.getJarFilePath());
    assertArrayEquals(classpath, programOptions.getClasspaths().toArray());
    assertArrayEquals(reducedArguments, programOptions.getProgramArgs());
    PackagedProgram prog = frontend.buildProgram(programOptions);
    Assert.assertArrayEquals(reducedArguments, prog.getArguments());
    Assert.assertEquals(TEST_JAR_MAIN_CLASS, prog.getMainClassName());
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) CommandLine(org.apache.commons.cli.CommandLine) URL(java.net.URL) Test(org.junit.Test)

Example 10 with PackagedProgram

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

the class ApplicationDispatcherBootstrapTest method testClusterIsShutdownInAttachedModeWhenJobCancelled.

@Test
public void testClusterIsShutdownInAttachedModeWhenJobCancelled() throws Exception {
    final CompletableFuture<ApplicationStatus> clusterShutdown = new CompletableFuture<>();
    final TestingDispatcherGateway dispatcherGateway = canceledJobGatewayBuilder().setClusterShutdownFunction(status -> {
        clusterShutdown.complete(status);
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).build();
    final PackagedProgram program = getProgram(2);
    final Configuration configuration = getConfiguration();
    configuration.set(DeploymentOptions.ATTACHED, true);
    final ApplicationDispatcherBootstrap bootstrap = new ApplicationDispatcherBootstrap(program, Collections.emptyList(), configuration, dispatcherGateway, scheduledExecutor, e -> {
    });
    final CompletableFuture<Void> applicationFuture = bootstrap.getApplicationCompletionFuture();
    assertException(applicationFuture, UnsuccessfulExecutionException.class);
    assertEquals(clusterShutdown.get(), ApplicationStatus.CANCELED);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) FailingJob(org.apache.flink.client.testjar.FailingJob) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlinkException(org.apache.flink.util.FlinkException) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EnumSource(org.junit.jupiter.params.provider.EnumSource) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Supplier(java.util.function.Supplier) EmbeddedExecutor(org.apache.flink.client.deployment.application.executors.EmbeddedExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) MultiExecuteJob(org.apache.flink.client.testjar.MultiExecuteJob) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) HighAvailabilityMode(org.apache.flink.runtime.jobmanager.HighAvailabilityMode) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Configuration(org.apache.flink.configuration.Configuration) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) JobID(org.apache.flink.api.common.JobID) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) PackagedProgram(org.apache.flink.client.program.PackagedProgram) CompletableFuture(java.util.concurrent.CompletableFuture) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Configuration(org.apache.flink.configuration.Configuration) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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