From 89a11930d0a330ccc81659c3d4772bb747a2d694 Mon Sep 17 00:00:00 2001 From: Kun Huang Date: Wed, 11 Nov 2015 11:51:22 +0800 Subject: [PATCH] fix task stop there are some codes should in client side, but I put in agent(server) side before Change-Id: I3ca3bedd6f67d7994f7011bd85aa2c8fc6fa7403 --- scalpels/agents/server.py | 22 ++++------------------ scalpels/cli/actions/stop.py | 17 ++++++++++++++++- scalpels/cli/api.py | 4 ++-- scalpels/cli/rpcapi.py | 4 ++-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/scalpels/agents/server.py b/scalpels/agents/server.py index 3da1bdc..97356fb 100644 --- a/scalpels/agents/server.py +++ b/scalpels/agents/server.py @@ -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) diff --git a/scalpels/cli/actions/stop.py b/scalpels/cli/actions/stop.py index 86912e5..2cda4f0 100644 --- a/scalpels/cli/actions/stop.py +++ b/scalpels/cli/actions/stop.py @@ -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"]) diff --git a/scalpels/cli/api.py b/scalpels/cli/api.py index 64cc78a..7c181a0 100644 --- a/scalpels/cli/api.py +++ b/scalpels/cli/api.py @@ -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) diff --git a/scalpels/cli/rpcapi.py b/scalpels/cli/rpcapi.py index e50fbd0..ba1e491 100644 --- a/scalpels/cli/rpcapi.py +++ b/scalpels/cli/rpcapi.py @@ -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)