adding more configuration around shard names and restconf port 02/35902/1
authorJamo Luhrsen <jluhrsen@redhat.com>
Tue, 8 Mar 2016 00:31:41 +0000 (16:31 -0800)
committerJamo Luhrsen <jluhrsen@redhat.com>
Tue, 8 Mar 2016 00:31:41 +0000 (16:31 -0800)
- added ability to provide specific port numbers for each controllers
  restconf endpoint

- added ability to selectively ignore some shards.  specifically, I
  didn't want to look at the toaster shard when giving a demo

Change-Id: Ia7186193d186e34ba7963741ac54902d9619d34f
Signed-off-by: Jamo Luhrsen <jluhrsen@redhat.com>
tools/clustering/cluster-monitor/cluster.json
tools/clustering/cluster-monitor/isolate.py
tools/clustering/cluster-monitor/monitor.py
tools/clustering/cluster-monitor/rejoin.py
tools/clustering/cluster-monitor/timed_isolation.py

index 299d8b4453c3739c5c626045f606c9d0bee40c9a..138c9d21d8bd53c49c19ff447c656b7b88525ec2 100644 (file)
@@ -1,11 +1,12 @@
 {
     "cluster": {
         "controllers": [
-            "172.17.10.93",
-            "172.17.10.94",
-            "172.17.10.95"
+            {"ip": "172.17.10.93", "port": "8181"},
+            {"ip": "172.17.10.93", "port": "8181"},
+            {"ip": "172.17.10.93", "port": "8181"}
         ],
         "user": "username",
-        "pass": "password"
+        "pass": "password",
+        "shards_to_exclude": []
     }
 }
index a1eebc963d4676f83efb2b57a51124bfb1776845..1dd80ef6b7d73b4aa95ca1f656a37ab845333dd6 100644 (file)
@@ -9,7 +9,7 @@ a single integer argument corresponding to the number of a controller
 in a json file's ordered list of controllers. This is the controller to
 be isolated.
 
-A file named 'cluster.json' containing a list of the IP addresses and
+A file named 'cluster.json' containing a list of the IP addresses, ports and
 credentials of the controllers is required. It resides in the same
 directory as monitor.py.
 
@@ -18,12 +18,12 @@ The file should look like this:
     {
         "cluster": {
             "controllers": [
-                "172.17.10.93",
-                "172.17.10.94",
-                "172.17.10.95"
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"}
             ],
             "user": "username",
-            "pass": "password"
+            "pass": "password",
         }
     }
 
@@ -52,6 +52,9 @@ except:
     exit(1)
 try:
     cluster_list = data["cluster"]["controllers"]
+    cluster_ips = []
+    for controller in cluster_list:
+        cluster_ips.append(controller["ip"])
     user_name = data["cluster"]["user"]
     user_pass = data["cluster"]["pass"]
 except:
@@ -66,4 +69,4 @@ except:
 
 print "isolating controller " + str(isolate)
 
