Ejemplo n.º 1
0
 def _locate_killers(self):
     start_traces = self.starttracereader.apps_started()
     killer_instances = dict()
     to_kill = list()
     for mp in start_traces:
         fn = mp['trace_fn']
         app_name = mp['name']
         # Figure out which class will stop it
         killcls = None
         runtype = "??"
         for (cmd, action) in tr.parse_fn(fn):
             if cmd == settings.RUN_TYPE_TYPE and action:
                 runtype = action
                 killcls = RUNNER_CLS_MAPPING.get(runtype)
                 break
         # Did we find a class that can do it?
         if killcls:
             if killcls in killer_instances:
                 killer = killer_instances[killcls]
             else:
                 killer = killcls(self.cfg, self.component_name, self.tracedir)
                 killer_instances[killcls] = killer
             to_kill.append((app_name, killer))
         else:
             msg = "Could not figure out which class to use to stop (%s, %s) of run type (%s)" % (app_name, fn, runtype)
             raise excp.StopException(msg)
     return to_kill
Ejemplo n.º 2
0
 def _find_session(self, app_name, trace_fn):
     session_id = None
     for (key, value) in tr.parse_fn(trace_fn):
         if key == SESSION_ID and value:
             session_id = value
     if not session_id:
         msg = "Could not find a screen session id for %s in file [%s]" % (app_name, trace_fn)
         raise excp.StopException(msg)
     return session_id
Ejemplo n.º 3
0
 def stop(self):
     #ensure it was installed
     if not self._was_installed():
         msg = "Can not stop %s since it was not installed" % (self.component_name)
         raise excp.StopException(msg)
     #we can only stop what has a started trace
     start_traces = self.starttracereader.apps_started()
     killedam = 0
     for mp in start_traces:
         #extract the apps name and where its trace is
         fn = mp.get('trace_fn')
         name = mp.get('name')
         #missing some key info, skip it
         if fn is None or name is None:
             continue
         #figure out which class will stop it
         contents = tr.parse_fn(fn)
         killcls = None
         runtype = None
         for (cmd, action) in contents:
             if cmd == "TYPE":
                 runtype = action
                 killcls = self._getstoppercls(runtype)
                 break
         #did we find a class that can do it?
         if killcls:
             #we can try to stop it
             LOG.info("Stopping %s of run type %s" % (name, runtype))
             #create an instance of the killer class and attempt to stop
             killer = killcls()
             killer.stop(name, trace_dir=self.tracedir)
             killedam += 1
         else:
             #TODO raise error??
             pass
     #if we got rid of them all get rid of the trace
     if killedam == len(start_traces):
         fn = self.starttracereader.trace_fn
         LOG.info("Deleting trace file %s" % (fn))
         sh.unlink(fn)
     return killedam