Package org.apache.storm.container
Class DefaultResourceIsolationManager
java.lang.Object
org.apache.storm.container.DefaultResourceIsolationManager
- All Implemented Interfaces:
ResourceIsolationInterface
- Direct Known Subclasses:
CgroupManager
This is the default class to manage worker processes, including launching, killing, profiling and etc.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
areAllProcessesDead
(String user, String workerId) Check if all the processes are dead.void
This function will be called when the worker needs to shutdown.void
Kill the given worker forcefully.getAllPids
(String workerId) Get all the pids that are a part of the container.long
getMemoryUsage
(String user, String workerId, int port) Get the current memory usage of the a given worker.long
Get the amount of free memory in MB.boolean
This class doesn't really manage resources.void
Kill the given worker.void
launchWorkerProcess
(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. calling reserveResourcesForWorker), this function can be used to launch worker process.void
Called when starting up.void
reserveResourcesForWorker
(String workerId, Integer workerMemory, Integer workerCpu, String numaId) This function should be used prior to starting the worker to reserve resources for the worker.boolean
runProfilingCommand
(String user, String workerId, List<String> command, Map<String, String> env, String logPrefix, File targetDir) Run profiling command.
-
Field Details
-
conf
-
runAsUser
protected boolean runAsUser
-
-
Constructor Details
-
DefaultResourceIsolationManager
public DefaultResourceIsolationManager()
-
-
Method Details
-
prepare
Description copied from interface:ResourceIsolationInterface
Called when starting up.- Specified by:
prepare
in interfaceResourceIsolationInterface
- Parameters:
conf
- the cluster config- Throws:
IOException
- on any error.
-
reserveResourcesForWorker
public void reserveResourcesForWorker(String workerId, Integer workerMemory, Integer workerCpu, String numaId) Description copied from interface:ResourceIsolationInterface
This function should be used prior to starting the worker to reserve resources for the worker.- Specified by:
reserveResourcesForWorker
in interfaceResourceIsolationInterface
- Parameters:
workerId
- worker id of the worker to startworkerMemory
- the amount of memory for the worker or null if not enforcedworkerCpu
- the amount of cpu for the worker or null if not enforcednumaId
- NUMA zone if applicable the worker should be bound to
-
cleanup
Description copied from interface:ResourceIsolationInterface
This 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:
cleanup
in interfaceResourceIsolationInterface
- Parameters:
user
- the user of the workerworkerId
- worker id to shutdown and clean up afterport
- the port of the worker- Throws:
IOException
-
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:ResourceIsolationInterface
After reserving resources for the worker (i.e. calling reserveResourcesForWorker), this function can be used to launch worker process.- Specified by:
launchWorkerProcess
in interfaceResourceIsolationInterface
- 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:ResourceIsolationInterface
Get the current memory usage of the a given worker.- Specified by:
getMemoryUsage
in interfaceResourceIsolationInterface
- 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
-
getSystemFreeMemoryMb
Description copied from interface:ResourceIsolationInterface
Get the amount of free memory in MB. This might not be the entire box, it might be within a parent resource group.- Specified by:
getSystemFreeMemoryMb
in interfaceResourceIsolationInterface
- Returns:
- The amount of memory in MB that are free on the system.
- Throws:
IOException
- on I/O exception
-
kill
Description copied from interface:ResourceIsolationInterface
Kill the given worker.- Specified by:
kill
in interfaceResourceIsolationInterface
- 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:ResourceIsolationInterface
Kill the given worker forcefully.- Specified by:
forceKill
in interfaceResourceIsolationInterface
- Parameters:
user
- the user that the worker is running asworkerId
- the id of the worker to kill- Throws:
IOException
- on I/O exception
-
getAllPids
Get all the pids that are a part of the container.- Returns:
- all of the pids that are a part of this container
- Throws:
IOException
-
areAllProcessesDead
Description copied from interface:ResourceIsolationInterface
Check if all the processes are dead.- Specified by:
areAllProcessesDead
in interfaceResourceIsolationInterface
- Parameters:
user
- the user that the processes are running asworkerId
- the id of the worker to kill- Returns:
- true if all the processed are dead; false otherwise
- 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, InterruptedExceptionDescription copied from interface:ResourceIsolationInterface
Run profiling command.- Specified by:
runProfilingCommand
in interfaceResourceIsolationInterface
- Parameters:
user
- the user that the worker is running asworkerId
- the id of the workercommand
- the command to runenv
- the environment to run the commandlogPrefix
- the prefix to include in the logstargetDir
- the working directory to run the command in- Returns:
- true if succeeds; false otherwise
- Throws:
IOException
- on I/O exceptionInterruptedException
- if interrupted
-
isResourceManaged
public boolean isResourceManaged()This class doesn't really manage resources.- Specified by:
isResourceManaged
in interfaceResourceIsolationInterface
- Returns:
- false
-