use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1 in project netvirt by opendaylight.
the class L2GwValidateCli method compareNodes.
private boolean compareNodes(Node node1, Node node2, boolean parentChildComparison, LogicalDatastoreType datastoreType) {
if (node1 == null || node2 == null) {
return false;
}
InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
PhysicalSwitchAugmentation psAug1 = node1.getAugmentation(PhysicalSwitchAugmentation.class);
PhysicalSwitchAugmentation psAug2 = node2.getAugmentation(PhysicalSwitchAugmentation.class);
HwvtepGlobalAugmentation aug1 = node1.getAugmentation(HwvtepGlobalAugmentation.class);
HwvtepGlobalAugmentation aug2 = node2.getAugmentation(HwvtepGlobalAugmentation.class);
boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
for (MergeCommand cmd : commands) {
List<DataObject> data1 = null;
List<DataObject> data2 = null;
if (globalNodes) {
data1 = cmd.getData(aug1);
data2 = cmd.getData(aug2);
} else {
data1 = cmd.getData(node1);
data2 = cmd.getData(node2);
}
data1 = data1 == null ? Collections.EMPTY_LIST : data1;
data2 = data2 == null ? Collections.EMPTY_LIST : data2;
if (parentChildComparison) {
data2 = cmd.transform(nodeIid1, data2);
}
Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
data1 = Lists.transform(data1, withoutUuidTransformer);
data2 = Lists.transform(data2, withoutUuidTransformer);
Map<Identifier<?>, DataObject> map1 = new HashMap<>();
Map<Identifier<?>, DataObject> map2 = new HashMap<>();
for (DataObject dataObject : data1) {
map1.put(cmd.getKey(dataObject), dataObject);
}
for (DataObject dataObject : data2) {
map2.put(cmd.getKey(dataObject), dataObject);
}
Set<DataObject> diff = Sets.newHashSet();
for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
DataObject obj1 = entry.getValue();
DataObject obj2 = map2.get(entry.getKey());
if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
diff.add(obj1);
}
}
if (!diff.isEmpty()) {
if (parentChildComparison) {
pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType + " parent node " + nodeId1 + " contain " + " more entries than child " + nodeId2 + " " + diff.size());
} else {
pw.println("Missing " + cmd.getDescription() + " op entries config " + nodeId1 + " contain " + " more entries than operational node " + diff.size());
}
if (diff.size() < 10) {
for (Object obj : diff) {
pw.println(cmd.getKey((DataObject) obj));
}
}
}
diff = Sets.newHashSet();
for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
DataObject obj1 = entry.getValue();
DataObject obj2 = map1.get(entry.getKey());
if (globalNodes || parentChildComparison) {
if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
diff.add(obj1);
}
}
}
if (!diff.isEmpty()) {
if (parentChildComparison) {
pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node " + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
} else {
pw.println("Extra " + cmd.getDescription() + " operational node " + nodeId2 + " contain " + " more entries than config node " + diff.size());
}
if (diff.size() < 10) {
for (Object obj : diff) {
pw.println(cmd.getKey((DataObject) obj));
}
}
}
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1 in project openflowplugin by opendaylight.
the class TerminationPointChangeListenerImplTest method testOnNodeConnectorRemoved.
@SuppressWarnings("rawtypes")
@Test
public void testOnNodeConnectorRemoved() {
NodeKey topoNodeKey = new NodeKey(new NodeId("node1"));
TerminationPointKey terminationPointKey = new TerminationPointKey(new TpId("tp1"));
final InstanceIdentifier<Node> topoNodeII = topologyIID.child(Node.class, topoNodeKey);
Node topoNode = new NodeBuilder().setKey(topoNodeKey).build();
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey(topoNodeKey.getNodeId().getValue());
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey ncKey = newInvNodeConnKey(terminationPointKey.getTpId().getValue());
final InstanceIdentifier<?> invNodeConnID = newNodeConnID(nodeKey, ncKey);
List<Link> linkList = Arrays.asList(newLink("link1", newSourceTp("tp1"), newDestTp("dest")), newLink("link2", newSourceTp("source"), newDestTp("tp1")), newLink("link3", newSourceTp("source2"), newDestTp("dest2")));
final Topology topology = new TopologyBuilder().setLink(linkList).build();
final InstanceIdentifier[] expDeletedIIDs = { topologyIID.child(Link.class, linkList.get(0).getKey()), topologyIID.child(Link.class, linkList.get(1).getKey()), topologyIID.child(Node.class, new NodeKey(new NodeId("node1"))).child(TerminationPoint.class, new TerminationPointKey(new TpId("tp1"))) };
final SettableFuture<Optional<Topology>> readFuture = SettableFuture.create();
readFuture.set(Optional.of(topology));
ReadWriteTransaction mockTx1 = mock(ReadWriteTransaction.class);
doReturn(Futures.makeChecked(readFuture, ReadFailedException.MAPPER)).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topologyIID);
SettableFuture<Optional<Node>> readFutureNode = SettableFuture.create();
readFutureNode.set(Optional.of(topoNode));
doReturn(Futures.makeChecked(readFutureNode, ReadFailedException.MAPPER)).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
final CountDownLatch submitLatch1 = setupStubbedSubmit(mockTx1);
int expDeleteCalls = expDeletedIIDs.length;
CountDownLatch deleteLatch = new CountDownLatch(expDeleteCalls);
ArgumentCaptor<InstanceIdentifier> deletedLinkIDs = ArgumentCaptor.forClass(InstanceIdentifier.class);
setupStubbedDeletes(mockTx1, deletedLinkIDs, deleteLatch);
doReturn(mockTx1).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(DELETE, invNodeConnID);
terminationPointListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForSubmit(submitLatch1);
setReadFutureAsync(topology, readFuture);
waitForDeletes(expDeleteCalls, deleteLatch);
assertDeletedIDs(expDeletedIIDs, deletedLinkIDs);
verifyMockTx(mockTx1);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1 in project openflowplugin by opendaylight.
the class TerminationPointChangeListenerImplTest method testOnNodeConnectorUpdatedWithPortDown.
@SuppressWarnings("rawtypes")
@Test
public void testOnNodeConnectorUpdatedWithPortDown() {
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey("node1");
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey ncKey = newInvNodeConnKey("tp1");
final InstanceIdentifier<?> invNodeConnID = newNodeConnID(nodeKey, ncKey);
List<Link> linkList = Arrays.asList(newLink("link1", newSourceTp("tp1"), newDestTp("dest")));
Topology topology = new TopologyBuilder().setLink(linkList).build();
ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
doReturn(Futures.immediateCheckedFuture(Optional.of(topology))).when(mockTx).read(LogicalDatastoreType.OPERATIONAL, topologyIID);
setupStubbedSubmit(mockTx);
CountDownLatch deleteLatch = new CountDownLatch(1);
ArgumentCaptor<InstanceIdentifier> deletedLinkIDs = ArgumentCaptor.forClass(InstanceIdentifier.class);
setupStubbedDeletes(mockTx, deletedLinkIDs, deleteLatch);
doReturn(mockTx).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, invNodeConnID);
when(dataTreeModification.getRootNode().getDataAfter()).thenReturn(provideFlowCapableNodeConnector(false, true));
terminationPointListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForDeletes(1, deleteLatch);
InstanceIdentifier<TerminationPoint> expTpPath = topologyIID.child(Node.class, new NodeKey(new NodeId("node1"))).child(TerminationPoint.class, new TerminationPointKey(new TpId("tp1")));
verify(mockTx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(expTpPath), any(TerminationPoint.class), eq(true));
assertDeletedIDs(new InstanceIdentifier[] { topologyIID.child(Link.class, linkList.get(0).getKey()) }, deletedLinkIDs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1 in project openflowplugin by opendaylight.
the class TerminationPointChangeListenerImplTest method testOnNodeConnectorUpdated.
@Test
public void testOnNodeConnectorUpdated() {
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey("node1");
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey ncKey = newInvNodeConnKey("tp1");
InstanceIdentifier<?> invNodeConnID = newNodeConnID(nodeKey, ncKey);
ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
CountDownLatch submitLatch = setupStubbedSubmit(mockTx);
doReturn(mockTx).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, invNodeConnID);
terminationPointListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForSubmit(submitLatch);
ArgumentCaptor<TerminationPoint> mergedNode = ArgumentCaptor.forClass(TerminationPoint.class);
NodeId expNodeId = new NodeId("node1");
TpId expTpId = new TpId("tp1");
InstanceIdentifier<TerminationPoint> expTpPath = topologyIID.child(Node.class, new NodeKey(expNodeId)).child(TerminationPoint.class, new TerminationPointKey(expTpId));
verify(mockTx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(expTpPath), mergedNode.capture(), eq(true));
assertEquals("getTpId", expTpId, mergedNode.getValue().getTpId());
InventoryNodeConnector augmentation = mergedNode.getValue().getAugmentation(InventoryNodeConnector.class);
assertNotNull("Missing augmentation", augmentation);
assertEquals("getInventoryNodeConnectorRef", new NodeConnectorRef(invNodeConnID), augmentation.getInventoryNodeConnectorRef());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1 in project netvirt by opendaylight.
the class L2GwValidateCli method compareNodes.
private <D extends Datastore> boolean compareNodes(Node node1, Node node2, boolean parentChildComparison, Class<D> datastoreType) {
if (node1 == null || node2 == null) {
return false;
}
InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
PhysicalSwitchAugmentation psAug1 = node1.augmentation(PhysicalSwitchAugmentation.class);
PhysicalSwitchAugmentation psAug2 = node2.augmentation(PhysicalSwitchAugmentation.class);
HwvtepGlobalAugmentation aug1 = node1.augmentation(HwvtepGlobalAugmentation.class);
HwvtepGlobalAugmentation aug2 = node2.augmentation(HwvtepGlobalAugmentation.class);
boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
for (MergeCommand cmd : commands) {
List<DataObject> data1 = null;
List<DataObject> data2 = null;
if (globalNodes) {
data1 = cmd.getData(aug1);
data2 = cmd.getData(aug2);
} else {
data1 = cmd.getData(node1);
data2 = cmd.getData(node2);
}
data1 = data1 == null ? Collections.emptyList() : data1;
data2 = data2 == null ? Collections.emptyList() : data2;
if (parentChildComparison) {
data2 = cmd.transform(nodeIid1, data2);
}
Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
data1 = data1.stream().map(withoutUuidTransformer).collect(Collectors.toList());
data2 = data2.stream().map(withoutUuidTransformer).collect(Collectors.toList());
Map<Identifier<?>, DataObject> map1 = new HashMap<>();
Map<Identifier<?>, DataObject> map2 = new HashMap<>();
for (DataObject dataObject : data1) {
map1.put(cmd.getKey(dataObject), dataObject);
}
for (DataObject dataObject : data2) {
map2.put(cmd.getKey(dataObject), dataObject);
}
Set<DataObject> diff = new HashSet<>();
for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
DataObject obj1 = entry.getValue();
DataObject obj2 = map2.get(entry.getKey());
if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
diff.add(obj1);
}
}
if (!diff.isEmpty()) {
if (parentChildComparison) {
pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType + " parent node " + nodeId1 + " contain " + " more entries than child " + nodeId2 + " " + diff.size());
} else {
pw.println("Missing " + cmd.getDescription() + " op entries config " + nodeId1 + " contain " + " more entries than operational node " + diff.size());
}
if (diff.size() < 10) {
for (Object obj : diff) {
pw.println(cmd.getKey((DataObject) obj));
}
}
}
diff = new HashSet<>();
for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
DataObject obj1 = entry.getValue();
DataObject obj2 = map1.get(entry.getKey());
if (globalNodes || parentChildComparison) {
if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
diff.add(obj1);
}
}
}
if (!diff.isEmpty()) {
if (parentChildComparison) {
pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node " + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
} else {
pw.println("Extra " + cmd.getDescription() + " operational node " + nodeId2 + " contain " + " more entries than config node " + diff.size());
}
if (diff.size() < 10) {
for (Object obj : diff) {
pw.println(cmd.getKey((DataObject) obj));
}
}
}
}
return true;
}
Aggregations