本文整理汇总了Python中DIRAC.RequestManagementSystem.Client.Request.Request.addOperation方法的典型用法代码示例。如果您正苦于以下问题:Python Request.addOperation方法的具体用法?Python Request.addOperation怎么用?Python Request.addOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.RequestManagementSystem.Client.Request.Request
的用法示例。
在下文中一共展示了Request.addOperation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RequestTaskTests
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
class RequestTaskTests( unittest.TestCase ):
"""
.. class:: RequestTaskTests
"""
def setUp( self ):
""" test case set up """
self.handlersDict = { "ForwardDISET" : "DIRAC/RequestManagementSystem/private/ForwardDISET" }
self.req = Request()
self.req.RequestName = "foobarbaz"
self.req.OwnerGroup = "dirac_user"
self.req.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=cibak/CN=605919/CN=Krzysztof Ciba"
self.op = Operation( { "Type": "ForwardDISET", "Arguments" : "tts10:helloWorldee" } )
self.req.addOperation( self.op )
self.task = None
def tearDown( self ):
""" test case tear down """
del self.req
del self.op
del self.task
def testAPI( self ):
""" test API """
self.task = RequestTask( self.req.toXML()["Value"], self.handlersDict )
self.task.requestClient = Mock( return_value = Mock(spec=RequestClient) )
self.task.requestClient().updateRequest = Mock()
self.task.requestClient().updateRequest.return_value = { "OK" : True, "Value" : None }
ret = self.task()
self.assertEqual( ret["OK"], True , "call failed")
示例2: OperationHandlerBaseTests
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
class OperationHandlerBaseTests( unittest.TestCase ):
"""
.. class:: OperationHandlerBaseTests
"""
def setUp( self ):
""" test set up """
self.req = Request()
self.req.RequestName = "testRequest"
self.op = Operation( {"Type" : "ForwardDISET", "Arguments" : "foobar" } )
self.req.addOperation( self.op )
self.baseOp = OperationHandlerBase()
def tearDown( self ):
""" test tear down """
del self.baseOp
del self.op
del self.req
def testOperationHandlerBase( self ):
""" base op test """
self.baseOp.setOperation( self.op )
# # log is there
self.assertEqual( "log" in dir( self.baseOp ), True, "log missing" )
# # operation is there
self.assertEqual( "operation" in dir( self.baseOp ), True, "operation is missing" )
# # request is there
self.assertEqual( "request" in dir( self.baseOp ), True, "request is missing" )
# # __call__ not implemented
self.assertRaises( NotImplementedError, self.baseOp )
# # replica manager
self.assertEqual( isinstance( self.baseOp.dm, DataManager ), True, "DataManager is missing" )
示例3: __deleteSandboxFromExternalBackend
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def __deleteSandboxFromExternalBackend( self, SEName, SEPFN ):
if self.getCSOption( "DelayedExternalDeletion", True ):
gLogger.info( "Setting deletion request" )
try:
request = Request()
request.RequestName = "RemoteSBDeletion:%s|%s:%s" % ( SEName, SEPFN, time.time() )
physicalRemoval = Operation()
physicalRemoval.Type = "PhysicalRemoval"
physicalRemoval.TargetSE = SEName
fileToRemove = File()
fileToRemove.PFN = SEPFN
physicalRemoval.addFile( fileToRemove )
request.addOperation( physicalRemoval )
return ReqClient().putRequest( request )
except Exception as e:
gLogger.exception( "Exception while setting deletion request" )
return S_ERROR( "Cannot set deletion request: %s" % str( e ) )
else:
gLogger.info( "Deleting external Sandbox" )
try:
return StorageElement( SEName ).removeFile( SEPFN )
except Exception as e:
gLogger.exception( "RM raised an exception while trying to delete a remote sandbox" )
return S_ERROR( "RM raised an exception while trying to delete a remote sandbox" )
示例4: myRequest
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def myRequest():
"""Create a request and put it to the db"""
request = Request()
request.RequestName = 'myAwesomeRemovalRequest.xml'
request.JobID = 0
request.SourceComponent = "myScript"
remove = Operation()
remove.Type = "RemoveFile"
lfn = "/ilc/user/s/sailer/test.txt"
rmFile = File()
rmFile.LFN = lfn
remove.addFile( rmFile )
request.addOperation( remove )
isValid = RequestValidator().validate( request )
if not isValid['OK']:
raise RuntimeError( "Failover request is not valid: %s" % isValid['Message'] )
else:
print("It is a GOGOGO")
requestClient = ReqClient()
result = requestClient.putRequest( request )
print(result)
示例5: createRequest
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def createRequest(requestID, opType, opStatus, fileStatus, lfnError=" ",
lfn="/ilc/fake/lfn"):
"""Create a request."""
req = Request({"RequestID": requestID})
op = Operation({"Type": opType, "Status": opStatus})
op.addFile(File({"LFN": lfn, "Status": fileStatus, "Error": lfnError}))
req.addOperation(op)
return req
示例6: prepareTransformationTasks
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def prepareTransformationTasks( self, transBody, taskDict, owner = '', ownerGroup = '', ownerDN = '' ):
""" Prepare tasks, given a taskDict, that is created (with some manipulation) by the DB
"""
if ( not owner ) or ( not ownerGroup ):
res = getProxyInfo( False, False )
if not res['OK']:
return res
proxyInfo = res['Value']
owner = proxyInfo['username']
ownerGroup = proxyInfo['group']
if not ownerDN:
res = getDNForUsername( owner )
if not res['OK']:
return res
ownerDN = res['Value'][0]
requestOperation = 'ReplicateAndRegister'
if transBody:
try:
_requestType, requestOperation = transBody.split( ';' )
except AttributeError:
pass
for taskID in sorted( taskDict ):
paramDict = taskDict[taskID]
if paramDict['InputData']:
transID = paramDict['TransformationID']
oRequest = Request()
transfer = Operation()
transfer.Type = requestOperation
transfer.TargetSE = paramDict['TargetSE']
if isinstance( paramDict['InputData'], list ):
files = paramDict['InputData']
elif isinstance( paramDict['InputData'], basestring ):
files = paramDict['InputData'].split( ';' )
for lfn in files:
trFile = File()
trFile.LFN = lfn
transfer.addFile( trFile )
oRequest.addOperation( transfer )
oRequest.RequestName = _requestName( transID, taskID )
oRequest.OwnerDN = ownerDN
oRequest.OwnerGroup = ownerGroup
isValid = self.requestValidator.validate( oRequest )
if not isValid['OK']:
return isValid
taskDict[taskID]['TaskObject'] = oRequest
return S_OK( taskDict )
示例7: _sendToFailover
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def _sendToFailover( rpcStub ):
""" Create a ForwardDISET operation for failover
"""
request = Request()
request.RequestName = "Accounting.DataStore.%s.%s" % ( time.time(), random.random() )
forwardDISETOp = Operation()
forwardDISETOp.Type = "ForwardDISET"
forwardDISETOp.Arguments = DEncode.encode( rpcStub )
request.addOperation( forwardDISETOp )
return ReqClient().putRequest( request )
示例8: _multiOperationsBody
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def _multiOperationsBody(self, transJson, taskDict, ownerDN, ownerGroup):
""" deal with a Request that has multiple operations
:param transJson: list of lists of string and dictionaries, e.g.:
.. code :: python
body = [ ( "ReplicateAndRegister", { "SourceSE":"FOO-SRM", "TargetSE":"BAR-SRM" }),
( "RemoveReplica", { "TargetSE":"FOO-SRM" } ),
]
:param dict taskDict: dictionary of tasks, modified in this function
:param str ownerDN: certificate DN used for the requests
:param str onwerGroup: dirac group used for the requests
:returns: None
"""
failedTasks = []
for taskID, task in taskDict.items():
transID = task['TransformationID']
if not task.get('InputData'):
self._logError("Error creating request for task", "%s, No input data" % taskID, transID=transID)
taskDict.pop(taskID)
continue
files = []
oRequest = Request()
if isinstance(task['InputData'], list):
files = task['InputData']
elif isinstance(task['InputData'], basestring):
files = task['InputData'].split(';')
# create the operations from the json structure
for operationTuple in transJson:
op = Operation()
op.Type = operationTuple[0]
for parameter, value in operationTuple[1].iteritems():
setattr(op, parameter, value)
for lfn in files:
opFile = File()
opFile.LFN = lfn
op.addFile(opFile)
oRequest.addOperation(op)
result = self._assignRequestToTask(oRequest, taskDict, transID, taskID, ownerDN, ownerGroup)
if not result['OK']:
failedTasks.append(taskID)
# Remove failed tasks
for taskID in failedTasks:
taskDict.pop(taskID)
示例9: RequestTaskTests
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
class RequestTaskTests( unittest.TestCase ):
"""
.. class:: RequestTaskTests
"""
def setUp( self ):
""" test case set up """
self.handlersDict = { "ForwardDISET" : "DIRAC/RequestManagementSystem/private/ForwardDISET" }
self.req = Request()
self.req.RequestName = "foobarbaz"
self.req.OwnerGroup = "lhcb_user"
self.req.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=chaen/CN=705305/CN=Christophe Haen"
self.op = Operation( { "Type": "ForwardDISET", "Arguments" : "tts10:helloWorldee" } )
self.req.addOperation( self.op )
self.task = None
self.mockRC = MagicMock()
self.mockObjectOps = MagicMock()
self.mockObjectOps.getSections.return_value = {'OK': True,
'Value': ['DataProcessing',
'DataManager']}
self.mockObjectOps.getOptionsDict.return_value = {'OK': True,
'Value': {'Group': 'lhcb_user', 'User': 'fstagni'}}
self.mockOps = MagicMock()
self.mockOps.return_value = self.mockObjectOps
def tearDown( self ):
""" test case tear down """
del self.req
del self.op
del self.task
def testAPI( self ):
""" test API
"""
rt = importlib.import_module( 'DIRAC.RequestManagementSystem.private.RequestTask' )
rt.gMonitor = MagicMock()
rt.Operations = self.mockOps
rt.CS = MagicMock()
self.task = RequestTask( self.req.toJSON()["Value"], self.handlersDict, 'csPath', 'RequestManagement/RequestExecutingAgent',
requestClient = self.mockRC )
self.task.requestClient = Mock( return_value = Mock( spec = ReqClient ) )
self.task.requestClient().updateRequest = Mock()
self.task.requestClient().updateRequest.return_value = { "OK" : True, "Value" : None }
ret = self.task()
self.assertEqual( ret["OK"], True , "call failed" )
ret = self.task.setupProxy()
print ret
示例10: RequestManagerHandlerTests
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
class RequestManagerHandlerTests( unittest.TestCase ):
"""
.. class:: RequestManagerHandlerTests
"""
def setUp( self ):
""" test setup
:param self: self reference
"""
self.request = Request()
self.request.RequestName = "RequestManagerHandlerTests"
self.request.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=cibak/CN=605919/CN=Krzysztof Ciba"
self.request.OwnerGroup = "dirac_user"
self.operation = Operation()
self.operation.Type = "ReplicateAndRegister"
self.operation.TargetSE = "CERN-USER"
self.file = File()
self.file.LFN = "/lhcb/user/c/cibak/testFile"
self.file.Checksum = "123456"
self.file.ChecksumType = "ADLER32"
self.request.addOperation( self.operation )
self.operation.addFile( self.file )
# # xml representation of a whole request
self.xmlStr = self.request.toXML( True )["Value"]
# # request client
self.requestClient = RequestClient()
def tearDown( self ):
""" test case tear down """
del self.request
del self.operation
del self.file
del self.xmlStr
def test01PutRequest( self ):
""" test set request """
put = self.requestClient.putRequest( self.request )
self.assertEqual( put["OK"], True, "put failed" )
def test02GetRequest( self ):
""" test get request """
get = self.requestClient.getRequest( self.request.RequestName )
self.assertEqual( get["OK"], True, "get failed" )
def test03DeleteRequest( self ):
""" test delete request """
delete = self.requestClient.deleteRequest( "test" )
self.assertEqual( delete["OK"], True, "delete failed" )
示例11: ReqClientTestCase
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
class ReqClientTestCase(unittest.TestCase):
"""
.. class:: ReqClientTestCase
"""
def setUp(self):
""" test case set up """
gLogger.setLevel('INFO')
self.file = File()
self.file.LFN = "/lhcb/user/c/cibak/testFile"
self.file.Checksum = "123456"
self.file.ChecksumType = "ADLER32"
self.file2 = File()
self.file2.LFN = "/lhcb/user/f/fstagni/testFile"
self.file2.Checksum = "654321"
self.file2.ChecksumType = "ADLER32"
self.operation = Operation()
self.operation.Type = "ReplicateAndRegister"
self.operation.TargetSE = "CERN-USER"
self.operation.addFile(self.file)
self.operation.addFile(self.file2)
proxyInfo = getProxyInfo()['Value']
self.request = Request()
self.request.RequestName = "RequestManagerHandlerTests"
self.request.OwnerDN = proxyInfo['identity']
self.request.OwnerGroup = proxyInfo['group']
self.request.JobID = 123
self.request.addOperation(self.operation)
# # JSON representation of a whole request
self.jsonStr = self.request.toJSON()['Value']
# # request client
self.requestClient = ReqClient()
self.stressRequests = 1000
self.bulkRequest = 1000
def tearDown(self):
""" clean up """
del self.request
del self.operation
del self.file
del self.jsonStr
示例12: ReqClientTestCase
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
class ReqClientTestCase( unittest.TestCase ):
"""
.. class:: ReqClientTestCase
"""
def setUp( self ):
""" test case set up """
gLogger.setLevel( 'NOTICE' )
self.file = File()
self.file.LFN = "/lhcb/user/c/cibak/testFile"
self.file.Checksum = "123456"
self.file.ChecksumType = "ADLER32"
self.file2 = File()
self.file2.LFN = "/lhcb/user/f/fstagni/testFile"
self.file2.Checksum = "654321"
self.file2.ChecksumType = "ADLER32"
self.operation = Operation()
self.operation.Type = "ReplicateAndRegister"
self.operation.TargetSE = "CERN-USER"
self.operation.addFile( self.file )
self.operation.addFile( self.file2 )
self.request = Request()
self.request.RequestName = "RequestManagerHandlerTests"
self.request.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=cibak/CN=605919/CN=Krzysztof Ciba"
self.request.OwnerGroup = "dirac_user"
self.request.JobID = 123
self.request.addOperation( self.operation )
# # JSON representation of a whole request
self.jsonStr = self.request.toJSON()['Value']
# # request client
self.requestClient = ReqClient()
self.stressRequests = 1000
self.bulkRequest = 1000
def tearDown( self ):
""" clean up """
del self.request
del self.operation
del self.file
del self.jsonStr
示例13: _sendToFailover
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def _sendToFailover( rpcStub ):
""" Create a ForwardDISET operation for failover
"""
try:
request = Request()
request.RequestName = "Accounting.DataStore.%s.%s" % ( time.time(), random.random() )
forwardDISETOp = Operation()
forwardDISETOp.Type = "ForwardDISET"
forwardDISETOp.Arguments = DEncode.encode( rpcStub )
request.addOperation( forwardDISETOp )
return ReqClient().putRequest( request )
# We catch all the exceptions, because it should never crash
except Exception as e: # pylint: disable=broad-except
return S_ERROR( ERMSUKN, "Exception sending accounting failover request: %s" % repr( e ) )
示例14: _singleOperationsBody
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def _singleOperationsBody(self, transBody, taskDict, ownerDN, ownerGroup):
""" deal with a Request that has just one operation, as it was sofar
:param transBody: string, can be an empty string
:param dict taskDict: dictionary of tasks, modified in this function
:param str ownerDN: certificate DN used for the requests
:param str onwerGroup: dirac group used for the requests
:returns: None
"""
requestOperation = 'ReplicateAndRegister'
if transBody:
try:
_requestType, requestOperation = transBody.split(';')
except AttributeError:
pass
failedTasks = []
# Do not remove sorted, we might pop elements in the loop
for taskID, task in taskDict.iteritems():
transID = task['TransformationID']
oRequest = Request()
transfer = Operation()
transfer.Type = requestOperation
transfer.TargetSE = task['TargetSE']
# If there are input files
if task.get('InputData'):
if isinstance(task['InputData'], list):
files = task['InputData']
elif isinstance(task['InputData'], basestring):
files = task['InputData'].split(';')
for lfn in files:
trFile = File()
trFile.LFN = lfn
transfer.addFile(trFile)
oRequest.addOperation(transfer)
result = self._assignRequestToTask(oRequest, taskDict, transID, taskID, ownerDN, ownerGroup)
if not result['OK']:
failedTasks.append(taskID)
# Remove failed tasks
for taskID in failedTasks:
taskDict.pop(taskID)
示例15: test07List
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import addOperation [as 别名]
def test07List( self ):
""" setitem, delitem, getitem and dirty """
r = Request()
ops = [ Operation() for i in range( 5 ) ]
for op in ops:
r.addOperation( op )
for i, op in enumerate( ops ):
self.assertEqual( op, r[i], "__getitem__ failed" )
op = Operation()
r[0] = op
self.assertEqual( op, r[0], "__setitem__ failed" )
del r[0]
self.assertEqual( len( r ), 4, "__delitem__ failed" )
r.RequestID = 1
del r[0]
self.assertEqual( r.cleanUpSQL(), None, "cleanUpSQL failed after __delitem__ (no opId)" )
r[0].OperationID = 1
del r[0]
clean = r.cleanUpSQL()
self.assertEqual( clean,
['DELETE FROM `Operation` WHERE `RequestID`=1 AND `OperationID` IN (1);\n',
'DELETE FROM `File` WHERE `OperationID`=1;\n'],
"cleanUpSQL failed after __delitem__ (opId set)\n%s" % clean )
r[0].OperationID = 2
r[0] = Operation()
clean = r.cleanUpSQL()
self.assertEqual( clean,
['DELETE FROM `Operation` WHERE `RequestID`=1 AND `OperationID` IN (1,2);\n',
'DELETE FROM `File` WHERE `OperationID`=1;\n', 'DELETE FROM `File` WHERE `OperationID`=2;\n'],
"cleanUpSQL failed after __setitem_ (opId set):\n%s" % clean )
json = r.toJSON()
self.assertEqual( "__dirty" in json["Value"], True, "__dirty missing in json" )
r2 = Request( json["Value"] )
self.assertEqual( r.cleanUpSQL(), r2.cleanUpSQL(), "wrong cleanUpSQL after json" )