Move mount point registration after schema resolution 72/31472/4
authorTomas Cere <tcere@cisco.com>
Wed, 16 Dec 2015 18:28:40 +0000 (19:28 +0100)
committerTomas Cere <tcere@cisco.com>
Mon, 21 Dec 2015 12:22:34 +0000 (12:22 +0000)
Also a couple other minor bugfixes.

Change-Id: Id1e412a748225f4194f0b9c5e39d45f6bf58db4c
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java
opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeOperationalDataAggregator.java
opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java

index 9813bbc878be3227466e114ad959e2d0713ea39d..c4eaae9ad77c3e8c67ee66c7f3378b263052e172 100644 (file)
@@ -166,6 +166,8 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
                                 .setHost(netconfNode.getHost())
                                 .setPort(netconfNode.getPort())
                                 .setConnectionStatus(ConnectionStatus.Connecting)
+                                .setAvailableCapabilities(new AvailableCapabilitiesBuilder().setAvailableCapability(new ArrayList<String>()).build())
+                                .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList<UnavailableCapability>()).build())
                                 .setClusteredConnectionStatus(
                                         new ClusteredConnectionStatusBuilder()
                                                 .setNodeStatus(
@@ -196,6 +198,8 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
                                 .setHost(netconfNode.getHost())
                                 .setPort(netconfNode.getPort())
                                 .setConnectionStatus(ConnectionStatus.UnableToConnect)
+                                .setAvailableCapabilities(new AvailableCapabilitiesBuilder().setAvailableCapability(new ArrayList<String>()).build())
+                                .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList<UnavailableCapability>()).build())
                                 .setClusteredConnectionStatus(
                                         new ClusteredConnectionStatusBuilder()
                                                 .setNodeStatus(
@@ -262,8 +266,8 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
                                                         .build())
                                         .setHost(netconfNode.getHost())
                                         .setPort(netconfNode.getPort())
-                                        .setAvailableCapabilities(new AvailableCapabilitiesBuilder().build())
-                                        .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().build())
+                                        .setAvailableCapabilities(new AvailableCapabilitiesBuilder().setAvailableCapability(new ArrayList<String>()).build())
+                                        .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList<UnavailableCapability>()).build())
                                         .build()).build();
                 return currentOperationalNode;
             }
@@ -320,8 +324,8 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
                                                         .build())
                                         .setHost(netconfNode.getHost())
                                         .setPort(netconfNode.getPort())
-                                        .setAvailableCapabilities(new AvailableCapabilitiesBuilder().build())
-                                        .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().build())
+                                        .setAvailableCapabilities(new AvailableCapabilitiesBuilder().setAvailableCapability(new ArrayList<String>()).build())
+                                        .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList<UnavailableCapability>()).build())
                                         .build())
                         .build();
             }
@@ -351,29 +355,20 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
         topologyDispatcher.unregisterMountPoint(new NodeId(nodeId));
 
         isMaster = roleChangeDTO.isOwner();
