Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Public Attributes | Static Public Attributes
storage.client.AHashClient Class Reference
Inheritance diagram for storage.client.AHashClient:
Inheritance graph
[legend]
Collaboration diagram for storage.client.AHashClient:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_tree
def get
def change
def reset
def call
def call_raw

Public Attributes

 ns
 urls
 https
 print_xml
 xmlnode_class
 ssl_config
 cfg
 get_trusted_dns_method
 connection_cache
 semapool

Static Public Attributes

 NS_class = arc.NS

Detailed Description

Definition at line 33 of file client.py.


Constructor & Destructor Documentation

def storage.client.AHashClient.__init__ (   self,
  url,
  print_xml = False,
  ssl_config = {} 
)

Definition at line 35 of file client.py.

00035 
00036     def __init__(self, url, print_xml = False, ssl_config = {}):
00037         ns = self.NS_class('ahash', ahash_uri)
00038         Client.__init__(self, url, ns, print_xml, ssl_config = ssl_config)


Member Function Documentation

def arcom.client.Client.call (   self,
  tree,
  return_tree_only = False 
) [inherited]
Create a SOAP message from an XMLTree and send it to the service.

call(tree, return_tree_only = False)

tree is an XMLTree object containing the content of the request
return_tree_only indicates that we only need to put the response into an XMLTree

Definition at line 60 of file client.py.

00060 
00061     def call(self, tree, return_tree_only = False):
00062         """ Create a SOAP message from an XMLTree and send it to the service.
00063         
00064         call(tree, return_tree_only = False)
00065         
00066         tree is an XMLTree object containing the content of the request
00067         return_tree_only indicates that we only need to put the response into an XMLTree
00068         """
00069         # create a new PayloadSOAP object with the given namespace
00070         out = arc.PayloadSOAP(self.ns)
00071         # add the content of the XMLTree to the XMLNode of the SOAP object
00072         tree.add_to_node(out)
00073         if self.print_xml:
00074             msg = out.GetXML()
00075             print 'Request:'
00076             print XMLTree(out).pretty_xml(indent = '    ', prefix = '        #   ')
00077             print
00078         # call the service and get back the response, and the HTTP status
00079         resp = self.call_raw(out)
00080         if self.print_xml:
00081             print 'Response:'
00082             try:
00083                 print XMLTree(from_string = resp).pretty_xml(indent = '    ', prefix = '        #   ')
00084             except:
00085                 print resp
00086             print
00087         if return_tree_only:
00088             # wrap the response into an XMLTree and return only the tree
00089             return XMLTree(from_string = resp, forget_namespace = True).get_trees('///')[0]
00090         else:
00091             return resp

Here is the call graph for this function:

Here is the caller graph for this function:

def arcom.client.Client.call_raw (   self,
  outpayload 
) [inherited]
Send a POST request with the SOAP XML message.

call_raw(outpayload)

outpayload is an XMLNode with the SOAP message

Definition at line 99 of file client.py.

00099 
00100     def call_raw(self, outpayload):
00101         """ Send a POST request with the SOAP XML message.
00102         
00103         call_raw(outpayload)
00104         
00105         outpayload is an XMLNode with the SOAP message
00106         """
00107         tid = thread.get_ident()
00108         s = self.connection_cache.get(tid, None)
00109         if s:
00110             try:
00111                 resp, status = s.process(outpayload)
00112                 if not self._fawlty(resp, status):
00113                     return resp.GetXML()
00114             except:
00115                 pass
00116             self.connection_cache[tid] = None
00117         if len(self.urls) == 0:
00118             log.msg(arc.WARNING, 'No URLs to connect to (in %s)' % str(self.__class__.__name__))
00119             raise Exception, 'No URLs to connect'
00120         random.shuffle(self.urls)
00121         #print "available URLs", [url.fullstr() for url in self.urls]
00122         for url in self.urls:
00123             #print "trying URL", url.fullstr()
00124             try:
00125                 s = arc.ClientSOAP(self.cfg, url)
00126                 if self.get_trusted_dns_method:
00127                     dnlist = self.get_trusted_dns_method()
00128                     if dnlist:
00129                         dnlistconf = arc.DNListHandlerConfig(dnlist, 'outgoing')
00130                         # _s points to the superclass, but not the object, so it needs the object as first argument
00131                         s._s._s.AddSecHandler(s, dnlistconf, arc.TLSSec)
00132                 resp, status = s.process(outpayload)
00133                 fawlty = self._fawlty(resp, status)
00134                 if fawlty:
00135                     raise Exception, fawlty
00136                 resp = resp.GetXML()
00137                 self.connection_cache[tid] = s
00138                 return resp
00139             except:
00140                 log.msg(arc.WARNING, "ERROR connecting to", url.fullstr())
00141                 pass
00142         log.msg(arc.ERROR, "ERROR connecting to all of these:", ', '.join([url.fullstr() for url in self.urls]))
00143         raise

Here is the call graph for this function:

Here is the caller graph for this function:

def storage.client.AHashClient.change (   self,
  changes 
)
Call the change method of the A-Hash service.

change(changes)

'changes' is a dictionary of {changeID : (ID, changeType, section, property, value, conditions)}
    where 'conditions' is a dictionary of {conditionID : (conditionType, section, property, value)}

