[ https://issues.apache.org/jira/browse/BEAM-3327?focusedWorklogId=94389&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-94389 ]
ASF GitHub Bot logged work on BEAM-3327: ---------------------------------------- Author: ASF GitHub Bot Created on: 24/Apr/18 00:13 Start Date: 24/Apr/18 00:13 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_r183565840 ########## File path: runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/environment/DockerContainerEnvironment.java ########## @@ -0,0 +1,79 @@ +/* + * 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 javax.annotation.concurrent.ThreadSafe; +import org.apache.beam.model.pipeline.v1.RunnerApi.Environment; +import org.apache.beam.runners.fnexecution.control.InstructionRequestHandler; + +/** + * A {@link RemoteEnvironment} that wraps a running Docker container. + * + * <p>A {@link DockerContainerEnvironment} owns both the underlying docker container that it + * communicates with an the {@link InstructionRequestHandler} that it uses to do so. + */ +@ThreadSafe +class DockerContainerEnvironment implements RemoteEnvironment { + + static DockerContainerEnvironment create( + DockerCommand docker, + Environment environment, + String containerId, + InstructionRequestHandler instructionHandler) { + return new DockerContainerEnvironment(docker, environment, containerId, instructionHandler); + } + + private final Object lock = new Object(); + private final DockerCommand docker; + private final Environment environment; + private final String containerId; + private final InstructionRequestHandler instructionHandler; + + private DockerContainerEnvironment( + DockerCommand docker, + Environment environment, + String containerId, + InstructionRequestHandler instructionHandler) { + this.docker = docker; + this.environment = environment; + this.containerId = containerId; + this.instructionHandler = instructionHandler; + } + + @Override + public Environment getEnvironment() { + return environment; + } + + @Override + public InstructionRequestHandler getInstructionRequestHandler() { + return instructionHandler; + } + + /** + * Closes this remote docker environment. The associated {@link InstructionRequestHandler} should + * not be used after calling this. + */ + @Override + public void close() throws Exception { + synchronized (lock) { Review comment: This was a result of https://github.com/apache/beam/pull/5189#discussion_r183470809. The net result is that it's generally unsafe for multiple threads to close a given docker environment. I was hesitant to provide synchronization here to emphasize the fact that there should only be a single owner, but @tgroh believed it was easier to understand if all methods were thread-safe. I'll make it idempotent and add an internal and javadoc comment. ---------------------------------------------------------------- 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: 94389) Time Spent: 21h (was: 20h 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: 21h > Remaining Estimate: 0h > > This permits remote stage execution for arbitrary environments -- This message was sent by Atlassian JIRA (v7.6.3#76005)