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

Unified Diff: chrome/common/extensions/docs/server2/admin_servlets.py

Issue 736773002: Docserver: Add commit history and _reset_commit servlet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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: chrome/common/extensions/docs/server2/admin_servlets.py
diff --git a/chrome/common/extensions/docs/server2/handler.py b/chrome/common/extensions/docs/server2/admin_servlets.py
similarity index 51%
copy from chrome/common/extensions/docs/server2/handler.py
copy to chrome/common/extensions/docs/server2/admin_servlets.py
index a0e044e753aab96ad34bc124736999020b42f372..b569f5d8ae318091c025a45caa7f677ad24ed098 100644
--- a/chrome/common/extensions/docs/server2/handler.py
+++ b/chrome/common/extensions/docs/server2/admin_servlets.py
@@ -1,24 +1,15 @@
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Copyright 2014 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 time
-
from appengine_wrappers import taskqueue
from commit_tracker import CommitTracker
-from cron_servlet import CronServlet
-from instance_servlet import InstanceServlet
+from future import All
from object_store_creator import ObjectStoreCreator
-from patch_servlet import PatchServlet
-from refresh_servlet import RefreshServlet
-from servlet import Servlet, Request, Response
-from test_servlet import TestServlet
-
-
-_DEFAULT_SERVLET = InstanceServlet.GetConstructor()
+from servlet import Servlet, Response
-class _EnqueueServlet(Servlet):
+class EnqueueServlet(Servlet):
'''This Servlet can be used to manually enqueue tasks on the default
taskqueue. Useful for when an admin wants to manually force a specific
DataSource refresh, but the refresh operation takes longer than the 60 sec
@@ -41,7 +32,7 @@ class _EnqueueServlet(Servlet):
return Response.Ok('Task enqueued.')
-class _QueryCommitServlet(Servlet):
+class QueryCommitServlet(Servlet):
'''Provides read access to the commit ID cache within the server. For example:
/_query_commit/master
@@ -57,36 +48,40 @@ class _QueryCommitServlet(Servlet):
def Get(self):
object_store_creator = ObjectStoreCreator(start_empty=False)
commit_tracker = CommitTracker(object_store_creator)
- return Response.Ok(commit_tracker.Get(self._request.path).Get())
+ def generate_response(result):
+ commit_id, history = result
+ history_log = ''.join('%s: %s<br>' % (entry.datetime, entry.commit_id)
+ for entry in reversed(history))
+ response = 'Current commit: %s<br><br>Most recent commits:<br>%s' % (
+ commit_id, history_log)
+ return response
+
+ commit_name = self._request.path
+ id_future = commit_tracker.Get(commit_name)
+ history_future = commit_tracker.GetHistory(commit_name)
+ return Response.Ok(
+ All((id_future, history_future)).Then(generate_response).Get())
+
+
+class ResetCommitServlet(Servlet):
+ '''Writes a new commit ID to the commit cache. For example:
-_SERVLETS = {
- 'cron': CronServlet,
- 'enqueue': _EnqueueServlet,
- 'patch': PatchServlet,
- 'query_commit': _QueryCommitServlet,
- 'refresh': RefreshServlet,
- 'test': TestServlet,
-}
+ /_reset_commit/master/123456
+ will reset the 'master' commit ID to '123456'. The provided commit MUST be
+ in the named commit's recent history or it will be ignored.
+ '''
+ def __init__(self, request):
+ Servlet.__init__(self, request)
-class Handler(Servlet):
def Get(self):
- path = self._request.path
-
- if path.startswith('_'):
- servlet_path = path[1:]
- if not '/' in servlet_path:
- servlet_path += '/'
- servlet_name, servlet_path = servlet_path.split('/', 1)
- servlet = _SERVLETS.get(servlet_name)
- if servlet is None:
- return Response.NotFound('"%s" servlet not found' % servlet_path)
- else:
- servlet_path = path
- servlet = _DEFAULT_SERVLET
-
- return servlet(Request(servlet_path,
- self._request.host,
- self._request.headers,
- self._request.arguments)).Get()
+ object_store_creator = ObjectStoreCreator(start_empty=False)
+ commit_tracker = CommitTracker(object_store_creator)
+ commit_name, commit_id = self._request.path.split('/')
not at google - send to devlin 2014/11/19 19:32:41 You might want to use .split('/', 1) so that this
Ken Rockot(use gerrit already) 2015/02/02 23:57:44 Done.
+ history = commit_tracker.GetHistory(commit_name).Get()
+ if not any(entry.commit_id == commit_id for entry in history):
+ return Response.NotFound('Commit %s not found.' % commit_id)
not at google - send to devlin 2014/11/19 19:32:41 Nit, but I don't think 404 is actually the right e
Ken Rockot(use gerrit already) 2015/02/02 23:57:44 Done. 400 seems like the only reasonable option.
+ commit_tracker.Set(commit_name, commit_id).Get()
+ return Response.Ok('Commit "%s" updated to %s' % (commit_name, commit_id))
+
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/app.yaml » ('j') | chrome/common/extensions/docs/server2/commit_tracker.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698