def POST(self, *args): raw_crash, dumps = self._get_raw_crash_from_form() current_timestamp = utc_now() raw_crash.submitted_timestamp = current_timestamp.isoformat() # legacy - ought to be removed someday raw_crash.timestamp = time.time() if (not self.config.accept_submitted_crash_id or 'crash_id' not in raw_crash ): crash_id = createNewOoid(current_timestamp) raw_crash.crash_id = crash_id self.logger.info('%s received', crash_id) else: crash_id = raw_crash.crash_id self.logger.info('%s received with existing crash_id:', crash_id) raw_crash.type_tag = self.type_tag self.crash_storage.save_raw_crash( raw_crash, dumps, crash_id ) self.logger.info('%s accepted', crash_id) return "CrashID=%s%s\n" % (self.type_tag, crash_id)
def POST(self, *args): raw_crash, dumps = self._get_raw_crash_from_form() current_timestamp = utc_now() raw_crash.submitted_timestamp = current_timestamp.isoformat() # legacy - ought to be removed someday raw_crash.timestamp = time.time() if (not self.accept_submitted_crash_id or 'uuid' not in raw_crash): crash_id = createNewOoid(current_timestamp) raw_crash.uuid = crash_id self.logger.info('%s received', crash_id) else: crash_id = raw_crash.uuid self.logger.info('%s received with existing crash_id:', crash_id) if ('legacy_processing' not in raw_crash or not self.accept_submitted_legacy_processing): raw_crash.legacy_processing, raw_crash.throttle_rate = ( self.throttler.throttle(raw_crash)) else: raw_crash.legacy_processing = int(raw_crash.legacy_processing) if raw_crash.legacy_processing == DISCARD: self.logger.info('%s discarded', crash_id) return "Discarded=1\n" if raw_crash.legacy_processing == IGNORE: self.logger.info('%s ignored', crash_id) return "Unsupported=1\n" raw_crash.type_tag = self.dump_id_prefix.strip('-') self.crash_storage.save_raw_crash(raw_crash, dumps, crash_id) self.logger.info('%s accepted', crash_id) return "CrashID=%s%s\n" % (self.dump_id_prefix, crash_id)
def setUp(self): self.baseDate = dt.datetime(2008, 12, 25, tzinfo=UTC) self.rawuuids = [] self.yyyyoids = [] self.dyyoids = [] self.depths = [4, 4, 3, 3, 3, 2, 2, 2, 1, 1] self.badooid0 = "%s%s" % (str(uu.uuid4())[:-8], 'ffeea1b2') self.badooid1 = "%s%s" % (str(uu.uuid4())[:-8], 'f3eea1b2') for i in range(10): self.rawuuids.append(str(uu.uuid4())) assert len(self.depths) == len(self.rawuuids) for i in self.rawuuids: self.yyyyoids.append("%s%4d%02d%02d" % (i[:-8], self.baseDate.year, self.baseDate.month, self.baseDate.day)) for i in range(len(self.rawuuids)): self.dyyoids.append( "%s%d%02d%02d%02d" % (self.rawuuids[i][:-7], self.depths[i], self.baseDate.year % 100, self.baseDate.month, self.baseDate.day)) today = utc_now() self.nowstamp = dt.datetime(today.year, today.month, today.day, tzinfo=UTC) self.xmas05 = dt.datetime(2005, 12, 25, tzinfo=UTC)
def _current_slot(self): now = utc_now() return [ "%02d" % now.hour, "%02d_%02d" % (now.minute, now.second // self.config.minute_slice_interval) ]
def test_utc_now(): """ Test datetimeutil.utc_now() """ res = datetimeutil.utc_now() eq_(res.strftime('%Z'), 'UTC') eq_(res.strftime('%z'), '+0000') ok_(res.tzinfo)
def _get_base(self, crash_id): """this method overrides the base method to define the daily file system root directory name. While the default class is to use a YYYYMMDD form, this class substitutes a simple DD form. This is the mechanism of directory recycling as at the first day of a new month we return to the same directiory structures that were created on the first day of the previous month""" date = dateFromOoid(crash_id) if not date: date = utc_now() date_formatted = "%02d" % (date.day,) return [self.config.fs_root, date_formatted]
def createNewOoid(timestamp=None, depth=None): """Create a new Ooid for a given time, to be stored at a given depth timestamp: the year-month-day is encoded in the ooid. If none, use current day depth: the expected storage depth is encoded in the ooid. If non, use the defaultDepth returns a new opaque id string holding 24 random hex digits and encoded date and depth info """ if not timestamp: timestamp = utc_now().date() if not depth: depth = defaultDepth assert depth <= 4 and depth >=1 uuid = str(uu.uuid4()) return "%s%d%02d%02d%02d" %(uuid[:-7],depth,timestamp.year%100,timestamp.month,timestamp.day)
def uuidToOoid(uuid,timestamp=None, depth= None): """ Create an ooid from a 32-hex-digit string in regular uuid format. uuid: must be uuid in expected format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxx7777777 timestamp: the year-month-day is encoded in the ooid. If none, use current day depth: the expected storage depth is encoded in the ooid. If non, use the defaultDepth returns a new opaque id string holding the first 24 digits of the provided uuid and encoded date and depth info """ if not timestamp: timestamp = utc_now().date() if not depth: depth = defaultDepth assert depth <= 4 and depth >=1 return "%s%d%02d%02d%02d" %(uuid[:-7],depth,timestamp.year%100,timestamp.month,timestamp.day)
def createNewOoid(timestamp=None, depth=None): """Create a new Ooid for a given time, to be stored at a given depth timestamp: the year-month-day is encoded in the ooid. If none, use current day depth: the expected storage depth is encoded in the ooid. If non, use the defaultDepth returns a new opaque id string holding 24 random hex digits and encoded date and depth info """ if not timestamp: timestamp = utc_now().date() if not depth: depth = defaultDepth assert depth <= 4 and depth >= 1 uuid = str(uu.uuid4()) return "%s%d%02d%02d%02d" % (uuid[:-7], depth, timestamp.year % 100, timestamp.month, timestamp.day)
def uuidToOoid(uuid, timestamp=None, depth=None): """ Create an ooid from a 32-hex-digit string in regular uuid format. uuid: must be uuid in expected format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxx7777777 timestamp: the year-month-day is encoded in the ooid. If none, use current day depth: the expected storage depth is encoded in the ooid. If non, use the defaultDepth returns a new opaque id string holding the first 24 digits of the provided uuid and encoded date and depth info """ if not timestamp: timestamp = utc_now().date() if not depth: depth = defaultDepth assert depth <= 4 and depth >= 1 return "%s%d%02d%02d%02d" % (uuid[:-7], depth, timestamp.year % 100, timestamp.month, timestamp.day)
def _get_base(self, crash_id): """Overrides the base method to define the daily file system root directory name. While the default class uses a YYYYMMDD form, this class substitutes a simple DD form. This is the mechanism of directory recycling as at the first day of a new month we return to the same directiory structures that were created on the first day of the previous month. """ date = dateFromOoid(crash_id) if not date: date = utc_now() date_formatted = "%02d" % (date.day, ) return [self.config.fs_root, date_formatted]
def POST(self, *args): raw_crash, dumps = self._get_raw_crash_from_form() current_timestamp = utc_now() raw_crash.submitted_timestamp = current_timestamp.isoformat() # legacy - ought to be removed someday raw_crash.timestamp = time.time() if (not self.accept_submitted_crash_id or 'uuid' not in raw_crash): crash_id = createNewOoid(current_timestamp) raw_crash.uuid = crash_id self.logger.info('%s received', crash_id) else: crash_id = raw_crash.uuid self.logger.info('%s received with existing crash_id:', crash_id) if ('legacy_processing' not in raw_crash or not self.accept_submitted_legacy_processing ): raw_crash.legacy_processing, raw_crash.throttle_rate = ( self.throttler.throttle(raw_crash) ) else: raw_crash.legacy_processing = int(raw_crash.legacy_processing) if raw_crash.legacy_processing == DISCARD: self.logger.info('%s discarded', crash_id) return "Discarded=1\n" if raw_crash.legacy_processing == IGNORE: self.logger.info('%s ignored', crash_id) return "Unsupported=1\n" raw_crash.type_tag = self.dump_id_prefix.strip('-') self.crash_storage.save_raw_crash( raw_crash, dumps, crash_id ) self.logger.info('%s accepted', crash_id) return "CrashID=%s%s\n" % (self.dump_id_prefix, crash_id)
def setUp(self): self.baseDate = dt.datetime(2008,12,25, tzinfo=UTC) self.rawuuids = [] self.yyyyoids = [] self.dyyoids = [] self.depths = [4,4,3,3,3,2,2,2,1,1] self.badooid0 = "%s%s" %(str(uu.uuid4())[:-8],'ffeea1b2') self.badooid1 = "%s%s" %(str(uu.uuid4())[:-8],'f3eea1b2') for i in range(10): self.rawuuids.append(str(uu.uuid4())) assert len(self.depths) == len(self.rawuuids) for i in self.rawuuids: self.yyyyoids.append("%s%4d%02d%02d" % (i[:-8],self.baseDate.year,self.baseDate.month,self.baseDate.day)) for i in range(len(self.rawuuids)): self.dyyoids.append("%s%d%02d%02d%02d" %(self.rawuuids[i][:-7],self.depths[i],self.baseDate.year%100,self.baseDate.month,self.baseDate.day)) today = utc_now() self.nowstamp = dt.datetime(today.year,today.month,today.day,tzinfo=UTC) self.xmas05 = dt.datetime(2005,12,25,tzinfo=UTC)
def POST(self, *args): raw_crash, dumps = self._get_raw_crash_from_form() current_timestamp = utc_now() raw_crash.submitted_timestamp = current_timestamp.isoformat() # legacy - ought to be removed someday raw_crash.timestamp = time.time() if (not self.config.accept_submitted_crash_id or 'crash_id' not in raw_crash): crash_id = createNewOoid(current_timestamp) raw_crash.crash_id = crash_id self.logger.info('%s received', crash_id) else: crash_id = raw_crash.crash_id self.logger.info('%s received with existing crash_id:', crash_id) raw_crash.type_tag = self.type_tag self.crash_storage.save_raw_crash(raw_crash, dumps, crash_id) self.logger.info('%s accepted', crash_id) return "CrashID=%s%s\n" % (self.type_tag, crash_id)
def _get_base(self, crash_id): date = dateFromOoid(crash_id) if not date: date = utc_now() date_formatted = "%4d%02d%02d" % (date.year, date.month, date.day) return [self.config.fs_root, date_formatted]
def _get_current_date(self): date = utc_now() return "%02d" % date.day
def _current_slot(self): now = utc_now() return ["%02d" % now.hour, "%02d_%02d" % (now.minute, now.second // self.config.minute_slice_interval)]
def _get_current_date(self): date = utc_now() return "%02d%02d%02d" % (date.year, date.month, date.day)