Back to index

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

List of all members.

Public Member Functions

def __init__
def write
def read
def GetLocalInformation
def process

Public Attributes

 service_name
 transferdir
 notify
 ssl_config
 state
 request_config
 ns

Private Member Functions

def _filename
def _call_request

Detailed Description

Definition at line 114 of file byteio.py.


Constructor & Destructor Documentation

Definition at line 116 of file byteio.py.

00116 
00117     def __init__(self, cfg):
00118         self.service_name = 'ByteIO'
00119         # names of provided methods
00120         request_names = ['read', 'write']
00121         # call the Service's constructor
00122         Service.__init__(self, [{'request_names' : request_names, 'namespace_prefix': 'rb', 'namespace_uri': rbyteio_uri}], cfg)
00123         self.transferdir = str(cfg.Get('TransferDir'))
00124         log.msg(arc.VERBOSE, "ByteIOService transfer dir:", self.transferdir)
00125         ssl_config = parse_ssl_config(cfg)
00126         self.notify = NotifyClient(str(cfg.Get('NotifyURL')), ssl_config = ssl_config)


Member Function Documentation

def storage.shepherd.byteio.ByteIOService._call_request (   self,
  request_name,
  inmsg 
) [private]

Reimplemented from arcom.service.Service.

Definition at line 171 of file byteio.py.

00171 
00172     def _call_request(self, request_name, inmsg):
00173         # gets the last part of the request url
00174         # TODO: somehow detect if this is just the path of the service which means: no subject
00175         subject = inmsg.Attributes().get('ENDPOINT').split('/')[-1]
00176         # the subject of the byteio request: reference to the file
00177         log.msg(arc.VERBOSE, 'Subject:', subject)
00178         inpayload = inmsg.Payload()
00179         return getattr(self,request_name)(inpayload, subject)
00180 

Here is the call graph for this function:

def storage.shepherd.byteio.ByteIOService._filename (   self,
  subject 
) [private]

Definition at line 127 of file byteio.py.

00127 
00128     def _filename(self, subject):
00129         return os.path.join(self.transferdir, subject)

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:

def storage.shepherd.byteio.ByteIOService.read (   self,
  inpayload,
  subject 
)

Definition at line 155 of file byteio.py.

00155 
00156     def read(self, inpayload, subject):
00157         try:
00158             data = file(self._filename(subject),'rb').read()
00159         except:
00160             log.msg()
00161             data = ''
00162         self.notify.notify(subject, 'sent')
00163         out = self._new_soap_payload()
00164         response_node = out.NewChild('rb:readResponse')
00165         transfer_node = response_node.NewChild('rb:transfer-information')
00166         transfer_node.NewAttribute('transfer-mechanism').Set(byteio_simple_uri)
00167         encoded_data = base64.b64encode(data)
00168         transfer_node.Set(encoded_data)
00169         return out
00170 

Here is the call graph for this function:

def storage.shepherd.byteio.ByteIOService.write (   self,
  inpayload,
  subject 
)

Definition at line 130 of file byteio.py.

00130 
00131     def write(self, inpayload, subject):
00132         request_node = inpayload.Child()
00133         transfer_node = request_node.Get('transfer-information')
00134         if str(transfer_node.Attribute(0)) != byteio_simple_uri:
00135             raise Exception, 'transfer-mechanism not supported'
00136         try:
00137             fn = self._filename(subject)
00138             file(fn) # check existance
00139             f = file(fn,'wb') # open for overwriting
00140         except:
00141             log.msg()
00142             raise Exception, 'denied'
00143         encoded_data = str(transfer_node)
00144         data = base64.b64decode(encoded_data)
00145         try:
00146             f.write(data)
00147             f.close()
00148         except:
00149             log.msg()
00150             raise Exception, 'write failed'
00151         self.notify.notify(subject, 'received')
00152         out = self._new_soap_payload()
00153         response_node = out.NewChild('rb:writeResponse').Set('OK')
00154         return out

Here is the call graph for this function:


Member Data Documentation

Definition at line 125 of file byteio.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 117 of file byteio.py.

Definition at line 47 of file service.py.

Definition at line 49 of file service.py.

Definition at line 122 of file byteio.py.


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