-        if (isMaster) {
-            LOG.warn("Gained ownership of node - registering master mount point");
-            topologyDispatcher.registerMountPoint(TypedActor.context(), new NodeId(nodeId));
-        } else {
-            // even though mount point is ready, we dont know who the master mount point will be since we havent received the announce msg
-            // after we receive the message we can go ahead and register the mount point
-            if (connected && masterDataBrokerRef != null) {
-                topologyDispatcher.registerMountPoint(TypedActor.context(), new NodeId(nodeId), masterDataBrokerRef);
-            } else {
-                LOG.debug("Mount point is ready, still waiting for master mount point");
-            }
-        }
     }
 
     @Override
     public void onDeviceConnected(final SchemaContext remoteSchemaContext, final NetconfSessionPreferences netconfSessionPreferences, final DOMRpcService deviceRpc) {
         // we need to notify the higher level that something happened, get a current status from all other nodes, and aggregate a new result
         connected = true;
-        if (!isMaster && masterDataBrokerRef != null) {
-            // if we're not master but one is present already, we need to register mountpoint
+        if (isMaster) {
+            LOG.debug("Master is done with schema resolution, registering mount point");
+            topologyDispatcher.registerMountPoint(TypedActor.context(), new NodeId(nodeId));
+        } else if (masterDataBrokerRef != null) {
             LOG.warn("Device connected, master already present in topology, registering mount point");
             topologyDispatcher.registerMountPoint(cachedContext, new NodeId(nodeId), masterDataBrokerRef);
         }
+
         List<String> capabilityList = new ArrayList<>();
         capabilityList.addAll(netconfSessionPreferences.getNetconfDeviceCapabilities().getNonModuleBasedCapabilities());
         capabilityList.addAll(FluentIterable.from(netconfSessionPreferences.getNetconfDeviceCapabilities().getResolvedCapabilities()).transform(AVAILABLE_CAPABILITY_TRANSFORMER).toList());
@@ -413,10 +408,6 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
         LOG.debug("onDeviceDisconnected received, unregistered role candidate");
         connected = false;
         if (isMaster) {
-            // announce that master mount point is going down
-//            for (final Member member : clusterExtension.state().getMembers()) {
-//                actorSystem.actorSelection(member.address() + "/user/" + topologyId + "/" + nodeId).tell(new AnnounceMasterMountPointDown(), null);
-//            }
             // set master to false since we are unregistering, the ownershipChanged callback can sometimes lag behind causing multiple nodes behaving as masters
             isMaster = false;
             // onRoleChanged() callback can sometimes lag behind, so unregister the mount right when it disconnects
@@ -428,6 +419,8 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
                 .addAugmentation(NetconfNode.class,
                         new NetconfNodeBuilder()
                                 .setConnectionStatus(ConnectionStatus.Connecting)
+                                .setAvailableCapabilities(new AvailableCapabilitiesBuilder().setAvailableCapability(new ArrayList<String>()).build())
+                                .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList<UnavailableCapability>()).build())
                                 .setClusteredConnectionStatus(
                                         new ClusteredConnectionStatusBuilder()
                                                 .setNodeStatus(
@@ -447,7 +440,7 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
     public void onDeviceFailed(Throwable throwable) {
         // we need to notify the higher level that something happened, get a current status from all other nodes, and aggregate a new result
         // no need to remove mountpoint, we should receive onRoleChanged callback after unregistering from election that unregisters the mountpoint
-        LOG.debug("onDeviceFailed received");
+        LOG.warn("Netconf node {} failed with {}", nodeId, throwable);
         connected = false;
         String reason = (throwable != null && throwable.getMessage() != null) ? throwable.getMessage() : UNKNOWN_REASON;
 
@@ -455,6 +448,8 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
                 .addAugmentation(NetconfNode.class,
                         new NetconfNodeBuilder()
                                 .setConnectionStatus(ConnectionStatus.UnableToConnect)
+                                .setAvailableCapabilities(new AvailableCapabilitiesBuilder().setAvailableCapability(new ArrayList<String>()).build())
+                                .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList<UnavailableCapability>()).build())
                                 .setClusteredConnectionStatus(
                                         new ClusteredConnectionStatusBuilder()
                                                 .setNodeStatus(
@@ -481,17 +476,17 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
 
     @Override
     public void onReceive(Object message, ActorRef actorRef) {
-        LOG.warn("Netconf node callback received message {}", message);
+        LOG.debug("Netconf node callback received message {}", message);
         if (message instanceof AnnounceMasterMountPoint) {
             masterDataBrokerRef = actorRef;
             // candidate gets registered when mount point is already prepared so we can go ahead a register it
-            if (roleChangeStrategy.isCandidateRegistered()) {
+            if (connected) {
                 topologyDispatcher.registerMountPoint(TypedActor.context(), new NodeId(nodeId), masterDataBrokerRef);
             } else {
-                LOG.warn("Announce master mount point msg received but mount point is not ready yet");
+                LOG.debug("Announce master mount point msg received but mount point is not ready yet");
             }
         } else if (message instanceof AnnounceMasterMountPointDown) {
-            LOG.warn("Master mountpoint went down");
+            LOG.debug("Master mountpoint went down");
             masterDataBrokerRef = null;
             topologyDispatcher.unregisterMountPoint(new NodeId(nodeId));
         }
index 1d9e7c91700fb8ea682aa08ab726e42e708c2cd7..4a739f9750642c7166a65388736e6c23bfe8ed65 100644 (file)
@@ -18,7 +18,9 @@ import org.opendaylight.netconf.topology.StateAggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.ClusteredConnectionStatusBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.UnavailableCapabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.clustered.connection.status.NodeStatus;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
@@ -38,6 +40,8 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
             public void onSuccess(final List<Node> result) {
                 Node base = null;
                 NetconfNode baseAugmentation = null;
+                AvailableCapabilities masterCaps = null;
+                UnavailableCapabilities unavailableMasterCaps = null;
                 final ArrayList<NodeStatus> statusList = new ArrayList<>();
                 for (final Node node : result) {
                     final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
@@ -45,6 +49,15 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
                         base = node;
                         baseAugmentation = netconfNode;
                     }
+                    // we need to pull out caps from master, since slave does not go through resolution
+                    if (masterCaps == null) {
+                        masterCaps = netconfNode.getAvailableCapabilities();
+                        unavailableMasterCaps = netconfNode.getUnavailableCapabilities();
+                    }
+                    if (netconfNode.getAvailableCapabilities().getAvailableCapability().size() > masterCaps.getAvailableCapability().size()) {
+                        masterCaps = netconfNode.getAvailableCapabilities();
+                        unavailableMasterCaps = netconfNode.getUnavailableCapabilities();
+                    }
                     LOG.debug(netconfNode.toString());
                     statusList.addAll(netconfNode.getClusteredConnectionStatus().getNodeStatus());
                 }
@@ -52,11 +65,9 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
                 if (base == null) {
                     base = result.get(0);
                     baseAugmentation = result.get(0).getAugmentation(NetconfNode.class);
-                    LOG.warn("All results {}", result.toString());
+                    LOG.debug("All results {}", result.toString());
                 }
 
-                LOG.warn("Base node: {}", base);
-
                 final Node aggregatedNode =
                         new NodeBuilder(base)
                                 .addAugmentation(NetconfNode.class,
@@ -65,8 +76,11 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
                                                         new ClusteredConnectionStatusBuilder()
                                                                 .setNodeStatus(statusList)
                                                                 .build())
+                                                .setAvailableCapabilities(masterCaps)
+                                                .setUnavailableCapabilities(unavailableMasterCaps)
                                                 .build())
                                 .build();
+
                 future.set(aggregatedNode);
             }
 
@@ -88,6 +102,8 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
             public void onSuccess(final List<Node> result) {
                 Node base = null;
                 NetconfNode baseAugmentation = null;
+                AvailableCapabilities masterCaps = null;
+                UnavailableCapabilities unavailableMasterCaps = null;
                 final ArrayList<NodeStatus> statusList = new ArrayList<>();
                 for (final Node node : result) {
                     final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
@@ -95,6 +111,15 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
                         base = node;
                         baseAugmentation = netconfNode;
                     }
+                    // we need to pull out caps from master, since slave does not go through resolution
+                    if (masterCaps == null) {
+                        masterCaps = netconfNode.getAvailableCapabilities();
+                        unavailableMasterCaps = netconfNode.getUnavailableCapabilities();
+                    }
+                    if (netconfNode.getAvailableCapabilities().getAvailableCapability().size() > masterCaps.getAvailableCapability().size()) {
+                        masterCaps = netconfNode.getAvailableCapabilities();
+                        unavailableMasterCaps = netconfNode.getUnavailableCapabilities();
+                    }
                     LOG.debug(netconfNode.toString());
                     statusList.addAll(netconfNode.getClusteredConnectionStatus().getNodeStatus());
                 }
@@ -102,7 +127,7 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
                 if (base == null) {
                     base = result.get(0);
                     baseAugmentation = result.get(0).getAugmentation(NetconfNode.class);
-                    LOG.warn("All results {}", result.toString());
+                    LOG.debug("All results {}", result.toString());
                 }
 
                 final Node aggregatedNode =
@@ -113,6 +138,8 @@ public class NetconfNodeOperationalDataAggregator implements StateAggregator{
                                                         new ClusteredConnectionStatusBuilder()
                                                                 .setNodeStatus(statusList)
                                                                 .build())
+                                                .setAvailableCapabilities(masterCaps)
+                                                .setUnavailableCapabilities(unavailableMasterCaps)
                                                 .build())
                                 .build();
                 future.set(aggregatedNode);
index 33ebb89f559478e3dda9be4c01f40e5807f947f7..269db6907bc987757b3f642966434cf343bdec11 100644 (file)
@@ -78,6 +78,7 @@ public class TopologyMountPointFacade implements AutoCloseable, RemoteDeviceHand
                                   final NetconfSessionPreferences netconfSessionPreferences,
                                   final DOMRpcService deviceRpc) {
         // prepare our prerequisites for mountpoint
+        LOG.debug("Mount point facade onConnected capabilities {}", netconfSessionPreferences);
         this.remoteSchemaContext = remoteSchemaContext;
         this.netconfSessionPreferences = netconfSessionPreferences;
         this.deviceRpc = deviceRpc;
@@ -108,6 +109,11 @@ public class TopologyMountPointFacade implements AutoCloseable, RemoteDeviceHand
     }
 
     public void registerMountPoint(final ActorSystem actorSystem, final ActorContext context) {
+        if (remoteSchemaContext == null || netconfSessionPreferences == null) {
+            LOG.debug("Master mount point does not have schemas ready yet, delaying registration");
+            return;
+        }
+
         Preconditions.checkNotNull(id);
         Preconditions.checkNotNull(remoteSchemaContext, "Device has no remote schema context yet. Probably not fully connected.");
         Preconditions.checkNotNull(netconfSessionPreferences, "Device has no capabilities yet. Probably not fully connected.");
@@ -121,7 +127,7 @@ public class TopologyMountPointFacade implements AutoCloseable, RemoteDeviceHand
                 return new NetconfDeviceMasterDataBroker(actorSystem, id, remoteSchemaContext, deviceRpc, netconfSessionPreferences, defaultRequestTimeoutMillis);
             }
         }), MOUNT_POINT);
-        LOG.warn("Master data broker registered on path {}", TypedActor.get(actorSystem).getActorRefFor(deviceDataBroker).path());
+        LOG.debug("Master data broker registered on path {}", TypedActor.get(actorSystem).getActorRefFor(deviceDataBroker).path());
         salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, deviceDataBroker, deviceRpc, notificationService);
         final Cluster cluster = Cluster.get(actorSystem);
         final Iterable<Member> members = cluster.state().getMembers();
