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
=== modified file 'lib/mysql/fabric/command.py'
--- lib/mysql/fabric/command.py 2014-03-07 06:36:46 +0000
+++ lib/mysql/fabric/command.py 2014-05-04 23:21:53 +0000
@@ -42,6 +42,8 @@
42import functools42import functools
43import traceback43import traceback
4444
45import json
46
45import mysql.fabric.errors as _errors47import mysql.fabric.errors as _errors
46import mysql.fabric.executor as _executor48import mysql.fabric.executor as _executor
4749
@@ -452,13 +454,13 @@
452 :param params: The parameters to the function454 :param params: The parameters to the function
453455
454 :return: {success:True/False, message:<for example exception>,456 :return: {success:True/False, message:<for example exception>,
455 return:<return values>}.457 return:<Json string with return values>}.
456 """458 """
457 try:459 try:
458 status = func(*params)460 status = func(*params)
459 except Exception:461 except Exception:
460 return [False, traceback.format_exc(), True]462 return [False, traceback.format_exc(), True]
461 return [True, "", status]463 return [True, "", json.dumps(status)]
462464
463465
464class ProcedureCommand(Command):466class ProcedureCommand(Command):
465467
=== modified file 'lib/mysql/fabric/services/health.py'
--- lib/mysql/fabric/services/health.py 2014-02-24 15:18:57 +0000
+++ lib/mysql/fabric/services/health.py 2014-05-04 23:21:53 +0000
@@ -28,6 +28,8 @@
28 Command,28 Command,
29)29)
3030
31import json
32
31_LOGGER = logging.getLogger(__name__)33_LOGGER = logging.getLogger(__name__)
3234
33class CheckHealth(Command):35class CheckHealth(Command):
@@ -51,6 +53,40 @@
51 """53 """
52 return Command.generate_output_pattern(_health, group_id)54 return Command.generate_output_pattern(_health, group_id)
5355
56 @staticmethod
57 def command_status(status, details=False):
58 """Present the result reported by a command in a friendly-user way.
59
60 :param status: The command status.
61 :param details: Whether details on failures should be printed or
62 not.
63 """
64
65 returned = ""
66
67 if not isinstance(status, list):
68 returned = status
69 elif not isinstance(status[0], bool):
70 returned = status
71 else:
72 returned = "Group health:\n"
73
74 if status[0]:
75 health = json.loads(status[2])
76 for i in health.items():
77 returned += "\n".join([
78 " serverid = %s" % (i[0], ),
79 " is_alive = %s" % (i[1]['is_alive'] ),
80 " status = %s" % (i[1]['status'] ),
81 " address = %s" % (i[1]['address'] ),
82 " threads = %s" % (i[1]['threads'] ),
83 ""
84 ])
85 else:
86 returned = status[1].split("\n")[-2]
87
88 return returned
89
54def _health(group_id):90def _health(group_id):
55 """Check which servers in a group are up and down.91 """Check which servers in a group are up and down.
56 """92 """
@@ -65,7 +101,9 @@
65 is_master = (group.master == server.uuid)101 is_master = (group.master == server.uuid)
66 thread_issues = {}102 thread_issues = {}
67 status = server.status103 status = server.status
68 try:104 address = server.address
105
106 try:
69 server.connect()107 server.connect()
70 alive = True108 alive = True
71 if not is_master:109 if not is_master:
@@ -84,7 +122,8 @@
84 availability[str(server.uuid)] = {122 availability[str(server.uuid)] = {
85 "is_alive" : alive,123 "is_alive" : alive,
86 "status" : status,124 "status" : status,
87 "threads" : thread_issues125 "threads" : thread_issues,
126 "address" : address
88 }127 }
89128
90 return availability129 return availability

Subscribers

People subscribed via source and target branches