Definition at line 93 of file client.py.

00093 
00094     def change(self, changes):
00095         """ Call the change method of the A-Hash service.
00096         
00097         change(changes)
00098 
00099         'changes' is a dictionary of {changeID : (ID, changeType, section, property, value, conditions)}
00100             where 'conditions' is a dictionary of {conditionID : (conditionType, section, property, value)}
00101         """
00102         
00103         tree = XMLTree(from_tree =
00104             ('ahash:change', [
00105                 ('ahash:changeRequestList', [
00106                     ('ahash:changeRequestElement', [
00107                         ('ahash:changeID', changeID),
00108                         ('ahash:ID', ID),
00109                         ('ahash:changeType', changeType),
00110                         ('ahash:section', section),
00111                         ('ahash:property', property),
00112                         ('ahash:value', value),
00113                         ('ahash:conditionList', [
00114                             ('ahash:condition', [
00115                                 ('ahash:conditionID', conditionID),
00116                                 ('ahash:conditionType',conditionType),
00117                                 ('ahash:section',conditionSection),
00118                                 ('ahash:property',conditionProperty),
00119                                 ('ahash:value',conditionValue)
00120                             ]) for conditionID, (conditionType, conditionSection,
00121                                         conditionProperty, conditionValue) in conditions.items()
00122                         ])
00123                     ]) for changeID, (ID, changeType, section, property, value, conditions) in changes.items()
00124                 ])
00125             ])
00126         )
00127         self.semapool.acquire()
00128         msg = self.call(tree)
00129         self.semapool.release()
00130         xml = self.xmlnode_class(msg)
00131         return parse_node(get_data_node(xml), ['changeID', 'success', 'conditionID'])

Here is the call graph for this function:

def storage.client.AHashClient.get (   self,
  IDs,
  neededMetadata = [] 
)

Definition at line 71 of file client.py.

00071 
00072     def get(self, IDs, neededMetadata = []):
00073         tree = XMLTree(from_tree =
00074             ('ahash:get', [
00075                 ('ahash:neededMetadataList', [
00076                     ('ahash:neededMetadataElement', [
00077                         ('ahash:section', section),
00078                         ('ahash:property', property)
00079                     ]) for section, property in neededMetadata
00080                 ]),
00081                 ('ahash:IDs', [
00082                     ('ahash:ID', i) for i in IDs
00083                 ])
00084             ])
00085         )
00086         msg = self.call(tree)
00087         xml = self.xmlnode_class(msg)
00088         error = str(xml.Get('Body').Child().Get('error'))
00089         if error:
00090             raise Exception, error
00091         objects = parse_node(get_data_node(xml), ['ID', 'metadataList'], single = True, string = False)
00092         return dict([(str(ID), parse_metadata(metadataList)) for ID, metadataList in objects.items()])

Here is the call graph for this function:

def storage.client.AHashClient.get_tree (   self,
  IDs,
  neededMetadata = [] 
)

Definition at line 39 of file client.py.

00039 
00040     def get_tree(self, IDs, neededMetadata = []):
00041         tree = XMLTree(from_tree =
00042             ('ahash:get', [
00043                 ('ahash:neededMetadataList', [
00044                     ('ahash:neededMetadataElement', [
00045                         ('ahash:section', section),
00046                         ('ahash:property', property)
00047                     ]) for section, property in neededMetadata
00048                 ]),
00049                 ('ahash:IDs', [
00050                     ('ahash:ID', i) for i in IDs
00051                 ])
00052             ])
00053         )
00054         msg = self.call(tree)
00055         xml = self.xmlnode_class(msg)
00056         error = str(xml.Get('Body').Child().Get('error'))
00057         if error:
00058             raise Exception, error
00059         ahash_prefix = xml.NamespacePrefix(ahash_uri)
00060         rewrite = {
00061             ahash_prefix + ':objects' : 'lbr:getResponseList',
00062             ahash_prefix + ':object' : 'lbr:getResponseElement',
00063             ahash_prefix + ':ID' : 'lbr:GUID',
00064             ahash_prefix + ':metadataList' : 'lbr:metadataList',
00065             ahash_prefix + ':metadata' : 'lbr:metadata',
00066             ahash_prefix + ':section' : 'lbr:section',
00067             ahash_prefix + ':property' : 'lbr:property',
00068             ahash_prefix + ':value' : 'lbr:value'
00069         }
00070         return XMLTree(get_data_node(xml), rewrite = rewrite)

Here is the call graph for this function:

def arcom.client.Client.reset (   self) [inherited]

Definition at line 56 of file client.py.

00056 
00057     def reset(self):
00058         tid = thread.get_ident()
00059         self.connection_cache[tid] = None


Member Data Documentation

Definition at line 34 of file client.py.

Definition at line 36 of file client.py.

Definition at line 35 of file client.py.

Definition at line 30 of file client.py.

Definition at line 24 of file client.py.

arcom.client.Client.NS_class = arc.NS [static, inherited]

Definition at line 13 of file client.py.

Definition at line 31 of file client.py.

Definition at line 38 of file client.py.

Definition at line 33 of file client.py.

Definition at line 29 of file client.py.

Definition at line 32 of file client.py.


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