From commits-return-60299-archive-asf-public=cust-asf.ponee.io@beam.apache.org Fri Mar 9 03:19:06 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 10C7118064C for ; Fri, 9 Mar 2018 03:19:05 +0100 (CET) Received: (qmail 29193 invoked by uid 500); 9 Mar 2018 02:19:05 -0000 Mailing-List: contact commits-help@beam.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@beam.apache.org Delivered-To: mailing list commits@beam.apache.org Received: (qmail 29184 invoked by uid 99); 9 Mar 2018 02:19:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Mar 2018 02:19:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 9515AC0111 for ; Fri, 9 Mar 2018 02:19:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.511 X-Spam-Level: X-Spam-Status: No, score=-109.511 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id QzJJM-tNTK-k for ; Fri, 9 Mar 2018 02:19:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 731435F195 for ; Fri, 9 Mar 2018 02:19:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 78640E00A7 for ; Fri, 9 Mar 2018 02:19:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 379722540A for ; Fri, 9 Mar 2018 02:19:00 +0000 (UTC) Date: Fri, 9 Mar 2018 02:19:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: commits@beam.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Work logged] (BEAM-3327) Add abstractions to manage Environment Instance lifecycles. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/BEAM-3327?focusedWorklogId=78768&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-78768 ] ASF GitHub Bot logged work on BEAM-3327: ---------------------------------------- Author: ASF GitHub Bot Created on: 09/Mar/18 02:18 Start Date: 09/Mar/18 02:18 Worklog Time Spent: 10m Work Description: bsidhom commented on a change in pull request #4751: [BEAM-3327] Implement simple Docker container manager URL: https://github.com/apache/beam/pull/4751#discussion_r173350125 ########## File path: runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/environment/SingletonDockerEnvironmentManager.java ########## @@ -0,0 +1,107 @@ +package org.apache.beam.runners.fnexecution.environment; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeoutException; +import javax.annotation.concurrent.GuardedBy; +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.SdkHarnessClientControlService; +import org.apache.beam.runners.fnexecution.logging.GrpcLoggingService; +import org.apache.beam.runners.fnexecution.provisioning.StaticGrpcProvisionService; + +/** An {@link EnvironmentManager} that manages a single docker container. */ +public class SingletonDockerEnvironmentManager implements EnvironmentManager { + + public static SingletonDockerEnvironmentManager forServices( + DockerWrapper docker, + GrpcFnServer controlServiceServer, + GrpcFnServer loggingServiceServer, + GrpcFnServer retrievalServiceServer, + GrpcFnServer provisioningServiceServer) { + return new SingletonDockerEnvironmentManager(docker, controlServiceServer, loggingServiceServer, + retrievalServiceServer, provisioningServiceServer); + } + + private final Object lock = new Object(); + private final DockerWrapper docker; + private final GrpcFnServer controlServiceServer; + private final GrpcFnServer loggingServiceServer; + private final GrpcFnServer retrievalServiceServer; + private final GrpcFnServer provisioningServiceServer; + + @GuardedBy("lock") + private RemoteEnvironment dockerEnvironment = null; + + private SingletonDockerEnvironmentManager( + DockerWrapper docker, + GrpcFnServer controlServiceServer, + GrpcFnServer loggingServiceServer, + GrpcFnServer retrievalServiceServer, + GrpcFnServer provisioningServiceServer) { + this.docker = docker; + this.controlServiceServer = controlServiceServer; + this.loggingServiceServer = loggingServiceServer; + this.retrievalServiceServer = retrievalServiceServer; + this.provisioningServiceServer = provisioningServiceServer; + } + + /** + * Retrieve a handle for the given environment. The same environment must be requested every time. + * The same remote handle is returned to every caller, so the environment cannot be used once + * closed. + */ + @Override + public RemoteEnvironment getEnvironment(Environment environment) throws Exception { + synchronized (lock) { + if (dockerEnvironment == null) { + dockerEnvironment = createDockerEnv(environment); + } else { + checkArgument( + environment.getUrl().equals(dockerEnvironment.getEnvironment().getUrl()), + "A %s must only be queried for a single %s. Existing %s, Argument %s", + SingletonDockerEnvironmentManager.class.getSimpleName(), + Environment.class.getSimpleName(), + dockerEnvironment.getEnvironment().getUrl(), + environment.getUrl()); + } + return dockerEnvironment; + } + } + + private DockerContainerEnvironment createDockerEnv(Environment environment) + throws IOException, TimeoutException, InterruptedException { + // TODO: Generate environment id correctly. + String environmentId = Long.toString(-123); + Path workerPersistentDirectory = Files.createTempDirectory("worker_persistent_directory"); + Path semiPersistentDirectory = Files.createTempDirectory("semi_persistent_dir"); + String containerImage = environment.getUrl(); + // TODO: 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 args = Arrays.asList( + "-v", + String.format("%s:%S", workerPersistentDirectory, semiPersistentDirectory), + // TODO: This needs to be special-cased for Mac. + "--network=host", Review comment: I've played around with it a bit and it looks like Docker for Mac accepts the `--network=host` flag but silently ignores it. It looks like the only change we actually need to make between Mac and Linux is to add a restriction on the temporary directory. By default, Docker for Mac only accepts temporary mounts under `/tmp` and requires explicit user configuration to use the default Java generated directory `/var/...`. In the interest of making things "just work" for local development, we should add this change, but I'll do that in a follow-up PR where I also address the network hosts for Mac. ---------------------------------------------------------------- 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: users@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 78768) Time Spent: 4h 10m (was: 4h) > 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: 4h 10m > Remaining Estimate: 0h > > This permits remote stage execution for arbitrary environments -- This message was sent by Atlassian JIRA (v7.6.3#76005)