App Engine Python SDK version 1.8.8
[gae.git] / python / google / appengine / ext / mapreduce / main.py
blob7732022eb0f352ad32851a7a1d3ecff1413f657c
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 + [
87 (r".*/worker_callback.*", handlers.MapperWorkerCallbackHandler),
88 (r".*/controller_callback.*", handlers.ControllerCallbackHandler),
89 (r".*/kickoffjob_callback.*", handlers.KickOffJobHandler),
90 (r".*/finalizejob_callback.*", handlers.FinalizeJobHandler),
94 (r".*/command/start_job", handlers.StartJobHandler),
95 (r".*/command/cleanup_job", handlers.CleanUpJobHandler),
96 (r".*/command/abort_job", handlers.AbortJobHandler),
97 (r".*/command/list_configs", status.ListConfigsHandler),
98 (r".*/command/list_jobs", status.ListJobsHandler),
99 (r".*/command/get_job_detail", status.GetJobDetailHandler),
102 (STATIC_RE, status.ResourceHandler),
105 (r".*", RedirectHandler),
108 def create_application():
109 """Create new WSGIApplication and register all handlers.
111 Returns:
112 an instance of webapp.WSGIApplication with all mapreduce handlers
113 registered.
115 return webapp.WSGIApplication(create_handlers_map(),
116 debug=True)
119 APP = create_application()
122 def main():
123 util.run_wsgi_app(APP)
126 if __name__ == "__main__":
127 main()