本文整理汇总了Python中WMCore.Services.Requests.JSONRequests类的典型用法代码示例。如果您正苦于以下问题:Python JSONRequests类的具体用法?Python JSONRequests怎么用?Python JSONRequests使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSONRequests类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getRequestInfo
def getRequestInfo():
requestName = sys.argv[1]
print "Getting information from cmsweb about %s... %s" % (requestName, time.strftime('%H:%M:%S'))
requestor = JSONRequests(url = 'https://cmsweb.cern.ch/reqmgr/reqMgr')
response = requestor.get('/request?requestName=%s' % requestName)
if response[1] != 200:
raise RuntimeError("Request information was not available!")
requestDict = response[0]
#print requestDict.get('RunWhitelist')
#print requestDict.get('RunBlacklist')
if not requestDict.get('RunWhitelist'):
requestDict['RunWhitelist'] = []
if not requestDict.get('RunBlacklist'):
requestDict['RunBlacklist'] = []
if not requestDict.get('BlockWhitelist'):
requestDict['BlockWhitelist'] = []
if not requestDict.get('BlockBlacklist'):
requestDict['BlockBlacklist'] = []
compactRequest = {'InputDataset' : requestDict['InputDataset'],
'RunWhitelist' : requestDict['RunWhitelist'],
'RunBlacklist' : requestDict['RunBlacklist'],
'BlockWhitelist' : requestDict['BlockWhitelist'],
'BlockBlacklist' : requestDict['BlockBlacklist'],
'OutputDatasets' : []}
response = requestor.get('/outputDatasetsByRequestName?requestName=%s' % requestName)
if response[1] != 200:
raise RuntimeError("Output dataset information was not available!")
compactRequest['OutputDatasets'] = response[0]
print "Done querying cmsweb... %s" % time.strftime('%H:%M:%S')
return compactRequest
示例2: __init__
def __init__(self, url = 'http://localhost:5984', usePYCurl = False, ckey = None, cert = None, capath = None):
"""
Initialise requests
"""
JSONRequests.__init__(self, url, {"cachepath" : None, "pycurl" : usePYCurl, "key" : ckey, "cert" : cert, "capath" : capath})
self.accept_type = "application/json"
self["timeout"] = 600
示例3: assignRequest
def assignRequest(self,url,workflow,team,site,args={}):
params = {"action": "Assign",
"Team"+team: "checked",
"SiteWhitelist": [],
"SiteBlacklist": [],
"MergedLFNBase": "/store/user",
"UnmergedLFNBase": "/store/temp/user",
"MinMergeSize": 1,
"MaxMergeSize": 1,
"MaxMergeEvents": 50000,
#"AcquisitionEra": era,
"maxRSS": 4294967296,
"maxVSize": 4294967296,
"dashboard": "CMSYAATAnalysis",
"checkbox"+workflow: "checked"}
request = JSONRequests(url)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
request.post("/reqmgr/assign/handleAssignmentPage", params, headers)
(data, status, reason, _) = request.getresponse()
if status != 200:
self.debugHttpError(data, status, reason)
raise RuntimeError, "POST failed with code %s" % status
self.logger.info("Assigned the workflow %s" % workflow)
示例4: decodeJson
def decodeJson(self, result):
"""
decodeJson
decode the response result reveiced from the server
"""
encoder = JSONRequests(idict={"pycurl" : True})
return encoder.decode(result)
示例5: decodeJson
def decodeJson(self, result):
"""
decodeJson
decode the response result reveiced from the server
"""
encoder = JSONRequests()
return encoder.decode(result)
示例6: wmbsServiceSetup
def wmbsServiceSetup(self, argstring, kargs={}, returnType="text"):
if returnType == "json":
request = JSONRequests(self.server_url)
else:
request = Requests(self.server_url)
results = request.get("/wmbs/%s/" % argstring, kargs)
return results
示例7: approveRequest
def approveRequest(self, url,workflow):
params = {"requestName": workflow, "status": "assignment-approved"}
request = JSONRequests(url)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
request.put("/reqmgr/reqMgr/request", params, headers)
(data, status, reason, _) = request.getresponse()
if status != 200:
self.debugHttpError(data, status, reason)
raise RuntimeError, "PUT failed with code %s" % status
self.logger.info("Approved the workflow %s" % workflow)
示例8: _verifyDBSCall
def _verifyDBSCall(dbsURL, uri):
try:
# from WMCore.Services.DBS.DBS3Reader import DBS3Reader
# DBS3Reader(dbsURL).dbs.serverinfo()
from WMCore.Services.Requests import JSONRequests
jsonSender = JSONRequests(dbsURL)
result = jsonSender.get("/%s" % uri)
if not result[1] == 200:
raise WMSpecFactoryException("DBS is not connected: %s : %s" % (dbsURL, str(result)))
except:
raise WMSpecFactoryException("DBS is not responding: %s" % dbsURL)
return result[0]
示例9: makeRequest
def makeRequest(self, url, params):
request = JSONRequests(url)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
request.post("/reqmgr/create/makeSchema", params, headers)
(data, status, reason, _) = request.getresponse()
if status != 303:
self.debugHttpError(data, status, reason)
raise RuntimeError, "POST failed with code %s" % status
workflow=data.split("'")[1].split('/')[-1]
self.logger.info('Injected workflow:',workflow,'into',url)
return workflow
示例10: RequestManagerTest
class RequestManagerTest(RESTBaseUnitTest):
"""
Test RequestMgr Service client
It will start RequestMgr RESTService
Server DB is whatever env is set
This checks whether DS call makes without error and return the results.
This test only test service call returns without error.
The correctness of each function is tested in test/python/RequestManager_t/RequestMgr_t.py
"""
def initialize(self):
self.couchDBName = "reqmgr_t_0"
self.config = RequestManagerConfig(
'WMCore.HTTPFrontEnd.RequestManager.ReqMgrRESTModel')
dbUrl = os.environ.get("DATABASE", None)
self.config.setDBUrl(dbUrl)
self.config.setFormatter('WMCore.WebTools.RESTFormatter')
self.config.setupRequestConfig()
self.config.setupCouchDatabase(dbName = self.couchDBName)
self.config.setPort(8888)
self.schemaModules = ["WMCore.RequestManager.RequestDB"]
def setUp(self):
RESTBaseUnitTest.setUp(self)
self.testInit.setupCouch("%s" % self.couchDBName,
"GroupUser", "ConfigCache")
self.params = {}
self.params['endpoint'] = self.config.getServerUrl()
self.reqService = RequestManagerDS(self.params)
self.jsonSender = JSONRequests(self.config.getServerUrl())
self.jsonSender.put('user/[email protected]')
self.jsonSender.put('group/PeopleLikeMe')
self.jsonSender.put('group/PeopleLikeMe/me')
self.jsonSender.put('version/CMSSW_3_5_8/slc5_ia32_gcc434')
schema = ReReco.getTestArguments()
schema['RequestName'] = 'TestReReco'
schema['RequestType'] = 'ReReco'
schema['CmsPath'] = "/uscmst1/prod/sw/cms"
schema['Requestor'] = '%s' % "me"
schema['Group'] = '%s' % "PeopleLikeMe"
schema['BlockWhitelist'] = ['/dataset/dataset/dataset#alpha']
schema['BlockBlacklist'] = ['/dataset/dataset/dataset#beta']
schema['Campaign'] = 'MyTestCampaign'
try:
r = self.jsonSender.put('request/' + schema['RequestName'], schema)
except Exception, ex:
print "Exception during set up, investigate exception instance attributes:"
print dir(ex)
return
self.requestName = r[0]['RequestName']
示例11: setUp
def setUp(self):
RESTBaseUnitTest.setUp(self)
self.testInit.setupCouch("%s" % self.couchDBName, "GroupUser", "ConfigCache", "ReqMgr")
self.testInit.setupCouch("%s_wmstats" % self.couchDBName, "WMStats")
# logging stuff from TestInit is broken, setting myself
l = logging.getLogger()
l.setLevel(logging.DEBUG)
self.params = {}
self.params['endpoint'] = self.config.getServerUrl()
self.reqService = RequestManagerDS(self.params)
self.jsonSender = JSONRequests(self.config.getServerUrl())
userName = 'Taizong'
groupName = 'Li'
teamName = 'Tang'
schema = utils.getAndSetupSchema(self,
userName = userName,
groupName = groupName,
teamName = teamName)
schema['ConfigCacheID'] = self.createConfig()
schema['CouchDBName'] = self.couchDBName
schema['CouchWorkloadDBName'] = self.couchDBName
try:
r = self.jsonSender.put('request', schema)
try:
self.requestName = r[0]['RequestName']
except:
self.requestName = r[0].values()[0]['RequestName']
except Exception as ex:
msg = traceback.format_exc()
print("Exception during set up, reason: %s" % msg)
raise ex
示例12: __init__
def __init__(self, dict):
defaultdict = {'endpoint': "https://cmsweb.cern.ch/registration/",
'cacheduration': 1,
'cachepath': '/tmp'}
defaultdict.update(dict)
defaultdict["method"] = 'PUT'
if 'logger' not in defaultdict.keys():
logging.basicConfig(level = logging.DEBUG,
format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt = '%m-%d %H:%M',
filename = defaultdict['cachepath'] + '/regsvc.log',
filemode = 'w')
defaultdict['logger'] = logging.getLogger('RegService')
Service.__init__(self, defaultdict)
JSONRequests.__init__(self, defaultdict['endpoint'])
示例13: setUp
def setUp(self):
RESTBaseUnitTest.setUp(self)
self.testInit.setupCouch("%s" % self.couchDBName,
"GroupUser", "ConfigCache")
self.params = {}
self.params['endpoint'] = self.config.getServerUrl()
self.reqService = RequestManagerDS(self.params)
self.jsonSender = JSONRequests(self.config.getServerUrl())
self.jsonSender.put('user/[email protected]')
self.jsonSender.put('group/PeopleLikeMe')
self.jsonSender.put('group/PeopleLikeMe/me')
self.jsonSender.put('version/CMSSW_3_5_8/slc5_ia32_gcc434')
schema = ReReco.getTestArguments()
schema['RequestName'] = 'TestReReco'
schema['RequestType'] = 'ReReco'
schema['CmsPath'] = "/uscmst1/prod/sw/cms"
schema['Requestor'] = '%s' % "me"
schema['Group'] = '%s' % "PeopleLikeMe"
schema['BlockWhitelist'] = ['/dataset/dataset/dataset#alpha']
schema['BlockBlacklist'] = ['/dataset/dataset/dataset#beta']
schema['Campaign'] = 'MyTestCampaign'
try:
r = self.jsonSender.put('request/' + schema['RequestName'], schema)
except Exception, ex:
print "Exception during set up, investigate exception instance attributes:"
print dir(ex)
return
示例14: testPush
def testPush(self):
reg_info ={
"location": "https://globaldbs",
"admin": "[email protected]",
"type": "DBS",
"name": "Global DBS",
"timeout": 2
}
reg = Registration({'server': self.testInit.couchUrl, 'database': self.couch_db}, reg_info)
json = BasicAuthJSONRequests(self.testInit.couchUrl)
data = json.get('/%s/%s' % (self.couch_db, str(reg_info['location'].__hash__())))
for k, v in reg_info.items():
if k != 'timestamp':
assert data[0][k] == v, \
"Registration incomplete: %s should equal %s for key %s" % (data[0][k], v, k)
示例15: setUp
def setUp(self):
"""
setUP global values
Database setUp is done in base class
"""
self.couchDBName = "reqmgr_t_0"
RESTBaseUnitTest.setUp(self)
self.testInit.setupCouch("%s" % self.couchDBName, "GroupUser", "ConfigCache")
self.testInit.setupCouch("%s_wmstats" % self.couchDBName, "WMStats")
reqMgrHost = self.config.getServerUrl()
self.jsonSender = JSONRequests(reqMgrHost)