Back to index

nordugrid-arc-nox  1.1.0~rc6
Classes | Functions | Variables
arcom.service Namespace Reference

Classes

class  ServiceState
class  Service

Functions

def parse_node
def parse_to_dict
def create_response
def node_to_data
def get_data_node

Variables

string ahash_uri = 'http://www.nordugrid.org/schemas/ahash'
string librarian_uri = 'http://www.nordugrid.org/schemas/librarian'
string bartender_uri = 'http://www.nordugrid.org/schemas/bartender'
string shepherd_uri = 'http://www.nordugrid.org/schemas/shepherd'
string gateway_uri = 'http://www.nordugrid.org/schemas/gateway'
string delegation_uri = 'http://www.nordugrid.org/schemas/delegation'
string rbyteio_uri = 'http://schemas.ggf.org/byteio/2005/10/random-access'
string wsrf_rp_uri = 'http://docs.oasis-open.org/wsrf/rp-2'
string ahash_servicetype = 'org.nordugrid.storage.ahash'
string librarian_servicetype = 'org.nordugrid.storage.librarian'
string bartender_servicetype = 'org.nordugrid.storage.bartender'
string shepherd_servicetype = 'org.nordugrid.storage.shepherd'
string byteio_simple_uri = 'http://schemas.ggf.org/byteio/2005/10/transfer-mechanisms/simple'
string true = '1'
string false = '0'
int default_checking_interval = 600
string default_ahash_id = '3'
tuple log = Logger(arc.Logger(arc.Logger_getRootLogger(), 'Storage.Service'))

Function Documentation

def arcom.service.create_response (   method_name,
  tag_names,
  elements,
  payload,
  single = False 
)
Creates an XMLNode payload from a dictionary of tag names and list of values.

create_response(method_name, tag_names, elements, payload, single = False)

method_name is the name of the method which will be used as a prefix in the name of the 'Response' tag
tag_names is a list of names which will be used in the specified order as tag names
elements is a dictionary where the key will be tagged as the first tag name,
    and the value is a list whose items will be tagged in the order of the tag_names list
payload is an XMLNode, the response will be added to that
single indicates if there is only one value per key

Example:

    elements = {'123': ['alive', '871432'], '456': ['alive', '945']}
    tag_names = ['requestID', 'state', 'size']
    method_name = 'stat'
    payload = arc.PayloadSOAP(arc.NS())

after create_response(method_name, tag_names, elements, payload, single = False) payload will contain:

    <statResponse>
        <statResponseList>
            <statResponseElement>
                <requestID>123</requestID>
                <state>alive</state>
                <size>871432</size>
            </statResponseElement>
            <statResponseElement>
                <requestID>456</requestID>
                <state>alive</state>
                <size>945</size>
            </statResponseElement>
        </statResponseList>
    </statResponse>

The method_name used to prefix the 'Response' the 'ResponseList' and 'ResponseElement' node names.
We could say
    method_name = 'ns:stat'
    tag_names = ['ns:requestID', 'ns:state', 'ns:size']
if we want namespace prefixes.

Definition at line 320 of file service.py.

