Netconf Karaf CLI code clean-up 67/39667/1
authorRashmi Pujar <rpujar@inocybe.com>
Tue, 31 May 2016 19:05:49 +0000 (15:05 -0400)
committerRashmi Pujar <rpujar@inocybe.com>
Tue, 31 May 2016 19:05:49 +0000 (15:05 -0400)
- Fix show-device command argument checking
- Remove default values for strings to make Help look cleaner
- Check for null node to avoid NPE

Change-Id: I5376e76e252cbe3743410f84c8b20722a483e20d
Signed-off-by: Rashmi Pujar <rpujar@inocybe.com>
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfConnectDeviceCommand.java
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfDisconnectDeviceCommand.java
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfShowDeviceCommand.java
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfUpdateDeviceCommand.java
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java

index 7139e1ea313b1055018a732457a171a206871c6b..55175a93382c36b587c53ccd26c8a735602242c0 100644 (file)
@@ -35,7 +35,7 @@ public class NetconfConnectDeviceCommand extends AbstractAction {
             description = "IP address of the netconf device",
             required = true,
             multiValued = false)
-    private String deviceIp = "";
+    private String deviceIp;
 
     @Option(name = "-p",
             aliases = { "--port" },
@@ -60,7 +60,7 @@ public class NetconfConnectDeviceCommand extends AbstractAction {
 
     @Option(name = "-t",
             aliases = { "--tcp-only" },
-            description = "Type of connection, true for tcp only, false by default",
+            description = "Type of connection, true for tcp only",
             required = false,
             multiValued = false)
     private String connectionType = "false";
@@ -70,7 +70,7 @@ public class NetconfConnectDeviceCommand extends AbstractAction {
             description = "Node Identifier of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceId = "";
+    private String deviceId;
 
     @Override
     protected Object doExecute() throws Exception {
index efba6b62a3988773651a0be84e202be54150d932..94361901fdd123b96189cca32598f678d2658a06 100644 (file)
@@ -29,7 +29,7 @@ public class NetconfDisconnectDeviceCommand extends AbstractAction {
             description = "IP address of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceIp = "";
+    private String deviceIp;
 
     @Option(name = "-p",
             aliases = { "--port" },
@@ -43,7 +43,7 @@ public class NetconfDisconnectDeviceCommand extends AbstractAction {
             description = "Node Identifier of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceId = "";
+    private String deviceId;
 
     @Override
     protected Object doExecute() throws Exception {
index f5bf7a5c07f46628209fdfd49f864f2e799c76b9..b50ea715493a732c47853f03131e889b96a6e90e 100644 (file)
@@ -33,14 +33,14 @@ public class NetconfShowDeviceCommand extends AbstractAction {
             description = "Node Identifier of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceId = "";
+    private String deviceId;
 
     @Option(name = "-i",
             aliases = { "--ipaddress" },
             description = "IP address of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceIp = "";
+    private String deviceIp;
 
     @Option(name = "-p",
             aliases = { "--port" },
@@ -52,7 +52,7 @@ public class NetconfShowDeviceCommand extends AbstractAction {
     @Override
     protected Object doExecute() throws Exception {
 
-        if (Strings.isNullOrEmpty(deviceIp) || Strings.isNullOrEmpty(devicePort) && Strings.isNullOrEmpty(deviceId)) {
+        if ((Strings.isNullOrEmpty(deviceIp) || Strings.isNullOrEmpty(devicePort)) && Strings.isNullOrEmpty(deviceId)) {
             return "You must provide either the device Ip and the device Port or the device Id";
         }
 
index a15daf29d373b38e1702c87a0f9546d78a0aa4ea..b03556948e3e29b45469fad02ab99a19c8566898 100644 (file)
@@ -77,7 +77,7 @@ public class NetconfUpdateDeviceCommand extends AbstractAction {
 
     @Option(name = "-t",
             aliases = { "--tcp-only" },
-            description = "Type of connection, true for tcp only, false by default",
+            description = "Type of connection, true for tcp only",
             required = false,
             multiValued = false)
     private String newConnectionType = "false";
index f85b35bd95d074760f681e6b999ecbbf7c47acbe..68d30db1e48c0f6acf61a17018801e8a6b212b68 100644 (file)
@@ -90,14 +90,16 @@ public class NetconfCommandsImpl implements NetconfCommands {
         }
         if (nodeList != null) {
             for (final Node node : nodeList) {
-                final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
-                final Map<String, List<String>> attributes = new HashMap<>();
-                attributes.put(NetconfConsoleConstants.NETCONF_ID, ImmutableList.of(node.getNodeId().getValue()));
-                attributes.put(NetconfConsoleConstants.NETCONF_IP, ImmutableList.of(netconfNode.getHost().getIpAddress().getIpv4Address().getValue()));
-                attributes.put(NetconfConsoleConstants.NETCONF_PORT, ImmutableList.of(netconfNode.getPort().getValue().toString()));
-                attributes.put(NetconfConsoleConstants.STATUS, ImmutableList.of(netconfNode.getConnectionStatus().name()));
-                attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, netconfNode.getAvailableCapabilities().getAvailableCapability());
-                device.put(node.getNodeId().getValue(), attributes);
+                if (node != null) {
+                    final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+                    final Map<String, List<String>> attributes = new HashMap<>();
+                    attributes.put(NetconfConsoleConstants.NETCONF_ID, ImmutableList.of(node.getNodeId().getValue()));
+                    attributes.put(NetconfConsoleConstants.NETCONF_IP, ImmutableList.of(netconfNode.getHost().getIpAddress().getIpv4Address().getValue()));
+                    attributes.put(NetconfConsoleConstants.NETCONF_PORT, ImmutableList.of(netconfNode.getPort().getValue().toString()));
+                    attributes.put(NetconfConsoleConstants.STATUS, ImmutableList.of(netconfNode.getConnectionStatus().name()));
+                    attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, netconfNode.getAvailableCapabilities().getAvailableCapability());
+                    device.put(node.getNodeId().getValue(), attributes);
+                }
             }
         }
         return device;