diff options
author | Harald Musum <musum@verizonmedia.com> | 2019-07-25 09:31:50 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2019-07-25 09:31:50 +0200 |
commit | 73e4cdb14ccdc75bd140914efddfcc3c53dae075 (patch) | |
tree | de201b050aa98b216d7777a579a1225321808ea3 /config | |
parent | 80dda20918caeee849df00ba9795457e7676c3a2 (diff) |
Version is not used anymore, simplify and cleanup
Diffstat (limited to 'config')
-rw-r--r-- | config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java | 104 | ||||
-rw-r--r-- | config/src/test/java/com/yahoo/vespa/config/util/ConfigUtilsTest.java | 67 |
2 files changed, 26 insertions, 145 deletions
diff --git a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java index f09f8e3a11a..124783756ca 100644 --- a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java +++ b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java @@ -21,17 +21,17 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Utilities for mangling config text, finding md5sums, version numbers in .def files etc. + * Utilities for mangling config text, finding md5sums, finding name and namespace in .def files etc. */ public class ConfigUtils { /* Patterns used for finding ranges in config definitions */ private static final Pattern intPattern = Pattern.compile(".*int.*range.*"); private static final Pattern doublePattern = Pattern.compile(".*double.*range.*"); private static final Pattern spaceBeforeCommaPatter = Pattern.compile("\\s,"); - public static final String intFormattedMax = new DecimalFormat("#.#").format(0x7fffffff); - public static final String intFormattedMin = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.ENGLISH)).format(-0x80000000); - public static final String doubleFormattedMax = new DecimalFormat("#.#").format(1e308); - public static final String doubleFormattedMin = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.ENGLISH)).format(-1e308); + private static final String intFormattedMax = new DecimalFormat("#.#").format(0x7fffffff); + private static final String intFormattedMin = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.ENGLISH)).format(-0x80000000); + private static final String doubleFormattedMax = new DecimalFormat("#.#").format(1e308); + private static final String doubleFormattedMin = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.ENGLISH)).format(-1e308); /** * Computes Md5 hash of a list of strings. The only change to input lines before @@ -198,17 +198,6 @@ public class ConfigUtils { } /** - * Finds the def version from a reader for a def-file. Returns "" (empty string) - * if no version was found. - * - * @param in A reader to a def-file - * @return version of the def-file, or "" (empty string) if no version was found - */ - public static String getDefVersion(Reader in) { - return getDefKeyword(in, "version"); - } - - /** * 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. @@ -223,17 +212,6 @@ public class ConfigUtils { return getDefKeyword(defLines, "namespace"); } - /** - * Finds the value of the keyword in <code>keyword</code> from a reader for a def-file. - * Returns "" (empty string) if no value for keyword was found. - * - * @param in A reader to a def-file - * @return value of keyword, or "" (empty string) if no line matching keyword was found - */ - public static String getDefKeyword(Reader in, String keyword) { - return getDefKeyword(getDefLines(in), keyword); - } - private static String getDefKeyword(List<String> defLines, String keyword) { for (String line : defLines) { if (line.startsWith(keyword)) { @@ -271,16 +249,15 @@ public class ConfigUtils { } /** - * Finds the name and version from a string with "name,version". - * If no name is given, the first part of the tuple will be the empty string - * If no version is given, the second part of the tuple will be the empty string + * Finds the name and namespace part from a string "name.namespace,version", which + * is how it is serialized in zookeeper (versions is always empty) * - * @param nameCommaVersion A string consisting of "name,version" - * @return a Tuple2 with first item being name and second item being version + * @param nameCommaVersion A string consisting of "name.namespace,version" or "name.namespace," + * @return a string with name.namespace */ - public static Tuple2<String, String> getNameAndVersionFromString(String nameCommaVersion) { + private static String getNameFromSerializedString(String nameCommaVersion) { String[] av = nameCommaVersion.split(","); - return new Tuple2<>(av[0], av.length >= 2 ? av[1] : ""); + return av[0]; } /** @@ -302,46 +279,6 @@ public class ConfigUtils { } /** - * Creates a ConfigDefinitionKey based on a string with namespace, name and version - * (e.g. Vespa's own config definitions in $VESPA_HOME/share/vespa/configdefinitions) - * - * @param input A string consisting of "namespace.name.version" - * @return a ConfigDefinitionKey - */ - public static ConfigDefinitionKey getConfigDefinitionKeyFromString(String input) { - final String name; - final String namespace; - if (!input.contains(".")) { - name = input; - namespace = ""; - } else if (input.lastIndexOf(".") == input.indexOf(".")) { - Tuple2<String, String> tuple = ConfigUtils.getNameAndNamespaceFromString(input); - boolean containsVersion = false; - for (int i=0; i < tuple.first.length(); i++) { - if (Character.isDigit(tuple.first.charAt(i))) { - containsVersion = true; - break; - } - } - if (containsVersion) { - name = tuple.second; - namespace = ""; - } else { - name = tuple.first; - namespace = tuple.second; - } - } else { - Tuple2<String, String> tuple = ConfigUtils.getNameAndNamespaceFromString(input); - - String tempName = tuple.second; - tuple = ConfigUtils.getNameAndNamespaceFromString(tempName); - name = tuple.first; - namespace = tuple.second; - } - return new ConfigDefinitionKey(name, namespace); - } - - /** * Creates a ConfigDefinitionKey from a string for the name of a node in ZooKeeper * that holds a config definition * @@ -351,21 +288,13 @@ public class ConfigUtils { public static ConfigDefinitionKey createConfigDefinitionKeyFromZKString(String nodeName) { final String name; final String namespace; - if (nodeName.contains(".")) { - Tuple2<String, String> tuple = ConfigUtils.getNameAndVersionFromString(nodeName); - String tempName = tuple.first; // includes namespace - tuple = ConfigUtils.getNameAndNamespaceFromString(tempName); - name = tuple.first; - namespace = tuple.second; - } else { - Tuple2<String, String> tuple = ConfigUtils.getNameAndVersionFromString(nodeName); - name = tuple.first; - namespace = ""; - } + String tempName = ConfigUtils.getNameFromSerializedString(nodeName); // includes namespace + Tuple2<String, String> tuple = ConfigUtils.getNameAndNamespaceFromString(tempName); + name = tuple.first; + namespace = tuple.second; return new ConfigDefinitionKey(name, namespace); } - /** * 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 @@ -390,7 +319,7 @@ public class ConfigUtils { * @param content content of a config definition * @return a ConfigDefinitionKey */ - public static ConfigDefinitionKey createConfigDefinitionKeyFromDefContent(String name, byte[] content) { + static ConfigDefinitionKey createConfigDefinitionKeyFromDefContent(String name, byte[] content) { String namespace = ConfigUtils.getDefNamespace(new StringReader(Utf8.toString(content))); if (namespace.isEmpty()) { namespace = CNode.DEFAULT_NAMESPACE; @@ -398,7 +327,6 @@ public class ConfigUtils { return new ConfigDefinitionKey(name, namespace); } - /** * Escapes a config value according to the cfg format. * @param input the string to escape diff --git a/config/src/test/java/com/yahoo/vespa/config/util/ConfigUtilsTest.java b/config/src/test/java/com/yahoo/vespa/config/util/ConfigUtilsTest.java index 0b615e59179..5a5a9d1e100 100644 --- a/config/src/test/java/com/yahoo/vespa/config/util/ConfigUtilsTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/util/ConfigUtilsTest.java @@ -114,22 +114,6 @@ public class ConfigUtilsTest { } @Test - public void testGetVersion() { - StringReader reader = new StringReader("version=1\nint a default=0"); - assertThat(ConfigUtils.getDefVersion(reader), is("1")); - - // no version - reader = new StringReader("int a default=0"); - assertThat(ConfigUtils.getDefVersion(reader), is("")); - - // namespace and version - reader = new StringReader("version=1\nnamespace=foo\nint a default=0"); - assertThat(ConfigUtils.getDefVersion(reader), is("1")); - reader = new StringReader("namespace=foo\nversion=1\nint a default=0"); - assertThat(ConfigUtils.getDefVersion(reader), is("1")); - } - - @Test public void testGetNamespace() { StringReader reader = new StringReader("version=1\nnamespace=a\nint a default=0"); assertThat(ConfigUtils.getDefNamespace(reader), is("a")); @@ -154,26 +138,6 @@ public class ConfigUtilsTest { } @Test - public void testGetNameCommaVersion() { - String nameCommaversion = "foo,1"; - Tuple2<String, String> tuple = ConfigUtils.getNameAndVersionFromString(nameCommaversion); - assertThat(tuple.first, is("foo")); - assertThat(tuple.second, is("1")); - - // no version - nameCommaversion = "foo"; - tuple = ConfigUtils.getNameAndVersionFromString(nameCommaversion); - assertThat(tuple.first, is("foo")); - assertThat(tuple.second, is("")); - - // no name - nameCommaversion = ",1"; - tuple = ConfigUtils.getNameAndVersionFromString(nameCommaversion); - assertThat(tuple.first, is("")); - assertThat(tuple.second, is("1")); - } - - @Test public void testNamespaceDotNames() { String namespaceDotName = "foo.bar"; Tuple2<String, String> tuple = ConfigUtils.getNameAndNamespaceFromString(namespaceDotName); @@ -205,29 +169,18 @@ public class ConfigUtilsTest { } @Test - public void testGetConfigDefinitionKey() { - String input = "foo.bar"; - ConfigDefinitionKey def = ConfigUtils.getConfigDefinitionKeyFromString(input); - assertThat(def.getName(), is("bar")); - assertThat(def.getNamespace(), is("foo")); - - input = "foo.bar.1"; - def = ConfigUtils.getConfigDefinitionKeyFromString(input); - assertThat(def.getName(), is("bar")); - assertThat(def.getNamespace(), is("foo")); + public void testCreateConfigDefinitionKeyFromZKString() { + ConfigDefinitionKey def1 = ConfigUtils.createConfigDefinitionKeyFromZKString("bar.foo,1"); + assertThat(def1.getName(), is("foo")); + assertThat(def1.getNamespace(), is("bar")); - input = "foo.bar.qux.2"; - def = ConfigUtils.getConfigDefinitionKeyFromString(input); - assertThat(def.getName(), is("qux")); - assertThat(def.getNamespace(), is("foo.bar")); - } + ConfigDefinitionKey def2 = ConfigUtils.createConfigDefinitionKeyFromZKString("bar.foo,"); + assertThat(def2.getName(), is("foo")); + assertThat(def2.getNamespace(), is("bar")); - @Test - public void testCreateConfigDefinitionKeyFromZKString() { - String input = "bar.foo,1"; - ConfigDefinitionKey def = ConfigUtils.createConfigDefinitionKeyFromZKString(input); - assertThat(def.getName(), is("foo")); - assertThat(def.getNamespace(), is("bar")); + ConfigDefinitionKey def3 = ConfigUtils.createConfigDefinitionKeyFromZKString("bar.foo"); + assertThat(def3.getName(), is("foo")); + assertThat(def3.getNamespace(), is("bar")); } @Test |