Changeset 2860 for TI05-delivery


Ignore:
Timestamp:
30/08/07 11:42:47 (12 years ago)
Author:
lawrence
Message:

First step to remote ndg document retrieval

Location:
TI05-delivery/ows_framework/trunk/ows_server
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/trunk/ows_server/development.ini

    r2769 r2860  
    3333configfile = %(here)s/ndgDiscovery.config 
    3434#the password file needs to be outside the egg: 
    35 passwordFile =  %(here)s/passwords.txt   
    36  
     35#passwordFile =  %(here)s/passwords.txt   
     36#but it's gone back to ndgDiscoveryq 
    3737 
    3838# If you'd like to fine-tune the individual locations of the cache data dirs 
  • TI05-delivery/ows_framework/trunk/ows_server/ndgDiscovery.config

    r2800 r2860  
    1313# 
    1414# the following is the server on which the NDG discovery service is running! (Not to be confused with 
    15 # the server on which the NDG discover web service is running) 
     15# the server on which the NDG discovery web service is running). This can and probably should be the local 
     16# server (i.e. dont change it!) 
    1617# 
    1718ndgServer:      %(server)s 
     
    2829metadataMaintainer: b.n.lawrence@rl.ac.uk 
    2930repository:       http://localhost:8080 
     31tbrecipient:      b.n.lawrence@rl.ac.uk 
    3032 
     33# The following should only be needed for debugging some parts of the code when running on sandboxes behind a firewall 
     34proxyServer:      http://wwwcache3.rl.ac.uk:8080/ 
    3135 
    3236[SEARCH] 
     
    8185neodc.nerc.ac.uk: %(server)s 
    8286badc.nerc.ac.uk: %(server)s 
    83 npm.ac.uk: wwwdev.npm.ac.uk/rsdas/projects/ndg 
    84 #grid.bodc.nerc.ac.uk: glue.badc.rl.ac.uk 
    85 grid.bodc.nerc.ac.uk: localhost:8001 
    86 ndg.noc.soton.ac.uk: ndg.noc.soton.ac.uk:8001 
     87www.npm.ac.uk: http://wwwdev.neodaas.ac.uk/projects/ndg 
     88grid.bodc.nerc.ac.uk: http://grid.bodc.nerc.ac.uk 
     89ndg.noc.soton.ac.uk: http://ndg.noc.soton.ac.uk:8001 
    8790icon: %(layout)s/B.gif 
    8891icon_alt: B Service 
     
    104107grid.bodc.nerc.ac.uk: grid.bodc.nerc.ac.uk 
    105108ndg.noc.soton.ac.uk: ndg.noc.soton.ac.uk 
    106 npm.ac.uk: pgsql.npm.ac.uk 
     109www.npm.ac.uk: pgsql.npm.ac.uk 
     110passwordFile: /home/bnl/sandboxes/ndg/TI05-delivery/ows_framework/trunk/ows_server/passwords.txt 
    107111 
    108112[NDG_SECURITY] 
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/DocumentRetrieve.py

    r2672 r2860  
    22from ndg_xqueries import * 
    33from xml.dom import minidom  
     4import urllib2 
    45#from stripped_xqueries import strip_de_xquery 
    56 
     
    114115        self.sessionRelease(id) 
    115116        return r 
     117             
     118             
     119class RestfulGet: 
     120    ''' Provides a get method to obtain an xml document from a remote NDG repository ''' 
     121    def __init__(self,remoteHost,proxyServer=None): 
     122        self.remoteHost=remoteHost 
     123        if proxyServer is None: 
     124            proxyHandler=urllib2.ProxyHandler({}) 
     125        else: 
     126            proxy=proxyServer 
     127            if proxy[0:4]!='http':proxy='http://'+proxy 
     128            proxyHandler=urllib2.ProxyHandler({'http':proxy}) 
     129        self.opener=urllib2.build_opener(proxyHandler) 
     130 
     131    def get(self,repository,schema,localID,format='NDG-B0',targetCollection=None): 
     132        #TODO what about security? Probably means we need to get the headers of our responses sorted ... 
     133        url='%s/view/%s__%s__%s?format=raw&outputSchema=%s'%(self.remoteHost,repository,schema,localID,format) 
     134        #http://docs.python.org/lib/urllib2-examples.html 
     135        request=urllib2.Request(url) 
     136        response='Error obtaining remote file: ' 
     137        try: 
     138            f = self.opener.open(request) 
     139            response='' 
     140        except urllib2.URLError,e: 
     141            if hasattr(e,'reason'): 
     142                response+='No access to server [%s]'%e.reason 
     143            elif hasattr(e,'code'): 
     144                response+='Response code [%s]'%e.code 
     145        except socket.error: 
     146            response+='Network Socket problem' 
     147        except Exception,e: 
     148            response+='[%s]'%str(e) 
     149        if response=='': 
     150            return f.read() 
     151        else: 
     152            raise IOError(response) 
     153     
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/ndgRetrieve.py

    r2852 r2860  
    55 
    66 
    7 def ndgRetrieve(uri,config,logger=0,output=''): 
     7def ndgRetrieve(uri,config,logger=0,output='',remote=0): 
    88     
    9     ''' Given an ndgObject, uri, retrieve it, with security in place ''' 
     9    ''' Given an ndgObject, uri, retrieve it, with security in place. 
     10            If logger is non-zero it should be a python log class 
     11            If output is not '' it should be desired output schema (normally 
     12        to be used for discovery documents in a variety of outputs or 
     13        to indicate that an original document is required. 
     14            If remote is non zero, then attempt to get the document 
     15        from a remote site via a (secured) restful http call''' 
    1016     
    11      
    12     def getws(config,uri,): 
     17    def getws(config,uri,remote): 
    1318        ''' Get a ws connection to the local exist database ''' 
    1419        # The logic here is that 
     
    2025        r=config.get('NDG_B_SERVICE',uri.repository) 
    2126        sr=config.get('DEFAULT','repository') 
     27        er=config.get('NDG_EXIST',uri.repository) 
    2228        if r<> sr: 
    23             return 0,'The uri [%s] is not available on [%s]'%(uri,server) 
    24         er=config.get('NDG_EXIST',uri.repository) 
    25          
    26         #Changes by Dom: 
    27         #pwf=config.get('DEFAULT','passwordFile')   
    28         #passwordFile is now in development.ini, moved from ndgDiscovery.config 
    29         pwf=cf= CONFIG['app_conf']['passwordFile'] 
    30         ws=DocumentRetrieve.DocumentRetrieve(er,pwfile=pwf) 
     29            if not remote: 
     30                return 0,'The uri [%s] is not available on [%s]'%(uri,server) 
     31            else: 
     32                ps=config.get('DEFAULT','proxyServer') 
     33                ws=DocumentRetrieve.RestfulGet(r,proxyServer=ps) 
     34        else: 
     35            pwf=config.get('NDG_EXIST','passwordFile') 
     36            ws=DocumentRetrieve.DocumentRetrieve(er,pwfile=pwf) 
    3137        return 1,ws 
    3238     
     
    3440    if uri.schema in ['DIF','MDIP']: 
    3541        r=server 
    36         ws=ndgSearch.ndgSearch() 
     42        status,ws=1,ndgSearch.ndgSearch() 
    3743    elif uri.schema[0:5]=='NDG-B' or uri.schema=='NumSim': 
    38         status,ws=getws(config,uri) 
    39         if not status: return status,ws 
     44        status,ws=getws(config,uri,remote) 
    4045    elif uri.schema=='NDG-A0': 
    41         status,ws=getws(config,uri) 
    42         if not status: return status,ws 
     46        status,ws=getws(config,uri,remote) 
     47      
     48    if not status: return status,ws 
     49            
    4350    #try: 
    4451    if uri.schema=='NDG-A0': 
     
    4855    else: 
    4956        target='/db/ndg_B_metadata' 
    50      
    51     print uri.uri, 'Output format [%s]'%output 
    5257      
    5358    if output=='': output=uri.schema  
    5459    
    55     
    56   
    5760    #do the actual retrieve: 
    5861    e=None 
     
    9093     
    9194    def setup(self): 
    92         self.c=myConfig('../config/ndgDiscovery.config') 
     95        self.c=myConfig('../../ndgDiscovery.config') 
    9396     
    9497    def testSOAP(self): 
     
    150153        if status: s=str(xml) 
    151154 
     155    def testRemoteGet(self): 
     156        ''' Attempt a remote get ''' 
     157        self.setup() 
     158        doc='www.npm.ac.uk__NDG-B1__data_entity.692' 
     159        uri=ndgObject.ndgObject(doc) 
     160        status,xml=ndgRetrieve(uri,self.c,remote=1) 
     161        if not status: print xml 
     162        self.assertEqual(status,1) 
    152163         
    153164         
Note: See TracChangeset for help on using the changeset viewer.