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

Unified Diff: dashboard/dashboard/pinpoint/handlers/new.py

Issue 2960873002: WIP - Pinpoint - New Page.
Patch Set: . Created 3 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 side-by-side diff with in-line comments
Download patch
Index: dashboard/dashboard/pinpoint/handlers/new.py
diff --git a/dashboard/dashboard/pinpoint/handlers/new.py b/dashboard/dashboard/pinpoint/handlers/new.py
index f818a24533dc45771eedc2e02a4b23d11030be91..93ef1eb74aaf9259cfbf195cd5109676ba76b013 100644
--- a/dashboard/dashboard/pinpoint/handlers/new.py
+++ b/dashboard/dashboard/pinpoint/handlers/new.py
@@ -2,51 +2,71 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
+import logging
import webapp2
+from google.appengine.api import users
+from dashboard.api import oauth
from dashboard.pinpoint.models import change
from dashboard.pinpoint.models import job as job_module
+from dashboard.services import gitiles_service
+from dashboard import oauth2_decorator
+
+
+class ParameterValidationError(Exception):
+ pass
class New(webapp2.RequestHandler):
"""Handler that cooks up a fresh Pinpoint job."""
def post(self):
+ logging.info('TRY NEW')
+ try:
+ try:
+ self._CreateJob()
+ except Exception as e:
+ logging.info("EXCEPTION: %s" % str(e))
+ except oauth.NotLoggedInError:
+ self._WriteErrorMessage('User not authenticated')
+ except oauth.OAuthError:
+ self._WriteErrorMessage('User authentication error')
+ except ParameterValidationError as e:
+ self._WriteErrorMessage(e.message)
+
+ def _WriteErrorMessage(self, message):
+ self.response.out.write(json.dumps({'error': message}))
+
+ @oauth.Authorize
+ def _CreateJob(self):
"""Start a new Pinpoint job."""
- # TODO(dtu): Read the parameters from the request object.
- # Not doing it for now because it's easier to run tests this way.
- configuration = 'Mac Pro 10.11 Perf'
- test_suite = 'speedometer'
- test = None
- metric = None
- auto_explore = True
+ configuration = self.request.get('configuration')
+ test_suite = self.request.get('test_suite')
+ test = self.request.get('test')
+ metric = self.request.get('metric')
+ auto_explore = self.request.get('auto_explore') == '1'
change_1 = {
'base_commit': {
- 'repository': 'src',
- 'git_hash': '2c1f8ed028edcb44c954cb2a0625a8f278933481',
+ 'repository': self.request.get('start_repository'),
+ 'git_hash': self.request.get('start_git_hash')
}
}
+
change_2 = {
'base_commit': {
- 'repository': 'src',
- 'git_hash': '858ceafc7cf4f11a6549b8c1ace839a45d943d68',
+ 'repository': self.request.get('end_repository'),
+ 'git_hash': self.request.get('end_git_hash')
}
}
# Validate parameters.
- try:
- if metric and not test_suite:
- raise ValueError("Specified a metric but there's no test_suite to run.")
- changes = (change.Change.FromDict(change_1),
- change.Change.FromDict(change_2))
- except (KeyError, ValueError) as e:
- self.response.set_status(400)
- self.response.write(e)
- return
+ self._ValidateTestPath(configuration, test_suite, test, metric)
# Convert parameters to canonical internal representation.
+ changes = self._ValidateChanges(change_1, change_2)
# Create job.
job = job_module.Job.New(
@@ -64,7 +84,42 @@ class New(webapp2.RequestHandler):
job_id = job.put().urlsafe()
# Start job.
- job.Start()
- job.put()
+ #job.Start()
+ #job.put()
+
+ self.response.out.write(json.dumps({
+ 'jobId': job_id
+ }))
+ logging.info('SUCCESS')
- self.response.write(job_id)
+ def _ValidateChanges(self, change_1, change_2):
+ try:
+ changes = (change.Change.FromDict(change_1),
+ change.Change.FromDict(change_2))
+ except (KeyError, ValueError) as e:
+ logging.info('FAIL1: %s' % str(e))
+ raise ParameterValidationError(str(e))
+
+ try:
+ commits = gitiles_service.CommitRange(
+ changes[0].base_commit.repository_url,
+ changes[0].base_commit.git_hash,
+ changes[1].base_commit.git_hash)
+ if len(commits) <= 1:
+ logging.info('FAIL: bad range')
+ raise ParameterValidationError('Commit range too small.')
+ except gitiles_service.NotFoundError as e:
+ logging.info('FAIL2: %s' % str(e))
+ raise ParameterValidationError(e.message)
+
+ return changes
+
+ def _ValidateTestPath(self, configuration, test_suite, test, metric):
+ try:
+ if metric and not test_suite:
+ logging.info('FAIL: suite')
+ raise ParameterValidationError(
+ "Specified a metric but there's no test_suite to run.")
+ except (KeyError, ValueError) as e:
+ logging.info('FAIL3: %s' % str(e))
+ raise ParameterValidationError(str(e))
« no previous file with comments | « dashboard/dashboard/pinpoint/elements/new-page.html ('k') | dashboard/dashboard/pinpoint/services/dashboard_service.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698