X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Ftopology-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmd%2Fcontroller%2Ftopology%2Fmanager%2FFlowCapableTopologyExporter.java;h=361373d78da93f114f51c887ab95c78bc6ab3265;hp=10aec4ca2e85038cdc7ff21dd0ebd4dc4b6cddf6;hb=65292f0c7ee04222ccaaa9c9dcf9ece4438dc96e;hpb=e5a5a73c0ed9f298f539cfda61aa6ba8d3f65c9e diff --git a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java index 10aec4ca2e..361373d78d 100644 --- a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java +++ b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java @@ -15,9 +15,9 @@ import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMap import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNode; import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNodeId; +import java.util.Collection; import java.util.Collections; import java.util.List; - import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; @@ -50,17 +50,19 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, OpendaylightInventoryListener { - private final Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyExporter.class); + private static final Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyExporter.class); private final InstanceIdentifier topology; private final OperationProcessor processor; - FlowCapableTopologyExporter(final OperationProcessor processor, final InstanceIdentifier topology) { + FlowCapableTopologyExporter(final OperationProcessor processor, + final InstanceIdentifier topology) { this.processor = Preconditions.checkNotNull(processor); this.topology = Preconditions.checkNotNull(topology); } @@ -73,15 +75,14 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(final ReadWriteTransaction transaction) { - removeAffectedLinks(nodeId); + public void applyOperation(ReadWriteTransaction transaction) { + removeAffectedLinks(nodeId, transaction); + transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeInstance); } - }); - processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(ReadWriteTransaction transaction) { - transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeInstance); + public String toString() { + return "onNodeRemoved"; } }); } @@ -97,6 +98,11 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open final InstanceIdentifier path = getNodePath(toTopologyNodeId(notification.getId())); transaction.merge(LogicalDatastoreType.OPERATIONAL, path, node, true); } + + @Override + public String toString() { + return "onNodeUpdated"; + } }); } } @@ -104,28 +110,30 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open @Override public void onNodeConnectorRemoved(final NodeConnectorRemoved notification) { - final InstanceIdentifier tpInstance = toTerminationPointIdentifier(notification - .getNodeConnectorRef()); + final InstanceIdentifier tpInstance = toTerminationPointIdentifier( + notification.getNodeConnectorRef()); - processor.enqueueOperation(new TopologyOperation() { - @Override - public void applyOperation(final ReadWriteTransaction transaction) { - final TpId tpId = toTerminationPointId(getNodeConnectorKey(notification.getNodeConnectorRef()).getId()); - removeAffectedLinks(tpId); - } - }); + final TpId tpId = toTerminationPointId(getNodeConnectorKey( + notification.getNodeConnectorRef()).getId()); processor.enqueueOperation(new TopologyOperation() { @Override public void applyOperation(ReadWriteTransaction transaction) { + removeAffectedLinks(tpId, transaction); transaction.delete(LogicalDatastoreType.OPERATIONAL, tpInstance); } + + @Override + public String toString() { + return "onNodeConnectorRemoved"; + } }); } @Override public void onNodeConnectorUpdated(final NodeConnectorUpdated notification) { - final FlowCapableNodeConnectorUpdated fcncu = notification.getAugmentation(FlowCapableNodeConnectorUpdated.class); + final FlowCapableNodeConnectorUpdated fcncu = notification.getAugmentation( + FlowCapableNodeConnectorUpdated.class); if (fcncu != null) { processor.enqueueOperation(new TopologyOperation() { @Override @@ -137,9 +145,14 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open transaction.merge(LogicalDatastoreType.OPERATIONAL, path, point, true); if ((fcncu.getState() != null && fcncu.getState().isLinkDown()) || (fcncu.getConfiguration() != null && fcncu.getConfiguration().isPORTDOWN())) { - removeAffectedLinks(point.getTpId()); + removeAffectedLinks(point.getTpId(), transaction); } } + + @Override + public String toString() { + return "onNodeConnectorUpdated"; + } }); } } @@ -151,7 +164,12 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open public void applyOperation(final ReadWriteTransaction transaction) { final Link link = toTopologyLink(notification); final InstanceIdentifier path = linkPath(link); - transaction.put(LogicalDatastoreType.OPERATIONAL, path, link); + transaction.merge(LogicalDatastoreType.OPERATIONAL, path, link, true); + } + + @Override + public String toString() { + return "onLinkDiscovered"; } }); } @@ -168,6 +186,11 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open public void applyOperation(final ReadWriteTransaction transaction) { transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(toTopologyLink(notification))); } + + @Override + public String toString() { + return "onLinkRemoved"; + } }); } @@ -188,62 +211,92 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open return tpPath(toTopologyNodeId(invNodeKey.getId()), toTerminationPointId(invNodeConnectorKey.getId())); } - private void removeAffectedLinks(final NodeId id) { - processor.enqueueOperation(new TopologyOperation() { + private void removeAffectedLinks(final NodeId id, final ReadWriteTransaction transaction) { + CheckedFuture, ReadFailedException> topologyDataFuture = + transaction.read(LogicalDatastoreType.OPERATIONAL, topology); + Futures.addCallback(topologyDataFuture, new FutureCallback>() { @Override - public void applyOperation(final ReadWriteTransaction transaction) { - CheckedFuture, ReadFailedException> topologyDataFuture = transaction.read(LogicalDatastoreType.OPERATIONAL, topology); - Futures.addCallback(topologyDataFuture, new FutureCallback>() { - @Override - public void onSuccess(Optional topologyOptional) { - if (topologyOptional.isPresent()) { - List linkList = topologyOptional.get().getLink() != null - ? topologyOptional.get().getLink() : Collections. emptyList(); - for (Link link : linkList) { - if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) { - transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link)); - } - } - } - } + public void onSuccess(Optional topologyOptional) { + removeAffectedLinks(id, topologyOptional); + } - @Override - public void onFailure(Throwable throwable) { - LOG.error("Error reading topology data for topology {}", topology, throwable); - } - }); + @Override + public void onFailure(Throwable throwable) { + LOG.error("Error reading topology data for topology {}", topology, throwable); } }); } - private void removeAffectedLinks(final TpId id) { - processor.enqueueOperation(new TopologyOperation() { - @Override - public void applyOperation(final ReadWriteTransaction transaction) { - CheckedFuture, ReadFailedException> topologyDataFuture = transaction.read(LogicalDatastoreType.OPERATIONAL, topology); - Futures.addCallback(topologyDataFuture, new FutureCallback>() { - @Override - public void onSuccess(Optional topologyOptional) { - if (topologyOptional.isPresent()) { - List linkList = topologyOptional.get().getLink() != null - ? topologyOptional.get().getLink() : Collections. emptyList(); - for (Link link : linkList) { - if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) { - transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link)); - } - } - } - } + private void removeAffectedLinks(final NodeId id, Optional topologyOptional) { + if (!topologyOptional.isPresent()) { + return; + } + + List linkList = topologyOptional.get().getLink() != null ? + topologyOptional.get().getLink() : Collections. emptyList(); + final List> linkIDsToDelete = Lists.newArrayList(); + for (Link link : linkList) { + if (id.equals(link.getSource().getSourceNode()) || + id.equals(link.getDestination().getDestNode())) { + linkIDsToDelete.add(linkPath(link)); + } + } + + enqueueLinkDeletes(linkIDsToDelete); + } - @Override - public void onFailure(Throwable throwable) { - LOG.error("Error reading topology data for topology {}", topology, throwable); + private void enqueueLinkDeletes(final Collection> linkIDsToDelete) { + if(!linkIDsToDelete.isEmpty()) { + processor.enqueueOperation(new TopologyOperation() { + @Override + public void applyOperation(ReadWriteTransaction transaction) { + for(InstanceIdentifier linkID: linkIDsToDelete) { + transaction.delete(LogicalDatastoreType.OPERATIONAL, linkID); } - }); + } + + @Override + public String toString() { + return "Delete Links " + linkIDsToDelete.size(); + } + }); + } + } + + private void removeAffectedLinks(final TpId id, final ReadWriteTransaction transaction) { + CheckedFuture, ReadFailedException> topologyDataFuture = + transaction.read(LogicalDatastoreType.OPERATIONAL, topology); + Futures.addCallback(topologyDataFuture, new FutureCallback>() { + @Override + public void onSuccess(Optional topologyOptional) { + removeAffectedLinks(id, topologyOptional); + } + + @Override + public void onFailure(Throwable throwable) { + LOG.error("Error reading topology data for topology {}", topology, throwable); } }); } + private void removeAffectedLinks(final TpId id, Optional topologyOptional) { + if (!topologyOptional.isPresent()) { + return; + } + + List linkList = topologyOptional.get().getLink() != null + ? topologyOptional.get().getLink() : Collections. emptyList(); + final List> linkIDsToDelete = Lists.newArrayList(); + for (Link link : linkList) { + if (id.equals(link.getSource().getSourceTp()) || + id.equals(link.getDestination().getDestTp())) { + linkIDsToDelete.add(linkPath(link)); + } + } + + enqueueLinkDeletes(linkIDsToDelete); + } + private InstanceIdentifier getNodePath(final NodeId nodeId) { return topology.child(Node.class, new NodeKey(nodeId)); }