-print UtilLibrary.isolate_controller(cluster_list, user_name, user_pass, isolate)
+print UtilLibrary.isolate_controller(cluster_ips, user_name, user_pass, isolate)
index 4df556bb27e5e5c2a4583ba80d5faf01a99d1fb0..c9fb3ee5d7dd59198f4ff27637d5fd0c826c76e9 100644 (file)
@@ -2,25 +2,26 @@
 """
 Cluster Monitor Tool
 Author: Phillip Shea
-Updated: 2015-May-07
+Updated: 2016-Mar-07
 
 This tool provides real-time visualization of the cluster member roles for all
 shards in the config datastore.
 
-A file named 'cluster.json' contaning a list of the IP addresses of the
-controllers is required. This resides in the same directory as monitor.py.
+A file named 'cluster.json' contaning a list of the IP addresses and port numbers
+of the controllers is required. This resides in the same directory as monitor.py.
 "user" and "pass" are not required for monitor.py, but they may be
 needed for other apps in this folder. The file should look like this:
 
     {
         "cluster": {
             "controllers": [
-                "172.17.10.93",
-                "172.17.10.94",
-                "172.17.10.95"
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"}
             ],
             "user": "username",
-            "pass": "password"
+            "pass": "password",
+            "shards_to_exclude": []  # list of shard names to omit from output
         }
     }
 
@@ -51,30 +52,30 @@ def rest_get(restURL):
 
 
 def getClusterRolesWithCurl(shardName, *args):
-    ips = args[0]
+    controllers = args[0]
     names = args[1]
     controller_state = {}
-    for i, ip in enumerate(ips):
-        controller_state[ip] = None
-        url = 'http://' + ip + ':' + '8181/jolokia/read/org.opendaylight.controller:'
+    for i, controller in enumerate(controllers):
+        controller_state[controller["ip"]] = None
+        url = "http://" + controller["ip"] + ":" + controller["port"] + "/jolokia/read/org.opendaylight.controller:"
         url += 'Category=Shards,name=' + names[i]
         url += '-shard-' + shardName + '-config,type=DistributedConfigDatastore'
         try:
             resp = rest_get(url)
             if resp['status'] != 200:
-                controller_state[ip] = 'HTTP ' + str(resp['status'])
+                controller_state[controller["ip"]] = 'HTTP ' + str(resp['status'])
             if 'value' in resp:
                 data_value = resp['value']
-                controller_state[ip] = data_value['RaftState']
+                controller_state[controller["ip"]] = data_value['RaftState']
         except:
             if 'timed out' in str(sys.exc_info()[1]):
-                controller_state[ip] = 'timeout'
+                controller_state[controller["ip"]] = 'timeout'
             elif 'JSON' in str(sys.exc_info()):
-                controller_state[ip] = 'JSON error'
+                controller_state[controller["ip"]] = 'JSON error'
             elif 'connect to host' in str(sys.exc_info()):
-                controller_state[ip] = 'no connection'
+                controller_state[controller["ip"]] = 'no connection'
             else:
-                controller_state[ip] = 'down'
+                controller_state[controller["ip"]] = 'down'
     return controller_state
 
 
@@ -101,6 +102,7 @@ except:
     exit(1)
 try:
     controllers = data["cluster"]["controllers"]
+    shards_to_exclude = data["cluster"]["shards_to_exclude"]
 except:
     print str(sys.exc_info())
     print 'Error reading the file cluster.json'
@@ -110,7 +112,7 @@ controller_names = []
 Shards = set()
 # Retrieve controller names and shard names.
 for controller in controllers:
-    url = "http://" + controller + ":8181/jolokia/read/org.opendaylight.controller:"
+    url = "http://" + controller["ip"] + ":" + controller["port"] + "/jolokia/read/org.opendaylight.controller:"
     url += "Category=ShardManager,name=shard-manager-config,type=DistributedConfigDatastore"
     try:
         data = rest_get(url)
@@ -132,7 +134,8 @@ for controller in controllers:
     # collect shards found in any controller; does not require all controllers to have the same shards
     for localShard in data['value']['LocalShards']:
         shardName = localShard[(localShard.find("-shard-") + 7):localShard.find("-config")]
-        Shards.add(shardName)
+        if shardName not in shards_to_exclude:
+            Shards.add(shardName)
 print controller_names
 print Shards
 field_len = max(map(len, Shards)) + 2
@@ -167,16 +170,17 @@ while key != ord('q') and key != ord('Q'):
     key = stdscr.getch()
 
     for data_column, shard_name in enumerate(Shards):
-        cluster_stat = getClusterRolesWithCurl(shard_name, controllers, controller_names)
-        for row, controller in enumerate(controllers):
-            status = size_and_color(cluster_stat, field_len, controller)
-            stdscr.addstr(row + 1, (field_len + 1) * (data_column + 1), status['txt'], status['color'])
-    time.sleep(0.5)
-    if odd_or_even % 2 == 0:
-        stdscr.addstr(0, field_len / 2 - 2, " <3 ", curses.color_pair(5))
-    else:
-        stdscr.addstr(0, field_len / 2 - 2, " <3 ", curses.color_pair(0))
-    stdscr.refresh()
+        if shard_name not in shards_to_exclude:
+            cluster_stat = getClusterRolesWithCurl(shard_name, controllers, controller_names)
+            for row, controller in enumerate(controllers):
+                status = size_and_color(cluster_stat, field_len, controller["ip"])
+                stdscr.addstr(row + 1, (field_len + 1) * (data_column + 1), status['txt'], status['color'])
+        time.sleep(0.5)
+        if odd_or_even % 2 == 0:
+            stdscr.addstr(0, field_len / 2 - 2, " <3 ", curses.color_pair(5))
+        else:
+            stdscr.addstr(0, field_len / 2 - 2, " <3 ", curses.color_pair(0))
+        stdscr.refresh()
 
 # clean up
 curses.nocbreak()
index 172788c0ae14a3050f0a1b49162db3d8e5108316..c9735db4f2eb942aa3f5ad7c6753386f96b2e31e 100644 (file)
@@ -15,12 +15,12 @@ The file should look like this:
     {
         "cluster": {
             "controllers": [
-                "172.17.10.93",
-                "172.17.10.94",
-                "172.17.10.95"
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"}
             ],
             "user": "username",
-            "pass": "password"
+            "pass": "password",
         }
     }
 
@@ -49,6 +49,9 @@ except:
     exit(1)
 try:
     cluster_list = data["cluster"]["controllers"]
+    cluster_ips = []
+    for controller in cluster_list:
+        cluster_ips.append(controller["ip"])
     user_name = data["cluster"]["user"]
     user_pass = data["cluster"]["pass"]
 except:
@@ -56,4 +59,4 @@ except:
     print 'Error reading the file cluster.json'
     exit(1)
 
-print UtilLibrary.flush_iptables(cluster_list, user_name, user_pass)
+print UtilLibrary.flush_iptables(cluster_ips, user_name, user_pass)
index 8406e592effe3499167a7ac65ec4420ed7a96c60..06b5d127870536b00eae1e60745045f03e362804 100644 (file)
@@ -19,12 +19,12 @@ The file should look like this:
     {
         "cluster": {
             "controllers": [
-                "172.17.10.93",
-                "172.17.10.94",
-                "172.17.10.95"
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"},
+                {"ip": "172.17.10.93", "port": "8181"}
             ],
             "user": "username",
-            "pass": "password"
+            "pass": "password",
         }
     }
 
@@ -53,7 +53,10 @@ except:
     print 'unable to open the file cluster.json'
     exit(1)
 try:
-    controllers = data["cluster"]["controllers"]
+    cluster_list = data["cluster"]["controllers"]
+    cluster_ips = []
+    for controller in cluster_list:
+        cluster_ips.append(controller["ip"])
     user_name = data["cluster"]["user"]
     user_pass = data["cluster"]["pass"]
 except:
@@ -69,9 +72,9 @@ except:
 
 print 'Isolating controller ' + str(isolate)
 
-print UtilLibrary.isolate_controller(controllers, user_name, user_pass, isolate)
+print UtilLibrary.isolate_controller(cluster_ips, user_name, user_pass, isolate)
 
 print 'Pausing for ' + str(duration) + ' seconds...'
 time.sleep(duration)
 
-print UtilLibrary.flush_iptables(controllers, user_name, user_pass)
+print UtilLibrary.flush_iptables(cluster_ips, user_name, user_pass)