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

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

                Author: ASF GitHub Bot
            Created on: 11/Apr/18 15:25
            Start Date: 11/Apr/18 15:25
    Worklog Time Spent: 10m 
      Work Description: rezarokni commented on a change in pull request #3961: 
[BEAM-2871] Add advanced examples of running external libraries on workers
URL: https://github.com/apache/beam/pull/3961#discussion_r180796160
 
 

 ##########
 File path: 
examples/java8/src/main/java/org/apache/beam/examples/advanced/subprocess/kernel/SubProcessKernel.java
 ##########
 @@ -0,0 +1,310 @@
+/*
+ * 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.examples.advanced.subprocess.kernel;
+
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import 
org.apache.beam.examples.advanced.subprocess.configuration.SubProcessConfiguration;
+import 
org.apache.beam.examples.advanced.subprocess.utils.CallingSubProcessUtils;
+import org.apache.beam.examples.advanced.subprocess.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is the process kernel which deals with exec of the subprocess.
+ * It also deals with all I/O.
+ */
+public class SubProcessKernel {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(SubProcessKernel.class);
+
+  private static final int MAX_SIZE_COMMAND_LINE_ARGS = 128 * 1024;
+
+  SubProcessConfiguration configuration;
+  ProcessBuilder processBuilder;
+
+  private SubProcessKernel() {};
+
+  /**
+   * Creates the SubProcess Kernel ready for execution.
+   * Will deal with all input and outputs to the SubProcess
+   * @param options
+   * @param binaryName
+   */
+  public SubProcessKernel(SubProcessConfiguration options, String binaryName) {
+    this.configuration = options;
+    this.processBuilder = new ProcessBuilder(binaryName);
+  }
+
+  public List<String> exec(SubProcessCommandLineArgs commands) throws 
Exception {
+    try (CallingSubProcessUtils.Permit permit = new 
CallingSubProcessUtils.Permit(processBuilder.command().get(0))) {
+
+      List<String> results = null;
+
+      try (SubProcessIOFiles outputFiles = new 
SubProcessIOFiles(configuration.getWorkerPath())) {
+
+        try {
+          Process process = execBinary(processBuilder, commands, outputFiles);
+          results = collectProcessResults(process, processBuilder, 
outputFiles);
+        } catch (Exception ex) {
+          LOG.error("Error running executable ", ex);
+          throw (ex);
 
 Review comment:
   Good point will add as TODO and deal with in another PR

----------------------------------------------------------------
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: 89997)
    Time Spent: 0.5h  (was: 20m)

> Add examples of running external libraries on workers
> -----------------------------------------------------
>
>                 Key: BEAM-2871
>                 URL: https://issues.apache.org/jira/browse/BEAM-2871
>             Project: Beam
>          Issue Type: New Feature
>          Components: examples-java
>    Affects Versions: 2.1.0
>            Reporter: Reza ardeshir rokni
>            Assignee: Reuven Lax
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Provide example for how to run external libraries such as c++ code within a 
> DoFn. 
> More details of this pattern can be viewed in the blog:
> https://cloud.google.com/blog/big-data/2017/07/running-external-libraries-with-cloud-dataflow-for-grid-computing-workloads



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

Reply via email to