Back to index

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

List of all members.

Public Member Functions

def __init__
def get
def change
def RegistrationCollector
def GetAdditionalLocalInformation
def GetLocalInformation
def process

Public Attributes

 service_name
 ahash
 ssl_config
 state
 request_config
 ns

Detailed Description

AHashService class implementing the XML interface of the A-Hash service. 

Definition at line 203 of file ahash.py.


Constructor & Destructor Documentation

def storage.ahash.ahash.AHashService.__init__ (   self,
  cfg 
)
Constructor of the AHashService

AHashService(cfg)

'cfg' is an XMLNode which containes the config of this service.

Definition at line 206 of file ahash.py.

00206 
00207     def __init__(self, cfg):
00208         """ Constructor of the AHashService
00209 
00210         AHashService(cfg)
00211 
00212         'cfg' is an XMLNode which containes the config of this service.
00213         """
00214         self.service_name = 'A-Hash'
00215         # names of provided methods
00216         request_names = ['get','change']
00217         # the name of the class which implements the business logic of the A-Hash service
00218         ahashclass = str(cfg.Get('AHashClass'))
00219         # import and instatiate the business logic class
00220         try:
00221             cl = import_class_from_string(ahashclass)
00222         except:
00223             log.msg(arc.ERROR, 'Error importing class', ahashclass)
00224             raise Exception, 'A-Hash cannot run.'
00225         self.ahash = cl(cfg)
00226         ahash_request_names = self.ahash.public_request_names
00227         # bring the additional request methods into the namespace of this object
00228         for name in ahash_request_names:
00229             if not hasattr(self, name):
00230                 setattr(self, name, getattr(self.ahash, name))
00231                 request_names.append(name)
00232         # call the Service's constructor
00233         Service.__init__(self, [{'request_names' : request_names, 'namespace_prefix': 'ahash', 'namespace_uri': ahash_uri}], cfg)
00234         self.ahash.ns = self.ns


Member Function Documentation

def storage.ahash.ahash.AHashService.change (   self,
  inpayload 
)
Make changes in objects, if given conditions are met, return which change was successful.

change(inpayload)

'inpayload' is an XMLNode containing the change requests.

Definition at line 280 of file ahash.py.

00280 
00281     def change(self, inpayload):
00282         """ Make changes in objects, if given conditions are met, return which change was successful.
00283 
00284         change(inpayload)
00285 
00286         'inpayload' is an XMLNode containing the change requests.
00287         """
00288         # get the grandchild of the root node, which is the 'changeRequestList'
00289         requests_node = inpayload.Child().Child()
00290         # get all the requests:
00291         request_nodes = [requests_node.Child(i) for i in range(requests_node.Size())]
00292         # prepare the dictionary which will hold the requests
00293         changes = {}
00294         # for each request:
00295         for request_node in request_nodes:
00296             # get all the data: changeID, ID, changeType, section, property, value, conditions
00297             changeID, change = node_to_data(request_node,
00298                 ['changeID', 'ID', 'changeType', 'section', 'property', 'value'])
00299             # get the conditionList node
00300             conditionList_node = request_node.Get('conditionList')
00301             # get the nodes of all the conditions
00302             condition_nodes = [conditionList_node.Child(i) for i in range(conditionList_node.Size())]
00303             # for each condition get all the data: conditionID, conditionType, section, property, value
00304             conditions = dict([
00305                 node_to_data(condition_node, ['conditionID', 'conditionType', 'section', 'property', 'value'])
00306                     for condition_node in condition_nodes
00307             ])
00308             # append the conditions dict to the chnage request
00309             change.append(conditions)
00310             # put this change request into the changes dictionary
00311             changes[changeID] = change
00312         # prepare the response payload
00313         out = self._new_soap_payload()
00314         # create the 'changeResponse' node
00315         response_node = out.NewChild('ahash:changeResponse')
00316         # call the business logic class
00317         try:
00318             resp = self.ahash.change(changes)
00319         except:
00320             error_node = response_node.NewChild('ahash:error')
00321             error_node.Set('ahash is not ready')
00322             return out
00323         # create an XMLTree for the response
00324         tree = XMLTree(from_tree = 
00325             ('ahash:changeResponseList', [
00326                 ('ahash:changeResponseElement', [ # for each change
00327                     ('ahash:changeID', changeID),
00328                     ('ahash:success', success),
00329                     ('ahash:conditionID', conditionID)
00330                 ]) for (changeID, (success, conditionID)) in resp.items()
00331             ])
00332         )
00333         # add the XMLTree to the XMLNode
00334         tree.add_to_node(response_node)
00335         return out

Here is the call graph for this function:

def storage.ahash.ahash.AHashService.get (   self,
  inpayload 
)
Returns the data of the requested objects.

get(inpayload)

'inpayload' is an XMLNode containing the IDs of the requested objects

Definition at line 235 of file ahash.py.

00235 
00236     def get(self, inpayload):
00237         """ Returns the data of the requested objects.
00238 
00239         get(inpayload)
00240 
00241         'inpayload' is an XMLNode containing the IDs of the requested objects
00242         """
00243         # if inpayload.auth:
00244         #     print 'A-Hash auth "get": ', inpayload.auth
00245         # extract the IDs from the XMLNode using the '//ID' XPath expression
00246         ids = [str(id) for id in inpayload.XPathLookup('//ahash:ID', self.ns)]
00247         # get the neededMetadata from the XMLNode
00248         try:
00249             neededMetadata = [
00250                 node_to_data(node, ['section', 'property'], single = True)
00251                     for node in get_child_nodes(inpayload.Child().Get('neededMetadataList'))
00252             ]
00253         except:
00254             log.msg()
00255             neededMetadata = []
00256         # create the response payload
00257         out = self._new_soap_payload()
00258         # create the 'getResponse' node
00259         response_node = out.NewChild('ahash:getResponse')
00260         # gets the result from the business logic class
00261         try:
00262             objects = self.ahash.get(ids, neededMetadata)
00263         except:
00264             error_node = response_node.NewChild('ahash:error')
00265             error_node.Set('ahash is not ready')
00266             return out
00267         # create an XMLTree from the results
00268         tree = XMLTree(from_tree = 
00269             ('ahash:objects', [
00270                 ('ahash:object', [ # for each object
00271                     ('ahash:ID', ID),
00272                     # create the metadata section of the response:
00273                     ('ahash:metadataList', create_metadata(metadata, 'ahash'))
00274                 ]) for (ID, metadata) in objects.items()
00275             ])
00276         )
00277         # convert to tree to XML via adding it to the 'getResponse' node
00278         tree.add_to_node(response_node)
00279         return out

Here is the call graph for this function:

Definition at line 343 of file ahash.py.

00343 
00344     def GetAdditionalLocalInformation(self, service_node):
00345         service_node.NewChild('Type').Set(ahash_servicetype)
00346 
00347 

Here is the caller graph for this function:

def arcom.service.Service.GetLocalInformation (   self) [inherited]

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 
) [inherited]
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:

Definition at line 336 of file ahash.py.

00336 
00337     def RegistrationCollector(self, doc):
00338         regentry = arc.XMLNode('<RegEntry />')
00339         regentry.NewChild('SrcAdv').NewChild('Type').Set(ahash_servicetype)
00340         #Place the document into the doc attribute
00341         doc.Replace(regentry)
00342         return True


Member Data Documentation

Definition at line 224 of file ahash.py.

Definition at line 92 of file service.py.

Definition at line 91 of file service.py.

Reimplemented from arcom.service.Service.

Definition at line 213 of file ahash.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: