blob: 1cab6cd462d6dc4dc7065e4975c55fc98d698666 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright Yahoo. 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.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 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) {
if (documentsElement == null || documentsElement.subElements("document").isEmpty())
return Collections.emptySet();
return documentsElement.subElements("document")
.stream()
.filter(GlobalDistributionBuilder::isGloballyDistributed)
.map(GlobalDistributionBuilder::getDocumentName)
.map(this::getDocumentType)
.collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
}
private static boolean isGloballyDistributed(ModelElement e) {
return e.booleanAttribute("global", false);
}
private static String getDocumentName(ModelElement e) {
return e.stringAttribute("type");
}
private NewDocumentType getDocumentType(String name) {
return documentDefinitions.get(name);
}
}
|