| OLD | NEW |
| 1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Main entry point for Swarming service. | 5 """Main entry point for Swarming service. |
| 6 | 6 |
| 7 This file contains the URL handlers for all the Swarming service URLs, | 7 This file contains the URL handlers for all the Swarming service URLs, |
| 8 implemented using the webapp2 framework. | 8 implemented using the webapp2 framework. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 url='/internal/taskqueue/mapreduce/launch/%s' % job_id, | 131 url='/internal/taskqueue/mapreduce/launch/%s' % job_id, |
| 132 queue_name=mapreduce_jobs.MAPREDUCE_TASK_QUEUE, | 132 queue_name=mapreduce_jobs.MAPREDUCE_TASK_QUEUE, |
| 133 use_dedicated_module=False) | 133 use_dedicated_module=False) |
| 134 # New tasks should show up on the status page. | 134 # New tasks should show up on the status page. |
| 135 if success: | 135 if success: |
| 136 self.redirect('/restricted/mapreduce/status') | 136 self.redirect('/restricted/mapreduce/status') |
| 137 else: | 137 else: |
| 138 self.abort(500, 'Failed to launch the job') | 138 self.abort(500, 'Failed to launch the job') |
| 139 | 139 |
| 140 | 140 |
| 141 ### Public pages. | 141 ### Redirectors. |
| 142 | |
| 143 | |
| 144 class OldUIHandler(auth.AuthenticatingHandler): | |
| 145 @auth.public | |
| 146 def get(self): | |
| 147 params = { | |
| 148 'host_url': self.request.host_url, | |
| 149 'is_admin': acl.is_admin(), | |
| 150 'is_privileged_user': acl.is_privileged_user(), | |
| 151 'is_user': acl.is_user(), | |
| 152 'is_bootstrapper': acl.is_bootstrapper(), | |
| 153 'bootstrap_token': '...', | |
| 154 'mapreduce_jobs': [], | |
| 155 'user_type': acl.get_user_type(), | |
| 156 'xsrf_token': '', | |
| 157 } | |
| 158 if acl.is_admin(): | |
| 159 params['mapreduce_jobs'] = [ | |
| 160 {'id': job_id, 'name': job_def['job_name']} | |
| 161 for job_id, job_def in mapreduce_jobs.MAPREDUCE_JOBS.iteritems() | |
| 162 ] | |
| 163 params['xsrf_token'] = self.generate_xsrf_token() | |
| 164 if acl.is_bootstrapper(): | |
| 165 params['bootstrap_token'] = bot_code.generate_bootstrap_token() | |
| 166 self.response.write(template.render('swarming/root.html', params)) | |
| 167 | 142 |
| 168 | 143 |
| 169 class BotsListHandler(auth.AuthenticatingHandler): | 144 class BotsListHandler(auth.AuthenticatingHandler): |
| 170 """Redirects to a list of known bots.""" | 145 """Redirects to a list of known bots.""" |
| 171 | 146 |
| 172 @auth.public | 147 @auth.public |
| 173 def get(self): | 148 def get(self): |
| 174 limit = int(self.request.get('limit', 100)) | 149 limit = int(self.request.get('limit', 100)) |
| 175 | 150 |
| 176 dimensions = ( | 151 dimensions = ( |
| 177 l.strip() for l in self.request.get('dimensions', '').splitlines() | 152 l.strip() for l in self.request.get('dimensions', '').splitlines() |
| 178 ) | 153 ) |
| 179 dimensions = [i for i in dimensions if i] | 154 dimensions = [i for i in dimensions if i] |
| 180 | 155 |
| 181 new_ui_link = '/botlist?l=%d' % limit | 156 new_ui_link = '/botlist?l=%d' % limit |
| 182 if dimensions: | 157 if dimensions: |
| 183 new_ui_link += '&f=' + '&f='.join(dimensions) | 158 new_ui_link += '&f=' + '&f='.join(dimensions) |
| 184 | 159 |
| 185 self.redirect(new_ui_link) | 160 self.redirect(new_ui_link) |
| 186 | 161 |
| 187 | 162 |
| 188 class BotHandler(auth.AuthenticatingHandler): | 163 class BotHandler(auth.AuthenticatingHandler): |
| 189 """Redirects to a page about the bot, including last tasks and events.""" | 164 """Redirects to a page about the bot, including last tasks and events.""" |
| 190 | 165 |
| 191 @auth.public | 166 @auth.public |
| 192 def get(self, bot_id): | 167 def get(self, bot_id): |
| 193 self.redirect('/bot?id=%s' % bot_id) | 168 self.redirect('/bot?id=%s' % bot_id) |
| 194 | 169 |
| 195 | 170 |
| 196 ### User accessible pages. | |
| 197 | |
| 198 | |
| 199 class TasksHandler(auth.AuthenticatingHandler): | 171 class TasksHandler(auth.AuthenticatingHandler): |
| 200 """Redirects to a list of all task requests.""" | 172 """Redirects to a list of all task requests.""" |
| 201 | 173 |
| 202 @auth.public | 174 @auth.public |
| 203 def get(self): | 175 def get(self): |
| 204 limit = int(self.request.get('limit', 100)) | 176 limit = int(self.request.get('limit', 100)) |
| 205 task_tags = [ | 177 task_tags = [ |
| 206 line for line in self.request.get('task_tag', '').splitlines() if line | 178 line for line in self.request.get('task_tag', '').splitlines() if line |
| 207 ] | 179 ] |
| 208 | 180 |
| 209 new_ui_link = '/tasklist?l=%d' % limit | 181 new_ui_link = '/tasklist?l=%d' % limit |
| 210 if task_tags: | 182 if task_tags: |
| 211 new_ui_link += '&f=' + '&f='.join(task_tags) | 183 new_ui_link += '&f=' + '&f='.join(task_tags) |
| 212 | 184 |
| 213 self.redirect(new_ui_link) | 185 self.redirect(new_ui_link) |
| 214 | 186 |
| 215 | 187 |
| 216 class TaskHandler(auth.AuthenticatingHandler): | 188 class TaskHandler(auth.AuthenticatingHandler): |
| 217 """Redirects to a page containing task request and result.""" | 189 """Redirects to a page containing task request and result.""" |
| 218 | 190 |
| 219 @auth.public | 191 @auth.public |
| 220 def get(self, task_id): | 192 def get(self, task_id): |
| 221 self.redirect('/task?id=%s' % task_id) | 193 self.redirect('/task?id=%s' % task_id) |
| 222 | 194 |
| 223 | 195 |
| 196 ### Public pages. |
| 197 |
| 198 |
| 224 class UIHandler(auth.AuthenticatingHandler): | 199 class UIHandler(auth.AuthenticatingHandler): |
| 225 """Serves the landing page for the new UI of the requested page. | 200 """Serves the landing page for the new UI of the requested page. |
| 226 | 201 |
| 227 This landing page is stamped with the OAuth 2.0 client id from the | 202 This landing page is stamped with the OAuth 2.0 client id from the |
| 228 configuration.""" | 203 configuration.""" |
| 229 @auth.public | 204 @auth.public |
| 230 def get(self, page): | 205 def get(self, page): |
| 231 if not page: | 206 if not page: |
| 232 page = 'swarming' | 207 page = 'swarming' |
| 233 | 208 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 class EmailHandler(webapp2.RequestHandler): | 249 class EmailHandler(webapp2.RequestHandler): |
| 275 """Blackhole any email sent.""" | 250 """Blackhole any email sent.""" |
| 276 def post(self, to): | 251 def post(self, to): |
| 277 pass | 252 pass |
| 278 | 253 |
| 279 | 254 |
| 280 def get_routes(): | 255 def get_routes(): |
| 281 routes = [ | 256 routes = [ |
| 282 # Frontend pages. They return HTML. | 257 # Frontend pages. They return HTML. |
| 283 # Public pages. | 258 # Public pages. |
| 284 ('/oldui', OldUIHandler), | |
| 285 ('/<page:(bot|botlist|task|tasklist|)>', UIHandler), | 259 ('/<page:(bot|botlist|task|tasklist|)>', UIHandler), |
| 286 | 260 |
| 287 # Task pages. Redirects to Polymer UI | 261 # Redirects to Polymer UI |
| 288 ('/user/tasks', TasksHandler), | 262 ('/user/tasks', TasksHandler), |
| 289 ('/user/task/<task_id:[0-9a-fA-F]+>', TaskHandler), | 263 ('/user/task/<task_id:[0-9a-fA-F]+>', TaskHandler), |
| 290 | |
| 291 # Bot pages. Redirects to Polymer UI | |
| 292 ('/restricted/bots', BotsListHandler), | 264 ('/restricted/bots', BotsListHandler), |
| 293 ('/restricted/bot/<bot_id:[^/]+>', BotHandler), | 265 ('/restricted/bot/<bot_id:[^/]+>', BotHandler), |
| 294 | 266 |
| 295 # Admin pages. | 267 # Admin pages. |
| 268 # TODO(maruel): Get rid of them. |
| 296 ('/restricted/config', RestrictedConfigHandler), | 269 ('/restricted/config', RestrictedConfigHandler), |
| 297 ('/restricted/upload/bot_config', UploadBotConfigHandler), | 270 ('/restricted/upload/bot_config', UploadBotConfigHandler), |
| 298 ('/restricted/upload/bootstrap', UploadBootstrapHandler), | 271 ('/restricted/upload/bootstrap', UploadBootstrapHandler), |
| 299 | 272 |
| 300 # Mapreduce related urls. | 273 # Mapreduce related urls. |
| 301 (r'/restricted/launch_mapreduce', RestrictedLaunchMapReduceJob), | 274 (r'/restricted/launch_mapreduce', RestrictedLaunchMapReduceJob), |
| 302 | 275 |
| 303 ('/_ah/mail/<to:.+>', EmailHandler), | 276 ('/_ah/mail/<to:.+>', EmailHandler), |
| 304 ('/_ah/warmup', WarmupHandler), | 277 ('/_ah/warmup', WarmupHandler), |
| 305 ] | 278 ] |
| 306 return [webapp2.Route(*i) for i in routes] | 279 return [webapp2.Route(*i) for i in routes] |
| 307 | 280 |
| 308 | 281 |
| 309 def create_application(debug): | 282 def create_application(debug): |
| 310 routes = [] | 283 routes = [] |
| 311 routes.extend(get_routes()) | 284 routes.extend(get_routes()) |
| 312 routes.extend(handlers_bot.get_routes()) | 285 routes.extend(handlers_bot.get_routes()) |
| 313 routes.extend(handlers_endpoints.get_routes()) | 286 routes.extend(handlers_endpoints.get_routes()) |
| 314 return webapp2.WSGIApplication(routes, debug=debug) | 287 return webapp2.WSGIApplication(routes, debug=debug) |
| OLD | NEW |