コード例 #1
0
ファイル: IntegrationFCT.py プロジェクト: sposs/DIRAC
    def buildRequest(self, owner, group, sourceSE, targetSE1, targetSE2):

        files = self.files(owner, group)

        putAndRegister = Operation()
        putAndRegister.Type = "PutAndRegister"
        putAndRegister.TargetSE = sourceSE
        for fname, lfn, size, checksum, guid in files:
            putFile = File()
            putFile.LFN = lfn
            putFile.PFN = fname
            putFile.Checksum = checksum
            putFile.ChecksumType = "adler32"
            putFile.Size = size
            putFile.GUID = guid
            putAndRegister.addFile(putFile)

        replicateAndRegister = Operation()
        replicateAndRegister.Type = "ReplicateAndRegister"
        replicateAndRegister.TargetSE = "%s,%s" % (targetSE1, targetSE2)
        for fname, lfn, size, checksum, guid in files:
            repFile = File()
            repFile.LFN = lfn
            repFile.Size = size
            repFile.Checksum = checksum
            repFile.ChecksumType = "adler32"
            replicateAndRegister.addFile(repFile)

        removeReplica = Operation()
        removeReplica.Type = "RemoveReplica"
        removeReplica.TargetSE = sourceSE
        for fname, lfn, size, checksum, guid in files:
            removeReplica.addFile(File({"LFN": lfn}))

        removeFile = Operation()
        removeFile.Type = "RemoveFile"
        for fname, lfn, size, checksum, guid in files:
            removeFile.addFile(File({"LFN": lfn}))

        removeFileInit = Operation()
        removeFileInit.Type = "RemoveFile"
        for fname, lfn, size, checksum, guid in files:
            removeFileInit.addFile(File({"LFN": lfn}))

        req = Request()
        req.addOperation(removeFileInit)
        req.addOperation(putAndRegister)
        req.addOperation(replicateAndRegister)
        req.addOperation(removeReplica)
        req.addOperation(removeFile)
        return req
コード例 #2
0
ファイル: IntegrationFCT.py プロジェクト: arrabito/TestDIRAC
  def buildRequest( self, owner, group, sourceSE, targetSE1, targetSE2 ):

    files = self.files( owner, group )

    putAndRegister = Operation()
    putAndRegister.Type = "PutAndRegister"
    putAndRegister.TargetSE = sourceSE
    for fname, lfn, size, checksum, guid in files:
      putFile = File()
      putFile.LFN = lfn
      putFile.PFN = fname
      putFile.Checksum = checksum
      putFile.ChecksumType = "adler32"
      putFile.Size = size
      putFile.GUID = guid
      putAndRegister.addFile( putFile )

    replicateAndRegister = Operation()
    replicateAndRegister.Type = "ReplicateAndRegister"
    replicateAndRegister.TargetSE = "%s,%s" % ( targetSE1, targetSE2 )
    for fname, lfn, size, checksum, guid in files:
      repFile = File()
      repFile.LFN = lfn
      repFile.Size = size
      repFile.Checksum = checksum
      repFile.ChecksumType = "adler32"
      replicateAndRegister.addFile( repFile )

    removeReplica = Operation()
    removeReplica.Type = "RemoveReplica"
    removeReplica.TargetSE = sourceSE
    for fname, lfn, size, checksum, guid in files:
      removeReplica.addFile( File( {"LFN": lfn } ) )

    removeFile = Operation()
    removeFile.Type = "RemoveFile"
    for fname, lfn, size, checksum, guid in files:
      removeFile.addFile( File( {"LFN": lfn } ) )

    removeFileInit = Operation()
    removeFileInit.Type = "RemoveFile"
    for fname, lfn, size, checksum, guid in files:
      removeFileInit.addFile( File( {"LFN": lfn } ) )

    req = Request()
    req.addOperation( removeFileInit )
    req.addOperation( putAndRegister )
    req.addOperation( replicateAndRegister )
    req.addOperation( removeReplica )
    req.addOperation( removeFile )
    return req
コード例 #3
0
    def _setFileReplicationRequest(self,
                                   lfn,
                                   targetSE,
                                   fileMetaDict,
                                   sourceSE=""):
        """Sets a registration request."""
        self.log.info("Setting ReplicateAndRegister request",
                      "for %s to %s" % (lfn, targetSE))

        transfer = Operation()
        transfer.Type = "ReplicateAndRegister"
        transfer.TargetSE = targetSE
        if sourceSE:
            transfer.SourceSE = sourceSE

        trFile = File()
        trFile.LFN = lfn

        cksm = fileMetaDict.get("Checksum", None)
        cksmType = fileMetaDict.get("ChecksumType", self.defaultChecksumType)
        if cksm and cksmType:
            trFile.Checksum = cksm
            trFile.ChecksumType = cksmType
        size = fileMetaDict.get("Size", 0)
        if size:
            trFile.Size = size
        guid = fileMetaDict.get("GUID", "")
        if guid:
            trFile.GUID = guid

        transfer.addFile(trFile)

        self.request.addOperation(transfer)

        return S_OK()
コード例 #4
0
ファイル: ModuleBase.py プロジェクト: antolu/LHCbDIRAC
  def setBKRegistrationRequest(self, lfn, error='',
                               metaData={'Checksum': 'justSomething',
                                         'ChecksumType': 'ADLER32',
                                         'GUID': 'aGUID'}):
    """ Set a BK registration request for changing the replica flag.
        Uses the global request object (self.request).
    """
    if error:
      self.log.info('BK registration for %s failed with message: "%s" setting failover request' % (lfn, error))
    else:
      self.log.info('Setting BK registration request for %s' % (lfn))

    regFile = Operation()
    regFile.Type = 'RegisterFile'
    regFile.Catalog = 'BookkeepingDB'

    bkFile = File()
    bkFile.LFN = lfn
    # this should NOT be needed... but RMS complains!
    bkFile.PFN = lfn
    bkFile.GUID = metaData['GUID']
    bkFile.Checksum = metaData['Checksum']
    bkFile.ChecksumType = metaData['ChecksumType']

    regFile.addFile(bkFile)
    res = self.request.addOperation(regFile)
    if not res['OK']:
      raise RuntimeError(res['Message'])
コード例 #5
0
    def getRegisterOperation(self,
                             opFile,
                             targetSE,
                             type='RegisterFile',
                             catalog=None):
        """ add RegisterReplica operation for file

    :param File opFile: operation file
    :param str targetSE: target SE
    """
        # # add RegisterReplica operation
        registerOperation = Operation()
        registerOperation.Type = type
        registerOperation.TargetSE = targetSE
        if catalog:
            registerOperation.Catalog = catalog

        registerFile = File()
        registerFile.LFN = opFile.LFN
        registerFile.PFN = StorageElement(targetSE).getPfnForLfn(
            opFile.LFN).get('Value', {}).get('Successful', {}).get(opFile.LFN)
        registerFile.GUID = opFile.GUID
        registerFile.Checksum = opFile.Checksum
        registerFile.ChecksumType = opFile.ChecksumType
        registerFile.Size = opFile.Size

        registerOperation.addFile(registerFile)
        return registerOperation
