ibzib commented on a change in pull request #14942:
URL: https://github.com/apache/beam/pull/14942#discussion_r647777306
##########
File path:
runners/portability/java/src/main/java/org/apache/beam/runners/portability/ExternalWorkerService.java
##########
@@ -90,10 +97,59 @@ public void stopWorker(
public void close() {}
public GrpcFnServer<ExternalWorkerService> start() throws Exception {
- GrpcFnServer<ExternalWorkerService> server =
- GrpcFnServer.allocatePortAndCreateFor(this, serverFactory);
+ final String externalServiceAddress =
+
Environments.getExternalServiceAddress(options.as(PortablePipelineOptions.class));
+ GrpcFnServer<ExternalWorkerService> server;
+ if (externalServiceAddress.isEmpty()) {
+ server = GrpcFnServer.allocatePortAndCreateFor(this, serverFactory);
+ } else {
+ server =
+ GrpcFnServer.create(
+ this,
+
Endpoints.ApiServiceDescriptor.newBuilder().setUrl(externalServiceAddress).build(),
+ serverFactory);
+ }
LOG.debug(
"Listening for worker start requests at {}.",
server.getApiServiceDescriptor().getUrl());
return server;
}
+
+ /**
+ * Worker pool entry point.
+ *
+ * <p>The worker pool exposes an RPC service that is used with EXTERNAL
environment to start and
+ * stop the SDK workers.
+ *
+ * <p>The worker pool uses threads for parallelism;
+ *
+ * <p>This entry point is used by the Java SDK container in worker pool mode
and expects the
+ * following environment variables:
+ *
+ * <ul>
+ * <li>PIPELINE_OPTIONS: A serialized form of {@link PipelineOptions}. It
needs to be known
+ * up-front and matches the running job. See {@link PipelineOptions}
for further details.
+ * </ul>
+ */
+ public static void main(String[] args) throws Exception {
+ main(System::getenv);
+ }
+
+ public static void main(Function<String, String> environmentVarGetter)
throws Exception {
+ LOG.info("Starting external worker service");
+ LOG.info("Pipeline options {}",
environmentVarGetter.apply(PIPELINE_OPTIONS_ENV_VAR));
+ PipelineOptions options =
+
PipelineOptionsTranslation.fromJson(environmentVarGetter.apply(PIPELINE_OPTIONS_ENV_VAR));
+
+ try (GrpcFnServer<ExternalWorkerService> server = new
ExternalWorkerService(options).start()) {
+ LOG.info(
+ "External worker service started at address: {}",
+ server.getApiServiceDescriptor().getUrl());
+ // Wait to keep ExternalWorkerService running
+ Sleeper.DEFAULT.sleep(Long.MAX_VALUE);
+ } catch (Exception e) {
+ LOG.error("Error running worker service:" + e);
Review comment:
The logger has a special method signature for throwables.
http://www.slf4j.org/apidocs/org/slf4j/Logger.html#error(java.lang.String,java.lang.Throwable)
```suggestion
LOG.error("Error running worker service", e);
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]