本文整理汇总了Python中DIRAC.RequestManagementSystem.Client.RequestContainer.RequestContainer类的典型用法代码示例。如果您正苦于以下问题:Python RequestContainer类的具体用法?Python RequestContainer怎么用?Python RequestContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setRequest
def setRequest( self, requestName, requestString, desiredStatus = None ):
""" Set request to the database (including all sub-requests)
"""
gLogger.info( "RequestDBFile._setRequest: Attempting to set %s." % requestName )
request = RequestContainer( requestString )
requestTypes = request.getSubRequestTypes()['Value']
try:
for requestType in requestTypes:
subRequestString = request.toXML( desiredType = requestType )['Value']
if subRequestString:
if desiredStatus:
status = desiredStatus
elif not request.isRequestTypeEmpty( requestType )['Value']:
status = 'ToDo'
else:
status = 'Done'
subRequestDir = '%s/%s/%s' % ( self.root, requestType, status )
if not os.path.exists( subRequestDir ):
os.makedirs( subRequestDir )
subRequestPath = '%s/%s' % ( subRequestDir, requestName )
subRequestFile = open( subRequestPath, 'w' )
subRequestFile.write( subRequestString )
subRequestFile.close()
gLogger.info( "RequestDBFile._setRequest: Successfully set %s." % requestName )
return S_OK()
except Exception, x:
errStr = "RequestDBFile._setRequest: Exception while setting request."
gLogger.exception( errStr, requestName, lException = x )
self.deleteRequest( requestName )
return S_ERROR( errStr )
示例2: setRequest
def setRequest(self, requestName, requestString, desiredStatus=None):
""" Set request to the database (including all sub-requests)
:param self: self reference
:param str requestName: request name
:param str requestString: serilised request
:param mixed desiredState: optional request status, defult = None
"""
self.log.info("setRequest: Attempting to set %s." % requestName)
request = RequestContainer(requestString)
requestTypes = request.getSubRequestTypes()["Value"]
try:
for requestType in requestTypes:
subRequestString = request.toXML(desiredType=requestType)["Value"]
if subRequestString:
if desiredStatus:
status = desiredStatus
elif not request.isRequestTypeEmpty(requestType)["Value"]:
status = "Waiting"
else:
status = "Done"
subRequestDir = os.path.join(self.root, requestType, status)
if not os.path.exists(subRequestDir):
os.makedirs(subRequestDir)
subRequestPath = os.path.join(subRequestDir, requestName)
subRequestFile = open(subRequestPath, "w")
subRequestFile.write(subRequestString)
subRequestFile.close()
self.log.info("setRequest: Successfully set %s." % requestName)
return S_OK()
except Exception, error:
errStr = "setRequest: Exception while setting request."
self.log.exception(errStr, requestName, lException=error)
self.deleteRequest(requestName)
return S_ERROR(errStr)
示例3: _sendToFailover
def _sendToFailover( rpcStub ):
requestClient = RequestClient()
request = RequestContainer()
request.setDISETRequest( rpcStub )
requestStub = request.toXML()['Value']
return requestClient.setRequest( "Accounting.DataStore.%s.%s" % ( time.time(), random.random() ),
requestStub )
示例4: updateRequest
def updateRequest( self, requestName, requestString ):
""" update request given its name and xml serilised string
:param str requestName: Requests.RequestName
:param str requestString: request serilised to xml
"""
request = RequestContainer( request = requestString )
requestTypes = ['transfer', 'register', 'removal', 'stage', 'diset', 'logupload']
requestID = request.getRequestID()['Value']
updateRequestFailed = False
for requestType in requestTypes:
res = request.getNumSubRequests( requestType )
if res['OK']:
numRequests = res['Value']
for ind in range( numRequests ):
res = request.getSubRequestAttributes( ind, requestType )
if res['OK']:
subRequestDict = res['Value']
if 'SubRequestID' in subRequestDict:
subRequestID = res['Value']['SubRequestID']
res = self.__updateSubRequestFiles( ind, requestType, subRequestID, request )
if res['OK']:
if request.isSubRequestDone( ind, requestType )['Value']:
res = self._setSubRequestAttribute( requestID, subRequestID, 'Status', 'Done' )
else:
res = self._setSubRequestAttribute( requestID, subRequestID, 'Status', 'Waiting' )
if not res['OK']:
updateRequestFailed = True
else:
updateRequestFailed = True
if "Error" in subRequestDict:
result = self._setSubRequestAttribute( requestID, subRequestID,
'Error', subRequestDict['Error'] )
if not result['OK']:
updateRequestFailed = True
else:
updateRequestFailed = True
else:
updateRequestFailed = True
else:
updateRequestFailed = True
if updateRequestFailed:
errStr = 'Failed to update request %s.' % requestID
return S_ERROR( errStr )
else:
requestStatus = self.getRequestStatus( requestID )
if not requestStatus["OK"]:
return requestStatus
requestStatus = requestStatus["Value"]
if requestStatus["SubRequestStatus"] not in ( "Waiting", "Assigned" ):
res = self._setRequestAttribute( requestID, 'Status', 'Done' )
if not res['OK']:
errStr = 'Failed to update request status of %s to Done.' % requestID
return S_ERROR( errStr )
return S_OK()
示例5: submitTaskToExternal
def submitTaskToExternal(self,request):
if type(request) in types.StringTypes:
oRequest = RequestContainer(request)
name = oRequest.getRequestName()['Value']
elif type(request) == types.InstanceType:
name = request.getRequestName()['Value']
request = request.toXML()['Value']
else:
return S_ERROR("Request should be string or request object")
return self.requestClient.setRequest(name,request)
示例6: generateRequest
def generateRequest(self):
""" Commit the accumulated records and generate request eventually """
result = self.commit()
request = None
if not result['OK']:
# Generate Request
request = RequestContainer()
if result.has_key('FailedResults'):
for res in result['FailedResults']:
if res.has_key('rpcStub'):
request.setDISETRequest(res['rpcStub'])
return S_OK(request)
示例7: __forwardable
def __forwardable( requestString ):
""" check if request if forwardable
The sub-request of type transfer:putAndRegister, removal:physicalRemoval and removal:reTransfer are
definitely not, they should be executed locally, as they are using local fs.
:param str requestString: XML-serialised request
"""
request = RequestContainer( requestString )
subRequests = request.getSubRequests( "transfer" )["Value"] + request.getSubRequests( "removal" )["Value"]
for subRequest in subRequests:
if subRequest["Attributes"]["Operation"] in ( "putAndRegister", "physicalRemoval", "reTransfer" ):
return S_ERROR("found operation '%s' that cannot be forwarded" % subRequest["Attributes"]["Operation"] )
return S_OK()
示例8: __getRequestString
def __getRequestString( self, requestName ):
""" Obtain the string for request (including all sub-requests)
"""
gLogger.info( "RequestDBFile.__getRequestString: Attempting to get string for %s." % requestName )
res = self.__locateRequest( requestName )
if not res['OK']:
return res
subRequestPaths = res['Value']
try:
oRequest = RequestContainer( init = False )
for subRequestPath in subRequestPaths:
res = self.__readSubRequestString( subRequestPath )
if not res['OK']:
return res
subRequestString = res['Value']
tempRequest = RequestContainer( subRequestString )#,init=False)
oRequest.setRequestAttributes( tempRequest.getRequestAttributes()['Value'] )
oRequest.update( tempRequest )
requestString = oRequest.toXML()['Value']
gLogger.info( "RequestDBFile.__getRequestString: Successfully obtained string for %s." % requestName )
result = S_OK( requestString )
result['Request'] = oRequest
return result
except Exception, x:
errStr = "RequestDBFile.__getRequestString: Exception while obtaining request string."
gLogger.exception( errStr, requestName, lException = x )
return S_ERROR( errStr )
示例9: __getRequestString
def __getRequestString(self, requestName):
""" Obtain the string for request (including all sub-requests)
:param self: self reference
:param str requestName: request name
"""
self.log.info("__getRequestString: Attempting to get string for %s." % requestName)
res = self.__locateRequest(requestName)
if not res["OK"]:
return res
subRequestPaths = res["Value"]
try:
oRequest = RequestContainer(init=False)
for subRequestPath in subRequestPaths:
res = self.__readSubRequestString(subRequestPath)
if not res["OK"]:
return res
subRequestString = res["Value"]
tempRequest = RequestContainer(subRequestString)
oRequest.setRequestAttributes(tempRequest.getRequestAttributes()["Value"])
oRequest.update(tempRequest)
requestString = oRequest.toXML()["Value"]
self.log.info("__getRequestString: Successfully obtained string for %s." % requestName)
result = S_OK(requestString)
result["Request"] = oRequest
return result
except Exception, error:
errStr = "__getRequestString: Exception while obtaining request string."
self.log.exception(errStr, requestName, lException=error)
return S_ERROR(errStr)
示例10: applicationSpecificInputs
def applicationSpecificInputs(self):
""" Resolve all input variables for the module here.
@return: S_OK()
"""
if self.step_commons.has_key('DataAttributes'):
self.dataattributes = self.step_commons['DataAttributes']
else:
return S_ERROR('No data attributes found, cannot proceed with registration in Catalog, ABORT!')
for attribute in self.dataattributes.split(";"):
if self.step_commons.has_key(attribute):
self.attributesdict[attribute] = self.step_commons[attribute]
if self.step_commons.has_key("destination"):
self.destination = self.step_commons['destination']
if self.step_commons.has_key('GENFile'):
self.generatorfile = self.step_commons['GENFile']
if self.step_commons.has_key('MokkaFile'):
self.mokkafile = self.step_commons['MokkaFile']
if self.step_commons.has_key('MarlinFiles'):
self.marlinfiles = self.step_commons['MarlinFiles'].split(';')
if self.step_commons.has_key('SLICFile'):
self.slicfile = self.step_commons['SLICFile']
if self.step_commons.has_key('LCSIMFiles'):
self.lcsimfiles = self.step_commons['LCSIMFiles'].split(';')
if self.workflow_commons.has_key('Request'):
self.request = self.workflow_commons['Request']
else:
self.request = RequestContainer()
self.request.setRequestName('job_%s_request.xml' % self.jobID)
self.request.setJobID(self.jobID)
self.request.setSourceComponent("Job_%s" % self.jobID)
return S_OK('Parameters resolved')
示例11: test_01_getRequestStatus
def test_01_getRequestStatus( self ):
self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ),
{'OK': True, 'Value': {'SubRequestStatus': 'Waiting', 'RequestStatus': 'Waiting'}})
## get request
getRemoval = self.requestDB.getRequest( "removal" )
oRequest = RequestContainer( getRemoval["Value"]["RequestString"] )
self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ),
{'OK': True, 'Value': {'SubRequestStatus': 'Assigned', 'RequestStatus': 'Waiting'}} )
## make removal Done
oRequest.subRequests["removal"][0]["Attributes"]["Status"] = "Done"
oRequest.subRequests["removal"][0]["Files"][0]["Status"] = "Done"
update = self.requestDB.updateRequest( getRemoval["Value"]["RequestName"],
oRequest.toXML()["Value"] )
## get status
self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ),
{'OK': True, 'Value': {'SubRequestStatus': 'Waiting', 'RequestStatus': u'Waiting'}})
## make transfer Done
oRequest.subRequests["transfer"][0]["Attributes"]["Status"] = "Done"
oRequest.subRequests["transfer"][0]["Files"][0]["Status"] = "Done"
update = self.requestDB.updateRequest( getRemoval["Value"]["RequestName"],
oRequest.toXML()["Value"] )
## get status
self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ),
{'OK': True, 'Value': {'SubRequestStatus': 'Done', 'RequestStatus': 'Done'}} )
示例12: __deleteSandboxFromExternalBackend
def __deleteSandboxFromExternalBackend( self, SEName, SEPFN ):
if self.getCSOption( "DelayedExternalDeletion", True ):
gLogger.info( "Setting deletion request" )
try:
request = RequestContainer()
result = request.addSubRequest( { 'Attributes' : { 'Operation' : 'removePhysicalFile',
'TargetSE' : SEName,
'ExecutionOrder' : 1
} },
'removal' )
index = result['Value']
fileDict = { 'PFN' : SEPFN, 'Status' : 'Waiting' }
request.setSubRequestFiles( index, 'removal', [ fileDict ] )
return RequestClient().setRequest( "RemoteSBDeletion:%s|%s:%s" % ( SEName, SEPFN, time.time() ),
request.toXML()[ 'Value' ] )
except Exception, e:
gLogger.exception( "Exception while setting deletion request" )
return S_ERROR( "Cannot set deletion request: %s" % str( e ) )
示例13: applicationSpecificInputs
def applicationSpecificInputs(self):
if self.step_commons.has_key("Enable"):
self.enable = self.step_commons["Enable"]
if not type(self.enable) == type(True):
self.log.warn("Enable flag set to non-boolean value %s, setting to False" % self.enable)
self.enable = False
if self.step_commons.has_key("TestFailover"):
self.enable = self.step_commons["TestFailover"]
if not type(self.failoverTest) == type(True):
self.log.warn("Test failover flag set to non-boolean value %s, setting to False" % self.failoverTest)
self.failoverTest = False
if os.environ.has_key("JOBID"):
self.jobID = os.environ["JOBID"]
self.log.verbose("Found WMS JobID = %s" % self.jobID)
else:
self.log.info("No WMS JobID found, disabling module via control flag")
self.enable = False
if self.workflow_commons.has_key("LogFilePath") and self.workflow_commons.has_key("LogTargetPath"):
self.logFilePath = self.workflow_commons["LogFilePath"]
self.logLFNPath = self.workflow_commons["LogTargetPath"]
else:
self.log.info("LogFilePath parameter not found, creating on the fly")
result = getLogPath(self.workflow_commons)
if not result["OK"]:
self.log.error("Could not create LogFilePath", result["Message"])
return result
self.logFilePath = result["Value"]["LogFilePath"][0]
self.logLFNPath = result["Value"]["LogTargetPath"][0]
if not type(self.logFilePath) == type(" "):
self.logFilePath = self.logFilePath[0]
if not type(self.logLFNPath) == type(" "):
self.logLFNPath = self.logLFNPath[0]
example_file = self.logFilePath
if "/ilc/prod/clic" in example_file:
self.experiment = "CLIC"
elif "/ilc/prod/ilc/sid" in example_file:
self.experiment = "ILC_SID"
elif "/ilc/prod/ilc/mc-dbd" in example_file:
self.experiment = "ILC_ILD"
else:
self.log.warn("Failed to determine experiment, reverting to default: %s" % self.experiment)
if self.workflow_commons.has_key("Request"):
self.request = self.workflow_commons["Request"]
else:
self.request = RequestContainer()
self.request.setRequestName("job_%s_request.xml" % self.jobID)
self.request.setJobID(self.jobID)
self.request.setSourceComponent("Job_%s" % self.jobID)
return S_OK("Parameters resolved")
示例14: applicationSpecificInputs
def applicationSpecificInputs(self):
""" By convention the module parameters are resolved here.
"""
self.log.verbose(self.workflow_commons)
self.log.verbose(self.step_commons)
#Earlier modules may have populated the report objects
if self.workflow_commons.has_key('JobReport'):
self.jobReport = self.workflow_commons['JobReport']
if self.step_commons.has_key('Enable'):
self.enable = self.step_commons['Enable']
if not type(self.enable) == type(True):
self.log.warn('Enable flag set to non-boolean value %s, setting to False' %self.enable)
self.enable = False
if self.step_commons.has_key('TestFailover'):
self.enable = self.step_commons['TestFailover']
if not type(self.failoverTest) == type(True):
self.log.warn('Test failover flag set to non-boolean value %s, setting to False' % self.failoverTest)
self.failoverTest = False
if os.environ.has_key('JOBID'):
self.jobID = os.environ['JOBID']
self.log.verbose('Found WMS JobID = %s' % self.jobID)
else:
self.log.info('No WMS JobID found, disabling module via control flag')
self.enable = False
if self.workflow_commons.has_key('Request'):
self.request = self.workflow_commons['Request']
else:
self.request = RequestContainer()
self.request.setRequestName('job_%s_request.xml' % self.jobID)
self.request.setJobID(self.jobID)
self.request.setSourceComponent("Job_%s" % self.jobID)
#Use LHCb utility for local running via dirac-jobexec
if self.workflow_commons.has_key('UserOutputData'):
self.userOutputData = self.workflow_commons['UserOutputData']
if not type(self.userOutputData) == type([]):
self.userOutputData = [i.strip() for i in self.userOutputData.split(';')]
if self.workflow_commons.has_key('UserOutputSE'):
specifiedSE = self.workflow_commons['UserOutputSE']
if not type(specifiedSE) == type([]):
self.userOutputSE = [i.strip() for i in specifiedSE.split(';')]
else:
self.log.verbose('No UserOutputSE specified, using default value: %s' % (string.join(self.defaultOutputSE,
', ')))
self.userOutputSE = self.defaultOutputSE
if self.workflow_commons.has_key('UserOutputPath'):
self.userOutputPath = self.workflow_commons['UserOutputPath']
return S_OK('Parameters resolved')
示例15: readRequestsForJobs
def readRequestsForJobs( self, jobIDs ):
""" read requests for jobs
:param list jobIDs: list with jobIDs
:return: S_OK( { "Successful" : { jobID1 : RequestContainer, ... },
"Failed" : { jobIDn : "Fail reason" } } )
"""
readReqsForJobs = self.requestManager().readRequestsForJobs( jobIDs )
if not readReqsForJobs["OK"]:
return readReqsForJobs
ret = readReqsForJobs["Value"] if readReqsForJobs["Value"] else None
if not ret:
return S_ERROR( "No values returned" )
# # create RequestContainers out of xml strings for successful reads
if "Successful" in ret:
for jobID, xmlStr in ret["Successful"].items():
req = RequestContainer( init = False )
req.parseRequest( request = xmlStr )
ret["Successful"][jobID] = req
return S_OK( ret )