Search in sources :

Example 1 with PortableRunner

use of org.apache.beam.runners.portability.PortableRunner in project beam by apache.

the class TestUniversalRunner method run.

@Override
public PipelineResult run(Pipeline pipeline) {
    Options testOptions = options.as(Options.class);
    if (testOptions.getLocalJobServicePortFile() != null) {
        String localServicePortFilePath = testOptions.getLocalJobServicePortFile();
        try {
            testOptions.setJobEndpoint("localhost:" + new String(Files.readAllBytes(Paths.get(localServicePortFilePath)), Charsets.UTF_8).trim());
        } catch (IOException e) {
            throw new RuntimeException(String.format("Error reading local job service port file %s", localServicePortFilePath), e);
        }
    }
    PortablePipelineOptions portableOptions = options.as(PortablePipelineOptions.class);
    portableOptions.setRunner(PortableRunner.class);
    PortableRunner runner = PortableRunner.fromOptions(portableOptions);
    PipelineResult result = runner.run(pipeline);
    assertThat("Pipeline did not succeed.", result.waitUntilFinish(), Matchers.is(PipelineResult.State.DONE));
    return result;
}
Also used : TestPipelineOptions(org.apache.beam.sdk.testing.TestPipelineOptions) PortablePipelineOptions(org.apache.beam.sdk.options.PortablePipelineOptions) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) PortablePipelineOptions(org.apache.beam.sdk.options.PortablePipelineOptions) PipelineResult(org.apache.beam.sdk.PipelineResult) IOException(java.io.IOException) PortableRunner(org.apache.beam.runners.portability.PortableRunner)

Example 2 with PortableRunner

use of org.apache.beam.runners.portability.PortableRunner in project beam by apache.

the class TestPortableRunner method run.

@Override
public PipelineResult run(Pipeline pipeline) {
    TestPortablePipelineOptions testPortablePipelineOptions = options.as(TestPortablePipelineOptions.class);
    String jobServerHostPort;
    JobServerDriver jobServerDriver;
    Class<JobServerDriver> jobServerDriverClass = testPortablePipelineOptions.getJobServerDriver();
    String[] parameters = testPortablePipelineOptions.getJobServerConfig();
    try {
        jobServerDriver = InstanceBuilder.ofType(jobServerDriverClass).fromFactoryMethod("fromParams").withArg(String[].class, parameters).build();
        jobServerHostPort = jobServerDriver.start();
    } catch (IOException e) {
        throw new RuntimeException("Failed to start job server", e);
    }
    try {
        PortablePipelineOptions portableOptions = options.as(PortablePipelineOptions.class);
        portableOptions.setRunner(PortableRunner.class);
        portableOptions.setJobEndpoint(jobServerHostPort);
        PortableRunner runner = PortableRunner.fromOptions(portableOptions);
        PipelineResult result = runner.run(pipeline);
        assertThat("Pipeline did not succeed.", result.waitUntilFinish(), Matchers.is(State.DONE));
        return result;
    } finally {
        jobServerDriver.stop();
    }
}
Also used : PortablePipelineOptions(org.apache.beam.sdk.options.PortablePipelineOptions) JobServerDriver(org.apache.beam.runners.jobsubmission.JobServerDriver) PipelineResult(org.apache.beam.sdk.PipelineResult) IOException(java.io.IOException) PortableRunner(org.apache.beam.runners.portability.PortableRunner)

Aggregations

IOException (java.io.IOException)2 PortableRunner (org.apache.beam.runners.portability.PortableRunner)2 PipelineResult (org.apache.beam.sdk.PipelineResult)2 PortablePipelineOptions (org.apache.beam.sdk.options.PortablePipelineOptions)2 JobServerDriver (org.apache.beam.runners.jobsubmission.JobServerDriver)1 PipelineOptions (org.apache.beam.sdk.options.PipelineOptions)1 TestPipelineOptions (org.apache.beam.sdk.testing.TestPipelineOptions)1