ARC SDK
Job Filtering
1 #! /usr/bin/env python
2 import arc
3 import sys
4 import os
5 
6 def example():
7  # Creating a UserConfig object with the user's proxy
8  # and the path of the trusted CA certificates
9  uc = arc.UserConfig()
10  uc.ProxyPath("/tmp/x509up_u%s" % os.getuid())
11  uc.CACertificatesDirectory("/etc/grid-security/certificates")
12 
13  # Retrieve all the jobs from this computing element
14  endpoint = arc.Endpoint("piff.hep.lu.se:443/arex", arc.Endpoint.COMPUTINGINFO)
15  print "Querying %s for jobs..." % endpoint.str()
16  jobs = arc.JobContainer()
17  retriever = arc.JobListRetriever(uc)
18  retriever.addConsumer(jobs)
19  retriever.addEndpoint(endpoint)
20  retriever.wait()
21 
22  print "%s jobs found" % len(jobs)
23 
24  # Create a JobSupervisor to handle all the jobs
25  job_supervisor = arc.JobSupervisor(uc, jobs)
26 
27  print "Getting job states..."
28  # Update the states of the jobs
29  job_supervisor.Update()
30 
31  # Get the updated jobs
32  jobs = job_supervisor.GetAllJobs()
33 
34  print "The jobs have the following states:", ", ".join([job.State.GetGeneralState() for job in jobs])
35 
36  # Select failed jobs
37  job_supervisor.SelectByStatus(["Failed"])
38  failed_jobs = job_supervisor.GetSelectedJobs()
39 
40  print "The failed jobs:"
41  for job in failed_jobs:
42  job.SaveToStream(arc.CPyOstream(sys.stdout), True)
43 
44 # wait for all the background threads to finish before we destroy the objects they may use
45 import atexit
46 @atexit.register
47 def wait_exit():
48  arc.ThreadInitializer().waitExit()
49 
50 # arc.Logger.getRootLogger().addDestination(arc.LogStream(sys.stderr))
51 # arc.Logger.getRootLogger().setThreshold(arc.DEBUG)
52 
53 # run the example
54 example()