コード例 #6
0
def archiveRequestAndOp(listOfLFNs):
    """Return a tuple of the request and operation."""
    req = Request()
    req.RequestName = "MyRequest"
    op = Operation()
    switches = {}
    archiveLFN = "/vo/tars/myTar.tar"
    op.Arguments = DEncode.encode({
        "SourceSE":
        switches.get("SourceSE", "SOURCE-SE"),
        "TarballSE":
        switches.get("TarballSE", "TARBALL-SE"),
        "RegisterDescendent":
        False,
        "ArchiveLFN":
        archiveLFN,
    })
    op.Type = "ArchiveFiles"
    for index, lfn in enumerate(listOfLFNs):
        oFile = File()
        oFile.LFN = lfn
        oFile.Size = index
        oFile.Checksum = "01130a%0d" % index
        oFile.ChecksumType = "adler32"
        op.addFile(oFile)

    req.addOperation(op)
    return req, op
コード例 #7
0
    def getRegisterOperation(self, opFile, targetSE, type="RegisterFile", catalog=None):
        """add RegisterReplica operation for file

        :param ~DIRAC.RequestManagementSystem.Client.File.File opFile: operation file
        :param str targetSE: target SE
        """
        # # add RegisterReplica operation
        registerOperation = Operation()
        registerOperation.Type = type
        registerOperation.TargetSE = targetSE
        if catalog:
            registerOperation.Catalog = catalog

        registerFile = File()
        registerFile.LFN = opFile.LFN
        registerFile.PFN = (
            StorageElement(targetSE)
            .getURL(opFile.LFN, protocol=self.registrationProtocols)
            .get("Value", {})
            .get("Successful", {})
            .get(opFile.LFN)
        )
        registerFile.GUID = opFile.GUID
        registerFile.Checksum = opFile.Checksum
        registerFile.ChecksumType = opFile.ChecksumType
        registerFile.Size = opFile.Size

        registerOperation.addFile(registerFile)
        return registerOperation
コード例 #8
0
ファイル: FailoverTransfer.py プロジェクト: graciani/DIRAC
  def __setFileReplicationRequest( self, lfn, targetSE, fileMetaDict, sourceSE = '' ):
    """ Sets a registration request.
    """
    self.log.info( 'Setting replication request for %s to %s' % ( lfn, targetSE ) )

    transfer = Operation()
    transfer.Type = "ReplicateAndRegister"
    transfer.TargetSE = targetSE
    if sourceSE:
      transfer.SourceSE = sourceSE

    trFile = File()
    trFile.LFN = lfn

    cksm = fileMetaDict.get( "Checksum", None )
    cksmType = fileMetaDict.get( "ChecksumType", None )
    if cksm and cksmType:
      trFile.Checksum = cksm
      trFile.ChecksumType = cksmType
    size = fileMetaDict.get( "Size", 0 )
    if size:
      trFile.Size = size
    guid = fileMetaDict.get( "GUID", "" )
    if guid:
      trFile.GUID = guid

    transfer.addFile( trFile )

    self.request.addOperation( transfer )

    return S_OK()
コード例 #9
0
 def __submitRMSOp(self, target_se, lfns_chunk_dict, whichRMSOp='ReplicateAndRegister' ):
     """ target_se : SE name to which to replicate
         lfns_chunk_dict : LFNS dict with 100 lfns as key andeEach lfn has 'Size', 'Checksum'
         whichRMSOp: Choose from RMP operation - ReplicateAndRegister, ReplicateAndRemove, PutAndRegister
         """
 
     ## Setup request
     request = Request()
     request.RequestName = "DDM_"+ str(target_se) +  datetime.datetime.now().strftime("_%Y%m%d_%H%M%S")
     myOp = Operation()
     myOp.Type = whichRMSOp
     myOp.TargetSE = target_se
     ## Add LFNS to operations
     for lfn in lfns_chunk_dict.keys():
         opFile = File()
         opFile.LFN = lfn
         opFile.Size = lfns_chunk_dict[lfn]['Size']
         if "Checksum" in lfns_chunk_dict[lfn]:
             opFile.Checksum = lfns_chunk_dict[lfn]['Checksum']
             opFile.ChecksumType = 'ADLER32'
             ## Add file to operation
             myOp.addFile( opFile )
 
     request.addOperation( myOp )
     reqClient = ReqClient()
     putRequest = reqClient.putRequest( request )
     if not putRequest["OK"]:
         gLogger.error( "Unable to put request '%s': %s" % ( request.RequestName, putRequest["Message"] ) )
         return S_ERROR("Problem submitting to RMS.")
コード例 #10
0
ファイル: FailoverTransfer.py プロジェクト: msapunov/DIRAC
  def __setRegistrationRequest( self, lfn, targetSE, fileDict, catalog ):
    """ Sets a registration request

    :param str lfn: LFN
    :param list se: list of SE
    :param list catalog: list of catalogs to use
    :param dict fileDict: file metadata
    """
    self.log.info( 'Setting registration request for %s at %s.' % ( lfn, targetSE ) )

    for cat in catalog:

      register = Operation()
      register.Type = "RegisterFile"
      register.Catalog = cat
      register.TargetSE = targetSE

      regFile = File()
      regFile.LFN = lfn
      regFile.Checksum = fileDict.get( "Checksum", "" )
      regFile.ChecksumType = fileDict.get( "ChecksumType", "" )
      regFile.Size = fileDict.get( "Size", 0 )
      regFile.GUID = fileDict.get( "GUID", "" )

      se = StorageElement( targetSE )
      pfn = se.getPfnForLfn( lfn )
      if not pfn["OK"]:
        self.log.error( "unable to get PFN for LFN: %s" % pfn["Message"] )
        return pfn
      regFile.PFN = pfn["Value"]

      register.addFile( regFile )
      self.request.addOperation( register )

    return S_OK()
コード例 #11
0
def archiveRequestAndOp(listOfLFNs):
    """Return a tuple of the request and operation."""
    req = Request()
    req.RequestName = 'MyRequest'
    op = Operation()
    switches = {}
    archiveLFN = '/vo/tars/myTar.tar'
    op.Arguments = DEncode.encode({
        'SourceSE':
        switches.get('SourceSE', 'SOURCE-SE'),
        'TarballSE':
        switches.get('TarballSE', 'TARBALL-SE'),
        'RegisterDescendent':
        False,
        'ArchiveLFN':
        archiveLFN
    })
    op.Type = 'ArchiveFiles'
    for index, lfn in enumerate(listOfLFNs):
        oFile = File()
        oFile.LFN = lfn
        oFile.Size = index
        oFile.Checksum = '01130a%0d' % index
        oFile.ChecksumType = 'adler32'
        op.addFile(oFile)

    req.addOperation(op)
    return req, op
コード例 #12
0
def checkRequestAndOp(listOfLFNs):
    req = Request()
    req.RequestName = 'MyRequest'
    op = Operation()
    op.Type = 'CheckMigration'
    for index, lfn in enumerate(listOfLFNs):
        oFile = File()
        oFile.LFN = lfn
        oFile.Size = index
        oFile.Checksum = '01130a%0d' % index
        oFile.ChecksumType = 'adler32'
        op.addFile(oFile)
    req.addOperation(op)
    return req, op
