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

Side by Side Diff: appengine/findit/model/wf_config.py

Issue 1497783003: [Findit] Use Findit's own versioned config. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@versioned_model
Patch Set: Created 5 years 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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 """Findit for Waterfall configuration.""" 5 """Findit for Waterfall configuration."""
6 6
7 from google.appengine.ext import ndb 7 from google.appengine.ext import ndb
8 8
9 from components import datastore_utils 9 from model.versioned_config import VersionedConfig
10 10
11 11
12 # TODO(lijeffrey): It seems importing config from luci causes import breakages 12 class FinditConfig(VersionedConfig):
13 # in other parts of the code. Need to debug and fix the import error and 13 """Global configuration of findit."""
14 # subclass FinditConfig from config.GlobalConfig if possible.
15 class FinditConfig(ndb.Model):
16 """Singleton entity with the global configuration of findit."""
17 _config_fetcher = None
18
19 # A Dict mapping supported masters to lists of unsupported steps. 14 # A Dict mapping supported masters to lists of unsupported steps.
20 masters_to_blacklisted_steps = ndb.JsonProperty(indexed=False, default={}) 15 masters_to_blacklisted_steps = ndb.JsonProperty(indexed=False, default={})
21 16
22 # Mapping of waterfall builders to try-server trybots, which are used to 17 # Mapping of waterfall builders to try-server trybots, which are used to
23 # re-run compile to identify culprits for compile failures. 18 # re-run compile to identify culprits for compile failures.
24 builders_to_trybots = ndb.JsonProperty(indexed=False, default={}) 19 builders_to_trybots = ndb.JsonProperty(indexed=False, default={})
25
26 @property
27 def VersionNumber(self): # pragma: no cover
28 return datastore_utils.HIGH_KEY_ID - self.key.integer_id()
29
30 @classmethod
31 def _get_root_model(cls): # pragma: no cover
32 return datastore_utils.get_versioned_root_model('%sRoot' % cls.__name__)
33
34 @classmethod
35 def _get_root_key(cls): # pragma: no cover
36 return ndb.Key(cls._get_root_model(), 1)
37
38 @classmethod
39 def fetch(cls): # pragma: no cover
40 """Returns the current up-to-date version of the config entity.
41
42 Always fetches it from datastore. May return None if missing.
43 """
44 return datastore_utils.get_versioned_most_recent(cls, cls._get_root_key())
45
46 @classmethod
47 def cached(cls): # pragma: no cover
48 if not cls._config_fetcher:
49 def config_fetcher():
50 conf = cls.fetch()
51 if not conf:
52 conf = cls()
53 conf.store()
54 return conf
55 cls._config_fetcher = staticmethod(config_fetcher)
56 return cls._config_fetcher()
57
58 def store(self): # pragma: no cover
59 """Stores a new version of the config entity."""
60 # Create an incomplete key, to be completed by 'store_new_version'.
61 self.key = ndb.Key(self.__class__, None, parent=self._get_root_key())
62 return datastore_utils.store_new_version(self, self._get_root_model())
63
64 def modify(self, **kwargs): # pragma: no cover
65 """Applies |kwargs| dict to the entity and stores the entity if changed."""
66 dirty = False
67 for k, v in kwargs.iteritems():
68 assert k in self._properties, k
69 if getattr(self, k) != v:
70 setattr(self, k, v)
71 dirty = True
72 if dirty:
73 self.store()
74 return dirty
75
76 # Mapping of waterfall builders to try-server trybots, which are used to
77 # re-run compile to identify culprits for compile failures.
78 builders_to_trybots = ndb.JsonProperty(indexed=False, default={})
79
80
81 def Settings(): # pragma: no cover
82 return FinditConfig.cached()
83
84
85 def Update(new_config_dict): # pragma: no cover
86 conf = Settings()
87 conf.modify(**new_config_dict)
OLDNEW
« no previous file with comments | « appengine/findit/handlers/test/config_test.py ('k') | appengine/findit/waterfall/test/waterfall_config_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698