def __getJobs( selDict, startJob = 0, maxJobs = 500 ): result = getRPCClient( "WorkloadManagement/JobMonitoring", group = gOAData.userGroup, userDN = gOAData.userDN ).getJobPageSummaryWeb( selDict, [( 'JobID', 'DESC' )], startJob, maxJobs, True ) if not result[ 'OK' ]: bottle.abort( 500, result[ 'Message' ] ) origData = result[ 'Value' ] totalRecords = origData[ 'TotalRecords' ] retData = { 'entries' : totalRecords, 'jobs' : [] } if totalRecords == 0: return retData indexes = __findIndexes( origData[ 'ParameterNames' ] ) records = origData[ 'Records' ] for record in records: job = {} for param in indexes[ 'attrs' ]: job[ param ] = record[ indexes[ 'attrs' ][ param ] ] if param in integerFields: job[ param ] = int( float( job[ param ] ) ) for k in ( 'flags', 'times' ): job[ k ] = {} for field in indexes[ k ]: value = record[ indexes[ k ][ field ] ] if value.lower() == "none": continue if k == 'flags': job[ k ][ field ] = value.lower() == 'true' else: job[ k ][ field ] = value retData[ 'jobs' ].append( job ) return retData
def __getJobCounters( selDict ): cutDate = selDict.pop('cutDate','') result = getRPCClient( "WorkloadManagement/JobMonitoring" ).getCounters( ['Status'], selDict, cutDate) if not result[ 'OK' ]: bottle.abort( 500, result[ 'Message' ] ) resultDict = {} for statusDict, count in result['Value']: status = statusDict['Status'] resultDict[status] = count return resultDict
def killJob( jid ): result = gOAManager.authorize() if not result[ 'OK' ]: bottle.abort( 401, result[ 'Message' ] ) wms = getRPCClient( "WorkloadManagement/JobManager" ) result = wms.killJob( jid ) if not result[ 'OK' ]: if 'NonauthorizedJobIDs' in result: bottle.abort( 401, "Not authorized" ) if 'InvalidJobIDs' in result: bottle.abort( 400, "Invalid JID" ) if 'FailedJobIDs' in result: bottle.abort( 500, "Could not delete JID" ) return { 'jid' : jid }
def putJob( jid ): result = gOAManager.authorize() if not result[ 'OK' ]: bottle.abort( 401, result[ 'Message' ] ) #Modify a job rpc = getRPCClient( 'WorkloadManagement/JobManager' ) result = rpc.rescheduleJob( jid ) if not result[ 'OK' ]: if 'InvalidJobIDs' in result: bottle.abort( 400, "Invalid JID" ) if 'FailedJobIDs' in result: bottle.abort( 500, "Could not reschedule JID" ) else: bottle.abort( 401, result[ 'Message' ] ) return { 'jid' : jid }
def __getJobDescription( jid ): result = getRPCClient( "WorkloadManagement/JobMonitoring" ).getJobJDL( jid ) if not result[ 'OK' ]: bottle.abort( 500, result[ 'Message' ] ) result = loadJDLAsCFG( result[ 'Value' ] ) if not result[ 'OK' ]: bottle.abort( 500, result[ 'Message' ] ) cfg = result[ 'Value' ][0] jobData = {} stack = [ ( cfg, jobData ) ] while stack: cfg, level = stack.pop( 0 ) for op in cfg.listOptions(): val = List.fromChar( cfg[ op ] ) if len( val ) == 1: val = val[0] level[ op ] = val for sec in cfg.listSections(): level[ sec ] = {} stack.append( ( cfg[ sec ], level[ sec ] ) ) return jobData
def getJobsHistory(): result = gOAManager.authorize() if not result[ 'OK' ]: bottle.abort( 401, result[ 'Message' ] ) condDict = {} if 'allOwners' not in bottle.request.params: condDict[ 'User' ] = gOAData.userName timeSpan = 86400 if 'timeSpan' in bottle.request.params: try: timeSpan = max( 86400, int( bottle.request.params[ 'timeSpan' ] ) ) except ValueError: bottle.abort( 400, "timeSpan has to be an integer!" ) print "[DEBUG] condDict is %s" % condDict rpg = ReportsClient( rpcClient = getRPCClient("Accounting/ReportGenerator"), transferClient = getTransferClient("Accounting/ReportGenerator") ) end = datetime.datetime.utcnow() start = end - datetime.timedelta( seconds = timeSpan ) result = rpg.getReport( "WMSHistory", "NumberOfJobs", start, end, condDict, 'Status' ) if not result[ 'OK' ]: bottle.abort( 500, "Server Error: %s" % result[ 'Message' ] ) return result[ 'Value' ]
def getWMSClient(): return WMSClient( getRPCClient( "WorkloadManagement/JobManager" ), getRPCClient( "WorkloadManagement/SandboxStore" ), getTransferClient( "WorkloadManagement/SandboxStore" ) )