00320 
00321 def create_response(method_name, tag_names, elements, payload, single = False):
00322     """ Creates an XMLNode payload from a dictionary of tag names and list of values.
00323     
00324     create_response(method_name, tag_names, elements, payload, single = False)
00325     
00326     method_name is the name of the method which will be used as a prefix in the name of the 'Response' tag
00327     tag_names is a list of names which will be used in the specified order as tag names
00328     elements is a dictionary where the key will be tagged as the first tag name,
00329         and the value is a list whose items will be tagged in the order of the tag_names list
00330     payload is an XMLNode, the response will be added to that
00331     single indicates if there is only one value per key
00332     
00333     Example:
00334     
00335         elements = {'123': ['alive', '871432'], '456': ['alive', '945']}
00336         tag_names = ['requestID', 'state', 'size']
00337         method_name = 'stat'
00338         payload = arc.PayloadSOAP(arc.NS())
00339 
00340     after create_response(method_name, tag_names, elements, payload, single = False) payload will contain:
00341     
00342         <statResponse>
00343             <statResponseList>
00344                 <statResponseElement>
00345                     <requestID>123</requestID>
00346                     <state>alive</state>
00347                     <size>871432</size>
00348                 </statResponseElement>
00349                 <statResponseElement>
00350                     <requestID>456</requestID>
00351                     <state>alive</state>
00352                     <size>945</size>
00353                 </statResponseElement>
00354             </statResponseList>
00355         </statResponse>
00356 
00357     The method_name used to prefix the 'Response' the 'ResponseList' and 'ResponseElement' node names.
00358     We could say
00359         method_name = 'ns:stat'
00360         tag_names = ['ns:requestID', 'ns:state', 'ns:size']
00361     if we want namespace prefixes.
00362     """
00363     # first create an XMLTree, then add it to the payload XMLNode
00364     from arcom.xmltree import XMLTree
00365     if single:
00366         # if there is only a single value for each key
00367         tree = XMLTree(from_tree =
00368             (method_name + 'ResponseList', [
00369                 (method_name + 'ResponseElement', [
00370                     (tag_names[0], key),
00371                     (tag_names[1], value)
00372                 ]) for key, value in elements.items()
00373             ])
00374         )
00375     else:
00376         # if there is more values for a key
00377         tree = XMLTree(from_tree =
00378             (method_name + 'ResponseList', [
00379                 (method_name + 'ResponseElement', [
00380                     (tag_names[0], key) # tag the key with the first item in tag_names
00381                 ] + [ # for each item in the values list pick the next name from tag_names
00382                     (tag_names[i + 1], values[i]) for i in range(len(values))
00383                 ]) for key, values in elements.items()
00384             ])
00385         )
00386     # create a <method_name>Response child node in the payload
00387     response_node = payload.NewChild(method_name + 'Response')
00388     # add the XMLTree to this newly created node
00389     tree.add_to_node(response_node)
00390     # return the payload XMLNode
00391     return payload

Here is the caller graph for this function:

Definition at line 454 of file service.py.

00454 
00455 def get_data_node(node):
00456     return node.Get('Body').Child().Child()
00457 

Here is the caller graph for this function:

def arcom.service.node_to_data (   node,
  names,
  single = False,
  string = True 
)
Get some children of an XMLNode and return them in a list in the specified order using the first one as a key.

node_to_data(node, names, single = False, string = True)

node is an XMLNode which has some children
names is a list of strings, the names of the children we want to extract, the first name always will be a key
single is a boolean indicating if we want only a single value thus do not put it in a list
string is a boolean indicating if we want the string values of the nodes or the nodes itself

Example:

    node:
        <changeRequest>
            <changeID>0</changeID>
            <ID>123</ID>
            <section>states</section>
            <property>neededReplicas</property>
            <value>3</value>
            <somethingElse>not interesting</somethingElse>
            <changeType>set</changeType>
        </changeRequest>
        
    names: ['changeID', 'ID', 'changeType', 'section', 'property', 'value']
    
    here changeID will be the key, and all the other names will be in a list in the specified order
    
    so it returns ('0', ['123', 'set', 'states', 'neededReplicas', '3'])
    
        ('somethingElse' is not returned)

Example:

    node:
        <getRequest>
            <GUID>11</GUID>
            <requestID>99</requestID>
        </getRequest>
        
    names: ['requestID', 'GUID']
    single: True
    
    here requestID will be the key, and GUID is the single value which won't be in a list
    
    so it returns ('99', '11')
    
        (instead of '99', ['11'])

Definition at line 392 of file service.py.

00392 
00393 def node_to_data(node, names, single = False, string = True):
00394     """ Get some children of an XMLNode and return them in a list in the specified order using the first one as a key.
00395     
00396     node_to_data(node, names, single = False, string = True)
00397     
00398     node is an XMLNode which has some children
00399     names is a list of strings, the names of the children we want to extract, the first name always will be a key
00400     single is a boolean indicating if we want only a single value thus do not put it in a list
00401     string is a boolean indicating if we want the string values of the nodes or the nodes itself
00402     
00403     Example:
00404     
00405         node:
00406             <changeRequest>
00407                 <changeID>0</changeID>
00408                 <ID>123</ID>
00409                 <section>states</section>
00410                 <property>neededReplicas</property>
00411                 <value>3</value>
00412                 <somethingElse>not interesting</somethingElse>
00413                 <changeType>set</changeType>
00414             </changeRequest>
00415             
00416         names: ['changeID', 'ID', 'changeType', 'section', 'property', 'value']
00417         
00418         here changeID will be the key, and all the other names will be in a list in the specified order
00419         
00420         so it returns ('0', ['123', 'set', 'states', 'neededReplicas', '3'])
00421         
00422             ('somethingElse' is not returned)
00423     
00424     Example:
00425     
00426         node:
00427             <getRequest>
00428                 <GUID>11</GUID>
00429                 <requestID>99</requestID>
00430             </getRequest>
00431             
00432         names: ['requestID', 'GUID']
00433         single: True
00434         
00435         here requestID will be the key, and GUID is the single value which won't be in a list
00436         
00437         so it returns ('99', '11')
00438         
00439             (instead of '99', ['11'])
00440     """
00441     if string:
00442         # if we need the strings
00443         # for each name get the string data of the child with that name,
00444         data = [str(node.Get(name)) for name in names]
00445     else:
00446         # for each name get the child node itself
00447         data = [node.Get(name) for name in names]
00448     if single:
00449         # return the first item as a key and the second item as a single value
00450         return data[0], data[1]
00451     else:
00452         # return the first item as a key, and all the rest items as a list
00453         return data[0], data[1:]

