You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "damondouglas (via GitHub)" <gi...@apache.org> on 2024/07/07 22:36:16 UTC

[PR] A Java support class executes the Prism binary [beam]

damondouglas opened a new pull request, #31795:
URL: https://github.com/apache/beam/pull/31795

   This PR closes #31792 via a support class for executing the Prism binary. This PR depends on PR #31794 before declaring ready. 
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support class executes the Prism binary [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #31795:
URL: https://github.com/apache/beam/pull/31795#discussion_r1669518329


##########
runners/prism/java/src/main/java/org/apache/beam/runners/prism/PrismExecutor.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.prism;
+
+import static org.apache.beam.sdk.util.Preconditions.checkStateNotNull;
+
+import com.google.auto.value.AutoValue;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.io.ByteStreams;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link PrismExecutor} builds and executes a {@link ProcessBuilder} for use by the {@link
+ * PrismRunner}. Prism is a {@link org.apache.beam.runners.portability.PortableRunner} maintained at
+ * <a href="https://github.com/apache/beam/tree/master/sdks/go/cmd/prism">sdks/go/cmd/prism</a>.
+ */
+@AutoValue
+abstract class PrismExecutor {
+
+  private static final Logger LOG = LoggerFactory.getLogger(PrismExecutor.class);
+
+  protected @MonotonicNonNull Process process;
+  protected ExecutorService executorService = Executors.newSingleThreadExecutor();
+  protected @MonotonicNonNull Future<?> future = null;
+
+  static Builder builder() {
+    return new AutoValue_PrismExecutor.Builder();
+  }
+
+  /** The command to execute the Prism binary. */
+  abstract String getCommand();
+
+  /**
+   * Additional arguments to pass when invoking the Prism binary. Defaults to an {@link
+   * Collections#emptyList()}.
+   */
+  abstract List<String> getArguments();
+
+  /** Stops the execution of the {@link Process}, created as a result of {@link #execute}. */
+  void stop() {
+    LOG.info("Stopping Prism...");
+    if (future != null) {
+      future.cancel(true);
+    }
+    executorService.shutdown();
+    try {
+      boolean ignored = executorService.awaitTermination(1000L, TimeUnit.MILLISECONDS);
+    } catch (InterruptedException ignored) {
+    }
+    if (process == null) {
+      return;
+    }
+    if (!process.isAlive()) {
+      return;
+    }
+    process.destroy();
+    try {
+      process.waitFor();
+    } catch (InterruptedException ignored) {
+    }
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to STDOUT.
+   */
+  void execute() throws IOException {
+    execute(createProcessBuilder().inheritIO());
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param outputStream}.
+   */
+  void execute(OutputStream outputStream) throws IOException {
+    execute(createProcessBuilder().redirectErrorStream(true));
+    this.future =
+        executorService.submit(
+            () -> {
+              try {
+                ByteStreams.copy(checkStateNotNull(process).getInputStream(), outputStream);
+              } catch (IOException e) {
+                throw new RuntimeException(e);
+              }
+            });
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param file}.
+   */
+  void execute(File file) throws IOException {
+    execute(
+        createProcessBuilder()
+            .redirectErrorStream(true)
+            .redirectOutput(ProcessBuilder.Redirect.appendTo(file)));
+  }
+
+  private void execute(ProcessBuilder processBuilder) throws IOException {
+    this.process = processBuilder.start();
+    LOG.info(
+        "started {}, pid: {}",
+        String.join(" ", getCommandWithArguments()),
+        getPidOrNotAvailableWarning());
+  }
+
+  private List<String> getCommandWithArguments() {
+    List<String> commandWithArguments = new ArrayList<>();
+    commandWithArguments.add(getCommand());
+    commandWithArguments.addAll(getArguments());
+
+    return commandWithArguments;
+  }
+
+  private ProcessBuilder createProcessBuilder() {
+    return new ProcessBuilder(getCommandWithArguments());
+  }
+
+  private String getPidOrNotAvailableWarning() {

Review Comment:
   these three private methods look very strange to me. Why need reflection to get a pid from a process? Doesn't process.pid() work?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support class executes the Prism binary [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #31795:
URL: https://github.com/apache/beam/pull/31795#discussion_r1669640265


##########
runners/prism/java/src/main/java/org/apache/beam/runners/prism/PrismExecutor.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.prism;
+
+import static org.apache.beam.sdk.util.Preconditions.checkStateNotNull;
+
+import com.google.auto.value.AutoValue;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.io.ByteStreams;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link PrismExecutor} builds and executes a {@link ProcessBuilder} for use by the {@link
+ * PrismRunner}. Prism is a {@link org.apache.beam.runners.portability.PortableRunner} maintained at
+ * <a href="https://github.com/apache/beam/tree/master/sdks/go/cmd/prism">sdks/go/cmd/prism</a>.
+ */
+@AutoValue
+abstract class PrismExecutor {
+
+  private static final Logger LOG = LoggerFactory.getLogger(PrismExecutor.class);
+
+  protected @MonotonicNonNull Process process;
+  protected ExecutorService executorService = Executors.newSingleThreadExecutor();
+  protected @MonotonicNonNull Future<?> future = null;
+
+  static Builder builder() {
+    return new AutoValue_PrismExecutor.Builder();
+  }
+
+  /** The command to execute the Prism binary. */
+  abstract String getCommand();
+
+  /**
+   * Additional arguments to pass when invoking the Prism binary. Defaults to an {@link
+   * Collections#emptyList()}.
+   */
+  abstract List<String> getArguments();
+
+  /** Stops the execution of the {@link Process}, created as a result of {@link #execute}. */
+  void stop() {
+    LOG.info("Stopping Prism...");
+    if (future != null) {
+      future.cancel(true);
+    }
+    executorService.shutdown();
+    try {
+      boolean ignored = executorService.awaitTermination(1000L, TimeUnit.MILLISECONDS);
+    } catch (InterruptedException ignored) {
+    }
+    if (process == null) {
+      return;
+    }
+    if (!process.isAlive()) {
+      return;
+    }
+    process.destroy();
+    try {
+      process.waitFor();
+    } catch (InterruptedException ignored) {
+    }
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to STDOUT.
+   */
+  void execute() throws IOException {
+    execute(createProcessBuilder().inheritIO());
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param outputStream}.
+   */
+  void execute(OutputStream outputStream) throws IOException {
+    execute(createProcessBuilder().redirectErrorStream(true));
+    this.future =
+        executorService.submit(
+            () -> {
+              try {
+                ByteStreams.copy(checkStateNotNull(process).getInputStream(), outputStream);
+              } catch (IOException e) {
+                throw new RuntimeException(e);
+              }
+            });
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param file}.
+   */
+  void execute(File file) throws IOException {
+    execute(
+        createProcessBuilder()
+            .redirectErrorStream(true)
+            .redirectOutput(ProcessBuilder.Redirect.appendTo(file)));
+  }
+
+  private void execute(ProcessBuilder processBuilder) throws IOException {
+    this.process = processBuilder.start();
+    LOG.info(
+        "started {}, pid: {}",
+        String.join(" ", getCommandWithArguments()),
+        getPidOrNotAvailableWarning());
+  }
+
+  private List<String> getCommandWithArguments() {
+    List<String> commandWithArguments = new ArrayList<>();
+    commandWithArguments.add(getCommand());
+    commandWithArguments.addAll(getArguments());
+
+    return commandWithArguments;
+  }
+
+  private ProcessBuilder createProcessBuilder() {
+    return new ProcessBuilder(getCommandWithArguments());
+  }
+
+  private String getPidOrNotAvailableWarning() {

Review Comment:
   I see, https://docs.oracle.com/javase%2F9%2Fdocs%2Fapi%2F%2F/java/lang/Process.html#pid-- says "Since:
   9".
   
   Would you mind adding a comment and also a TODO saying moving on to pid() when beam/java Prism runner drops Java8 support?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support class executes the Prism binary [beam]

Posted by "damondouglas (via GitHub)" <gi...@apache.org>.
damondouglas merged PR #31795:
URL: https://github.com/apache/beam/pull/31795


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support class executes the Prism binary [beam]

Posted by "damondouglas (via GitHub)" <gi...@apache.org>.
damondouglas commented on code in PR #31795:
URL: https://github.com/apache/beam/pull/31795#discussion_r1670751114


##########
runners/prism/java/src/main/java/org/apache/beam/runners/prism/PrismExecutor.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.prism;
+
+import static org.apache.beam.sdk.util.Preconditions.checkStateNotNull;
+
+import com.google.auto.value.AutoValue;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.io.ByteStreams;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link PrismExecutor} builds and executes a {@link ProcessBuilder} for use by the {@link
+ * PrismRunner}. Prism is a {@link org.apache.beam.runners.portability.PortableRunner} maintained at
+ * <a href="https://github.com/apache/beam/tree/master/sdks/go/cmd/prism">sdks/go/cmd/prism</a>.
+ */
+@AutoValue
+abstract class PrismExecutor {
+
+  private static final Logger LOG = LoggerFactory.getLogger(PrismExecutor.class);
+
+  protected @MonotonicNonNull Process process;
+  protected ExecutorService executorService = Executors.newSingleThreadExecutor();
+  protected @MonotonicNonNull Future<?> future = null;
+
+  static Builder builder() {
+    return new AutoValue_PrismExecutor.Builder();
+  }
+
+  /** The command to execute the Prism binary. */
+  abstract String getCommand();
+
+  /**
+   * Additional arguments to pass when invoking the Prism binary. Defaults to an {@link
+   * Collections#emptyList()}.
+   */
+  abstract List<String> getArguments();
+
+  /** Stops the execution of the {@link Process}, created as a result of {@link #execute}. */
+  void stop() {
+    LOG.info("Stopping Prism...");
+    if (future != null) {
+      future.cancel(true);
+    }
+    executorService.shutdown();
+    try {
+      boolean ignored = executorService.awaitTermination(1000L, TimeUnit.MILLISECONDS);
+    } catch (InterruptedException ignored) {
+    }
+    if (process == null) {
+      return;
+    }
+    if (!process.isAlive()) {
+      return;
+    }
+    process.destroy();
+    try {
+      process.waitFor();
+    } catch (InterruptedException ignored) {
+    }
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to STDOUT.
+   */
+  void execute() throws IOException {
+    execute(createProcessBuilder().inheritIO());
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param outputStream}.
+   */
+  void execute(OutputStream outputStream) throws IOException {
+    execute(createProcessBuilder().redirectErrorStream(true));
+    this.future =
+        executorService.submit(
+            () -> {
+              try {
+                ByteStreams.copy(checkStateNotNull(process).getInputStream(), outputStream);
+              } catch (IOException e) {
+                throw new RuntimeException(e);
+              }
+            });
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param file}.
+   */
+  void execute(File file) throws IOException {
+    execute(
+        createProcessBuilder()
+            .redirectErrorStream(true)
+            .redirectOutput(ProcessBuilder.Redirect.appendTo(file)));
+  }
+
+  private void execute(ProcessBuilder processBuilder) throws IOException {
+    this.process = processBuilder.start();
+    LOG.info(
+        "started {}, pid: {}",
+        String.join(" ", getCommandWithArguments()),
+        getPidOrNotAvailableWarning());
+  }
+
+  private List<String> getCommandWithArguments() {
+    List<String> commandWithArguments = new ArrayList<>();
+    commandWithArguments.add(getCommand());
+    commandWithArguments.addAll(getArguments());
+
+    return commandWithArguments;
+  }
+
+  private ProcessBuilder createProcessBuilder() {
+    return new ProcessBuilder(getCommandWithArguments());
+  }
+
+  private String getPidOrNotAvailableWarning() {

Review Comment:
   I removed it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support class executes the Prism binary [beam]

Posted by "damondouglas (via GitHub)" <gi...@apache.org>.
damondouglas commented on code in PR #31795:
URL: https://github.com/apache/beam/pull/31795#discussion_r1669617222


##########
runners/prism/java/src/main/java/org/apache/beam/runners/prism/PrismExecutor.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.prism;
+
+import static org.apache.beam.sdk.util.Preconditions.checkStateNotNull;
+
+import com.google.auto.value.AutoValue;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.io.ByteStreams;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link PrismExecutor} builds and executes a {@link ProcessBuilder} for use by the {@link
+ * PrismRunner}. Prism is a {@link org.apache.beam.runners.portability.PortableRunner} maintained at
+ * <a href="https://github.com/apache/beam/tree/master/sdks/go/cmd/prism">sdks/go/cmd/prism</a>.
+ */
+@AutoValue
+abstract class PrismExecutor {
+
+  private static final Logger LOG = LoggerFactory.getLogger(PrismExecutor.class);
+
+  protected @MonotonicNonNull Process process;
+  protected ExecutorService executorService = Executors.newSingleThreadExecutor();
+  protected @MonotonicNonNull Future<?> future = null;
+
+  static Builder builder() {
+    return new AutoValue_PrismExecutor.Builder();
+  }
+
+  /** The command to execute the Prism binary. */
+  abstract String getCommand();
+
+  /**
+   * Additional arguments to pass when invoking the Prism binary. Defaults to an {@link
+   * Collections#emptyList()}.
+   */
+  abstract List<String> getArguments();
+
+  /** Stops the execution of the {@link Process}, created as a result of {@link #execute}. */
+  void stop() {
+    LOG.info("Stopping Prism...");
+    if (future != null) {
+      future.cancel(true);
+    }
+    executorService.shutdown();
+    try {
+      boolean ignored = executorService.awaitTermination(1000L, TimeUnit.MILLISECONDS);
+    } catch (InterruptedException ignored) {
+    }
+    if (process == null) {
+      return;
+    }
+    if (!process.isAlive()) {
+      return;
+    }
+    process.destroy();
+    try {
+      process.waitFor();
+    } catch (InterruptedException ignored) {
+    }
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to STDOUT.
+   */
+  void execute() throws IOException {
+    execute(createProcessBuilder().inheritIO());
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param outputStream}.
+   */
+  void execute(OutputStream outputStream) throws IOException {
+    execute(createProcessBuilder().redirectErrorStream(true));
+    this.future =
+        executorService.submit(
+            () -> {
+              try {
+                ByteStreams.copy(checkStateNotNull(process).getInputStream(), outputStream);
+              } catch (IOException e) {
+                throw new RuntimeException(e);
+              }
+            });
+  }
+
+  /**
+   * Execute the {@link ProcessBuilder} that starts the Prism service. Redirects output to the
+   * {@param file}.
+   */
+  void execute(File file) throws IOException {
+    execute(
+        createProcessBuilder()
+            .redirectErrorStream(true)
+            .redirectOutput(ProcessBuilder.Redirect.appendTo(file)));
+  }
+
+  private void execute(ProcessBuilder processBuilder) throws IOException {
+    this.process = processBuilder.start();
+    LOG.info(
+        "started {}, pid: {}",
+        String.join(" ", getCommandWithArguments()),
+        getPidOrNotAvailableWarning());
+  }
+
+  private List<String> getCommandWithArguments() {
+    List<String> commandWithArguments = new ArrayList<>();
+    commandWithArguments.add(getCommand());
+    commandWithArguments.addAll(getArguments());
+
+    return commandWithArguments;
+  }
+
+  private ProcessBuilder createProcessBuilder() {
+    return new ProcessBuilder(getCommandWithArguments());
+  }
+
+  private String getPidOrNotAvailableWarning() {

Review Comment:
   @Abacn Not all Java versions have support for querying the PID. The recommendation is to use reflection to determine whether support exists.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] A Java support class executes the Prism binary [beam]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #31795:
URL: https://github.com/apache/beam/pull/31795#issuecomment-2214913299

   ## [Codecov](https://app.codecov.io/gh/apache/beam/pull/31795?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 71.20%. Comparing base [(`c08afea`)](https://app.codecov.io/gh/apache/beam/commit/c08afeae60dfb1a15a0f4c8669085662a847249f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`0f34d52`)](https://app.codecov.io/gh/apache/beam/commit/0f34d52e5e5a76e6b7a60edb20227152a3736632?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 5 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@            Coverage Diff            @@
   ##             master   #31795   +/-   ##
   =========================================
     Coverage     71.20%   71.20%           
     Complexity     3020     3020           
   =========================================
     Files          1058     1058           
     Lines        134159   134159           
     Branches       3257     3257           
   =========================================
     Hits          95534    95534           
     Misses        35489    35489           
     Partials       3136     3136           
   ```
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/beam/pull/31795?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] A Java support class executes the Prism binary [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #31795:
URL: https://github.com/apache/beam/pull/31795#issuecomment-2214910631

   Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
   
   R: @Abacn added as fallback since no labels match configuration
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review comments).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org