Class ContainerUtils

java.lang.Object
org.apache.hadoop.ozone.container.common.helpers.ContainerUtils

public final class ContainerUtils extends Object
A mix of helper functions for containers.
  • Method Details

    • logAndReturnError

      public static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto logAndReturnError(org.slf4j.Logger log, org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException ex, org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto request)
      Logs the error and returns a response to the caller.
      Parameters:
      log - - Logger
      ex - - Exception
      request - - Request Object
      Returns:
      Response
    • getContainerNameFromFile

      public static String getContainerNameFromFile(File containerFile)
      get containerName from a container file.
      Parameters:
      containerFile - - File
      Returns:
      Name of the container.
    • getContainerIDFromFile

      public static long getContainerIDFromFile(File containerFile)
    • verifyIsNewContainer

      public static void verifyIsNewContainer(File containerFile) throws org.apache.hadoop.fs.FileAlreadyExistsException
      Verifies that this is indeed a new container.
      Parameters:
      containerFile - - Container File to verify
      Throws:
      org.apache.hadoop.fs.FileAlreadyExistsException
    • getContainerDbFileName

      public static String getContainerDbFileName(String containerName)
    • writeDatanodeDetailsTo

      public static void writeDatanodeDetailsTo(org.apache.hadoop.hdds.protocol.DatanodeDetails datanodeDetails, File path, org.apache.hadoop.hdds.conf.ConfigurationSource conf) throws IOException
      Persistent a DatanodeDetails to a local file.
      Throws:
      IOException - when read/write error occurs
    • readDatanodeDetailsFrom

      public static org.apache.hadoop.hdds.protocol.DatanodeDetails readDatanodeDetailsFrom(File path) throws IOException
      Read DatanodeDetails from a local ID file. Use DatanodeDetails.validateDatanodeIpAddress() to ensure that the IP address matches with the hostname
      Parameters:
      path - ID file local path
      Returns:
      DatanodeDetails
      Throws:
      IOException - If the id file is malformed or other I/O exceptions
    • verifyContainerFileChecksum

      public static void verifyContainerFileChecksum(ContainerData containerData, org.apache.hadoop.hdds.conf.ConfigurationSource conf) throws IOException
      Verify that the checksum stored in containerData is equal to the computed checksum.
      Throws:
      IOException
    • getContainerFileChecksum

      public static String getContainerFileChecksum(String containerDataYamlStr) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Return the SHA-256 checksum of the containerData.
      Parameters:
      containerDataYamlStr - ContainerData as a Yaml String
      Returns:
      Checksum of the container data
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • getContainerFile

      public static File getContainerFile(File containerBaseDir)
      Get the .container file from the containerBaseDir.
      Parameters:
      containerBaseDir - container base directory. The name of this directory is same as the containerID
      Returns:
      the .container file
    • getChunkDir

      public static File getChunkDir(ContainerData containerData) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Get the chunk directory from the containerData.
      Parameters:
      containerData - ContainerData
      Returns:
      the file of chunk directory
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • getContainerID

      public static long getContainerID(File containerBaseDir)
      ContainerID can be decoded from the container base directory name.
    • getContainerTarName

      public static String getContainerTarName(long containerId)
    • retrieveContainerIdFromTarName

      public static long retrieveContainerIdFromTarName(String tarName) throws IOException
      Throws:
      IOException
    • getPendingDeletionBlocks

      public static long getPendingDeletionBlocks(ContainerData containerData)
    • assertSpaceAvailability

      public static void assertSpaceAvailability(long containerId, HddsVolume volume, int sizeRequested) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException