Class ConfigUtils

java.lang.Object
com.yahoo.vespa.config.util.ConfigUtils

public class ConfigUtils extends Object
Utilities for mangling config text, finding checksums, finding name and namespace in .def files etc.
  • Constructor Details

    • ConfigUtils

      public ConfigUtils()
  • Method Details

    • getMd5

      public static String getMd5(String input)
    • getMd5

      public static String getMd5(com.yahoo.text.AbstractUtf8Array input)
    • getXxhash64

      public static String getXxhash64(com.yahoo.text.AbstractUtf8Array input)
    • getXxhash64

      public static String getXxhash64(ByteBuffer input)
    • getXxhash64

      public static String getXxhash64(ConfigPayload payload)
    • stripSpaces

      public static String stripSpaces(String str)
      Replaces sequences of spaces with 1 space, unless inside quotes. Public for testing;
      Parameters:
      str - String to strip spaces from
      Returns:
      String with spaces stripped
    • getDefMd5

      public static String getDefMd5(List<String> lines)
      Computes Md5 hash of a list of strings with the contents of a def-file.

      Each string is normalized according to the rules of Vespa config definition files before they are used:

      1. Remove trailing space.
      2. Remove comment lines.
      3. Remove trailing comments, and spaces before trailing comments.
      4. Remove empty lines
      5. Remove 'version=<version-number>'
      Parameters:
      lines - A list of lines constituting a def-file
      Returns:
      the Md5 hash of the list, with lowercase letters
    • getDefNamespace

      public static String getDefNamespace(Reader in)
      Finds the def package or namespace from a reader for a def-file. Returns "" (empty string) if no package or namespace was found. If both package and namespace are declared in the def file, the package is returned.
      Parameters:
      in - A reader to a def-file
      Returns:
      namespace of the def-file, or "" (empty string) if no namespace was found
    • getNameAndNamespaceFromString

      public static com.yahoo.collections.Tuple2<String,String> getNameAndNamespaceFromString(String nameDotNamespace)
      Finds the name and namespace from a string with "namespace.name". namespace may contain dots. If no namespace is given (".name" or just "name"), the second part of the tuple will be the empty string If no name is given, the first part of the tuple will be the empty string
      Parameters:
      nameDotNamespace - A string consisting of "namespace.name"
      Returns:
      a Tuple2 with first item being name and second item being namespace
    • createConfigDefinitionKeyFromZKString

      public static ConfigDefinitionKey createConfigDefinitionKeyFromZKString(String nodeName)
      Creates a ConfigDefinitionKey from a string for the name of a node in ZooKeeper that holds a config definition
      Parameters:
      nodeName - name of a node in ZooKeeper that holds a config definition
      Returns:
      a ConfigDefinitionKey
    • createConfigDefinitionKeyFromDefFile

      public static ConfigDefinitionKey createConfigDefinitionKeyFromDefFile(File file) throws IOException
      Creates a ConfigDefinitionKey from a file by reading the file and parsing contents for namespace. Name and from filename, but the filename may be prefixed with the namespace (if two def files has the same name for instance).
      Parameters:
      file - a config definition file
      Returns:
      a ConfigDefinitionKey
      Throws:
      IOException
    • escapeConfigFormatValue

      public static String escapeConfigFormatValue(String input)
      Escapes a config value according to the cfg format.
      Parameters:
      input - the string to escape
      Returns:
      the escaped string
    • getDefMd5FromRequest

      public static String getDefMd5FromRequest(String defMd5, List<String> defContent)
    • getCanonicalHostName

      public static String getCanonicalHostName()
    • getEnvValue

      public static String getEnvValue(String defaultValue, String... envVars)
      Loop through values and return the first one that is set and non-empty.
      Parameters:
      defaultValue - The default value to use if no environment variables are set.
      envVars - one or more environment variable strings
      Returns:
      a String with the value of the environment variable
    • isGenerationNewer

      public static boolean isGenerationNewer(long newGen, long oldGen)