org.apache.storm.container.cgroup

## Class CgroupManager

- java.lang.Object
- - org.apache.storm.container.cgroup.CgroupManager

- All Implemented Interfaces:
    ResourceIsolationInterface

      public class CgroupManager
      extends Object
      implements ResourceIsolationInterface

  Class that implements ResourceIsolationInterface that manages cgroups.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CgroupManager()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<String>` | `getLaunchCommand(String workerId, List<String> existingCommand)` After reserving resources for the worker (i.e.
    `List<String>` | `getLaunchCommandPrefix(String workerId)` After reserving resources for the worker (i.e.
    `long` | `getMemoryUsage(String workerId)` Get the current memory usage of the a given worker.
    `Set<Long>` | `getRunningPids(String workerId)` Get the list of PIDs currently in an isolated container.
    `long` | `getSystemFreeMemoryMb()`
    `void` | `prepare(Map<String,Object> conf)` initialize data structures.
    `void` | `releaseResourcesForWorker(String workerId)` This function will be called when the worker needs to shutdown.
    `void` | `reserveResourcesForWorker(String workerId, Integer totalMem, Integer cpuNum)` This function should be used prior to starting the worker to reserve resources for the worker.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CgroupManager

          public CgroupManager()

  - ### Method Detail

    - #### prepare

          public void prepare(Map<String,Object> conf)
                       throws IOException

      initialize data structures.

      Specified by:
        `prepare` in interface `ResourceIsolationInterface`
      Parameters:
        `conf` - storm confs
      Throws:
        `IOException` - on any error.

    - #### reserveResourcesForWorker

          public void reserveResourcesForWorker(String workerId,
                                                Integer totalMem,
                                                Integer cpuNum)
                                         throws SecurityException

      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 interface `ResourceIsolationInterface`
      Parameters:
        `workerId` - worker id of the worker to start
        `totalMem` - the amount of memory for the worker or null if not enforced
        `cpuNum` - the amount of cpu for the worker or null if not enforced
      Throws:
        `SecurityException`

    - #### releaseResourcesForWorker

          public void releaseResourcesForWorker(String workerId)

      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:
        `releaseResourcesForWorker` in interface `ResourceIsolationInterface`
      Parameters:
        `workerId` - worker id to shutdown and clean up after

    - #### getLaunchCommand

          public List<String> getLaunchCommand(String workerId,
                                               List<String> existingCommand)

      Description copied from interface: `ResourceIsolationInterface`

      After reserving resources for the worker (i.e. calling reserveResourcesForWorker). This function can be used to get the modified command line to launch the worker with resource isolation

      Specified by:
        `getLaunchCommand` in interface `ResourceIsolationInterface`
        `existingCommand` - the current command to run that may need to be modified.
      Returns:
        new commandline with necessary additions to launch worker with resource isolation

    - #### getLaunchCommandPrefix

          public List<String> getLaunchCommandPrefix(String workerId)

      Description copied from interface: `ResourceIsolationInterface`

      After reserving resources for the worker (i.e. calling reserveResourcesForWorker). this function can be used to get the launch command prefix

      Specified by:
        `getLaunchCommandPrefix` in interface `ResourceIsolationInterface`
      Parameters:
        `workerId` - the of the worker
      Returns:
        the command line prefix for launching a worker with resource isolation

    - #### getRunningPids

          public Set<Long> getRunningPids(String workerId)
                                   throws IOException

      Description copied from interface: `ResourceIsolationInterface`

      Get the list of PIDs currently in an isolated container.

      Specified by:
        `getRunningPids` in interface `ResourceIsolationInterface`
      Parameters:
        `workerId` - the id of the worker to get these for
      Returns:
        the set of PIDs, this will be combined with other ways of getting PIDs. An Empty set if no PIDs are found.
      Throws:
        `IOException` - on any error

    - #### getMemoryUsage

          public long getMemoryUsage(String workerId)
                              throws IOException

      Description copied from interface: `ResourceIsolationInterface`

      Get the current memory usage of the a given worker.

      Specified by:
        `getMemoryUsage` in interface `ResourceIsolationInterface`
      Parameters:
        `workerId` - the id of the worker
      Returns:
        the amount of memory the worker is using in bytes or -1 if not supported
      Throws:
        `IOException` - on any error.

    - #### getSystemFreeMemoryMb

          public long getSystemFreeMemoryMb()
                                     throws IOException

      Specified by:
        `getSystemFreeMemoryMb` in interface `ResourceIsolationInterface`
      Returns:
        The amount of memory in bytes that are free on the system. This might not be the entire box, it might be within a parent resource group.
      Throws:
        `IOException` - on any error.

Copyright © 2019 The Apache Software Foundation. All rights reserved.