[
https://issues.apache.org/jira/browse/BEAM-3327?focusedWorklogId=93507&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-93507
]
ASF GitHub Bot logged work on BEAM-3327:
----------------------------------------
Author: ASF GitHub Bot
Created on: 21/Apr/18 00:36
Start Date: 21/Apr/18 00:36
Worklog Time Spent: 10m
Work Description: bsidhom commented on a change in pull request #5189:
[BEAM-3327] Basic Docker environment factory
URL: https://github.com/apache/beam/pull/5189#discussion_r183193526
##########
File path:
runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/environment/DockerEnvironmentFactory.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.environment;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Supplier;
+import org.apache.beam.model.pipeline.v1.RunnerApi.Environment;
+import org.apache.beam.runners.fnexecution.GrpcFnServer;
+import org.apache.beam.runners.fnexecution.artifact.ArtifactRetrievalService;
+import org.apache.beam.runners.fnexecution.control.ControlClientSource;
+import
org.apache.beam.runners.fnexecution.control.FnApiControlClientPoolService;
+import org.apache.beam.runners.fnexecution.control.InstructionRequestHandler;
+import org.apache.beam.runners.fnexecution.logging.GrpcLoggingService;
+import
org.apache.beam.runners.fnexecution.provisioning.StaticGrpcProvisionService;
+
+/**
+ * An {@link EnvironmentFactory} that creates docker containers by shelling
out to docker. Returned
+ * {@link RemoteEnvironment RemoteEnvironments} own their respective docker
containers. Not
+ * thread-safe.
+ */
+public class DockerEnvironmentFactory implements EnvironmentFactory {
+
+ public static DockerEnvironmentFactory forServices(
+ DockerWrapper docker,
+ GrpcFnServer<FnApiControlClientPoolService> controlServiceServer,
+ GrpcFnServer<GrpcLoggingService> loggingServiceServer,
+ GrpcFnServer<ArtifactRetrievalService> retrievalServiceServer,
+ GrpcFnServer<StaticGrpcProvisionService> provisioningServiceServer,
+ ControlClientSource clientSource,
+ // TODO: Refine this to IdGenerator when we determine where that should
live.
+ Supplier<String> idGenerator) {
+ return new DockerEnvironmentFactory(
+ docker,
+ controlServiceServer,
+ loggingServiceServer,
+ retrievalServiceServer,
+ provisioningServiceServer,
+ idGenerator,
+ clientSource);
+ }
+
+ private final DockerWrapper docker;
+ private final GrpcFnServer<FnApiControlClientPoolService>
controlServiceServer;
+ private final GrpcFnServer<GrpcLoggingService> loggingServiceServer;
+ private final GrpcFnServer<ArtifactRetrievalService> retrievalServiceServer;
+ private final GrpcFnServer<StaticGrpcProvisionService>
provisioningServiceServer;
+ private final Supplier<String> idGenerator;
+ private final ControlClientSource clientSource;
+
+ private DockerEnvironmentFactory(
+ DockerWrapper docker,
+ GrpcFnServer<FnApiControlClientPoolService> controlServiceServer,
+ GrpcFnServer<GrpcLoggingService> loggingServiceServer,
+ GrpcFnServer<ArtifactRetrievalService> retrievalServiceServer,
+ GrpcFnServer<StaticGrpcProvisionService> provisioningServiceServer,
+ Supplier<String> idGenerator,
+ ControlClientSource clientSource) {
+ this.docker = docker;
+ this.controlServiceServer = controlServiceServer;
+ this.loggingServiceServer = loggingServiceServer;
+ this.retrievalServiceServer = retrievalServiceServer;
+ this.provisioningServiceServer = provisioningServiceServer;
+ this.idGenerator = idGenerator;
+ this.clientSource = clientSource;
+ }
+
+ /** Creates a new, active {@link RemoteEnvironment} backed by a local Docker
container. */
+ @Override
+ public RemoteEnvironment createEnvironment(Environment environment) throws
Exception {
+ String workerId = idGenerator.get();
+
+ // Prepare docker invocation.
+ Path workerPersistentDirectory =
Files.createTempDirectory("worker_persistent_directory");
+ Path semiPersistentDirectory =
Files.createTempDirectory("semi_persistent_dir");
+ String containerImage = environment.getUrl();
+ // TODO: https://issues.apache.org/jira/browse/BEAM-4148 The default
service address will not
+ // work for Docker for Mac.
+ String loggingEndpoint =
loggingServiceServer.getApiServiceDescriptor().getUrl();
+ String artifactEndpoint =
retrievalServiceServer.getApiServiceDescriptor().getUrl();
+ String provisionEndpoint =
provisioningServiceServer.getApiServiceDescriptor().getUrl();
+ String controlEndpoint =
controlServiceServer.getApiServiceDescriptor().getUrl();
+ List<String> args =
+ Arrays.asList(
+ "-v",
+ // TODO: Mac only allows temporary mounts under /tmp by default
(as of 17.12).
+ String.format("%s:%s", workerPersistentDirectory,
semiPersistentDirectory),
+ // NOTE: Host networking does not work on Mac, but the command
line flag is accepted.
+ "--network=host",
+ containerImage,
+ String.format("--id=%s", workerId),
+ String.format("--logging_endpoint=%s", loggingEndpoint),
+ String.format("--artifact_endpoint=%s", artifactEndpoint),
+ String.format("--provision_endpoint=%s", provisionEndpoint),
+ String.format("--control_endpoint=%s", controlEndpoint),
+ String.format("--semi_persist_dir=%s", semiPersistentDirectory));
+
+ // Wrap the blocking call to clientSource.get in case an exception is
thrown.
+ String containerId = null;
+ InstructionRequestHandler instructionHandler;
+ try {
+ containerId = docker.runImage(containerImage, args);
+ // Wait on a client from the gRPC server.
+ instructionHandler = clientSource.get(workerId);
Review comment:
That's a good idea. We could do that within DockerEnvironmentFactory and use
an independent executor to induce timeouts on the blocking call (somewhat ugly
and wasteful), we could change the client source to always take a timeout
parameter (annoying in tests and other places where we don't want timeouts), or
we could augment client source with another method and make it no longer a
functional interface (annoying in this case but possibly the best approach.
This actually makes me wonder if it's worth returning a future from the
client source and making this explicit and configurable by clients. That does
come with the cost of making use of the source annoying because we will want
the client to be materialized pretty much everywhere. Preferences?
----------------------------------------------------------------
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: 93507)
Time Spent: 17h (was: 16h 50m)
> Add abstractions to manage Environment Instance lifecycles.
> -----------------------------------------------------------
>
> Key: BEAM-3327
> URL: https://issues.apache.org/jira/browse/BEAM-3327
> Project: Beam
> Issue Type: New Feature
> Components: runner-core
> Reporter: Thomas Groh
> Assignee: Ben Sidhom
> Priority: Major
> Labels: portability
> Time Spent: 17h
> Remaining Estimate: 0h
>
> This permits remote stage execution for arbitrary environments
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)