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

Unified Diff: tools/android/loading/cloud/common/clovis_task.py

Issue 1878943013: tools/android/loading Add appengine frontend for Clovis (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor
Patch Set: Add gitignore Created 4 years, 8 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
« no previous file with comments | « tools/android/loading/cloud/common/__init__.py ('k') | tools/android/loading/cloud/frontend/.gitignore » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/cloud/common/clovis_task.py
diff --git a/tools/android/loading/cloud/common/clovis_task.py b/tools/android/loading/cloud/common/clovis_task.py
new file mode 100644
index 0000000000000000000000000000000000000000..8bc3127a34364c279459cd8f576eac396d2c6d69
--- /dev/null
+++ b/tools/android/loading/cloud/common/clovis_task.py
@@ -0,0 +1,66 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import base64
+import json
+
+class ClovisTask(object):
+ """Generic task, generated by the AppEngine frontend and consumed by the
+ ComputeEngine backend.
+ """
+
+ def __init__(self, action, params, taskqueue_tag):
+ """Params:
+ action(str): Action accomplished by this task.
+ params(dict): Parameters of task.
+ taskqueue_tag(str): Tag of the task. Optional.
+ """
+ self._action = action
+ self._params = params
+ self._taskqueue_tag = taskqueue_tag
+
+ @classmethod
+ def FromJsonDict(cls, json_dict):
+ """Loads a ClovisTask from a JSON string.
+
+ Returns:
+ ClovisTask: The task, or None if the string is invalid.
+ """
+ try:
+ data = json.loads(json_dict)
+ action = data['action']
+ params = data['params']
+ tag = data.get('taskqueue_tag')
+ # Vaidate the format.
+ if action == 'trace':
+ urls = params['urls']
+ if (type(urls) is not list) or (len(urls) == 0):
+ return None
+ else:
+ # When more actions are supported, check that they are valid here.
+ return None
+ return cls(action, params, tag)
+ except Exception:
+ return None
+
+ @classmethod
+ def FromBase64(cls, base64_string):
+ """Loads a ClovisTask from a base 64 string."""
+ return ClovisTask.FromJsonDict(base64.b64decode(base64_string))
+
+ def ToJsonDict(self):
+ """Returns the JSON representation of the task."""
+ task_dict = { 'action': self._action, 'params': self._params }
+ if self._taskqueue_tag:
+ task_dict['taskqueue_tag'] = self._taskqueue_tag
+ return json.dumps(task_dict)
+
+ def Action(self):
+ return self._action
+
+ def Params(self):
+ return self._params
+
+ def TaskqueueTag(self):
+ return self._taskqueue_tag
« no previous file with comments | « tools/android/loading/cloud/common/__init__.py ('k') | tools/android/loading/cloud/frontend/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698