From c091b2f1934d325a5c55fb3279631452d7ce4e94 Mon Sep 17 00:00:00 2001 From: Tomas Cere Date: Wed, 16 Dec 2015 19:28:40 +0100 Subject: [PATCH] Move mount point registration after schema resolution Also a couple other minor bugfixes. Change-Id: Id1e412a748225f4194f0b9c5e39d45f6bf58db4c Signed-off-by: Tomas Cere --- .../impl/NetconfNodeManagerCallback.java | 49 +++++++++---------- .../NetconfNodeOperationalDataAggregator.java | 35 +++++++++++-- .../pipeline/TopologyMountPointFacade.java | 16 ++++-- 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java b/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java index 9813bbc878..c4eaae9ad7 100644 --- a/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java +++ b/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java @@ -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()).build()) + .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList()).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()).build()) + .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList()).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()).build()) + .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList()).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()).build()) + .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList()).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 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()).build()) + .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList()).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()).build()) + .setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().setUnavailableCapability(new ArrayList()).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)); } diff --git a/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeOperationalDataAggregator.java b/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeOperationalDataAggregator.java index 1d9e7c9170..4a739f9750 100644 --- a/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeOperationalDataAggregator.java +++ b/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeOperationalDataAggregator.java @@ -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 result) { Node base = null; NetconfNode baseAugmentation = null; + AvailableCapabilities masterCaps = null; + UnavailableCapabilities unavailableMasterCaps = null; final ArrayList 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 result) { Node base = null; NetconfNode baseAugmentation = null; + AvailableCapabilities masterCaps = null; + UnavailableCapabilities unavailableMasterCaps = null; final ArrayList 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); diff --git a/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java b/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java index 33ebb89f55..269db6907b 100644 --- a/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java +++ b/opendaylight/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java @@ -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 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; -- 2.36.6