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

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

lots of minor fixes. including removing username from process configs.

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 import utils
17from cows_wps.renderer.ui_renderer import *
18from cows_wps.model.managers import requestManager
19from cows_wps.process_handler.context.process_context import ProcessContext
20from cows_wps.renderer import xml_renderer
21
22from cows_wps.utils.parse_wps_config import wps_config_dict
23from cows_wps.utils.parse_capabilities_config import caps_config_dict
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 urllib.unquote(wps_request_url)
43            return self._submitToWPSAndRedirectToJobViewer(wps_request_url)
44
45        # Now we are only dealing with async requests
46        cost_only_request_url = wps_request_url + "&Costonly=true"
47
48        wps_resp_div = "wps_response_div"
49        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
50
51        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
52        resp += """<script type="text/javascript">
53
54        function init() {
55                makeWPSRequest('%s', '%s');
56        }
57
58</script>""" % (cost_only_request_url, wps_resp_div)
59
60        submitter_url = url_for(controller='submitter', action='conf')
61        resp += """<br><form id="confirmation" name="confirmation" action="%s" method="GET">
62<input type="hidden" name="wps_request_url" value="%s" />
63<input type="submit" name="submit" id="submit" value="Submit" disabled="disabled" />
64</form>""" % (submitter_url, urllib.unquote(wps_request_url))
65
66        renderer = UIPageRenderer()
67        resp = renderer.render("Confirmation page",
68                               [("Information about your asynchronous job", resp)])
69
70        return resp
71
72
73    def _submitToWPSAndRedirectToJobViewer(self, wps_request_url):
74        "Submits request and gets statusLocation then redirects to job viewer controller."
75        base_url = "http://" + request.url[7:].split("/")[0]
76        full_url = base_url + wps_request_url
77       # return full_url
78        """getter = urllib.urlopen(full_url)
79        xml = getter.read()
80        getter.close()
81        """
82
83        clean_request_url = urllib.unquote(wps_request_url)
84        xml = request.environ['paste.recursive.include'](clean_request_url)
85        return str(xml)
86
87
88        m = re.search('statusLocation="(.+?)"', xml)
89 #       if m: return "Matched:  " + str(m.groups())
90 #       return "BAD"
91        status_url = m.groups()[0]
92
93        jobviewer_url = url_for(controller='jobviewer', status_url = status_url)
94        return redirect_to(jobviewer_url)
95
96
97    def conf(self):
98        "Called once confirmation is complete and just calls WPS and forwards."
99        wps_request_url = str(request.params.getone("wps_request_url"))
100        return self._submitToWPSAndRedirectToJobViewer(wps_request_url)
101       
102
103    def _isAsync(self, proc_id):
104        "Returns boolean by looking up if WPS is async."
105        process_conf = caps_config_dict[proc_id]
106        process_type = process_conf["wps_interface"]["process_type"]
107
108        if process_type.find("async") == 0:
109            return True
110        else:
111            return False
112       
Note: See TracBrowser for help on using the repository browser.