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

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

various fixes, got ui renderer working instead of html pages. fixes zoom
and center of the bounding box on submit page.

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