コード例 #13
0
ファイル: FileTests.py プロジェクト: sbel/bes3-jinr
  def test02props( self ):
    """ test props and attributes  """
    theFile = File()

    # valid props
    theFile.FileID = 1
    self.assertEqual( theFile.FileID, 1 )
    theFile.Status = "Done"
    self.assertEqual( theFile.Status, "Done" )
    theFile.LFN = "/some/path/somewhere"
    self.assertEqual( theFile.LFN, "/some/path/somewhere" )
    theFile.PFN = "/some/path/somewhere"
    self.assertEqual( theFile.PFN, "/some/path/somewhere" )
    theFile.Attempt = 1
    self.assertEqual( theFile.Attempt, 1 )
    theFile.Size = 1
    self.assertEqual( theFile.Size, 1 )
    theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66"
    self.assertEqual( theFile.GUID, "2bbabe80-e2f1-11e1-9b23-0800200c9a66" )
    theFile.ChecksumType = "adler32"
    self.assertEqual( theFile.ChecksumType, "ADLER32" )
    theFile.Checksum = "123456"
    self.assertEqual( theFile.Checksum, "123456" )

    # #
    theFile.Checksum = None
    theFile.ChecksumType = None
    self.assertEqual( theFile.Checksum, "" )
    self.assertEqual( theFile.ChecksumType, "" )

    # # invalid props

    # FileID
    try:
      theFile.FileID = "foo"
    except Exception, error:
      self.assertEqual( isinstance( error, ValueError ), True )
コード例 #14
0
ファイル: FileTests.py プロジェクト: ptakha/DIRAC-1
    def test02props(self):
        """ test props and attributes  """
        theFile = File()

        # valid props
        theFile.FileID = 1
        self.assertEqual(theFile.FileID, 1)
        theFile.Status = "Done"
        self.assertEqual(theFile.Status, "Done")
        theFile.LFN = "/some/path/somewhere"
        self.assertEqual(theFile.LFN, "/some/path/somewhere")
        theFile.PFN = "/some/path/somewhere"
        self.assertEqual(theFile.PFN, "/some/path/somewhere")
        theFile.Attempt = 1
        self.assertEqual(theFile.Attempt, 1)
        theFile.Size = 1
        self.assertEqual(theFile.Size, 1)
        theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66"
        self.assertEqual(theFile.GUID, "2bbabe80-e2f1-11e1-9b23-0800200c9a66")
        theFile.ChecksumType = "adler32"
        self.assertEqual(theFile.ChecksumType, "ADLER32")
        theFile.Checksum = "123456"
        self.assertEqual(theFile.Checksum, "123456")

        # #
        theFile.Checksum = None
        theFile.ChecksumType = None
        self.assertEqual(theFile.Checksum, "")
        self.assertEqual(theFile.ChecksumType, "")

        # # invalid props

        # FileID
        try:
            theFile.FileID = "foo"
        except Exception, error:
            self.assertEqual(isinstance(error, ValueError), True)
コード例 #15
0
def checkRequestAndOp(listOfLFNs):
    req = Request()
    req.RequestName = "MyRequest"
    op = Operation()
    op.Type = "CheckMigration"
    op.TargetSE = "Foo-SE"
    for index, lfn in enumerate(listOfLFNs):
        oFile = File()
        oFile.LFN = lfn
        oFile.Size = index
        oFile.Checksum = "01130a%0d" % index
        oFile.ChecksumType = "adler32"
        op.addFile(oFile)
    req.addOperation(op)
    return req, op
コード例 #16
0
ファイル: FailoverTransfer.py プロジェクト: ptakha/DIRAC-1
    def _setRegistrationRequest(self, lfn, targetSE, fileDict, catalog):
        """ Sets a registration request

    :param str lfn: LFN
    :param list se: list of SE (or just string)
    :param list catalog: list (or string) of catalogs to use
    :param dict fileDict: file metadata
    """
        self.log.info('Setting registration request for %s at %s.' %
                      (lfn, targetSE))

        if not type(catalog) == type([]):
            catalog = [catalog]

        for cat in catalog:

            register = Operation()
            register.Type = "RegisterFile"
            register.Catalog = cat
            register.TargetSE = targetSE

            regFile = File()
            regFile.LFN = lfn
            regFile.Checksum = fileDict.get("Checksum", "")
            regFile.ChecksumType = fileDict.get("ChecksumType",
                                                self.defaultChecksumType)
            regFile.Size = fileDict.get("Size", 0)
            regFile.GUID = fileDict.get("GUID", "")

            se = StorageElement(targetSE)
            pfn = se.getPfnForLfn(lfn)
            if not pfn["OK"] or lfn not in pfn["Value"]['Successful']:
                self.log.error(
                    "unable to get PFN for LFN: %s" %
                    pfn.get('Message',
                            pfn.get('Value', {}).get('Failed', {}).get(lfn)))
                return pfn
            regFile.PFN = pfn["Value"]['Successful'][lfn]

            register.addFile(regFile)
            self.request.addOperation(register)

        return S_OK()
コード例 #17
0
    def _setRegistrationRequest(self, lfn, targetSE, fileDict, catalog):
        """Sets a registration request

        :param str lfn: LFN
        :param list se: list of SE (or just string)
        :param list catalog: list (or string) of catalogs to use
        :param dict fileDict: file metadata
        """
        self.log.info("Setting registration request",
                      "for %s at %s." % (lfn, targetSE))

        if not isinstance(catalog, list):
            catalog = [catalog]

        for cat in catalog:

            register = Operation()
            register.Type = "RegisterFile"
            register.Catalog = cat
            register.TargetSE = targetSE

            regFile = File()
            regFile.LFN = lfn
            regFile.Checksum = fileDict.get("Checksum", "")
            regFile.ChecksumType = fileDict.get("ChecksumType",
                                                self.defaultChecksumType)
            regFile.Size = fileDict.get("Size", 0)
            regFile.GUID = fileDict.get("GUID", "")

            se = StorageElement(targetSE)
            res = returnSingleResult(se.getURL(lfn,
                                               self.registrationProtocols))
            if not res["OK"]:
                self.log.error("Unable to get PFN for LFN", res["Message"])
                return res
            regFile.PFN = res["Value"]

            register.addFile(regFile)
            self.request.addOperation(register)

        return S_OK()
コード例 #18
0
def test_valid_properties():
    theFile = File()

    theFile.FileID = 1
    assert theFile.FileID == 1
    theFile.Status = "Done"
    assert theFile.Status == "Done"
    theFile.LFN = "/some/path/somewhere"
    assert theFile.LFN == "/some/path/somewhere"
    theFile.PFN = "/some/path/somewhere"
    assert theFile.PFN == "/some/path/somewhere"
    theFile.Attempt = 1
    assert theFile.Attempt == 1
    theFile.Size = 1
    assert theFile.Size == 1
    theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66"
    assert theFile.GUID == "2bbabe80-e2f1-11e1-9b23-0800200c9a66"
    theFile.ChecksumType = "adler32"
    assert theFile.ChecksumType == "ADLER32"
    theFile.Checksum = "123456"
    assert theFile.Checksum == "123456"
コード例 #19
0
    def getRegisterOperation(self, opFile, targetSE):
        """ add RegisterReplica operation for file

    :param File opFile: operation file
    :param str targetSE: target SE
    """
        # # add RegisterReplica operation
        registerOperation = Operation()
        registerOperation.Type = "RegisterFile"
        registerOperation.TargetSE = targetSE

        registerFile = File()
        registerFile.LFN = opFile.LFN
        registerFile.PFN = opFile.PFN
        registerFile.GUID = opFile.GUID
        registerFile.Checksum = opFile.Checksum
        registerFile.ChecksumType = opFile.ChecksumType
        registerFile.Size = opFile.Size

        registerOperation.addFile(registerFile)
        return registerOperation
