Class StorageUtils


  • public final class StorageUtils
    extends Object
    Utility class for implementations of Storage.
    • Method Detail

      • getDBDirectory

        public static Path getDBDirectory​(String parentDbDirectory,
                                          String backendId,
                                          ServerContext serverContext)
        Returns a database directory file from the provided parent database directory and backendId.
        Parameters:
        parentDbDirectory - the parent database directory
        backendId - the backend id
        serverContext - the server context
        Returns:
        a database directory file where to store data for the provided backendId
      • setupStorageFiles

        public static void setupStorageFiles​(Path backendDir,
                                             String dbDirPermissions,
                                             Dn configDN)
                                      throws ConfigException
        Ensure backendDir exists (creating it if not) and has the specified dbDirPermissions.
        Parameters:
        backendDir - the backend directory where to set the storage files
        dbDirPermissions - the permissions to set for the database directory
        configDN - the backend configuration DN
        Throws:
        ConfigException - if configuration fails
      • checkDBDirExistsOrCanCreate

        public static void checkDBDirExistsOrCanCreate​(Path backendDir,
                                                       ConfigChangeResult ccr,
                                                       boolean cleanup)
        Checks a directory exists or can actually be created.
        Parameters:
        backendDir - the directory to check for
        ccr - the list of reasons to return upstream or null if called from setupStorage()
        cleanup - true if the directory should be deleted after creation
      • checkDBDirPermissions

        public static void checkDBDirPermissions​(String dbDirPermissions,
                                                 Dn configDN,
                                                 ConfigChangeResult ccr)
        Returns false if directory permissions in the configuration are invalid. Otherwise returns the same value as it was passed in.
        Parameters:
        dbDirPermissions - the permissions to set for the database directory
        configDN - the backend configuration DN
        ccr - the current list of change results
      • setDBDirPermissions

        public static void setDBDirPermissions​(Path backendDir,
                                               String dbDirPermissions,
                                               Dn configDN,
                                               ConfigChangeResult ccr)
        Sets files permissions on the backend directory.
        Parameters:
        backendDir - the directory to setup
        dbDirPermissions - the permissions to set for the database directory
        configDN - the backend configuration DN
        ccr - the current list of change results
      • addErrorMessage

        public static void addErrorMessage​(ConfigChangeResult ccr,
                                           LocalizableMessage message)
        Adds the provided message to the provided config change result.
        Parameters:
        ccr - the config change result
        message - the message to add
      • removeStorageFiles

        public static void removeStorageFiles​(Path backendDir)
        Removes the storage files from the provided backend directory.
        Parameters:
        backendDir - the backend directory where to remove storage files
      • statusWhenDiskSpaceFull

        public static StorageStatus statusWhenDiskSpaceFull​(File directory,
                                                            long thresholdInBytes,
                                                            String backendId)
        Creates a new unusable StorageStatus for the disk full threshold.
        Parameters:
        directory - the directory which reached the disk full threshold
        thresholdInBytes - the threshold in bytes
        backendId - the backend id
        Returns:
        a new unusable StorageStatus
      • statusWhenDiskSpaceLow

        public static StorageStatus statusWhenDiskSpaceLow​(File directory,
                                                           long thresholdInBytes,
                                                           String backendId)
        Creates a new locked down StorageStatus for the disk low threshold.
        Parameters:
        directory - the directory which reached the disk low threshold
        thresholdInBytes - the threshold in bytes
        backendId - the backend id
        Returns:
        a new locked down StorageStatus