0

I'm using PyWPS 3.2.4 that I containerized into Docker Containers to run into Mesos Marathon.

The external IP's and ports of my WPS Servers are therefore dynamic for being assigned by the Marathon framework.

I am able to send a GetCapabilities or Execute requests to these distributed WPS Servers in the Cluster since I know the 'public' IPs and ports. However the XML documents sent back to the client by the PyWPS servers contain 'polling' and 'results' IPs refering to the values set in 'pywps.cfg' (and not the IP and port used by the client to communicate with the server).

For example:

[wps]

...
serveraddress=http://172.16.10.40
...

[server]
...
outputUrl=http://172.16.10.40/wps/wpsoutputs/
...

Thus, the problem arise once it gets to poll for the end of the execution. How can I configure PyWPS to force it to provides polling and results URLs on the same public URLs that the client request?

1

I finally solved my problem adding a new function in wsgiwps.py:

def dynUpdateConfigurationURLs(new_url):
    '''
    Update dynamically PyWPS configuration to match public IP:port of this server into the cluster.

    PyWPS servers are meant to be deployed into a dynamic Mesos Cluster. Their IP:port are therefore auto-assigned by Marathon,
    and are not deterministic.
    The values of 'serveraddress' and 'outputURL' in wpsserver.conf can't be forecasted in advance.

    This function is meant to be called the client emit a request.
    The base URL requested by the client is retrieved and reinjected in PyWPS configuration, so that the client can poll and get the result seamlessly.
    '''
    confFile = os.environ.get('PYWPS_CFG', '/var/www/wps/pywps.cfg')
    configpar = ConfigParser.ConfigParser()
    configpar.read('/var/www/wps/pywps.cfg')
    # Old values
    oldServerAddress = configpar.get('wps', 'serveraddress')
    oldOutputURL = configpar.get('server', 'outputUrl')

    # New values
    new_url = re.sub('^https?://', '', new_url)  # Remove http[s] if present
    newServerAddress = 'http://' + new_url
    newOutputURL = newServerAddress + '/wps/wpsoutputs/'

    # Update the config is URLs are not the same as the one used for this HTTP requet.
    if (oldServerAddress != newServerAddress) or (oldOutputURL != newOutputURL):
        configpar.set('wps', 'serveraddress', newServerAddress)
        configpar.set('server', 'outputUrl', newOutputURL)

        with open(confFile, 'wb') as configfilePtr:
            configpar.write(configfilePtr)

        print('--------------------------------------------------------------------------------------------------------------------------')
        print('Dynamically update PyWPS config \'serveraddress\' to \'%s\' and \'outputUrl\' to \'%s\'' % (newServerAddress, newOutputURL))

def application(environ, start_response):
    dynUpdateConfigurationURLs(environ['HTTP_HOST'])   # Ex: 'HTTP_HOST': '172.16.10.21',   

    ......

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.