コード例 #20
0
  def getRegisterOperation( self, opFile, targetSE ):
    """ add RegisterReplica operation for file

    :param File opFile: operation file
    :param str targetSE: target SE
    """
    # # add RegisterReplica operation
    registerOperation = Operation()
    registerOperation.Type = "RegisterFile"
    registerOperation.TargetSE = targetSE

    registerFile = File()
    registerFile.LFN = opFile.LFN
    registerFile.PFN = opFile.PFN
    registerFile.GUID = opFile.GUID
    registerFile.Checksum = opFile.Checksum
    registerFile.ChecksumType = opFile.ChecksumType
    registerFile.Size = opFile.Size

    registerOperation.addFile( registerFile )
    return registerOperation
コード例 #21
0
  def addRegisterReplica( self, opFile, targetSE ):
    """ add RegisterReplica operation for file

    :param File opFile: operation file
    :param str targetSE: target SE
    """
    # # add RegisterReplica operation
    registerOperation = Operation()
    registerOperation.Type = "RegisterFile"
    registerOperation.TargetSE = targetSE

    registerFile = File()
    registerFile.LFN = opFile.LFN
    registerFile.PFN = opFile.PFN
    registerFile.GUID = opFile.GUID
    registerFile.Checksum = opFile.Checksum
    registerFile.ChecksumType = opFile.ChecksumType
    registerFile.Size = opFile.Size

    registerOperation.addFile( registerFile )
    self.request.insertAfter( registerOperation, self.operation )
    return S_OK()
コード例 #22
0
    def addRegisterReplica(self, opFile, targetSE):
        """ add RegisterReplica operation for file

    :param File opFile: operation file
    :param str targetSE: target SE
    """
        # # add RegisterReplica operation
        registerOperation = Operation()
        registerOperation.Type = "RegisterFile"
        registerOperation.TargetSE = targetSE

        registerFile = File()
        registerFile.LFN = opFile.LFN
        registerFile.PFN = opFile.PFN
        registerFile.GUID = opFile.GUID
        registerFile.Checksum = opFile.Checksum
        registerFile.ChecksumType = opFile.ChecksumType
        registerFile.Size = opFile.Size

        registerOperation.addFile(registerFile)
        self.request.insertAfter(registerOperation, self.operation)
        return S_OK()
コード例 #23
0
    def addLFNs(self, operation, lfns, addPFN=False):
        """Add lfns to operation.

        :param operation: the operation instance to which the files will be added
        :param list lfns: list of lfns
        :param bool addPFN: if true adds PFN to each File
        """
        if not self.metaData:
            self.getLFNMetadata()

        for lfn in lfns:
            metaDict = self.metaData["Successful"][lfn]
            opFile = File()
            opFile.LFN = lfn
            if addPFN:
                opFile.PFN = lfn
            opFile.Size = metaDict["Size"]
            if "Checksum" in metaDict:
                # should check checksum type, now assuming Adler32 (metaDict['ChecksumType'] = 'AD')
                opFile.Checksum = metaDict["Checksum"]
                opFile.ChecksumType = "ADLER32"
            operation.addFile(opFile)
コード例 #24
0
  def _setRegistrationRequest( self, lfn, targetSE, fileDict, catalog ):
    """ Sets a registration request

    :param str lfn: LFN
    :param list se: list of SE (or just string)
    :param list catalog: list (or string) of catalogs to use
    :param dict fileDict: file metadata
    """
    self.log.info( 'Setting registration request for %s at %s.' % ( lfn, targetSE ) )

    if not isinstance( catalog, list ):
      catalog = [catalog]

    for cat in catalog:

      register = Operation()
      register.Type = "RegisterFile"
      register.Catalog = cat
      register.TargetSE = targetSE

      regFile = File()
      regFile.LFN = lfn
      regFile.Checksum = fileDict.get( "Checksum", "" )
      regFile.ChecksumType = fileDict.get( "ChecksumType", self.defaultChecksumType )
      regFile.Size = fileDict.get( "Size", 0 )
      regFile.GUID = fileDict.get( "GUID", "" )

      se = StorageElement( targetSE )
      pfn = se.getURL( lfn, self.registrationProtocols )
      if not pfn["OK"] or lfn not in pfn["Value"]['Successful']:
        self.log.error( "Unable to get PFN for LFN", "%s" % pfn.get( 'Message', pfn.get( 'Value', {} ).get( 'Failed', {} ).get( lfn ) ) )
        return pfn
      regFile.PFN = pfn["Value"]['Successful'][lfn]

      register.addFile( regFile )
      self.request.addOperation( register )

    return S_OK()
コード例 #25
0
  def getRegisterOperation( self, opFile, targetSE, type = 'RegisterFile', catalog = None ):
    """ add RegisterReplica operation for file

    :param File opFile: operation file
    :param str targetSE: target SE
    """
    # # add RegisterReplica operation
    registerOperation = Operation()
    registerOperation.Type = type
    registerOperation.TargetSE = targetSE
    if catalog:
      registerOperation.Catalog = catalog

    registerFile = File()
    registerFile.LFN = opFile.LFN
    registerFile.PFN = StorageElement( targetSE ).getURL( opFile.LFN, protocol = self.registrationProtocols ).get( 'Value', {} ).get( 'Successful', {} ).get( opFile.LFN )
    registerFile.GUID = opFile.GUID
    registerFile.Checksum = opFile.Checksum
    registerFile.ChecksumType = opFile.ChecksumType
    registerFile.Size = opFile.Size

    registerOperation.addFile( registerFile )
    return registerOperation
コード例 #26
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(" sourceSE:   source SE")
    Script.registerArgument(" LFN:        LFN or file containing a List of LFNs")
    Script.registerArgument(["targetSE:   target SEs"])
    Script.parseCommandLine()

    import DIRAC
    from DIRAC import gLogger

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    args = Script.getPositionalArgs()

    sourceSE = args[0]
    lfnList = getLFNList(args[1])
    targetSEs = list(set([se for targetSE in args[2:] for se in targetSE.split(",")]))

    gLogger.info(
        "Will create request with 'MoveReplica' "
        "operation using %s lfns and %s target SEs" % (len(lfnList), len(targetSEs))
    )

    from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
    from DIRAC.RequestManagementSystem.Client.Request import Request
    from DIRAC.RequestManagementSystem.Client.Operation import Operation
    from DIRAC.RequestManagementSystem.Client.File import File
    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
    from DIRAC.Core.Utilities.List import breakListIntoChunks

    lfnChunks = breakListIntoChunks(lfnList, 100)
    multiRequests = len(lfnChunks) > 1

    error = 0
    count = 0
    reqClient = ReqClient()
    fc = FileCatalog()
    for lfnChunk in lfnChunks:
        metaDatas = fc.getFileMetadata(lfnChunk)
        if not metaDatas["OK"]:
            gLogger.error("unable to read metadata for lfns: %s" % metaDatas["Message"])
            error = -1
            continue
        metaDatas = metaDatas["Value"]
        for failedLFN, reason in metaDatas["Failed"].items():
            gLogger.error("skipping %s: %s" % (failedLFN, reason))
        lfnChunk = set(metaDatas["Successful"])

        if not lfnChunk:
            gLogger.error("LFN list is empty!!!")
            error = -1
            continue

        if len(lfnChunk) > Operation.MAX_FILES:
            gLogger.error("too many LFNs, max number of files per operation is %s" % Operation.MAX_FILES)
            error = -1
            continue

        count += 1

        request = Request()
        request.RequestName = "%s_%s" % (
            md5(repr(time.time()).encode()).hexdigest()[:16],
            md5(repr(time.time()).encode()).hexdigest()[:16],
        )

        moveReplica = Operation()
        moveReplica.Type = "MoveReplica"
        moveReplica.SourceSE = sourceSE
        moveReplica.TargetSE = ",".join(targetSEs)

        for lfn in lfnChunk:
            metaDict = metaDatas["Successful"][lfn]
            opFile = File()
            opFile.LFN = lfn
            opFile.Size = metaDict["Size"]

            if "Checksum" in metaDict:
                # # should check checksum type, now assuming Adler32 (metaDict["ChecksumType"] = 'AD'
                opFile.Checksum = metaDict["Checksum"]
                opFile.ChecksumType = "ADLER32"
            moveReplica.addFile(opFile)

        request.addOperation(moveReplica)

        result = reqClient.putRequest(request)
        if not result["OK"]:
            gLogger.error("Failed to submit Request: %s" % (result["Message"]))
            error = -1
            continue

        if not multiRequests:
            gLogger.always("Request %d submitted successfully" % result["Value"])

    if multiRequests:
        gLogger.always("%d requests have been submitted" % (count))
    DIRAC.exit(error)
