summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-16 10:07:43 +0200
committerGitHub <noreply@github.com>2022-05-16 10:07:43 +0200
commite4e4740cd2c4d12feef9776e71de5a86de95bda0 (patch)
tree03a6b8a605c753bfa847b3768aab480a7f09a4c9 /config-model/src/main/java/com/yahoo
parent4eefbd147e96d1dab546d71f44f288d755c2648c (diff)
parent4427aebe50bf1b2d17267ac315787a361d117ead (diff)
Merge pull request #22613 from vespa-engine/bratseth/constants-cleanup-2-take-2
Bratseth/constants cleanup 2 take 2
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
-rw-r--r--config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java3
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java56
2 files changed, 16 insertions, 43 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java
index 74d92bcfd02..3cd2499f968 100644
--- a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java
+++ b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java
@@ -41,6 +41,7 @@ import com.yahoo.vespa.model.container.search.QueryProfiles;
import com.yahoo.vespa.model.container.search.QueryProfilesBuilder;
import com.yahoo.vespa.model.container.search.SemanticRuleBuilder;
import com.yahoo.vespa.model.container.search.SemanticRules;
+import com.yahoo.yolean.Exceptions;
import java.io.File;
import java.io.FileNotFoundException;
@@ -217,7 +218,7 @@ public class DeployState implements ConfigDefinitionStore {
for (var entry : importedModels.getSkippedModels().entrySet()) {
// TODO: Vespa 8: Throw IllegalArgumentException instead
deployLogger.logApplicationPackage(Level.WARNING, "Skipping import of model " + entry.getKey() + " as an exception " +
- "occurred during import. Error: " + entry.getValue());
+ "occurred during import: " + entry.getValue());
}
return importedModels;
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java
index c9b0ed2f628..8de86beacdb 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java
@@ -20,54 +20,30 @@ import java.util.function.Function;
*/
public class FileDistributedConstants {
- private final FileRegistry fileRegistry;
-
- private final Map<String, DistributableConstant> constants = new LinkedHashMap<>();
+ private final Map<String, DistributableConstant> constants;
public FileDistributedConstants(FileRegistry fileRegistry, Collection<RankProfile.Constant> constants) {
- this.fileRegistry = fileRegistry;
+ Map<String, DistributableConstant> distributableConstants = new LinkedHashMap<>();
for (var constant : constants) {
- if (constant.valuePath().isPresent())
- add(new DistributableConstant(constant.name().simpleArgument().get(),
- constant.type(),
- constant.valuePath().get(),
- constant.pathType().get()));
+ if ( ! constant.valuePath().isPresent()) continue;
+
+ var distributableConstant = new DistributableConstant(constant.name().simpleArgument().get(),
+ constant.type(),
+ constant.valuePath().get(),
+ constant.pathType().get());
+ distributableConstant.validate();
+ distributableConstant.register(fileRegistry);
+ distributableConstants.put(distributableConstant.getName(), distributableConstant);
}
- }
-
- public void add(DistributableConstant constant) {
- constant.validate();
- constant.register(fileRegistry);
- String name = constant.getName();
- DistributableConstant prev = constants.putIfAbsent(name, constant);
- if ( prev != null )
- throw new IllegalArgumentException("Constant '" + name + "' defined twice");
- }
-
- public void putIfAbsent(DistributableConstant constant) {
- constant.validate();
- constant.register(fileRegistry);
- String name = constant.getName();
- constants.putIfAbsent(name, constant);
- }
-
- public void computeIfAbsent(String name, Function<? super String, ? extends DistributableConstant> createConstant) {
- constants.computeIfAbsent(name, key -> {
- DistributableConstant constant = createConstant.apply(key);
- constant.validate();
- constant.register(fileRegistry);
- return constant;
- });
+ this.constants = Collections.unmodifiableMap(distributableConstants);
}
/** Returns a read-only map of the constants in this indexed by name. */
- public Map<String, DistributableConstant> asMap() {
- return Collections.unmodifiableMap(constants);
- }
+ public Map<String, DistributableConstant> asMap() { return constants; }
public static class DistributableConstant extends DistributableResource {
- private TensorType tensorType;
+ private final TensorType tensorType;
public DistributableConstant(String name, TensorType type, String fileName) {
this(name, type, fileName, PathType.FILE);
@@ -79,10 +55,6 @@ public class FileDistributedConstants {
validate();
}
- public void setType(TensorType type) {
- this.tensorType = type;
- }
-
public TensorType getTensorType() { return tensorType; }
public String getType() { return tensorType.toString(); }