diff options
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
2 files changed, 43 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidator.java new file mode 100644 index 00000000000..9f081f7083b --- /dev/null +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidator.java @@ -0,0 +1,42 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.content; + +import com.yahoo.documentmodel.NewDocumentType; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class ReservedDocumentTypeNameValidator { + + public static final List<String> ORDERED_RESERVED_NAMES = Collections.unmodifiableList( + Arrays.asList("and", "false", "id", "not", "null", "or", "true")); + public static final Set<String> RESERVED_NAMES = Collections.unmodifiableSet(new HashSet<>(ORDERED_RESERVED_NAMES)); + + public void validate(Map<String, NewDocumentType> documentDefinitions) { + List<String> conflictingNames = documentDefinitions.keySet().stream() + .filter(this::isReservedName) + .collect(Collectors.toList()); + if (!conflictingNames.isEmpty()) { + throw new IllegalArgumentException(makeReservedNameMessage(conflictingNames)); + } + } + + private boolean isReservedName(String name) { + return RESERVED_NAMES.contains(name.toLowerCase()); + } + + private static String asQuotedListString(List<String> list) { + return list.stream().map(s -> String.format("'%s'", s)).collect(Collectors.joining(", ")); + } + + private static String makeReservedNameMessage(List<String> conflictingNames) { + return String.format("The following document types conflict with reserved keyword names: %s. Reserved keywords are %s", + asQuotedListString(conflictingNames), asQuotedListString(ORDERED_RESERVED_NAMES)); + } + +} 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 b4f8889690e..c7755d3de5a 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 @@ -617,6 +617,7 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri throw new IllegalArgumentException("In indexed content cluster '" + search.getClusterName() + "': Using multi-level dispatch setup is not supported when using hierarchical distribution."); } } + new ReservedDocumentTypeNameValidator().validate(documentDefinitions); new GlobalDistributionValidator().validate(documentDefinitions, globallyDistributedDocuments, redundancy); } |