Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
arcom.service.Service Class Reference
Inheritance diagram for arcom.service.Service:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def __del__
def GetLocalInformation
def process

Public Attributes

 ssl_config
 state
 service_name
 request_config
 ns

Private Member Functions

def _get_dns_from_ahash
def _is_trusted
def _get_trusted_dns
def _new_soap_payload
def _call_request

Private Attributes

 _trust_manager
 _force_trust

Detailed Description

Definition at line 43 of file service.py.


Constructor & Destructor Documentation

def arcom.service.Service.__init__ (   self,
  request_config,
  cfg = None,
  start_service = True 
)

Definition at line 45 of file service.py.

00045 
00046     def __init__(self, request_config, cfg = None, start_service = True):
00047         self._trust_manager = []
00048         self.ssl_config = {}
00049         self._force_trust = False
00050         self.state = ServiceState(start_service)
00051         if cfg:
00052             self.ssl_config = parse_ssl_config(cfg)
00053             trust_manager_node = cfg.Get('TrustManager')
00054             fromFile = str(trust_manager_node.Attribute('FromFile'))
00055             if fromFile:
00056                 try:
00057                     xml_string = file(fromFile).read()
00058                     trust_manager_node = arc.XMLNode(xml_string)
00059                 except:
00060                     log.msg()
00061                     pass
00062             self._force_trust = str(trust_manager_node.Attribute('Force')) not in ['no', 'No', 'NO']
00063             entries = get_child_nodes(trust_manager_node)
00064             for entry in entries:
00065                 name = entry.Name()
00066                 if name in ['DN', 'CA']:
00067                     self._trust_manager.append({'type': name, 'DNs': [str(entry)]})
00068                 if name in ['DNsFromAHash']:
00069                     try:
00070                         checking_interval = int(str(entry.Attribute('CheckingInterval')))
00071                     except:
00072                         checking_interval = None
00073                     if not checking_interval:
00074                         checking_interval = default_checking_interval
00075                     ahash_id = str(entry.Attribute('ID'))
00076                     if not ahash_id:
00077                         ahash_id = default_ahash_id
00078                     ahashes = get_child_nodes(entry)
00079                     ahash_urls = []
00080                     for ahash in ahashes:
00081                         if ahash.Name() == 'AHashURL':
00082                             ahash_urls.append(str(ahash))
00083                     data = {'type': name, 'DNs' : [], 'URLs' : ahash_urls,
00084                         'checking_interval' : checking_interval, 'ahash_id' : ahash_id}
00085                     self._trust_manager.append(data)
00086                     threading.Thread(target = self._get_dns_from_ahash, args = [data]).start()
00087         if not hasattr(self,'service_name'):
00088             self.service_name = 'Python Service With No Name'
00089         #if self._trust_manager:
00090         #    print self.service_name, "TrustManager:", self._force_trust and 'force' or 'don\'t force', self._trust_manager
00091         log.msg(arc.INFO, "Starting:", self.service_name)
00092         self.request_config = request_config
00093         self.ns = arc.NS(dict([(request_type['namespace_prefix'], request_type['namespace_uri'])
00094             for request_type in self.request_config]))
        

Reimplemented in storage.librarian.librarian.LibrarianService.

Definition at line 95 of file service.py.

00095 
00096     def __del__(self):
00097         try:
00098             self.state.running = False
00099         except:
00100             pass
00101         log.msg(arc.INFO, "Stopping:", self.service_name)
    

Here is the caller graph for this function:


Member Function Documentation

def arcom.service.Service._call_request (   self,
  request_name,
  inmsg 
) [private]

Reimplemented in storage.shepherd.byteio.ByteIOService.

Definition at line 154 of file service.py.

00154 
00155     def _call_request(self, request_name, inmsg):
00156         inpayload = inmsg.Payload()
00157         auth = AuthRequest(inmsg)
00158         inpayload.auth = auth
00159         if self._force_trust and not self._is_trusted(*auth.get_identity_and_ca()):
00160             raise Exception, 'client is not trusted'
00161         return getattr(self,request_name)(inpayload)
    

Here is the call graph for this function:

Here is the caller graph for this function:

def arcom.service.Service._get_dns_from_ahash (   self,
  data 
) [private]

Definition at line 102 of file service.py.

00102 
00103     def _get_dns_from_ahash(self, data):
00104         try:
00105             from storage.client import AHashClient
00106         except:
00107             log.msg()
00108         # first just wait a few seconds
00109         time.sleep(10)
00110         while True:
00111             try:
00112                 #print "Start getting a list of DNs from an AHash"
00113                 ahash_url = random.choice(data['URLs'])
00114                 #print "Chosen AHash:", ahash_url
00115                 ahash = AHashClient(ahash_url, ssl_config = self.ssl_config)
00116                 results = ahash.get([data['ahash_id']])[data['ahash_id']]
00117                 data['DNs'] = [DN for (_, DN) in results.keys()]
00118                 #print "data", data
00119                 #print "Done, waiting for %d seconds" % data['checking_interval']
00120                 time.sleep(data['checking_interval'])
00121             except:
00122                 log.msg()
00123                 time.sleep(1)
    
def arcom.service.Service._get_trusted_dns (   self) [private]

Definition at line 144 of file service.py.

00144 
00145     def _get_trusted_dns(self):
00146         dns = []
00147         for entry in self._trust_manager:
00148             if entry['type'] in ['DN' or 'DNsFromAHash']:
00149                 dns.extend(entry['DNs'])
00150         return dns
    
