Merge lp:~martinarrieta/mysql-fabric/BUG-71445 into lp:mysql-fabric

Proposed by Martin Arrieta
Status: Needs review
Proposed branch: lp:~martinarrieta/mysql-fabric/BUG-71445
Merge into: lp:mysql-fabric
Diff against target: 103 lines (+45/-4)
2 files modified
lib/mysql/fabric/command.py (+4/-2)
lib/mysql/fabric/services/health.py (+41/-2)
To merge this branch: bzr merge lp:~martinarrieta/mysql-fabric/BUG-71445
Reviewer Review Type Date Requested Status
Oracle/MySQL Engineering Pending
Review via email: mp+218223@code.launchpad.net

Description of the change

Hello,

I have added the Json support for the returned string and I also have added a dispatcher method for the Group Health as an example about why this Json string is useful.

For example:

# mysqlfabric group health test1
Group health:
 serverid = 12f4a168-d08e-11e3-92cf-08002760fc47
  is_alive = False
  status = FAULTY
  address = 192.168.70.102
  threads = {}
 serverid = 1189e6be-d08e-11e3-92cf-08002760fc47
  is_alive = False
  status = FAULTY
  address = 192.168.70.103
  threads = {}
 serverid = 0efa44fb-d08e-11e3-92cf-08002760fc47
  is_alive = False
  status = FAULTY
  address = 192.168.70.104
  threads = {}

We can try to re-wrinte the default dispatcher to iterate the result in order to make a "general" solution, but this will depend if you like the idea or not.

Please let me know what do you think and if you want to change anything feel free to do it or let me know it and I'll do it.

Regards,

Martin Arrieta.
@martinarrietac

To post a comment you must log in.
227. By Martin Arrieta

Changed the method from dispatcher to command_status

228. By Martin Arrieta

Fixed error with groups that does not exist

Unmerged revisions

228. By Martin Arrieta

Fixed error with groups that does not exist

227. By Martin Arrieta

Changed the method from dispatcher to command_status

226. By Martin Arrieta

fixex the group health command

225. By Martin Arrieta

Adding Json support for the result

224. By Martin Arrieta

added the address of the servers to the group health command

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/mysql/fabric/command.py'
2--- lib/mysql/fabric/command.py 2014-03-07 06:36:46 +0000
3+++ lib/mysql/fabric/command.py 2014-05-04 23:21:53 +0000
4@@ -42,6 +42,8 @@
5 import functools
6 import traceback
7
8+import json
9+
10 import mysql.fabric.errors as _errors
11 import mysql.fabric.executor as _executor
12
13@@ -452,13 +454,13 @@
14 :param params: The parameters to the function
15
16 :return: {success:True/False, message:<for example exception>,
17- return:<return values>}.
18+ return:<Json string with return values>}.
19 """
20 try:
21 status = func(*params)
22 except Exception:
23 return [False, traceback.format_exc(), True]
24- return [True, "", status]
25+ return [True, "", json.dumps(status)]
26
27
28 class ProcedureCommand(Command):
29
30=== modified file 'lib/mysql/fabric/services/health.py'
31--- lib/mysql/fabric/services/health.py 2014-02-24 15:18:57 +0000
32+++ lib/mysql/fabric/services/health.py 2014-05-04 23:21:53 +0000
33@@ -28,6 +28,8 @@
34 Command,
35 )
36
37+import json
38+
39 _LOGGER = logging.getLogger(__name__)
40
41 class CheckHealth(Command):
42@@ -51,6 +53,40 @@
43 """
44 return Command.generate_output_pattern(_health, group_id)
45
46+ @staticmethod
47+ def command_status(status, details=False):
48+ """Present the result reported by a command in a friendly-user way.
49+
50+ :param status: The command status.
51+ :param details: Whether details on failures should be printed or
52+ not.
53+ """
54+
55+ returned = ""
56+
57+ if not isinstance(status, list):
58+ returned = status
59+ elif not isinstance(status[0], bool):
60+ returned = status
61+ else:
62+ returned = "Group health:\n"
63+
64+ if status[0]:
65+ health = json.loads(status[2])
66+ for i in health.items():
67+ returned += "\n".join([
68+ " serverid = %s" % (i[0], ),
69+ " is_alive = %s" % (i[1]['is_alive'] ),
70+ " status = %s" % (i[1]['status'] ),
71+ " address = %s" % (i[1]['address'] ),
72+ " threads = %s" % (i[1]['threads'] ),
73+ ""
74+ ])
75+ else:
76+ returned = status[1].split("\n")[-2]
77+
78+ return returned
79+
80 def _health(group_id):
81 """Check which servers in a group are up and down.
82 """
83@@ -65,7 +101,9 @@
84 is_master = (group.master == server.uuid)
85 thread_issues = {}
86 status = server.status
87- try:
88+ address = server.address
89+
90+ try:
91 server.connect()
92 alive = True
93 if not is_master:
94@@ -84,7 +122,8 @@
95 availability[str(server.uuid)] = {
96 "is_alive" : alive,
97 "status" : status,
98- "threads" : thread_issues
99+ "threads" : thread_issues,
100+ "address" : address
101 }
102
103 return availability

Subscribers

People subscribed via source and target branches