Exemplo n.º 1
0
  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()
Exemplo n.º 2
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
Exemplo n.º 3
0
  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" )
Exemplo n.º 4
0
  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'])
Exemplo n.º 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
Exemplo n.º 6
0
  def __insertRegisterOperation( self, request, operation, toRegister ):
    """ add RegisterReplica operation

    :param Request request: request instance
    :param Operation transferOp: 'ReplicateAndRegister' operation for this FTSJob
    :param list toRegister: [ FTSDB.FTSFile, ... ] - files that failed to register
    """
    log = self.log.getSubLogger( "req_%s/%s/registerFiles" % ( request.RequestID, request.RequestName ) )

    byTarget = {}
    for ftsFile in toRegister:
      if ftsFile.TargetSE not in byTarget:
        byTarget.setdefault( ftsFile.TargetSE, [] )
      byTarget[ftsFile.TargetSE].append( ftsFile )
    log.info( "will create %s 'RegisterReplica' operations" % len( byTarget ) )

    for target, ftsFileList in byTarget.iteritems():
      log.info( "creating 'RegisterReplica' operation for targetSE %s with %s files..." % ( target,
                                                                                            len( ftsFileList ) ) )
      registerOperation = Operation()
      registerOperation.Type = "RegisterReplica"
      registerOperation.Status = "Waiting"
      registerOperation.TargetSE = target
      targetSE = StorageElement( target )
      for ftsFile in ftsFileList:
        opFile = File()
        opFile.LFN = ftsFile.LFN
        pfn = returnSingleResult( targetSE.getURL( ftsFile.LFN, protocol = self.registrationProtocols ) )
        if not pfn["OK"]:
          continue
        opFile.PFN = pfn["Value"]
        registerOperation.addFile( opFile )
      request.insertBefore( registerOperation, operation )

    return S_OK()
Exemplo n.º 7
0
  def __insertRegisterOperation( self, request, operation, toRegister ):
    """ add RegisterReplica operation

    :param Request request: request instance
    :param Operation transferOp: 'ReplicateAndRegister' operation for this FTSJob
    :param list toRegister: [ FTSDB.FTSFile, ... ] - files that failed to register
    """
    log = self.log.getSubLogger( "req_%s/%s/registerFiles" % ( request.RequestID, request.RequestName ) )

    byTarget = {}
    for ftsFile in toRegister:
      if ftsFile.TargetSE not in byTarget:
        byTarget.setdefault( ftsFile.TargetSE, [] )
      byTarget[ftsFile.TargetSE].append( ftsFile )
    log.info( "will create %s 'RegisterReplica' operations" % len( byTarget ) )

    for target, ftsFileList in byTarget.iteritems():
      log.info( "creating 'RegisterReplica' operation for targetSE %s with %s files..." % ( target,
                                                                                            len( ftsFileList ) ) )
      registerOperation = Operation()
      registerOperation.Type = "RegisterReplica"
      registerOperation.Status = "Waiting"
      registerOperation.TargetSE = target
      targetSE = StorageElement( target )
      for ftsFile in ftsFileList:
        opFile = File()
        opFile.LFN = ftsFile.LFN
        pfn = returnSingleResult( targetSE.getURL( ftsFile.LFN, protocol = self.registrationProtocols ) )
        if not pfn["OK"]:
          continue
        opFile.PFN = pfn["Value"]
        registerOperation.addFile( opFile )
      request.insertBefore( registerOperation, operation )

    return S_OK()
Exemplo n.º 8
0
    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"
                )
Exemplo n.º 9
0
 def _setFileRemovalRequest(self, lfn, se="", pfn=""):
     """Sets a removal request for a file including all replicas."""
     remove = Operation()
     remove.Type = "RemoveFile"
     if se:
         remove.TargetSE = se
     rmFile = File()
     rmFile.LFN = lfn
     if pfn:
         rmFile.PFN = pfn
     remove.addFile(rmFile)
     self.request.addOperation(remove)
     return S_OK()
Exemplo n.º 10
0
  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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
 def __setFileRemovalRequest( self, lfn, se = '', pfn = '' ):
   """ Sets a removal request for a file including all replicas.
   """
   remove = Operation()
   remove.Type = "RemoveFile"
   if se:
     remove.TargetSE = se
   rmFile = File()
   rmFile.LFN = lfn
   if pfn:
     rmFile.PFN = pfn
   remove.addFile( rmFile )
   self.request.addOperation( remove )
   return S_OK()
