2 * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. 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.ovsdb.hwvtepsouthbound.reconciliation.configuration;
10 import java.util.ArrayList;
11 import java.util.Collection;
13 import java.util.Optional;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.api.DataTreeModification;
16 import org.opendaylight.mdsal.binding.api.ReadTransaction;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
19 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionManager;
20 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
21 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
22 import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.ReconciliationManager;
23 import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.ReconciliationTask;
24 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
25 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.TransactCommandAggregator;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 public class HwvtepReconciliationTask extends ReconciliationTask {
33 private final HwvtepConnectionInstance connectionInstance;
34 private final DataBroker db;
35 private final Node psNode;
37 public HwvtepReconciliationTask(ReconciliationManager reconciliationManager,
38 HwvtepConnectionManager connectionManager,
39 InstanceIdentifier<?> nodeId,
41 HwvtepConnectionInstance connectionInstance,
43 super(reconciliationManager, connectionManager, nodeId, null);
46 this.connectionInstance = connectionInstance;
49 private void transactChangesToDevice(final Collection<DataTreeModification<Node>> changes,
50 final Node globalOperNode,
52 HwvtepOperationalState hwvtepOperationalState = new HwvtepOperationalState(db, connectionInstance, changes,
53 globalOperNode, node);
54 hwvtepOperationalState.setInReconciliation(true);
55 boolean reconcile = true;
56 connectionInstance.transact(new TransactCommandAggregator(hwvtepOperationalState,changes), reconcile);
60 public boolean reconcileConfiguration(HwvtepConnectionManager connectionManagerOfDevice) {
61 InstanceIdentifier<Node> psNodeIid = HwvtepSouthboundMapper.createInstanceIdentifier(psNode.getNodeId());
62 InstanceIdentifier<Node> nodeId = (InstanceIdentifier<Node>)nodeIid;
64 ReadTransaction tx = reconciliationManager.getDb().newReadOnlyTransaction();
65 Node globalConfigNode = readNode(tx, LogicalDatastoreType.CONFIGURATION, nodeId);
66 Node globalOpNode = readNode(tx, LogicalDatastoreType.OPERATIONAL, nodeId);
67 Node psConfigNode = readNode(tx, LogicalDatastoreType.CONFIGURATION, psNodeIid);
69 DataTreeModification<Node> change = null;
70 Collection<DataTreeModification<Node>> changes = new ArrayList<>();
71 change = GlobalConfigOperationalChangeGetter.getModification(nodeId, globalConfigNode, globalOpNode);
74 change = SwitchConfigOperationalChangeGetter.getModification(psNodeIid, psConfigNode, psNode);
77 if (globalConfigNode != null) {
78 HwvtepGlobalAugmentation augmentation = globalConfigNode.augmentation(HwvtepGlobalAugmentation.class);
79 if (augmentation != null) {
80 Map<LogicalSwitchesKey, LogicalSwitches> switches = augmentation.getLogicalSwitches();
81 if (switches != null) {
82 for (LogicalSwitches logicalSwitches : switches.values()) {
83 connectionInstance.getDeviceInfo().updateConfigData(LogicalSwitches.class,
84 nodeId.augmentation(HwvtepGlobalAugmentation.class).child(LogicalSwitches.class,
85 logicalSwitches.key()), logicalSwitches);
90 transactChangesToDevice(changes, globalOpNode, psNode);
95 public void doRetry(boolean wasPreviousAttemptSuccessful) {
99 public void checkReadinessAndProcess() {
103 public long retryDelayInMills() {
107 private static Node readNode(ReadTransaction transaction,
108 LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<Node> iid) {
109 Optional<Node> optional = HwvtepSouthboundUtil.readNode(transaction, logicalDatastoreType, iid);
110 if (optional.isPresent()) {
111 return optional.get();