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 com.google.common.base.Optional;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.concurrent.ExecutionException;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.openflowplugin.common.txchain.TransactionChainManager;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 final class TopologyManagerUtil {
26 private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
28 private TopologyManagerUtil() {
31 static void removeAffectedLinks(final NodeId id, final TransactionChainManager manager,
32 InstanceIdentifier<Topology> topology) {
33 Optional<Topology> topologyOptional = Optional.absent();
35 topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).get();
36 } catch (InterruptedException | ExecutionException e) {
37 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
38 LOG.debug("Error reading topology data for topology.. ", e);
40 if (topologyOptional.isPresent()) {
41 removeAffectedLinks(id, topologyOptional, manager, topology);
45 private static void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional,
46 TransactionChainManager manager,
47 final InstanceIdentifier<Topology> topology) {
48 if (!topologyOptional.isPresent()) {
53 topologyOptional.get().getLink() != null ? topologyOptional.get().getLink() : Collections.emptyList();
54 for (Link link : linkList) {
55 if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
56 manager.addDeleteOperationToTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
61 static void removeAffectedLinks(final TpId id, final TransactionChainManager manager,
62 final InstanceIdentifier<Topology> topology) {
63 Optional<Topology> topologyOptional = Optional.absent();
65 topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).get();
66 } catch (InterruptedException | ExecutionException e) {
67 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
68 LOG.debug("Error reading topology data for topology..", e);
70 if (topologyOptional.isPresent()) {
71 removeAffectedLinks(id, topologyOptional, manager, topology);
75 private static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional,
76 TransactionChainManager manager,
77 final InstanceIdentifier<Topology> topology) {
78 if (!topologyOptional.isPresent()) {
82 List<Link> linkList = topologyOptional.get().getLink() != null ? topologyOptional.get()
83 .getLink() : Collections.<Link>emptyList();
84 for (Link link : linkList) {
85 if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) {
86 manager.addDeleteOperationToTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
91 static InstanceIdentifier<Link> linkPath(final Link link, final InstanceIdentifier<Topology> topology) {
92 return topology.child(Link.class, link.getKey());