Package com.yahoo.vespa.config.util
Class ConfigUtils
- java.lang.Object
-
- com.yahoo.vespa.config.util.ConfigUtils
-
public class ConfigUtils extends java.lang.Object
Utilities for mangling config text, finding md5sums, finding name and namespace in .def files etc.
-
-
Constructor Summary
Constructors Constructor Description ConfigUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConfigDefinitionKey
createConfigDefinitionKeyFromDefFile(java.io.File file)
Creates a ConfigDefinitionKey from a file by reading the file and parsing contents for namespace.static ConfigDefinitionKey
createConfigDefinitionKeyFromZKString(java.lang.String nodeName)
Creates a ConfigDefinitionKey from a string for the name of a node in ZooKeeper that holds a config definitionstatic java.lang.String
escapeConfigFormatValue(java.lang.String input)
Escapes a config value according to the cfg format.static java.lang.String
getCanonicalHostName()
static java.lang.String
getDefMd5(java.util.List<java.lang.String> lines)
Computes Md5 hash of a list of strings with the contents of a def-file.static java.lang.String
getDefMd5FromRequest(java.lang.String defMd5, java.util.List<java.lang.String> defContent)
static java.lang.String
getDefNamespace(java.io.Reader in)
Finds the def package or namespace from a reader for a def-file.static java.lang.String
getEnvValue(java.lang.String defaultValue, java.lang.String... envVars)
Loop through values and return the first one that is set and non-empty.static java.lang.String
getMd5(byte[] input)
static java.lang.String
getMd5(com.yahoo.text.Utf8Array input)
static java.lang.String
getMd5(ConfigPayload payload)
Computes Md5 hash of a list of strings.static java.lang.String
getMd5(java.lang.String input)
Computes Md5 hash of a string.static com.yahoo.collections.Tuple2<java.lang.String,java.lang.String>
getNameAndNamespaceFromString(java.lang.String nameDotNamespace)
Finds the name and namespace from a string with "namespace.name".static boolean
isGenerationNewer(long newGen, long oldGen)
static java.lang.String
stripSpaces(java.lang.String str)
Replaces sequences of spaces with 1 space, unless inside quotes.
-
-
-
Method Detail
-
getMd5
public static java.lang.String getMd5(ConfigPayload payload)
Computes Md5 hash of a list of strings.- Parameters:
payload
- a config payload- Returns:
- the Md5 hash of the list, with lowercase letters
-
getMd5
public static java.lang.String getMd5(java.lang.String input)
Computes Md5 hash of a string.- Parameters:
input
- the input String- Returns:
- the Md5 hash of the input, with lowercase letters
-
getMd5
public static java.lang.String getMd5(com.yahoo.text.Utf8Array input)
-
getMd5
public static java.lang.String getMd5(byte[] input)
-
stripSpaces
public static java.lang.String stripSpaces(java.lang.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 java.lang.String getDefMd5(java.util.List<java.lang.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:
- 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
public static java.lang.String getDefNamespace(java.io.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<java.lang.String,java.lang.String> getNameAndNamespaceFromString(java.lang.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(java.lang.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(java.io.File file) throws java.io.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:
java.io.IOException
-
escapeConfigFormatValue
public static java.lang.String escapeConfigFormatValue(java.lang.String input)
Escapes a config value according to the cfg format.- Parameters:
input
- the string to escape- Returns:
- the escaped string
-
getDefMd5FromRequest
public static java.lang.String getDefMd5FromRequest(java.lang.String defMd5, java.util.List<java.lang.String> defContent)
-
getCanonicalHostName
public static java.lang.String getCanonicalHostName()
-
getEnvValue
public static java.lang.String getEnvValue(java.lang.String defaultValue, java.lang.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)
-
-