2 * Copyright (c) 2016 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
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
11 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
12 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
13 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.Identifiable;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import java.util.List;
21 public abstract class DependentJob<T extends Identifiable> {
23 private final long expiryTime;
24 private final InstanceIdentifier key;
26 private final Map<Class<? extends DataObject>, List<InstanceIdentifier>> dependencies;
28 DependentJob(InstanceIdentifier key,
29 T data, Map<Class<? extends DataObject>, List<InstanceIdentifier>> dependencies) {
30 this.expiryTime = System.currentTimeMillis() + HwvtepSouthboundConstants.WAITING_JOB_EXPIRY_TIME_MILLIS;
33 this.dependencies = dependencies;
37 * This call back method gets called when all its dependencies are resolved
38 * @param operationalState new current operational state
39 * @param transactionBuilder transaction builder to create device transaction
41 protected abstract void onDependencyResolved(HwvtepOperationalState operationalState,
42 TransactionBuilder transactionBuilder);
45 * This method is to check if all the given dependency of this job or not
46 * @param deviceInfo The device info of tis job
47 * @param cls dependency type to be checked for
48 * @param iid instance identifier to be checked for
49 * @return true if the dependency is met
51 protected abstract boolean isDependencyMet(HwvtepDeviceInfo deviceInfo, Class<? extends DataObject> cls,
52 InstanceIdentifier iid);
54 boolean isExpired(long currentTime) {
55 return currentTime > expiryTime;
59 * This method checks if all the dependencies of this job or met or not
60 * @param deviceInfo The device info of this job
61 * @return true if all the dependencies are met
63 boolean areDependenciesMet(HwvtepDeviceInfo deviceInfo) {
64 for (Class<? extends DataObject> cls : dependencies.keySet()) {
65 for (InstanceIdentifier iid : dependencies.get(cls)) {
66 if (!isDependencyMet(deviceInfo, cls, iid)) {
74 public InstanceIdentifier getKey() {
82 public abstract static class ConfigWaitingJob<T extends Identifiable> extends DependentJob {
84 public ConfigWaitingJob(InstanceIdentifier key, T data, Map dependencies) {
85 super(key, data, dependencies);
89 protected boolean isDependencyMet(HwvtepDeviceInfo deviceInfo, Class cls, InstanceIdentifier iid) {
90 return deviceInfo.isConfigDataAvailable(cls, iid);
94 public abstract static class OpWaitingJob<T extends Identifiable> extends DependentJob {
96 public OpWaitingJob(InstanceIdentifier key, T data, Map dependencies) {
97 super(key, data, dependencies);
101 protected boolean isDependencyMet(HwvtepDeviceInfo deviceInfo, Class cls, InstanceIdentifier iid) {
102 HwvtepDeviceInfo.DeviceData deviceData = deviceInfo.getDeviceOpData(cls, iid);
103 return deviceData == null || deviceData.getStatus() != HwvtepDeviceInfo.DeviceDataStatus.IN_TRANSIT;