org.apache.storm.daemon.logviewer.utils

## Class WorkerLogs

- java.lang.Object
- - org.apache.storm.daemon.logviewer.utils.WorkerLogs

-     public class WorkerLogs
      extends Object

  A class that knows about how to operate with worker log directory.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `WORKER_YAML`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WorkerLogs(Map<String,Object> stormConf, Path logRootDir, StormMetricsRegistry metricsRegistry)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Set<String>` | `getAliveIds(int nowSecs)` Retrieve the set of alive worker IDs.
    `SortedSet<Path>` | `getAliveWorkerDirs()` Return a sorted set of paths that were written by workers that are now active.
    `List<Path>` | `getAllLogsForRootDir()` Return a list of all log files from worker directories in root log directory.
    `Set<Path>` | `getAllWorkerDirs()` Return a set of all worker directories in all topology directories in root log directory.
    `SortedSet<Path>` | `getLogDirs(Set<Path> logDirs, Predicate<String> predicate)` Finds directories for specific worker ids that can be cleaned up.
    `Optional<Path>` | `getMetadataFileForWorkerLogDir(Path logDir)` Return a metadata file (worker.yaml) for given worker log directory.
    `String` | `getTopologyOwnerFromMetadataFile(Path metaFile)` Return topology owner from worker meta file.
    `static String` | `getTopologyPortWorkerLog(Path file)` Return the path of the worker log with the format of topoId/port/worker.log.*
    `String` | `getWorkerIdFromMetadataFile(Path metaFile)` Return worker id from worker meta file.
    `void` | `setLogFilePermission(String fileName)` Set permission of log file so that logviewer can serve the file.

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

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

- - ### Field Detail

    - #### WORKER_YAML

          public static final String WORKER_YAML

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### WorkerLogs

          public WorkerLogs(Map<String,Object> stormConf,
                            Path logRootDir,
                            StormMetricsRegistry metricsRegistry)

      Constructor.

      Parameters:
        `stormConf` - storm configuration
        `logRootDir` - the log root directory
        `metricsRegistry` - The logviewer metrics registry

  - ### Method Detail

    - #### setLogFilePermission

          public void setLogFilePermission(String fileName)
                                    throws IOException

      Set permission of log file so that logviewer can serve the file.

      Parameters:
        `fileName` - log file
      Throws:
        `IOException`

    - #### getAllLogsForRootDir

          public List<Path> getAllLogsForRootDir()
                                          throws IOException

      Return a list of all log files from worker directories in root log directory.

      Throws:
        `IOException`

    - #### getAllWorkerDirs

          public Set<Path> getAllWorkerDirs()

      Return a set of all worker directories in all topology directories in root log directory.

    - #### getAliveWorkerDirs

          public SortedSet<Path> getAliveWorkerDirs()
                                             throws IOException

      Return a sorted set of paths that were written by workers that are now active.

      Throws:
        `IOException`

    - #### getMetadataFileForWorkerLogDir

          public Optional<Path> getMetadataFileForWorkerLogDir(Path logDir)
                                                        throws IOException

      Return a metadata file (worker.yaml) for given worker log directory.

      Parameters:
        `logDir` - worker log directory
      Throws:
        `IOException`

    - #### getWorkerIdFromMetadataFile

          public String getWorkerIdFromMetadataFile(Path metaFile)

      Return worker id from worker meta file.

      Parameters:
        `metaFile` - metadata file

    - #### getTopologyOwnerFromMetadataFile

          public String getTopologyOwnerFromMetadataFile(Path metaFile)

      Return topology owner from worker meta file.

      Parameters:
        `metaFile` - metadata file

    - #### getAliveIds

          public Set<String> getAliveIds(int nowSecs)
                                  throws IOException

      Retrieve the set of alive worker IDs.

      Parameters:
        `nowSecs` - current time in seconds
      Throws:
        `IOException`

    - #### getLogDirs

          public SortedSet<Path> getLogDirs(Set<Path> logDirs,
                                            Predicate<String> predicate)

      Finds directories for specific worker ids that can be cleaned up.

      Parameters:
        `logDirs` - directories to check whether they’re worker directories or not
        `predicate` - a check on a worker id to see if the log dir should be included
      Returns:
        directories that can be cleaned up.

    - #### getTopologyPortWorkerLog

          public static String getTopologyPortWorkerLog(Path file)

      Return the path of the worker log with the format of topoId/port/worker.log.*

      Parameters:
        `file` - worker log

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