def testCreateTuple3(self): """Create from a tuple""" right_now = datetime.now() crt_dict = {} crt_dict[EVENT_ATTR_REC_ID] = 2 crt_dict[EVENT_ATTR_EVENT_ID] = "Event2" crt_dict[EVENT_ATTR_TIME_OCCURRED] = right_now crt_dict[EVENT_ATTR_TIME_LOGGED] = right_now + timedelta(seconds=1) crt_dict[EVENT_ATTR_SRC_COMP] = "SC" crt_dict[EVENT_ATTR_SRC_LOC] = "SCL" crt_dict[EVENT_ATTR_SRC_LOC_TYPE] = "S" crt_dict[EVENT_ATTR_RPT_COMP] = "RC" crt_dict[EVENT_ATTR_RPT_LOC] = "RL" crt_dict[EVENT_ATTR_RPT_LOC_TYPE] = None crt_dict[EVENT_ATTR_EVENT_CNT] = None crt_dict[EVENT_ATTR_ELAPSED_TIME] = None crt_dict[EVENT_ATTR_RAW_DATA_FMT] = long("0x5445535400000001", 16) crt_dict[EVENT_ATTR_RAW_DATA] = "When in the course" in_tuple = ( crt_dict[EVENT_ATTR_REC_ID], crt_dict[EVENT_ATTR_EVENT_ID], crt_dict[EVENT_ATTR_TIME_OCCURRED], crt_dict[EVENT_ATTR_TIME_LOGGED], crt_dict[EVENT_ATTR_SRC_COMP], crt_dict[EVENT_ATTR_SRC_LOC], crt_dict[EVENT_ATTR_SRC_LOC_TYPE], crt_dict[EVENT_ATTR_RPT_COMP], crt_dict[EVENT_ATTR_RPT_LOC], crt_dict[EVENT_ATTR_RPT_LOC_TYPE], crt_dict[EVENT_ATTR_EVENT_CNT], crt_dict[EVENT_ATTR_ELAPSED_TIME], crt_dict[EVENT_ATTR_RAW_DATA_FMT], crt_dict[EVENT_ATTR_RAW_DATA], ) te1 = Event.fromDB(in_tuple) self.assertEquals(te1.get_rec_id(), 2) # Can't use any other get methods, since they will try to # load the Event from the DB is they are not set self.assertEquals(te1.event_id, crt_dict[EVENT_ATTR_EVENT_ID]) self.assertEquals(te1.time_occurred, crt_dict[EVENT_ATTR_TIME_OCCURRED]) self.assertEquals(te1.time_logged, crt_dict[EVENT_ATTR_TIME_LOGGED]) self.assertEquals(te1.src_comp, crt_dict[EVENT_ATTR_SRC_COMP]) self.assertEquals(te1.src_loc.get_location(), crt_dict[EVENT_ATTR_SRC_LOC]) self.assertEquals(te1.src_loc.get_id(), crt_dict[EVENT_ATTR_SRC_LOC_TYPE]) self.assertEquals(te1.rpt_comp, crt_dict[EVENT_ATTR_RPT_COMP]) self.assertEquals(te1.rpt_loc, None) # Couldn't create self.assertEquals(te1.event_cnt, crt_dict[EVENT_ATTR_EVENT_CNT]) self.assertEquals(te1.elapsed_time, crt_dict[EVENT_ATTR_ELAPSED_TIME]) self.assertEquals(te1.raw_data[EXT_DATA_RAW_DATA], crt_dict[EVENT_ATTR_RAW_DATA]) # No associations # Valid because has all required fields self.assertFalse(te1.is_valid()) return
def start(self): '''Start the historic monitor. Make one large query and iterate through each event that is returned passing it through the processing pipeline. A test will be made to quit if requested by the client. At the end of processing all events, a shutdown request will be submitted ''' event_q = registry.get_service(SERVICE_EVENT_Q) dbi = registry.get_service(SERVICE_DB_INTERFACE) cursor = dbi.get_connection().cursor() disp_delta = timedelta(seconds=3) disp_time = datetime.now() + disp_delta get_logger().debug('Historic query: {0}'.format(self.query)) for row in cursor.execute(self.query): # Create the event from the database and post it to the event queue e = Event.fromDB(row) event_q.put(e) # Quit executing the loop if we are supposed to shut down if self.running == False: get_logger().info('Monitor event injection thread interrupted. last recid = {0}'.format(row[0])) break # Display progress to the user cur_time = datetime.now() if cur_time >= disp_time: disp_time = cur_time + disp_delta print >>sys.stderr,'.', # If the program is still running, initiate a shutdown now that all requests have been submitted # to the processing pipeline if self.running: print >>sys.stderr registry.get_service(SERVICE_SHUTDOWN).notify()