*/
package org.opendaylight.netvirt.elan.l2gw.ha;
-import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
-import com.google.common.base.Optional;
import com.google.common.base.Strings;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.genius.infra.Datastore;
-import org.opendaylight.genius.infra.Datastore.Configuration;
-import org.opendaylight.genius.infra.Datastore.Operational;
-import org.opendaylight.genius.infra.TypedReadWriteTransaction;
-import org.opendaylight.genius.infra.TypedWriteTransaction;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.util.Datastore;
+import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
+import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
import org.opendaylight.netvirt.elan.l2gw.ha.commands.SwitchesCmd;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ManagersKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.managers.ManagerOtherConfigs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.managers.ManagerOtherConfigsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.managers.ManagerOtherConfigsKey;
public static final String MANAGER_KEY = "managerKey";
public static final String L2GW_JOB_KEY = ":l2gw";
- private HwvtepHAUtil() { }
+ private HwvtepHAUtil() {
+
+ }
public static HwvtepPhysicalLocatorRef buildLocatorRef(InstanceIdentifier<Node> nodeIid, String tepIp) {
InstanceIdentifier<TerminationPoint> tepId = buildTpId(nodeIid, tepIp);
return tpId.firstKeyOf(TerminationPoint.class).getTpId().getValue().substring("vxlan_over_ipv4:".length());
}
- public static String getLogicalSwitchSwitchName(HwvtepLogicalSwitchRef logicalSwitchRef) {
- InstanceIdentifier<LogicalSwitches> id = (InstanceIdentifier<LogicalSwitches>) logicalSwitchRef.getValue();
- return id.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
- }
-
- public static String getNodeIdFromLocatorRef(HwvtepPhysicalLocatorRef locatorRef) {
- InstanceIdentifier<TerminationPoint> tpId = (InstanceIdentifier<TerminationPoint>) locatorRef.getValue();
- return tpId.firstKeyOf(Node.class).getNodeId().getValue();
- }
-
- public static String getNodeIdFromLogicalSwitches(HwvtepLogicalSwitchRef logicalSwitchRef) {
- InstanceIdentifier<LogicalSwitches> id = (InstanceIdentifier<LogicalSwitches>) logicalSwitchRef.getValue();
- return id.firstKeyOf(Node.class).getNodeId().getValue();
- }
-
public static InstanceIdentifier<Node> createInstanceIdentifierFromHAId(String haUUidVal) {
String nodeString = HWVTEP_URI_PREFIX + "://"
+ UUID + "/" + java.util.UUID.nameUUIDFromBytes(haUUidVal.getBytes(StandardCharsets.UTF_8)).toString();
@Nullable
public static Node getUpdated(DataObjectModification<Node> mod) {
- Node node = null;
switch (mod.getModificationType()) {
case SUBTREE_MODIFIED:
- node = mod.getDataAfter();
- break;
case WRITE:
- if (mod.getDataAfter() != null) {
- node = mod.getDataAfter();
- }
- break;
+ return mod.getDataAfter();
default:
- break;
+ return null;
}
- return node;
}
@Nullable
}
@Nullable
- public static String getPsName(Node psNode) {
- String psNodeId = psNode.getNodeId().getValue();
+ public static String getPsName(InstanceIdentifier<Node> psNodeIid) {
+ String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
if (psNodeId.contains(PHYSICALSWITCH)) {
- return psNodeId.substring(psNodeId.indexOf(PHYSICALSWITCH) + PHYSICALSWITCH.length());
+ return psNodeId.substring(psNodeId.indexOf(PHYSICALSWITCH) + PHYSICALSWITCH.length());
}
return null;
}
@Nullable
- public static String getPsName(InstanceIdentifier<Node> psNodeIid) {
- String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
+ public static String getPsName(String psNodeId) {
if (psNodeId.contains(PHYSICALSWITCH)) {
- return psNodeId.substring(psNodeId.indexOf(PHYSICALSWITCH) + PHYSICALSWITCH.length());
+ return psNodeId.substring(psNodeId.indexOf(PHYSICALSWITCH) + PHYSICALSWITCH.length());
}
return null;
}
}
HwvtepGlobalAugmentation globalAugmentation = node.augmentation(HwvtepGlobalAugmentation.class);
if (globalAugmentation != null) {
- List<Managers> managers = globalAugmentation.getManagers();
+ List<Managers> managers = new ArrayList<Managers>(globalAugmentation.nonnullManagers().values());
if (managers != null && !managers.isEmpty() && managers.get(0).getManagerOtherConfigs() != null) {
- for (ManagerOtherConfigs configs : managers.get(0).getManagerOtherConfigs()) {
+ for (ManagerOtherConfigs configs : managers.get(0).nonnullManagerOtherConfigs().values()) {
if (HA_ID.equals(configs.getOtherConfigKey())) {
return configs.getOtherConfigValue();
}
haGlobalConfigNodeOptional.get().augmentation(HwvtepGlobalAugmentation.class);
if (augmentation != null && augmentation.getManagers() != null
&& augmentation.getManagers().size() > 0) {
- Managers managers = augmentation.getManagers().get(0);
+ Managers managers = new ArrayList<Managers>(augmentation.nonnullManagers().values()).get(0);
if (null == managers.getManagerOtherConfigs()) {
return childNodeIds;
}
- for (ManagerOtherConfigs otherConfigs : managers.getManagerOtherConfigs()) {
+ for (ManagerOtherConfigs otherConfigs : managers.nonnullManagerOtherConfigs().values()) {
if (HA_CHILDREN.equals(otherConfigs.getOtherConfigKey())) {
String nodeIdsVal = otherConfigs.getOtherConfigValue();
if (nodeIdsVal != null) {
if (!switchesAlreadyPresent) {
HwvtepGlobalAugmentation augmentation = childNode.augmentation(HwvtepGlobalAugmentation.class);
if (augmentation != null && augmentation.getSwitches() != null) {
- List<Switches> src = augmentation.getSwitches();
+ List<Switches> src = new ArrayList<Switches>(augmentation.nonnullSwitches().values());
if (src != null && src.size() > 0) {
psList.add(new SwitchesCmd().transform(haNodePath, src.get(0)));
}
nodeBuilder.setNodeId(haNodePath.firstKeyOf(Node.class).getNodeId());
nodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, hwvtepGlobalBuilder.build());
Node configHANode = nodeBuilder.build();
- tx.merge(haNodePath, configHANode, CREATE_MISSING_PARENTS);
+ tx.mergeParentStructureMerge(haNodePath, configHANode);
}
public static <D extends Datastore> void deleteNodeIfPresent(TypedReadWriteTransaction<D> tx,
return;
}
HashMap<InstanceIdentifier<Node>,Boolean> deleted = new HashMap<>();
- List<Switches> switches = globalAugmentation.getSwitches();
+ Map<SwitchesKey, Switches> switches = globalAugmentation.nonnullSwitches();
if (switches != null) {
- for (Switches switche : switches) {
+ for (Switches switche : switches.values()) {
InstanceIdentifier<Node> psId = (InstanceIdentifier<Node>)switche.getSwitchRef().getValue();
deleteNodeIfPresent(tx, psId);
deleted.put(psId, Boolean.TRUE);
if (topologyOptional.isPresent()) {
Topology topology = topologyOptional.get();
if (topology.getNode() != null) {
- for (Node psNode : topology.getNode()) {
+ for (Node psNode : topology.nonnullNode().values()) {
PhysicalSwitchAugmentation ps = psNode.augmentation(PhysicalSwitchAugmentation.class);
if (ps != null) {
InstanceIdentifier<Node> iid = (InstanceIdentifier<Node>)ps.getManagedBy().getValue();
}
}
- /**
- * Delete switches from Node in Operational Data Tree .
- *
- * @param haPath HA node path from whih switches will be deleted
- * @param tx Transaction object
- */
- public static void deleteSwitchesManagedByNode(InstanceIdentifier<Node> haPath,
- TypedReadWriteTransaction<Operational> tx) throws ExecutionException, InterruptedException {
-
- Optional<Node> nodeOptional = tx.read(haPath).get();
- if (!nodeOptional.isPresent()) {
- return;
- }
- Node node = nodeOptional.get();
- HwvtepGlobalAugmentation globalAugmentation = node.augmentation(HwvtepGlobalAugmentation.class);
- if (globalAugmentation == null) {
- return;
- }
- List<Switches> switches = globalAugmentation.getSwitches();
- if (switches != null) {
- for (Switches switche : switches) {
- InstanceIdentifier<Node> id = (InstanceIdentifier<Node>)switche.getSwitchRef().getValue();
- deleteNodeIfPresent(tx, id);
- }
- }
- }
-
- /**
- * Returns true/false if all the childrens are deleted from Operational Data store.
- *
- * @param children IID for the child node to read from OP data tree
- * @param tx Transaction
- * @return true/false boolean
- * @throws ReadFailedException Exception thrown if read fails
- */
- public static boolean areAllChildDeleted(Set<InstanceIdentifier<Node>> children,
- ReadWriteTransaction tx) throws ReadFailedException {
- for (InstanceIdentifier<Node> childId : children) {
- if (tx.read(OPERATIONAL, childId).checkedGet().isPresent()) {
- return false;
- }
- }
- return true;
- }
-
public static void addToCacheIfHAChildNode(InstanceIdentifier<Node> childPath, Node childNode,
HwvtepNodeHACache hwvtepNodeHACache) {
String haId = HwvtepHAUtil.getHAIdFromManagerOtherConfig(childNode);