[
https://issues.apache.org/jira/browse/BEAM-6271?focusedWorklogId=180452&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-180452
]
ASF GitHub Bot logged work on BEAM-6271:
----------------------------------------
Author: ASF GitHub Bot
Created on: 02/Jan/19 23:21
Start Date: 02/Jan/19 23:21
Worklog Time Spent: 10m
Work Description: xinyuiscool commented on pull request #7321:
[BEAM-6271] SamzaRunner: initial support for portable api in samza runner
URL: https://github.com/apache/beam/pull/7321#discussion_r244882732
##########
File path:
runners/samza/src/main/java/org/apache/beam/runners/samza/translation/PortableTranslationContext.java
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.samza.translation;
+
+import com.google.common.collect.Iterables;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.beam.model.pipeline.v1.RunnerApi;
+import org.apache.beam.runners.core.construction.RehydratedComponents;
+import org.apache.beam.runners.core.construction.WindowingStrategyTranslation;
+import org.apache.beam.runners.core.construction.graph.PipelineNode;
+import org.apache.beam.runners.core.construction.graph.QueryablePipeline;
+import org.apache.beam.runners.fnexecution.wire.WireCoders;
+import org.apache.beam.runners.samza.SamzaPipelineOptions;
+import org.apache.beam.runners.samza.runtime.OpMessage;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.apache.beam.sdk.values.WindowingStrategy;
+import
org.apache.beam.vendor.protobuf.v3.com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.samza.operators.MessageStream;
+import org.apache.samza.operators.OutputStream;
+import org.apache.samza.operators.StreamGraph;
+
+/**
+ * Helper that keeps the mapping from BEAM PCollection id to Samza {@link
MessageStream}. It also
+ * provides other context data such as input and output of a {@link
+ * org.apache.beam.model.pipeline.v1.RunnerApi.PTransform}.
+ */
+public class PortableTranslationContext {
+ private final Map<String, MessageStream<?>> messsageStreams = new
HashMap<>();
+ private final StreamGraph streamGraph;
+ private final SamzaPipelineOptions options;
+ private int topologicalId;
+ private final Set<String> registeredInputStreams = new HashSet<>();
+
+ public PortableTranslationContext(StreamGraph streamGraph,
SamzaPipelineOptions options) {
+ this.streamGraph = streamGraph;
+ this.options = options;
+ }
+
+ public SamzaPipelineOptions getSamzaPipelineOptions() {
+ return this.options;
+ }
+
+ public void setCurrentTopologicalId(int id) {
+ this.topologicalId = id;
+ }
+
+ public int getCurrentTopologicalId() {
+ return this.topologicalId;
+ }
+
+ public <T> List<MessageStream<OpMessage<T>>> getAllInputMessageStreams(
+ PipelineNode.PTransformNode transform) {
+ final Collection<String> inputStreamIds =
transform.getTransform().getInputsMap().values();
+ return
inputStreamIds.stream().map(this::<T>getMessageStreamById).collect(Collectors.toList());
+ }
+
+ public <T> MessageStream<OpMessage<T>> getOneInputMessageStream(
+ PipelineNode.PTransformNode transform) {
+ String id =
Iterables.getOnlyElement(transform.getTransform().getInputsMap().values());
+ return getMessageStreamById(id);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> MessageStream<OpMessage<T>> getMessageStreamById(String id) {
+ return (MessageStream<OpMessage<T>>) messsageStreams.get(id);
+ }
+
+ public String getInputId(PipelineNode.PTransformNode transform) {
+ return
Iterables.getOnlyElement(transform.getTransform().getInputsMap().values());
+ }
+
+ public String getOutputId(PipelineNode.PTransformNode transform) {
+ return
Iterables.getOnlyElement(transform.getTransform().getOutputsMap().values());
+ }
+
+ public <T> void registerMessageStream(String id, MessageStream<OpMessage<T>>
stream) {
+ if (messsageStreams.containsKey(id)) {
+ throw new IllegalArgumentException("Stream already registered for id: "
+ id);
+ }
+ messsageStreams.put(id, stream);
+ }
+
+ /** Register an input stream, using the PCollection id as the config id. */
+ public void registerInputMessageStream(String id) {
+ registerInputMessageStreamWithStreamId(id, id);
+ }
+
+ /** Get output stream by stream id. */
+ public <T> OutputStream<T> getOutputStreamById(String outputStreamId) {
+ return streamGraph.getOutputStream(outputStreamId);
+ }
+
+ /**
+ * Register an input stream with certain config id.
+ *
+ * @param id id of the PCollection in the input/output of PTransform
+ * @param streamId samza stream id which user can use to customize the
stream level config
+ */
+ public <T> void registerInputMessageStreamWithStreamId(String id, String
streamId) {
+ // we want to register it with the Samza graph only once per i/o stream
+ if (registeredInputStreams.contains(streamId)) {
+ return;
+ }
+ final MessageStream<OpMessage<T>> stream =
+ streamGraph
+ .<org.apache.samza.operators.KV<?,
OpMessage<T>>>getInputStream(streamId)
+ .map(org.apache.samza.operators.KV::getValue);
+
+ registerMessageStream(id, stream);
+ registeredInputStreams.add(streamId);
+ }
+
+ public WindowedValue.WindowedValueCoder instantiateCoder(
Review comment:
Seems instantiateCoder() and getPortableWindowStrategy() can be static util
classes in the util package, or inline it if there is only one use case.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 180452)
Time Spent: 2.5h (was: 2h 20m)
> initial support for portable api in samza runner
> ------------------------------------------------
>
> Key: BEAM-6271
> URL: https://issues.apache.org/jira/browse/BEAM-6271
> Project: Beam
> Issue Type: Task
> Components: runner-samza
> Reporter: Hai Lu
> Assignee: Hai Lu
> Priority: Major
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
> Support portable api in Samza runner.
> This ticket tracks the initial effort to support portable api in Samza
> runner, including job server inside samza runner, config translation for
> portable pipeline, transform translation for portable pipeline, refactor of
> existing codes to merge logic of portable api and java api as much as
> possible, etc.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)