Search in sources :

Example 11 with ModelElement

use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.

the class DocumentSelectionBuilder method build.

public String build(ModelElement elem) {
    StringBuilder sb = new StringBuilder();
    if (elem != null) {
        for (ModelElement e : elem.subElements("document")) {
            if (sb.length() > 0) {
                sb.append(" OR ");
            }
            sb.append('(');
            String type = e.getStringAttribute("type");
            sb.append(type);
            String selection = e.getStringAttribute("selection");
            if (selection != null) {
                validateSelectionExpression(selection, type);
                sb.append(" AND (");
                sb.append(selection);
                sb.append(')');
            }
            sb.append(')');
        }
        String globalSelection = elem.getStringAttribute("selection");
        if (globalSelection != null) {
            validateSelectionExpression(globalSelection, null);
            StringBuilder global = new StringBuilder();
            global.append('(').append(globalSelection).append(") AND (").append(sb.toString()).append(')');
            return global.toString();
        }
    }
    return sb.toString();
}
Also used : ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement)

Example 12 with ModelElement

use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.

the class DomDispatchBuilder method buildGroup.

private static DispatchSpec.Group buildGroup(ModelElement groupElement) {
    List<ModelElement> nodes = groupElement.subElements("node");
    DispatchSpec.Group group = new DispatchSpec.Group();
    for (ModelElement nodeElement : nodes) {
        group.addNode(buildNode(nodeElement));
    }
    return group;
}
Also used : ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement) DispatchSpec(com.yahoo.vespa.model.content.DispatchSpec)

Example 13 with ModelElement

use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.

the class DomDispatchBuilder method build.

public static DispatchSpec build(ModelElement contentXml) {
    DispatchSpec.Builder builder = new DispatchSpec.Builder();
    ModelElement dispatchElement = contentXml.getChild("dispatch");
    if (dispatchElement == null) {
        return builder.build();
    }
    builder.setNumDispatchGroups(dispatchElement.childAsInteger("num-dispatch-groups"));
    List<ModelElement> groupsElement = dispatchElement.subElements("group");
    if (groupsElement != null) {
        builder.setGroups(buildGroups(groupsElement));
    }
    return builder.build();
}
Also used : ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement) DispatchSpec(com.yahoo.vespa.model.content.DispatchSpec)

Example 14 with ModelElement

use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.

the class DomSearchCoverageBuilder method build.

public static SearchCoverage build(ModelElement contentXml) {
    SearchCoverage.Builder builder = new SearchCoverage.Builder();
    ModelElement searchElement = contentXml.getChild("search");
    if (searchElement == null) {
        return builder.build();
    }
    ModelElement coverageElement = searchElement.getChild("coverage");
    if (coverageElement == null) {
        return builder.build();
    }
    builder.setMinimum(coverageElement.childAsDouble("minimum"));
    builder.setMinWaitAfterCoverageFactor(coverageElement.childAsDouble("min-wait-after-coverage-factor"));
    builder.setMaxWaitAfterCoverageFactor(coverageElement.childAsDouble("max-wait-after-coverage-factor"));
    return builder.build();
}
Also used : ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement) SearchCoverage(com.yahoo.vespa.model.content.SearchCoverage)

Example 15 with ModelElement

use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.

the class GlobalDistributionBuilderTest method global_documents_are_identified.

@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);
}
Also used : ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ModelElement (com.yahoo.vespa.model.builder.xml.dom.ModelElement)15 ClusterMembership (com.yahoo.config.provision.ClusterMembership)3 HostResource (com.yahoo.vespa.model.HostResource)3 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)2 NodesSpecification (com.yahoo.vespa.model.builder.xml.dom.NodesSpecification)2 DispatchSpec (com.yahoo.vespa.model.content.DispatchSpec)2 Element (org.w3c.dom.Element)2 ContentSearch (com.yahoo.vespa.model.content.ContentSearch)1 Redundancy (com.yahoo.vespa.model.content.Redundancy)1 ResourceLimits (com.yahoo.vespa.model.content.ResourceLimits)1 SearchCoverage (com.yahoo.vespa.model.content.SearchCoverage)1 TuningDispatch (com.yahoo.vespa.model.content.TuningDispatch)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1