Index: dashboard/dashboard/pinpoint/handlers/new.py |
diff --git a/dashboard/dashboard/pinpoint/handlers/new.py b/dashboard/dashboard/pinpoint/handlers/new.py |
index 6f7f71c8d4ac4391351aad5ce5f7ca8ca86b4e86..ec8ff73ba4a2476b7605b3bcccc93f3e5005c87f 100644 |
--- a/dashboard/dashboard/pinpoint/handlers/new.py |
+++ b/dashboard/dashboard/pinpoint/handlers/new.py |
@@ -8,14 +8,10 @@ import webapp2 |
from dashboard.api import api_auth |
from dashboard.pinpoint.models import change |
from dashboard.pinpoint.models import job as job_module |
+from dashboard.pinpoint.models import quest_generator as quest_generator_module |
-_ERROR_METRIC_NO_TEST_SUITE = "Specified a metric but there's no test_suite "\ |
- "to run." |
-_ERROR_BUG_ID = 'Bug ID must be integer value.' |
- |
-class ParameterValidationError(Exception): |
- pass |
+_ERROR_BUG_ID = 'Bug ID must be an integer.' |
class New(webapp2.RequestHandler): |
@@ -24,7 +20,7 @@ class New(webapp2.RequestHandler): |
def post(self): |
try: |
self._CreateJob() |
- except (api_auth.ApiAuthException, ParameterValidationError) as e: |
+ except (api_auth.ApiAuthException, KeyError, TypeError, ValueError) as e: |
self._WriteErrorMessage(e.message) |
def _WriteErrorMessage(self, message): |
@@ -33,12 +29,8 @@ class New(webapp2.RequestHandler): |
@api_auth.Authorize |
def _CreateJob(self): |
"""Start a new Pinpoint job.""" |
- 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' |
- bug_id = self._ValidateBugId(self.request.get('bug_id')) |
+ bug_id = self.request.get('bug_id') |
change_1 = { |
'base_commit': { |
@@ -54,18 +46,15 @@ class New(webapp2.RequestHandler): |
} |
} |
- # Validate parameters. |
- self._ValidateMetric(test_suite, metric) |
- |
- # Convert parameters to canonical internal representation. |
+ # Validate arguments and convert them to canonical internal representation. |
+ quest_generator = quest_generator_module.QuestGenerator(self.request) |
+ bug_id = self._ValidateBugId(bug_id) |
changes = self._ValidateChanges(change_1, change_2) |
# Create job. |
job = job_module.Job.New( |
- configuration=configuration, |
- test_suite=test_suite, |
- test=test, |
- metric=metric, |
+ arguments=quest_generator.AsDict(), |
+ quests=quest_generator.Quests(), |
auto_explore=auto_explore, |
bug_id=bug_id) |
@@ -80,6 +69,8 @@ class New(webapp2.RequestHandler): |
job.Start() |
job.put() |
+ # TODO: Figure out if these should be underscores or lowerCamelCase. |
+ # TODO: They should match the input arguments. |
self.response.out.write(json.dumps({ |
'jobId': job_id, |
'jobUrl': job.url |
@@ -92,17 +83,7 @@ class New(webapp2.RequestHandler): |
try: |
return int(bug_id) |
except ValueError: |
- raise ParameterValidationError(_ERROR_BUG_ID) |
+ raise ValueError(_ERROR_BUG_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: |
- raise ParameterValidationError(str(e)) |
- |
- return changes |
- |
- def _ValidateMetric(self, test_suite, metric): |
- if metric and not test_suite: |
- raise ParameterValidationError(_ERROR_METRIC_NO_TEST_SUITE) |
+ return (change.Change.FromDict(change_1), change.Change.FromDict(change_2)) |