@@ -135,13 +141,17 @@ public class TopologyMountPointFacade implements AutoCloseable, RemoteDeviceHand
     }
 
     public void registerMountPoint(final ActorSystem actorSystem, final ActorContext context, final ActorRef masterRef) {
+        if (remoteSchemaContext == null || netconfSessionPreferences == null) {
+            LOG.debug("Slave mount point does not have schemas ready yet, delaying registration");
+            return;
+        }
+
         Preconditions.checkNotNull(id);
         Preconditions.checkNotNull(remoteSchemaContext, "Device has no remote schema context yet. Probably not fully connected.");
         Preconditions.checkNotNull(netconfSessionPreferences, "Device has no capabilities yet. Probably not fully connected.");
         this.actorSystem = actorSystem;
         final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
 
-        LOG.warn("Creating a proxy for master data broker");
         final ProxyNetconfDeviceDataBroker masterDataBroker = TypedActor.get(actorSystem).typedActorOf(new TypedProps<>(ProxyNetconfDeviceDataBroker.class, NetconfDeviceMasterDataBroker.class), masterRef);
         LOG.warn("Creating slave data broker for device {}", id);
         final DOMDataBroker deviceDataBroker = new NetconfDeviceSlaveDataBroker(actorSystem, id, masterDataBroker);
@@ -151,7 +161,7 @@ public class TopologyMountPointFacade implements AutoCloseable, RemoteDeviceHand
     public void unregisterMountPoint() {
         salProvider.getMountInstance().onTopologyDeviceDisconnected();
         if (deviceDataBroker != null) {
-            LOG.warn("Stopping master data broker for device {}", id.getName());
+            LOG.debug("Stopping master data broker for device {}", id.getName());
             for (final Member member : Cluster.get(actorSystem).state().getMembers()) {
                 if (member.address().equals(Cluster.get(actorSystem).selfAddress())) {
                     continue;