2 * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.applications.topology.manager;
10 import java.util.Optional;
11 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.openflowplugin.common.txchain.TransactionChainManager;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 final class TopologyManagerUtil {
24 private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
26 private TopologyManagerUtil() {
29 static void removeAffectedLinks(final NodeId id, final TransactionChainManager manager,
30 InstanceIdentifier<Topology> topology) {
31 Optional<Topology> topologyOptional = Optional.empty();
33 topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).get();
34 } catch (InterruptedException | ExecutionException e) {
35 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
36 LOG.debug("Error reading topology data for topology.. ", e);
38 if (topologyOptional.isPresent()) {
39 removeAffectedLinks(id, topologyOptional, manager, topology);
43 private static void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional,
44 TransactionChainManager manager,
45 final InstanceIdentifier<Topology> topology) {
46 if (!topologyOptional.isPresent()) {
50 for (Link link : topologyOptional.get().nonnullLink().values()) {
51 if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
52 manager.addDeleteOperationToTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
57 static void removeAffectedLinks(final TpId id, final TransactionChainManager manager,
58 final InstanceIdentifier<Topology> topology) {
59 Optional<Topology> topologyOptional = Optional.empty();
61 topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).get();
62 } catch (InterruptedException | ExecutionException e) {
63 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
64 LOG.debug("Error reading topology data for topology..", e);
66 if (topologyOptional.isPresent()) {
67 removeAffectedLinks(id, topologyOptional, manager, topology);
71 private static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional,
72 TransactionChainManager manager,
73 final InstanceIdentifier<Topology> topology) {
74 if (!topologyOptional.isPresent()) {
78 for (Link link : topologyOptional.get().nonnullLink().values()) {
79 if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) {
80 manager.addDeleteOperationToTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
85 static InstanceIdentifier<Link> linkPath(final Link link, final InstanceIdentifier<Topology> topology) {
86 return topology.child(Link.class, link.key());