import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepTableReader;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
+import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
T oldData = null;
Type type = getClass().getGenericSuperclass();
Type classType = ((ParameterizedType) type).getActualTypeArguments()[0];
- if (getDeviceInfo().getConfigData((Class<? extends Identifiable>) classType, key) != null) {
- oldData = (T) getDeviceInfo().getConfigData((Class<? extends Identifiable>) classType, key);
+ if (getDeviceInfo().getConfigData((Class<? extends Identifiable>) classType, key) != null
+ && getDeviceInfo().getConfigData((Class<? extends Identifiable>) classType, key).getData() != null) {
+ oldData = (T) getDeviceInfo().getConfigData((Class<? extends Identifiable>) classType, key).getData();
}
updates.putIfAbsent(getDeviceTransaction(), new ArrayList<MdsalUpdate<T>>());
updates.get(getDeviceTransaction()).add(new MdsalUpdate<>(key, data, oldData));
void updateControllerTxHistory(TransactionType transactionType, Object element) {
getOperationalState().getDeviceInfo().addToControllerTx(transactionType, element);
}
+
+ public <T> HwvtepDeviceInfo.DeviceData fetchDeviceData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
+ HwvtepDeviceInfo.DeviceData deviceData = getDeviceOpData(cls, key);
+ if (deviceData == null) {
+ LOG.debug("Could not find data for key {}", getNodeKeyStr(key));
+ java.util.Optional<TypedBaseTable> optional = getTableReader().getHwvtepTableEntryUUID(cls, key, null);
+ if (optional.isPresent()) {
+ LOG.debug("Found the data for key from device {} ", getNodeKeyStr(key));
+ getDeviceInfo().updateDeviceOperData(cls, key, optional.get().getUuid(), (T)optional.get());
+ return getDeviceOpData(cls, key);
+ } else {
+ LOG.info("Could not Find the data for key from device {} ", getNodeKeyStr(key));
+ }
+ }
+ return deviceData;
+ }
+
+ protected String getNodeKeyStr(InstanceIdentifier iid) {
+ try {
+ return getClassType().getTypeName() + "." + ((Node) iid.firstKeyOf(Node.class)).getNodeId().getValue() + "."
+ + getKeyStr(iid);
+ } catch (ClassCastException exp) {
+ LOG.error("Error in getting the Node id ", exp);
+ }
+ return iid.toString();
+ }
+
+ protected String getKeyStr(InstanceIdentifier iid) {
+ return iid.toString();
+ }
+
+ public HwvtepDeviceInfo.DeviceData getDeviceOpData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
+ return getOperationalState().getDeviceInfo().getDeviceOperData(cls, key);
+ }
+
+ public HwvtepTableReader getTableReader() {
+ return getOperationalState().getConnectionInstance().getHwvtepTableReader();
+ }
}
@Override
public void execute(final TransactionBuilder transaction) {
- Map<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> createds =
- extractCreated(getChanges(),HwvtepPhysicalPortAugmentation.class);
+ Map<InstanceIdentifier<Node>, List<TerminationPoint>> createds =
+ extractCreated(getChanges(),TerminationPoint.class);
if (!createds.isEmpty()) {
- for (Entry<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> created:
+ for (Entry<InstanceIdentifier<Node>, List<TerminationPoint>> created:
createds.entrySet()) {
updatePhysicalPort(transaction, created.getKey(), created.getValue());
}
}
- Map<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> updateds =
- extractUpdatedPorts(getChanges(), HwvtepPhysicalPortAugmentation.class);
+ Map<InstanceIdentifier<Node>, List<TerminationPoint>> updateds =
+ extractUpdatedPorts(getChanges(), TerminationPoint.class);
if (!updateds.isEmpty()) {
- for (Entry<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> updated:
+ for (Entry<InstanceIdentifier<Node>, List<TerminationPoint>> updated:
updateds.entrySet()) {
updatePhysicalPort(transaction, updated.getKey(), updated.getValue());
}
public void updatePhysicalPort(final TransactionBuilder transaction,
final InstanceIdentifier<Node> psNodeiid,
- final List<HwvtepPhysicalPortAugmentation> listPort) {
+ final List<TerminationPoint> listPort) {
//Get physical switch which the port belong to: in operation DS or new created
- for (HwvtepPhysicalPortAugmentation port : listPort) {
+ for (TerminationPoint tp : listPort) {
+ HwvtepPhysicalPortAugmentation port = tp.augmentation(HwvtepPhysicalPortAugmentation.class);
LOG.debug("Creating a physical port named: {}", port.getHwvtepNodeName().getValue());
- HwvtepDeviceInfo.DeviceData deviceOperdata = getDeviceInfo().getDeviceOperData(TerminationPoint.class,
- getTpIid(psNodeiid, port.getHwvtepNodeName().getValue()));
- if (deviceOperdata == null) {
+ InstanceIdentifier<TerminationPoint> key = getTpIid(psNodeiid, port.getHwvtepNodeName().getValue());
+
+ getOperationalState().getDeviceInfo().updateConfigData(TerminationPoint.class, key, tp);
+ HwvtepDeviceInfo.DeviceData deviceOperdata = getDeviceInfo().getDeviceOperData(TerminationPoint.class, key);
+ if (deviceOperdata == null || deviceOperdata.getData() == null) {
+ LOG.error("Updated the device oper cache for port from actual device {}", key);
+ deviceOperdata = super.fetchDeviceData(TerminationPoint.class, key);
+ }
+ if (deviceOperdata == null || deviceOperdata.getData() == null) {
//create a physical port always happens from device
LOG.error("Physical port {} not present in oper datastore", port.getHwvtepNodeName().getValue());
} else {
PhysicalPort physicalPort = transaction.getTypedRowWrapper(PhysicalPort.class);
physicalPort.setName(port.getHwvtepNodeName().getValue());
- setVlanBindings(psNodeiid, physicalPort, port, transaction);
+ setVlanBindings(psNodeiid, physicalPort, tp, transaction);
setDescription(physicalPort, port);
String existingPhysicalPortName = port.getHwvtepNodeName().getValue();
PhysicalPort extraPhyscialPort = transaction.getTypedRowWrapper(PhysicalPort.class);
private void setVlanBindings(final InstanceIdentifier<Node> psNodeiid,
final PhysicalPort physicalPort,
- final HwvtepPhysicalPortAugmentation inputPhysicalPort,
+ final TerminationPoint tp,
final TransactionBuilder transaction) {
+ HwvtepPhysicalPortAugmentation inputPhysicalPort = tp.augmentation(HwvtepPhysicalPortAugmentation.class);
if (inputPhysicalPort.getVlanBindings() != null) {
//get UUID by LogicalSwitchRef
Map<Long, UUID> bindingMap = new HashMap<>();
getOperationalState(), vlanBinding);
if (!HwvtepSouthboundUtil.isEmptyMap(configDependencies)) {
- createConfigWaitJob(psNodeiid, inputPhysicalPort,
+ createConfigWaitJob(psNodeiid, tp,
vlanBinding, configDependencies, vlanIid);
continue;
}
if (!HwvtepSouthboundUtil.isEmptyMap(inTransitDependencies)) {
- createOperWaitingJob(psNodeiid, inputPhysicalPort,
+ createOperWaitingJob(psNodeiid, tp,
vlanBinding, inTransitDependencies, vlanIid);
continue;
}
}
private void createOperWaitingJob(final InstanceIdentifier<Node> psNodeiid,
- final HwvtepPhysicalPortAugmentation inputPhysicalPort,
+ final TerminationPoint inputPhysicalPort,
final VlanBindings vlanBinding,
final Map inTransitDependencies,
final InstanceIdentifier<VlanBindings> vlanIid) {
}
private void createConfigWaitJob(final InstanceIdentifier<Node> psNodeiid,
- final HwvtepPhysicalPortAugmentation inputPhysicalPort,
+ final TerminationPoint inputPhysicalPort,
final VlanBindings vlanBinding,
final Map configDependencies,
final InstanceIdentifier<VlanBindings> vlanIid) {
}
}
- private static Map<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> extractCreated(
- final Collection<DataTreeModification<Node>> changes, final Class<HwvtepPhysicalPortAugmentation> class1) {
- Map<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> result = new HashMap<>();
+ private static Map<InstanceIdentifier<Node>, List<TerminationPoint>> extractCreated(
+ final Collection<DataTreeModification<Node>> changes, final Class<TerminationPoint> class1) {
+ Map<InstanceIdentifier<Node>, List<TerminationPoint>> result = new HashMap<>();
if (changes != null && !changes.isEmpty()) {
for (DataTreeModification<Node> change : changes) {
final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
final DataObjectModification<Node> mod = change.getRootNode();
Node created = TransactUtils.getCreated(mod);
if (created != null) {
- List<HwvtepPhysicalPortAugmentation> portListUpdated = new ArrayList<>();
+ List<TerminationPoint> portListUpdated = new ArrayList<>();
if (created.getTerminationPoint() != null) {
for (TerminationPoint tp : created.getTerminationPoint()) {
HwvtepPhysicalPortAugmentation hppAugmentation =
tp.augmentation(HwvtepPhysicalPortAugmentation.class);
if (hppAugmentation != null) {
- portListUpdated.add(hppAugmentation);
+ portListUpdated.add(tp);
}
}
}
return result;
}
- private static Map<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> extractUpdatedPorts(
- final Collection<DataTreeModification<Node>> changes, final Class<HwvtepPhysicalPortAugmentation> class1) {
- Map<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> result = new HashMap<>();
+ private static Map<InstanceIdentifier<Node>, List<TerminationPoint>> extractUpdatedPorts(
+ final Collection<DataTreeModification<Node>> changes, final Class<TerminationPoint> class1) {
+ Map<InstanceIdentifier<Node>, List<TerminationPoint>> result = new HashMap<>();
if (changes != null && !changes.isEmpty()) {
for (DataTreeModification<Node> change : changes) {
final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
Node updated = TransactUtils.getUpdated(mod);
Node before = mod.getDataBefore();
if (updated != null && before != null) {
- List<HwvtepPhysicalPortAugmentation> portListUpdated = new ArrayList<>();
- List<HwvtepPhysicalPortAugmentation> portListBefore = new ArrayList<>();
+ List<TerminationPoint> portListUpdated = new ArrayList<>();
+ List<TerminationPoint> portListBefore = new ArrayList<>();
if (updated.getTerminationPoint() != null) {
for (TerminationPoint tp : updated.getTerminationPoint()) {
HwvtepPhysicalPortAugmentation hppAugmentation =
tp.augmentation(HwvtepPhysicalPortAugmentation.class);
if (hppAugmentation != null) {
- portListUpdated.add(hppAugmentation);
+ portListUpdated.add(tp);
}
}
}
HwvtepPhysicalPortAugmentation hppAugmentation =
tp.augmentation(HwvtepPhysicalPortAugmentation.class);
if (hppAugmentation != null) {
- portListBefore.add(hppAugmentation);
+ portListBefore.add(tp);
}
}
}
}
return result;
}
+
+ protected String getKeyStr(InstanceIdentifier iid) {
+ try {
+ return ((TerminationPoint)iid.firstKeyOf(TerminationPoint.class)).getTpId().getValue();
+ } catch (ClassCastException exp) {
+ LOG.error("Error in getting the TerminationPoint id ", exp);
+ }
+ return super.getKeyStr(iid);
+ }
+
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.MoreExecutors;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
import org.opendaylight.ovsdb.hwvtepsouthbound.events.PortEvent;
if (getDeviceInfo().getDeviceOperData(TerminationPoint.class, tpPath) != null) {
//case of port update not new port add
return;
+
}
//case of individual port add , reconcile to this port
getDeviceInfo().updateDeviceOperData(TerminationPoint.class, tpPath, portUpdate.getUuid(), portUpdate);
- Futures.addCallback(mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, tpPath),
- new FutureCallback<Optional<TerminationPoint>>() {
- @Override
- public void onSuccess(final Optional<TerminationPoint> optionalConfigTp) {
- if (!optionalConfigTp.isPresent() || optionalConfigTp.get().augmentation(
- HwvtepPhysicalPortAugmentation.class) == null) {
- //TODO port came with some vlan bindings clean them up use PortRemovedCommand
- return;
- }
- addToDeviceUpdate(TransactionType.ADD,
- new ReconcilePortEvent(portUpdate, tpPath.firstKeyOf(Node.class).getNodeId()));
- getDeviceInfo().updateDeviceOperData(TerminationPoint.class, tpPath,
- portUpdate.getUuid(), portUpdate);
- TerminationPoint configTp = optionalConfigTp.get();
- getDeviceInfo().scheduleTransaction((transactionBuilder) -> {
- InstanceIdentifier psIid = tpPath.firstIdentifierOf(Node.class);
- HwvtepOperationalState operState = new HwvtepOperationalState(getOvsdbConnectionInstance());
- PhysicalPortUpdateCommand portUpdateCommand = new PhysicalPortUpdateCommand(
- operState, Collections.EMPTY_LIST);
- portUpdateCommand.updatePhysicalPort(transactionBuilder, psIid,
- Lists.newArrayList(configTp.augmentation(HwvtepPhysicalPortAugmentation.class)));
- });
- }
+ HwvtepDeviceInfo.DeviceData data = getDeviceInfo().getConfigData(TerminationPoint.class, tpPath);
+ if (data == null || data.getData() == null) {
+ LOG.error("No config data present ");
+ } else {
+ addToDeviceUpdate(TransactionType.ADD,
+ new ReconcilePortEvent(portUpdate, tpPath.firstKeyOf(Node.class).getNodeId()));
+ LOG.info("addToDeviceUpdate {}", portUpdate);
+ getDeviceInfo().updateDeviceOperData(TerminationPoint.class, tpPath,
+ portUpdate.getUuid(), portUpdate);
+ getDeviceInfo().scheduleTransaction((transactionBuilder) -> {
+ InstanceIdentifier psIid = tpPath.firstIdentifierOf(Node.class);
+ HwvtepOperationalState operState = new HwvtepOperationalState(getOvsdbConnectionInstance());
+ PhysicalPortUpdateCommand portUpdateCommand = new PhysicalPortUpdateCommand(
+ operState, Collections.EMPTY_LIST);
+ TerminationPoint cfgPoint = (TerminationPoint) data.getData();
+ portUpdateCommand.updatePhysicalPort(transactionBuilder, psIid,
+ Lists.newArrayList(cfgPoint));
- @Override
- public void onFailure(final Throwable throwable) {
- }
- }, MoreExecutors.directExecutor());
+ });
+ }
}
private static <T extends DataObject> void deleteEntries(final ReadWriteTransaction transaction,