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
3 # found in the LICENSE file.
7 from appengine_wrappers import taskqueue
8 from commit_tracker import CommitTracker
9 from cron_servlet import CronServlet
10 from instance_servlet import InstanceServlet
11 from object_store_creator import ObjectStoreCreator
12 from patch_servlet import PatchServlet
13 from refresh_servlet import RefreshServlet
14 from servlet import Servlet, Request, Response
15 from test_servlet import TestServlet
18 _DEFAULT_SERVLET = InstanceServlet.GetConstructor()
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
27 /_enqueue/_refresh/content_providers/cr-native-client?commit=123ff65468dcafff0
29 which will enqueue a task (/_refresh/content_providers/cr-native-client) to
30 refresh the NaCl documentation cache for commit 123ff65468dcafff0.
32 Access to this servlet should always be restricted to administrative users.
34 def __init__(self, request):
35 Servlet.__init__(self, request)
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.')
44 class _QueryCommitServlet(Servlet):
45 '''Provides read access to the commit ID cache within the server. For example:
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.
54 def __init__(self, request):
55 Servlet.__init__(self, request)
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())
65 'enqueue': _EnqueueServlet,
66 'patch': PatchServlet,
67 'query_commit': _QueryCommitServlet,
68 'refresh': RefreshServlet,
73 class Handler(Servlet):
75 path = self._request.path
77 if path.startswith('_'):
78 servlet_path = path[1:]
79 if not '/' in servlet_path:
81 servlet_name, servlet_path = servlet_path.split('/', 1)
82 servlet = _SERVLETS.get(servlet_name)
84 return Response.NotFound('"%s" servlet not found' % servlet_path)
87 servlet = _DEFAULT_SERVLET
89 return servlet(Request(servlet_path,
91 self._request.headers,
92 self._request.arguments)).Get()