Class Container

All Implemented Interfaces:
Direct Known Subclasses:
BasicContainer, LocalContainer

public abstract class Container extends Object implements Killable
Represents a container that a worker will run in.
  • Field Details

    • conf

      protected final Map<String,Object> conf
    • topoConf

      protected final Map<String,Object> topoConf
    • topologyId

      protected final String topologyId
    • supervisorId

      protected final String supervisorId
    • supervisorPort

      protected final int supervisorPort
    • port

      protected final int port
    • assignment

      protected final LocalAssignment assignment
    • ops

      protected final AdvancedFSOps ops
    • resourceIsolationManager

      protected final ResourceIsolationInterface resourceIsolationManager
    • symlinksDisabled

      protected final boolean symlinksDisabled
    • workerId

      protected String workerId
    • type

      protected Container.ContainerType type
    • containerMemoryTracker

      protected ContainerMemoryTracker containerMemoryTracker
    • runAsUser

      protected boolean runAsUser
  • Constructor Details

    • Container

      protected Container(Container.ContainerType type, Map<String,Object> conf, String supervisorId, int supervisorPort, int port, LocalAssignment assignment, ResourceIsolationInterface resourceIsolationManager, String workerId, Map<String,Object> topoConf, AdvancedFSOps ops, StormMetricsRegistry metricsRegistry, ContainerMemoryTracker containerMemoryTracker) throws IOException
      Create a new Container.
      type - the type of container being made.
      conf - the supervisor config
      supervisorId - the ID of the supervisor this is a part of.
      supervisorPort - the thrift server port of the supervisor this is a part of.
      port - the port the container is on. Should be <= 0 if only a partial recovery @param assignment the assignment for this container. Should be null if only a partial recovery.
      resourceIsolationManager - used to isolate resources for a container can be null if no isolation is used.
      workerId - the id of the worker to use. Must not be null if doing a partial recovery.
      topoConf - the config of the topology (mostly for testing) if null and not a partial recovery the real conf is read.
      ops - file system operations (mostly for testing) if null a new one is made
      metricsRegistry - The metrics registry.
      containerMemoryTracker - The shared memory tracker for the supervisor's containers
      IOException - on any error.
  • Method Details

    • toString

      public String toString()
      toString in class Object
    • readTopoConf

      protected Map<String,Object> readTopoConf() throws IOException
    • kill

      public void kill() throws IOException
      Description copied from interface: Killable
      Kill the processes in this container nicely. kill -15 equivalent
      Specified by:
      kill in interface Killable
      IOException - on any error
    • forceKill

      public void forceKill() throws IOException
      Description copied from interface: Killable
      Kill the processes in this container violently. kill -9 equivalent
      Specified by:
      forceKill in interface Killable
      IOException - on any error
    • readHeartbeat

      public LSWorkerHeartbeat readHeartbeat() throws IOException
      Read the Heartbeat for the current container.
      the Heartbeat
      IOException - on any error
    • areAllProcessesDead

      public boolean areAllProcessesDead() throws IOException
      Description copied from interface: Killable
      Check whether all processes are dead.
      Specified by:
      areAllProcessesDead in interface Killable
      true if all of the processes are dead, else false
      IOException - on any error
    • cleanUp

      public void cleanUp() throws IOException
      Description copied from interface: Killable
      Clean up the container. It is not coming back. by default do the same thing as when restarting.
      Specified by:
      cleanUp in interface Killable
      IOException - on any error
    • setup

      protected void setup() throws IOException
      Setup the container to run. By default this creates the needed directories/links in the local file system PREREQUISITE: All needed blobs and topology, jars/configs have been downloaded and placed in the appropriate locations
      IOException - on any error
    • writeLogMetadata

      protected void writeLogMetadata(String user) throws IOException
      Write out the file used by the log viewer to allow/reject log access.
      user - the user this is going to run as
      IOException - on any error
    • createArtifactsLink

      protected void createArtifactsLink() throws IOException
      Create symlink from the containers directory/artifacts to the artifacts directory.
      IOException - on any error
    • createBlobstoreLinks

      protected void createBlobstoreLinks() throws IOException
      Create symlinks for each of the blobs from the container's directory to corresponding links in the storm dist directory.
      IOException - on any error.
    • getWorkerUser

      protected String getWorkerUser() throws IOException
      Get the user of the worker.
      the user that some operations should be done as.
      IOException - on any error
    • saveWorkerUser

      protected void saveWorkerUser(String user) throws IOException
    • deleteSavedWorkerUser

      protected void deleteSavedWorkerUser() throws IOException
    • cleanUpForRestart

      public void cleanUpForRestart() throws IOException
      Clean up the container partly preparing for restart. By default delete all of the temp directories we are going to get a new worker_id anyways. POST CONDITION: the workerId will be set to null
      IOException - on any error
    • isMemoryLimitViolated

      public boolean isMemoryLimitViolated(LocalAssignment withUpdatedLimits) throws IOException
      Check if the container is over its memory limit AND needs to be killed. This does not necessarily mean that it just went over the limit.
      IOException - on any error
    • updateMemoryAccounting

      protected void updateMemoryAccounting()
    • getTotalTopologyMemoryUsed

      public long getTotalTopologyMemoryUsed()
      Get the total memory used (on and off heap).
    • getTotalTopologyMemoryReserved

      public long getTotalTopologyMemoryReserved(LocalAssignment withUpdatedLimits)
      Get the total memory reserved.
      withUpdatedLimits - the local assignment with shared memory
      the total memory reserved.
    • getTotalWorkersForThisTopology

      public long getTotalWorkersForThisTopology()
      Get the number of workers for this topology.
    • getMemoryUsageMb

      public long getMemoryUsageMb()
      Get the current memory usage of this container.
    • getMemoryReservationMb

      public long getMemoryReservationMb()
      Get the current memory reservation of this container.
    • launch

      public abstract void launch() throws IOException
      Launch the process for the first time. PREREQUISITE: setup has run and passed
      IOException - on any error
    • relaunch

      public abstract void relaunch() throws IOException
      Restart the processes in this container. PREREQUISITE: cleanUpForRestart has run and passed
      IOException - on any error
    • didMainProcessExit

      public abstract boolean didMainProcessExit()
      Return true if the main process exited, else false. This is just best effort return false if unknown.
    • runProfiling

      public abstract boolean runProfiling(ProfileRequest request, boolean stop) throws IOException, InterruptedException
      Run a profiling request.
      request - the request to run
      stop - is this a stop request?
      true if it succeeded, else false
      IOException - on any error
      InterruptedException - if running the command is interrupted.
    • getWorkerId

      public String getWorkerId()
      Get the id of the container or null if there is no worker id right now.