Class ConfigurationUtils

java.lang.Object
com.illumon.util.ConfigurationUtils

public class ConfigurationUtils extends Object
Class to provide functionality that expands on Configuration and adds utility methods for accessing global deephaven installation configuration data.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    findPropertyName(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return the first property name found.
    static String
    findRequiredPropertyValue(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return the first value found.
    static String
    getBinaryLogDir(com.fishlib.configuration.Configuration configuration, boolean createDirectory)
    Get the default directory for binary logs.
    static String
    getBinaryLogDir(com.fishlib.configuration.Configuration configuration, String namespace, String tableName, boolean createDirectory)
    Get the directory for binary logs for a given namespace and table.
    static String
    getBinaryLogDirWithoutValidation(com.fishlib.configuration.Configuration configuration)
    Get the default directory for binary logs.
    static String
    getBinaryLogFile(com.fishlib.configuration.Configuration configuration, boolean createDirectory, String filename)
    Get the directory for binary logs, concatenated with the provided log file name.
    static boolean
    getBooleanWithDefault(com.fishlib.configuration.Configuration configuration, String processName, String propertySuffix, Class<?> className, boolean defaultValue)
    Look for a cascading property value returning the most specified value found as a boolean.
    static String
    Gets the date of the last change associated with current version of Deephaven
    static String
    Gets the year of the last change associated with current version of Deephaven
    static String
    getDirectoryString(com.fishlib.configuration.Configuration configuration, String property)
    Retrieve a property that represents a directory and perform token substitution as in Configuration.normalizeLogDirectoryPath(java.lang.String).
    static <T extends Enum<T>>
    T
    getEnum(com.fishlib.configuration.Configuration config, Class<T> clazz, String property)
    Equivalent to Enum.valueOf(clazz, config.getProperty(property))
    static <T extends Enum<T>>
    EnumSet<T>
    getEnumSet(com.fishlib.configuration.Configuration config, Class<T> clazz, String property)
    Creates the EnumSet based on the string array for the given property.
    static Optional<File>
    getFirstExistingFile(com.fishlib.configuration.Configuration configuration, String property)
    Given a configuration and property splits along , and finds the first File that exists.
    static String
    Gets the Iris Gradle Version.
    static int
    getIntWithDefault(com.fishlib.configuration.Configuration configuration, String processName, String propertySuffix, Class<?> className, int defaultValue)
    Look for a cascading property value returning the most specified value found as an int.
    static long
    getLongWithDefault(com.fishlib.configuration.Configuration configuration, String processName, String propertySuffix, Class<?> className, long defaultValue)
    Look for a cascading property value returning the most specified value found as a long.
    getMapFromProperty(com.fishlib.configuration.Configuration configuration, String property)
    Given a configuration and property splits along , for key=value pairs and turns it into a Map.
    static int
    getPortProperty(com.fishlib.configuration.Configuration configuration, String propertyName)
    Get a property and validate that the value is valid as a port (between 0 and 65535).
    static boolean
    getPossibleBooleanWithDefault(com.fishlib.configuration.Configuration configuration, boolean defaultValue, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return its value if it is found.
    static int
    getPossibleIntegerWithDefault(com.fishlib.configuration.Configuration configuration, int defaultValue, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return its value if it is found.
    static long
    getPossibleLongWithDefault(com.fishlib.configuration.Configuration configuration, long defaultValue, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return its value if it is found.
    static String
    getPossibleStringWithDefault(com.fishlib.configuration.Configuration configuration, String defaultValue, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return its value if it is found.
    static boolean
    getRequiredBoolean(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return the first value found.
    static int
    getRequiredInteger(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
    Look for a property name matching one of the passed-in names, and return the first value found.
    static String
    getResourceString(String resourceName)
    This reads the first line of text from the named resource, assuming the resource is a text file with one line of data
    static List<String>
    getStringPropertyValues(com.fishlib.configuration.Configuration configuration, String propertyPrefix)
    Return a List all values for all properties matching the specified prefix.
    static String
    Gets the VCS Version
    static boolean
    Returns true if the configuration property Kubernetes.deployment is set to true, or if /tmp/k8s-init exists on the filesystem.
    static long
    parseByteQuantity(String quantityString)
    Parse a quantity in the same formats supported by JVM args, e.g.
    static void
    Registers Configuration.getInstance() as an MBean - see ConfigurationDynamicMBean, if the value of the property JMX_REGISTER_CONFIG is true.
    static String
    substitutePath(com.fishlib.configuration.Configuration configuration, String path)
    Replace <devroot> and <workspace> with the paths from configuration
    static String
    Replace <devroot> and <workspace> with the paths from the default configuration's property.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConfigurationUtils

      public ConfigurationUtils()
  • Method Details

    • getMapFromProperty

      public static Optional<Map<String,String>> getMapFromProperty(com.fishlib.configuration.Configuration configuration, String property)
      Given a configuration and property splits along , for key=value pairs and turns it into a Map. If the property is not specified, then an empty optional is returned.
      Parameters:
      configuration - configuration option to retrieve the property from.
      property - the property name to fetch
      Returns:
      an Optional with the map derived from the property.
    • getFirstExistingFile

      public static Optional<File> getFirstExistingFile(com.fishlib.configuration.Configuration configuration, String property)
      Given a configuration and property splits along , and finds the first File that exists.
      Parameters:
      configuration - configuration option to retrieve the property from.
      property - the property name to fetch
      Returns:
      an Optional with the File derived from the property.
    • getPossibleLongWithDefault

      public static long getPossibleLongWithDefault(com.fishlib.configuration.Configuration configuration, long defaultValue, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return its value if it is found. If values are found for multiple of the specified names, throw an exception. If a matching property is found it will be parsed into a long.
      Parameters:
      configuration - the Configuration instance
      defaultValue - default value to be returned if none of the properties are found
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's value, or defaultValue if none of the properties are found
    • getPossibleStringWithDefault

      public static String getPossibleStringWithDefault(com.fishlib.configuration.Configuration configuration, String defaultValue, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return its value if it is found. If values are found for multiple of the specified names, throw an exception.
      Parameters:
      configuration - the Configuration instance
      defaultValue - default value to be returned if none of the properties are found
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's value, or defaultValue if none of the properties are found
    • getRequiredInteger

      public static int getRequiredInteger(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return the first value found. If no values are found, throw an exception.. If a matching property is found it will be parsed into an int.
      Parameters:
      configuration - the Configuration instance
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's value, or defaultValue if none of the properties are found
    • getPossibleIntegerWithDefault

      public static int getPossibleIntegerWithDefault(com.fishlib.configuration.Configuration configuration, int defaultValue, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return its value if it is found. If values are found for multiple of the specified names, throw an exception. If a matching property is found it will be parsed into an int.
      Parameters:
      configuration - the Configuration instance
      defaultValue - default value to be returned if none of the properties are found
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's value, or defaultValue if none of the properties are found
    • getRequiredBoolean

      public static boolean getRequiredBoolean(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return the first value found. If no values are found, throw an exception.. If a matching property is found it will be parsed into a boolean.
      Parameters:
      configuration - the Configuration instance
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's value, or defaultValue if none of the properties are found
    • getPossibleBooleanWithDefault

      public static boolean getPossibleBooleanWithDefault(com.fishlib.configuration.Configuration configuration, boolean defaultValue, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return its value if it is found. If values are found for multiple of the specified names, throw an exception. If a matching property is found it will be parsed into an boolean.
      Parameters:
      configuration - the Configuration instance
      defaultValue - default value to be returned if none of the properties are found
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's value, or defaultValue if none of the properties are found
    • findRequiredPropertyValue

      public static String findRequiredPropertyValue(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return the first value found. If no values are found, throw an exception.
      Parameters:
      configuration - the Configuration instance
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's value
      Throws:
      IllegalArgumentException - if no value is found for any of the specified property names
    • findPropertyName

      public static String findPropertyName(com.fishlib.configuration.Configuration configuration, String... possiblePropertyNames)
      Look for a property name matching one of the passed-in names, and return the first property name found. If no values are found, return null.
      Parameters:
      configuration - the Configuration instance
      possiblePropertyNames - the possible property names, in order of preference (a property name later in the properties is deprecated by one earlier)
      Returns:
      the found property's name
    • getDirectoryString

      public static String getDirectoryString(com.fishlib.configuration.Configuration configuration, String property)
      Retrieve a property that represents a directory and perform token substitution as in Configuration.normalizeLogDirectoryPath(java.lang.String).
      Parameters:
      configuration - configuration option to retrieve the property from.
      property - the property name to fetch
      Returns:
      the retrieved property, with the substitutions performed
    • substitutePath

      public static String substitutePath(com.fishlib.configuration.Configuration configuration, String path)
      Replace <devroot> and <workspace> with the paths from configuration
      Parameters:
      configuration - the configuration object to retrieve the devroot and workspace path from
      path - the path to substitute values in
      Returns:
      the path with values substituted
    • substitutePathFromProperty

      public static String substitutePathFromProperty(String property)
      Replace <devroot> and <workspace> with the paths from the default configuration's property.
      Parameters:
      property - that contains the path to substitute values in
      Returns:
      the path with values substituted
    • getPortProperty

      public static int getPortProperty(com.fishlib.configuration.Configuration configuration, String propertyName)
      Get a property and validate that the value is valid as a port (between 0 and 65535).
      Parameters:
      configuration - the Configuration to use
      propertyName - the property name
      Returns:
      a valid port, or throws a runtime exception
    • getStringPropertyValues

      public static List<String> getStringPropertyValues(com.fishlib.configuration.Configuration configuration, String propertyPrefix)
      Return a List all values for all properties matching the specified prefix. Properties that map to empty values are not returned in the list. The values in the list will be sorted by property name.
      Parameters:
      configuration - the Configuration instance
      propertyPrefix - the property prefix
      Returns:
      the List of matching string values, or an empty list if none is found
    • getBooleanWithDefault

      public static boolean getBooleanWithDefault(com.fishlib.configuration.Configuration configuration, String processName, String propertySuffix, Class<?> className, boolean defaultValue)
      Look for a cascading property value returning the most specified value found as a boolean. Properties are checked in this order of preference:
      1. {className}.{processName}{propertySuffix}
      2. {processName}{propertySuffix}
      3. {className}{propertySuffix}
      4. defaultValue
      Parameters:
      configuration - the Configuration to use
      processName - the process name
      propertySuffix - the property suffix (begin with a . or other separator if desired)
      className - the class name (className.getSimpleName() will be used)
      defaultValue - the default value to be used if no matching properties are defined
      Returns:
      the determined value
    • getIntWithDefault

      public static int getIntWithDefault(com.fishlib.configuration.Configuration configuration, String processName, String propertySuffix, Class<?> className, int defaultValue)
      Look for a cascading property value returning the most specified value found as an int. Properties are checked in this order of preference:
      1. {className}.{processName}{propertySuffix}
      2. {processName}{propertySuffix}
      3. {className}{propertySuffix}
      4. defaultValue
      Parameters:
      configuration - the Configuration to use
      processName - the process name
      propertySuffix - the property suffix (begin with a . or other separator if desired)
      className - the class name (className.getSimpleName() will be used)
      defaultValue - the default value to be used if no matching properties are defined
      Returns:
      the determined value
    • getLongWithDefault

      public static long getLongWithDefault(com.fishlib.configuration.Configuration configuration, String processName, String propertySuffix, Class<?> className, long defaultValue)
      Look for a cascading property value returning the most specified value found as a long. Properties are checked in this order of preference:
      1. {className}.{processName}{propertySuffix}
      2. {processName}{propertySuffix}
      3. {className}{propertySuffix}
      4. defaultValue
      Parameters:
      configuration - the Configuration to use
      processName - the process name
      propertySuffix - the property suffix (begin with a . or other separator if desired)
      className - the class name (className.getSimpleName() will be used)
      defaultValue - the default value to be used if no matching properties are defined
      Returns:
      the determined value
    • getBinaryLogDir

      public static String getBinaryLogDir(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull String namespace, @NotNull String tableName, boolean createDirectory) throws IOException
      Get the directory for binary logs for a given namespace and table. Create it if it doesn't exist and createDirectory is true. Look for properties in the following order:
      1. BINARY_LOG_DIR_PROPERTY.namespace.tableName
      2. BINARY_LOG_DIR_PROPERTY.namespace
      3. BINARY_LOG_DIR_PROPERTY
      If the properties can't be found, use Configuration.getLogDir(), otherwise perform substitution and normalization with Configuration.normalizeLogDirectoryPath(java.lang.String).
      Parameters:
      configuration - the Configuration to use
      namespace - the namespace for the binary log
      tableName - the table name for the binary log
      createDirectory - if true, create the directory if it doesn't exist
      Returns:
      the directory name
      Throws:
      IOException - if the path exists and is not a directory, if the path doesn't exist and createDirectory is false, or if the path doesn't exist and can't be created
    • getBinaryLogFile

      public static String getBinaryLogFile(com.fishlib.configuration.Configuration configuration, boolean createDirectory, String filename) throws IOException
      Get the directory for binary logs, concatenated with the provided log file name. Create it if it doesn't exist and createDirectory is true. Use the property BINARY_LOG_DIR_PROPERTY to retrieve the directory name, and if this property doesn't exist use Configuration.getLogDir(). Perform substitution and normalization with Configuration.normalizeLogDirectoryPath(java.lang.String).
      Parameters:
      configuration - the Configuration to use
      createDirectory - if true, create the directory if it doesn't exist
      filename - the name of the binary log file
      Returns:
      the binary log directory name concatenated with the filename
      Throws:
      IOException - if the path exists and is not a directory, if the path doesn't exist and createDirectory is false, or if the path doesn't exist and can't be created
    • getBinaryLogDir

      public static String getBinaryLogDir(com.fishlib.configuration.Configuration configuration, boolean createDirectory) throws IOException
      Get the default directory for binary logs. Create it if it doesn't exist and createDirectory is true. Use the property BINARY_LOG_DIR_PROPERTY to retrieve the directory name, and if this property doesn't exist use Configuration.getLogDir(). Perform substitution and normalization with Configuration.normalizeLogDirectoryPath(java.lang.String).
      Parameters:
      configuration - the Configuration to use
      createDirectory - if true, create the directory if it doesn't exist
      Returns:
      the directory name
      Throws:
      IOException - if the path exists and is not a directory, if the path doesn't exist and createDirectory is false, or if the path doesn't exist and can't be created
    • getBinaryLogDirWithoutValidation

      public static String getBinaryLogDirWithoutValidation(com.fishlib.configuration.Configuration configuration) throws IOException
      Get the default directory for binary logs. Do not validate that it exists or create it. Use the property BINARY_LOG_DIR_PROPERTY to retrieve the directory name, and if this property doesn't exist use Configuration.getLogDir(). Perform substitution and normalization with Configuration.normalizeLogDirectoryPath(java.lang.String).
      Parameters:
      configuration - the Configuration to use
      Returns:
      the directory name
      Throws:
      IOException - from the directory calls
    • getEnum

      public static <T extends Enum<T>> T getEnum(com.fishlib.configuration.Configuration config, Class<T> clazz, String property)
      Equivalent to Enum.valueOf(clazz, config.getProperty(property))
      Throws:
      IllegalArgumentException - if the value is invalid according to Enum.valueOf(Class, String)
    • getEnumSet

      public static <T extends Enum<T>> EnumSet<T> getEnumSet(com.fishlib.configuration.Configuration config, Class<T> clazz, String property)
      Creates the EnumSet based on the string array for the given property. If the given property doesn't exist, the returned set will be empty. Each item in the array is converted into the enum via the equivalent of Enum.valueOf(clazz, value).
      Throws:
      IllegalArgumentException - if the value is invalid according to Enum.valueOf(Class, String)
    • registerStaticConfigMBean

      public static void registerStaticConfigMBean(AuditEventLoggerBasic audit)
      Registers Configuration.getInstance() as an MBean - see ConfigurationDynamicMBean, if the value of the property JMX_REGISTER_CONFIG is true.
    • parseByteQuantity

      public static long parseByteQuantity(@NotNull String quantityString)
      Parse a quantity in the same formats supported by JVM args, e.g. -Xmx (Format: -Xmx<size>[g|G|m|M|k|K]).
      Parameters:
      quantityString - The quantity in String form
      Returns:
      The result byte quantity
    • getResourceString

      @Nullable public static String getResourceString(String resourceName)
      This reads the first line of text from the named resource, assuming the resource is a text file with one line of data
      Parameters:
      resourceName - the resource name
      Returns:
      the resource string or undetermined if it cannot be found.
    • getGradleVersion

      public static String getGradleVersion()
      Gets the Iris Gradle Version.
      Returns:
      the Iris Gradle Version
    • getVcsVersion

      public static String getVcsVersion()
      Gets the VCS Version
      Returns:
      the VCS Version
    • getDeephavenUpdateDate

      @NotNull public static String getDeephavenUpdateDate()
      Gets the date of the last change associated with current version of Deephaven
      Returns:
      the last updated date when successful or empty string
    • getDeephavenUpdateYear

      @NotNull public static String getDeephavenUpdateYear()
      Gets the year of the last change associated with current version of Deephaven
      Returns:
      the Year extracted from last update date or empty string
    • isKubernetesDeployment

      public static boolean isKubernetesDeployment()
      Returns true if the configuration property Kubernetes.deployment is set to true, or if /tmp/k8s-init exists on the filesystem.
      Returns:
      true if the system is deployed in a Kubernetes environment