def __init__(self, eeagent_cfg, pyon_container, log=logging): self.log = log self.log.debug("Starting PyonExe") self._eename = eeagent_cfg.name self._slots = int(eeagent_cfg.slots) self._working_dir = eeagent_cfg.launch_type.persistence_directory self._known_pws = {} from pidantic.pyon.pidpyon import PyonPidanticFactory self._factory = PyonPidanticFactory(pyon_container=pyon_container, name=self._eename, directory=self._working_dir, log=self.log) pidantic_instances = self._factory.reload_instances() if len(pidantic_instances.keys()) > 0: self.log.error("Restarting eeagent, and found dead processes: %s" % ','.join(pidantic_instances.keys())) for name, pidantic in pidantic_instances.iteritems(): upid = pidantic.get_name() pw = PidWrapper(self, upid) pw.set_pidantic(pidantic) self._known_pws[upid] = pw self._state_change_cb = None self._state_change_cb_arg = None
def __init__(self, eeagent_cfg, pyon_container, log=logging): self.log = log self.log.debug("Starting PyonExe") self._eename = eeagent_cfg.name self._slots = int(eeagent_cfg.slots) self._working_dir = eeagent_cfg.launch_type.persistence_directory self._known_pws = {} from pidantic.pyon.pidpyon import PyonPidanticFactory self._factory = PyonPidanticFactory( pyon_container=pyon_container, name=self._eename, directory=self._working_dir, log=self.log ) pidantic_instances = self._factory.reload_instances() if len(pidantic_instances.keys()) > 0: self.log.error("Restarting eeagent, and found dead processes: %s" % ",".join(pidantic_instances.keys())) for name, pidantic in pidantic_instances.iteritems(): upid = pidantic.get_name() pw = PidWrapper(self, upid) pw.set_pidantic(pidantic) self._known_pws[upid] = pw self._state_change_cb = None self._state_change_cb_arg = None
class PyonExe(object): def __init__(self, eeagent_cfg, pyon_container, log=logging): self.log = log self.log.debug("Starting PyonExe") self._eename = eeagent_cfg.name self._slots = int(eeagent_cfg.slots) self._working_dir = eeagent_cfg.launch_type.persistence_directory self._known_pws = {} from pidantic.pyon.pidpyon import PyonPidanticFactory self._factory = PyonPidanticFactory( pyon_container=pyon_container, name=self._eename, directory=self._working_dir, log=self.log ) pidantic_instances = self._factory.reload_instances() if len(pidantic_instances.keys()) > 0: self.log.error("Restarting eeagent, and found dead processes: %s" % ",".join(pidantic_instances.keys())) for name, pidantic in pidantic_instances.iteritems(): upid = pidantic.get_name() pw = PidWrapper(self, upid) pw.set_pidantic(pidantic) self._known_pws[upid] = pw self._state_change_cb = None self._state_change_cb_arg = None def set_state_change_callback(self, cb, user_arg): self._state_change_cb = cb self._state_change_cb_arg = user_arg for name in self._known_pws: pw = self._known_pws[name] pw.set_state_change_callback(self._state_change_cb, self._state_change_cb_arg) def run(self, name, parameters): pyon_params = {} config = yaml.dump(parameters.get("config", {})) pid = self._factory.get_pidantic( directory=self._working_dir, process_name=name, pyon_name=parameters.get("name"), module_uri=parameters.get("module_uri"), module=parameters.get("module"), cls=parameters.get("cls"), config=config, ) pw = PidWrapper(self, name, p=pid) self._known_pws[name] = pw if self._state_change_cb: pw.set_state_change_callback(self._state_change_cb, self._state_change_cb_arg) running_jobs = self._get_running() if len(running_jobs) <= self._slots: pid.start() else: pid.cancel_request() return None def poll(self): return self._factory.poll() def terminate(self): self._factory.terminate() def get_all(self): return self._known_pws def _remove_proc(self, proc_name): del self._known_pws[proc_name] def _get_running(self): running_states = [PidWrapper.RUNNING, PidWrapper.TERMINATING, PidWrapper.PENDING] a = self.get_all().values() running = [i.get_state() for i in a] running = [i for i in a if i.get_state() in running_states] return running def lookup_id(self, process_name, ignore_round=False): if ignore_round: process_upid, process_round = unmake_id(process_name) for name, proc in self._known_pws.iteritems(): upid, round = unmake_id(name) if process_upid == upid: return proc else: return None else: if process_name not in self._known_pws: return None return self._known_pws[process_name]
class PyonExe(object): def __init__(self, eeagent_cfg, pyon_container, log=logging): self.log = log self.log.debug("Starting PyonExe") self._eename = eeagent_cfg.name self._slots = int(eeagent_cfg.slots) self._working_dir = eeagent_cfg.launch_type.persistence_directory self._known_pws = {} from pidantic.pyon.pidpyon import PyonPidanticFactory self._factory = PyonPidanticFactory(pyon_container=pyon_container, name=self._eename, directory=self._working_dir, log=self.log) pidantic_instances = self._factory.reload_instances() if len(pidantic_instances.keys()) > 0: self.log.error("Restarting eeagent, and found dead processes: %s" % ','.join(pidantic_instances.keys())) for name, pidantic in pidantic_instances.iteritems(): upid = pidantic.get_name() pw = PidWrapper(self, upid) pw.set_pidantic(pidantic) self._known_pws[upid] = pw self._state_change_cb = None self._state_change_cb_arg = None def set_state_change_callback(self, cb, user_arg): self._state_change_cb = cb self._state_change_cb_arg = user_arg for name in self._known_pws: pw = self._known_pws[name] pw.set_state_change_callback(self._state_change_cb, self._state_change_cb_arg) def run(self, name, parameters): pyon_params = {} config = yaml.dump(parameters.get('config', {})) pid = self._factory.get_pidantic( directory=self._working_dir, process_name=name, pyon_name=parameters.get('name'), module_uri=parameters.get('module_uri'), module=parameters.get('module'), cls=parameters.get('cls'), config=config) pw = PidWrapper(self, name, p=pid) self._known_pws[name] = pw if self._state_change_cb: pw.set_state_change_callback(self._state_change_cb, self._state_change_cb_arg) running_jobs = self._get_running() if len(running_jobs) <= self._slots: pid.start() else: pid.cancel_request() return None def poll(self): return self._factory.poll() def terminate(self): self._factory.terminate() def get_all(self): return self._known_pws def _remove_proc(self, proc_name): del self._known_pws[proc_name] def _get_running(self): running_states = [ PidWrapper.RUNNING, PidWrapper.TERMINATING, PidWrapper.PENDING ] a = self.get_all().values() running = [i.get_state() for i in a] running = [i for i in a if i.get_state() in running_states] return running def lookup_id(self, process_name, ignore_round=False): if ignore_round: process_upid, process_round = unmake_id(process_name) for name, proc in self._known_pws.iteritems(): upid, round = unmake_id(name) if process_upid == upid: return proc else: return None else: if process_name not in self._known_pws: return None return self._known_pws[process_name]