BUG-2218: Keep existing link augmentations during discovery process
[controller.git] / opendaylight / clustering / test / src / main / java / org / opendaylight / controller / clustering / test / internal / SimpleClient.java
index 3e9717fa62a751744d9a9f9633b2925a0cb72faa..52cc56e377e0529c3c39ca4ecf8cd278614cc904 100644 (file)
@@ -9,6 +9,7 @@
 
 package org.opendaylight.controller.clustering.test.internal;
 
+import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
@@ -151,7 +152,7 @@ public class SimpleClient implements CommandProvider {
                 .getILoggerFactory();
         if (lc != null) {
             for (ch.qos.logback.classic.Logger l : lc.getLoggerList()) {
-                if (loggerName == null || l.getName().startsWith(loggerName)) {
+                if ((loggerName == null) || l.getName().startsWith(loggerName)) {
                     ci.println(retrieveLogLevel(l));
                 }
             }
@@ -243,6 +244,7 @@ public class SimpleClient implements CommandProvider {
         }
     }
 
+    @SuppressWarnings("deprecation") //IGetUpdates intentionally deprecated
     public void _unlisten(CommandInterpreter ci) {
         if (this.icluster == null) {
             ci.println("\nNo Clustering services available");
@@ -267,12 +269,30 @@ public class SimpleClient implements CommandProvider {
         ci.println(cacheName + " is no longer being monitored for updates");
     }
 
+    public void _myController(CommandInterpreter ci) {
+        if (this.icluster == null) {
+            ci.println("\nNo Clustering services available");
+            return;
+        }
+        ci.println("This Controller : " +icluster.getMyAddress().getHostAddress());
+    }
+
+    public void _getClusterNodes(CommandInterpreter ci) {
+        if (this.icluster == null) {
+            ci.println("\nNo Clustering services available");
+            return;
+        }
+        for (InetAddress address : icluster.getClusteredControllers()) {
+            ci.println("\t"+address.getHostAddress());
+        }
+    }
+
     public void _listcaches(CommandInterpreter ci) {
         if (this.icluster == null) {
             ci.println("\nNo Clustering services available");
             return;
         }
-        String containerName = ci.nextArgument();
+        String containerName = ci.nextArgument().toLowerCase();
         if (containerName == null) {
             ci.println("containerName not supplied");
             return;
@@ -324,7 +344,13 @@ public class SimpleClient implements CommandProvider {
                 containerName, cacheName);
         if (c != null) {
             ci.println("\nAdd mapping " + key + " = " + sValue);
-            c.put(key, new StringContainer(sValue));
+            try {
+                c.put(key, new StringContainer(sValue));
+            } catch (Exception e) {
+                ci.println("Exception raised:" + e);
+                ci.println("\tStacktrace:");
+                e.printStackTrace();
+            }
         } else {
             ci.println("Cache " + cacheName + " on container " + containerName
                     + " not existant!");
@@ -370,8 +396,8 @@ public class SimpleClient implements CommandProvider {
     }
 
     public void _dumper(CommandInterpreter ci) {
-        ConcurrentMap c;
-        String containerName = ci.nextArgument();
+        ConcurrentMap<Object, Object> c;
+        String containerName = ci.nextArgument().toLowerCase();
         if (containerName == null) {
             ci.println("containerName not supplied");
             return;
@@ -381,10 +407,11 @@ public class SimpleClient implements CommandProvider {
             ci.println("Cache not supplied");
             return;
         }
-        c = (ConcurrentMap) this.icluster.getCache(containerName, cacheName);
+        int count = 0;
+        c = (ConcurrentMap<Object, Object>) this.icluster.getCache(containerName, cacheName);
         if (c != null) {
-            for (Object e : c.entrySet()) {
-                Map.Entry entry = (Map.Entry) e;
+            for (Map.Entry<Object, Object> e : c.entrySet()) {
+                Map.Entry<Object, Object> entry = e;
                 Object v = entry.getValue();
                 String res = "<NOT KNOWN>";
                 if (v != null) {
@@ -393,7 +420,9 @@ public class SimpleClient implements CommandProvider {
                 ci.println("Element " + entry.getKey() + "(hashCode="
                         + entry.getKey().hashCode() + ") has value = (" + res
                         + ")");
+                count++;
             }
+            ci.println("Dumped " + count + " records");
         } else {
             ci.println("Cache " + cacheName + " on container " + containerName
                     + " not existant!");
@@ -437,27 +466,7 @@ public class SimpleClient implements CommandProvider {
         }
     }
 
-    public void _getRole(CommandInterpreter ci) {
-        if (this.icluster == null) {
-            ci.println("\nNo Clustering services available");
-            return;
-        }
-        String role = "Active";
-        if (this.icluster.amIStandby()) {
-            role = "Standby";
-        }
-        ci.println("My role is: " + role);
-    }
-
-    public void _getActive(CommandInterpreter ci) {
-        if (this.icluster == null) {
-            ci.println("\nNo Clustering services available");
-            return;
-        }
-        ci.println("Current active address is "
-                + this.icluster.getActiveAddress());
-    }
-
+    @SuppressWarnings("deprecation") //TODO: remove use of deprecated listenRoleChange
     public void _listenActive(CommandInterpreter ci) {
         if (this.icluster == null) {
             ci.println("\nNo Clustering services available");
@@ -473,6 +482,7 @@ public class SimpleClient implements CommandProvider {
         ci.println("Register listenRoleChanges");
     }
 
+    @SuppressWarnings("deprecation") //TODO: remove deprecated call to unlistenRoleChange
     public void _unlistenActive(CommandInterpreter ci) {
         if (this.icluster == null) {
             ci.println("\nNo Clustering services available");
@@ -485,6 +495,7 @@ public class SimpleClient implements CommandProvider {
     }
 
     class DoListenRoleChanged implements IListenRoleChange {
+        @Override
         public void newActiveAvailable() {
             logger.debug("New Active is available");
         }
@@ -631,16 +642,12 @@ public class SimpleClient implements CommandProvider {
         help.append("\tunlistenActive   - UNListen to Active updates\n");
         help.append("\tdestroy          - Destroy a cache\n");
         help.append("\tcreate           - Create a cache\n");
-        help.append("\tgetRole          - Tell if active or standby\n");
-        help.append("\tgetActive        - Report the IP address of Active\n");
-        help
-                .append("\tputComplex       - Fill a more complex data structure\n");
-        help
-                .append("\tupdateComplex    - Update the value of a more complex data structure\n");
-        help
-                .append("\tgetLogLevel      - Get the loglevel for the logger specified\n");
-        help
-                .append("\tsetLogLevel      - Set the loglevel for the logger specified\n");
+        help.append("\tmyController     - Print this controller's Cluster identifier\n");
+        help.append("\tgetClusterNodes  - Print all the controllers that make this cluster\n");
+        help.append("\tputComplex       - Fill a more complex data structure\n");
+        help.append("\tupdateComplex    - Update the value of a more complex data structure\n");
+        help.append("\tgetLogLevel      - Get the loglevel for the logger specified\n");
+        help.append("\tsetLogLevel      - Set the loglevel for the logger specified\n");
         return help.toString();
     }
 }