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 {
23 private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
25 private TopologyManagerUtil() {
29 static void removeAffectedLinks(final NodeId id, final TransactionChainManager manager,
30 final InstanceIdentifier<Topology> topology) {
31 final Optional<Topology> topologyOptional;
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);
39 if (topologyOptional.isPresent()) {
40 for (Link link : topologyOptional.orElseThrow().nonnullLink().values()) {
41 if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
42 manager.addDeleteOperationToTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
48 static void removeAffectedLinks(final TpId id, final TransactionChainManager manager,
49 final InstanceIdentifier<Topology> topology) {
50 final Optional<Topology> topologyOptional;
52 topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).get();
53 } catch (InterruptedException | ExecutionException e) {
54 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
55 LOG.debug("Error reading topology data for topology..", e);
58 if (topologyOptional.isPresent()) {
59 for (Link link : topologyOptional.orElseThrow().nonnullLink().values()) {
60 if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) {
61 manager.addDeleteOperationToTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
67 static InstanceIdentifier<Link> linkPath(final Link link, final InstanceIdentifier<Topology> topology) {
68 return topology.child(Link.class, link.key());