use of org.apache.beam.runners.jobsubmission.JobInvocation in project beam by apache.
the class SamzaJobInvoker method invokeWithExecutor.
@Override
protected JobInvocation invokeWithExecutor(RunnerApi.Pipeline pipeline, Struct options, @Nullable String retrievalToken, ListeningExecutorService executorService) {
LOG.trace("Parsing pipeline options");
final SamzaPortablePipelineOptions samzaOptions = PipelineOptionsTranslation.fromProto(options).as(SamzaPortablePipelineOptions.class);
final PortablePipelineRunner pipelineRunner;
if (Strings.isNullOrEmpty(samzaOptions.getOutputExecutablePath())) {
pipelineRunner = new SamzaPipelineRunner(samzaOptions);
} else {
/*
* To support --output_executable_path where bundles the input pipeline along with all
* artifacts, etc. required to run the pipeline into a jar that can be executed later.
*/
pipelineRunner = new PortablePipelineJarCreator(SamzaPipelineRunner.class);
}
final String invocationId = String.format("%s_%s", samzaOptions.getJobName(), UUID.randomUUID().toString());
final JobInfo jobInfo = JobInfo.create(invocationId, samzaOptions.getJobName(), retrievalToken, options);
return new JobInvocation(jobInfo, executorService, pipeline, pipelineRunner);
}
use of org.apache.beam.runners.jobsubmission.JobInvocation in project beam by apache.
the class ReadSourcePortableTest method testExecution.
@Test(timeout = 120_000)
public void testExecution() throws Exception {
PipelineOptions options = PipelineOptionsFactory.fromArgs("--experiments=use_deprecated_read").create();
options.setRunner(CrashingRunner.class);
options.as(FlinkPipelineOptions.class).setFlinkMaster("[local]");
options.as(FlinkPipelineOptions.class).setStreaming(isStreaming);
options.as(FlinkPipelineOptions.class).setParallelism(2);
options.as(PortablePipelineOptions.class).setDefaultEnvironmentType(Environments.ENVIRONMENT_EMBEDDED);
Pipeline p = Pipeline.create(options);
PCollection<Long> result = p.apply(Read.from(new Source(10))).apply(Window.into(FixedWindows.of(Duration.millis(1))));
PAssert.that(result).containsInAnyOrder(ImmutableList.of(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L));
SplittableParDo.convertReadBasedSplittableDoFnsToPrimitiveReads(p);
RunnerApi.Pipeline pipelineProto = PipelineTranslation.toProto(p);
List<RunnerApi.PTransform> readTransforms = pipelineProto.getComponents().getTransformsMap().values().stream().filter(transform -> transform.getSpec().getUrn().equals(PTransformTranslation.READ_TRANSFORM_URN)).collect(Collectors.toList());
assertThat(readTransforms, not(empty()));
// execute the pipeline
JobInvocation jobInvocation = FlinkJobInvoker.create(null).createJobInvocation("fakeId", "fakeRetrievalToken", flinkJobExecutor, pipelineProto, options.as(FlinkPipelineOptions.class), new FlinkPipelineRunner(options.as(FlinkPipelineOptions.class), null, Collections.emptyList()));
jobInvocation.start();
while (jobInvocation.getState() != JobState.Enum.DONE) {
assertThat(jobInvocation.getState(), not(JobState.Enum.FAILED));
Thread.sleep(100);
}
}
use of org.apache.beam.runners.jobsubmission.JobInvocation in project beam by apache.
the class FlinkSavepointTest method executePortable.
private JobID executePortable(Pipeline pipeline) throws Exception {
pipeline.getOptions().as(PortablePipelineOptions.class).setDefaultEnvironmentType(Environments.ENVIRONMENT_EMBEDDED);
pipeline.getOptions().as(FlinkPipelineOptions.class).setFlinkMaster(getFlinkMaster());
RunnerApi.Pipeline pipelineProto = PipelineTranslation.toProto(pipeline);
FlinkPipelineOptions pipelineOptions = pipeline.getOptions().as(FlinkPipelineOptions.class);
JobInvocation jobInvocation = FlinkJobInvoker.create(null).createJobInvocation("id", "none", flinkJobExecutor, pipelineProto, pipelineOptions, new FlinkPipelineRunner(pipelineOptions, null, Collections.emptyList()));
jobInvocation.start();
return waitForJobToBeReady(pipeline.getOptions().getJobName());
}
use of org.apache.beam.runners.jobsubmission.JobInvocation in project beam by apache.
the class PortableStateExecutionTest method testExecution.
@Test(timeout = 120_000)
public void testExecution() throws Exception {
PipelineOptions options = PipelineOptionsFactory.fromArgs("--experiments=beam_fn_api").create();
options.setRunner(CrashingRunner.class);
options.as(FlinkPipelineOptions.class).setFlinkMaster("[local]");
options.as(FlinkPipelineOptions.class).setStreaming(isStreaming);
options.as(FlinkPipelineOptions.class).setParallelism(2);
options.as(PortablePipelineOptions.class).setDefaultEnvironmentType(Environments.ENVIRONMENT_EMBEDDED);
Pipeline p = Pipeline.create(options);
PCollection<KV<String, String>> output = p.apply(Impulse.create()).apply(ParDo.of(new DoFn<byte[], KV<String, Integer>>() {
@ProcessElement
public void process(ProcessContext ctx) {
// Values == -1 will clear the state
ctx.output(KV.of("clearedState", 1));
ctx.output(KV.of("clearedState", CLEAR_STATE));
// values >= 1 will be added on top of each other
ctx.output(KV.of("bla1", 42));
ctx.output(KV.of("bla", 23));
ctx.output(KV.of("bla2", 64));
ctx.output(KV.of("bla", 1));
ctx.output(KV.of("bla", 1));
// values == -2 will write the current state to the output
ctx.output(KV.of("bla", WRITE_STATE));
ctx.output(KV.of("bla1", WRITE_STATE));
ctx.output(KV.of("bla2", WRITE_STATE));
ctx.output(KV.of("clearedState", WRITE_STATE));
}
})).apply("statefulDoFn", ParDo.of(new DoFn<KV<String, Integer>, KV<String, String>>() {
@StateId("valueState")
private final StateSpec<ValueState<Integer>> valueStateSpec = StateSpecs.value(VarIntCoder.of());
@StateId("valueState2")
private final StateSpec<ValueState<Integer>> valueStateSpec2 = StateSpecs.value(VarIntCoder.of());
@ProcessElement
public void process(ProcessContext ctx, @StateId("valueState") ValueState<Integer> valueState, @StateId("valueState2") ValueState<Integer> valueState2) {
performStateUpdates(ctx, valueState);
performStateUpdates(ctx, valueState2);
}
private void performStateUpdates(ProcessContext ctx, ValueState<Integer> valueState) {
Integer value = ctx.element().getValue();
if (value == null) {
throw new IllegalStateException();
}
switch(value) {
case CLEAR_STATE:
valueState.clear();
break;
case WRITE_STATE:
Integer read = valueState.read();
ctx.output(KV.of(ctx.element().getKey(), read == null ? "null" : read.toString()));
break;
default:
Integer currentState = valueState.read();
if (currentState == null) {
currentState = value;
} else {
currentState += value;
}
valueState.write(currentState);
}
}
}));
PAssert.that(output).containsInAnyOrder(KV.of("bla", "25"), KV.of("bla1", "42"), KV.of("bla2", "64"), KV.of("clearedState", "null"), KV.of("bla", "25"), KV.of("bla1", "42"), KV.of("bla2", "64"), KV.of("clearedState", "null"));
RunnerApi.Pipeline pipelineProto = PipelineTranslation.toProto(p);
JobInvocation jobInvocation = FlinkJobInvoker.create(null).createJobInvocation("id", "none", flinkJobExecutor, pipelineProto, options.as(FlinkPipelineOptions.class), new FlinkPipelineRunner(options.as(FlinkPipelineOptions.class), null, Collections.emptyList()));
jobInvocation.start();
while (jobInvocation.getState() != JobState.Enum.DONE) {
Thread.sleep(1000);
}
}
use of org.apache.beam.runners.jobsubmission.JobInvocation in project beam by apache.
the class PortableExecutionTest method testExecution.
@Test(timeout = 120_000)
public void testExecution() throws Exception {
PipelineOptions options = PipelineOptionsFactory.fromArgs("--experiments=beam_fn_api").create();
options.setRunner(CrashingRunner.class);
options.as(FlinkPipelineOptions.class).setFlinkMaster("[local]");
options.as(FlinkPipelineOptions.class).setStreaming(isStreaming);
options.as(FlinkPipelineOptions.class).setParallelism(2);
options.as(PortablePipelineOptions.class).setDefaultEnvironmentType(Environments.ENVIRONMENT_EMBEDDED);
Pipeline p = Pipeline.create(options);
PCollection<KV<String, Iterable<Long>>> result = p.apply("impulse", Impulse.create()).apply("create", ParDo.of(new DoFn<byte[], String>() {
@ProcessElement
public void process(ProcessContext ctxt) {
ctxt.output("zero");
ctxt.output("one");
ctxt.output("two");
}
})).apply("len", ParDo.of(new DoFn<String, Long>() {
@ProcessElement
public void process(ProcessContext ctxt) {
ctxt.output((long) ctxt.element().length());
}
})).apply("addKeys", WithKeys.of("foo")).setCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianLongCoder.of())).apply("gbk", GroupByKey.create());
PAssert.that(result).containsInAnyOrder(KV.of("foo", ImmutableList.of(4L, 3L, 3L)));
RunnerApi.Pipeline pipelineProto = PipelineTranslation.toProto(p);
// execute the pipeline
JobInvocation jobInvocation = FlinkJobInvoker.create(null).createJobInvocation("fakeId", "fakeRetrievalToken", flinkJobExecutor, pipelineProto, options.as(FlinkPipelineOptions.class), new FlinkPipelineRunner(options.as(FlinkPipelineOptions.class), null, Collections.emptyList()));
jobInvocation.start();
while (jobInvocation.getState() != JobState.Enum.DONE) {
Thread.sleep(1000);
}
}
Aggregations