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

Side by Side Diff: dashboard/dashboard/pinpoint/handlers/new.py

Issue 2996473002: [pinpoint] Add QuestGenerator object. (Closed)
Patch Set: Created 3 years, 4 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
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 json 5 import json
6 import webapp2 6 import webapp2
7 7
8 from dashboard.api import api_auth 8 from dashboard.api import api_auth
9 from dashboard.pinpoint.models import change 9 from dashboard.pinpoint.models import change
10 from dashboard.pinpoint.models import job as job_module 10 from dashboard.pinpoint.models import job as job_module
11 11 from dashboard.pinpoint.models import test_config as test_config_module
12 _ERROR_METRIC_NO_TEST_SUITE = "Specified a metric but there's no test_suite "\
13 "to run."
14 _ERROR_BUG_ID = 'Bug ID must be integer value.'
15 12
16 13
17 class ParameterValidationError(Exception): 14 _ERROR_BUG_ID = 'Bug ID must be an integer.'
18 pass
19 15
20 16
21 class New(webapp2.RequestHandler): 17 class New(webapp2.RequestHandler):
22 """Handler that cooks up a fresh Pinpoint job.""" 18 """Handler that cooks up a fresh Pinpoint job."""
23 19
24 def post(self): 20 def post(self):
25 try: 21 try:
26 self._CreateJob() 22 self._CreateJob()
27 except (api_auth.ApiAuthException, ParameterValidationError) as e: 23 except (api_auth.ApiAuthException, KeyError, TypeError, ValueError) as e:
28 self._WriteErrorMessage(e.message) 24 self._WriteErrorMessage(e.message)
29 25
30 def _WriteErrorMessage(self, message): 26 def _WriteErrorMessage(self, message):
31 self.response.out.write(json.dumps({'error': message})) 27 self.response.out.write(json.dumps({'error': message}))
32 28
33 @api_auth.Authorize 29 @api_auth.Authorize
34 def _CreateJob(self): 30 def _CreateJob(self):
35 """Start a new Pinpoint job.""" 31 """Start a new Pinpoint job."""
36 configuration = self.request.get('configuration') 32 configuration = self.request.get('configuration')
37 test_suite = self.request.get('test_suite') 33 target = self.request.get('target')
38 test = self.request.get('test') 34 test_config = self.request.get('test_config')
perezju 2017/08/07 12:06:12 Seems like this is not needed? (Value is thrown aw
dtu 2017/08/15 17:06:40 Done. Previously I was going to put all the test c
39 metric = self.request.get('metric')
40 auto_explore = self.request.get('auto_explore') == '1' 35 auto_explore = self.request.get('auto_explore') == '1'
41 bug_id = self._ValidateBugId(self.request.get('bug_id')) 36 bug_id = self.request.get('bug_id')
42 37
43 change_1 = { 38 change_1 = {
44 'base_commit': { 39 'base_commit': {
45 'repository': self.request.get('start_repository'), 40 'repository': self.request.get('start_repository'),
46 'git_hash': self.request.get('start_git_hash') 41 'git_hash': self.request.get('start_git_hash')
47 } 42 }
48 } 43 }
49 44
50 change_2 = { 45 change_2 = {
51 'base_commit': { 46 'base_commit': {
52 'repository': self.request.get('end_repository'), 47 'repository': self.request.get('end_repository'),
53 'git_hash': self.request.get('end_git_hash') 48 'git_hash': self.request.get('end_git_hash')
54 } 49 }
55 } 50 }
56 51
57 # Validate parameters. 52 # Validate parameters and convert them to canonical internal representation.
58 self._ValidateMetric(test_suite, metric) 53 test_config = test_config_module.TestConfig(target, self.request)
59 54 bug_id = self._ValidateBugId(bug_id)
60 # Convert parameters to canonical internal representation.
61 changes = self._ValidateChanges(change_1, change_2) 55 changes = self._ValidateChanges(change_1, change_2)
62 56
63 # Create job. 57 # Create job.
64 job = job_module.Job.New( 58 job = job_module.Job.New(
65 configuration=configuration, 59 configuration=configuration,
66 test_suite=test_suite, 60 target=target,
67 test=test, 61 test_config=test_config,
68 metric=metric,
69 auto_explore=auto_explore, 62 auto_explore=auto_explore,
70 bug_id=bug_id) 63 bug_id=bug_id)
71 64
72 # Add changes. 65 # Add changes.
73 for c in changes: 66 for c in changes:
74 job.AddChange(c) 67 job.AddChange(c)
75 68
76 # Put job into datastore. 69 # Put job into datastore.
77 job_id = job.put().urlsafe() 70 job_id = job.put().urlsafe()
78 71
79 # Start job. 72 # Start job.
80 job.Start() 73 job.Start()
81 job.put() 74 job.put()
82 75
76 # TODO: Figure out if these should be underscores or lowerCamelCase.
77 # TODO: They should match the input parameters.
83 self.response.out.write(json.dumps({ 78 self.response.out.write(json.dumps({
84 'jobId': job_id, 79 'jobId': job_id,
85 'jobUrl': job.url 80 'jobUrl': job.url
86 })) 81 }))
87 82
88 def _ValidateBugId(self, bug_id): 83 def _ValidateBugId(self, bug_id):
89 if not bug_id: 84 if not bug_id:
90 return None 85 return None
91 86
92 try: 87 try:
93 return int(bug_id) 88 return int(bug_id)
94 except ValueError: 89 except ValueError:
95 raise ParameterValidationError(_ERROR_BUG_ID) 90 raise ValueError(_ERROR_BUG_ID)
96 91
97 def _ValidateChanges(self, change_1, change_2): 92 def _ValidateChanges(self, change_1, change_2):
98 try: 93 return (change.Change.FromDict(change_1), change.Change.FromDict(change_2))
99 changes = (change.Change.FromDict(change_1),
100 change.Change.FromDict(change_2))
101 except (KeyError, ValueError) as e:
102 raise ParameterValidationError(str(e))
103
104 return changes
105
106 def _ValidateMetric(self, test_suite, metric):
107 if metric and not test_suite:
108 raise ParameterValidationError(_ERROR_METRIC_NO_TEST_SUITE)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698