diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-08-23 11:24:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-08-23 11:24:44 +0200 |
commit | 4ea1e9e228f2cce531d67cb0b21bbd4fd303f43b (patch) | |
tree | 9ce68dd771a6937b8d4919a50231431592cf93d4 /config-model/src | |
parent | 207f2963125c9094d65f50f5ea41d98cf3ba8524 (diff) |
Remove dead code
Diffstat (limited to 'config-model/src')
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java | 3 | ||||
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java (renamed from config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfig.java) | 17 | ||||
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigBertBaseTransformer.java | 40 | ||||
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigTransformer.java | 101 | ||||
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderOption.java | 193 | ||||
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java | 5 |
6 files changed, 8 insertions, 351 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 0ba3ae7eca9..213c2ca5df0 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -83,7 +83,6 @@ import com.yahoo.vespa.model.container.search.ContainerSearch; import com.yahoo.vespa.model.container.search.PageTemplates; import com.yahoo.vespa.model.container.search.searchchain.SearchChains; import com.yahoo.vespa.model.container.xml.document.DocumentFactoryBuilder; -import com.yahoo.vespa.model.container.xml.embedder.EmbedderConfig; import com.yahoo.vespa.model.content.StorageGroup; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -355,7 +354,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private static void addEmbedderComponents(DeployState deployState, ApplicationContainerCluster cluster, Element spec) { for (Element node : XML.getChildren(spec, "embedder")) { - Element transformed = EmbedderConfig.transform(deployState, node); + Element transformed = EmbedderConfigTransformer.transform(deployState, node); cluster.addComponent(new DomComponentBuilder().build(deployState, cluster, transformed)); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfig.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java index f28776fd0ae..82ce8070c29 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfig.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java @@ -1,11 +1,10 @@ -package com.yahoo.vespa.model.container.xml.embedder; +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.container.xml; import com.yahoo.config.model.deploy.DeployState; import com.yahoo.text.XML; import org.w3c.dom.Element; -import java.util.Map; - /** * Translates config in services.xml of the form * @@ -24,8 +23,9 @@ import java.util.Map; * with some added interpretations based on recognizing the class. * * @author lesters + * @author bratseth */ -public class EmbedderConfig { +public class EmbedderConfigTransformer { // Until we have optional path parameters, use services.xml as it is guaranteed to exist private final static String dummyPath = "services.xml"; @@ -80,13 +80,6 @@ public class EmbedderConfig { parent.appendChild(element); } - private static EmbedderConfigTransformer getEmbedderTransformer(Element spec, boolean hosted) { - return switch (embedderConfigFrom(spec)) { - case "embedding.bert-base-embedder" -> new EmbedderConfigBertBaseTransformer(spec, hosted); - default -> new EmbedderConfigTransformer(spec, hosted); - }; - } - private static String embedderConfigFrom(Element spec) { String explicitDefinition = spec.getAttribute("def"); if ( ! explicitDefinition.isEmpty()) return explicitDefinition; @@ -98,7 +91,7 @@ public class EmbedderConfig { }; } - static String modelIdToUrl(String id) { + private static String modelIdToUrl(String id) { switch (id) { case "test-model-id": return "test-model-url"; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigBertBaseTransformer.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigBertBaseTransformer.java deleted file mode 100644 index 9431926d088..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigBertBaseTransformer.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.yahoo.vespa.model.container.xml.embedder; - -import org.w3c.dom.Element; - -import java.util.Map; - -/** - * Transforms embedding configuration to component configuration for the - * BertBaseEmbedder using embedder.bert-base-embedder.def - * - * @author lesters - */ -public class EmbedderConfigBertBaseTransformer extends EmbedderConfigTransformer { - - private static final String BUNDLE = "model-integration"; - private static final String DEF = "embedding.bert-base-embedder"; - - public EmbedderConfigBertBaseTransformer(Element spec, boolean hosted) { - super(spec, hosted, BUNDLE, DEF); - - EmbedderOption.Builder modelOption = new EmbedderOption.Builder() - .name("model") - .required(true) - .optionTransformer(new EmbedderOption.ModelOptionTransformer("transformerModelPath", "transformerModelUrl")); - EmbedderOption.Builder vocabOption = new EmbedderOption.Builder() - .name("vocab") - .required(true) - .optionTransformer(new EmbedderOption.ModelOptionTransformer("tokenizerVocabPath", "tokenizerVocabUrl")); - - // Defaults - if (hosted) { - modelOption.attributes(Map.of("id", "minilm-l6-v2")).value(""); - vocabOption.attributes(Map.of("id", "bert-base-uncased")).value(""); - } - - addOption(modelOption.build()); - addOption(vocabOption.build()); - } - -} diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigTransformer.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigTransformer.java deleted file mode 100644 index efb1aafdbe3..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderConfigTransformer.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.yahoo.vespa.model.container.xml.embedder; - -import com.yahoo.config.model.deploy.DeployState; -import com.yahoo.text.XML; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - - -/** - * A specific embedder to component configuration transformer. - * - * @author lesters - */ -public class EmbedderConfigTransformer { - - private final Document doc = XML.getDocumentBuilder().newDocument(); - - private final String id; - private final String className; - private final String bundle; - private final String def; - private final Map<String, EmbedderOption> options = new HashMap<>(); - - public EmbedderConfigTransformer(Element spec, boolean hosted) { - this(spec, hosted, null, null); - } - - public EmbedderConfigTransformer(Element spec, boolean hosted, String defaultBundle, String defaultDef) { - id = spec.getAttribute("id"); - className = spec.hasAttribute("class") ? spec.getAttribute("class") : id; - bundle = spec.hasAttribute("bundle") ? spec.getAttribute("bundle") : defaultBundle; - def = spec.hasAttribute("def") ? spec.getAttribute("def") : defaultDef; - - if (className == null || className.length() == 0) { - throw new IllegalArgumentException("Embedder class is empty"); - } - if (this.bundle == null || this.bundle.length() == 0) { - throw new IllegalArgumentException("Embedder configuration requires a bundle name"); - } - if (this.def == null || this.def.length() == 0) { - throw new IllegalArgumentException("Embedder configuration requires a config definition name"); - } - } - - Element createComponentConfig(DeployState deployState) { - checkRequiredOptions(); - - Element component = doc.createElement("component"); - component.setAttribute("id", id); - component.setAttribute("class", className); - component.setAttribute("bundle", bundle); - - if (options.size() > 0) { - Element config = doc.createElement("config"); - config.setAttribute("name", def); - for (Map.Entry<String, EmbedderOption> entry : options.entrySet()) { - entry.getValue().toElement(deployState, config); - } - component.appendChild(config); - } - - return component; - } - - // TODO: support nested options - void addOption(Element elem) { - String name = elem.getTagName(); - - EmbedderOption.Builder builder = new EmbedderOption.Builder(); - builder.name(name); - builder.value(elem.getTextContent()); - builder.attributes(elem); - - if (options.containsKey(name)) { - builder.required(options.get(name).required()); - builder.optionTransformer(options.get(name).optionTransformer()); - } - options.put(name, builder.build()); - } - - void addOption(EmbedderOption option) { - options.put(option.name(), option); - } - - private void checkRequiredOptions() { - var missingOptions = options.values() - .stream() - .filter(option -> ! option.isSet()) - .map(option -> option.name()) - .collect(Collectors.toList()); - if (missingOptions.size() > 0) - throw new IllegalArgumentException("Embedder '" + className + "' requires options for " + missingOptions); - } - -} diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderOption.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderOption.java deleted file mode 100644 index 715c3d9ef34..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/embedder/EmbedderOption.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.yahoo.vespa.model.container.xml.embedder; - -import com.yahoo.config.model.deploy.DeployState; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; - -import java.util.HashMap; -import java.util.Map; - - -/** - * Holds options for embedder configuration. This includes code for handling special - * options such as model specifiers. - * - * @author lesters - */ -public class EmbedderOption { - - public static final OptionTransformer defaultOptionTransformer = new OptionTransformer(); - - private final String name; - private final boolean required; - private final String value; - private final Map<String, String> attributes; - private final OptionTransformer optionTransformer; - private final boolean set; - - private EmbedderOption(Builder builder) { - this.name = builder.name; - this.required = builder.required; - this.value = builder.value; - this.attributes = builder.attributes; - this.optionTransformer = builder.optionTransformer; - this.set = builder.set; - } - - public void toElement(DeployState deployState, Element parent) { - optionTransformer.transform(deployState, parent, this); - } - - public String name() { - return name; - } - - public String value() { - return value; - } - - public boolean required() { - return required; - } - - public OptionTransformer optionTransformer() { - return optionTransformer; - } - - public boolean isSet() { - return set; - } - - @Override - public String toString() { - return "embedder option '" + name + "'"; - } - - /** - * Basic option transformer. No special handling of options. - */ - public static class OptionTransformer { - - public void transform(DeployState deployState, Element parent, EmbedderOption option) { - if (option.value().isEmpty()) - createElement(parent, option.name(), option.attributes.get("path")); // always understand path=".." - else - createElement(parent, option.name(), option.value()); - } - - public static Element createElement(Element parent, String name, String value) { - Element element = parent.getOwnerDocument().createElement(name); - element.setTextContent(value); - parent.appendChild(element); - return element; - } - } - - /** - * Transforms model options of type <x id="..." url="..." path="..." /> to the - * required fields in the config definition. - */ - public static class ModelOptionTransformer extends OptionTransformer { - - private final String pathField; - private final String urlField; - - public ModelOptionTransformer(String pathField, String urlField) { - super(); - this.pathField = pathField; - this.urlField = urlField; - } - - @Override - public void transform(DeployState deployState, Element parent, EmbedderOption option) { - String id = option.attributes.get("id"); - String url = option.attributes.get("url"); - String path = option.attributes.get("path"); - - // Always use path if it is set - if (path != null && path.length() > 0) { - createElement(parent, pathField, path); - createElement(parent, urlField, ""); - return; - } - - // Only use the id if we're on cloud - if (deployState.isHosted() && id != null && id.length() > 0) { - createElement(parent, urlField, EmbedderConfig.modelIdToUrl(id)); - createElement(parent, pathField, createDummyPath(deployState)); - return; - } - - // Otherwise, use url - if (url != null && url.length() > 0) { - createElement(parent, urlField, url); - createElement(parent, pathField, createDummyPath(deployState)); - return; - } - - if ( ! deployState.isHosted() && id != null && id.length() > 0) { - throw new IllegalArgumentException("Model option 'id' is not valid here"); - } - throw new IllegalArgumentException("Model option requires either a 'path' or a 'url' attribute"); - } - - private String createDummyPath(DeployState deployState) { - // For now, until we have optional config parameters, return services.xml as it is guaranteed to exist - return "services.xml"; - } - - } - - public static class Builder { - private String name = ""; - private boolean required = false; - private String value = ""; - private Map<String, String> attributes = Map.of(); - private OptionTransformer optionTransformer = defaultOptionTransformer; - private boolean set = false; - - public Builder name(String name) { - this.name = name; - return this; - } - - public Builder required(boolean required) { - this.required = required; - return this; - } - - public Builder value(String value) { - this.value = value; - this.set = true; - return this; - } - - public Builder attributes(Map<String, String> attributes) { - this.attributes = attributes; - return this; - } - - public Builder attributes(Element element) { - NamedNodeMap map = element.getAttributes(); - if (map.getLength() > 0) { - this.attributes = new HashMap<>(map.getLength()); - for (int i = 0; i < map.getLength(); ++i) { - String attr = map.item(i).getNodeName(); - attributes.put(attr, element.getAttribute(attr)); - } - } - return this; - } - - public Builder optionTransformer(OptionTransformer optionTransformer) { - this.optionTransformer = optionTransformer; - return this; - } - - public EmbedderOption build() { - return new EmbedderOption(this); - } - - } - -} diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java index fef461a4b7a..d64e726eb6a 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java @@ -12,7 +12,6 @@ import com.yahoo.vespa.config.ConfigPayloadBuilder; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.container.ApplicationContainerCluster; import com.yahoo.vespa.model.container.component.Component; -import com.yahoo.vespa.model.container.xml.embedder.EmbedderConfig; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -169,7 +168,7 @@ public class EmbedderTestCase { private void assertTransform(String embedder, String component, boolean hosted) throws IOException, SAXException { Element emb = createElement(embedder); Element cmp = createElement(component); - Element trans = EmbedderConfig.transform(createEmptyDeployState(hosted), emb); + Element trans = EmbedderConfigTransformer.transform(createEmptyDeployState(hosted), emb); assertSpec(cmp, trans); } @@ -201,7 +200,7 @@ public class EmbedderTestCase { private void assertTransformThrows(String embedder, String expectedMessage, boolean hosted) throws IOException, SAXException { try { - EmbedderConfig.transform(createEmptyDeployState(hosted), createElement(embedder)); + EmbedderConfigTransformer.transform(createEmptyDeployState(hosted), createElement(embedder)); fail("Expected exception was not thrown: " + expectedMessage); } catch (IllegalArgumentException e) { assertEquals(expectedMessage, e.getMessage()); |