コード例 #27
0
def main():
    catalog = None
    Script.registerSwitch("C:", "Catalog=", "Catalog to use")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(" requestName:  a request name")
    Script.registerArgument(" LFNs:         single LFN or file with LFNs")
    Script.registerArgument(["targetSE:     target SE"])
    Script.parseCommandLine()
    for switch in Script.getUnprocessedSwitches():
        if switch[0] == "C" or switch[0].lower() == "catalog":
            catalog = switch[1]

    args = Script.getPositionalArgs()

    requestName = None
    targetSEs = None
    if len(args) < 3:
        Script.showHelp(exitCode=1)

    requestName = args[0]
    lfnList = getLFNList(args[1])
    targetSEs = list(
        set([se for targetSE in args[2:] for se in targetSE.split(",")]))

    gLogger.info("Will create request '%s' with 'ReplicateAndRegister' "
                 "operation using %s lfns and %s target SEs" %
                 (requestName, len(lfnList), len(targetSEs)))

    from DIRAC.RequestManagementSystem.Client.Request import Request
    from DIRAC.RequestManagementSystem.Client.Operation import Operation
    from DIRAC.RequestManagementSystem.Client.File import File
    from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
    from DIRAC.Core.Utilities.List import breakListIntoChunks

    lfnChunks = breakListIntoChunks(lfnList, 100)
    multiRequests = len(lfnChunks) > 1

    error = 0
    count = 0
    reqClient = ReqClient()
    fc = FileCatalog()
    requestIDs = []
    for lfnChunk in lfnChunks:
        metaDatas = fc.getFileMetadata(lfnChunk)
        if not metaDatas["OK"]:
            gLogger.error("unable to read metadata for lfns: %s" %
                          metaDatas["Message"])
            error = -1
            continue
        metaDatas = metaDatas["Value"]
        for failedLFN, reason in metaDatas["Failed"].items():
            gLogger.error("skipping %s: %s" % (failedLFN, reason))
        lfnChunk = set(metaDatas["Successful"])

        if not lfnChunk:
            gLogger.error("LFN list is empty!!!")
            error = -1
            continue

        if len(lfnChunk) > Operation.MAX_FILES:
            gLogger.error(
                "too many LFNs, max number of files per operation is %s" %
                Operation.MAX_FILES)
            error = -1
            continue

        count += 1
        request = Request()
        request.RequestName = requestName if not multiRequests else "%s_%d" % (
            requestName, count)

        replicateAndRegister = Operation()
        replicateAndRegister.Type = "ReplicateAndRegister"
        replicateAndRegister.TargetSE = ",".join(targetSEs)
        if catalog is not None:
            replicateAndRegister.Catalog = catalog

        for lfn in lfnChunk:
            metaDict = metaDatas["Successful"][lfn]
            opFile = File()
            opFile.LFN = lfn
            opFile.Size = metaDict["Size"]

            if "Checksum" in metaDict:
                # # should check checksum type, now assuming Adler32 (metaDict["ChecksumType"] = 'AD'
                opFile.Checksum = metaDict["Checksum"]
                opFile.ChecksumType = "ADLER32"
            replicateAndRegister.addFile(opFile)

        request.addOperation(replicateAndRegister)

        putRequest = reqClient.putRequest(request)
        if not putRequest["OK"]:
            gLogger.error("unable to put request '%s': %s" %
                          (request.RequestName, putRequest["Message"]))
            error = -1
            continue
        requestIDs.append(str(putRequest["Value"]))
        if not multiRequests:
            gLogger.always(
                "Request '%s' has been put to ReqDB for execution." %
                request.RequestName)

    if multiRequests:
        gLogger.always(
            "%d requests have been put to ReqDB for execution, with name %s_<num>"
            % (count, requestName))
    if requestIDs:
        gLogger.always("RequestID(s): %s" % " ".join(requestIDs))
    gLogger.always(
        "You can monitor requests' status using command: 'dirac-rms-request <requestName/ID>'"
    )
    DIRAC.exit(error)
コード例 #28
0
    replicateAndRegister = Operation()
    replicateAndRegister.Type = "ReplicateAndRegister"
    replicateAndRegister.TargetSE = ",".join( targetSEs )
    if catalog is not None:
      replicateAndRegister.Catalog = catalog

    for lfn in lfnChunk:
      metaDict = metaDatas["Successful"][lfn]
      opFile = File()
      opFile.LFN = lfn
      opFile.Size = metaDict["Size"]

      if "Checksum" in metaDict:
        # # should check checksum type, now assuming Adler32 (metaDict["ChecksumType"] = 'AD'
        opFile.Checksum = metaDict["Checksum"]
        opFile.ChecksumType = "ADLER32"
      replicateAndRegister.addFile( opFile )

    request.addOperation( replicateAndRegister )

    putRequest = reqClient.putRequest( request )
    if not putRequest["OK"]:
      gLogger.error( "unable to put request '%s': %s" % ( request.RequestName, putRequest["Message"] ) )
      error = -1
      continue
    requestIDs.append( str( putRequest["Value"] ) )
    if not multiRequests:
      gLogger.always( "Request '%s' has been put to ReqDB for execution." % request.RequestName )

  if multiRequests:
    gLogger.always( "%d requests have been put to ReqDB for execution, with name %s_<num>" % ( count, requestName ) )
コード例 #29
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("requestName:  a request name")
    Script.registerArgument("LFN:          logical file name")
    Script.registerArgument("localFile:    local file you want to put")
    Script.registerArgument("targetSE:     target SE")
    Script.parseCommandLine()

    import DIRAC
    from DIRAC import gLogger

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    requestName, LFN, PFN, targetSE = Script.getPositionalArgs(group=True)

    if not os.path.isabs(LFN):
        gLogger.error("LFN should be absolute path!!!")
        DIRAC.exit(-1)

    gLogger.info("will create request '%s' with 'PutAndRegister' "
                 "operation using %s pfn and %s target SE" %
                 (requestName, PFN, targetSE))

    from DIRAC.RequestManagementSystem.Client.Request import Request
    from DIRAC.RequestManagementSystem.Client.Operation import Operation
    from DIRAC.RequestManagementSystem.Client.File import File
    from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
    from DIRAC.Core.Utilities.Adler import fileAdler

    if not os.path.exists(PFN):
        gLogger.error("%s does not exist" % PFN)
        DIRAC.exit(-1)
    if not os.path.isfile(PFN):
        gLogger.error("%s is not a file" % PFN)
        DIRAC.exit(-1)

    PFN = os.path.abspath(PFN)
    size = os.path.getsize(PFN)
    adler32 = fileAdler(PFN)

    request = Request()
    request.RequestName = requestName

    putAndRegister = Operation()
    putAndRegister.Type = "PutAndRegister"
    putAndRegister.TargetSE = targetSE
    opFile = File()
    opFile.LFN = LFN
    opFile.PFN = PFN
    opFile.Size = size
    opFile.Checksum = adler32
    opFile.ChecksumType = "ADLER32"
    putAndRegister.addFile(opFile)
    request.addOperation(putAndRegister)
    reqClient = ReqClient()
    putRequest = reqClient.putRequest(request)
    if not putRequest["OK"]:
        gLogger.error("unable to put request '%s': %s" %
                      (requestName, putRequest["Message"]))
        DIRAC.exit(-1)

    gLogger.always("Request '%s' has been put to ReqDB for execution." %
                   requestName)
    gLogger.always(
        "You can monitor its status using command: 'dirac-rms-request %s'" %
        requestName)
    DIRAC.exit(0)
