App Engine Python SDK version 1.8.9
[gae.git] / python / google / appengine / ext / mapreduce / main.py
blob118b4d13c327b2dd700aa923e73c24871fa9d92c
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
33 """Main module for map-reduce implementation.
35 This module should be specified as a handler for mapreduce URLs in app.yaml:
37 handlers:
38 - url: /mapreduce(/.*)?
39 login: admin
40 script: mapreduce/main.py
41 """
45 import google
48 try:
49 from appengine_pipeline.src import pipeline
50 except ImportError:
51 pipeline = None
54 from google.appengine.ext import webapp
55 from google.appengine.ext.mapreduce import handlers
56 from google.appengine.ext.mapreduce import status
57 from google.appengine.ext.webapp import util
60 STATIC_RE = r".*/([^/]*\.(?:css|js)|status|detail)$"
63 class RedirectHandler(webapp.RequestHandler):
64 """Redirects the user back to the status page."""
66 def get(self):
67 new_path = self.request.path
68 if not new_path.endswith("/"):
69 new_path += "/"
70 new_path += "status"
71 self.redirect(new_path)
74 def create_handlers_map():
75 """Create new handlers map.
77 Returns:
78 list of (regexp, handler) pairs for WSGIApplication constructor.
79 """
80 pipeline_handlers_map = []
82 if pipeline:
83 pipeline_handlers_map = pipeline.create_handlers_map(prefix=".*/pipeline")
85 return pipeline_handlers_map + [
89 (r".*/worker_callback/.*", handlers.MapperWorkerCallbackHandler),
90 (r".*/controller_callback/.*", handlers.ControllerCallbackHandler),
91 (r".*/kickoffjob_callback/.*", handlers.KickOffJobHandler),
92 (r".*/finalizejob_callback/.*", handlers.FinalizeJobHandler),
96 (r".*/command/start_job", handlers.StartJobHandler),
97 (r".*/command/cleanup_job", handlers.CleanUpJobHandler),
98 (r".*/command/abort_job", handlers.AbortJobHandler),
99 (r".*/command/list_configs", status.ListConfigsHandler),
100 (r".*/command/list_jobs", status.ListJobsHandler),
101 (r".*/command/get_job_detail", status.GetJobDetailHandler),
104 (STATIC_RE, status.ResourceHandler),
107 (r".*", RedirectHandler),
110 def create_application():
111 """Create new WSGIApplication and register all handlers.
113 Returns:
114 an instance of webapp.WSGIApplication with all mapreduce handlers
115 registered.
117 return webapp.WSGIApplication(create_handlers_map(),
118 debug=True)
121 APP = create_application()
124 def main():
125 util.run_wsgi_app(APP)
128 if __name__ == "__main__":
129 main()