ARC SDK
Service Discovery
1 #! /usr/bin/env python
2 import arc
3 import sys
4 import os
5 
6 def retrieve(uc, endpoints):
7  # The ComputingServiceRetriever needs the UserConfig to know which credentials
8  # to use in case of HTTPS connections
9  retriever = arc.ComputingServiceRetriever(uc, endpoints)
10  # the constructor of the ComputingServiceRetriever returns immediately
11  print
12  print "ComputingServiceRetriever created with the following endpoints:"
13  for endpoint in endpoints:
14  print "-", endpoint.str()
15  # here we want to wait until all the results arrive
16  print "Waiting for the results..."
17  retriever.wait()
18  return retriever
19 
20 def example():
21  # Creating a UserConfig object with the user's proxy
22  # and the path of the trusted CA certificates
23  uc = arc.UserConfig()
24  uc.ProxyPath("/tmp/x509up_u%s" % os.getuid())
25  uc.CACertificatesDirectory("/etc/grid-security/certificates")
26 
27  # Query two registries (index servers) for Computing Services
28  registries = [
29  # for the index1, we specify that it is an EGIIS service
30  arc.Endpoint("index1.nordugrid.org", arc.Endpoint.REGISTRY, "org.nordugrid.ldapegiis"),
31  # for the arc-emi.grid.upjs.sk, we don't specify the type (the InterfaceName)
32  # we let the system to try all possibilities
33  arc.Endpoint("arc-emi.grid.upjs.sk/O=Grid/Mds-Vo-Name=ARC-EMI", arc.Endpoint.REGISTRY)
34  ]
35 
36  retriever = retrieve(uc, registries)
37 
38  # The retriever acts as a list containing all the discovered ComputingServices:
39  print "Discovered ComputingServices:", ", ".join([service.Name for service in retriever])
40 
41  # Get all the ExecutionTargets on these ComputingServices
42  targets = retriever.GetExecutionTargets()
43  print "Number of ExecutionTargets on these ComputingServices:", len(targets)
44 
45  # Query the local infosys (COMPUTINGINFO) of computing elements
46  computing_elements = [
47  # for piff, we specify that we want to query the LDAP GLUE2 tree
48  arc.Endpoint("piff.hep.lu.se", arc.Endpoint.COMPUTINGINFO, "org.nordugrid.ldapglue2"),
49  # for pgs03, we don't specify the interface, we let the system try all possibilities
50  arc.Endpoint("pgs03.grid.upjs.sk", arc.Endpoint.COMPUTINGINFO)
51  ]
52 
53  retriever2 = retrieve(uc, computing_elements)
54 
55  # Get all the ExecutionTargets on these ComputingServices
56  targets2 = retriever2.GetExecutionTargets()
57 
58  print "The discovered ExecutionTargets:"
59  for target in targets2:
60  print target
61 
62 
63  # Query both registries and computing elements at the same time:
64  endpoints = [
65  arc.Endpoint("arc-emi.grid.upjs.sk/O=Grid/Mds-Vo-Name=ARC-EMI", arc.Endpoint.REGISTRY),
66  arc.Endpoint("piff.hep.lu.se", arc.Endpoint.COMPUTINGINFO, "org.nordugrid.ldapglue2")
67  ]
68 
69  retriever3 = retrieve(uc, endpoints)
70 
71  print "Discovered ComputingServices:", ", ".join([service.Name for service in retriever3])
72 
73 
74 # wait for all the background threads to finish before we destroy the objects they may use
75 import atexit
76 @atexit.register
77 def wait_exit():
78  arc.ThreadInitializer().waitExit()
79 
80 # arc.Logger.getRootLogger().addDestination(arc.LogStream(sys.stderr))
81 # arc.Logger.getRootLogger().setThreshold(arc.DEBUG)
82 
83 # run the example
84 example()