package org.opendaylight.netvirt.elan.cli.l2gw;
-import com.google.common.base.Optional;
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 org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
}
@Override
+ @Nullable
protected Object doExecute() {
List<Node> nodes = new ArrayList<>();
Set<String> networks = new HashSet<>();
- if (nodeId == null) {
- Optional<Topology> topologyOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
- createHwvtepTopologyInstanceIdentifier());
- if (topologyOptional.isPresent()) {
- nodes = topologyOptional.get().getNode();
- }
- } else {
- Optional<Node> nodeOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
- createInstanceIdentifier(new NodeId(new Uri(nodeId))));
- if (nodeOptional.isPresent()) {
- nodes.add(nodeOptional.get());
+ try {
+ if (nodeId == null) {
+ Optional<Topology> topologyOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, createHwvtepTopologyInstanceIdentifier());
+ if (topologyOptional.isPresent()) {
+ nodes.addAll(topologyOptional.get().nonnullNode());
+ }
+ } else {
+ Optional<Node> nodeOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, createInstanceIdentifier(new NodeId(new Uri(nodeId))));
+ if (nodeOptional.isPresent()) {
+ nodes.add(nodeOptional.get());
+ }
}
- }
- if (elanName == null) {
- //get all elan instance
- //get all device node id
- //print result
- Optional<ElanInstances> elanInstancesOptional = MDSALUtil.read(dataBroker,
- LogicalDatastoreType.CONFIGURATION,
- InstanceIdentifier.builder(ElanInstances.class).build());
- if (elanInstancesOptional.isPresent()) {
- List<ElanInstance> elans = elanInstancesOptional.get().getElanInstance();
- if (elans != null) {
- for (ElanInstance elan : elans) {
- networks.add(elan.getElanInstanceName());
+ if (elanName == null) {
+ //get all elan instance
+ //get all device node id
+ //print result
+ Optional<ElanInstances> elanInstancesOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.builder(ElanInstances.class).build());
+ if (elanInstancesOptional.isPresent()) {
+ List<ElanInstance> elans = elanInstancesOptional.get().getElanInstance();
+ if (elans != null) {
+ for (ElanInstance elan : elans) {
+ networks.add(elan.getElanInstanceName());
+ }
}
}
+ } else {
+ networks.add(elanName);
}
- } else {
- networks.add(elanName);
- }
- for (Node node : nodes) {
- if (node.getNodeId().getValue().contains("physicalswitch")) {
- continue;
- }
- Node hwvtepConfigNode =
- HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION, node.getNodeId());
- Node hwvtepOpPsNode = getPSnode(node, LogicalDatastoreType.OPERATIONAL);
- Node hwvtepConfigPsNode = null;
- if (hwvtepOpPsNode != null) {
- hwvtepConfigPsNode = HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION,
- hwvtepOpPsNode.getNodeId());
- opPSNodes.put(node.getNodeId(), hwvtepOpPsNode);
- }
- opNodes.put(node.getNodeId(), node);
- configNodes.put(node.getNodeId(), hwvtepConfigNode);
+ if (nodes != null) {
+ for (Node node : nodes) {
+ if (node.getNodeId().getValue().contains("physicalswitch")) {
+ continue;
+ }
+ Node hwvtepConfigNode =
+ HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION, node.getNodeId());
+ Node hwvtepOpPsNode = getPSnode(node, LogicalDatastoreType.OPERATIONAL);
+ Node hwvtepConfigPsNode = null;
+ if (hwvtepOpPsNode != null) {
+ hwvtepConfigPsNode = HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ hwvtepOpPsNode.getNodeId());
+ opPSNodes.put(node.getNodeId(), hwvtepOpPsNode);
+ }
+ opNodes.put(node.getNodeId(), node);
+ configNodes.put(node.getNodeId(), hwvtepConfigNode);
- if (hwvtepConfigPsNode != null) {
- configPSNodes.put(node.getNodeId(), hwvtepConfigPsNode);
+ if (hwvtepConfigPsNode != null) {
+ configPSNodes.put(node.getNodeId(), hwvtepConfigPsNode);
+ }
+ }
}
- }
- for (String network : networks) {
- session.getConsole().println("Network info for " + network);
- for (Node node : nodes) {
- if (node.getNodeId().getValue().contains("physicalswitch")) {
- continue;
+ if (!networks.isEmpty()) {
+ for (String network : networks) {
+ session.getConsole().println("Network info for " + network);
+ for (Node node : nodes) {
+ if (node.getNodeId().getValue().contains("physicalswitch")) {
+ continue;
+ }
+ session.getConsole().println("Printing for node " + node.getNodeId().getValue());
+ process(node.getNodeId(), network);
+ }
}
- session.getConsole().println("Printing for node " + node.getNodeId().getValue());
- process(node.getNodeId(), network);
}
+ } catch (ExecutionException | InterruptedException e) {
+ session.getConsole().println("Failed with error " + e.getMessage());
}
return null;
}
if (elanName.equals(lsFromLocalMac)) {
String mac = localMac.getMacEntryKey().getValue();
List<String> locatorsets = new ArrayList<>();
- for (LocatorSet locatorSet : localMac.getLocatorSet()) {
+ for (LocatorSet locatorSet : localMac.nonnullLocatorSet()) {
locatorsets.add(getLocatorValue(locatorSet.getLocatorRef()));
}
session.getConsole().println(mac + GAP + locatorsets.toString());
if (elanName.equals(lsFromremoteMac)) {
String mac = remoteMac.getMacEntryKey().getValue();
List<String> locatorsets = new ArrayList<>();
- for (LocatorSet locatorSet : remoteMac.getLocatorSet()) {
+ for (LocatorSet locatorSet : remoteMac.nonnullLocatorSet()) {
locatorsets.add(getLocatorValue(locatorSet.getLocatorRef()));
}
session.getConsole().println(mac + GAP + locatorsets.toString());
}
+ @Nullable
String getLocatorValue(HwvtepPhysicalLocatorRef locatorRef) {
if (locatorRef == null) {
return null;
.firstKeyOf(TerminationPoint.class).getTpId().getValue();
}
+ @Nullable
String getLogicalSwitchValue(HwvtepLogicalSwitchRef logicalSwitchRef) {
if (logicalSwitchRef == null) {
return null;
.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
}
- Node getPSnode(Node hwvtepNode, LogicalDatastoreType datastoreType) {
- if (hwvtepNode.augmentation(HwvtepGlobalAugmentation.class) != null
- && hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches() != null) {
- for (Switches switches : hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches()) {
- NodeId psNodeId = switches.getSwitchRef().getValue().firstKeyOf(Node.class).getNodeId();
- return HwvtepUtils.getHwVtepNode(dataBroker, datastoreType, psNodeId);
+ @Nullable
+ Node getPSnode(Node hwvtepNode, LogicalDatastoreType datastoreType) throws ExecutionException,
+ InterruptedException {
+ if (hwvtepNode.augmentation(HwvtepGlobalAugmentation.class) != null) {
+ List<Switches> switches = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches();
+ if (switches != null) {
+ return HwvtepUtils.getHwVtepNode(dataBroker, datastoreType,
+ switches.iterator().next().getSwitchRef().getValue().firstKeyOf(Node.class).getNodeId());
}
}
return null;