예제 #1
0
 def _build_tree_by_level(self, collection):
     """ method iterated thru all documents in all timetable collections and builds tree of known system state"""
     cursor = collection.find({})
     if cursor.count() == 0:
         self.logger.warning('No TimeTable Records in %s.' % str(collection))
     else:
         for document in cursor:
             obj = TimeTableEntry(document)
             tree = self.get_tree(obj.get_process_name())
             if tree is not None:
                 tree.update_node_by_process(obj.get_process_name(), obj)
             else:
                 self.logger.warning('Skipping TimeTable record for %s, as no tree is handling it.'
                                     % obj.get_process_name())
    def _search_by_level(self, collection, timestamp, unprocessed_only):
        """ method iterated thru all documents in all timetable collections and builds tree of known system state"""
        resp = dict()
        try:
            if unprocessed_only:
                query = { AbstractModel.TIMESTAMP : {'$regex': timestamp },
                          TimeTableEntry.STATE : {'$ne' : TimeTableEntry.STATE_PROCESSED }}
            else:
                query = { AbstractModel.TIMESTAMP : {'$regex': timestamp }}

            cursor = collection.find(query)
            if cursor.count() == 0:
                self.logger.warning('No TimeTable Records in %s.' % str(collection))
            else:
                for document in cursor:
                    obj = TimeTableEntry(document)
                    key = (obj.get_process_name(), obj.get_timestamp())
                    resp[key] = obj
                    print(key)
        except Exception as e:
            self.logger.error('ProcessingStatements error: %s' % str(e))
        return resp
예제 #3
0
    def _callback_timetable_record(self, process_name, timestamp, tree_node):
        """ is called from tree to create timetable record and bind it to the tree node"""
        collection = self._get_timetable_collection(process_name)
        time_record = collection.find_one({TimeTableEntry.PROCESS_NAME : process_name,
                                   AbstractModel.TIMESTAMP : timestamp})

        if time_record is None:
            time_record = TimeTableEntry()
            time_record.set_state(TimeTableEntry.STATE_EMBRYO)
            time_record.set_timestamp(timestamp)
            time_record.set_process_name(process_name)

            tr_id = self._save_time_record(process_name, time_record)
            self.logger.info('Created time-record %s, with timestamp %s for process %s' \
                             % (str(tr_id), timestamp, process_name))
        tree_node.time_record = time_record