2 * Copyright (c) 2016 Brocade Communications 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.ovsdb.hwvtepsouthbound.reconciliation;
10 import com.google.common.base.Preconditions;
12 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionManager;
13 import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.connection.ConnectionReconciliationTask;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Copied from org.opendaylight.ovsdb.southbound.reconciliation.ReconciliationTask
22 * Abstract implementation of a reconciliation task. Each new type of
23 * resource configuration reconciliation task should extend this class
24 * and implement the abstract methods.
25 * Created by Anil Vishnoi (avishnoi@Brocade.com) on 3/9/16.
27 public abstract class ReconciliationTask implements Runnable {
29 private static final Logger LOG = LoggerFactory.getLogger(ReconciliationTask.class);
31 protected final ReconciliationManager reconciliationManager;
32 protected final HwvtepConnectionManager connectionManager;
33 protected final InstanceIdentifier<?> nodeIid;
34 protected final DataObject configData;
36 protected ReconciliationTask(ReconciliationManager reconciliationManager, HwvtepConnectionManager connectionManager,
37 InstanceIdentifier<?> nodeIid,
38 DataObject configData) {
39 Preconditions.checkNotNull(reconciliationManager, "Reconciliation manager must not be null");
40 Preconditions.checkNotNull(connectionManager, "Connection manager must not be null");
41 Preconditions.checkNotNull(nodeIid, "Node Iid must not be null");
42 this.reconciliationManager = reconciliationManager;
43 this.connectionManager = connectionManager;
44 this.nodeIid = nodeIid;
45 this.configData = configData;
49 * Method contains task reconciliation logic. Please refer to
50 * {@link ConnectionReconciliationTask#reconcileConfiguration(HwvtepConnectionManager)}
52 * @param connectionManager Connection manager to get connection instance of the device
53 * @return True if reconciliation was successful, else false
55 public abstract boolean reconcileConfiguration(HwvtepConnectionManager connectionManager);
58 * Extended task should implement the logic that decides whether retry for the task
59 * is required or not. If retry is required but it does not requires any delay, submit
60 * the task immediately using {@link ReconciliationManager#enqueue(ReconciliationTask)}.
61 * If retry requires delay, use {@link ReconciliationManager#enqueueForRetry(ReconciliationTask)}
62 * and specify the delay using {@link #retryDelayInMills()}.
63 * If data store operation is required to decide if the task need retry, please implement
64 * it as an async operation and submit the task on the callback of the future.
66 * Note:Please do not write blocking data store operations
67 * {@link ConnectionReconciliationTask#doRetry(boolean)}
69 * @param wasPreviousAttemptSuccessful Status of the previous attempt
71 public abstract void doRetry(boolean wasPreviousAttemptSuccessful);
74 * Extended task should implement the logic that check the readiness of the task
75 * for execution. If task is ready for the execution, submit it for immediate
76 * execution using {@link ReconciliationManager#enqueue(ReconciliationTask)}.
77 * If task is not ready for execution yet, enqueue it again for delayed execution
78 * using {@link ReconciliationManager#enqueueForRetry(ReconciliationTask)}.
79 * To check the readiness of the task, if the data store operation is required, please
80 * implement it as an async operation and submit the task on the callback of the future.
82 * Note:Please do not write blocking data store operations
83 * {@link ConnectionReconciliationTask#doRetry(boolean)}
86 public abstract void checkReadinessAndProcess();
89 * Method returns the time interval for retrying the failed task.
90 * {@link ReconciliationTask#doRetry(boolean)}
93 public abstract long retryDelayInMills();
97 boolean status = this.reconcileConfiguration(connectionManager);
102 public boolean equals(Object o) {
103 if (this == o) return true;
104 if (o == null || getClass() != o.getClass()) {
108 ReconciliationTask that = (ReconciliationTask) o;
110 return nodeIid.equals(that.nodeIid);
115 public int hashCode() {
116 return getClass().hashCode() + nodeIid.hashCode();
121 public String toString() {
122 return "ReconciliationTask{ type=" + getClass().toString()+
123 ", nodeIid=" + nodeIid +