本文整理汇总了Python中DIRAC.RequestManagementSystem.Client.Request.Request.toJSON方法的典型用法代码示例。如果您正苦于以下问题:Python Request.toJSON方法的具体用法?Python Request.toJSON怎么用?Python Request.toJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.RequestManagementSystem.Client.Request.Request
的用法示例。
在下文中一共展示了Request.toJSON方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test01CtorSerilization
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
def test01CtorSerilization( self ):
""" c'tor and serialization """
# # empty c'tor
req = Request()
self.assertEqual( isinstance( req, Request ), True )
self.assertEqual( req.JobID, 0 )
self.assertEqual( req.Status, "Waiting" )
req = Request( self.fromDict )
self.assertEqual( isinstance( req, Request ), True )
self.assertEqual( req.RequestName, "test" )
self.assertEqual( req.JobID, 12345 )
self.assertEqual( req.Status, "Waiting" )
toJSON = req.toJSON()
self.assertEqual( toJSON["OK"], True, "JSON serialization failed" )
fromJSON = toJSON["Value"]
req = Request( fromJSON )
toSQL = req.toSQL()
self.assertEqual( toSQL["OK"], True )
toSQL = toSQL["Value"]
self.assertEqual( toSQL.startswith( "INSERT" ), True )
req.RequestID = 1
toSQL = req.toSQL()
self.assertEqual( toSQL["OK"], True )
toSQL = toSQL["Value"]
self.assertEqual( toSQL.startswith( "UPDATE" ), True )
示例2: RequestTaskTests
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [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
示例3: ReqClientTestCase
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [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
示例4: ReqClientTestCase
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [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
示例5: test07List
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [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" )
示例6: test04Operations
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
def test04Operations( self ):
""" operations arithmetic and state machine """
req = Request()
self.assertEqual( len( req ), 0 )
transfer = Operation()
transfer.Type = "ReplicateAndRegister"
transfer.addFile( File( { "LFN" : "/a/b/c", "Status" : "Waiting" } ) )
getWaiting = req.getWaiting()
self.assertEqual( getWaiting["OK"], True )
self.assertEqual( getWaiting["Value"], None )
req.addOperation( transfer )
self.assertEqual( len( req ), 1 )
self.assertEqual( transfer.Order, req.Order )
self.assertEqual( transfer.Status, "Waiting" )
getWaiting = req.getWaiting()
self.assertEqual( getWaiting["OK"], True )
self.assertEqual( getWaiting["Value"], transfer )
removal = Operation( { "Type" : "RemoveFile" } )
removal.addFile( File( { "LFN" : "/a/b/c", "Status" : "Waiting" } ) )
req.insertBefore( removal, transfer )
getWaiting = req.getWaiting()
self.assertEqual( getWaiting["OK"], True )
self.assertEqual( getWaiting["Value"], removal )
self.assertEqual( len( req ), 2 )
self.assertEqual( [ op.Status for op in req ], ["Waiting", "Queued"] )
self.assertEqual( req.subStatusList() , ["Waiting", "Queued"] )
self.assertEqual( removal.Order, 0 )
self.assertEqual( removal.Order, req.Order )
self.assertEqual( transfer.Order, 1 )
self.assertEqual( removal.Status, "Waiting" )
self.assertEqual( transfer.Status, "Queued" )
for subFile in removal:
subFile.Status = "Done"
removal.Status = "Done"
self.assertEqual( removal.Status, "Done" )
self.assertEqual( transfer.Status, "Waiting" )
self.assertEqual( transfer.Order, req.Order )
# # len, looping
self.assertEqual( len( req ), 2 )
self.assertEqual( [ op.Status for op in req ], ["Done", "Waiting"] )
self.assertEqual( req.subStatusList() , ["Done", "Waiting"] )
digest = req.toJSON()
self.assertEqual( digest["OK"], True )
getWaiting = req.getWaiting()
self.assertEqual( getWaiting["OK"], True )
self.assertEqual( getWaiting["Value"], transfer )
示例7: ReqClient
# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
requestClient = ReqClient()
requestOperation = 'replicateAndRegister'
for lfnList in breakListIntoChunks( lfns, 100 ):
oRequest = Request()
oRequest.RequestName = "%s_%s" % ( md5( repr( time.time() ) ).hexdigest()[:16], md5( repr( time.time() ) ).hexdigest()[:16] )
replicateAndRegister = Operation()
replicateAndRegister.Type = 'ReplicateAndRegister'
replicateAndRegister.TargetSE = targetSE
for lfn in lfnList:
rarFile = File()
rarFile.LFN = lfn
replicateAndRegister.addFile( rarFile )
oRequest.addOperation( replicateAndRegister )
isValid = gRequestValidator.validate( oRequest )
if not isValid['OK']:
print "Request is not valid: ", isValid['Message']
DIRAC.exit( 1 )
DIRAC.gLogger.info( oRequest.toJSON()['Value'] )
result = requestClient.putRequest( oRequest )
if result['OK']:
print 'Submitted Request:', result['Value']
else:
print 'Failed to submit Request', result['Message']