Class ContainerUtils
java.lang.Object
org.apache.hadoop.ozone.container.common.helpers.ContainerUtils
A mix of helper functions for containers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertSpaceAvailability(long containerId, HddsVolume volume, int sizeRequested) static FilegetChunkDir(ContainerData containerData) Get the chunk directory from the containerData.static StringgetContainerDbFileName(String containerName) static FilegetContainerFile(File containerBaseDir) Get the .container file from the containerBaseDir.static StringgetContainerFileChecksum(String containerDataYamlStr) Return the SHA-256 checksum of the containerData.static longgetContainerID(File containerBaseDir) ContainerID can be decoded from the container base directory name.static longgetContainerIDFromFile(File containerFile) static StringgetContainerNameFromFile(File containerFile) get containerName from a container file.static StringgetContainerTarName(long containerId) static longgetPendingDeletionBlocks(ContainerData containerData) static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProtologAndReturnError(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.static org.apache.hadoop.hdds.protocol.DatanodeDetailsreadDatanodeDetailsFrom(File path) ReadDatanodeDetailsfrom a local ID file.static longretrieveContainerIdFromTarName(String tarName) static voidverifyContainerFileChecksum(ContainerData containerData, org.apache.hadoop.hdds.conf.ConfigurationSource conf) Verify that the checksum stored in containerData is equal to the computed checksum.static voidverifyIsNewContainer(File containerFile) Verifies that this is indeed a new container.static voidwriteDatanodeDetailsTo(org.apache.hadoop.hdds.protocol.DatanodeDetails datanodeDetails, File path, org.apache.hadoop.hdds.conf.ConfigurationSource conf) Persistent aDatanodeDetailsto a local file.
-
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- - Loggerex- - Exceptionrequest- - Request Object- Returns:
- Response
-
getContainerNameFromFile
get containerName from a container file.- Parameters:
containerFile- - File- Returns:
- Name of the container.
-
getContainerIDFromFile
-
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
-
writeDatanodeDetailsTo
public static void writeDatanodeDetailsTo(org.apache.hadoop.hdds.protocol.DatanodeDetails datanodeDetails, File path, org.apache.hadoop.hdds.conf.ConfigurationSource conf) throws IOException Persistent aDatanodeDetailsto a local file.- Throws:
IOException- when read/write error occurs
-
readDatanodeDetailsFrom
public static org.apache.hadoop.hdds.protocol.DatanodeDetails readDatanodeDetailsFrom(File path) throws IOException ReadDatanodeDetailsfrom a local ID file. UseDatanodeDetails.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
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
ContainerID can be decoded from the container base directory name. -
getContainerTarName
-
retrieveContainerIdFromTarName
- Throws:
IOException
-
getPendingDeletionBlocks
-
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
-