Script.parseCommandLine() from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient args = Script.getPositionalArgs() if (len(args) != 1): Script.showHelp() # get arguments prodID = args[0] prodClient = ProductionClient() transClient = TransformationClient() res = prodClient.getProductionTransformations(prodID) transIDs = [] if res['OK']: transList = res['Value'] if not transList: DIRAC.gLogger.notice('No transformation associated with production %s' % prodID) DIRAC.exit(-1) for trans in transList: transIDs.append(trans['TransformationID']) else: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) fields = [
class ProdTransManager(object): def __init__(self): self.transClient = TransformationClient() self.prodClient = ProductionClient() def deleteTransformations(self, transIDs): """Delete given transformations from the TS :param list transIDs: a list of Transformation IDs """ gLogger.notice("Deleting transformations %s from the TS" % transIDs) for transID in transIDs: res = self.transClient.deleteTransformation(transID) if not res["OK"]: return res return S_OK() def deleteProductionTransformations(self, prodID): """Delete the production transformations from the TS :param int prodID: the ProductionID """ res = self.prodClient.getProductionTransformations(prodID) if res["OK"]: transList = res["Value"] gLogger.notice("Deleting production transformations %s from the TS" % transList) for trans in transList: transID = trans["TransformationID"] res = self.transClient.deleteTransformation(transID) if not res["OK"]: gLogger.error(res["Message"]) return S_OK() def addTransformationStep(self, stepID, prodID): """Add the transformation step to the TS :param int stepID: the production step ID :param int prodID: the production ID :return: """ res = self.prodClient.getProductionStep(stepID) if not res["OK"]: return res prodStep = res["Value"] gLogger.notice("Add step %s to production %s" % (prodStep[0], prodID)) stepDesc = prodStep[2] stepLongDesc = prodStep[3] stepBody = prodStep[4] stepType = prodStep[5] stepPlugin = prodStep[6] stepAgentType = prodStep[7] stepGroupsize = prodStep[8] stepInputquery = json.loads(prodStep[9]) stepOutputquery = json.loads(prodStep[10]) stepName = "%08d" % prodID + "_" + prodStep[1] res = self.transClient.addTransformation( stepName, stepDesc, stepLongDesc, stepType, stepPlugin, stepAgentType, "", groupSize=stepGroupsize, body=stepBody, inputMetaQuery=stepInputquery, outputMetaQuery=stepOutputquery, ) if not res["OK"]: return S_ERROR(res["Message"]) return S_OK(res["Value"]) def executeActionOnTransformations(self, prodID, action): """Wrapper to start/stop/clean the transformations of a production :param int prodID: the production ID :param str action: it can be start/stop/clean """ # Check if there is any action to do if not action: return S_OK() # Get the transformations of the production res = self.prodClient.getProductionTransformations(prodID) if not res["OK"]: return res transList = res["Value"] method = getattr(self.transClient, action) gLogger.notice("Executing action %s to %s" % (action, transList)) # Execute the action on each transformation for trans in transList: transID = trans["TransformationID"] res = method(transID) if not res["OK"]: return res return S_OK()
def main(): Script.parseCommandLine() from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient args = Script.getPositionalArgs() if len(args) < 1: Script.showHelp(exitCode=1) # get arguments prodID = args[0] prodClient = ProductionClient() transClient = TransformationClient() res = prodClient.getProductionTransformations(prodID) transIDs = [] if res['OK']: transList = res['Value'] if not transList: DIRAC.gLogger.notice( 'No transformation associated with production %s' % prodID) DIRAC.exit(-1) for trans in transList: transIDs.append(trans['TransformationID']) else: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) fields = [ 'TransformationName', 'Status', 'F_Proc.', 'F_Proc.(%)', 'TransformationID', 'ProductionID', 'Prod_LastUpdate', 'Prod_InsertedTime' ] records = [] paramShowNames = [ 'TransformationID', 'TransformationName', 'Type', 'Status', 'Files_Total', 'Files_PercentProcessed', 'Files_Processed', 'Files_Unused', 'Jobs_TotalCreated', 'Jobs_Waiting', 'Jobs_Running', 'Jobs_Done', 'Jobs_Failed', 'Jobs_Stalled' ] resList = [] res = transClient.getTransformationSummaryWeb( {'TransformationID': transIDs}, [], 0, len(transIDs)) if not res['OK']: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) if res['Value']['TotalRecords'] > 0: paramNames = res['Value']['ParameterNames'] for paramValues in res['Value']['Records']: paramShowValues = map( lambda pname: paramValues[paramNames.index(pname)], paramShowNames) showDict = dict(zip(paramShowNames, paramShowValues)) resList.append(showDict) for res in resList: files_Processed = res['Files_Processed'] files_PercentProcessed = res['Files_PercentProcessed'] status = res['Status'] type = res['Type'] transName = res['TransformationName'] transID = res['TransformationID'] records.append([ transName, status, str(files_Processed), str(files_PercentProcessed), str(transID), str(prodID), str(trans['LastUpdate']), str(trans['InsertedTime']) ]) printTable(fields, records) DIRAC.exit(0)
def main(): # Registering arguments will automatically add their description to the help menu Script.registerArgument("prodID: Production ID") _, args = Script.parseCommandLine() from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient # get arguments prodID = args[0] prodClient = ProductionClient() transClient = TransformationClient() res = prodClient.getProductionTransformations(prodID) transIDs = [] if res["OK"]: transList = res["Value"] if not transList: DIRAC.gLogger.notice( "No transformation associated with production %s" % prodID) DIRAC.exit(-1) for trans in transList: transIDs.append(trans["TransformationID"]) else: DIRAC.gLogger.error(res["Message"]) DIRAC.exit(-1) fields = [ "TransformationName", "Status", "F_Proc.", "F_Proc.(%)", "TransformationID", "ProductionID", "Prod_LastUpdate", "Prod_InsertedTime", ] records = [] paramShowNames = [ "TransformationID", "TransformationName", "Type", "Status", "Files_Total", "Files_PercentProcessed", "Files_Processed", "Files_Unused", "Jobs_TotalCreated", "Jobs_Waiting", "Jobs_Running", "Jobs_Done", "Jobs_Failed", "Jobs_Stalled", ] resList = [] res = transClient.getTransformationSummaryWeb( {"TransformationID": transIDs}, [], 0, len(transIDs)) if not res["OK"]: DIRAC.gLogger.error(res["Message"]) DIRAC.exit(-1) if res["Value"]["TotalRecords"] > 0: paramNames = res["Value"]["ParameterNames"] for paramValues in res["Value"]["Records"]: paramShowValues = map( lambda pname: paramValues[paramNames.index(pname)], paramShowNames) showDict = dict(zip(paramShowNames, paramShowValues)) resList.append(showDict) for res in resList: files_Processed = res["Files_Processed"] files_PercentProcessed = res["Files_PercentProcessed"] status = res["Status"] type = res["Type"] transName = res["TransformationName"] transID = res["TransformationID"] records.append([ transName, status, str(files_Processed), str(files_PercentProcessed), str(transID), str(prodID), str(trans["LastUpdate"]), str(trans["InsertedTime"]), ]) printTable(fields, records) DIRAC.exit(0)