2 from nel_message
import *
5 class CAdminServiceWeb(CCallbackClient
):
7 def globalCmd(self
, command
):
10 msg
.serialString(command
)
11 return self
.sendMessage(msg
)
13 def controlCmd(self
, serviceAlias
, command
):
17 msg
.serialString(serviceAlias
)
18 msg
.serialString(command
)
20 return self
.sendMessage(msg
)
23 def serviceCmd(self
, serviceAlias
, command
):
27 msg
.serialString(serviceAlias
)
28 msg
.serialString(command
)
30 return self
.sendMessage(msg
)
32 def getShardOrders(self
):
37 ret
= sendMessage(msg
)
39 print("getShardOrders: Error in 'sendMessage'")
42 retMsg
= waitMessage()
44 print("getShardOrders: Error in 'waitMessage'")
47 if not retMsg
.MsgName
== "R_GSO":
48 print("getShardOrders: Invalid response, awaited 'R_GSO', received: "+retMsg
.MsgName
)
52 retMsg
.serialUInt32(nbElem
)
54 for i
in range(nbElem
):
55 retMsg
.serialString(item
)
61 def waitCallback(self
):
62 message
= self
.waitMessage()
67 if message
.MsgName
== "CMDR":
68 self
.commandResult_skel(message
)
73 def commandResult_skel(self
, message
):
74 serviceAlias
= message
.serialString()
75 result
= message
.serialString()
76 self
.commandResult(serviceAlias
, result
)
78 def commandResult(self
, serviceAlias
, result
):
79 global command_return_data
80 command_return_data
= result
84 def queryShard(service_name
, fullcmd
, waitCallback
=True, is_control
=False):
85 global command_return_data
88 nel_status
= not waitCallback
92 adminService
= CAdminServiceWeb()
94 if adminService
.connect("127.0.0.1", 46700, res
):
95 command_return_data
= ""
97 if isinstance(fullcmd
, str):
99 adminService
.controlCmd(service_name
, fullcmd
)
101 adminService
.serviceCmd(service_name
, fullcmd
)
102 service_command
= fullcmd
104 if waitCallback
and adminService
.waitCallback():
106 nel_result
+= command_return_data
108 for service_command
in fullcmd
:
110 adminService
.controlCmd(service_name
, service_command
)
112 adminService
.serviceCmd(service_name
, service_command
)
115 return {"status": nel_status
, "query": service_name
+":"+fullcmd
, "raw": nel_result
.split("\n")[1:]}