This wiki is obsolete, see the NorduGrid web pages for up to date information.
NOX/Python ARClib
From NorduGrid
< NOX
Jump to navigationJump to search
ARC lib examples
The ARC client library is also available in python. It is very useful as basis for writing Grid applications, job management scripts or similar. The following examples show the basic job cycle with submission, status and output retrieval and cleaning of jobs.
Submit jobs
This basic example shows how to retrieve possible target clusters and submit jobs.
#!/usr/bin/python import arc, sys joblist = "jobs.xml" usercfg = arc.UserConfig("","") logger = arc.Logger(arc.Logger_getRootLogger(), "arcsub.py") logcout = arc.LogStream(sys.stdout) arc.Logger_getRootLogger().addDestination(logcout) arc.Logger_getRootLogger().setThreshold(arc.ERROR) targen = arc.TargetGenerator(usercfg) targen.GetTargets(0, 1) targets = targen.FoundTargets() job = arc.JobDescription() job.Application.Executable.Name = '/bin/echo' job.Application.Executable.Argument.append('Hello') job.Application.Executable.Argument.append('World') job.Application.Output = 'std.out' #std.out will be not deleted if it is finished job_output = arc.FileType() job_output.Name = 'std.out' job.DataStaging.File.append(job_output) info = arc.XMLNode(arc.NS(), 'Jobs') for target in targets: submitter = target.GetSubmitter(usercfg) print 'Submitting to ', target.Cluster.ConnectionURL() submitted = submitter.Submit(job, target) if submitted: print "Job ID: " + submitted.fullstr() # Uncomment break if one wants to submit only one job #break;
Job status
This example shows how to list the status of all jobs a user has in the system. It corresponds to the "arcstat -a" command.
#!/usr/bin/python import arc, sys; usercfg = arc.UserConfig(""); joblist = "jobs.xml"; # Logging... logger = arc.Logger(arc.Logger_getRootLogger(), "arcstat.py"); logcout = arc.LogStream(sys.stdout); arc.Logger_getRootLogger().addDestination(logcout); arc.Logger_getRootLogger().setThreshold(arc.ERROR); jobmaster = arc.JobSupervisor(usercfg,[]); jobcontrollers = jobmaster.GetJobControllers(); for job in jobcontrollers: job.PrintJobStatus([], True);
Get results
This example shows how to download the jobs once they are finished. It corresponds to "arcget -a".
#!/usr/bin/python import arc, sys; # User configuration file. # Initialise a default user configuration. usercfg = arc.UserConfig("","") # List of job ids to process. jobids = sys.argv[1:]; # List of clusters to process. clusters = []; # Job list containing active jobs. joblist = "jobs.xml"; # Process only jobs with the following status codes. # If list is empty all jobs will be processed. status = []; # Directory where the job directory will be created. downloaddir = "/scratch/knowarc/test/"; # Keep the files on the server. keep = False; # Logging... logger = arc.Logger(arc.Logger_getRootLogger(), "arcget.py"); logcout = arc.LogStream(sys.stdout); arc.Logger_getRootLogger().addDestination(logcout); arc.Logger_getRootLogger().setThreshold(arc.ERROR); jobmaster = arc.JobSupervisor(usercfg,[]); jobcontrollers = jobmaster.GetJobControllers(); i = 0 for job in jobcontrollers: job.Get(status, downloaddir, keep); i += 1