def deleteLFN(self, lfn): """ attempts to delete a file. will raise if none of the methods work, returns details otherwise """ log.info("Beginning to delete %s" % 'lfn') retval = {} # generate list of stageout methods we will try stageOutMethods = [self.defaultMethod] stageOutMethods.extend(self.fallbacks) # loop over all the different methods. This unifies regular and fallback stuff. Nice. methodCounter = 0 for currentMethod in stageOutMethods: methodCounter += 1 (seName, command, options, pfn, protocol) =\ self.getTransferDetails(lfn, currentMethod) retval = {'LFN': lfn, 'PFN': pfn, 'SEName': seName} log.info("Attempting deletion method %s" % (methodCounter, )) log.info("Current method information: %s" % currentMethod) try: deleteSlave = retrieveStageOutImpl(command, useNewVersion=True) except RegistryError: deleteSlave = retrieveStageOutImpl(command, useNewVersion=False) logging.error( "Tried to load stageout backend %s, a new version isn't there yet" % command) logging.error( "Will try to fall back to the oldone, but it's really best to redo it" ) logging.error("Here goes...") deleteSlave.removeFile(pfn) return retval # do the delete. The implementation is responsible for its own verification try: deleteSlave.doDelete(pfn, seName, command, options, protocol) except StageOutError, ex: log.info("Delete failed in an expected manner. Exception is:") log.info("%s" % str(ex)) log.info(traceback.format_exc()) if not self.firstException: self.firstException = ex continue # note to people who think it's cheeky to catch exception after ranting against it: # this makes sense because no matter what the exception, we want to keep going # additionally, it prints out the proper backtrace so we can diagnose issues # AMM - 6/30/2010 except Exception, ex: log.critical( "Delete failed in an unexpected manner. Exception is:") log.critical("%s" % str(ex)) log.info(traceback.format_exc()) if not self.firstException: self.firstException = ex continue
def _doTransfer(self, currentMethod, methodCounter, localFileName, pfn, stageOut): """ performs a transfer using a selected method and retries. necessary because python doesn't have a good nested loop break syntax """ (seName, command, options, _, protocol) =\ self.getTransferDetails(localFileName, currentMethod) # Swap directions if we're staging in if not stageOut: tempPfn = pfn pfn = localFileName localFileName = tempPfn for retryNumber in range(self.numberOfRetries + 1): log.info("Attempting transfer method %s, Retry number: %s" % (methodCounter, retryNumber)) log.info("Current method information: %s" % currentMethod) try: stageOutSlave = retrieveStageOutImpl(command, useNewVersion=True, stagein = not stageOut) except RegistryError: stageOutSlave = retrieveStageOutImpl(command, useNewVersion=False, stagein = not stageOut) logging.error("Tried to load stageout backend %s, a new version isn't there yet" % command) logging.error("Will try to fall back to the oldone, but it's really best to redo it") logging.error("Here goes...") stageOutSlave( protocol, localFileName, pfn, options ) return pfn # do the copy. The implementation is responsible for its own verification newPfn = None try: # FIXME add checksum stuff newPfn = stageOutSlave.doTransfer( localFileName, pfn, stageOut, seName, command, options, protocol, None ) except StageOutError, ex: log.info("Transfer failed in an expected manner. Exception is:") log.info("%s" % str(ex)) log.info("Sleeping for %s seconds" % self.retryPauseTime) log.info(traceback.format_exc()) time.sleep( self.retryPauseTime ) if not self.firstException: self.firstException = ex continue # note to people who think it's cheeky to catch exception after ranting against it: # this makes sense because no matter what the exception, we want to keep going # additionally, it prints out the proper backtrace so we can diagnose issues # AMM - 6/30/2010 except Exception, ex: log.critical("Transfer failed in an unexpected manner. Exception is:") log.critical("%s" % str(ex)) log.critical("Since this is an unexpected error, we are continuing to the next method") log.critical("and not retrying the same one") log.critical(traceback.format_exc()) if not self.firstException: self.firstException = ex break
def testRetrieveProperBackends(self): # make sure the default still gives the old behavior self.assertTrue(isinstance(retrieveStageOutImpl('test-win'), WMCore.Storage.Backends.UnittestImpl.WinImpl)) # make sure you can still explicitly get the old one self.assertTrue(isinstance(retrieveStageOutImpl('test-win', useNewVersion=False), WMCore.Storage.Backends.UnittestImpl.WinImpl)) # make sure that you get the new one if you want it self.assertTrue(retrieveStageOutImpl('test-win', useNewVersion=True), WMCore.Storage.Plugins.TestWinImpl.TestWinImpl)
def deleteLFN(self, lfn): """ attempts to delete a file. will raise if none of the methods work, returns details otherwise """ log.info("Beginning to delete %s" % 'lfn') retval = {} # generate list of stageout methods we will try stageOutMethods = [ self.defaultMethod ] stageOutMethods.extend( self.fallbacks ) # loop over all the different methods. This unifies regular and fallback stuff. Nice. methodCounter = 0 for currentMethod in stageOutMethods: methodCounter += 1 (seName, command, options, pfn, protocol) =\ self.getTransferDetails(lfn, currentMethod) retval = { 'LFN' : lfn, 'PFN': pfn, 'SEName': seName} log.info("Attempting deletion method %s" % (methodCounter, )) log.info("Current method information: %s" % currentMethod) try: deleteSlave = retrieveStageOutImpl(command, useNewVersion=True) except RegistryError: deleteSlave = retrieveStageOutImpl(command, useNewVersion=False) logging.error("Tried to load stageout backend %s, a new version isn't there yet" % command) logging.error("Will try to fall back to the oldone, but it's really best to redo it") logging.error("Here goes...") deleteSlave.removeFile( pfn ) return retval # do the delete. The implementation is responsible for its own verification try: deleteSlave.doDelete( pfn, seName, command, options, protocol ) except StageOutError, ex: log.info("Delete failed in an expected manner. Exception is:") log.info("%s" % str(ex)) log.info(traceback.format_exc()) if not self.firstException: self.firstException = ex continue # note to people who think it's cheeky to catch exception after ranting against it: # this makes sense because no matter what the exception, we want to keep going # additionally, it prints out the proper backtrace so we can diagnose issues # AMM - 6/30/2010 except Exception, ex: log.critical("Delete failed in an unexpected manner. Exception is:") log.critical("%s" % str(ex)) log.info(traceback.format_exc()) if not self.firstException: self.firstException = ex continue
def deletePFN(self, pfn, lfn, command): """ Delete the given PFN """ try: impl = retrieveStageOutImpl(command) except Exception as ex: msg = "Unable to retrieve impl for file deletion in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command, ) raise StageOutFailure(msg, Command=command, LFN=lfn, ExceptionDetail=str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl.removeFile(pfn) except Exception as ex: msg = "Failure for file deletion in:\n" msg += str(ex) try: import traceback msg += traceback.format_exc() except AttributeError as ex: msg += "Traceback unavailable\n" raise StageOutFailure(msg, Command=command, Protocol=command, LFN=lfn, TargetPFN=pfn) return pfn
def deletePFN(self, pfn, lfn, command): """ Delete the given PFN """ try: impl = retrieveStageOutImpl(command) except Exception as ex: msg = "Unable to retrieve impl for file deletion in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command,) raise StageOutFailure(msg, Command = command, LFN = lfn, ExceptionDetail = str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl.removeFile(pfn) except Exception as ex: msg = "Failure for file deletion in:\n" msg += str(ex) try: import traceback msg += traceback.format_exc() except AttributeError as ex: msg += "Traceback unavailable\n" raise StageOutFailure(msg, Command = command, Protocol = command, LFN = lfn, TargetPFN = pfn) return pfn
def deletePFN(self, pfn, lfn, command): """ Delete the given PFN """ try: impl = retrieveStageOutImpl(command) except Exception as ex: msg = "Unable to retrieve impl for file deletion in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command, ) raise StageOutFailure(msg, Command=command, LFN=lfn, ExceptionDetail=str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl.removeFile(pfn) except Exception as ex: self.logger.error("Failed to delete file: %s", pfn) ex.addInfo(Protocol=command, LFN=lfn, TargetPFN=pfn) raise ex return pfn
def localStageOut(self, lfn, localPfn): """ _localStageOut_ Given the lfn and local stage out params, invoke the local stage out """ seName = self.siteCfg.localStageOut['se-name'] command = self.siteCfg.localStageOut['command'] options = self.siteCfg.localStageOut.get('option', None) pfn = self.searchTFC(lfn) protocol = self.tfc.preferredProtocol if pfn == None: msg = "Unable to match lfn to pfn: \n %s" % lfn raise StageOutFailure(msg, LFN = lfn, TFC = str(self.tfc)) try: impl = retrieveStageOutImpl(command) except Exception, ex: msg = "Unable to retrieve impl for local stage out:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command,) raise StageOutFailure(msg, Command = command, LFN = lfn, ExceptionDetail = str(ex))
def localStageIn(self, lfn, override=None): """ _localStageOut_ Given the lfn and local stage out params, invoke the local stage in i.e. stage in lfn to pfn if override is used the follwoing params should be defined: command - the stage out impl plugin name to be used option - the option values to be passed to that command (None is allowed) lfn-prefix - the LFN prefix to generate the PFN se-name - the Name of the SE to which the file is being xferred """ localPfn = os.path.join(os.getcwd(), os.path.basename(lfn)) if override: seName = override['se-name'] command = override['command'] options = override['option'] pfn = "%s%s" % (override['lfn-prefix'], lfn) protocol = command else: seName = self.siteCfg.localStageOut['se-name'] command = self.siteCfg.localStageOut['command'] options = self.siteCfg.localStageOut.get('option', None) pfn = self.searchTFC(lfn) protocol = self.tfc.preferredProtocol if pfn == None: msg = "Unable to match lfn to pfn: \n %s" % lfn raise StageOutFailure(msg, LFN=lfn, TFC=str(self.tfc)) try: impl = retrieveStageOutImpl(command, stagein=True) except Exception as ex: msg = "Unable to retrieve impl for local stage in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command, ) raise StageOutFailure(msg, Command=command, LFN=lfn, ExceptionDetail=str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl(protocol, pfn, localPfn, options) except Exception as ex: msg = "Failure for local stage in:\n" msg += str(ex) raise StageOutFailure(msg, Command=command, Protocol=protocol, LFN=lfn, InputPFN=localPfn, TargetPFN=pfn) return localPfn
def fallbackStageOut(self, lfn, localPfn, fbParams, checksums): """ _fallbackStageOut_ Given the lfn and parameters for a fallback stage out, invoke it parameters should contain: command - the stage out impl plugin name to be used option - the option values to be passed to that command (None is allowed) lfn-prefix - the LFN prefix to generate the PFN se-name - the Name of the SE to which the file is being xferred """ pfn = "%s%s" % (fbParams['lfn-prefix'], lfn) try: impl = retrieveStageOutImpl(fbParams['command']) except Exception, ex: msg = "Unable to retrieve impl for fallback stage out:\n" msg += "Error retrieving StageOutImpl for command named: " msg += "%s\n" % fbParams['command'] raise StageOutFailure(msg, Command=fbParams['command'], LFN=lfn, ExceptionDetail=str(ex))
def localStageOut(self, lfn, localPfn, checksums): """ _localStageOut_ Given the lfn and local stage out params, invoke the local stage out """ seName = self.siteCfg.localStageOut['se-name'] command = self.siteCfg.localStageOut['command'] options = self.siteCfg.localStageOut.get('option', None) pfn = self.searchTFC(lfn) protocol = self.tfc.preferredProtocol if pfn == None: msg = "Unable to match lfn to pfn: \n %s" % lfn raise StageOutFailure(msg, LFN=lfn, TFC=str(self.tfc)) try: impl = retrieveStageOutImpl(command) except Exception, ex: msg = "Unable to retrieve impl for local stage out:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command, ) raise StageOutFailure(msg, Command=command, LFN=lfn, ExceptionDetail=str(ex))
def fallbackStageOut(self, lfn, localPfn, fbParams, checksums): """ _fallbackStageOut_ Given the lfn and parameters for a fallback stage out, invoke it parameters should contain: command - the stage out impl plugin name to be used option - the option values to be passed to that command (None is allowed) lfn-prefix - the LFN prefix to generate the PFN se-name - the Name of the SE to which the file is being xferred """ pfn = "%s%s" % (fbParams["lfn-prefix"], lfn) try: impl = retrieveStageOutImpl(fbParams["command"]) except Exception as ex: msg = "Unable to retrieve impl for fallback stage out:\n" msg += "Error retrieving StageOutImpl for command named: " msg += "%s\n" % fbParams["command"] raise StageOutFailure(msg, Command=fbParams["command"], LFN=lfn, ExceptionDetail=str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl(fbParams["command"], localPfn, pfn, fbParams.get("option", None), checksums) except Exception as ex: msg = "Failure for fallback stage out:\n" msg += str(ex) raise StageOutFailure(msg, Command=fbParams["command"], LFN=lfn, InputPFN=localPfn, TargetPFN=pfn) return pfn
def localStageIn(self, lfn, override = None): """ _localStageOut_ Given the lfn and local stage out params, invoke the local stage in i.e. stage in lfn to pfn if override is used the follwoing params should be defined: command - the stage out impl plugin name to be used option - the option values to be passed to that command (None is allowed) lfn-prefix - the LFN prefix to generate the PFN se-name - the Name of the SE to which the file is being xferred phedex-node - the Name of the PNN to which the file is being xferred """ localPfn = os.path.join(os.getcwd(), os.path.basename(lfn)) if override: seName = override['se-name'] pnn = override['phedex-node'] command = override['command'] options = override['option'] pfn = "%s%s" % (override['lfn-prefix'], lfn) protocol = command else: seName = self.siteCfg.localStageOut['se-name'] pnn = self.siteCfg.localStageOut['phedex-node'] command = self.siteCfg.localStageOut['command'] options = self.siteCfg.localStageOut.get('option', None) pfn = self.searchTFC(lfn) protocol = self.tfc.preferredProtocol if pfn == None: msg = "Unable to match lfn to pfn: \n %s" % lfn raise StageOutFailure(msg, LFN = lfn, TFC = str(self.tfc)) try: impl = retrieveStageOutImpl(command, stagein=True) except Exception as ex: msg = "Unable to retrieve impl for local stage in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command,) raise StageOutFailure(msg, Command = command, LFN = lfn, ExceptionDetail = str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl(protocol, pfn, localPfn, options) except Exception as ex: msg = "Failure for local stage in:\n" msg += str(ex) raise StageOutFailure(msg, Command = command, Protocol = protocol, LFN = lfn, InputPFN = localPfn, TargetPFN = pfn) return localPfn
def performDirectTransferImpl(source_file, dest_pfn, dest_se, is_log): command = "srmv2-lcg" protocol = "srmv2" try: impl = retrieveStageOutImpl(command) except Exception, ex: msg = "Unable to retrieve impl for local stage out:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % (command,) raise StageOutError.StageOutFailure(msg, Command = command, LFN = dest_pfn, ExceptionDetail = str(ex))
def invokeCleanUp(self, lfn): """ _invokeCleanUp_ Instantiate the StageOut impl, map the LFN to PFN using the TFC and invoke the CleanUp on that PFN """ # // # // Load Impl #// try: implInstance = retrieveStageOutImpl(self.implName) except Exception as ex: msg = "Error retrieving Stage Out Impl for name: " msg += "%s\n" % self.implName msg += str(ex) raise CleanUpFailure(lfn, ImplName=self.implName, Message=msg) # // # // Match LFN #// pfn = self.tfc.matchLFN(self.tfc.preferredProtocol, lfn) if pfn == None: msg = "Unable to map LFN to PFN:\n" msg += "LFN: %s\n" % lfn raise CleanUpFailure(lfn, TFC=str(self.tfc), ImplName=self.implName, Message=msg, TFCProtocol=self.tfc.preferredProtocol) # // # // Invoke StageOut Impl removeFile method #// try: implInstance.removeFile(pfn) except Exception as ex: msg = "Error performing Cleanup command for impl " msg += "%s\n" % self.implName msg += "On PFN: %s\n" % pfn msg += str(ex) # // # // Will uncomment it after invalidating deleted lfn from mergesensordb # // raise CleanUpFailure(lfn, TFC=str(self.tfc), ImplName=self.implName, PFN=pfn, Message=msg, TFCProtocol=self.tfc.preferredProtocol)
def invokeCleanUp(self, lfn): """ _invokeCleanUp_ Instantiate the StageOut impl, map the LFN to PFN using the TFC and invoke the CleanUp on that PFN """ # // # // Load Impl #// try: implInstance = retrieveStageOutImpl(self.implName) except Exception as ex: msg = "Error retrieving Stage Out Impl for name: " msg += "%s\n" % self.implName msg += str(ex) raise CleanUpFailure(lfn, ImplName = self.implName, Message = msg) # // # // Match LFN #// pfn = self.tfc.matchLFN(self.tfc.preferredProtocol, lfn) if pfn == None: msg = "Unable to map LFN to PFN:\n" msg += "LFN: %s\n" % lfn raise CleanUpFailure(lfn, TFC = str(self.tfc), ImplName = self.implName, Message = msg, TFCProtocol = self.tfc.preferredProtocol) # // # // Invoke StageOut Impl removeFile method #// try: implInstance.removeFile(pfn) except Exception as ex: msg = "Error performing Cleanup command for impl " msg += "%s\n" % self.implName msg += "On PFN: %s\n" % pfn msg += str(ex) # // # // Will uncomment it after invalidating deleted lfn from mergesensordb # // raise CleanUpFailure(lfn, TFC = str(self.tfc), ImplName = self.implName, PFN = pfn, Message = msg, TFCProtocol = self.tfc.preferredProtocol)
def deletePFN(self, pfn, lfn, command): """ Delete the given PFN """ try: impl = retrieveStageOutImpl(command) except Exception, ex: msg = "Unable to retrieve impl for file deletion in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command,) raise StageOutFailure(msg, Command = command, LFN = lfn, ExceptionDetail = str(ex))
def deletePFN(self, pfn, lfn, command): """ Delete the given PFN """ try: impl = retrieveStageOutImpl(command) except Exception, ex: msg = "Unable to retrieve impl for file deletion in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command, ) raise StageOutFailure(msg, Command=command, LFN=lfn, ExceptionDetail=str(ex))
def localStageOut(self, lfn, localPfn, checksums): """ _localStageOut_ Given the lfn and local stage out params, invoke the local stage out """ seName = self.siteCfg.localStageOut['se-name'] pnn = self.siteCfg.localStageOut['phedex-node'] command = self.siteCfg.localStageOut['command'] options = self.siteCfg.localStageOut.get('option', None) pfn = self.searchTFC(lfn) protocol = self.tfc.preferredProtocol if pfn == None: msg = "Unable to match lfn to pfn: \n %s" % lfn raise StageOutFailure(msg, LFN=lfn, TFC=str(self.tfc)) try: impl = retrieveStageOutImpl(command) except Exception as ex: msg = "Unable to retrieve impl for local stage out:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command, ) raise StageOutFailure(msg, Command=command, LFN=lfn, ExceptionDetail=str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl(protocol, localPfn, pfn, options, checksums) except Exception as ex: msg = "Failure for local stage out:\n" msg += str(ex) try: import traceback msg += traceback.format_exc() except AttributeError as ex: msg += "Traceback unavailable\n" raise StageOutFailure(msg, Command=command, Protocol=protocol, LFN=lfn, InputPFN=localPfn, TargetPFN=pfn) return pfn
def stageOut(self, source, destination, token=None, filesize=None, checksum=None): """ _stageOut_ Perform a local stage out """ wasSuccessful = False msg = "" sourcePFN = os.path.join(os.getcwd(), source) seName = self.siteConf.localStageOut['se-name'] command = self.siteConf.localStageOut['command'] options = self.siteConf.localStageOut.get('option', None) protocol = self.tfc.preferredProtocol targetPFN = self.tfc.matchLFN(self.tfc.preferredProtocol, destination) msg += "Target PFN is: %s\n" % targetPFN if self.verbose: print msg # first try the regular stageout try: # an exception around normal stageout try: impl = retrieveStageOutImpl(command) except Exception, ex: msg += "Unable to retrieve impl for local stage out:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command,) self.summary['LocalStageOut'] = \ "Failure: Cant retrieve StageOut Impl" raise RuntimeError, msg try: impl.retryPause = 15 impl(protocol, sourcePFN, targetPFN, options) wasSuccessful = True except Exception, ex: msg += "Failure for local stage out:\n" msg += str(ex) self.summary['LocalStageOut'] = \ "Failure: Local Stage Out Failed" raise RuntimeError, msg
def cleanUp(self,destination): """ _cleanUp_ Clean up the file from SE """ commandList = [ self.siteConf.localStageOut[ 'command' ] ] pfnList = [ self.tfc.matchLFN(self.tfc.preferredProtocol, destination) ] for fallback in self.siteConf.fallbackStageOut: commandList.append( fallback[ 'command' ]) try: pfnList.append( fallback[ 'lfn-prefix' ] + destination ) except KeyError: pfnList.append( destination ) wasSuccessful = False msg = "" for (command, pfn) in zip( commandList, pfnList ): try: # outer try to catch the fallback as a whole try: # inner try for getting the impl implInstance = retrieveStageOutImpl(command) except Exception, ex: msg += "Unable to retrieve impl for clean up:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % (command,) self.summary['CleanUp'] = "Failure: Cant retrieve StageOut Impl" raise RuntimeError, msg # // # // Invoke StageOut Impl removeFile method #// try: # inner try for calling removeFile implInstance.removeFile(pfn) except Exception, ex: msg += "Error performing Cleanup command for impl " msg += "%s\n" % command msg += "On PFN: %s\n" % pfn msg += str(ex) self.summary['CleanUp'] = "Failure: Cleanup operation Failed" raise RuntimeError, msg self.summary['CleanUp'] = "Successful" wasSuccessful = True
def localStageOut(self, lfn, localPfn, checksums): """ _localStageOut_ Given the lfn and local stage out params, invoke the local stage out """ seName = self.siteCfg.localStageOut['se-name'] pnn = self.siteCfg.localStageOut['phedex-node'] command = self.siteCfg.localStageOut['command'] options = self.siteCfg.localStageOut.get('option', None) pfn = self.searchTFC(lfn) protocol = self.tfc.preferredProtocol if pfn == None: msg = "Unable to match lfn to pfn: \n %s" % lfn raise StageOutFailure(msg, LFN = lfn, TFC = str(self.tfc)) try: impl = retrieveStageOutImpl(command) except Exception as ex: msg = "Unable to retrieve impl for local stage out:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command,) raise StageOutFailure(msg, Command = command, LFN = lfn, ExceptionDetail = str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl(protocol, localPfn, pfn, options, checksums) except Exception as ex: msg = "Failure for local stage out:\n" msg += str(ex) try: import traceback msg += traceback.format_exc() except AttributeError as ex: msg += "Traceback unavailable\n" raise StageOutFailure(msg, Command = command, Protocol = protocol, LFN = lfn, InputPFN = localPfn, TargetPFN = pfn) return pfn
def fallbackStageOut(self, lfn, localPfn, fbParams, checksums): """ _fallbackStageOut_ Given the lfn and parameters for a fallback stage out, invoke it parameters should contain: command - the stage out impl plugin name to be used option - the option values to be passed to that command (None is allowed) lfn-prefix - the LFN prefix to generate the PFN phedex-node - the Name of the PNN to which the file is being xferred """ pfn = "%s%s" % (fbParams['lfn-prefix'], lfn) try: impl = retrieveStageOutImpl(fbParams['command']) except Exception as ex: msg = "Unable to retrieve impl for fallback stage out:\n" msg += "Error retrieving StageOutImpl for command named: " msg += "%s\n" % fbParams['command'] raise StageOutFailure(msg, Command=fbParams['command'], LFN=lfn, ExceptionDetail=str(ex)) impl.numRetries = self.numberOfRetries impl.retryPause = self.retryPauseTime try: impl(fbParams['command'], localPfn, pfn, fbParams.get("option", None), checksums) except Exception as ex: msg = "Failure for fallback stage out:\n" msg += str(ex) raise StageOutFailure(msg, Command=fbParams['command'], LFN=lfn, InputPFN=localPfn, TargetPFN=pfn) return pfn
def invokeCleanUp(self, lfn): """ _invokeCleanUp_ Instantiate the StageOut impl, map the LFN to PFN using the TFC and invoke the CleanUp on that PFN """ # // # // Load Impl #// try: implInstance = retrieveStageOutImpl(self.implName) except Exception, ex: msg = "Error retrieving Stage Out Impl for name: " msg += "%s\n" % self.implName msg += str(ex) raise CleanUpFailure(lfn, ImplName=self.implName, Message=msg)
def invokeCleanUp(self, lfn): """ _invokeCleanUp_ Instantiate the StageOut impl, map the LFN to PFN using the TFC and invoke the CleanUp on that PFN """ # // # // Load Impl #// try: implInstance = retrieveStageOutImpl(self.implName) except Exception, ex: msg = "Error retrieving Stage Out Impl for name: " msg += "%s\n" % self.implName msg += str(ex) raise CleanUpFailure(lfn, ImplName = self.implName, Message = msg)
def localStageIn(self, lfn, override=None): """ _localStageOut_ Given the lfn and local stage out params, invoke the local stage in i.e. stage in lfn to pfn if override is used the follwoing params should be defined: command - the stage out impl plugin name to be used option - the option values to be passed to that command (None is allowed) lfn-prefix - the LFN prefix to generate the PFN se-name - the Name of the SE to which the file is being xferred """ localPfn = os.path.join(os.getcwd(), os.path.basename(lfn)) if override: seName = override["se-name"] command = override["command"] options = override["option"] pfn = "%s%s" % (override["lfn-prefix"], lfn) protocol = command else: seName = self.siteCfg.localStageOut["se-name"] command = self.siteCfg.localStageOut["command"] options = self.siteCfg.localStageOut.get("option", None) pfn = self.searchTFC(lfn) protocol = self.tfc.preferredProtocol if pfn == None: msg = "Unable to match lfn to pfn: \n %s" % lfn raise StageOutFailure(msg, LFN=lfn, TFC=str(self.tfc)) try: impl = retrieveStageOutImpl(command, stagein=True) except Exception, ex: msg = "Unable to retrieve impl for local stage in:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % (command,) raise StageOutFailure(msg, Command=command, LFN=lfn, ExceptionDetail=str(ex))
def fallbackStageOut(self, lfn, localPfn, fbParams): """ _fallbackStageOut_ Given the lfn and parameters for a fallback stage out, invoke it parameters should contain: command - the stage out impl plugin name to be used option - the option values to be passed to that command (None is allowed) lfn-prefix - the LFN prefix to generate the PFN se-name - the Name of the SE to which the file is being xferred """ pfn = "%s%s" % (fbParams['lfn-prefix'], lfn) try: impl = retrieveStageOutImpl(fbParams['command']) except Exception, ex: msg = "Unable to retrieve impl for fallback stage out:\n" msg += "Error retrieving StageOutImpl for command named: " msg += "%s\n" % fbParams['command'] raise StageOutFailure(msg, Command = fbParams['command'], LFN = lfn, ExceptionDetail = str(ex))
def _doTransfer(self, currentMethod, methodCounter, localFileName, pfn, stageOut): """ performs a transfer using a selected method and retries. necessary because python doesn't have a good nested loop break syntax """ (pnn, command, options, _, protocol) = \ self.getTransferDetails(localFileName, currentMethod) # Swap directions if we're staging in if not stageOut: tempPfn = pfn pfn = localFileName localFileName = tempPfn for retryNumber in range(self.numberOfRetries + 1): log.info("Attempting transfer method %s, Retry number: %s" % (methodCounter, retryNumber)) log.info("Current method information: %s" % currentMethod) try: stageOutSlave = retrieveStageOutImpl(command, useNewVersion=True, stagein=not stageOut) except RegistryError: stageOutSlave = retrieveStageOutImpl(command, useNewVersion=False, stagein=not stageOut) logging.error( "Tried to load stageout backend %s, a new version isn't there yet" % command) logging.error( "Will try to fall back to the oldone, but it's really best to redo it" ) logging.error("Here goes...") stageOutSlave(protocol, localFileName, pfn, options) return pfn # do the copy. The implementation is responsible for its own verification newPfn = None try: # FIXME add checksum stuff newPfn = stageOutSlave.doTransfer(localFileName, pfn, stageOut, pnn, command, options, protocol, None) except StageOutError as ex: log.info( "Transfer failed in an expected manner. Exception is:") log.info("%s" % str(ex)) log.info("Sleeping for %s seconds" % self.retryPauseTime) log.info(traceback.format_exc()) time.sleep(self.retryPauseTime) if not self.firstException: self.firstException = ex continue # note to people who think it's cheeky to catch exception after ranting against it: # this makes sense because no matter what the exception, we want to keep going # additionally, it prints out the proper backtrace so we can diagnose issues # AMM - 6/30/2010 except Exception as ex: log.critical( "Transfer failed in an unexpected manner. Exception is:") log.critical("%s" % str(ex)) log.critical( "Since this is an unexpected error, we are continuing to the next method" ) log.critical("and not retrying the same one") log.critical(traceback.format_exc()) if not self.firstException: self.firstException = ex break # successful transfers make it here return newPfn # unseuccessful transfers make it here return False
except RuntimeError, ex: ### FALLBACK ### ### there are N fallbacks in a list called fallbackStageOut ### for fallbackCount in range(len(self.siteConf.fallbackStageOut)): seName = self.siteConf.fallbackStageOut[fallbackCount]['se-name'] command = self.siteConf.fallbackStageOut[fallbackCount]['command'] options = self.siteConf.fallbackStageOut[fallbackCount].get('option', None) try: targetPFN = self.siteConf.fallbackStageOut[fallbackCount]['lfn-prefix'] + destination except KeyError: targetPFN = destination try: impl = retrieveStageOutImpl(command) except Exception, ex: msg += "Unable to retrieve impl for local stage out:\n" msg += "Error retrieving StageOutImpl for command named: %s\n" % ( command,) self.summary['LocalStageOut'] += \ "\nFailure: Cant retrieve StageOut Impl for fallback %s" % fallbackCount raise RuntimeError, msg try: impl.retryPause = 15 impl(protocol, sourcePFN, targetPFN, options) wasSuccessful = True except Exception, ex: msg += "Failure for local stage out:\n" msg += str(ex)
def doTransfer(self, sourcePFN, targetPFN, stageOut, seName, command, options, protocol, checksum): """ performs a transfer. stageOut tells you which way to go. returns the new pfn or raises on failure. StageOutError (and inherited exceptions) are for expected errors such as temporary connection failures. Anything else will be handled as an unexpected error and skip retrying with this plugin """ targetPFN = self.createSourceName(protocol, targetPFN) sourcePFN = self.createSourceName(protocol, sourcePFN) # make directories self.createOutputDirectory(os.path.dirname(targetPFN)) if targetPFN.find('lustre') == -1: if not options: options = "" if stageOut: copyCommand = \ self.generateCommandFromPreAndPostParts(\ ["dccp", "-o", "86400", "-d", "0", "-X", "-role=cmsprod"], [sourcePFN, targetPFN], options) else: copyCommand = \ self.generateCommandFromPreAndPostParts(\ ["dccp"], [pnfsPfn(sourcePFN), targetPFN], options) logging.info("Staging out with DCCPFNAL") logging.info(" commandline: %s" % copyCommand) print "command is %s" % copyCommand (exitCode, output) = self.doWrapped(copyCommand) if exitCode: logging.error("Transfer failed") raise StageOutFailure("DCCP failed - No good") # riddle me this, the following line fails with: # not all arguments converted during string formatting #FIXME logging.info(" output from dccp: %s" % output) logging.info(" complete. #") #exit code" is %s" % exitCode) logging.info("Verifying file") (exitCode, output) = self.doWrapped([ '/opt/d-cache/dcap/bin/check_dCachefilecksum.sh', pnfsPfn(targetPFN), sourcePFN ]) if exitCode: logging.error("Checksum verify failed") try: self.doDelete(targetPFN, None, None, None, None) except: pass raise StageOutFailure("DCCP failed - No good") return targetPFN else: # looks like lustre -- do a regular CP copyGuy = retrieveStageOutImpl('cp', useNewVersion=True) return copyGuy.doTransfer(sourcePFN, targetPFN, stageOut, seName, command, options, protocol, checksum)
msg = "Error: ImplName not provided, you need to provide the --impl option" print msg sys.exit(1) if inputPfn == None: msg = "Error: Input PFN not provided: use the --input-pfn option" print msg sys.exit(1) if targetPfn == None: msg = "Error: Target PFN not provided: use the --target-pfn option" print msg sys.exit(1) try: implInstance = retrieveStageOutImpl(implName) except StageOutError, ex: print "Error retrieving plugin from registry named: %s" % implName print str(ex) sys.exit(1) print " Invoking StageOutImpl: %s" % implName implInstance(protocol, inputPfn, targetPfn) if doCleanup: # // # // Cleanup implies that we invoke the implementations #// removeFile method on the target PFN after the transfer print "Invoking %s.removeFile on %s" % (implName, targetPfn) implInstance.removeFile(targetPfn)
def doTransfer(self, sourcePFN, targetPFN, stageOut, pnn, command, options, protocol, checksum ): """ performs a transfer. stageOut tells you which way to go. returns the new pfn or raises on failure. StageOutError (and inherited exceptions) are for expected errors such as temporary connection failures. Anything else will be handled as an unexpected error and skip retrying with this plugin """ targetPFN = self.createSourceName(protocol, targetPFN) sourcePFN = self.createSourceName(protocol, sourcePFN) # make directories self.createOutputDirectory(os.path.dirname(targetPFN)) if targetPFN.find('lustre') == -1: if not options: options = "" if stageOut: copyCommand = \ self.generateCommandFromPreAndPostParts(\ ["dccp", "-o", "86400", "-d", "0", "-X", "-role=cmsprod"], [sourcePFN, targetPFN], options) else: copyCommand = \ self.generateCommandFromPreAndPostParts(\ ["dccp"], [pnfsPfn(sourcePFN), targetPFN], options) logging.info("Staging out with DCCPFNAL") logging.info(" commandline: %s" % copyCommand) print("command is %s" % copyCommand) (exitCode, output) = self.doWrapped(copyCommand) if exitCode: logging.error("Transfer failed") raise StageOutFailure("DCCP failed - No good") # riddle me this, the following line fails with: # not all arguments converted during string formatting #FIXME logging.info(" output from dccp: %s" % output) logging.info(" complete. #" )#exit code" is %s" % exitCode) logging.info("Verifying file") (exitCode, output) = self.doWrapped(['/opt/d-cache/dcap/bin/check_dCachefilecksum.sh', pnfsPfn(targetPFN), sourcePFN]) if exitCode: logging.error("Checksum verify failed") try: self.doDelete(targetPFN,None,None,None,None) except: pass raise StageOutFailure("DCCP failed - No good") return targetPFN else: # looks like lustre -- do a regular CP copyGuy = retrieveStageOutImpl('cp',useNewVersion = True) return copyGuy.doTransfer(sourcePFN,targetPFN,stageOut, pnn, command, options, protocol, checksum)
msg = "Error: ImplName not provided, you need to provide the --impl option" print(msg) sys.exit(1) if inputPfn == None: msg = "Error: Input PFN not provided: use the --input-pfn option" print(msg) sys.exit(1) if targetPfn == None: msg = "Error: Target PFN not provided: use the --target-pfn option" print(msg) sys.exit(1) try: implInstance = retrieveStageOutImpl(implName) except StageOutError as ex: print("Error retrieving plugin from registry named: %s" % implName) print(str(ex)) sys.exit(1) print(" Invoking StageOutImpl: %s" % implName) implInstance(protocol, inputPfn, targetPfn) if doCleanup: # // # // Cleanup implies that we invoke the implementations #// removeFile method on the target PFN after the transfer print("Invoking %s.removeFile on %s" % (implName, targetPfn))