コード例 #30
0
        replicateAndRegister = Operation()
        replicateAndRegister.Type = "ReplicateAndRegister"
        replicateAndRegister.TargetSE = ",".join(targetSEs)
        if catalog is not None:
            replicateAndRegister.Catalog = catalog

        for lfn in lfnChunk:
            metaDict = metaDatas["Successful"][lfn]
            opFile = File()
            opFile.LFN = lfn
            opFile.Size = metaDict["Size"]

            if "Checksum" in metaDict:
                # # should check checksum type, now assuming Adler32 (metaDict["ChecksumType"] = 'AD'
                opFile.Checksum = metaDict["Checksum"]
                opFile.ChecksumType = "ADLER32"
            replicateAndRegister.addFile(opFile)

        request.addOperation(replicateAndRegister)

        putRequest = reqClient.putRequest(request)
        if not putRequest["OK"]:
            gLogger.error("unable to put request '%s': %s" %
                          (request.RequestName, putRequest["Message"]))
            error = -1
            continue
        requestIDs.append(str(putRequest["Value"]))
        if not multiRequests:
            gLogger.always(
                "Request '%s' has been put to ReqDB for execution." %
                request.RequestName)
コード例 #31
0
def main():
    from DIRAC.Core.Base.Script import parseCommandLine
    parseCommandLine()

    import DIRAC
    from DIRAC import gLogger

    args = Script.getPositionalArgs()

    requestName = None
    LFN = None
    PFN = None
    targetSE = None
    if len(args) != 4:
        Script.showHelp()
    else:
        requestName = args[0]
        LFN = args[1]
        PFN = args[2]
        targetSE = args[3]

    if not os.path.isabs(LFN):
        gLogger.error("LFN should be absolute path!!!")
        DIRAC.exit(-1)

    gLogger.info("will create request '%s' with 'PutAndRegister' "
                 "operation using %s pfn and %s target SE" %
                 (requestName, PFN, targetSE))

    from DIRAC.RequestManagementSystem.Client.Request import Request
    from DIRAC.RequestManagementSystem.Client.Operation import Operation
    from DIRAC.RequestManagementSystem.Client.File import File
    from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
    from DIRAC.Core.Utilities.Adler import fileAdler

    if not os.path.exists(PFN):
        gLogger.error("%s does not exist" % PFN)
        DIRAC.exit(-1)
    if not os.path.isfile(PFN):
        gLogger.error("%s is not a file" % PFN)
        DIRAC.exit(-1)

    PFN = os.path.abspath(PFN)
    size = os.path.getsize(PFN)
    adler32 = fileAdler(PFN)

    request = Request()
    request.RequestName = requestName

    putAndRegister = Operation()
    putAndRegister.Type = "PutAndRegister"
    putAndRegister.TargetSE = targetSE
    opFile = File()
    opFile.LFN = LFN
    opFile.PFN = PFN
    opFile.Size = size
    opFile.Checksum = adler32
    opFile.ChecksumType = "ADLER32"
    putAndRegister.addFile(opFile)
    request.addOperation(putAndRegister)
    reqClient = ReqClient()
    putRequest = reqClient.putRequest(request)
    if not putRequest["OK"]:
        gLogger.error("unable to put request '%s': %s" %
                      (requestName, putRequest["Message"]))
        DIRAC.exit(-1)

    gLogger.always("Request '%s' has been put to ReqDB for execution." %
                   requestName)
    gLogger.always(
        "You can monitor its status using command: 'dirac-rms-request %s'" %
        requestName)
    DIRAC.exit(0)
コード例 #32
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(" SE:   StorageElement|All")
    Script.registerArgument(["LFN:  LFN or file containing a List of LFNs"])
    Script.parseCommandLine(ignoreErrors=False)

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    args = Script.getPositionalArgs()

    targetSE = args.pop(0)

    lfns = []
    for inputFileName in args:
        if os.path.exists(inputFileName):
            with open(inputFileName, "r") as inputFile:
                string = inputFile.read()
            lfns.extend([lfn.strip() for lfn in string.splitlines()])
        else:
            lfns.append(inputFileName)

    from DIRAC.Resources.Storage.StorageElement import StorageElement
    import DIRAC

    # Check is provided SE is OK
    if targetSE != "All":
        se = StorageElement(targetSE)
        if not se.valid:
            print(se.errorReason)
            print()
            Script.showHelp()

    from DIRAC.RequestManagementSystem.Client.Request import Request
    from DIRAC.RequestManagementSystem.Client.Operation import Operation
    from DIRAC.RequestManagementSystem.Client.File import File
    from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
    from DIRAC.RequestManagementSystem.private.RequestValidator import RequestValidator
    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    reqClient = ReqClient()
    fc = FileCatalog()

    requestOperation = "RemoveReplica"
    if targetSE == "All":
        requestOperation = "RemoveFile"

    for lfnList in breakListIntoChunks(lfns, 100):

        oRequest = Request()
        requestName = "%s_%s" % (
            md5(repr(time.time()).encode()).hexdigest()[:16],
            md5(repr(time.time()).encode()).hexdigest()[:16],
        )
        oRequest.RequestName = requestName

        oOperation = Operation()
        oOperation.Type = requestOperation
        oOperation.TargetSE = targetSE

        res = fc.getFileMetadata(lfnList)
        if not res["OK"]:
            print("Can't get file metadata: %s" % res["Message"])
            DIRAC.exit(1)
        if res["Value"]["Failed"]:
            print(
                "Could not get the file metadata of the following, so skipping them:"
            )
            for fFile in res["Value"]["Failed"]:
                print(fFile)

        lfnMetadata = res["Value"]["Successful"]

        for lfn in lfnMetadata:
            rarFile = File()
            rarFile.LFN = lfn
            rarFile.Size = lfnMetadata[lfn]["Size"]
            rarFile.Checksum = lfnMetadata[lfn]["Checksum"]
            rarFile.GUID = lfnMetadata[lfn]["GUID"]
            rarFile.ChecksumType = "ADLER32"
            oOperation.addFile(rarFile)

        oRequest.addOperation(oOperation)

        isValid = RequestValidator().validate(oRequest)
        if not isValid["OK"]:
            print("Request is not valid: ", isValid["Message"])
            DIRAC.exit(1)

        result = reqClient.putRequest(oRequest)
        if result["OK"]:
            print("Request %d Submitted" % result["Value"])
        else:
            print("Failed to submit Request: ", result["Message"])
