aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-10-15 17:58:13 +0200
committerJon Bratseth <bratseth@gmail.com>2021-10-15 17:58:13 +0200
commit813c270c2ea80953c7b09aac56dc6a5c254aca1e (patch)
tree272ba9fe3a0e7f94e30f7bd5e130eb9c9f4edad9 /config-model/src/main/java/com
parent3a755750ba601440cee41d2f19d4370e2817b3c1 (diff)
Add Application abstraction
Diffstat (limited to 'config-model/src/main/java/com')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/Application.java54
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/DocumentOnlySearch.java4
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java5
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/ImportedFieldsEnumerator.java5
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/Search.java57
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java44
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java2
7 files changed, 124 insertions, 47 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/Application.java b/config-model/src/main/java/com/yahoo/searchdefinition/Application.java
new file mode 100644
index 00000000000..5eb28201239
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/Application.java
@@ -0,0 +1,54 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition;
+
+import com.yahoo.config.application.api.ApplicationPackage;
+import com.yahoo.config.application.api.DeployLogger;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A collection of objects representing the content of an application package.
+ * This is created, then added to, and lastly validated when there is no more content to add.
+ * At that point it is ready to use for deriving configuration.
+ *
+ * @author bratseth
+ */
+public class Application {
+
+ private final ApplicationPackage applicationPackage;
+ private final Map<String, Search> schemas = new LinkedHashMap<>();
+
+ public Application(ApplicationPackage applicationPackage) {
+ this.applicationPackage = applicationPackage;
+ }
+
+ public ApplicationPackage applicationPackage() { return applicationPackage; }
+
+ public void add(Search schema) {
+ if (schemas.containsKey(schema.getName()))
+ throw new IllegalArgumentException("Duplicate schema '" + schema.getName() + "' in " + this);
+ schemas.put(schema.getName(), schema);
+ }
+
+ /** Returns an unmodifiable list of the schemas of this application */
+ public Map<String, Search> schemas() { return Collections.unmodifiableMap(schemas); }
+
+ /** Used by SearchBuilder, for now */
+ void replaceSchemasBy(List<Search> schemas) {
+ this.schemas.clear();
+ for (var schema : schemas)
+ this.schemas.put(schema.getName(), schema);
+ }
+
+ /** Validates this. Must be called after all content is added to it. */
+ public void validate(DeployLogger logger) {
+ schemas.values().forEach(schema -> schema.validate(logger));
+ }
+
+ @Override
+ public String toString() { return "application " + applicationPackage.getApplicationId(); }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentOnlySearch.java b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentOnlySearch.java
index d10aa26f429..29d8252f621 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentOnlySearch.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentOnlySearch.java
@@ -15,8 +15,8 @@ import com.yahoo.searchdefinition.document.SDDocumentType;
*/
public class DocumentOnlySearch extends Search {
- public DocumentOnlySearch(ApplicationPackage applicationPackage, FileRegistry fileRegistry, DeployLogger deployLogger, ModelContext.Properties properties) {
- super(applicationPackage, fileRegistry, deployLogger, properties);
+ public DocumentOnlySearch(Application application, FileRegistry fileRegistry, DeployLogger deployLogger, ModelContext.Properties properties) {
+ super(application, fileRegistry, deployLogger, properties);
}
@Override
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java
index 95fdd5dc297..a16433b36dc 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java
@@ -7,7 +7,6 @@ import com.yahoo.searchdefinition.document.SDDocumentType;
import com.yahoo.searchdefinition.document.SDField;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -26,7 +25,7 @@ public class DocumentReferenceResolver {
private final Map<String, Search> searchMapping;
- public DocumentReferenceResolver(List<Search> schemas) {
+ public DocumentReferenceResolver(Collection<Search> schemas) {
this.searchMapping = createDocumentNameToSearchMapping(schemas);
}
@@ -78,7 +77,7 @@ public class DocumentReferenceResolver {
return sdField.doesAttributing();
}
- private static Map<String, Search> createDocumentNameToSearchMapping(List<Search> searchDefintions) {
+ private static Map<String, Search> createDocumentNameToSearchMapping(Collection<Search> searchDefintions) {
return searchDefintions.stream()
.filter(search -> search.getDocument() != null)
.collect(toMap(search -> search.getDocument().getName(), identity()));
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/ImportedFieldsEnumerator.java b/config-model/src/main/java/com/yahoo/searchdefinition/ImportedFieldsEnumerator.java
index 25cdd1e08cd..91fd0aee957 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/ImportedFieldsEnumerator.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/ImportedFieldsEnumerator.java
@@ -3,6 +3,7 @@ package com.yahoo.searchdefinition;
import com.yahoo.searchdefinition.document.SDDocumentType;
+import java.util.Collection;
import java.util.List;
/**
@@ -11,9 +12,9 @@ import java.util.List;
*/
public class ImportedFieldsEnumerator {
- private final List<Search> schemas;
+ private final Collection<Search> schemas;
- public ImportedFieldsEnumerator(List<Search> schemas) {
+ public ImportedFieldsEnumerator(Collection<Search> schemas) {
this.schemas = schemas;
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java
index 415fcd1d34e..0b7b1687eb9 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java
@@ -59,9 +59,12 @@ public class Search implements ImmutableSearch {
private final FieldSets fieldSets = new FieldSets();
- /** The unique name of this search definition */
+ /** The unique name of this schema */
private String name;
+ /** The name of the schema this should inherit all the content of, if any */
+ private final Optional<String> inherited;
+
/** True if this doesn't define a search, just a document type */
private final boolean documentsOnly;
@@ -94,31 +97,52 @@ public class Search implements ImmutableSearch {
private Optional<TemporaryImportedFields> temporaryImportedFields = Optional.of(new TemporaryImportedFields());
private Optional<ImportedFields> importedFields = Optional.empty();
- private final ApplicationPackage applicationPackage;
+ private final Application application;
private final DeployLogger deployLogger;
private final ModelContext.Properties properties;
/** Testing only */
public Search(String name) {
- this(name, null, null, new BaseDeployLogger(), new TestProperties());
+ this(name, Optional.empty(), null, null, new BaseDeployLogger(), new TestProperties());
+ }
+
+ public Search(String name,
+ Application application,
+ FileRegistry fileRegistry,
+ DeployLogger deployLogger,
+ ModelContext.Properties properties) {
+ this(name, Optional.empty(), application, fileRegistry, deployLogger, properties);
}
+
/**
- * Creates a proper search definition
+ * Creates a schema
*
- * @param name of the the searchdefinition
- * @param applicationPackage the application containing this
+ * @param name of the schema
+ * @param inherited the schema this inherits, if any
+ * @param application the application containing this
*/
- public Search(String name, ApplicationPackage applicationPackage, FileRegistry fileRegistry, DeployLogger deployLogger, ModelContext.Properties properties) {
- this(applicationPackage, fileRegistry, deployLogger, properties, false);
+ public Search(String name,
+ Optional<String> inherited,
+ Application application,
+ FileRegistry fileRegistry,
+ DeployLogger deployLogger,
+ ModelContext.Properties properties) {
+ this(inherited, application, fileRegistry, deployLogger, properties, false);
this.name = name;
}
- protected Search(ApplicationPackage applicationPackage, FileRegistry fileRegistry, DeployLogger deployLogger, ModelContext.Properties properties) {
- this(applicationPackage, fileRegistry, deployLogger, properties, true);
+ protected Search(Application application, FileRegistry fileRegistry, DeployLogger deployLogger, ModelContext.Properties properties) {
+ this(Optional.empty(), application, fileRegistry, deployLogger, properties, true);
}
- private Search(ApplicationPackage applicationPackage, FileRegistry fileRegistry, DeployLogger deployLogger, ModelContext.Properties properties, boolean documentsOnly) {
- this.applicationPackage = applicationPackage;
+ private Search(Optional<String> inherited,
+ Application application,
+ FileRegistry fileRegistry,
+ DeployLogger deployLogger,
+ ModelContext.Properties properties,
+ boolean documentsOnly) {
+ this.inherited = inherited;
+ this.application = application;
this.deployLogger = deployLogger;
this.properties = properties;
this.documentsOnly = documentsOnly;
@@ -299,11 +323,16 @@ public class Search implements ImmutableSearch {
*/
@Override
public Reader getRankingExpression(String fileName) {
- return applicationPackage.getRankingExpression(fileName);
+ return application.applicationPackage().getRankingExpression(fileName);
}
+ public Application application() { return application; }
+
@Override
- public ApplicationPackage applicationPackage() { return applicationPackage; }
+ public ApplicationPackage applicationPackage() {
+ if (application == null) return null;
+ return application.applicationPackage();
+ }
@Override
public DeployLogger getDeployLogger() { return deployLogger; }
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
index 0f7ead43868..adfed2e8147 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
@@ -42,11 +42,12 @@ import java.util.List;
* expressions, using the setRankXXX() methods, 3) invoke the {@link #build()} method, and 4) retrieve the built
* search objects using the {@link #getSearch(String)} method.
*/
+// Since this was created we have added Application, and much of the content in this should probably migrate there.
public class SearchBuilder {
private final DocumentTypeManager docTypeMgr = new DocumentTypeManager();
private final DocumentModel model = new DocumentModel();
- private final ApplicationPackage app;
+ private final Application application;
private final RankProfileRegistry rankProfileRegistry;
private final QueryProfileRegistry queryProfileRegistry;
private final FileRegistry fileRegistry;
@@ -109,14 +110,14 @@ public class SearchBuilder {
QueryProfileRegistry queryProfileRegistry) {
this(app, fileRegistry, deployLogger, properties, rankProfileRegistry, queryProfileRegistry, false);
}
- private SearchBuilder(ApplicationPackage app,
+ private SearchBuilder(ApplicationPackage applicationPackage,
FileRegistry fileRegistry,
DeployLogger deployLogger,
ModelContext.Properties properties,
RankProfileRegistry rankProfileRegistry,
QueryProfileRegistry queryProfileRegistry,
boolean documentsOnly) {
- this.app = app;
+ this.application = new Application(applicationPackage);
this.rankProfileRegistry = rankProfileRegistry;
this.queryProfileRegistry = queryProfileRegistry;
this.fileRegistry = fileRegistry;
@@ -169,7 +170,7 @@ public class SearchBuilder {
private String importString(String str, String searchDefDir) throws ParseException {
SimpleCharStream stream = new SimpleCharStream(str);
try {
- return importRawSearch(new SDParser(stream, fileRegistry, deployLogger, properties, app, rankProfileRegistry, documentsOnly)
+ return importRawSearch(new SDParser(stream, fileRegistry, deployLogger, properties, application, rankProfileRegistry, documentsOnly)
.search(docTypeMgr, searchDefDir));
} catch (TokenMgrException e) {
throw new ParseException("Unknown symbol: " + e.getMessage());
@@ -183,21 +184,16 @@ public class SearchBuilder {
* {@link Search} object is considered to be "raw" if it has not already been processed. This is the case for most
* programmatically constructed search objects used in unit tests.
*
- * @param rawSearch the object to import.
+ * @param schema the object to import.
* @return the name of the imported object.
* @throws IllegalArgumentException if the given search object has already been processed.
*/
- public String importRawSearch(Search rawSearch) {
- if (rawSearch.getName() == null)
- throw new IllegalArgumentException("Search has no name.");
- String rawName = rawSearch.getName();
- for (Search search : searchList) {
- if (rawName.equals(search.getName())) {
- throw new IllegalArgumentException("A search definition with a search section called '" + rawName +
- "' has already been added.");
- }
- }
- searchList.add(rawSearch);
+ public String importRawSearch(Search schema) {
+ if (schema.getName() == null)
+ throw new IllegalArgumentException("Schema has no name");
+ String rawName = schema.getName();
+ application.add(schema);
+ searchList.add(schema);
return rawName;
}
@@ -223,7 +219,7 @@ public class SearchBuilder {
if (isBuilt) throw new IllegalStateException("Model already built");
if (validate)
- searchList.forEach(search -> search.validate(deployLogger));
+ application.validate(deployLogger);
List<Search> built = new ArrayList<>();
List<SDDocumentType> sdocs = new ArrayList<>();
@@ -282,10 +278,11 @@ public class SearchBuilder {
*/
public Search getSearch() {
if ( ! isBuilt) throw new IllegalStateException("Searches not built.");
- if (searchList.size() != 1)
- throw new IllegalStateException("This call only works if we have 1 search definition. Search definitions: " + searchList);
+ if (application.schemas().size() != 1)
+ throw new IllegalStateException("This call only works if we have 1 schema. Schemas: " +
+ application.schemas().values());
- return searchList.get(0);
+ return application.schemas().values().stream().findAny().get();
}
public DocumentModel getModel() {
@@ -304,16 +301,13 @@ public class SearchBuilder {
public Search getSearch(String name) {
if ( ! isBuilt) throw new IllegalStateException("Searches not built.");
if (name == null) return getSearch();
-
- for (Search search : searchList)
- if (search.getName().equals(name)) return search;
- return null;
+ return application.schemas().get(name);
}
/**
* Convenience method to return a list of all built {@link Search} objects.
*
- * @return The list of built searches.
+ * @return the list of built searches
*/
public List<Search> getSearchList() {
return new ArrayList<>(searchList);
diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java
index 23c1a48b6fe..67e26a899bd 100644
--- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java
+++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java
@@ -109,7 +109,7 @@ public class DocumentSummary extends FieldView {
return owner.getSummary(inherited);
}
- /** Returns the name of the summary this was declared to inherit, or null if not sett to inherit anything */
+ /** Returns the name of the summary this was declared to inherit, or null if not set to inherit anything */
public String getInheritedName() {
return inherited;
}