示例#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