def runsummary(run, debug): """Test RunSummary for given run number""" pat = '<runNumber>%s</runNumber>' % run key, cert = get_key_cert() url = 'https://cmswbm.web.cern.ch/cmswbm/cmsdb/servlet/RunSummary?' url += 'RUN=%s&DB=cms_omds_lb&FORMAT=XML' % run data = get_data(url, key, cert, debug) for line in data.read().split('\n'): if line == pat: return pat
def runsummary(run, debug): """Test RunSummary for given run number""" pat = "<runNumber>%s</runNumber>" % run key, cert = get_key_cert() url = "https://cmswbm.web.cern.ch/cmswbm/cmsdb/servlet/RunSummary?" url += "RUN=%s&DB=cms_omds_lb&FORMAT=XML" % run data = get_data(url, key, cert, debug) for line in data.read().split("\n"): if line == pat: return pat
def apicall(self, dasquery, url, api, args, dformat, expire): """ Invoke DBS API to execute given query. Return results as a list of dict, e.g. [{'run':1,'dataset':/a/b/c'}, ...] """ # translate selection keys into ones data-service APIs provides cond = dasquery.mongo_query['spec'] args = dict(self.params) for key, value in cond.iteritems(): if isinstance(value, dict): # we got equal condition if key == 'date': if isinstance(value, list) and len(value) != 2: msg = 'RunSummary service requires 2 time stamps.' msg += 'Please use either date last XXh format or' msg += 'date in YYYYMMDD-YYYYMMDD' raise Exception(msg) args['TIME_BEGIN'] = convert_datetime(value[0]) args['TIME_END'] = convert_datetime(value[1]) else: for param in self.dasmapping.das2api(self.name, key): args[param] = value elif key == 'run.number' or key == 'run.run_number': minrun = None maxrun = None for oper, val in value.iteritems(): if oper == '$in': minrun = int(val[0]) maxrun = int(val[-1]) elif oper == '$lt': maxrun = int(val) - 1 elif oper == '$lte': maxrun = int(val) elif oper == '$gt': minrun = int(val) + 1 elif oper == '$gte': minrun = int(val) else: msg = 'RunSummary does not support operator %s' % oper raise Exception(msg) args['RUN_BEGIN'] = minrun args['RUN_END'] = maxrun elif key == 'date' and value.has_key('$in') and \ len(value['$in']) == 2: date1, date2 = value['$in'] args['TIME_BEGIN'] = convert_datetime(date1) args['TIME_END'] = convert_datetime(date2) else: # we got some operator, e.g. key :{'$in' : [1,2,3]} # TODO: not sure how to deal with them right now, will throw msg = 'RunSummary does not support value %s for key=%s' \ % (value, key) raise Exception(msg) if args == self.params: # no parameter is provided args['TIME_END'] = convert_datetime(time.time()) args['TIME_BEGIN'] = convert_datetime(time.time() - 24*60*60) key, cert = get_key_cert() debug = 0 if self.verbose > 1: debug = 1 try: time0 = time.time() api = self.map.keys()[0] # we only register 1 API url = self.map[api]['url'] expire = self.map[api]['expire'] msg = 'DASAbstractService::%s::getdata(%s, %s)' \ % (self.name, url, args) self.logger.info(msg) data = get_data(run_summary_url(url, args), key, cert, debug) genrows = self.parser(data, api) ctime = time.time()-time0 self.write_to_cache(\ dasquery, expire, url, api, args, genrows, ctime) except: traceback.print_exc() msg = 'Fail to process: url=%s, api=%s, args=%s' \ % (url, api, args) self.logger.warning(msg)
def apicall(self, dasquery, url, api, args, dformat, expire): """ Invoke DBS API to execute given query. Return results as a list of dict, e.g. [{'run':1,'dataset':/a/b/c'}, ...] """ # translate selection keys into ones data-service APIs provides cond = dasquery.mongo_query['spec'] args = dict(self.params) for key, value in cond.items(): if isinstance(value, dict): # we got equal condition if key == 'date': if isinstance(value, list) and len(value) != 2: msg = 'RunSummary service requires 2 time stamps.' msg += 'Please use either date last XXh format or' msg += 'date in YYYYMMDD-YYYYMMDD' raise Exception(msg) args['TIME_BEGIN'] = convert_datetime(value[0]) args['TIME_END'] = convert_datetime(value[1]) else: for param in self.dasmapping.das2api(self.name, api, key): args[param] = value elif key == 'run.number' or key == 'run.run_number': minrun = None maxrun = None for oper, val in value.items(): if oper == '$in': minrun = int(val[0]) maxrun = int(val[-1]) elif oper == '$lt': maxrun = int(val) - 1 elif oper == '$lte': maxrun = int(val) elif oper == '$gt': minrun = int(val) + 1 elif oper == '$gte': minrun = int(val) else: msg = 'RunSummary does not support operator %s' % oper raise Exception(msg) args['RUN_BEGIN'] = minrun args['RUN_END'] = maxrun elif key == 'date' and '$in' in value and \ len(value['$in']) == 2: date1, date2 = value['$in'] args['TIME_BEGIN'] = convert_datetime(date1) args['TIME_END'] = convert_datetime(date2) else: # we got some operator, e.g. key :{'$in' : [1,2,3]} # TODO: not sure how to deal with them right now, will throw msg = 'RunSummary does not support value %s for key=%s' \ % (value, key) raise Exception(msg) if args == self.params: # no parameter is provided args['TIME_END'] = convert_datetime(time.time()) args['TIME_BEGIN'] = convert_datetime(time.time() - 24*60*60) key, cert = get_key_cert() debug = 0 if self.verbose > 1: debug = 1 try: time0 = time.time() api = list(self.map.keys())[0] # we only register 1 API url = self.map[api]['url'] expire = self.map[api]['expire'] msg = 'DASAbstractService::%s::getdata(%s, %s)' \ % (self.name, url, args) self.logger.info(msg) data = get_data(run_summary_url(url, args), key, cert, debug) genrows = self.parser(data, api) ctime = time.time()-time0 self.write_to_cache(\ dasquery, expire, url, api, args, genrows, ctime) except: traceback.print_exc() msg = 'Fail to process: url=%s, api=%s, args=%s' \ % (url, api, args) self.logger.warning(msg)