def arcom.service.Service._is_trusted (   self,
  DN,
  CA 
) [private]

Definition at line 124 of file service.py.

00124 
00125     def _is_trusted(self, DN, CA):
00126         if not self._trust_manager:
00127             return True
00128         #print '_is_trusted called with', DN, CA
00129         trusted = False
00130         for entry in self._trust_manager:
00131             if entry['type'] == 'DN':
00132                 if DN in entry['DNs']:
00133                     #print DN, 'is listed as trusted'
00134                     trusted = True
00135             if entry['type'] == 'CA':
00136                 if CA in entry['DNs']:
00137                     #print DN, 'has a CA which is listed as trusted'
00138                     trusted = True
00139             if entry['type'] == 'DNsFromAHash':
00140                 if DN in entry['DNs']:
00141                     #print DN, 'is listed as trusted in these AHashes:', ', '.join(entry['URLs'])
00142                     trusted = True
00143         return trusted
        

Here is the caller graph for this function:

def arcom.service.Service._new_soap_payload (   self) [private]

Definition at line 151 of file service.py.

00151 
00152     def _new_soap_payload(self):
00153         return arc.PayloadSOAP(self.ns)
    

Here is the caller graph for this function:

Definition at line 162 of file service.py.

00162 
00163     def GetLocalInformation(self):
00164         ns = arc.NS({'':'http://schemas.ogf.org/glue/2008/05/spec_2.0_d41_r01'})
00165         info = arc.XMLNode(ns,'Domains')
00166         service_node = info.NewChild('AdminDomain').NewChild('Services').NewChild('Service')
00167         endpoint_node = service_node.NewChild('Endpoint')
00168         endpoint_node.NewChild('HealthState').Set('ok')
00169         if self.state.running:
00170             serving_state = 'production'
00171         else:
00172             serving_state = 'closed'
00173         endpoint_node.NewChild('ServingState').Set(serving_state)
00174         try:
00175             self.GetAdditionalLocalInformation(service_node)
00176         except:
00177             pass
00178         return info
    

Here is the call graph for this function:

Here is the caller graph for this function:

def arcom.service.Service.process (   self,
  inmsg,
  outmsg 
)
Method to process incoming message and create outgoing one. 

Definition at line 179 of file service.py.

00179 
00180     def process(self, inmsg, outmsg):
00181         """ Method to process incoming message and create outgoing one. """
00182         # gets the payload from the incoming message
00183         inpayload = inmsg.Payload()
00184         try:
00185             # the first child of the payload should be the name of the request
00186             request_node = inpayload.Child()
00187             # get the namespace of the request node
00188             request_namespace = request_node.Namespace()
00189             matched_request_types = [request_type for request_type in self.request_config if request_type['namespace_uri'] == request_namespace]
00190             if len(matched_request_types) == 0:
00191                 # check if it is a LIDI request:
00192                 if request_namespace == wsrf_rp_uri:
00193                     outpayload = arc.PayloadSOAP(arc.NS({'wsrf-rp':wsrf_rp_uri}))
00194                     outpayload.NewChild('wsrf-rp:GetResourcePropertyDocumentResponse').NewChild(self.GetLocalInformation())
00195                     outmsg.Payload(outpayload)
00196                     return arc.MCC_Status(arc.STATUS_OK)
00197                 raise Exception, 'wrong namespace. expected: %s' % ', '.join([request_type['namespace_uri'] for request_type in self.request_config])
00198             current_request_type = matched_request_types[0]
00199             # get the name of the request without the namespace prefix
00200             request_name = request_node.Name()
00201             if request_name not in current_request_type['request_names']:
00202                 # if the name of the request is not in the list of supported request names
00203                 raise Exception, 'wrong request (%s)' % request_name
00204             log.msg(arc.VERBOSE,'%(sn)s.%(rn)s called' % {'sn':self.service_name, 'rn':request_name})
00205             if not self.state.running:
00206                 outpayload = arc.PayloadSOAP(self.ns, True)
00207                 fault = outpayload.Fault()
00208                 fault.Reason('%s service is inactive (not initialized yet or shutting down)' % self.service_name) 
00209                 outmsg.Payload(outpayload)
00210                 return arc.MCC_Status(arc.STATUS_OK)
00211             # if the request name is in the supported names,
00212             # then this class should have a method with this name
00213             # the 'getattr' method returns this method
00214             # which then we could call with the incoming payload
00215             # and which will return the response payload
00216             log.msg(arc.DEBUG, inpayload.GetXML())
00217             outpayload = self._call_request(request_name, inmsg)
00218             # sets the payload of the outgoing message
00219             outmsg.Payload(outpayload)
00220             # return with the STATUS_OK status
00221             return arc.MCC_Status(arc.STATUS_OK)
00222         except:
00223             # if there is any exception, print it
00224             msg = log.msg()
00225             outpayload = arc.PayloadSOAP(self.ns, True)
00226             fault = outpayload.Fault()
00227             fault.Reason('%s service raised a %s' % (self.service_name, msg))
00228             outmsg.Payload(outpayload)
00229             return arc.MCC_Status(arc.STATUS_OK)

Here is the call graph for this function:


Member Data Documentation

Definition at line 48 of file service.py.

Definition at line 46 of file service.py.

Definition at line 92 of file service.py.

Definition at line 91 of file service.py.

Definition at line 47 of file service.py.

Definition at line 49 of file service.py.


The documentation for this class was generated from the following file: