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

Side by Side Diff: chrome/common/extensions/docs/server2/handler.py

Issue 736773002: Docserver: Add commit history and _reset_commit servlet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup, test for commit reset Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 5 import time
6 6
7 from appengine_wrappers import taskqueue 7 from admin_servlets import (DumpRefreshServlet, EnqueueServlet,
8 from commit_tracker import CommitTracker 8 QueryCommitServlet, ResetCommitServlet)
9 from cron_servlet import CronServlet 9 from cron_servlet import CronServlet
10 from instance_servlet import InstanceServlet 10 from instance_servlet import InstanceServlet
11 from object_store_creator import ObjectStoreCreator
12 from patch_servlet import PatchServlet 11 from patch_servlet import PatchServlet
13 from refresh_servlet import RefreshServlet 12 from refresh_servlet import RefreshServlet
14 from servlet import Servlet, Request, Response 13 from servlet import Servlet, Request, Response
15 from test_servlet import TestServlet 14 from test_servlet import TestServlet
16 15
17 16
18 _DEFAULT_SERVLET = InstanceServlet.GetConstructor() 17 _DEFAULT_SERVLET = InstanceServlet.GetConstructor()
19 18
20 19
21 class _EnqueueServlet(Servlet):
22 '''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
24 DataSource refresh, but the refresh operation takes longer than the 60 sec
25 timeout of a non-taskqueue request. For example, you might query
26
27 /_enqueue/_refresh/content_providers/cr-native-client?commit=123ff65468dcafff0
28
29 which will enqueue a task (/_refresh/content_providers/cr-native-client) to
30 refresh the NaCl documentation cache for commit 123ff65468dcafff0.
31
32 Access to this servlet should always be restricted to administrative users.
33 '''
34 def __init__(self, request):
35 Servlet.__init__(self, request)
36
37 def Get(self):
38 queue = taskqueue.Queue()
39 queue.add(taskqueue.Task(url='/%s' % self._request.path,
40 params=self._request.arguments))
41 return Response.Ok('Task enqueued.')
42
43
44 class _QueryCommitServlet(Servlet):
45 '''Provides read access to the commit ID cache within the server. For example:
46
47 /_query_commit/master
48
49 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
51 corresponds to the commit ID whose data currently populates the data cache
52 used by live instances.
53 '''
54 def __init__(self, request):
55 Servlet.__init__(self, request)
56
57 def Get(self):
58 object_store_creator = ObjectStoreCreator(start_empty=False)
59 commit_tracker = CommitTracker(object_store_creator)
60 return Response.Ok(commit_tracker.Get(self._request.path).Get())
61
62
63 _SERVLETS = { 20 _SERVLETS = {
64 'cron': CronServlet, 21 'cron': CronServlet,
65 'enqueue': _EnqueueServlet, 22 'enqueue': EnqueueServlet,
66 'patch': PatchServlet, 23 'patch': PatchServlet,
67 'query_commit': _QueryCommitServlet, 24 'query_commit': QueryCommitServlet,
68 'refresh': RefreshServlet, 25 'refresh': RefreshServlet,
26 'reset_commit': ResetCommitServlet,
69 'test': TestServlet, 27 'test': TestServlet,
28 'dump_refresh': DumpRefreshServlet,
70 } 29 }
71 30
72 31
73 class Handler(Servlet): 32 class Handler(Servlet):
74 def Get(self): 33 def Get(self):
75 path = self._request.path 34 path = self._request.path
76 35
77 if path.startswith('_'): 36 if path.startswith('_'):
78 servlet_path = path[1:] 37 servlet_path = path[1:]
79 if not '/' in servlet_path: 38 if not '/' in servlet_path:
80 servlet_path += '/' 39 servlet_path += '/'
81 servlet_name, servlet_path = servlet_path.split('/', 1) 40 servlet_name, servlet_path = servlet_path.split('/', 1)
82 servlet = _SERVLETS.get(servlet_name) 41 servlet = _SERVLETS.get(servlet_name)
83 if servlet is None: 42 if servlet is None:
84 return Response.NotFound('"%s" servlet not found' % servlet_path) 43 return Response.NotFound('"%s" servlet not found' % servlet_path)
85 else: 44 else:
86 servlet_path = path 45 servlet_path = path
87 servlet = _DEFAULT_SERVLET 46 servlet = _DEFAULT_SERVLET
88 47
89 return servlet(Request(servlet_path, 48 return servlet(Request(servlet_path,
90 self._request.host, 49 self._request.host,
91 self._request.headers, 50 self._request.headers,
92 self._request.arguments)).Get() 51 self._request.arguments)).Get()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698