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=c1996f4691632637abc9fc7dffacce0bcb12f2ad;hp=6dbfd7225b81fe7651881e21f954dee73c729a7f;hb=1eeb5e88a3593ebd781b733123b8e12cf4cf757c;hpb=0a2c659c014737c7e12a39001310de14d5f85149 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 6dbfd7225b..c1996f4691 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,8 +15,12 @@ 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 org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader; -import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; +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; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryListener; @@ -41,10 +45,18 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; +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 final InstanceIdentifier topology; private final OperationProcessor processor; @@ -55,13 +67,21 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open @Override public void onNodeRemoved(final NodeRemoved notification) { + + final NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeRef()).getId()); + final InstanceIdentifier nodeInstance = toNodeIdentifier(notification.getNodeRef()); + + processor.enqueueOperation(new TopologyOperation() { + @Override + public void applyOperation(final ReadWriteTransaction transaction) { + removeAffectedLinks(nodeId); + } + }); + processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(final DataModificationTransaction transaction) { - NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeRef()).getId()); - InstanceIdentifier nodeInstance = toNodeIdentifier(notification.getNodeRef()); - transaction.removeOperationalData(nodeInstance); - removeAffectedLinks(transaction, nodeId); + public void applyOperation(ReadWriteTransaction transaction) { + transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeInstance); } }); } @@ -72,10 +92,10 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open if (fcnu != null) { processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(final DataModificationTransaction transaction) { - Node node = toTopologyNode(toTopologyNodeId(notification.getId()), notification.getNodeRef()); - InstanceIdentifier path = getNodePath(toTopologyNodeId(notification.getId())); - transaction.putOperationalData(path, node); + public void applyOperation(final ReadWriteTransaction transaction) { + final Node node = toTopologyNode(toTopologyNodeId(notification.getId()), notification.getNodeRef()); + final InstanceIdentifier path = getNodePath(toTopologyNodeId(notification.getId())); + transaction.merge(LogicalDatastoreType.OPERATIONAL, path, node, true); } }); } @@ -83,15 +103,22 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open @Override public void onNodeConnectorRemoved(final NodeConnectorRemoved notification) { + + final InstanceIdentifier tpInstance = toTerminationPointIdentifier(notification + .getNodeConnectorRef()); + processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(final DataModificationTransaction transaction) { - InstanceIdentifier tpInstance = toTerminationPointIdentifier(notification - .getNodeConnectorRef()); - TpId tpId = toTerminationPointId(getNodeConnectorKey(notification.getNodeConnectorRef()).getId()); + public void applyOperation(final ReadWriteTransaction transaction) { + final TpId tpId = toTerminationPointId(getNodeConnectorKey(notification.getNodeConnectorRef()).getId()); + removeAffectedLinks(tpId); + } + }); - transaction.removeOperationalData(tpInstance); - removeAffectedLinks(transaction, tpId); + processor.enqueueOperation(new TopologyOperation() { + @Override + public void applyOperation(ReadWriteTransaction transaction) { + transaction.delete(LogicalDatastoreType.OPERATIONAL, tpInstance); } }); } @@ -102,16 +129,15 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open if (fcncu != null) { processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(final DataModificationTransaction transaction) { - NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeConnectorRef()).getId()); + public void applyOperation(final ReadWriteTransaction transaction) { + final NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeConnectorRef()).getId()); TerminationPoint point = toTerminationPoint(toTerminationPointId(notification.getId()), notification.getNodeConnectorRef()); - InstanceIdentifier path = tpPath(nodeId, point.getKey().getTpId()); - - transaction.putOperationalData(path, point); + final InstanceIdentifier path = tpPath(nodeId, point.getKey().getTpId()); + transaction.merge(LogicalDatastoreType.OPERATIONAL, path, point, true); if ((fcncu.getState() != null && fcncu.getState().isLinkDown()) || (fcncu.getConfiguration() != null && fcncu.getConfiguration().isPORTDOWN())) { - removeAffectedLinks(transaction, point.getTpId()); + removeAffectedLinks(point.getTpId()); } } }); @@ -122,10 +148,10 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open public void onLinkDiscovered(final LinkDiscovered notification) { processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(final DataModificationTransaction transaction) { - Link link = toTopologyLink(notification); - InstanceIdentifier path = linkPath(link); - transaction.putOperationalData(path, link); + public void applyOperation(final ReadWriteTransaction transaction) { + final Link link = toTopologyLink(notification); + final InstanceIdentifier path = linkPath(link); + transaction.merge(LogicalDatastoreType.OPERATIONAL, path, link, true); } }); } @@ -139,8 +165,8 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open public void onLinkRemoved(final LinkRemoved notification) { processor.enqueueOperation(new TopologyOperation() { @Override - public void applyOperation(final DataModificationTransaction transaction) { - transaction.removeOperationalData(linkPath(toTopologyLink(notification))); + public void applyOperation(final ReadWriteTransaction transaction) { + transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(toTopologyLink(notification))); } }); } @@ -162,28 +188,60 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open return tpPath(toTopologyNodeId(invNodeKey.getId()), toTerminationPointId(invNodeConnectorKey.getId())); } - private void removeAffectedLinks(final DataModificationTransaction transaction, final NodeId id) { - TypeSafeDataReader reader = TypeSafeDataReader.forReader(transaction); - Topology topologyData = reader.readOperationalData(topology); - if (topologyData != null) { - for (Link link : topologyData.getLink()) { - if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) { - transaction.removeOperationalData(linkPath(link)); - } + private void removeAffectedLinks(final NodeId 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().getSourceNode()) || id.equals(link.getDestination().getDestNode())) { + transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link)); + } + } + } + } + + @Override + public void onFailure(Throwable throwable) { + LOG.error("Error reading topology data for topology {}", topology, throwable); + } + }); } - } + }); } - private void removeAffectedLinks(final DataModificationTransaction transaction, final TpId id) { - TypeSafeDataReader reader = TypeSafeDataReader.forReader(transaction); - Topology topologyData = reader.readOperationalData(topology); - if (topologyData != null) { - for (Link link : topologyData.getLink()) { - if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) { - transaction.removeOperationalData(linkPath(link)); - } + 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)); + } + } + } + } + + @Override + public void onFailure(Throwable throwable) { + LOG.error("Error reading topology data for topology {}", topology, throwable); + } + }); } - } + }); } private InstanceIdentifier getNodePath(final NodeId nodeId) {