fix task stop

there are some codes should in client side, but I put in agent(server)
side before

Change-Id: I3ca3bedd6f67d7994f7011bd85aa2c8fc6fa7403
This commit is contained in:
Kun Huang 2015-11-11 11:51:22 +08:00
parent fe44498986
commit 89a11930d0
4 changed files with 24 additions and 23 deletions

View File

@ -45,29 +45,15 @@ class TaskEndpoint(object):
LOWEST = 8
def get_last_task(self):
# XXX put it tu utils?
# XXX put it utils?
last_task = db_api.task_get_last()
return last_task
def stop_task(self, ctx):
uuid = ctx.get("uuid")
last = ctx.get("last")
if last and uuid:
raise ValueError("can't assign last and uuid togther")
elif not last and not uuid:
task = self.get_last_task()
elif last:
task = self.get_last_task()
elif uuid and len(uuid) < self.LOWEST:
print "at least %d to find a task" % self.LOWEST
return
else:
# len(uuid) > LOWEST
task = db_api.task_get(uuid, fuzzy=True)
def stop_task(self, ctx, uuid):
print "command stop: %s" % ctx
print "task: <%s>" % task.uuid
print "task: <%s>" % uuid
task = db_api.task_get(uuid)
for pid in task.pids:
p = psutil.Process(int(pid))
p.send_signal(signal.SIGINT)

View File

@ -12,4 +12,19 @@ def get_last_task():
return last_task
def run(config):
agent_api.stop_task(config)
uuid = config.get("uuid")
last = config.get("last")
if last and uuid:
raise ValueError("can't assign last and uuid togther")
elif not last and not uuid:
task = agent_api.get_latest_task()
elif last:
task = agent_api.get_latest_task()
elif uuid and len(uuid) < LOWEST:
print "at least %d to find a task" % LOWEST
return
else:
# len(uuid) > LOWEST
task = agent_api.get_task(uuid, fuzzy=True)
agent_api.stop_task(task["uuid"])

View File

@ -15,8 +15,8 @@ class API(object):
def start_tracers(self, tracers):
rpcapi.start_tracers(tracers=tracers)
def stop_task(self, config):
rpcapi.stop_task(config)
def stop_task(self, uuid):
rpcapi.stop_task(uuid=uuid)
def get_task(self, uuid, fuzzy=False):
return rpcapi.get_task(uuid=uuid, fuzzy=fuzzy)

View File

@ -13,8 +13,8 @@ class RPCAPI(object):
def start_tracers(self, ctxt={}, tracers=None):
self._client.cast(ctxt, "start_tracers", tracers=tracers)
def stop_task(self, ctxt={}):
self._client.cast(ctxt, "stop_task")
def stop_task(self, ctxt={}, uuid=None):
self._client.cast(ctxt, "stop_task", uuid=uuid)
def get_task(self, ctxt={}, uuid=None, fuzzy=False):
return self._client.call(ctxt, "get_task", uuid=uuid, fuzzy=fuzzy)