[ 
https://issues.apache.org/jira/browse/BEAM-4130?focusedWorklogId=111689&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-111689
 ]

ASF GitHub Bot logged work on BEAM-4130:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Jun/18 22:25
            Start Date: 13/Jun/18 22:25
    Worklog Time Spent: 10m 
      Work Description: angoenka commented on a change in pull request #5493: 
[BEAM-4130] Add job submission capabilities to Flink runner.
URL: https://github.com/apache/beam/pull/5493#discussion_r195252523
 
 

 ##########
 File path: 
runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/artifact/BeamFileSystemArtifactSource.java
 ##########
 @@ -0,0 +1,88 @@
+/*
+ * 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.fnexecution.artifact;
+
+import com.google.protobuf.ByteString;
+import com.google.protobuf.util.JsonFormat;
+import io.grpc.stub.StreamObserver;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.charset.StandardCharsets;
+import org.apache.beam.model.jobmanagement.v1.ArtifactApi;
+import org.apache.beam.sdk.io.FileSystems;
+
+/**
+ * An ArtifactSource suitable for retrieving artifacts uploaded via
+ * {@link BeamFileSystemArtifactStagingService}.
+ */
+public class BeamFileSystemArtifactSource implements ArtifactSource {
+
+  private static final int CHUNK_SIZE = 2 * 1024 * 1024;
+
+  private final String retrievalToken;
+  private ArtifactApi.ProxyManifest proxyManifest;
+
+  public BeamFileSystemArtifactSource(String retrievalToken) {
+    this.retrievalToken = retrievalToken;
+  }
+
+  public static BeamFileSystemArtifactSource create(String artifactToken) {
+    return new BeamFileSystemArtifactSource(artifactToken);
+  }
+
+  @Override
+  public ArtifactApi.Manifest getManifest() throws IOException {
+    return getProxyManifest().getManifest();
+  }
+
+  @Override
+  public void getArtifact(String name,
+      StreamObserver<ArtifactApi.ArtifactChunk> responseObserver) throws 
IOException {
+    ReadableByteChannel artifact = FileSystems
+        .open(FileSystems.matchNewResource(lookupUri(name), false));
+    ByteBuffer buffer = ByteBuffer.allocate(CHUNK_SIZE);
+    while (artifact.read(buffer) > -1) {
+      buffer.flip();
+      responseObserver.onNext(
+          
ArtifactApi.ArtifactChunk.newBuilder().setData(ByteString.copyFrom(buffer)).build());
+      buffer.clear();
+    }
+  }
+
+  private String lookupUri(String name) throws IOException {
+    for (ArtifactApi.ProxyManifest.Location location : 
getProxyManifest().getLocationList()) {
+      if (location.getName().equals(name)) {
+        return location.getUri();
+      }
+    }
+    throw new IllegalArgumentException("No such artifact: " + name);
+  }
+
+  private ArtifactApi.ProxyManifest getProxyManifest() throws IOException {
+    if (proxyManifest == null) {
+      ArtifactApi.ProxyManifest.Builder builder = 
ArtifactApi.ProxyManifest.newBuilder();
+      JsonFormat.parser().merge(Channels.newReader(
+          FileSystems.open(FileSystems.matchNewResource(retrievalToken, false 
/* is directory */)),
+          StandardCharsets.UTF_8.name()), builder);
 
 Review comment:
   Shall we standardize the characterset for all BeamFileSystemArtifact**** ?

----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 111689)
    Time Spent: 1h  (was: 50m)

> Portable Flink runner JobService entry point in a Docker container
> ------------------------------------------------------------------
>
>                 Key: BEAM-4130
>                 URL: https://issues.apache.org/jira/browse/BEAM-4130
>             Project: Beam
>          Issue Type: New Feature
>          Components: runner-flink
>            Reporter: Ben Sidhom
>            Priority: Minor
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> The portable Flink runner exists as a Job Service that runs somewhere. We 
> need a main entry point that itself spins up the job service (and artifact 
> staging service). The main program itself should be packaged into an uberjar 
> such that it can be run locally or submitted to a Flink deployment via `flink 
> run`.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to