Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: tools/android/loading/cloud/frontend/clovis_frontend.py

Issue 2027843004: tools/android/loading Prevent gcloud instance leak. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reportName
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging 5 import logging
6 import os 6 import os
7 import sys 7 import sys
8 import time 8 import time
9 9
10 import cloudstorage 10 import cloudstorage
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 user_email = email_helper.GetUserEmail() 261 user_email = email_helper.GetUserEmail()
262 user_name = user_email[:user_email.find('@')] 262 user_name = user_email[:user_email.find('@')]
263 if user_name: 263 if user_name:
264 task_dir_components.append(user_name) 264 task_dir_components.append(user_name)
265 task_name = task.BackendParams().get('task_name') 265 task_name = task.BackendParams().get('task_name')
266 if task_name: 266 if task_name:
267 task_dir_components.append(task_name) 267 task_dir_components.append(task_name)
268 task_dir_components.append(task_tag) 268 task_dir_components.append(task_tag)
269 task_dir = os.path.join(task.Action(), '_'.join(task_dir_components)) 269 task_dir = os.path.join(task.Action(), '_'.join(task_dir_components))
270 270
271 # Create the instance template if required.
272 if not CreateInstanceTemplate(task, task_dir):
273 return Render('Template creation failed.', memory_logs)
274
275 # Build the URL where the result will live. 271 # Build the URL where the result will live.
276 task_url = None 272 task_url = None
277 if task.Action() == 'trace': 273 if task.Action() == 'trace':
278 bucket = task.BackendParams().get('storage_bucket') 274 bucket = task.BackendParams().get('storage_bucket')
279 if bucket: 275 if bucket:
280 task_url = 'https://console.cloud.google.com/storage/%s/%s' % (bucket, 276 task_url = 'https://console.cloud.google.com/storage/%s/%s' % (bucket,
281 task_dir) 277 task_dir)
282 elif task.Action() == 'report': 278 elif task.Action() == 'report':
283 task_url = common.clovis_paths.GetBigQueryTableURL(project_name, task_tag) 279 task_url = common.clovis_paths.GetBigQueryTableURL(project_name, task_tag)
284 else: 280 else:
285 error_string = 'Unsupported action: %s.' % task.Action() 281 error_string = 'Unsupported action: %s.' % task.Action()
286 clovis_logger.error(error_string) 282 clovis_logger.error(error_string)
287 return Render(error_string, memory_logs) 283 return Render(error_string, memory_logs)
288 clovis_logger.info('Task result URL: ' + task_url) 284 clovis_logger.info('Task result URL: ' + task_url)
289 285
290 # Split the task in smaller tasks. 286 # Split the task in smaller tasks.
291 sub_tasks = SplitClovisTask(task) 287 sub_tasks = SplitClovisTask(task)
292 if not sub_tasks: 288 if not sub_tasks:
293 return Render('Task split failed.', memory_logs) 289 return Render('Task split failed.', memory_logs)
294 290
295 if not EnqueueTasks(sub_tasks, task_tag): 291 if not EnqueueTasks(sub_tasks, task_tag):
296 return Render('Task creation failed.', memory_logs) 292 return Render('Task creation failed.', memory_logs)
297 293
298 # Start the instances if required.
299 if not CreateInstances(task):
300 return Render('Instance creation failed.', memory_logs)
301
302 # Start polling the progress. 294 # Start polling the progress.
303 clovis_logger.info('Creating worker polling task.') 295 clovis_logger.info('Creating worker polling task.')
304 first_poll_delay_minutes = 10 296 first_poll_delay_minutes = 10
305 timeout_hours = task.BackendParams().get('timeout_hours', 5) 297 timeout_hours = task.BackendParams().get('timeout_hours', 5)
306 deferred.defer(PollWorkers, task_tag, time.time(), timeout_hours, user_email, 298 deferred.defer(PollWorkers, task_tag, time.time(), timeout_hours, user_email,
307 task_url, _countdown=(60 * first_poll_delay_minutes)) 299 task_url, _countdown=(60 * first_poll_delay_minutes))
308 300
301 # Start the instances if required.
302 if not CreateInstanceTemplate(task, task_dir):
303 return Render('Instance template creation failed.', memory_logs)
304 if not CreateInstances(task):
305 return Render('Instance creation failed.', memory_logs)
306
309 return Render(flask.Markup( 307 return Render(flask.Markup(
310 'Success!<br>Your task %s has started.<br>' 308 'Success!<br>Your task %s has started.<br>'
311 'You will be notified at %s when completed.') % (task_tag, user_email), 309 'You will be notified at %s when completed.') % (task_tag, user_email),
312 memory_logs) 310 memory_logs)
313 311
314 312
315 def EnqueueTasks(tasks, task_tag): 313 def EnqueueTasks(tasks, task_tag):
316 """Enqueues a list of tasks in the Google Cloud task queue, for consumption by 314 """Enqueues a list of tasks in the Google Cloud task queue, for consumption by
317 Google Compute Engine. 315 Google Compute Engine.
318 """ 316 """
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 @app.errorhandler(404) 358 @app.errorhandler(404)
361 def PageNotFound(e): # pylint: disable=unused-argument 359 def PageNotFound(e): # pylint: disable=unused-argument
362 """Return a custom 404 error.""" 360 """Return a custom 404 error."""
363 return 'Sorry, Nothing at this URL.', 404 361 return 'Sorry, Nothing at this URL.', 404
364 362
365 363
366 @app.errorhandler(500) 364 @app.errorhandler(500)
367 def ApplicationError(e): 365 def ApplicationError(e):
368 """Return a custom 500 error.""" 366 """Return a custom 500 error."""
369 return 'Sorry, unexpected error: {}'.format(e), 499 367 return 'Sorry, unexpected error: {}'.format(e), 499
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698