Here is the caller graph for this function:

def arcom.service.parse_node (   node,
  names,
  single = False,
  string = True 
)
Call node_to_data() for each child of the given node.

parse_node(node, names, single = False, string = True)

node is the XMLNode whose children we want to convert
names is a list of tag names which will be returned in the specified order
single indicates that we need only one value beside the key, do not put it into a list
string indicates that we need the string data of the nodes, not the nodes itself.

Example:

    xml = XMLNode('''
        <statRequestList>
            <statRequestElement>
                <requestID>0</requestID>
                <LN>/</LN>
            </statRequestElement>
            <statRequestElement>
                <requestID>1</requestID>
                <LN>/testfile</LN>
            </statRequestElement>
        </statRequestList>
    ''')
  
parse_node(xml, ['requestID','LN']) returns:
    
    {'0': ['/'], '1': ['/testfile']}


parse_node(xml, ['requestID','LN'], single = True) returns:
    
    {'0': '/', '1': '/testfile'}


parse_node(xml, ['LN','requestID'], True) returns:
    
    {'/': '0', '/testfile': '1'}


parse_node(xml, ['requestID','LN','LN']) returns:
    
    {'0': ['/', '/'], '1': ['/testfile', '/testfile']}

Definition at line 230 of file service.py.

00230 
00231 def parse_node(node, names, single = False, string = True):
00232     """ Call node_to_data() for each child of the given node.
00233     
00234     parse_node(node, names, single = False, string = True)
00235     
00236     node is the XMLNode whose children we want to convert
00237     names is a list of tag names which will be returned in the specified order
00238     single indicates that we need only one value beside the key, do not put it into a list
00239     string indicates that we need the string data of the nodes, not the nodes itself.
00240     
00241     Example:
00242     
00243         xml = XMLNode('''
00244             <statRequestList>
00245                 <statRequestElement>
00246                     <requestID>0</requestID>
00247                     <LN>/</LN>
00248                 </statRequestElement>
00249                 <statRequestElement>
00250                     <requestID>1</requestID>
00251                     <LN>/testfile</LN>
00252                 </statRequestElement>
00253             </statRequestList>
00254         ''')
00255       
00256     parse_node(xml, ['requestID','LN']) returns:
00257         
00258         {'0': ['/'], '1': ['/testfile']}
00259 
00260 
00261     parse_node(xml, ['requestID','LN'], single = True) returns:
00262         
00263         {'0': '/', '1': '/testfile'}
00264 
00265 
00266     parse_node(xml, ['LN','requestID'], True) returns:
00267         
00268         {'/': '0', '/testfile': '1'}
00269 
00270 
00271     parse_node(xml, ['requestID','LN','LN']) returns:
00272         
00273         {'0': ['/', '/'], '1': ['/testfile', '/testfile']}
00274 
00275 
00276     """
00277     return dict([
00278         node_to_data(n, names, single, string)
00279             for n in get_child_nodes(node)
00280     ])

Here is the call graph for this function:

Here is the caller graph for this function:

def arcom.service.parse_to_dict (   node,
  names 
)
Convert the children of the node to a dictionary of dictionaries.

parse_to_dict(node, names)

node is the XMLNode whose children we want to convert
names is a list of tag names, for each child only these names will be included in the dictionary

