Bug 2412: Expose Mountpoints on proper path 79/16279/2
authorMaros Marsalek <mmarsale@cisco.com>
Tue, 10 Mar 2015 16:14:08 +0000 (17:14 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 10 Mar 2015 21:53:52 +0000 (22:53 +0100)
Lists such as topology, node were not doubled
in the YANG Instance Identifier used as a key for mountpoints,
which prevented Binding compontents from accessing
them.

This patch fixes also bug in restconf, which was
also producing incorrect instance identifiers.

Change-Id: I3122163d00d4c23fcccc4bbffdf3d0113744c98d
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMMountPointListenerAdapter.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/util/RemoteDeviceId.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java

index 5698156934e398624b71838dcb990fff39db6c87..f33148271f4ba85590a35452efd7dfc8899cce21 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.md.sal.binding.impl;
 
+import com.google.common.base.Optional;
 import org.opendaylight.controller.md.sal.binding.api.MountPointService.MountPointListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener;
@@ -41,21 +42,30 @@ final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> im
     @Override
     public void onMountPointCreated(final YangInstanceIdentifier path) {
         try {
-            final InstanceIdentifier<? extends DataObject> bindingPath = codec.toBinding(path).get();
+            final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
             listener.onMountPointCreated(bindingPath);
         } catch (final DeserializationException e) {
-            BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Ommiting event.",path,e);
+            BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Omitting event.",path,e);
         }
 
     }
 
+    private InstanceIdentifier<? extends DataObject> toBinding(final YangInstanceIdentifier path) throws DeserializationException {
+        final Optional<InstanceIdentifier<? extends DataObject>> instanceIdentifierOptional = codec.toBinding(path);
+        if(instanceIdentifierOptional.isPresent()) {
+            return instanceIdentifierOptional.get();
+        } else {
+            throw new DeserializationException("Deserialization unsuccessful, " + instanceIdentifierOptional);
+        }
+    }
+
     @Override
     public void onMountPointRemoved(final YangInstanceIdentifier path) {
         try {
-            final InstanceIdentifier<? extends DataObject> bindingPath = codec.toBinding(path).get();
+            final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
             listener.onMountPointRemoved(bindingPath);
         } catch (final DeserializationException e) {
-            BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Ommiting event.",path,e);
+            BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Omitting event.",path,e);
         }
     }
 }
\ No newline at end of file
index 7f13a7a5ddf95f8f4ed2bb06c0ace36105dbb5f0..a280da9228845ae55ee43b271b7e7dc9743ed325 100644 (file)
@@ -96,7 +96,9 @@ public final class RemoteDeviceId {
                 org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder();
         builder
                 .node(NetworkTopology.QNAME)
+                .node(Topology.QNAME)
                 .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), TopologyNetconf.QNAME.getLocalName())
+                .node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.QNAME)
                 .nodeWithKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.QNAME,
                         QName.create(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.QNAME, "node-id"), name);
         return builder.build();
index 7df760115c168abd00806a50de61426ea471e81c..c4d46a7551a9bac8a3c8987056f8304240e84df8 100644 (file)
@@ -529,7 +529,7 @@ public class ControllerContext implements SchemaContextListener {
                             ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED);
                 }
 
-                final YangInstanceIdentifier partialPath = builder.toInstance();
+                final YangInstanceIdentifier partialPath = dataNormalizer.toNormalized(builder.build());
                 final Optional<DOMMountPoint> mountOpt = mountService.getMountPoint(partialPath);
                 if (!mountOpt.isPresent()) {
                     LOG.debug("Instance identifier to missing mount point: {}", partialPath);
@@ -544,12 +544,7 @@ public class ControllerContext implements SchemaContextListener {
                             ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT);
                 }
 
-                if (returnJustMountPoint) {
-                    final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
-                    return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
-                }
-
-                if (strings.size() == 1) {
+                if (returnJustMountPoint || strings.size() == 1) {
                     final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
                     return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
                 }