Adjust Blueprint to ensure the container is a ChildOf 84/100084/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Mar 2022 17:57:07 +0000 (18:57 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Mar 2022 17:59:15 +0000 (18:59 +0100)
InstanceIdentifier requires data tree steps, make sure we enforce
that invariant.

JIRA: MDSAL-370
Change-Id: Icb3c08eb7052eed28ef6638facb884857baec3e9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/BindingContext.java
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/DataStoreAppConfigMetadata.java

index dd672e4..14b7966 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Set;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Identifiable;
@@ -48,8 +49,6 @@ import org.xml.sax.SAXException;
  * @author Thomas Pantelis (originally; re-factored by Michael Vorburger.ch)
  */
 public abstract class BindingContext {
-    private static String GET_KEY_METHOD = "key";
-
     public static BindingContext create(final String logName, final Class<? extends DataObject> klass,
             final String appConfigListKeyValue) {
         if (Identifiable.class.isAssignableFrom(klass)) {
@@ -75,12 +74,12 @@ public abstract class BindingContext {
     }
 
     public final InstanceIdentifier<DataObject> appConfigPath;
-    public final Class<DataObject> appConfigBindingClass;
+    public final Class<?> appConfigBindingClass;
     public final Class<? extends DataSchemaNode> schemaType;
     public final QName bindingQName;
 
-    private BindingContext(final Class<DataObject> appConfigBindingClass,
-            final InstanceIdentifier<DataObject> appConfigPath, final Class<? extends DataSchemaNode> schemaType) {
+    private BindingContext(final Class<?> appConfigBindingClass, final InstanceIdentifier<DataObject> appConfigPath,
+            final Class<? extends DataSchemaNode> schemaType) {
         this.appConfigBindingClass = appConfigBindingClass;
         this.appConfigPath = appConfigPath;
         this.schemaType = schemaType;
@@ -113,8 +112,8 @@ public abstract class BindingContext {
     private static class ContainerBindingContext extends BindingContext {
         @SuppressWarnings("unchecked")
         ContainerBindingContext(final Class<? extends DataObject> appConfigBindingClass) {
-            super((Class<DataObject>) appConfigBindingClass,
-                    InstanceIdentifier.create((Class<DataObject>) appConfigBindingClass), ContainerSchemaNode.class);
+            super(appConfigBindingClass, InstanceIdentifier.create((Class) appConfigBindingClass),
+                ContainerSchemaNode.class);
         }
 
         @Override
@@ -142,8 +141,8 @@ public abstract class BindingContext {
                 final String listKeyValue) throws InstantiationException, IllegalAccessException,
                 IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
             // We assume the yang list key type is string.
-            Identifier keyInstance = (Identifier) bindingClass.getMethod(GET_KEY_METHOD).getReturnType()
-                    .getConstructor(String.class).newInstance(listKeyValue);
+            Identifier keyInstance = (Identifier) bindingClass.getMethod(BindingMapping.IDENTIFIABLE_KEY_NAME)
+                .getReturnType().getConstructor(String.class).newInstance(listKeyValue);
             InstanceIdentifier appConfigPath = InstanceIdentifier.builder((Class)bindingClass, keyInstance).build();
             return new ListBindingContext(bindingClass, appConfigPath, listKeyValue);
         }
index 5b20827..4fb4941 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSeriali
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaTreeInference;
@@ -86,7 +87,7 @@ public class DataStoreAppConfigMetadata extends AbstractDependentComponentFactor
         this.defaultAppConfigFileName = defaultAppConfigFileName;
         this.appConfigBindingClassName = appConfigBindingClassName;
         this.appConfigListKeyValue = appConfigListKeyValue;
-        this.appConfigUpdateStrategy = updateStrategyValue;
+        appConfigUpdateStrategy = updateStrategyValue;
     }
 
     @Override
@@ -97,10 +98,10 @@ public class DataStoreAppConfigMetadata extends AbstractDependentComponentFactor
         Class<DataObject> appConfigBindingClass;
         try {
             Class<?> bindingClass = container.getBundleContext().getBundle().loadClass(appConfigBindingClassName);
-            if (!DataObject.class.isAssignableFrom(bindingClass)) {
+            if (!ChildOf.class.isAssignableFrom(bindingClass)) {
                 throw new ComponentDefinitionException(String.format(
                         "%s: Specified app config binding class %s does not extend %s",
-                        logName(), appConfigBindingClassName, DataObject.class.getName()));
+                        logName(), appConfigBindingClassName, ChildOf.class.getName()));
             }
 
             appConfigBindingClass = (Class<DataObject>) bindingClass;