Exemplo n.º 13
0
    def __deleteSandboxFromExternalBackend(self, SEName, SEPFN):
        if self.getCSOption("DelayedExternalDeletion", True):
            gLogger.info("Setting deletion request")
            try:

                # We need the hostDN used in order to pass these credentials to the
                # SandboxStoreDB..
                hostCertLocation, _ = Locations.getHostCertificateAndKeyLocation(
                )
                hostCert = X509Certificate.X509Certificate()
                hostCert.loadFromFile(hostCertLocation)
                hostDN = hostCert.getSubjectDN().get("Value")

                # use the host authentication to fetch the data
                result = self.sandboxDB.getSandboxOwner(
                    SEName, SEPFN, hostDN, "hosts")
                if not result["OK"]:
                    return result
                _owner, ownerDN, ownerGroup = result["Value"]

                request = Request()
                request.RequestName = "RemoteSBDeletion:%s|%s:%s" % (
                    SEName, SEPFN, time.time())
                request.OwnerDN = ownerDN
                request.OwnerGroup = ownerGroup
                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(f"Cannot set deletion request: {e}")
        else:
            gLogger.info("Deleting external Sandbox")
            try:
                return StorageElement(SEName).removeFile(SEPFN)
            except Exception:
                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"
                )
Exemplo n.º 14
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 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()
Exemplo n.º 15
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()
Exemplo n.º 16
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
Exemplo n.º 17
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"
Exemplo n.º 18
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
    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)
Exemplo n.º 20
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()
Exemplo n.º 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()
Exemplo n.º 22
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()
Exemplo n.º 23
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
Exemplo n.º 24
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, error:
            self.assertEqual(isinstance(error, ValueError), True)
Exemplo n.º 25
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, error:
      self.assertEqual( isinstance( error, ValueError ), True )
Exemplo n.º 26
0
    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()
  purAndRegister.Type = "PutAndRegister"
  purAndRegister.TargetSE = targetSE
  opFile = File()
  opFile.LFN = LFN
  opFile.PFN = PFN
  opFile.Size = size
  opFile.Checksum = adler32
  opFile.ChecksumType = "ADLER32"
  putAndRegister.addFile( opFile )

  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." )
  gLogger.always( "You can monitor its status using command: 'dirac-rms-show-request %s'" % requestName )
  DIRAC.exit( 0 )
Exemplo n.º 27
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!")
Exemplo n.º 28
0
fr_mock = MagicMock()
fr_mock.getFiles.return_value = {}
fr_mock.setFileStatus.return_value = {'OK': True, 'Value': ''}
fr_mock.commit.return_value = {'OK': True, 'Value': ''}
fr_mock.generateForwardDISET.return_value = {'OK': True, 'Value': Operation()}

rc_mock = Request()
rc_mock.RequestName = 'aRequestName'
rc_mock.OwnerDN = 'pippo'
rc_mock.OwnerGroup = 'pippoGRP'
rOp = Operation()
rOp.Type = 'PutAndRegister'
rOp.TargetSE = 'anSE'
f = File()
f.LFN = '/foo/bar.py'
f.PFN = '/foo/bar.py'
rOp.addFile(f)
rc_mock.addOperation(rOp)


wf_commons = [{'PRODUCTION_ID': prod_id, 'JOB_ID': prod_job_id, 'eventType': '123456789', 'jobType': 'merge',
               'configName': 'aConfigName', 'configVersion': 'aConfigVersion', 'outputDataFileMask': '',
               'BookkeepingLFNs': 'aa', 'ProductionOutputData': 'ProductionOutputData', 'numberOfEvents': '100',
               'JobReport': jr_mock, 'Request': rc_mock, 'AccountingReport': ar_mock, 'FileReport': fr_mock,
               'SystemConfig': 'sys_config', 'runNumber': 'Unknown', 'gaudiSteps': ['someApp_1'],
               'outputSEs':{"DAVINCIHIST": "CERN-HIST", "TXT": "SE1"}},
              {'PRODUCTION_ID': prod_id, 'JOB_ID': prod_job_id,
               'configName': 'aConfigName', 'configVersion': 'aConfigVersion',
               'outputDataFileMask': '', 'jobType': 'merge',
               'BookkeepingLFNs': 'aa', 'ProductionOutputData': 'ProductionOutputData', 'numberOfEvents': '100',
               'JobReport': jr_mock, 'Request': rc_mock, 'AccountingReport': ar_mock, 'FileReport': fr_mock,
    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-show-request %s'" % requestName )
  DIRAC.exit( 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)
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)
Exemplo n.º 32
0
    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)
Exemplo n.º 33
0
  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 )