Class DockerManager
java.lang.Object
org.apache.storm.container.oci.OciContainerManager
org.apache.storm.container.docker.DockerManager
- All Implemented Interfaces:
ResourceIsolationInterface
For security, we can launch worker processes inside the docker container.
This class manages the interaction with docker containers including launching, stopping, profiling and etc.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.storm.container.oci.OciContainerManager
OciContainerManager.CmdType -
Field Summary
Fields inherited from class org.apache.storm.container.oci.OciContainerManager
cgroupParent, cgroupRootPath, conf, memoryCgroupRootPath, memoryCoreAtRoot, nscdPath, readonlyBindmounts, readwriteBindmounts, seccompJsonFile, stormHome, TMP_DIR, validatedNumaMap, workerToCores, workerToCpu, workerToMemoryMb, workerToMemoryZone -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanareAllProcessesDead(String user, String workerId) Currently it only checks if the container is alive.voidThis function will be called when the worker needs to shutdown.voidKill the given worker forcefully.longgetMemoryUsage(String user, String workerId, int port) Get the current memory usage of the a given worker.booleanReturn true if resources are being managed.voidKill the given worker.voidlaunchWorkerProcess(String user, String topologyId, Map<String, Object> topoConf, int port, String workerId, List<String> command, Map<String, String> env, String logPrefix, ExitCodeCallback processExitCallback, File targetDir) After reserving resources for the worker (i.e.voidCalled when starting up.booleanrunProfilingCommand(String user, String workerId, List<String> command, Map<String, String> env, String logPrefix, File targetDir) Run profiling command in the container.Methods inherited from class org.apache.storm.container.oci.OciContainerManager
commandFilePath, getImageName, getSystemFreeMemoryMb, reserveResourcesForWorker, writeToCommandFile
-
Constructor Details
-
DockerManager
public DockerManager()
-
-
Method Details
-
prepare
Description copied from interface:ResourceIsolationInterfaceCalled when starting up.- Specified by:
preparein interfaceResourceIsolationInterface- Overrides:
preparein classOciContainerManager- Parameters:
conf- the cluster config- Throws:
IOException- on any error.
-
launchWorkerProcess
public void launchWorkerProcess(String user, String topologyId, Map<String, Object> topoConf, int port, String workerId, List<String> command, Map<String, throws IOExceptionString> env, String logPrefix, ExitCodeCallback processExitCallback, File targetDir) Description copied from interface:ResourceIsolationInterfaceAfter reserving resources for the worker (i.e. calling reserveResourcesForWorker), this function can be used to launch worker process.- Parameters:
user- the user who runs the command astopologyId- the Id of the topologytopoConf- the topology configurationport- the port where the worker is onworkerId- the Id of the workercommand- the command to runenv- the environment to run the commandlogPrefix- the prefix to include in the logsprocessExitCallback- a callback for when the process exitstargetDir- the working directory to run the command in- Throws:
IOException- on I/O exception
-
getMemoryUsage
Description copied from interface:ResourceIsolationInterfaceGet the current memory usage of the a given worker.- Parameters:
user- the user that the worker is running asworkerId- the id of the workerport- the port of the worker- Returns:
- the amount of memory the worker is using in bytes or -1 if not supported
- Throws:
IOException- on I/O exception
-
kill
Description copied from interface:ResourceIsolationInterfaceKill the given worker.- Parameters:
user- the user that the worker is running asworkerId- the id of the worker to kill- Throws:
IOException- on I/O exception
-
forceKill
Description copied from interface:ResourceIsolationInterfaceKill the given worker forcefully.- Parameters:
user- the user that the worker is running asworkerId- the id of the worker to kill- Throws:
IOException- on I/O exception
-
areAllProcessesDead
Currently it only checks if the container is alive. If the worker process inside the container dies, the container will exit. So we only need to check if the container is running to know if the worker process is still alive.- Parameters:
user- the user of the processesworkerId- the id of the worker to kill- Returns:
- true if all processes are dead
- Throws:
IOException- on I/O exception
-
runProfilingCommand
public boolean runProfilingCommand(String user, String workerId, List<String> command, Map<String, String> env, String logPrefix, File targetDir) throws IOException, InterruptedExceptionRun profiling command in the container.- Parameters:
user- the user that the worker is running asworkerId- the id of the workercommand- the command to run. The profiler to be used is configured in worker-launcher.cfg.env- the environment to run the commandlogPrefix- the prefix to include in the logstargetDir- the working directory to run the command in- Returns:
- true if the command succeeds, false otherwise.
- Throws:
IOException- on I/O exceptionInterruptedException- if interrupted
-
cleanup
Description copied from interface:ResourceIsolationInterfaceThis function will be called when the worker needs to shutdown. This function should include logic to clean up after a worker is shutdown.- Specified by:
cleanupin interfaceResourceIsolationInterface- Overrides:
cleanupin classOciContainerManager- Parameters:
user- the user of the workerworkerId- worker id to shutdown and clean up afterport- the port of the worker- Throws:
IOException
-
isResourceManaged
public boolean isResourceManaged()Description copied from interface:ResourceIsolationInterfaceReturn true if resources are being managed. TheDefaultResourceIsolationManagerwill have it return false since it doesn't really manage resources.- Returns:
- true if resources are being managed.
-