| OLD | NEW |
| 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 """Access to bucket configurations. | 5 """Access to bucket configurations. |
| 6 | 6 |
| 7 Stores bucket list in datastore, synchronizes it with bucket configs in | 7 Stores bucket list in datastore, synchronizes it with bucket configs in |
| 8 project repositories: `projects/<project_id>:<buildbucket-app-id>.cfg`. | 8 project repositories: `projects/<project_id>:<buildbucket-app-id>.cfg`. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 @ndb.tasklet | 133 @ndb.tasklet |
| 134 def get_buckets_async(): | 134 def get_buckets_async(): |
| 135 """Returns a list of project_config_pb2.Bucket objects.""" | 135 """Returns a list of project_config_pb2.Bucket objects.""" |
| 136 buckets = yield Bucket.query().fetch_async() | 136 buckets = yield Bucket.query().fetch_async() |
| 137 raise ndb.Return([parse_bucket_config(b.config_content) for b in buckets]) | 137 raise ndb.Return([parse_bucket_config(b.config_content) for b in buckets]) |
| 138 | 138 |
| 139 | 139 |
| 140 @ndb.non_transactional | 140 @ndb.non_transactional |
| 141 @ndb.tasklet | 141 @ndb.tasklet |
| 142 def get_bucket_async(name): | 142 def get_bucket_async(name): |
| 143 """Returns a project_config_pb2.Bucket by name.""" | 143 """Returns a (project, project_config_pb2.Bucket) tuple.""" |
| 144 bucket = yield Bucket.get_by_id_async(name) | 144 bucket = yield Bucket.get_by_id_async(name) |
| 145 if bucket is None: | 145 if bucket is None: |
| 146 raise ndb.Return(None) | 146 raise ndb.Return(None, None) |
| 147 raise ndb.Return(parse_bucket_config(bucket.config_content)) | 147 raise ndb.Return( |
| 148 bucket.project_id, parse_bucket_config(bucket.config_content)) |
| 148 | 149 |
| 149 | 150 |
| 150 def cron_update_buckets(): | 151 def cron_update_buckets(): |
| 151 """Synchronizes Bucket entities with configs fetched from luci-config.""" | 152 """Synchronizes Bucket entities with configs fetched from luci-config.""" |
| 152 config_map = config.get_project_configs( | 153 config_map = config.get_project_configs( |
| 153 cfg_path(), project_config_pb2.BuildbucketCfg) | 154 cfg_path(), project_config_pb2.BuildbucketCfg) |
| 154 | 155 |
| 155 buckets_of_project = { | 156 buckets_of_project = { |
| 156 pid: set(b.name for b in pcfg.buckets) | 157 pid: set(b.name for b in pcfg.buckets) |
| 157 for pid, (_, pcfg) in config_map.iteritems() | 158 for pid, (_, pcfg) in config_map.iteritems() |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 config_url = config.get_config_set_location('projects/%s' % project_id) | 223 config_url = config.get_config_set_location('projects/%s' % project_id) |
| 223 if config_url is None: # pragma: no cover | 224 if config_url is None: # pragma: no cover |
| 224 return None | 225 return None |
| 225 try: | 226 try: |
| 226 loc = gitiles.Location.parse(config_url) | 227 loc = gitiles.Location.parse(config_url) |
| 227 except ValueError: # pragma: no cover | 228 except ValueError: # pragma: no cover |
| 228 logging.exception( | 229 logging.exception( |
| 229 'Not a valid Gitiles URL %r of project %s', config_url, project_id) | 230 'Not a valid Gitiles URL %r of project %s', config_url, project_id) |
| 230 return None | 231 return None |
| 231 return str(loc.join(cfg_path())) | 232 return str(loc.join(cfg_path())) |
| OLD | NEW |