コード例 #33
0
def main():
    Script.parseCommandLine(ignoreErrors=False)

    args = Script.getPositionalArgs()
    if len(args) < 2:
        Script.showHelp()

    targetSE = args.pop(0)

    lfns = []
    for inputFileName in args:
        if os.path.exists(inputFileName):
            inputFile = open(inputFileName, 'r')
            string = inputFile.read()
            inputFile.close()
            lfns.extend([lfn.strip() for lfn in string.splitlines()])
        else:
            lfns.append(inputFileName)

    from DIRAC.Resources.Storage.StorageElement import StorageElement
    import DIRAC
    # Check is provided SE is OK
    if targetSE != 'All':
        se = StorageElement(targetSE)
        if not se.valid:
            print(se.errorReason)
            print()
            Script.showHelp()

    from DIRAC.RequestManagementSystem.Client.Request import Request
    from DIRAC.RequestManagementSystem.Client.Operation import Operation
    from DIRAC.RequestManagementSystem.Client.File import File
    from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
    from DIRAC.RequestManagementSystem.private.RequestValidator import RequestValidator
    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    reqClient = ReqClient()
    fc = FileCatalog()

    requestOperation = 'RemoveReplica'
    if targetSE == 'All':
        requestOperation = 'RemoveFile'

    for lfnList in breakListIntoChunks(lfns, 100):

        oRequest = Request()
        requestName = "%s_%s" % (
            md5(repr(time.time()).encode()).hexdigest()[:16],
            md5(repr(time.time()).encode()).hexdigest()[:16],
        )
        oRequest.RequestName = requestName

        oOperation = Operation()
        oOperation.Type = requestOperation
        oOperation.TargetSE = targetSE

        res = fc.getFileMetadata(lfnList)
        if not res['OK']:
            print("Can't get file metadata: %s" % res['Message'])
            DIRAC.exit(1)
        if res['Value']['Failed']:
            print(
                "Could not get the file metadata of the following, so skipping them:"
            )
            for fFile in res['Value']['Failed']:
                print(fFile)

        lfnMetadata = res['Value']['Successful']

        for lfn in lfnMetadata:
            rarFile = File()
            rarFile.LFN = lfn
            rarFile.Size = lfnMetadata[lfn]['Size']
            rarFile.Checksum = lfnMetadata[lfn]['Checksum']
            rarFile.GUID = lfnMetadata[lfn]['GUID']
            rarFile.ChecksumType = 'ADLER32'
            oOperation.addFile(rarFile)

        oRequest.addOperation(oOperation)

        isValid = RequestValidator().validate(oRequest)
        if not isValid['OK']:
            print("Request is not valid: ", isValid['Message'])
            DIRAC.exit(1)

        result = reqClient.putRequest(oRequest)
        if result['OK']:
            print('Request %d Submitted' % result['Value'])
        else:
            print('Failed to submit Request: ', result['Message'])
コード例 #34
0
  def test02props(self):
    """ test props and attributes  """
    theFile = File()

    # valid props
    theFile.FileID = 1
    self.assertEqual(theFile.FileID, 1)
    theFile.Status = "Done"
    self.assertEqual(theFile.Status, "Done")
    theFile.LFN = "/some/path/somewhere"
    self.assertEqual(theFile.LFN, "/some/path/somewhere")
    theFile.PFN = "/some/path/somewhere"
    self.assertEqual(theFile.PFN, "/some/path/somewhere")
    theFile.Attempt = 1
    self.assertEqual(theFile.Attempt, 1)
    theFile.Size = 1
    self.assertEqual(theFile.Size, 1)
    theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66"
    self.assertEqual(theFile.GUID, "2bbabe80-e2f1-11e1-9b23-0800200c9a66")
    theFile.ChecksumType = "adler32"
    self.assertEqual(theFile.ChecksumType, "ADLER32")
    theFile.Checksum = "123456"
    self.assertEqual(theFile.Checksum, "123456")

    # #
    theFile.Checksum = None
    theFile.ChecksumType = None
#     self.assertEqual( theFile.Checksum, "" )
#     self.assertEqual( theFile.ChecksumType, "" )

    # # invalid props

    # FileID
    try:
      theFile.FileID = "foo"
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)

    # parent
    parent = Operation({"OperationID": 99999})
    parent += theFile

    theFile.FileID = 0

#     self.assertEqual( parent.OperationID, theFile.OperationID )
    try:
      theFile.OperationID = 111111
    except Exception as error:
      self.assertEqual(isinstance(error, AttributeError), True)
      self.assertEqual(str(error), "can't set attribute")

    # LFN
    try:
      theFile.LFN = 1
    except Exception as error:
      self.assertEqual(isinstance(error, TypeError), True)
      self.assertEqual(str(error), "LFN has to be a string!")
    try:
      theFile.LFN = "../some/path"
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
      self.assertEqual(str(error), "LFN should be an absolute path!")

    # PFN
    try:
      theFile.PFN = 1
    except Exception as error:
      self.assertEqual(isinstance(error, TypeError), True)
      self.assertEqual(str(error), "PFN has to be a string!")
    try:
      theFile.PFN = "snafu"
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
      self.assertEqual(str(error), "Wrongly formatted PFN!")

    # Size
    try:
      theFile.Size = "snafu"
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
    try:
      theFile.Size = -1
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
      self.assertEqual(str(error), "Size should be a positive integer!")

    # GUID
    try:
      theFile.GUID = "snafuu-uuu-uuu-uuu-uuu-u"
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
      self.assertEqual(str(error), "'snafuu-uuu-uuu-uuu-uuu-u' is not a valid GUID!")
    try:
      theFile.GUID = 2233345
    except Exception as error:
      self.assertEqual(isinstance(error, TypeError), True)
      self.assertEqual(str(error), "GUID should be a string!")

    # Attempt
    try:
      theFile.Attempt = "snafu"
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
    try:
      theFile.Attempt = -1
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
      self.assertEqual(str(error), "Attempt should be a positive integer!")

    # Status
    try:
      theFile.Status = None
    except Exception as error:
      self.assertEqual(isinstance(error, ValueError), True)
      self.assertEqual(str(error), "Unknown Status: None!")

    # Error
    try:
      theFile.Error = Exception("test")
    except Exception as error:
      self.assertEqual(isinstance(error, TypeError), True)
      self.assertEqual(str(error), "Error has to be a string!")
