OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 from branch_utility import BranchUtility | 5 from branch_utility import BranchUtility |
6 from compiled_file_system import CompiledFileSystem | 6 from compiled_file_system import CompiledFileSystem |
7 from environment import IsDevServer, IsReleaseServer | 7 from environment import IsDevServer, IsReleaseServer |
8 from github_file_system_provider import GithubFileSystemProvider | 8 from github_file_system_provider import GithubFileSystemProvider |
9 from host_file_system_provider import HostFileSystemProvider | 9 from host_file_system_provider import HostFileSystemProvider |
10 from third_party.json_schema_compiler.memoize import memoize | 10 from third_party.json_schema_compiler.memoize import memoize |
11 from render_servlet import RenderServlet | 11 from render_servlet import RenderServlet |
12 from object_store_creator import ObjectStoreCreator | 12 from object_store_creator import ObjectStoreCreator |
13 from server_instance import ServerInstance | 13 from server_instance import ServerInstance |
14 from gcs_file_system_provider import CloudStorageFileSystemProvider | 14 from gcs_file_system_provider import CloudStorageFileSystemProvider |
15 | 15 |
16 | |
17 | |
18 def _GetInstanceMasterCommit(): | |
not at google - send to devlin
2014/10/20 21:06:57
Comment.
Ken Rockot(use gerrit already)
2014/10/22 03:19:54
Done.
| |
19 creator = ObjectStoreCreator(start_empty=False) | |
20 store = creator.Create(str, category='commits') | |
not at google - send to devlin
2014/10/20 21:06:57
Use InstanceServlet rather than str?
Also you mig
Ken Rockot(use gerrit already)
2014/10/22 03:19:54
Done.
| |
21 def get_master(results): | |
22 return results.get('master') | |
23 return store.GetMulti(['master']).Then(get_master).Get() | |
not at google - send to devlin
2014/10/20 21:06:57
You could just return store.Get('master').Get()?
Ken Rockot(use gerrit already)
2014/10/22 03:19:54
Oh. Derp. Didn't actually look at the base ObjectS
| |
24 | |
25 | |
not at google - send to devlin
2014/10/20 21:06:57
dd
| |
26 | |
16 class InstanceServletRenderServletDelegate(RenderServlet.Delegate): | 27 class InstanceServletRenderServletDelegate(RenderServlet.Delegate): |
17 '''AppEngine instances should never need to call out to Gitiles. That should | 28 '''AppEngine instances should never need to call out to Gitiles. That should |
18 only ever be done by the cronjobs, which then write the result into | 29 only ever be done by the cronjobs, which then write the result into |
19 DataStore, which is as far as instances look. To enable this, crons can pass | 30 DataStore, which is as far as instances look. To enable this, crons can pass |
20 a custom (presumably online) ServerInstance into Get(). | 31 a custom (presumably online) ServerInstance into Get(). |
21 | 32 |
22 Why? Gitiles is slow and a bit flaky. Refresh jobs failing is annoying but | 33 Why? Gitiles is slow and a bit flaky. Refresh jobs failing is annoying but |
23 temporary. Instances failing affects users, and is really bad. | 34 temporary. Instances failing affects users, and is really bad. |
24 | 35 |
25 Anyway - to enforce this, we actually don't give instances access to | 36 Anyway - to enforce this, we actually don't give instances access to |
26 Gitiles. If anything is missing from datastore, it'll be a 404. If the | 37 Gitiles. If anything is missing from datastore, it'll be a 404. If the |
27 cronjobs don't manage to catch everything - uhoh. On the other hand, we'll | 38 cronjobs don't manage to catch everything - uhoh. On the other hand, we'll |
28 figure it out pretty soon, and it also means that legitimate 404s are caught | 39 figure it out pretty soon, and it also means that legitimate 404s are caught |
29 before a round trip to Gitiles. | 40 before a round trip to Gitiles. |
30 ''' | 41 ''' |
31 def __init__(self, delegate): | 42 def __init__(self, delegate): |
32 self._delegate = delegate | 43 self._delegate = delegate |
33 | 44 |
34 @memoize | 45 @memoize |
35 def CreateServerInstance(self): | 46 def CreateServerInstance(self): |
36 object_store_creator = ObjectStoreCreator(start_empty=False) | 47 object_store_creator = ObjectStoreCreator(start_empty=False) |
37 branch_utility = self._delegate.CreateBranchUtility(object_store_creator) | 48 branch_utility = self._delegate.CreateBranchUtility(object_store_creator) |
38 # In production have offline=True so that we can catch cron errors. In | 49 # In production have offline=True so that we can catch cron errors. In |
39 # development it's annoying to have to run the cron job, so offline=False. | 50 # development it's annoying to have to run the cron job, so offline=False. |
40 # Note that offline=True if running on any appengine server due to | 51 # Note that offline=True if running on any appengine server due to |
41 # http://crbug.com/345361. | 52 # http://crbug.com/345361. |
42 host_file_system_provider = self._delegate.CreateHostFileSystemProvider( | 53 host_file_system_provider = self._delegate.CreateHostFileSystemProvider( |
43 object_store_creator, | 54 object_store_creator, |
44 offline=not (IsDevServer() or IsReleaseServer())) | 55 offline=not (IsDevServer() or IsReleaseServer()), |
56 pinned_commit=_GetInstanceMasterCommit(), | |
57 cache_only=True) | |
45 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider( | 58 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider( |
46 object_store_creator) | 59 object_store_creator) |
47 return ServerInstance(object_store_creator, | 60 return ServerInstance(object_store_creator, |
48 CompiledFileSystem.Factory(object_store_creator), | 61 CompiledFileSystem.Factory(object_store_creator), |
49 branch_utility, | 62 branch_utility, |
50 host_file_system_provider, | 63 host_file_system_provider, |
51 github_file_system_provider, | 64 github_file_system_provider, |
52 CloudStorageFileSystemProvider(object_store_creator)) | 65 CloudStorageFileSystemProvider(object_store_creator)) |
53 | 66 |
54 class InstanceServlet(object): | 67 class InstanceServlet(object): |
(...skipping 14 matching lines...) Expand all Loading... | |
69 return GithubFileSystemProvider(object_store_creator) | 82 return GithubFileSystemProvider(object_store_creator) |
70 | 83 |
71 @staticmethod | 84 @staticmethod |
72 def GetConstructor(delegate_for_test=None): | 85 def GetConstructor(delegate_for_test=None): |
73 render_servlet_delegate = InstanceServletRenderServletDelegate( | 86 render_servlet_delegate = InstanceServletRenderServletDelegate( |
74 delegate_for_test or InstanceServlet.Delegate()) | 87 delegate_for_test or InstanceServlet.Delegate()) |
75 return lambda request: RenderServlet(request, render_servlet_delegate) | 88 return lambda request: RenderServlet(request, render_servlet_delegate) |
76 | 89 |
77 # NOTE: if this were a real Servlet it would implement a Get() method, but | 90 # NOTE: if this were a real Servlet it would implement a Get() method, but |
78 # GetConstructor returns an appropriate lambda function (Request -> Servlet). | 91 # GetConstructor returns an appropriate lambda function (Request -> Servlet). |
OLD | NEW |