Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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 }
Exemplo n.º 4
0
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 }
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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' ]  
Exemplo n.º 7
0
def getWMSClient():
  return WMSClient( getRPCClient( "WorkloadManagement/JobManager" ),
                    getRPCClient( "WorkloadManagement/SandboxStore" ),
                    getTransferClient( "WorkloadManagement/SandboxStore" ) )