Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Utilities for reading GCE Backend configuration.""" | 5 """Utilities for reading GCE Backend configuration.""" |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 import logging | 8 import logging |
| 9 | 9 |
| 10 from components import utils | 10 from components import utils |
| 11 utils.fix_protobuf_package() | 11 utils.fix_protobuf_package() |
| 12 | 12 |
| 13 from google import protobuf | 13 from google import protobuf |
| 14 from google.appengine.ext import ndb | 14 from google.appengine.ext import ndb |
| 15 | 15 |
| 16 import metrics | 16 import metrics |
| 17 | 17 |
| 18 from components import config | 18 from components import config |
| 19 from components import datastore_utils | 19 from components import datastore_utils |
| 20 from components import utils | |
| 20 from components.config import validation | 21 from components.config import validation |
| 21 | 22 |
| 22 from proto import config_pb2 | 23 from proto import config_pb2 |
| 23 | 24 |
| 24 | 25 |
| 25 TEMPLATES_CFG_FILENAME = 'templates.cfg' | 26 TEMPLATES_CFG_FILENAME = 'templates.cfg' |
| 26 MANAGERS_CFG_FILENAME = 'managers.cfg' | 27 MANAGERS_CFG_FILENAME = 'managers.cfg' |
| 28 SETTINGS_CFG_FILENAME = 'settings.cfg' | |
| 27 | 29 |
| 28 | 30 |
| 29 class Configuration(datastore_utils.config.GlobalConfig): | 31 class Configuration(datastore_utils.config.GlobalConfig): |
| 30 """Configuration for this service.""" | 32 """Configuration for this service.""" |
| 31 # Text-formatted proto.config_pb2.InstanceTemplateConfig. | 33 # Text-formatted proto.config_pb2.InstanceTemplateConfig. |
| 32 template_config = ndb.TextProperty() | 34 template_config = ndb.TextProperty() |
| 33 # Text-formatted proto.config_pb2.InstanceGroupManagerConfig. | 35 # Text-formatted proto.config_pb2.InstanceGroupManagerConfig. |
| 34 manager_config = ndb.TextProperty() | 36 manager_config = ndb.TextProperty() |
| 35 # Revision of the configs. | 37 # Revision of the configs. |
| 36 revision = ndb.StringProperty() | 38 revision = ndb.StringProperty() |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 context.error( | 130 context.error( |
| 129 'zone %s is not unique in template %s.', | 131 'zone %s is not unique in template %s.', |
| 130 manager.zone, | 132 manager.zone, |
| 131 manager.template_base_name, | 133 manager.template_base_name, |
| 132 ) | 134 ) |
| 133 valid = False | 135 valid = False |
| 134 else: | 136 else: |
| 135 zones[manager.template_base_name].add(manager.zone) | 137 zones[manager.template_base_name].add(manager.zone) |
| 136 | 138 |
| 137 metrics.config_valid.set(valid, fields={'config': MANAGERS_CFG_FILENAME}) | 139 metrics.config_valid.set(valid, fields={'config': MANAGERS_CFG_FILENAME}) |
| 140 | |
| 141 | |
| 142 @validation.self_rule(SETTINGS_CFG_FILENAME, config_pb2.SettingsCfg) | |
| 143 def validate_settings_config(config, context): | |
| 144 pass | |
| 145 | |
| 146 | |
| 147 def _get_settings(): | |
| 148 """Returns (rev, cfg) where cfg is a parsed SettingsCfg message. | |
| 149 | |
| 150 The config is cached in the datastore. | |
| 151 """ | |
| 152 rev, cfg = config.get_self_config( | |
| 153 SETTINGS_CFG_FILENAME, config_pb2.SettingsCfg, store_last_good=True) | |
|
M-A Ruel
2016/08/12 19:24:25
align arguments at +4
ryanmartens
2016/08/16 17:11:03
Done.
| |
| 154 cfg = cfg or config_pb2.SettingsCfg() | |
| 155 return rev, cfg | |
| 156 | |
| 157 | |
| 158 @utils.cache_with_expiration(60) | |
| 159 def settings(): | |
| 160 """Loads settings from an NDB-based cache or a default one if not present.""" | |
| 161 return _get_settings()[1] | |
| OLD | NEW |