def set(self, pckt, time): """Write values to a statefile.""" self.logger.debug("set %s to %s" % (self.filename, pckt)) if not self.filename: return self.packet = pckt self.time = time self.strtime = stock.strlocalydtime(time).strip() self.latency = stock.strtdelta(stock.now() - time).strip() # self.logger.debug( 'latency: %s' % self.latency ) try: self.pointer.seek(0) self.pointer.write( "%s\n%s\n%s\n%s\n%s\n" % (self.packet, self.time, self.strtime, self.latency, self.pid) ) except Exception as e: raise stateFileException( "Problems while writing to state file: %s %s" % (self.file, e) )
def _extract_request(self, request): net = request.args.get('net', [None]) sta = request.args.get('sta', [None])[0] chan_args = request.args.get('chan', []) time_window = float(request.args.get('tw', [0])[0]) time_start = float(request.args.get('ts', [-1])[0]) time_end = float(request.args.get('te', [-1])[0]) availability = request.args.get('availability', [False])[0] canvas_size = request.args.get('canvas_size', [config.canvas_size_default])[0] chans = list(set([chan.upper() for chan in chan_args])) if not chans: chans = list(config.default_chans) chans.sort() if config.verbose: print "Received request for:" print "\tnet:\t%s" % net print "\tsta:\t%s" % sta print "\tchans:\t%s" % str(chans) print "\ttime_window:\t%s" % stock.strtdelta(time_window) print "\ttime_start:\t%s" % stock.strtime(time_start) print "\ttime_end:\t%s" % stock.strtime(time_end) print "\tavailability:\t%s" % str(availability) print "\tcanvas_size:\t%d" % canvas_size return net, sta, chans, time_window, time_start, time_end, availability, canvas_size
def set(self, pckt, time): if not self.filename: return self.packet = pckt self.time = time self.strtime = stock.strlocalydtime(time).strip() self.latency = stock.strtdelta( stock.now()-time ).strip() #self.logging.debug( 'Orb latency: %s' % self.latency ) try: self.pointer.seek(0) self.pointer.write( '%s\n%s\n%s\n%s\n%s\n' % \ (self.packet,self.time,self.strtime,self.latency,self.pid) ) except Exception, e: raise pocException( 'Problems while writing to state file: %s %s' % (self.file,e) )
def _extract_data(self): """Look for all poc packets.""" self.orb["last_check"] = stock.now() if self.errors > MAX_EXTRACT_ERRORS: raise TooManyExtractError("10 consecutive errors on orb.reap()") try: self.poc.new(self.orb["orb"].reap(self.reap_wait)) except orb.OrbIncompleteException: self.logging.debug("OrbIncompleteException orb.reap(%s)" % self.orbname) return True except Exception as e: self.logging.warning("%s Exception in orb.reap(%s) [%s]" % (Exception, self.orbname, e)) self.errors += 1 return False else: # reset error counter self.errors = 0 # save ORB id to state file self.state.set(self.poc.id, self.poc.time) if self.poc.valid: self.logging.info("%s" % self.poc) # we print this on the statusFile class too... self.logging.debug("orblatency %s" % (stock.strtdelta(stock.now() - self.poc.time))) self.position = self.poc.id self.logging.debug("orbposition %s" % self.position) self.orb["last_success"] = stock.now() self._update_collection() return True
def _extract_data(self): """Reap data from orb packets.""" self.orb["last_check"] = stock.now() if self.errors > MAX_EXTRACT_ERRORS: raise TooManyOrbExtractErrors( "%s consecutive errors on orb.reap()" % MAX_EXTRACT_ERRORS) try: # REAP new packet from ORB # Squelch RuntimeWarnings from the Antelope layer with warnings.catch_warnings(): warnings.simplefilter("ignore") pktbuf = self.orb["orb"].reap(self.reap_wait) # Extract packet into our internal object self.packet.new(pktbuf) except orb.OrbIncompleteException as e: self.logger.debug("Caught OrbIncompleteException: " + str(e), exc_info=True) self.errors = 0 return True except stock.PfException: self.logger.exception("Couldn't read from pf packet.") self.error += 1 return False except Exception: self.logger.exception( "Unknown Exception occurred while extracting data(%s)" % (self.orbname)) self.errors += 1 return False self.logger.debug("_extract_data(%s,%s)" % (self.packet.id, self.packet.time)) # reset error counter self.errors = 0 if not self.packet.id or not self.packet.valid: self.logger.debug("_extract_data() => Not a valid packet") return False # save ORB id to state file self.state.set(self.packet.id, self.packet.time) self.logger.debug("errors:%s" % self.errors) if self.packet.valid: self.logger.debug("%s" % self.packet) # we print this on the statusFile class too... self.logger.debug( "orblatency %s" % (stock.strtdelta(stock.now() - self.packet.time))) self.position = self.packet.id self.logger.debug("orbposition %s" % self.position) self.orb["last_success"] = stock.now() self._update_collection() else: self.logger.debug("invalid packet: %s %s" % (self.packet.id, self.packet.srcname)) return False return True
def _extract_request(self, request): #{{{ type = request.args.get('type', [None])[0] net_args = request.args.get('net', None) sta_args = request.args.get('sta', None) orid = request.args.get('orid', [None])[0] availability= request.args.get('availability',[None])[0] orid_time = request.args.get('orid_time', [None])[0] time_start = request.args.get('ts', [None])[0] time_end = request.args.get('te', [None])[0] chan_args = request.args.get('chan', config.default_chans) time_window = request.args.get('tw', [config.default_time_window])[0] canvas_size = request.args.get('canvas_size', [config.canvas_size_default])[0] amount = request.args.get('amount', [None])[0] filter = request.args.get('filter', [None])[0] phases = request.args.get('phases', None) if net_args: net = list(set([n.upper() for n in net_args])) net.sort() else: net = None if sta_args: sta = list(set([s.upper() for s in sta_args])) sta.sort() else: sta = None chan = list(set([c.upper() for c in chan_args])) chan.sort() if time_start: time_start = float(time_start) if time_end: time_end = float(time_end) if time_window: time_window = float(time_window) if orid: try: orid = int(orid) except: orid = False if canvas_size: canvas_size = int(canvas_size) if config.verbose: log.msg("Received request for:") log.msg("\ttype:\t%s" % type) log.msg("\tnet:\t%s" % str(net)) log.msg("\tsta:\t%s" % str(sta)) log.msg("\torid:\t%s" % orid) log.msg("\toridtime:\t%s" % orid_time) log.msg("\tchan:\t%s" % str(chan)) log.msg("\ttime_window:\t%s" % stock.strtdelta(time_window)) log.msg("\ttime_start:\t%s" % time_start) log.msg("\ttime_end:\t%s" % time_end) log.msg("\tavailability:\t%s" % str(availability)) log.msg("\tcanvas_size:\t%d" % canvas_size) log.msg("\tamount:\t%s" % amount) log.msg("\tfilter:\t%s" % filter) log.msg("\tphases:\t%s" % phases) return type, net, sta, orid, chan, orid_time, time_window, time_start, time_end, availability, canvas_size, amount, filter, phases
return True except Exception,e: self.logging.warning("%s Exception in orb.reap(%s) [%s]" % (Exception,self.orbname,e)) self.errors += 1 return False else: # reset error counter self.errors = 0 # save ORB id to state file self.state.set(self.poc.id,self.poc.time) if self.poc.valid: self.logging.info( '%s' % self.poc ) # we print this on the statusFile class too... self.logging.debug( 'orblatency %s' % \ ( stock.strtdelta( stock.now() - self.poc.time ) ) ) self.position = self.poc.id self.logging.debug( 'orbposition %s' % self.position ) self.orb['last_success'] = stock.now() self._update_collection() return True def _update_collection(self): self.logging.info( 'update_collection()' ) # Verify if we need to update MongoDB if self.poc.valid: self.logging.debug('collection.update(%s)' % self.poc.sn)
self.errors = 0 if not self.packet.id or not self.packet.valid: self.logging.debug("_extract_data() => Not a valid packet" ) return False # save ORB id to state file self.state.set(self.packet.id,self.packet.time) self.logging.debug( 'errors:%s' % self.errors ) if self.packet.valid: self.logging.debug( '%s' % self.packet ) # we print this on the statusFile class too... self.logging.debug( 'orblatency %s' % \ ( stock.strtdelta( stock.now() - self.packet.time ) ) ) self.position = self.packet.id self.logging.debug( 'orbposition %s' % self.position ) self.orb['last_success'] = stock.now() self._update_collection() else: self.logging.debug( 'invalid packet: %s %s' % (self.packet.id, self.packet.srcname) ) return True def _update_collection(self): self.logging.debug( 'update_collection()' ) # Verify if we need to update MongoDB