Github user revans2 commented on a diff in the pull request: https://github.com/apache/storm/pull/1642#discussion_r76610605 --- Diff: storm-core/src/jvm/org/apache/storm/daemon/supervisor/Container.java --- @@ -0,0 +1,429 @@ +/** + * 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.storm.daemon.supervisor; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.ProcessBuilder.Redirect; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.storm.Config; +import org.apache.storm.container.ResourceIsolationInterface; +import org.apache.storm.generated.LSWorkerHeartbeat; +import org.apache.storm.generated.LocalAssignment; +import org.apache.storm.generated.ProfileRequest; +import org.apache.storm.utils.AdvancedFSOps; +import org.apache.storm.utils.ConfigUtils; +import org.apache.storm.utils.LocalState; +import org.apache.storm.utils.Utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +/** + * Represents a container that a worker will run in. + */ +public abstract class Container implements Killable { + private static final Logger LOG = LoggerFactory.getLogger(BasicContainer.class); + protected final Map<String, Object> _conf; + protected String _workerId; + protected final String _supervisorId; + protected final int _port; + protected final LocalAssignment _assignment; + protected final AdvancedFSOps _ops; + protected final ResourceIsolationInterface _resourceIsolationManager; + + protected Container(int port, LocalAssignment assignment, Map<String, Object> conf, + String supervisorId, ResourceIsolationInterface resourceIsolationManager) { + _port = port; + _assignment = assignment; + _conf = conf; + _supervisorId = supervisorId; + _resourceIsolationManager = resourceIsolationManager; + _ops = AdvancedFSOps.mk(conf); + } + + /** + * Constructor to use when trying to recover a container from just the worker ID. + * @param workerId the id of the worker + * @param conf the config of the supervisor + * @param supervisorId the id of the supervisor + * @param resourceIsolationManager the isolation manager. + */ + protected Container(String workerId, Map<String, Object> conf, + String supervisorId, ResourceIsolationInterface resourceIsolationManager) { + _port = -1; + _assignment = null; + _workerId = workerId; + _conf = conf; + _supervisorId = supervisorId; + _resourceIsolationManager = resourceIsolationManager; + _ops = AdvancedFSOps.mk(conf); + } + + /** + * Kill a given process + * @param pid the id of the process to kill + * @throws IOException + */ + protected void kill(long pid) throws IOException { + Utils.killProcessWithSigTerm(String.valueOf(pid)); + } + + /** + * Kill a given process + * @param pid the id of the process to kill + * @throws IOException + */ + protected void forceKill(long pid) throws IOException { + Utils.forceKillProcess(String.valueOf(pid)); + } + + @Override + public void kill() throws IOException { + LOG.info("Killing {}:{}", _supervisorId, _workerId); + Set<Long> pids = getAllPids(); + + for (Long pid : pids) { + kill(pid); + } + } + + @Override + public void forceKill() throws IOException { + LOG.info("Force Killing {}:{}", _supervisorId, _workerId); + Set<Long> pids = getAllPids(); + + for (Long pid : pids) { + forceKill(pid); + } + } + + /** + * Read the Heartbeat for the current container. + * @return the Heartbeat + * @throws IOException on any error + */ + public LSWorkerHeartbeat readHeartbeat() throws IOException { + LocalState localState = ConfigUtils.workerState(_conf, _workerId); + LSWorkerHeartbeat hb = localState.getWorkerHeartBeat(); + LOG.warn("{}: Reading heartbeat {}", _workerId, hb); + return hb; + } + + /** + * Is a process alive and running? + * @param pid the PID of the running process + * @param user the user that is expected to own that process + * @return true if it is, else false + * @throws IOException on any error + */ + protected boolean isProcessAlive(long pid, String user) throws IOException { + if (Utils.IS_ON_WINDOWS) { --- End diff -- done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---