Search in sources :

Example 1 with StreamingImpulseSource

use of org.apache.beam.runners.flink.translation.wrappers.streaming.io.StreamingImpulseSource in project beam by apache.

the class FlinkStreamingPortablePipelineTranslator method translateStreamingImpulse.

private void translateStreamingImpulse(String id, RunnerApi.Pipeline pipeline, StreamingTranslationContext context) {
    RunnerApi.PTransform pTransform = pipeline.getComponents().getTransformsOrThrow(id);
    TypeInformation<WindowedValue<byte[]>> typeInfo = new CoderTypeInformation<>(WindowedValue.getFullCoder(ByteArrayCoder.of(), GlobalWindow.Coder.INSTANCE), context.getPipelineOptions());
    ObjectMapper objectMapper = new ObjectMapper();
    final int intervalMillis;
    final int messageCount;
    try {
        JsonNode config = objectMapper.readTree(pTransform.getSpec().getPayload().toByteArray());
        intervalMillis = config.path("interval_ms").asInt(100);
        messageCount = config.path("message_count").asInt(0);
    } catch (IOException e) {
        throw new RuntimeException("Failed to parse configuration for streaming impulse", e);
    }
    SingleOutputStreamOperator<WindowedValue<byte[]>> source = context.getExecutionEnvironment().addSource(new StreamingImpulseSource(intervalMillis, messageCount), StreamingImpulseSource.class.getSimpleName()).returns(typeInfo);
    context.addDataStream(Iterables.getOnlyElement(pTransform.getOutputsMap().values()), source);
}
Also used : CoderTypeInformation(org.apache.beam.runners.flink.translation.types.CoderTypeInformation) RunnerApi(org.apache.beam.model.pipeline.v1.RunnerApi) WindowedValue(org.apache.beam.sdk.util.WindowedValue) StreamingImpulseSource(org.apache.beam.runners.flink.translation.wrappers.streaming.io.StreamingImpulseSource) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)1 CoderTypeInformation (org.apache.beam.runners.flink.translation.types.CoderTypeInformation)1 StreamingImpulseSource (org.apache.beam.runners.flink.translation.wrappers.streaming.io.StreamingImpulseSource)1 WindowedValue (org.apache.beam.sdk.util.WindowedValue)1