2 * Copyright (c) 2015 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
9 package org.opendaylight.netconf.topology.impl;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.SettableFuture;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.opendaylight.netconf.topology.StateAggregator;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.ClusteredConnectionStatusBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.clustered.connection.status.NodeStatus;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class NetconfNodeOperationalDataAggregator implements StateAggregator{
30 private static final Logger LOG = LoggerFactory.getLogger(NetconfNodeOperationalDataAggregator.class);
33 public ListenableFuture<Node> combineCreateAttempts(final List<ListenableFuture<Node>> stateFutures) {
34 final SettableFuture<Node> future = SettableFuture.create();
35 final ListenableFuture<List<Node>> allAsList = Futures.allAsList(stateFutures);
36 Futures.addCallback(allAsList, new FutureCallback<List<Node>>() {
38 public void onSuccess(final List<Node> result) {
40 NetconfNode baseAugmentation = null;
41 final ArrayList<NodeStatus> statusList = new ArrayList<>();
42 for (final Node node : result) {
43 final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
44 if (base == null && netconfNode.getConnectionStatus().equals(ConnectionStatus.Connected)) {
46 baseAugmentation = netconfNode;
48 LOG.debug(netconfNode.toString());
49 statusList.addAll(netconfNode.getClusteredConnectionStatus().getNodeStatus());
54 baseAugmentation = result.get(0).getAugmentation(NetconfNode.class);
55 LOG.warn("All results {}", result.toString());
58 LOG.warn("Base node: {}", base);
60 final Node aggregatedNode =
62 .addAugmentation(NetconfNode.class,
63 new NetconfNodeBuilder(baseAugmentation)
64 .setClusteredConnectionStatus(
65 new ClusteredConnectionStatusBuilder()
66 .setNodeStatus(statusList)
70 future.set(aggregatedNode);
74 public void onFailure(final Throwable t) {
75 LOG.error("One of the combined create attempts failed {}", t);
76 future.setException(t);
83 public ListenableFuture<Node> combineUpdateAttempts(final List<ListenableFuture<Node>> stateFutures) {
84 final SettableFuture<Node> future = SettableFuture.create();
85 final ListenableFuture<List<Node>> allAsList = Futures.allAsList(stateFutures);
86 Futures.addCallback(allAsList, new FutureCallback<List<Node>>() {
88 public void onSuccess(final List<Node> result) {
90 NetconfNode baseAugmentation = null;
91 final ArrayList<NodeStatus> statusList = new ArrayList<>();
92 for (final Node node : result) {
93 final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
94 if (base == null && netconfNode.getConnectionStatus().equals(ConnectionStatus.Connected)) {
96 baseAugmentation = netconfNode;
98 LOG.debug(netconfNode.toString());
99 statusList.addAll(netconfNode.getClusteredConnectionStatus().getNodeStatus());
103 base = result.get(0);
104 baseAugmentation = result.get(0).getAugmentation(NetconfNode.class);
105 LOG.warn("All results {}", result.toString());
108 final Node aggregatedNode =
109 new NodeBuilder(base)
110 .addAugmentation(NetconfNode.class,
111 new NetconfNodeBuilder(baseAugmentation)
112 .setClusteredConnectionStatus(
113 new ClusteredConnectionStatusBuilder()
114 .setNodeStatus(statusList)
118 future.set(aggregatedNode);
122 public void onFailure(final Throwable t) {
123 LOG.error("One of the combined update attempts failed {}", t);
124 future.setException(t);
131 public ListenableFuture<Void> combineDeleteAttempts(final List<ListenableFuture<Void>> stateFutures) {
132 final SettableFuture<Void> future = SettableFuture.create();
133 final ListenableFuture<List<Void>> allAsList = Futures.allAsList(stateFutures);
134 Futures.addCallback(allAsList, new FutureCallback<List<Void>>() {
136 public void onSuccess(final List<Void> result) {
141 public void onFailure(final Throwable t) {
142 LOG.error("One of the combined delete attempts failed {}", t);
143 future.setException(t);