Package com.yahoo.vespa.config.util
Class ConfigUtils
java.lang.Object
com.yahoo.vespa.config.util.ConfigUtils
Utilities for mangling config text, finding checksums, finding name and namespace in .def files etc.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigDefinitionKeyCreates a ConfigDefinitionKey from a file by reading the file and parsing contents for namespace.static ConfigDefinitionKeycreateConfigDefinitionKeyFromZKString(String nodeName) Creates a ConfigDefinitionKey from a string for the name of a node in ZooKeeper that holds a config definitionstatic StringescapeConfigFormatValue(String input) Escapes a config value according to the cfg format.static Stringstatic StringComputes Md5 hash of a list of strings with the contents of a def-file.static StringgetDefMd5FromRequest(String defMd5, List<String> defContent) static StringFinds the def package or namespace from a reader for a def-file.static StringgetEnvValue(String defaultValue, String... envVars) Loop through values and return the first one that is set and non-empty.static StringgetMd5(byte[] input) static StringgetMd5(com.yahoo.text.AbstractUtf8Array input) static StringgetNameAndNamespaceFromString(String nameDotNamespace) Finds the name and namespace from a string with "namespace.name".static StringgetXxhash64(com.yahoo.text.AbstractUtf8Array input) static StringgetXxhash64(ConfigPayload payload) static StringgetXxhash64(ByteBuffer input) static booleanisGenerationNewer(long newGen, long oldGen) static StringstripSpaces(String str) Replaces sequences of spaces with 1 space, unless inside quotes.
-
Constructor Details
-
ConfigUtils
public ConfigUtils()
-
-
Method Details
-
getMd5
-
getMd5
-
getMd5
-
getXxhash64
-
getXxhash64
-
getXxhash64
-
stripSpaces
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
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:
- Remove trailing space.
- Remove comment lines.
- Remove trailing comments, and spaces before trailing comments.
- Remove empty lines
- 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
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
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
Escapes a config value according to the cfg format.- Parameters:
input- the string to escape- Returns:
- the escaped string
-
getDefMd5FromRequest
-
getCanonicalHostName
-
getEnvValue
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)
-