本文整理汇总了Python中RESTInteractions.HTTPRequests.get方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPRequests.get方法的具体用法?Python HTTPRequests.get怎么用?Python HTTPRequests.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RESTInteractions.HTTPRequests
的用法示例。
在下文中一共展示了HTTPRequests.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_backendurls
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def get_backendurls(self):
self.logger.info("Querying server %s for HTCondor schedds and pool names." % self.resturi)
server = HTTPRequests(self.resthost, self.config.TaskWorker.cmscert, self.config.TaskWorker.cmskey, retry = 2)
result = server.get(self.resturi, data={'subresource':'backendurls'})[0]['result'][0]
self.pool = str(result['htcondorPool'])
self.schedds = [str(i) for i in result['htcondorSchedds']]
self.logger.info("Resulting pool %s; schedds %s" % (self.pool, ",".join(self.schedds)))
示例2: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
if self.options.task is None:
return CommandResult(2001, 'ERROR: Task option is required')
server = HTTPRequests(self.cachedinfo['Server'] + ':' + str(self.cachedinfo['Port']))
self.logger.debug('Looking up detailed postmortem of task %s' % self.cachedinfo['RequestName'])
dictresult, postmortem, reason = server.get(self.uri + self.cachedinfo['RequestName'])
if postmortem != 200:
msg = "Problem retrieving postmortem:\ninput:%s\noutput:%s\nreason:%s" % (str(self.cachedinfo['RequestName']), str(dictresult), str(reason))
return CommandResult(1, msg)
for workflow in dictresult['errors']:
self.logger.info("#%i %s" % (workflow['subOrder'], workflow['request']))
if self.options.verbose or self.options.outputfile:
self.printVerbose(workflow['details'], self.options.outputfile, os.path.join(self.requestarea, 'results', 'jobFailures.log'))
else:
self.logger.debug(" Aggregating job failures")
groupederrs = self.aggregateFailures(workflow['details'])
if not groupederrs:
self.logger.info(" No failures")
continue
self.logger.info(" List of failures and jobs per each failure: (one job could have more then one failure, one per each step)")
for hkey in groupederrs:
## removing duplicates and sort
joberrs = list(set(groupederrs[hkey]['jobs']))
joberrs.sort()
self.logger.info(' %s jobs failed with error "%s"' %(len(joberrs), groupederrs[hkey]['error']))
self.logger.info(' (%s)' %(', '.join([ str(jobid[0]) for jobid in joberrs])) )
return CommandResult(0, None)
示例3: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
server = HTTPRequests(self.serverurl, self.proxyfilename, self.proxyfilename, version=__version__)
self.logger.debug('Looking up detailed status of task %s' % self.cachedinfo['RequestName'])
user = self.cachedinfo['RequestName'].split("_")[2].split(":")[-1]
verbose = int(self.summary or self.long or self.json)
if self.idle:
verbose = 2
dictresult, status, reason = server.get(self.uri, data = { 'workflow' : self.cachedinfo['RequestName'], 'verbose': verbose })
dictresult = dictresult['result'][0] #take just the significant part
if status != 200:
msg = "Problem retrieving status:\ninput:%s\noutput:%s\nreason:%s" % (str(self.cachedinfo['RequestName']), str(dictresult), str(reason))
raise RESTCommunicationException(msg)
self.printShort(dictresult, user)
self.printPublication(dictresult)
if 'jobs' not in dictresult:
self.logger.info("\nNo jobs created yet!")
else:
# Note several options could be combined
if self.summary:
self.printSummary(dictresult)
if self.long:
self.printLong(dictresult)
if self.idle:
self.printIdle(dictresult, user)
if self.json:
self.logger.info(dictresult['jobs'])
示例4: server_info
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def server_info(subresource, server, proxyfilename, baseurl):
"""
Get relevant information about the server
"""
server = HTTPRequests(server, proxyfilename, proxyfilename, version=__version__)
dictresult, status, reason = server.get(baseurl, {'subresource' : subresource})
return dictresult['result'][0]
示例5: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
proxyfile = self.options.proxyfile if self.options.proxyfile else self.proxyfilename
server = HTTPRequests(self.serverurl, proxyfile, proxyfile, version=__version__)
self.logger.debug('Looking type for task %s' % self.cachedinfo['RequestName'])
dictresult, status, reason = server.get(self.uri, data = {'workflow': self.cachedinfo['RequestName'], 'subresource': 'type'})
self.logger.debug('Task type %s' % dictresult['result'][0])
return dictresult['result'][0]
示例6: getCountTasksByStatusAbs
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def getCountTasksByStatusAbs(self):
try:
resturi = "/crabserver/prod/task"
configreq = { 'minutes': "1000000000", 'subresource': "counttasksbystatus" }
server = HTTPRequests(self.resthost, "/data/certs/servicecert.pem", "/data/certs/servicekey.pem", retry = 2)
result = server.get(resturi, data = configreq)
return dict(result[0]['result'])
except Exception, e:
self.logger.debug("Error in getCountTasksByStatusAbs: %s"%str(e))
return []
示例7: getOutput
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def getOutput(self, job):
"""Retrieve the output of the job."""
"""
if not os.path.exists(job.inputdata.ui_working_dir):
raise CRABServerError('Workdir "%s" not found.' %
job.inputdata.ui_working_dir)
cmd = 'crab -getoutput %d -c %s' % (int(job.id) + 1,
job.inputdata.ui_working_dir)
self._send_with_retry(cmd, 'getoutput', job.backend.crab_env)
# Make output files coming from the WMS readable.
for root, _, files in os.walk(os.path.join(job.inputdata.ui_working_dir,
'res')): # Just 'res'.
for f in files:
os.chmod(os.path.join(root, f), 0644)
"""
logger.info('getting Output for job %s:%s' % (job.backend.taskname, job.backend.crabid))
inputlist = [ ('workflow', job.backend.taskname)]
inputlist.extend([('subresource', 'logs')])
inputlist.extend( [('jobids', job.backend.crabid)] )
#srv='hammer-crab3.cern.ch'# 'cmsweb-testbed.cern.ch'
#proxypath= '/afs/cern.ch/user/r/riahi/public/proxy'#'/afs/cern.ch/user/s/spiga/public/PerValentaina/proxy'
#resource='/crabserver/dev/workflow'
#server = HTTPRequests(srv, proxypath)
server = HTTPRequests(job.backend.server_name, job.backend.userproxy)
resource = job.backend.apiresource+'workflow'
try:
import sys, traceback
dictresult, status, reason = server.get(resource, data = inputlist)
input = dictresult['result']
rcopy = remoteCopy(input, job.outputdir, logger)
rcopy()
logger.info("Task: %s - subjob: %s output copied" % (job.backend.taskname, job.backend.crabid))
tfile = tarfile.open(os.path.join(job.outputdir, "cmsRun_%s.log.tar.gz" % job.backend.crabid))
tfile.extractall(job.outputdir)
except HTTPException, e:
msg = type(e)
msg += " "+dir(e)
msg += " "+e.req_headers
msg += " "+e.req_data
msg += " "+e.reason
msg += " "+e.message
msg += " "+e.headers
msg += " "+e.result
msg += " "+e.status
msg += " "+e.url
msg += " "+e.args
logger.error(msg)
示例8: getCountTasksByStatusAbs
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def getCountTasksByStatusAbs(self):
try:
resturi = "/crabserver/prod/task"
configreq = {'minutes': "1000000000", 'subresource': "counttasksbystatus"}
server = HTTPRequests(self.resthost, "/data/certs/servicecert.pem", "/data/certs/servicekey.pem", retry=10)
result = server.get(resturi, data=configreq)
return dict(result[0]['result'])
except Exception:
e = sys.exc_info()
if hasattr(e,"headers"):
self.logger.error(str(e.headers))
self.logger.exception("Error in getCountTasksByStatusAbs:")
pprint(e[1])
traceback.print_tb(e[2])
return []
示例9: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self, **argv):
#Setting default destination if -o is not provided
if not self.dest:
self.dest = os.path.join(self.requestarea, 'results')
#Creating the destination directory if necessary
if not os.path.exists( self.dest ):
self.logger.debug("Creating directory %s " % self.dest)
os.makedirs( self.dest )
elif not os.path.isdir( self.dest ):
raise ConfigurationException('Destination directory is a file')
self.logger.info("Setting the destination directory to %s " % self.dest )
#Retrieving output files location from the server
self.logger.debug('Retrieving locations for task %s' % self.cachedinfo['RequestName'] )
inputlist = [ ('workflow', self.cachedinfo['RequestName']) ]
inputlist.extend(list(argv.iteritems()))
if getattr(self.options, 'quantity', None):
self.logger.debug('Retrieving %s file locations' % self.options.quantity )
inputlist.append( ('limit',self.options.quantity) )
if getattr(self.options, 'jobids', None):
self.logger.debug('Retrieving jobs %s' % self.options.jobids )
inputlist.extend( self.options.jobids )
server = HTTPRequests(self.serverurl, self.proxyfilename, self.proxyfilename, version=__version__)
dictresult, status, reason = server.get(self.uri, data = inputlist)
self.logger.debug('Server result: %s' % dictresult )
dictresult = self.processServerResult(dictresult)
if status != 200:
msg = "Problem retrieving information from the server:\ninput:%s\noutput:%s\nreason:%s" % (str(inputlist), str(dictresult), str(reason))
raise ConfigurationException(msg)
totalfiles = len( dictresult['result'] )
cpresults = []
# for workflow in dictresult['result']: TODO re-enable this when we will have resubmissions
workflow = dictresult['result'] #TODO assigning workflow to dictresult. for the moment we have only one wf
arglist = ['-d', self.dest, '-i', workflow, '-t', self.options.task, '-p', self.proxyfilename]
if len(workflow) > 0:
self.logger.info("Retrieving %s files" % totalfiles )
copyoutput = remote_copy( self.logger, arglist )
copyoutput()
if totalfiles == 0:
self.logger.info("No files to retrieve")
示例10: getOutput
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def getOutput(self, job):
"""Retrieve the output of the job."""
"""
if not os.path.exists(job.inputdata.ui_working_dir):
raise CRABServerError('Workdir "%s" not found.' %
job.inputdata.ui_working_dir)
cmd = 'crab -getoutput %d -c %s' % (int(job.id) + 1,
job.inputdata.ui_working_dir)
self._send_with_retry(cmd, 'getoutput', job.backend.crab_env)
# Make output files coming from the WMS readable.
for root, _, files in os.walk(os.path.join(job.inputdata.ui_working_dir,
'res')): # Just 'res'.
for f in files:
os.chmod(os.path.join(root, f), 0644)
"""
logger.info('geting Output for jon %s:%s' % (job.backend.taskname, job.backend.crabid))
inputlist = [ ('workflow', job.backend.taskname)]
inputlist.extend([('subresource', 'logs')])
inputlist.extend( [('jobids', job.backend.crabid)] )
#srv='hammer-crab3.cern.ch'# 'cmsweb-testbed.cern.ch'
#proxypath= '/afs/cern.ch/user/r/riahi/public/proxy'#'/afs/cern.ch/user/s/spiga/public/PerValentaina/proxy'
#resource='/crabserver/dev/workflow'
#server = HTTPRequests(srv, proxypath)
server = HTTPRequests(job.backend.server_name, job.backend.userproxy)
resource = job.backend.apiresource+'workflow'
try:
dictresult, status, reason = server.get(resource, data = inputlist)
except HTTPException, e:
print type(e)
print dir(e)
print e.req_headers
print e.req_data
print e.reason
print e.message
print e.headers
print e.result
print e.status
print e.url
print e.args
示例11: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
server = HTTPRequests(self.serverurl, self.proxyfilename, self.proxyfilename, version=__version__)
self.logger.debug('Looking up report for task %s' % self.cachedinfo['RequestName'])
dictresult, status, reason = server.get(self.uri, data = {'workflow': self.cachedinfo['RequestName'], 'subresource': 'report'})
self.logger.debug("Result: %s" % dictresult)
if status != 200:
msg = "Problem retrieving report:\ninput:%s\noutput:%s\nreason:%s" % (str(self.cachedinfo['RequestName']), str(dictresult), str(reason))
raise RESTCommunicationException(msg)
if not dictresult['result'][0]['runsAndLumis'] :
self.logger.info('No jobs finished yet. Report is available when jobs complete')
return
runlumiLists = map(lambda x: literal_eval(x['runlumi']), dictresult['result'][0]['runsAndLumis'].values())
#convert lumi lists from strings to integers
for runlumi in runlumiLists:
for run in runlumi:
runlumi[run] = map(int, runlumi[run])
analyzed, diff, doublelumis = BasicJobType.mergeLumis(runlumiLists, dictresult['result'][0]['lumiMask'])
numFiles = len(reduce(set().union, map(lambda x: literal_eval(x['parents']), dictresult['result'][0]['runsAndLumis'].values())))
self.logger.info("%d files have been read" % numFiles)
self.logger.info("%d events have been read" % sum(map(lambda x: x['events'], dictresult['result'][0]['runsAndLumis'].values())))
if self.outdir:
jsonFileDir = self.outdir
else:
jsonFileDir = os.path.join(self.requestarea, 'results')
if analyzed:
with open(os.path.join(jsonFileDir, 'analyzed.json'), 'w') as jsonFile:
json.dump(analyzed, os.path.join(jsonFile))
jsonFile.write("\n")
self.logger.info("Analyzed lumi written to %s/analyzed.json" % jsonFileDir)
if diff:
with open(os.path.join(jsonFileDir, 'diff.json'), 'w') as jsonFile:
json.dump(diff, jsonFile)
jsonFile.write("\n")
self.logger.info("%sNot Analyzed lumi written to %s/diff.json%s" % (colors.RED, jsonFileDir, colors.NORMAL))
if doublelumis:
with open(os.path.join(jsonFileDir, 'double.json'), 'w') as jsonFile:
json.dump(doublelumis, jsonFile)
jsonFile.write("\n")
self.logger.info("%sDouble lumis written to %s/double.json%s" % (colors.RED, jsonFileDir, colors.NORMAL))
示例12: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
server = HTTPRequests(self.serverurl, self.proxyfilename, self.proxyfilename, version=__version__)
dictresult, status, reason = server.get(self.uri, data={"timestamp": self.date})
dictresult = dictresult["result"] # take just the significant part
if status != 200:
msg = "Problem retrieving tasks:\ninput:%s\noutput:%s\nreason:%s" % (
str(self.date),
str(dictresult),
str(reason),
)
raise RESTCommunicationException(msg)
dictresult.sort()
dictresult.reverse()
if self.options.status:
dictresult = [item for item in dictresult if item[1] == self.options.status]
result = [item[0:2] for item in dictresult]
today = date.today()
if not dictresult:
msg = "No tasks found from %s until %s" % (self.date, today)
if self.options.status:
msg += " with status %s" % (self.options.status)
self.logger.info(msg)
return result
msg = "\nList of tasks from %s until %s" % (self.date, today)
if self.options.status:
msg += " with status %s" % (self.options.status)
self.logger.info(msg)
self.logger.info("=" * 80)
self.logger.info("NAME\t\t\t\t\t\t\t\tSTATUS")
self.logger.info("=" * 80)
for item in dictresult:
name, status = item[0:2]
self.logger.info("%s\n\t\t\t\t\t\t\t\t%s" % (name, status))
self.logger.info("-" * 80)
self.logger.info("\n")
return result
示例13: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
server = HTTPRequests(self.serverurl, self.proxyfilename, self.proxyfilename, version=__version__)
self.logger.debug('Looking up detailed status of task %s' % self.cachedinfo['RequestName'])
dictresult, status, reason = server.get(self.uri, data = { 'workflow' : self.cachedinfo['RequestName']})
dictresult = dictresult['result'][0] #take just the significant part
if status != 200:
msg = "Problem retrieving status:\ninput:%s\noutput:%s\nreason:%s" % (str(self.cachedinfo['RequestName']), str(dictresult), str(reason))
raise RESTCommunicationException(msg)
self.logger.debug(dictresult) #should be something like {u'result': [[123, u'ciao'], [456, u'ciao']]}
self.logger.info("Task name:\t\t\t%s" % self.cachedinfo['RequestName'])
self.logger.info("Task status:\t\t\t%s" % dictresult['status'])
def logJDefErr(jdef):
"""Printing job def failures if any"""
if jdef['jobdefErrors']:
self.logger.error("%sFailed to inject %s\t%s out of %s:" %(colors.RED, colors.NORMAL,\
jdef['failedJobdefs'], jdef['totalJobdefs']))
for error in jdef['jobdefErrors']:
self.logger.info("\t%s" % error)
#Print the url of the panda monitor
if dictresult['taskFailureMsg']:
self.logger.error("%sError during task injection:%s\t%s" % (colors.RED,colors.NORMAL,dictresult['taskFailureMsg']))
# We might also have more information in the job def errors
logJDefErr(jdef=dictresult)
elif dictresult['jobSetID']:
username = urllib.quote(getUserName(self.logger))
self.logger.info("Panda url:\t\t\thttp://pandamon-cms-dev.cern.ch/jobinfo?jobtype=*&jobsetID=%s&prodUserName=%s" % (dictresult['jobSetID'], username))
# We have cases where the job def errors are there but we have a job def id
logJDefErr(jdef=dictresult)
#Print information about jobs
states = dictresult['jobsPerStatus']
total = sum( states[st] for st in states )
frmt = ''
for status in states:
frmt += status + ' %s\t' % self._percentageString(states[status], total)
if frmt:
self.logger.info('Details:\t\t\t%s' % frmt)
示例14: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
server = HTTPRequests(self.serverurl, self.proxyfilename, self.proxyfilename, version=__version__)
dictresult, status, reason = server.get(self.uri, data = {'timestamp': self.date})
dictresult = dictresult['result'] #take just the significant part
if status != 200:
msg = "Problem retrieving tasks:\ninput:%s\noutput:%s\nreason:%s" % (str(self.date), str(dictresult), str(reason))
raise RESTCommunicationException(msg)
dictresult.sort()
dictresult.reverse()
if self.options.status:
dictresult = [item for item in dictresult if item[1] == self.options.status]
result = [item[0:2] for item in dictresult]
today = date.today()
if not dictresult:
msg = "No tasks found from %s until %s" % (self.date, today)
if self.options.status:
msg += " with status %s" % (self.options.status)
self.logger.info(msg)
return result
msg = "\nList of tasks from %s until %s" % (self.date, today)
if self.options.status:
msg += " with status %s" % (self.options.status)
self.logger.info(msg)
msg = "Beware that STATUS here does not include information from grid jobs"
self.logger.info(msg)
self.logger.info('='*80)
self.logger.info('NAME\t\t\t\t\t\t\t\tSTATUS')
self.logger.info('='*80)
for item in dictresult:
name, status = item[0:2]
self.logger.info('%s\n\t\t\t\t\t\t\t\t%s' % (name, status))
self.logger.info('-'*80)
self.logger.info('\n')
return result
示例15: __call__
# 需要导入模块: from RESTInteractions import HTTPRequests [as 别名]
# 或者: from RESTInteractions.HTTPRequests import get [as 别名]
def __call__(self):
server = HTTPRequests(self.serverurl, self.proxyfilename, self.proxyfilename, version=__version__)
dictresult, status, reason = server.get(self.uri, data = { 'timestamp' : self.date })
dictresult = dictresult['result'] #take just the significant part
dictresult.sort()
dictresult.reverse()
today = date.today()
self.logger.info ('\n')
self.logger.info ('The list of tasks from %s until %s' %(self.date, today))
self.logger.info ('='*80)
self.logger.info ('NAME\t\t\t\t\t\t\t\tSTATUS')
self.logger.info ('='*80)
for item in dictresult:
name, status = item[0:2]
self.logger.info ('%s\n\t\t\t\t\t\t\t\t%s' %(name, status))
self.logger.info ('-'*80)
self.logger.info ('\n')