@Test public void testOnDataTreeChange_createAndDeleteNode() throws Exception { Node sxpNode = new NodeBuilder().setNodeId(new NodeId(SXP_NODE_ID)) .addAugmentation(SxpNodeIdentity.class, new SxpNodeIdentityBuilder().setSxpDomains(new SxpDomainsBuilder() .setSxpDomain(Collections.singletonList( new SxpDomainBuilder() .setDomainName(SXP_DOMAIN_NAME) .build())) .build()).build()) .build(); InstanceIdentifier<Node> sxpNodeIid = InstanceIdentifier.builder(NetworkTopology.class) .child(Topology.class, new TopologyKey(new TopologyId(IpSgtDistributionServiceImpl.SXP_TOPOLOGY_ID))) .child(Node.class, new NodeKey(new NodeId(SXP_NODE_ID))) .build(); WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); wtx.put(LogicalDatastoreType.CONFIGURATION, sxpNodeIid, sxpNode, true); Node node = new NodeBuilder().setNodeId(new NodeId(NODE_ID)) .addAugmentation(SxpConnectionAugmentation.class, new SxpConnectionAugmentationBuilder() .setSxpConnection(new SxpConnectionBuilder().setIpAddress(IP_ADDR).setPassword(PASSWD).build()).build()) .build(); InstanceIdentifier<Node> nodeIid = InstanceIdentifier.builder(NetworkTopology.class) .child(Topology.class, new TopologyKey(new TopologyId(TOPOLOGY_ID))) .child(Node.class, new NodeKey(new NodeId(NODE_ID))) .build(); wtx.put(LogicalDatastoreType.CONFIGURATION, nodeIid, node, true); wtx.submit().get(); assertEquals(DOMAIN_ID, nodeListener.getDomainIdForPeer(nodeIid)); InstanceIdentifier<SxpDomain> domainIid = InstanceIdentifier.builder(NetworkTopology.class) .child(Topology.class, new TopologyKey(new TopologyId(IpSgtDistributionServiceImpl.SXP_TOPOLOGY_ID))) .child(Node.class, new NodeKey(new NodeId(SXP_NODE_ID))) .augmentation(SxpNodeIdentity.class) .child(SxpDomains.class) .child(SxpDomain.class, new SxpDomainKey(DOMAIN_ID)) .build(); ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction(); CheckedFuture<Optional<SxpDomain>, ReadFailedException> read = rtx.read(LogicalDatastoreType.CONFIGURATION, domainIid); Optional<SxpDomain> optionalDomain = read.get(); assertTrue(optionalDomain.isPresent()); SxpDomain sxpDomain = optionalDomain.get(); Connections connections = sxpDomain.getConnections(); assertNotNull(connections); List<Connection> connectionList = connections.getConnection(); assertNotNull(connectionList); assertEquals(1, connectionList.size()); Connection connection = connectionList.get(0); assertEquals(IP_ADDR, connection.getPeerAddress()); assertEquals(PASSWD, connection.getPassword()); assertEquals(SXP_PORT, connection.getTcpPort()); assertEquals(ConnectionMode.Speaker, connection.getMode()); wtx = dataBroker.newWriteOnlyTransaction(); wtx.delete(LogicalDatastoreType.CONFIGURATION, nodeIid); wtx.submit().get(); assertNull(nodeListener.getDomainIdForPeer(nodeIid)); rtx = dataBroker.newReadOnlyTransaction(); read = rtx.read(LogicalDatastoreType.CONFIGURATION, domainIid); assertFalse(read.get().isPresent()); }
synchronized String getDomainIdForPeer(InstanceIdentifier<Node> peer) { return sxpCapableNodes.get(peer); }
SxpCapableNodeListener implements DataTreeChangeListener<SxpConnection> { synchronized String getDomainIdForPeer(InstanceIdentifier<Node> peer) { return sxpCapableNodes.get(peer); } }
SxpCapableNodeListener implements DataTreeChangeListener<SxpConnection> { synchronized String getDomainIdForPeer(InstanceIdentifier<Node> peer) { return sxpCapableNodes.get(peer); } SxpCapableNodeListener(DataBroker dataBroker, String sxpNodeId); }
SxpCapableNodeListener implements DataTreeChangeListener<SxpConnection> { synchronized String getDomainIdForPeer(InstanceIdentifier<Node> peer) { return sxpCapableNodes.get(peer); } SxpCapableNodeListener(DataBroker dataBroker, String sxpNodeId); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<SxpConnection>> changes); }
SxpCapableNodeListener implements DataTreeChangeListener<SxpConnection> { synchronized String getDomainIdForPeer(InstanceIdentifier<Node> peer) { return sxpCapableNodes.get(peer); } SxpCapableNodeListener(DataBroker dataBroker, String sxpNodeId); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<SxpConnection>> changes);  }