aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-02-07 10:47:53 +0100
committerBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-02-07 16:13:03 +0100
commit2ff4b49039be78c4156fe75e8bb6bc423b074a94 (patch)
tree46872dfea8890756ebc84ef29592be4ead48cd66
parent08b1d599b73d7937248d6b41b5b03df2e43c85fb (diff)
Determine the set of globally distributed documents
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java8
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java46
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java56
3 files changed, 108 insertions, 2 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java
index c80d17f8202..885d35f288e 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java
@@ -61,6 +61,7 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri
private String documentSelection;
ContentSearchCluster search;
final Map<String, NewDocumentType> documentDefinitions;
+ private final Set<NewDocumentType> globallyDistributedDocuments;
com.yahoo.vespa.model.content.StorageGroup rootGroup;
StorageCluster storageNodes;
DistributorCluster distributorNodes;
@@ -101,10 +102,11 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri
Map<String, NewDocumentType> documentDefinitions =
new SearchDefinitionBuilder().build(ancestor.getRoot().getDeployState().getDocumentModel().getDocumentManager(), documentsElement);
- String routingSelection = new DocumentSelectionBuilder().build(contentElement.getChild("documents"));
+ String routingSelection = new DocumentSelectionBuilder().build(documentsElement);
Redundancy redundancy = new RedundancyBuilder().build(contentElement);
+ Set<NewDocumentType> globallyDistributedDocuments = new GlobalDistributionBuilder(documentDefinitions).build(documentsElement);
- ContentCluster c = new ContentCluster(ancestor, getClusterName(contentElement), documentDefinitions, routingSelection, redundancy);
+ ContentCluster c = new ContentCluster(ancestor, getClusterName(contentElement), documentDefinitions, globallyDistributedDocuments, routingSelection, redundancy);
c.clusterControllerConfig = new ClusterControllerConfig.Builder(getClusterName(contentElement), contentElement).build(c, contentElement.getXml());
c.search = new ContentSearchCluster.Builder(documentDefinitions).build(c, contentElement.getXml());
c.persistenceFactory = new EngineFactoryBuilder().build(contentElement, c);
@@ -455,11 +457,13 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri
private ContentCluster(AbstractConfigProducer parent,
String clusterName,
Map<String, NewDocumentType> documentDefinitions,
+ Set<NewDocumentType> globallyDistributedDocuments,
String routingSelection,
Redundancy redundancy) {
super(parent, clusterName);
this.clusterName = clusterName;
this.documentDefinitions = documentDefinitions;
+ this.globallyDistributedDocuments = globallyDistributedDocuments;
this.documentSelection = routingSelection;
this.redundancy = redundancy;
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java
new file mode 100644
index 00000000000..e8c634ac264
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilder.java
@@ -0,0 +1,46 @@
+// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.model.content.cluster;
+
+import com.yahoo.documentmodel.NewDocumentType;
+import com.yahoo.vespa.model.builder.xml.dom.ModelElement;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import static java.util.stream.Collectors.toSet;
+
+/**
+ * Determines the set of document types that are configured to be globally distributed.
+ *
+ * @author bjorncs
+ */
+public class GlobalDistributionBuilder {
+
+ private final Map<String, NewDocumentType> documentDefinitions;
+
+ public GlobalDistributionBuilder(Map<String, NewDocumentType> documentDefinitions) {
+ this.documentDefinitions = Collections.unmodifiableMap(documentDefinitions);
+ }
+
+ public Set<NewDocumentType> build(ModelElement documentsElement) {
+ return documentsElement.subElements("document")
+ .stream()
+ .filter(GlobalDistributionBuilder::isGloballyDistributed)
+ .map(GlobalDistributionBuilder::getDocumentName)
+ .map(this::getDocumentType)
+ .collect(toSet());
+ }
+
+ private static boolean isGloballyDistributed(ModelElement e) {
+ return e.getBooleanAttribute("global", false);
+ }
+
+ private static String getDocumentName(ModelElement e) {
+ return e.getStringAttribute("type");
+ }
+
+ private NewDocumentType getDocumentType(String name) {
+ return documentDefinitions.get(name);
+ }
+}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java
new file mode 100644
index 00000000000..3823b8733fa
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/vespa/model/content/cluster/GlobalDistributionBuilderTest.java
@@ -0,0 +1,56 @@
+// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.model.content.cluster;
+
+import com.yahoo.documentmodel.NewDocumentType;
+import com.yahoo.text.XML;
+import com.yahoo.vespa.model.builder.xml.dom.ModelElement;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author bjorncs
+ */
+public class GlobalDistributionBuilderTest {
+
+ private static final NewDocumentType NON_GLOBAL_EXPLICIT = new NewDocumentType(new NewDocumentType.Name("non-global-explicit"));
+ private static final NewDocumentType NON_GLOBAL_IMPLICIT = new NewDocumentType(new NewDocumentType.Name("non-global-implicit"));
+ private static final NewDocumentType GLOBAL_1 = new NewDocumentType(new NewDocumentType.Name("global-1"));
+ private static final NewDocumentType GLOBAL_2 = new NewDocumentType(new NewDocumentType.Name("global-2"));
+
+ @Test
+ public void global_documents_are_identified() {
+ GlobalDistributionBuilder builder = new GlobalDistributionBuilder(createDocumentDefinitions());
+ String documentsElement =
+ "<documents>" +
+ " <document type=\"" + NON_GLOBAL_EXPLICIT.getName() + "\" global=\"false\"/>" +
+ " <document type=\"" + GLOBAL_1.getName() + "\" global=\"true\"/>" +
+ " <document type=\"" + NON_GLOBAL_IMPLICIT.getName() + "\"/>" +
+ " <document type=\"" + GLOBAL_2.getName() + "\" global=\"true\"/>" +
+ "</documents>";
+
+ Set<NewDocumentType> expectedResult = new HashSet<>(Arrays.asList(GLOBAL_1, GLOBAL_2));
+ Set<NewDocumentType> actualResult = builder.build(new ModelElement(XML.getDocument(documentsElement).getDocumentElement()));
+ assertEquals(expectedResult, actualResult);
+ }
+
+ private static Map<String, NewDocumentType> createDocumentDefinitions() {
+ Map<String, NewDocumentType> documentTypes = new HashMap<>();
+ addType(documentTypes, NON_GLOBAL_EXPLICIT);
+ addType(documentTypes, GLOBAL_1);
+ addType(documentTypes, NON_GLOBAL_IMPLICIT);
+ addType(documentTypes, GLOBAL_2);
+ return documentTypes;
+ }
+
+ private static void addType(Map<String, NewDocumentType> documentTypes, NewDocumentType documentType) {
+ documentTypes.put(documentType.getName(), documentType);
+ }
+
+}