def get_tracker_data(self, fw_id): data = [] for l in self.launches.find({'fw_id': fw_id}, {'trackers': 1, 'launch_id': 1}): if 'trackers' in l: # backwards compatibility trackers = [Tracker.from_dict(t) for t in l['trackers']] data.append({'launch_id': l['launch_id'], 'trackers': trackers}) return data
def checkout_fw(self, fworker, launch_dir, fw_id=None, host=None, ip=None): """ (internal method) Finds a FireWork that's ready to be run, marks it as running, and returns it to the caller. The caller is responsible for running the FireWork. :param fworker: A FWorker instance :param host: the host making the request (for creating a Launch object) :param ip: the ip making the request (for creating a Launch object) :param launch_dir: the dir the FW will be run in (for creating a Launch object) :return: a FireWork, launch_id tuple """ # TODO: this method is confusing, says AJ of Xmas past. Clean it up, remove duplication, etc. m_fw = self._get_a_fw_to_run(fworker.query, fw_id) if not m_fw: return None, None # was this Launch previously reserved? If so, overwrite that reservation with this Launch # note that adding a new Launch is problematic from a duplicate run standpoint prev_reservations = [l for l in m_fw.launches if l.state == 'RESERVED'] reserved_launch = None if len(prev_reservations) == 0 else prev_reservations[0] state_history = reserved_launch.state_history if reserved_launch else None l_id = reserved_launch.launch_id if reserved_launch else self.get_new_launch_id() trackers = [Tracker.from_dict(f) for f in m_fw.spec['_trackers']] if '_trackers' in m_fw.spec else None m_launch = Launch('RUNNING', launch_dir, fworker, host, ip, trackers=trackers, state_history=state_history, launch_id=l_id, fw_id=m_fw.fw_id) self.launches.find_and_modify({'launch_id': m_launch.launch_id}, m_launch.to_db_dict(), upsert=True) self.m_logger.debug('Created/updated Launch with launch_id: {}'.format(l_id)) if not reserved_launch: # we're appending a new FireWork m_fw.launches.append(m_launch) else: # we're updating an existing launch m_fw.launches = [m_launch if l.launch_id == m_launch.launch_id else l for l in m_fw.launches] m_fw.state = 'RUNNING' self._upsert_fws([m_fw]) # update any duplicated runs for fw in self.fireworks.find( {'launches': l_id, 'state': {'$in': ['WAITING', 'READY', 'RESERVED', 'FIZZLED']}}, {'fw_id': 1}): fw_id = fw['fw_id'] fw = self.get_fw_by_id(fw_id) fw.state = 'RUNNING' self._upsert_fws([fw]) self.m_logger.debug('Checked out FW with id: {}'.format(m_fw.fw_id)) # use dict as return type, just to be compatible with multiprocessing return m_fw, l_id
def checkout_fw(self, fworker, launch_dir, fw_id=None, host=None, ip=None): """ (internal method) Finds a FireWork that's ready to be run, marks it as running, and returns it to the caller. The caller is responsible for running the FireWork. :param fworker: A FWorker instance :param host: the host making the request (for creating a Launch object) :param ip: the ip making the request (for creating a Launch object) :param launch_dir: the dir the FW will be run in (for creating a Launch object) :return: a FireWork, launch_id tuple """ # TODO: this method is confusing, says AJ of Xmas past. Clean it up, remove duplication, etc. m_fw = self._get_a_fw_to_run(fworker.query, fw_id) if not m_fw: return None, None # was this Launch previously reserved? If so, overwrite that reservation with this Launch # note that adding a new Launch is problematic from a duplicate run standpoint prev_reservations = [l for l in m_fw.launches if l.state == 'RESERVED'] reserved_launch = None if len(prev_reservations) == 0 else prev_reservations[0] state_history = reserved_launch.state_history if reserved_launch else None l_id = reserved_launch.launch_id if reserved_launch else self.get_new_launch_id() trackers = [Tracker.from_dict(f) for f in m_fw.spec['_trackers']] if '_trackers' in m_fw.spec else None m_launch = Launch('RUNNING', launch_dir, fworker, host, ip, trackers=trackers, state_history=state_history, launch_id=l_id, fw_id=m_fw.fw_id) self.launches.find_and_modify({'launch_id': m_launch.launch_id}, m_launch.to_db_dict(), upsert=True) self.m_logger.debug('Created/updated Launch with launch_id: {}'.format(l_id)) if not reserved_launch: # we're appending a new FireWork m_fw.launches.append(m_launch) else: # we're updating an existing launch m_fw.launches = [m_launch if l.launch_id == m_launch.launch_id else l for l in m_fw.launches] m_fw.state = 'RUNNING' self._upsert_fws([m_fw]) # update any duplicated runs for fw in self.fireworks.find( {'launches': l_id, 'state': {'$in': ['WAITING', 'READY', 'RESERVED', 'FIZZLED']}}, {'fw_id': 1}): fw_id = fw['fw_id'] fw = self.get_fw_by_id(fw_id) fw.state = 'RUNNING' self._upsert_fws([fw]) self.m_logger.debug('Checked out FW with id: {}'.format(m_fw.fw_id)) return m_fw, l_id
def reserve_fw(self, fworker, launch_dir, host=None, ip=None): m_fw = self._get_a_fw_to_run(fworker.query) if not m_fw: return None, None # create a launch # TODO: this code is duplicated with checkout_fw with minimal mods, should refactor this!! launch_id = self.get_new_launch_id() trackers = [Tracker.from_dict(f) for f in m_fw.spec['_trackers']] if '_trackers' in m_fw.spec else None m_launch = Launch('RESERVED', launch_dir, fworker, host, ip, trackers=trackers, launch_id=launch_id, fw_id=m_fw.fw_id) self.launches.find_and_modify({'launch_id': m_launch.launch_id}, m_launch.to_db_dict(), upsert=True) # add launch to FW m_fw.launches.append(m_launch) m_fw.state = 'RESERVED' self._upsert_fws([m_fw]) self.m_logger.debug('Reserved FW with id: {}'.format(m_fw.fw_id)) return m_fw, launch_id
def _reserve_fw(self, fworker, launch_dir, host=None, ip=None): m_fw = self._get_a_fw_to_run(fworker.query) if not m_fw: return None, None # create a launch # TODO: this code is duplicated with checkout_fw with minimal mods, should refactor this!! launch_id = self.get_new_launch_id() trackers = [Tracker.from_dict(f) for f in m_fw.spec['_trackers']] if '_trackers' in m_fw.spec else None m_launch = Launch('RESERVED', launch_dir, fworker, host, ip, trackers=trackers, launch_id=launch_id, fw_id=m_fw.fw_id) self.launches.find_and_modify({'launch_id': m_launch.launch_id}, m_launch.to_db_dict(), upsert=True) # add launch to FW m_fw.launches.append(m_launch) m_fw.state = 'RESERVED' self._upsert_fws([m_fw]) self.m_logger.debug('Reserved FW with id: {}'.format(m_fw.fw_id)) return m_fw, launch_id