*/
package org.opendaylight.md.controller.topology.manager;
-import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.getNodeConnectorKey;
-import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.getNodeKey;
-import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTerminationPoint;
-import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTerminationPointId;
-import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyLink;
-import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNode;
-import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNodeId;
-
-import java.util.Collections;
-import java.util.List;
-
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
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.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;
+import java.util.Collections;
+import java.util.List;
+
+import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.getNodeConnectorKey;
+import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.getNodeKey;
+import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTerminationPoint;
+import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTerminationPointId;
+import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyLink;
+import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNode;
+import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNodeId;
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> topology;
private final OperationProcessor processor;
- FlowCapableTopologyExporter(final OperationProcessor processor, final InstanceIdentifier<Topology> topology) {
+ FlowCapableTopologyExporter(final OperationProcessor processor,
+ final InstanceIdentifier<Topology> topology) {
this.processor = Preconditions.checkNotNull(processor);
this.topology = Preconditions.checkNotNull(topology);
}
final NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeRef()).getId());
final InstanceIdentifier<Node> nodeInstance = toNodeIdentifier(notification.getNodeRef());
+
processor.enqueueOperation(new TopologyOperation() {
@Override
- public void applyOperation(final ReadWriteTransaction transaction) {
- removeAffectedLinks(nodeId);
+ public void applyOperation(ReadWriteTransaction transaction) {
+ Optional<Node> nodeOptional = Optional.absent();
+ try {
+ nodeOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, nodeInstance).checkedGet();
+ } catch (ReadFailedException e) {
+ LOG.error("Error occured when trying to read Node ", e);
+ }
+ if (nodeOptional.isPresent()) {
+ 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";
}
});
}
final InstanceIdentifier<Node> path = getNodePath(toTopologyNodeId(notification.getId()));
transaction.merge(LogicalDatastoreType.OPERATIONAL, path, node, true);
}
+
+ @Override
+ public String toString() {
+ return "onNodeUpdated";
+ }
});
}
}
@Override
public void onNodeConnectorRemoved(final NodeConnectorRemoved notification) {
- final InstanceIdentifier<TerminationPoint> tpInstance = toTerminationPointIdentifier(notification
- .getNodeConnectorRef());
+ final InstanceIdentifier<TerminationPoint> tpInstance = toTerminationPointIdentifier(
+ notification.getNodeConnectorRef());
+
+ final TpId tpId = toTerminationPointId(getNodeConnectorKey(
+ notification.getNodeConnectorRef()).getId());
processor.enqueueOperation(new TopologyOperation() {
@Override
- public void applyOperation(final ReadWriteTransaction transaction) {
- final TpId tpId = toTerminationPointId(getNodeConnectorKey(notification.getNodeConnectorRef()).getId());
- removeAffectedLinks(tpId);
+ public void applyOperation(ReadWriteTransaction transaction) {
+ Optional<TerminationPoint> terminationPointOptional = Optional.absent();
+ try {
+ terminationPointOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, tpInstance).checkedGet();
+ } catch (ReadFailedException e) {
+ LOG.error("Error occured when trying to read NodeConnector ", e);
+ }
+ if (terminationPointOptional.isPresent()) {
+ removeAffectedLinks(tpId, transaction);
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, tpInstance);
+ }
}
- });
- processor.enqueueOperation(new TopologyOperation() {
@Override
- public void applyOperation(ReadWriteTransaction transaction) {
- transaction.delete(LogicalDatastoreType.OPERATIONAL, tpInstance);
+ 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
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";
+ }
});
}
}
public void applyOperation(final ReadWriteTransaction transaction) {
final Link link = toTopologyLink(notification);
final InstanceIdentifier<Link> path = linkPath(link);
- transaction.merge(LogicalDatastoreType.OPERATIONAL, path, link, true);
+ transaction.put(LogicalDatastoreType.OPERATIONAL, path, link, true);
+ }
+
+ @Override
+ public String toString() {
+ return "onLinkDiscovered";
}
});
}
processor.enqueueOperation(new TopologyOperation() {
@Override
public void applyOperation(final ReadWriteTransaction transaction) {
- transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(toTopologyLink(notification)));
+ Optional<Link> linkOptional = Optional.absent();
+ try {
+ // read that checks if link exists (if we do not do this we might get an exception on delete)
+ linkOptional = transaction.read(LogicalDatastoreType.OPERATIONAL,
+ linkPath(toTopologyLink(notification))).checkedGet();
+ } catch (ReadFailedException e) {
+ LOG.error("Error occured when trying to read Link ", e);
+ }
+ if (linkOptional.isPresent()) {
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(toTopologyLink(notification)));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "onLinkRemoved";
}
});
}
+
@Override
public void onLinkUtilizationNormal(final LinkUtilizationNormal notification) {
// NOOP
return tpPath(toTopologyNodeId(invNodeKey.getId()), toTerminationPointId(invNodeConnectorKey.getId()));
}
- private void removeAffectedLinks(final NodeId id) {
- processor.enqueueOperation(new TopologyOperation() {
- @Override
- public void applyOperation(final ReadWriteTransaction transaction) {
- CheckedFuture<Optional<Topology>, ReadFailedException> topologyDataFuture = transaction.read(LogicalDatastoreType.OPERATIONAL, topology);
- Futures.addCallback(topologyDataFuture, new FutureCallback<Optional<Topology>>() {
- @Override
- public void onSuccess(Optional<Topology> topologyOptional) {
- if (topologyOptional.isPresent()) {
- List<Link> linkList = topologyOptional.get().getLink() != null
- ? topologyOptional.get().getLink() : Collections.<Link> emptyList();
- for (Link link : linkList) {
- if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
- transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link));
- }
- }
- }
- }
+ private void removeAffectedLinks(final NodeId id, final ReadWriteTransaction transaction) {
+ Optional<Topology> topologyOptional = Optional.absent();
+ try {
+ topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
+ } catch (ReadFailedException e) {
+ LOG.error("Error reading topology data for topology {}", topology, e);
+ }
+ if (topologyOptional.isPresent()) {
+ removeAffectedLinks(id, topologyOptional, transaction);
+ }
+ }
- @Override
- public void onFailure(Throwable throwable) {
- LOG.error("Error reading topology data for topology {}", topology, throwable);
- }
- });
+ private void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional, ReadWriteTransaction transaction) {
+ if (!topologyOptional.isPresent()) {
+ return;
+ }
+
+ List<Link> linkList = topologyOptional.get().getLink() != null ?
+ topologyOptional.get().getLink() : Collections.<Link> emptyList();
+ for (Link link : linkList) {
+ if (id.equals(link.getSource().getSourceNode()) ||
+ id.equals(link.getDestination().getDestNode())) {
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link));
}
- });
+ }
}
- private void removeAffectedLinks(final TpId id) {
- processor.enqueueOperation(new TopologyOperation() {
- @Override
- public void applyOperation(final ReadWriteTransaction transaction) {
- CheckedFuture<Optional<Topology>, ReadFailedException> topologyDataFuture = transaction.read(LogicalDatastoreType.OPERATIONAL, topology);
- Futures.addCallback(topologyDataFuture, new FutureCallback<Optional<Topology>>() {
- @Override
- public void onSuccess(Optional<Topology> topologyOptional) {
- if (topologyOptional.isPresent()) {
- List<Link> linkList = topologyOptional.get().getLink() != null
- ? topologyOptional.get().getLink() : Collections.<Link> 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 TpId id, final ReadWriteTransaction transaction) {
+ Optional<Topology> topologyOptional = Optional.absent();
+ try {
+ topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
+ } catch (ReadFailedException e) {
+ LOG.error("Error reading topology data for topology {}", topology, e);
+ }
+ if (topologyOptional.isPresent()) {
+ removeAffectedLinks(id, topologyOptional, transaction);
+ }
+ }
- @Override
- public void onFailure(Throwable throwable) {
- LOG.error("Error reading topology data for topology {}", topology, throwable);
- }
- });
+ private void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional, ReadWriteTransaction transaction) {
+ if (!topologyOptional.isPresent()) {
+ return;
+ }
+
+ List<Link> linkList = topologyOptional.get().getLink() != null
+ ? topologyOptional.get().getLink() : Collections.<Link> emptyList();
+ for (Link link : linkList) {
+ if (id.equals(link.getSource().getSourceTp()) ||
+ id.equals(link.getDestination().getDestTp())) {
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link));
}
- });
+ }
}
private InstanceIdentifier<Node> getNodePath(final NodeId nodeId) {