コード例 #35
0
ファイル: Test_Request.py プロジェクト: vingar/DIRAC
    def test_05FTS(self):
        """ FTS state machine """

        req = Request()
        req.RequestName = "FTSTest"

        ftsTransfer = Operation()
        ftsTransfer.Type = "ReplicateAndRegister"
        ftsTransfer.TargetSE = "CERN-USER"

        ftsFile = File()
        ftsFile.LFN = "/a/b/c"
        ftsFile.Checksum = "123456"
        ftsFile.ChecksumType = "Adler32"

        ftsTransfer.addFile(ftsFile)
        req.addOperation(ftsTransfer)

        self.assertEqual(req.Status, "Waiting",
                         "1. wrong request status: %s" % req.Status)
        self.assertEqual(ftsTransfer.Status, "Waiting",
                         "1. wrong ftsStatus status: %s" % ftsTransfer.Status)

        # # scheduled
        ftsFile.Status = "Scheduled"

        self.assertEqual(
            ftsTransfer.Status, "Scheduled",
            "2. wrong status for ftsTransfer: %s" % ftsTransfer.Status)
        self.assertEqual(req.Status, "Scheduled",
                         "2. wrong status for request: %s" % req.Status)

        # # add new operation before FTS
        insertBefore = Operation()
        insertBefore.Type = "RegisterReplica"
        insertBefore.TargetSE = "CERN-USER"
        insertFile = File()
        insertFile.LFN = "/a/b/c"
        insertFile.PFN = "http://foo/bar"
        insertBefore.addFile(insertFile)
        req.insertBefore(insertBefore, ftsTransfer)

        self.assertEqual(
            insertBefore.Status, "Waiting",
            "3. wrong status for insertBefore: %s" % insertBefore.Status)
        self.assertEqual(
            ftsTransfer.Status, "Scheduled",
            "3. wrong status for ftsStatus: %s" % ftsTransfer.Status)
        self.assertEqual(req.Status, "Waiting",
                         "3. wrong status for request: %s" % req.Status)

        # # prev done
        insertFile.Status = "Done"

        self.assertEqual(
            insertBefore.Status, "Done",
            "4. wrong status for insertBefore: %s" % insertBefore.Status)
        self.assertEqual(
            ftsTransfer.Status, "Scheduled",
            "4. wrong status for ftsStatus: %s" % ftsTransfer.Status)
        self.assertEqual(req.Status, "Scheduled",
                         "4. wrong status for request: %s" % req.Status)

        # # reschedule
        ftsFile.Status = "Waiting"

        self.assertEqual(
            insertBefore.Status, "Done",
            "5. wrong status for insertBefore: %s" % insertBefore.Status)
        self.assertEqual(
            ftsTransfer.Status, "Waiting",
            "5. wrong status for ftsStatus: %s" % ftsTransfer.Status)
        self.assertEqual(req.Status, "Waiting",
                         "5. wrong status for request: %s" % req.Status)

        # # fts done
        ftsFile.Status = "Done"

        self.assertEqual(
            insertBefore.Status, "Done",
            "5. wrong status for insertBefore: %s" % insertBefore.Status)
        self.assertEqual(
            ftsTransfer.Status, "Done",
            "5. wrong status for ftsStatus: %s" % ftsTransfer.Status)
        self.assertEqual(req.Status, "Done",
                         "5. wrong status for request: %s" % req.Status)
コード例 #36
0
ファイル: RequestTests.py プロジェクト: JanEbbing/DIRAC
  def test05FTS( self ):
    """ FTS state machine """

    req = Request()
    req.RequestName = "FTSTest"

    ftsTransfer = Operation()
    ftsTransfer.Type = "ReplicateAndRegister"
    ftsTransfer.TargetSE = "CERN-USER"

    ftsFile = File()
    ftsFile.LFN = "/a/b/c"
    ftsFile.Checksum = "123456"
    ftsFile.ChecksumType = "Adler32"

    ftsTransfer.addFile( ftsFile )
    req.addOperation( ftsTransfer )

    self.assertEqual( req.Status, "Waiting", "1. wrong request status: %s" % req.Status )
    self.assertEqual( ftsTransfer.Status, "Waiting", "1. wrong ftsStatus status: %s" % ftsTransfer.Status )

    # # scheduled
    ftsFile.Status = "Scheduled"

    self.assertEqual( ftsTransfer.Status, "Scheduled", "2. wrong status for ftsTransfer: %s" % ftsTransfer.Status )
    self.assertEqual( req.Status, "Scheduled", "2. wrong status for request: %s" % req.Status )

    # # add new operation before FTS
    insertBefore = Operation()
    insertBefore.Type = "RegisterReplica"
    insertBefore.TargetSE = "CERN-USER"
    insertFile = File()
    insertFile.LFN = "/a/b/c"
    insertFile.PFN = "http://foo/bar"
    insertBefore.addFile( insertFile )
    req.insertBefore( insertBefore, ftsTransfer )

    self.assertEqual( insertBefore.Status, "Waiting", "3. wrong status for insertBefore: %s" % insertBefore.Status )
    self.assertEqual( ftsTransfer.Status, "Scheduled", "3. wrong status for ftsStatus: %s" % ftsTransfer.Status )
    self.assertEqual( req.Status, "Waiting", "3. wrong status for request: %s" % req.Status )

    # # prev done
    insertFile.Status = "Done"

    self.assertEqual( insertBefore.Status, "Done", "4. wrong status for insertBefore: %s" % insertBefore.Status )
    self.assertEqual( ftsTransfer.Status, "Scheduled", "4. wrong status for ftsStatus: %s" % ftsTransfer.Status )
    self.assertEqual( req.Status, "Scheduled", "4. wrong status for request: %s" % req.Status )

    # # reschedule
    ftsFile.Status = "Waiting"

    self.assertEqual( insertBefore.Status, "Done", "5. wrong status for insertBefore: %s" % insertBefore.Status )
    self.assertEqual( ftsTransfer.Status, "Waiting", "5. wrong status for ftsStatus: %s" % ftsTransfer.Status )
    self.assertEqual( req.Status, "Waiting", "5. wrong status for request: %s" % req.Status )

    # # fts done
    ftsFile.Status = "Done"

    self.assertEqual( insertBefore.Status, "Done", "5. wrong status for insertBefore: %s" % insertBefore.Status )
    self.assertEqual( ftsTransfer.Status, "Done", "5. wrong status for ftsStatus: %s" % ftsTransfer.Status )
    self.assertEqual( req.Status, "Done", "5. wrong status for request: %s" % req.Status )
コード例 #37
0
    print "Can't get file metadata: %s" % res['Message']
    DIRAC.exit( 1 )
  if res['Value']['Failed']:
    print "Could not get the file metadata of the following, so skipping them:"
    for fFile in res['Value']['Failed']:
      print fFile

  lfnMetadata = res['Value']['Successful']

  for lfn in lfnMetadata:
    rarFile = File()
    rarFile.LFN = lfn
    rarFile.Size = lfnMetadata[lfn]['Size']
    rarFile.Checksum = lfnMetadata[lfn]['Checksum']
    rarFile.GUID = lfnMetadata[lfn]['GUID']
    rarFile.ChecksumType = 'ADLER32'
    replicateAndRegister.addFile( rarFile )

  oRequest.addOperation( replicateAndRegister )
  isValid = RequestValidator().validate( oRequest )
  if not isValid['OK']:
    print "Request is not valid: ", isValid['Message']
    DIRAC.exit( 1 )

  result = reqClient.putRequest( oRequest )
  if result['OK']:
    print "Request %d submitted successfully" % result['Value']
  else:
    print "Failed to submit Request: ", result['Message']

コード例 #38
0
    if not res['OK']:
        print "Can't get file metadata: %s" % res['Message']
        DIRAC.exit(1)
    if res['Value']['Failed']:
        print "Could not get the file metadata of the following, so skipping them:"
        for fFile in res['Value']['Failed']:
            print fFile

    lfnMetadata = res['Value']['Successful']

    for lfn in lfnMetadata:
        rarFile = File()
        rarFile.LFN = lfn
        rarFile.Size = lfnMetadata[lfn]['Size']
        rarFile.Checksum = lfnMetadata[lfn]['Checksum']
        rarFile.GUID = lfnMetadata[lfn]['GUID']
        rarFile.ChecksumType = 'ADLER32'
        replicateAndRegister.addFile(rarFile)

    oRequest.addOperation(replicateAndRegister)
    isValid = gRequestValidator.validate(oRequest)
    if not isValid['OK']:
        print "Request is not valid: ", isValid['Message']
        DIRAC.exit(1)

    result = reqClient.putRequest(oRequest)
    if result['OK']:
        print "Request %d submitted successfully" % result['Value']
    else:
        print "Failed to submit Request: ", result['Message']