示例#1
0
def getJobs():
  result = gOAManager.authorize()
  if not result[ 'OK' ]:
    bottle.abort( 401, result[ 'Message' ] )
  selDict = {}
  startJob = 0
  maxJobs = 100
  for convList in ( attrConv, flagConv ):
    for attrPair in convList:
      jAtt = attrPair[0]
      if jAtt in bottle.request.params:
        selDict[ attrPair[1] ] = List.fromChar( bottle.request.params[ attrPair[0] ] )
  if 'allOwners' not in bottle.request.params:
    selDict[ 'Owner' ] = gOAData.userName
  if 'startJob'  in bottle.request.params:
    try:
      startJob = max( 0, int( bottle.request.params[ 'startJob' ] ) )
    except:
      bottle.abort( 400, "startJob has to be a positive integer!" )
  if 'maxJobs' in bottle.request.params:
    try:
      maxJobs = min( 1000, int( bottle.request.params[ 'maxJobs' ] ) )
    except:
      bottle.abort( 400, "maxJobs has to be a positive integer no greater than 1000!" )
  
  return __getJobs( selDict, startJob, maxJobs )
示例#2
0
def postJobs():
  result = gOAManager.authorize()
  if not result[ 'OK' ]:
    bottle.abort( 401, result[ 'Message' ] )
  request = bottle.request
  if len( request.files ):
    result = uploadSandbox( request.files )
    if not result[ 'OK' ]:
      bottle.abort( 500, result[ 'Message' ] )
    isb = result[ 'Value' ]
  else:
    isb = False
  jobs = []
  wms = getWMSClient()
  for k in request.forms:
    origData = bottle.json_lds( request.forms[ k ] )
    jobData = origData
    if isb:
      if 'InputSandbox' not in jobData:
        jobData[ 'InputSandbox' ] = []
      jobData[ 'InputSandbox' ].append( isb )
    cfg = CFG.CFG().loadFromDict( jobData )
    jdl = dumpCFGAsJDL( cfg )
    result = wms.submitJob( jdl )
    if not result[ 'OK' ]:
      bottle.abort( 500, result[ 'Message' ] )
    jobs.append( result[ 'Value' ] )
  return { 'sandbox' : isb, 'jobs' : jobs }
示例#3
0
def getJobDescription( jid ):
  result = gOAManager.authorize()
  if not result[ 'OK' ]:
    bottle.abort( 401, result[ 'Message' ] )
  try:
    jid = int( jid )
  except ValueError:
    bottle.abort( 415, "jid has to be an integer! " )
  return __getJobDescription( jid )
示例#4
0
def getJobsSummary():
  result = gOAManager.authorize()
  if not result[ 'OK' ]:
    bottle.abort( 401, result[ 'Message' ] )
  selDict = {}
  if 'allOwners' not in bottle.request.params:
    selDict[ 'Owner' ] = gOAData.userName
  # Hard code last day for the time being
  #lastUpdate = Time.dateTime() - Time.day
  #selDict['cutDate'] = lastUpdate
  return __getJobCounters( selDict )
示例#5
0
def getJob( jid ):
  result = gOAManager.authorize()
  if not result[ 'OK' ]:
    bottle.abort( 401, result[ 'Message' ] )
  try:
    jid = int( jid )
  except ValueError:
    bottle.abort( 415, "jid has to be an integer! " )
  retDict = __getJobs( { 'JobID' : jid } )
  if retDict[ 'entries' ] == 0:
    bottle.abort( 404, "Unknown jid" )
  return retDict[ 'jobs'][0]
示例#6
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 }
示例#7
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 }
示例#8
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' ]  
示例#9
0
def getGroupedJobs( groupVar ):
  from itertools import chain
  def flatten(dictionary, groupBy):
    retDict = {'entries': 0, 'jobs': []}
    for entry in dictionary[ groupBy ]:
      retDict[ 'entries' ] += entry[ 'entries' ]
      retDict[ 'jobs' ].extend( entry[ 'jobs' ] )
    return retDict

  result = gOAManager.authorize()
  if not result[ 'OK' ]:
    bottle.abort( 401, result[ 'Message' ] )
  selDict = {}
  startJob = 0
  maxJobs = 100
  for convList in ( attrConv, flagConv ):
    for attrPair in convList:
      jAtt = attrPair[0]
      if jAtt in bottle.request.params:
        selDict[ attrPair[1] ] = List.fromChar( bottle.request.params[ attrPair[0] ] )
      if groupVar == attrPair[0]:
        groupVar = attrPair[1]
  if 'allOwners' not in bottle.request.params:
    selDict[ 'Owner' ] = gOAData.userName
  if 'startJob'  in bottle.request.params:
    try:
      startJob = max( 0, int( bottle.request.params[ 'startJob' ] ) )
    except:
      bottle.abort( 400, "startJob has to be a positive integer!" )
  if 'maxJobs' in bottle.request.params:
    try:
      maxJobs = min( 1000, int( bottle.request.params[ 'maxJobs' ] ) )
    except:
      bottle.abort( 400, "maxJobs has to be a positive integer no greater than 1000!" )
  ret = __getGroupedJobs( selDict , groupVar , maxJobs )
  if 'flatten' in bottle.request.params:
    ret = flatten(ret, groupVar)
  return ret