source: cows_wps/trunk/cows_wps/controllers/submitter.py @ 7000

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/controllers/submitter.py@7000
Revision 7000, 4.4 KB checked in by astephen, 9 years ago (diff)

various fixes on bbox etc

Line 
1import os
2import re
3import glob
4import logging
5import urllib
6
7from pylons import request, response, session, tmpl_context as c
8from pylons.controllers.util import abort, redirect_to
9from routes import url_for
10
11
12from cows.exceptions import *
13from cows.pylons.ows_controller import render_ows_exception
14
15from cows_wps.controllers import *
16from cows_wps.renderer.ui_renderer import *
17from cows_wps.model.managers import requestManager
18from cows_wps.process_handler.context.process_context import ProcessContext
19from cows_wps.renderer import xml_renderer
20
21from cows_wps.utils.parse_wps_config import wps_config_dict
22from cows_wps.utils.parse_capabilities_config import caps_config_dict
23from cows_wps.utils.common import downloadFromURL
24
25
26from cows_wps.model.managers import requestManager
27
28log = logging.getLogger(__name__)
29
30
31class SubmitterController(BaseController):
32
33
34    def index(self):
35        wps_request_url = str(request.params.getone("wps_request_url"))
36        proc_id = str(request.params.getone("proc_id"))
37
38        async = self._isAsync(proc_id)
39       
40        # If quick process then just forward
41        if async == False:
42            return self._submitToWPSAndRedirectToJobViewer(wps_request_url)
43
44        # Now we are only dealing with async requests
45        cost_only_request_url = wps_request_url + "&Costonly=true"
46
47        wps_resp_div = "wps_response_div"
48        resp = '<div>You have requested to run a "%s" job that will be run on the offline batch processing system. These jobs are controlled by a queuing system and it may take some time for your outputs to be produced.<br><br></div>' % proc_id
49
50        resp += '<div id="%s">Estimates of the size of the expected outputs and the duration of the job are being calculated...</div>' % wps_resp_div
51        resp += """<script type="text/javascript">
52
53        function init() {
54                makeWPSRequest('%s', '%s');
55        }
56
57</script>""" % (cost_only_request_url, wps_resp_div)
58
59        submitter_url = url_for(controller='submitter', action='conf')
60        resp += """<br><form id="confirmation" name="confirmation" action="%s" method="GET">
61<input type="hidden" name="wps_request_url" value="%s" />
62<input type="submit" name="submit" id="submit" value="Submit" disabled="disabled" />
63</form>""" % (submitter_url, urllib.unquote(wps_request_url))
64
65        renderer = UIPageRenderer()
66        resp = renderer.render("Confirmation page",
67                               [("Information about your asynchronous job", resp)])
68
69        return resp
70
71
72    def _submitToWPSAndRedirectToJobViewer(self, wps_request_url):
73        "Submits request and gets statusLocation then redirects to job viewer controller."
74        base_url = "http://" + request.url[7:].split("/")[0]
75        clean_request_url = base_url + urllib.unquote(wps_request_url)
76
77        """
78        req = urllib2.Request(url = clean_request_url)
79        cookies = request.cookies
80        expiration = datetime.datetime.now() + datetime.timedelta(days=30)
81
82        # Now go through each cookie and add it to the request object before sending
83        for cookie in cookies.items():
84            nc = Cookie.SimpleCookie()
85            (k, v) = cookie
86#            log.warn("COOKIE: %s = %s" % (k, v))
87            nc[k] = v
88#            nc[k]["domain"] = "ceda-wps1.badc.rl.ac.uk"
89            nc[k]["path"] = "/"
90#            nc[k]["expires"] = expiration.strftime("%a, %d-%b-%Y %H:%M:%S PST")
91            req.add_header('Cookie', nc.output())
92
93#        getter = urllib.urlopen(clean_request_url)
94        getter = urllib2.urlopen(req)
95        xml = getter.read()
96        getter.close()
97        """
98
99        xml = downloadFromURL(clean_request_url, cookies = request.cookies)
100
101        m = re.search('statusLocation="(.+?)"', xml)
102        status_url = m.groups()[0]
103
104        jobviewer_url = url_for(controller='jobviewer', status_url = status_url)
105        return redirect_to(jobviewer_url)
106
107
108    def conf(self):
109        "Called once confirmation is complete and just calls WPS and forwards."
110        wps_request_url = str(request.params.getone("wps_request_url"))
111        return self._submitToWPSAndRedirectToJobViewer(wps_request_url)
112       
113
114    def _isAsync(self, proc_id):
115        "Returns boolean by looking up if WPS is async."
116        process_conf = caps_config_dict[proc_id]
117        process_type = process_conf["wps_interface"]["process_type"]
118
119        if process_type.find("async") == 0:
120            return True
121        else:
122            return False
123       
Note: See TracBrowser for help on using the repository browser.