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

Side by Side 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 time
6
7 from appengine_wrappers import taskqueue 5 from appengine_wrappers import taskqueue
8 from commit_tracker import CommitTracker 6 from commit_tracker import CommitTracker
9 from cron_servlet import CronServlet 7 from future import All
10 from instance_servlet import InstanceServlet
11 from object_store_creator import ObjectStoreCreator 8 from object_store_creator import ObjectStoreCreator
12 from patch_servlet import PatchServlet 9 from servlet import Servlet, Response
13 from refresh_servlet import RefreshServlet
14 from servlet import Servlet, Request, Response
15 from test_servlet import TestServlet
16 10
17 11
18 _DEFAULT_SERVLET = InstanceServlet.GetConstructor() 12 class EnqueueServlet(Servlet):
19
20
21 class _EnqueueServlet(Servlet):
22 '''This Servlet can be used to manually enqueue tasks on the default 13 '''This Servlet can be used to manually enqueue tasks on the default
23 taskqueue. Useful for when an admin wants to manually force a specific 14 taskqueue. Useful for when an admin wants to manually force a specific
24 DataSource refresh, but the refresh operation takes longer than the 60 sec 15 DataSource refresh, but the refresh operation takes longer than the 60 sec
25 timeout of a non-taskqueue request. For example, you might query 16 timeout of a non-taskqueue request. For example, you might query
26 17
27 /_enqueue/_refresh/content_providers/cr-native-client?commit=123ff65468dcafff0 18 /_enqueue/_refresh/content_providers/cr-native-client?commit=123ff65468dcafff0
28 19
29 which will enqueue a task (/_refresh/content_providers/cr-native-client) to 20 which will enqueue a task (/_refresh/content_providers/cr-native-client) to
30 refresh the NaCl documentation cache for commit 123ff65468dcafff0. 21 refresh the NaCl documentation cache for commit 123ff65468dcafff0.
31 22
32 Access to this servlet should always be restricted to administrative users. 23 Access to this servlet should always be restricted to administrative users.
33 ''' 24 '''
34 def __init__(self, request): 25 def __init__(self, request):
35 Servlet.__init__(self, request) 26 Servlet.__init__(self, request)
36 27
37 def Get(self): 28 def Get(self):
38 queue = taskqueue.Queue() 29 queue = taskqueue.Queue()
39 queue.add(taskqueue.Task(url='/%s' % self._request.path, 30 queue.add(taskqueue.Task(url='/%s' % self._request.path,
40 params=self._request.arguments)) 31 params=self._request.arguments))
41 return Response.Ok('Task enqueued.') 32 return Response.Ok('Task enqueued.')
42 33
43 34
44 class _QueryCommitServlet(Servlet): 35 class QueryCommitServlet(Servlet):
45 '''Provides read access to the commit ID cache within the server. For example: 36 '''Provides read access to the commit ID cache within the server. For example:
46 37
47 /_query_commit/master 38 /_query_commit/master
48 39
49 will return the commit ID stored under the commit key "master" within the 40 will return the commit ID stored under the commit key "master" within the
50 commit cache. Currently "master" is the only named commit we cache, and it 41 commit cache. Currently "master" is the only named commit we cache, and it
51 corresponds to the commit ID whose data currently populates the data cache 42 corresponds to the commit ID whose data currently populates the data cache
52 used by live instances. 43 used by live instances.
53 ''' 44 '''
54 def __init__(self, request): 45 def __init__(self, request):
55 Servlet.__init__(self, request) 46 Servlet.__init__(self, request)
56 47
57 def Get(self): 48 def Get(self):
58 object_store_creator = ObjectStoreCreator(start_empty=False) 49 object_store_creator = ObjectStoreCreator(start_empty=False)
59 commit_tracker = CommitTracker(object_store_creator) 50 commit_tracker = CommitTracker(object_store_creator)
60 return Response.Ok(commit_tracker.Get(self._request.path).Get()) 51
52 def generate_response(result):
53 commit_id, history = result
54 history_log = ''.join('%s: %s<br>' % (entry.datetime, entry.commit_id)
55 for entry in reversed(history))
56 response = 'Current commit: %s<br><br>Most recent commits:<br>%s' % (
57 commit_id, history_log)
58 return response
59
60 commit_name = self._request.path
61 id_future = commit_tracker.Get(commit_name)
62 history_future = commit_tracker.GetHistory(commit_name)
63 return Response.Ok(
64 All((id_future, history_future)).Then(generate_response).Get())
61 65
62 66
63 _SERVLETS = { 67 class ResetCommitServlet(Servlet):
64 'cron': CronServlet, 68 '''Writes a new commit ID to the commit cache. For example:
65 'enqueue': _EnqueueServlet,
66 'patch': PatchServlet,
67 'query_commit': _QueryCommitServlet,
68 'refresh': RefreshServlet,
69 'test': TestServlet,
70 }
71 69
70 /_reset_commit/master/123456
72 71
73 class Handler(Servlet): 72 will reset the 'master' commit ID to '123456'. The provided commit MUST be
73 in the named commit's recent history or it will be ignored.
74 '''
75 def __init__(self, request):
76 Servlet.__init__(self, request)
77
74 def Get(self): 78 def Get(self):
75 path = self._request.path 79 object_store_creator = ObjectStoreCreator(start_empty=False)
80 commit_tracker = CommitTracker(object_store_creator)
81 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.
82 history = commit_tracker.GetHistory(commit_name).Get()
83 if not any(entry.commit_id == commit_id for entry in history):
84 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.
85 commit_tracker.Set(commit_name, commit_id).Get()
86 return Response.Ok('Commit "%s" updated to %s' % (commit_name, commit_id))
76 87
77 if path.startswith('_'):
78 servlet_path = path[1:]
79 if not '/' in servlet_path:
80 servlet_path += '/'
81 servlet_name, servlet_path = servlet_path.split('/', 1)
82 servlet = _SERVLETS.get(servlet_name)
83 if servlet is None:
84 return Response.NotFound('"%s" servlet not found' % servlet_path)
85 else:
86 servlet_path = path
87 servlet = _DEFAULT_SERVLET
88
89 return servlet(Request(servlet_path,
90 self._request.host,
91 self._request.headers,
92 self._request.arguments)).Get()
OLDNEW
« 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