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:
38 - url: /mapreduce(/.*)?
40 script: mapreduce/main.py
49 from appengine_pipeline
.src
import pipeline
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."""
67 new_path
= self
.request
.path
68 if not new_path
.endswith("/"):
71 self
.redirect(new_path
)
74 def create_handlers_map():
75 """Create new handlers map.
78 list of (regexp, handler) pairs for WSGIApplication constructor.
80 pipeline_handlers_map
= []
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.
112 an instance of webapp.WSGIApplication with all mapreduce handlers
115 return webapp
.WSGIApplication(create_handlers_map(),
119 APP
= create_application()
123 util
.run_wsgi_app(APP
)
126 if __name__
== "__main__":