2 * Copyright (c) 2015 China Telecom Beijing Research Institute 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.ovsdb.hwvtepsouthbound.transact;
11 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
12 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
13 import org.opendaylight.ovsdb.lib.notation.UUID;
14 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
17 import org.opendaylight.yangtools.yang.binding.Identifiable;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import java.util.Collection;
23 public abstract class AbstractTransactCommand<T extends Identifiable> implements TransactCommand<T> {
25 private HwvtepOperationalState operationalState;
26 private Collection<DataTreeModification<Node>> changes;
28 protected AbstractTransactCommand() {
32 public AbstractTransactCommand(HwvtepOperationalState state, Collection<DataTreeModification<Node>> changes) {
33 this.operationalState = state;
34 this.changes = changes;
37 public HwvtepOperationalState getOperationalState() {
38 return operationalState;
41 public Collection<DataTreeModification<Node>> getChanges() {
45 void updateCurrentTxData(Class<? extends Identifiable> cls, InstanceIdentifier key, UUID uuid, Object data) {
46 operationalState.updateCurrentTxData(cls, key, uuid);
47 operationalState.getDeviceInfo().markKeyAsInTransit(cls, key);
48 operationalState.getDeviceInfo().updateConfigData(cls, key, data);
51 void processDependencies(UnMetDependencyGetter<T> unMetDependencyGetter,
52 TransactionBuilder transaction,
53 final InstanceIdentifier<Node> nodeIid,
54 final InstanceIdentifier key,
57 HwvtepDeviceInfo deviceInfo = operationalState.getDeviceInfo();
58 Map inTransitDependencies = unMetDependencyGetter.getInTransitDependencies(operationalState, data);
59 Map confingDependencies = unMetDependencyGetter.getUnMetConfigDependencies(operationalState, data);
60 //we can skip the config termination point dependency as we can create them in device as part of this tx
61 confingDependencies.remove(TerminationPoint.class);
63 if (confingDependencies.isEmpty() && inTransitDependencies.isEmpty()) {
64 doDeviceTransaction(transaction, nodeIid, data);
66 if (!confingDependencies.isEmpty()) {
67 DependentJob<T> configWaitingJob = new DependentJob.ConfigWaitingJob(
68 key, data, confingDependencies) {
71 public void onDependencyResolved(HwvtepOperationalState operationalState,
72 TransactionBuilder transactionBuilder) {
73 AbstractTransactCommand.this.operationalState = operationalState;
74 onConfigUpdate(transactionBuilder, nodeIid, data);
77 deviceInfo.addJobToQueue(configWaitingJob);
79 if (inTransitDependencies.size() > 0) {
80 DependentJob<T> opWaitingJob = new DependentJob.OpWaitingJob(
81 key, data, inTransitDependencies) {
84 public void onDependencyResolved(HwvtepOperationalState operationalState,
85 TransactionBuilder transactionBuilder) {
86 AbstractTransactCommand.this.operationalState = operationalState;
87 onConfigUpdate(transactionBuilder, nodeIid, data);
90 deviceInfo.addJobToQueue(opWaitingJob);
94 public void doDeviceTransaction(TransactionBuilder transaction, InstanceIdentifier<Node> nodeIid, T data) {
95 //tobe removed as part of refactoring patch
98 public void onConfigUpdate(TransactionBuilder transaction, InstanceIdentifier<Node> nodeIid, T data) {
99 //tobe removed as part of refactoring patch