Back to index

nordugrid-arc-nox  1.1.0~rc6
SampleBroker.py
Go to the documentation of this file.
00001 '''
00002 Example implementation of a custom broker written in python.
00003 Invoke the broker with:
00004 
00005 arcsub -b PythonBroker:SampleBroker.MyBroker:brokerargs
00006 '''
00007 
00008 import arc
00009 import random
00010 
00011 class MyBroker:
00012 
00013     def __init__(self, usercfg):
00014 
00015         # Extract some useful information from the broker configuration
00016 
00017         self.proxypath = usercfg.ProxyPath()
00018         self.certificatepath = usercfg.CertificatePath()
00019         self.keypath = usercfg.KeyPath()
00020         self.cacertificatesdir = usercfg.CACertificatesDirectory()
00021         pos = usercfg.Broker().second.find(':')
00022         if pos > 0:
00023             self.args = usercfg.Broker.second[pos + 1:]
00024         else:
00025             self.args = ""
00026 
00027     def SortTargets(self, PossibleTargets, job):
00028 
00029         # Some printouts - only as an example
00030 
00031         print 'Proxy Path:', self.proxypath
00032         print 'Certificate Path:', self.certificatepath
00033         print 'Key Path:', self.keypath
00034         print 'CA Certificates Dir:', self.cacertificatesdir
00035 
00036         print 'Broker arguments:', self.args
00037 
00038         print 'JobName:', job.Identification.JobName
00039         print 'Executable:', job.Application.Executable.Name
00040         for i in range(job.Application.Executable.Argument.size()):
00041             print 'Argument', i, ':', job.Application.Executable.Argument[i]
00042 
00043         # Broker implementation starts here
00044 
00045         print 'Targets before brokering:'
00046 
00047         for t in PossibleTargets:
00048             print t.url.str()
00049 
00050         print 'Randomizing...'
00051 
00052         random.shuffle(PossibleTargets)
00053 
00054         print 'Targets after brokering:'
00055 
00056         for t in PossibleTargets:
00057             print t.url.str()