Ignore:
Timestamp:
Nov 20, 2008 7:14:58 PM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
Children:
cfabc40
Parents:
c922f23
Message:

Unify the code for calling SOAP and XMLRPC services into a couple classes.
Before there were slightly different semantics everywhere.

Also make the handlers classes rather than the output of stub compiling
functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_experiment_control.py

    rc922f23 r058f58e  
    145145                self.pdata.terminate()
    146146
     147    call_RequestAccess = service_caller('RequestAccess',
     148            'getfeddPortType', feddServiceLocator,
     149            RequestAccessRequestMessage, 'RequestAccessRequestBody')
     150
     151    call_ReleaseAccess = service_caller('ReleaseAccess',
     152            'getfeddPortType', feddServiceLocator,
     153            ReleaseAccessRequestMessage, 'ReleaseAccessRequestBody')
     154
     155    call_Ns2Split = service_caller('Ns2Split',
     156            'getfeddInternalPortType', feddInternalServiceLocator,
     157            Ns2SplitRequestMessage, 'Ns2SplitRequestBody')
     158
    147159    def __init__(self, config=None):
    148160        """
     
    242254        # Dispatch tables
    243255        self.soap_services = {\
    244                 'Create': make_soap_handler(\
     256                'Create': soap_handler(\
    245257                        CreateRequestMessage.typecode,
    246258                        getattr(self, "create_experiment"),
    247259                        CreateResponseMessage,
    248260                        "CreateResponseBody"),
    249                 'Vtopo': make_soap_handler(\
     261                'Vtopo': soap_handler(\
    250262                        VtopoRequestMessage.typecode,
    251263                        getattr(self, "get_vtopo"),
    252264                        VtopoResponseMessage,
    253265                        "VtopoResponseBody"),
    254                 'Vis': make_soap_handler(\
     266                'Vis': soap_handler(\
    255267                        VisRequestMessage.typecode,
    256268                        getattr(self, "get_vis"),
    257269                        VisResponseMessage,
    258270                        "VisResponseBody"),
    259                 'Info': make_soap_handler(\
     271                'Info': soap_handler(\
    260272                        InfoRequestMessage.typecode,
    261273                        getattr(self, "get_info"),
    262274                        InfoResponseMessage,
    263275                        "InfoResponseBody"),
    264                 'Terminate': make_soap_handler(\
     276                'Terminate': soap_handler(\
    265277                        TerminateRequestMessage.typecode,
    266278                        getattr(self, "terminate_experiment"),
     
    270282
    271283        self.xmlrpc_services = {\
    272                 'Create': make_xmlrpc_handler(\
     284                'Create': xmlrpc_handler(\
    273285                        getattr(self, "create_experiment"),
    274286                        "CreateResponseBody"),
    275                 'Vtopo': make_xmlrpc_handler(\
     287                'Vtopo': xmlrpc_handler(\
    276288                        getattr(self, "get_vtopo"),
    277289                        "VtopoResponseBody"),
    278                 'Vis': make_xmlrpc_handler(\
     290                'Vis': xmlrpc_handler(\
    279291                        getattr(self, "get_vis"),
    280292                        "VisResponseBody"),
    281                 'Info': make_xmlrpc_handler(\
     293                'Info': xmlrpc_handler(\
    282294                        getattr(self, "get_info"),
    283295                        "InfoResponseBody"),
    284                 'Terminate': make_xmlrpc_handler(\
     296                'Terminate': xmlrpc_handler(\
    285297                        getattr(self, "terminate_experiment"),
    286298                        "TerminateResponseBody"),
     
    816828            req['resources']['node'] = rnodes
    817829
    818         # No retry loop here.  Proxy servers must correctly authenticate
    819         # themselves without help
    820 
    821         try:
    822             ctx = fedd_ssl_context(self.cert_file,
    823                     self.trusted_certs, password=self.cert_pwd)
    824         except SSL.SSLError:
    825             raise service_error(service_error.server_config,
    826                     "Server certificates misconfigured")
    827 
    828         loc = feddServiceLocator();
    829         port = loc.getfeddPortType(uri,
    830                 transport=M2Crypto.httpslib.HTTPSConnection,
    831                 transdict={ 'ssl_context' : ctx })
    832 
    833         # Reconstruct the full request message
    834         msg = RequestAccessRequestMessage()
    835         msg.set_element_RequestAccessRequestBody(
    836                 pack_soap(msg, "RequestAccessRequestBody", req))
    837 
    838         try:
    839             resp = port.RequestAccess(msg)
    840         except ZSI.ParseException, e:
    841             raise service_error(service_error.req,
    842                     "Bad format message (XMLRPC??): %s" % str(e))
    843         except ZSI.FaultException, e:
    844             resp = e.fault.detail[0]
    845 
    846         # Again, weird incompatibilities rear their head.  userRoles, which are
    847         # restricted strings, seem to be encoded by ZSI as non-unicode strings
    848         # in a way that confuses the pickling and XMLRPC sending systems.
    849         # Explicitly unicoding them seems to fix this, though it concerns me
    850         # some.  It may be that these things are actually a ZSI string
    851         # subclass, and the character encoding is not the major issue.  In any
    852         # case, making all the subclasses of basestring into unicode strings
    853         # unifies the response format and solves the problem.
    854         r = make_unicode(fedids_to_obj(unpack_soap(resp)))
     830        r = self.call_RequestAccess(uri, req,
     831                self.cert_file, self.cert_pwd, self.trusted_certs)
    855832
    856833        if r.has_key('RequestAccessResponseBody'):
    857834            r = r['RequestAccessResponseBody']
    858835        else:
    859             raise service_error(service_error.proxy,
     836            raise service_error(service_error.protocol,
    860837                    "Bad proxy response")
    861838
     
    894871                    "Unknown testbed: %s" % tb)
    895872
    896         # The basic request
    897         req = { 'allocID' : aid }
    898 
    899         # No retry loop here.  Proxy servers must correctly authenticate
    900         # themselves without help
    901         try:
    902             ctx = fedd_ssl_context(self.cert_file,
    903                     self.trusted_certs, password=self.cert_pwd)
    904         except SSL.SSLError:
    905             raise service_error(service_error.server_config,
    906                     "Server certificates misconfigured")
    907 
    908         loc = feddServiceLocator();
    909         port = loc.getfeddPortType(uri,
    910                 transport=M2Crypto.httpslib.HTTPSConnection,
    911                 transdict={ 'ssl_context' : ctx })
    912 
    913         # Reconstruct the full request message
    914         msg = ReleaseAccessRequestMessage()
    915         msg.set_element_ReleaseAccessRequestBody(
    916                 pack_soap(msg, "ReleaseAccessRequestBody", req))
    917 
    918         try:
    919             resp = port.ReleaseAccess(msg)
    920         except ZSI.ParseException, e:
    921             raise service_error(service_error.req,
    922                     "Bad format message (XMLRPC??): %s" % str(e))
    923         except ZSI.FaultException, e:
    924             resp = e.fault.detail[0]
     873        resp = self.call_ReleaseAccess(uri, {'allocID': aid},
     874                self.cert_file, self.cert_pwd, self.trusted_certs)
    925875
    926876        # better error coding
     
    934884            }
    935885
    936         # No retry loop here.  Proxy servers must correctly authenticate
    937         # themselves without help
    938         try:
    939             ctx = fedd_ssl_context(self.cert_file,
    940                     self.trusted_certs, password=self.cert_pwd)
    941         except SSL.SSLError:
    942             raise service_error(service_error.server_config,
    943                     "Server certificates misconfigured")
    944 
    945         loc = feddInternalServiceLocator();
    946         port = loc.getfeddInternalPortType(uri,
    947                 transport=M2Crypto.httpslib.HTTPSConnection,
    948                 transdict={ 'ssl_context' : ctx })
    949 
    950         # Reconstruct the full request message
    951         msg = Ns2SplitRequestMessage()
    952         msg.set_element_Ns2SplitRequestBody(
    953                 pack_soap(msg, "Ns2SplitRequestBody", req))
    954 
    955         try:
    956             resp = port.Ns2Split(msg)
    957         except ZSI.ParseException, e:
    958             raise service_error(service_error.req,
    959                     "Bad format message (XMLRPC??): %s" %
    960                     str(e))
    961         r = unpack_soap(resp)
     886        r = self.call_Ns2Split(uri, req, self.cert_file, self.cert_pwd,
     887                self.trusted_certs)
     888
    962889        if r.has_key('Ns2SplitResponseBody'):
    963890            r = r['Ns2SplitResponseBody']
     
    965892                return r['output'].splitlines()
    966893            else:
    967                 raise service_error(service_error.proxy,
     894                raise service_error(service_error.protocol,
    968895                        "Bad splitter response (no output)")
    969896        else:
    970             raise service_error(service_error.proxy, "Bad splitter response")
     897            raise service_error(service_error.protocol, "Bad splitter response")
    971898       
    972899    class current_testbed:
Note: See TracChangeset for help on using the changeset viewer.