Example:

    <statResponseList>
        <statResponseElement>
            <requestID>123</requestID>
            <referenceID>abdad</referenceID>
            <state>alive</state>
            <size>871432</size>
        </statResponseElement>
        <statResponseElement>
            <requestID>456</requestID>
            <referenceID>fefeg</referenceID>
            <state>alive</state>
            <size>945</size>
        </statResponseElement>
    </statResponseList>
    
parse_to_dict(xml, ['requestID', 'state', 'size']) returns:

    {'123': {'size': '871432', 'state': 'alive'},
     '456': {'size': '945', 'state': 'alive'}}


parse_to_dict(xml, ['referenceID','requestID', 'state', 'size']) returns:

    {'abdad': {'requestID': '123', 'size': '871432', 'state': 'alive'},
     'fefeg': {'requestID': '456', 'size': '945', 'state': 'alive'}}

Definition at line 281 of file service.py.

00281 
00282 def parse_to_dict(node, names):
00283     """ Convert the children of the node to a dictionary of dictionaries.
00284     
00285     parse_to_dict(node, names)
00286     
00287     node is the XMLNode whose children we want to convert
00288     names is a list of tag names, for each child only these names will be included in the dictionary
00289     
00290     Example:
00291     
00292         <statResponseList>
00293             <statResponseElement>
00294                 <requestID>123</requestID>
00295                 <referenceID>abdad</referenceID>
00296                 <state>alive</state>
00297                 <size>871432</size>
00298             </statResponseElement>
00299             <statResponseElement>
00300                 <requestID>456</requestID>
00301                 <referenceID>fefeg</referenceID>
00302                 <state>alive</state>
00303                 <size>945</size>
00304             </statResponseElement>
00305         </statResponseList>
00306         
00307     parse_to_dict(xml, ['requestID', 'state', 'size']) returns:
00308 
00309         {'123': {'size': '871432', 'state': 'alive'},
00310          '456': {'size': '945', 'state': 'alive'}}
00311 
00312 
00313     parse_to_dict(xml, ['referenceID','requestID', 'state', 'size']) returns:
00314     
00315         {'abdad': {'requestID': '123', 'size': '871432', 'state': 'alive'},
00316          'fefeg': {'requestID': '456', 'size': '945', 'state': 'alive'}}
00317     """
00318     return dict([(str(n.Get(names[0])), dict([(name, str(n.Get(name))) for name in names[1:]]))
00319         for n in get_child_nodes(node)])

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

string arcom.service.ahash_servicetype = 'org.nordugrid.storage.ahash'

Definition at line 14 of file service.py.

string arcom.service.ahash_uri = 'http://www.nordugrid.org/schemas/ahash'

Definition at line 2 of file service.py.

string arcom.service.bartender_servicetype = 'org.nordugrid.storage.bartender'

Definition at line 16 of file service.py.

string arcom.service.bartender_uri = 'http://www.nordugrid.org/schemas/bartender'

Definition at line 4 of file service.py.

string arcom.service.byteio_simple_uri = 'http://schemas.ggf.org/byteio/2005/10/transfer-mechanisms/simple'

Definition at line 20 of file service.py.

Definition at line 26 of file service.py.

Definition at line 25 of file service.py.

string arcom.service.delegation_uri = 'http://www.nordugrid.org/schemas/delegation'

Definition at line 7 of file service.py.

string arcom.service.false = '0'

Definition at line 23 of file service.py.

string arcom.service.gateway_uri = 'http://www.nordugrid.org/schemas/gateway'

Definition at line 6 of file service.py.

string arcom.service.librarian_servicetype = 'org.nordugrid.storage.librarian'

Definition at line 15 of file service.py.

string arcom.service.librarian_uri = 'http://www.nordugrid.org/schemas/librarian'

Definition at line 3 of file service.py.

Definition at line 37 of file service.py.

string arcom.service.rbyteio_uri = 'http://schemas.ggf.org/byteio/2005/10/random-access'

Definition at line 8 of file service.py.

string arcom.service.shepherd_servicetype = 'org.nordugrid.storage.shepherd'

Definition at line 17 of file service.py.

string arcom.service.shepherd_uri = 'http://www.nordugrid.org/schemas/shepherd'

Definition at line 5 of file service.py.

string arcom.service.true = '1'

Definition at line 22 of file service.py.

string arcom.service.wsrf_rp_uri = 'http://docs.oasis-open.org/wsrf/rp-2'

Definition at line 10 of file service.py.