summaryrefslogtreecommitdiffstats
path: root/config-lib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-11-27 15:25:28 +0100
committerGitHub <noreply@github.com>2020-11-27 15:25:28 +0100
commit3c0d5e11e703cecc815f1afc77829a9e227db1a4 (patch)
treed1c6e1fc6efa5b7ab061937f1d89dc8ae9d6cab9 /config-lib
parent7a1a70055770a82bf42bff668abaf011af3f6e55 (diff)
Revert "Bratseth/apply on restart take 3"
Diffstat (limited to 'config-lib')
-rw-r--r--config-lib/abi-spec.json6
-rw-r--r--config-lib/pom.xml31
-rw-r--r--config-lib/src/main/java/com/yahoo/config/ConfigBuilder.java1
-rw-r--r--config-lib/src/main/java/com/yahoo/config/ConfigInstance.java107
-rw-r--r--config-lib/src/main/java/com/yahoo/config/Node.java4
5 files changed, 4 insertions, 145 deletions
diff --git a/config-lib/abi-spec.json b/config-lib/abi-spec.json
index a9c57c2d1a2..fa352d8f6bd 100644
--- a/config-lib/abi-spec.json
+++ b/config-lib/abi-spec.json
@@ -73,11 +73,7 @@
"public abstract boolean dispatchGetConfig(com.yahoo.config.ConfigInstance$Producer)",
"public abstract java.lang.String getDefName()",
"public abstract java.lang.String getDefNamespace()",
- "public abstract java.lang.String getDefMd5()",
- "public boolean getApplyOnRestart()",
- "public void setApplyOnRestart(boolean)",
- "public com.yahoo.config.ConfigInstance buildInstance(com.yahoo.config.codegen.InnerCNode)",
- "public static void applyDef(com.yahoo.config.ConfigBuilder, com.yahoo.config.codegen.InnerCNode)"
+ "public abstract java.lang.String getDefMd5()"
],
"fields": []
},
diff --git a/config-lib/pom.xml b/config-lib/pom.xml
index c9eceb10812..1002d43bc37 100644
--- a/config-lib/pom.xml
+++ b/config-lib/pom.xml
@@ -26,12 +26,6 @@
<artifactId>annotations</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>configgen</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
<build>
<plugins>
@@ -74,31 +68,6 @@
<groupId>com.yahoo.vespa</groupId>
<artifactId>abi-check-plugin</artifactId>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <configuration>
- <finalName>${project.artifactId}-jar-with-dependencies</finalName>
- <transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <manifestEntries>
- <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
- <Import-Package>
- com.yahoo.config.codegen<!-- TODO: Remove when the model of config def, which today is InnerCNode in codegen :-(, is moved to config-lib -->
- </Import-Package>
- </manifestEntries>
- </transformer>
- </transformers>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
</project>
diff --git a/config-lib/src/main/java/com/yahoo/config/ConfigBuilder.java b/config-lib/src/main/java/com/yahoo/config/ConfigBuilder.java
index 30bef223045..e35e6916849 100644
--- a/config-lib/src/main/java/com/yahoo/config/ConfigBuilder.java
+++ b/config-lib/src/main/java/com/yahoo/config/ConfigBuilder.java
@@ -5,6 +5,7 @@ package com.yahoo.config;
* Root interface for all config builders.
*
* @author gjoranv
+ * @since 5.1.6
*/
public interface ConfigBuilder {
}
diff --git a/config-lib/src/main/java/com/yahoo/config/ConfigInstance.java b/config-lib/src/main/java/com/yahoo/config/ConfigInstance.java
index b47bd17a5ba..04405839a9b 100644
--- a/config-lib/src/main/java/com/yahoo/config/ConfigInstance.java
+++ b/config-lib/src/main/java/com/yahoo/config/ConfigInstance.java
@@ -1,16 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
-
-import com.yahoo.config.codegen.CNode;
-import com.yahoo.config.codegen.InnerCNode;
-import com.yahoo.config.codegen.LeafCNode;
/**
* Represents an instance of an application config with a specific configId.
@@ -20,13 +13,10 @@ import com.yahoo.config.codegen.LeafCNode;
*/
public abstract class ConfigInstance extends InnerNode {
- private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(ConfigInstance.class.getName());
-
public interface Builder extends ConfigBuilder {
/**
* Dispatches a getConfig() call if this instance's producer is of the right type
- *
* @param producer a config producer
* @return true if this instance's producer was the correct type, and hence a getConfig call was dispatched
*/
@@ -36,103 +26,6 @@ public abstract class ConfigInstance extends InnerNode {
String getDefNamespace();
String getDefMd5();
- /** Returns true if this instance should be applied on restart, false if it should be applied immediately */
- default boolean getApplyOnRestart() { return false; }
-
- default void setApplyOnRestart(boolean applyOnRestart) { throw new java.lang.UnsupportedOperationException(); }
-
- default ConfigInstance buildInstance(InnerCNode targetDef) {
- try {
- if (targetDef != null) applyDef(this, targetDef);
- Class<? extends ConfigInstance> clazz = getConfigClass(getClass());
- return clazz.getConstructor(getClass()).newInstance(this);
- } catch (Exception e) {
- throw new ConfigurationRuntimeException(e);
- }
- }
-
- /**
- * If some fields on the builder are null now, set them from the def. Do recursively.
- * <p>
- * If the targetDef has some schema incompatibilities, they are not handled here
- * (except logging in some cases), but in ConfigInstance.serialize().
- *
- * @param builder a {@link com.yahoo.config.ConfigBuilder}
- * @param targetDef a config definition
- * @throws Exception if applying values form config definitions fails
- */
- static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception {
- for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) {
- CNode node = e.getValue();
- if (node instanceof LeafCNode) {
- setLeafValueIfUnset(targetDef, builder, (LeafCNode)node);
- } else if (node instanceof InnerCNode) {
- // Is there a private field on the builder that matches this inner node in the def?
- if (hasField(builder.getClass(), node.getName())) {
- Field innerField = builder.getClass().getDeclaredField(node.getName());
- innerField.setAccessible(true);
- Object innerFieldVal = innerField.get(builder);
- if (innerFieldVal instanceof List) {
- // inner array? Check that list elems are ConfigBuilder
- List<?> innerList = (List<?>) innerFieldVal;
- for (Object b : innerList) {
- if (b instanceof ConfigBuilder) {
- applyDef((ConfigBuilder) b, (InnerCNode) node);
- }
- }
- } else if (innerFieldVal instanceof ConfigBuilder) {
- // Struct perhaps
- applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node);
- } else {
- // Likely a config value mismatch. That is handled in ConfigInstance.serialize() (error message, omit from response.)
- }
- }
- }
- }
- }
-
- private static boolean hasField(Class<?> aClass, String name) {
- for (Field field : aClass.getDeclaredFields()) {
- if (name.equals(field.getName())) {
- return true;
- }
- }
- return false;
- }
-
- private static void setLeafValueIfUnset(InnerCNode targetDef, Object builder, LeafCNode node) throws Exception {
- if (hasField(builder.getClass(), node.getName())) {
- Field field = builder.getClass().getDeclaredField(node.getName());
- field.setAccessible(true);
- Object val = field.get(builder);
- if (val==null) {
- // Not set on builder, if the leaf node has a default value, try the private setter that takes String
- try {
- if (node.getDefaultValue()!=null) {
- Method setter = builder.getClass().getDeclaredMethod(node.getName(), String.class);
- setter.setAccessible(true);
- setter.invoke(builder, node.getDefaultValue().getValue());
- }
- } catch (Exception e) {
- log.log(Level.SEVERE,
- "For config '" + targetDef.getFullName() + "': " +
- "Unable to apply the default value for field '" + node.getName() +
- "' to config Builder (where it wasn't set)",
- e);
- }
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private static Class<? extends ConfigInstance> getConfigClass(Class<? extends ConfigInstance.Builder> builderClass) {
- Class<?> configClass = builderClass.getEnclosingClass();
- if (configClass == null || ! ConfigInstance.class.isAssignableFrom(configClass)) {
- throw new ConfigurationRuntimeException("Builder class " + builderClass + " has enclosing class " + configClass + ", which is not a ConfigInstance");
- }
- return (Class<? extends ConfigInstance>) configClass;
- }
-
}
public interface Producer {}
diff --git a/config-lib/src/main/java/com/yahoo/config/Node.java b/config-lib/src/main/java/com/yahoo/config/Node.java
index ed11bdc9891..8d16b9727c1 100644
--- a/config-lib/src/main/java/com/yahoo/config/Node.java
+++ b/config-lib/src/main/java/com/yahoo/config/Node.java
@@ -5,6 +5,7 @@ package com.yahoo.config;
* The Node class is superclass for all nodes in a {@link
* ConfigInstance}. Important subclasses of this node are {@link
* InnerNode} and {@link LeafNode}.
+ *
*/
public abstract class Node {
@@ -12,7 +13,7 @@ public abstract class Node {
* Postinitialize this node. Any node needing to process its values depending on the config
* id should override this method.
*
- * @param configId the configId of the ConfigInstance that owns (or is) this node
+ * @param configId the configId of the ConfigInstance that owns (or is) this node
*/
public void postInitialize(String configId) { return; }
@@ -25,5 +26,4 @@ public abstract class Node {
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
-
}