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

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

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2013 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.
4
5 from appengine_wrappers import IsDevServer
6 from branch_utility import BranchUtility
7 from caching_file_system import CachingFileSystem
8 from github_file_system import GithubFileSystem
9 from third_party.json_schema_compiler.memoize import memoize
10 from offline_file_system import OfflineFileSystem
11 from render_servlet import RenderServlet
12 from subversion_file_system import SubversionFileSystem
13 from object_store_creator import ObjectStoreCreator
14 from server_instance import ServerInstance
15 from servlet import Servlet
16
17 class _OfflineRenderServletDelegate(RenderServlet.Delegate):
18 '''AppEngine instances should never need to call out to SVN. That should only
19 ever be done by the cronjobs, which then write the result into DataStore,
20 which is as far as instances look. To enable this, crons can pass a custom
21 (presumably online) ServerInstance into Get().
22
23 Why? SVN is slow and a bit flaky. Cronjobs failing is annoying but temporary.
24 Instances failing affects users, and is really bad.
25
26 Anyway - to enforce this, we actually don't give instances access to SVN. If
27 anything is missing from datastore, it'll be a 404. If the cronjobs don't
28 manage to catch everything - uhoh. On the other hand, we'll figure it out
29 pretty soon, and it also means that legitimate 404s are caught before a round
30 trip to SVN.
31 '''
32 def __init__(self, delegate):
33 self._delegate = delegate
34
35 @memoize
36 def CreateServerInstanceForChannel(self, channel):
37 object_store_creator = ObjectStoreCreator(channel, start_empty=False)
38 branch = (self._delegate.CreateBranchUtility(object_store_creator)
39 .GetBranchForChannel(channel))
40 host_file_system = CachingFileSystem(
41 OfflineFileSystem(self._delegate.CreateHostFileSystemForBranch(branch)),
42 object_store_creator)
43 app_samples_file_system = self._delegate.CreateAppSamplesFileSystem(
44 object_store_creator)
45 return ServerInstance(channel,
46 object_store_creator,
47 host_file_system,
48 app_samples_file_system)
49
50 class InstanceServlet(object):
51 '''Servlet for running on normal AppEngine instances.
52 Create this via GetConstructor() so that cache state can be shared amongst
53 them via the memoizing Delegate.
54 '''
55 class Delegate(object):
56 '''Allow runtime dependencies to be overriden for testing.
57 '''
58 def CreateBranchUtility(self, object_store_creator):
59 return BranchUtility.Create(object_store_creator)
60
61 def CreateHostFileSystemForBranch(self, branch):
62 return SubversionFileSystem.Create(branch)
63
64 def CreateAppSamplesFileSystem(self, object_store_creator):
65 # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but
66 # the cron job doesn't crawl the samples yet.
67 return (EmptyDirFileSystem() if IsDevServer() else
68 GithubFileSystem.Create(object_store_creator))
69
70 @staticmethod
71 def GetConstructor(delegate_for_test=None):
72 render_servlet_delegate = _OfflineRenderServletDelegate(
73 delegate_for_test or InstanceServlet.Delegate())
74 return lambda request: RenderServlet(request, render_servlet_delegate)
75
76 # NOTE: if this were a real Servlet it would implement a Get() method, but
77 # GetConstructor returns an appropriate lambda function (Request -> Servlet).
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698