Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 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 google.appengine.ext import ndb | |
| 6 from protorpc import messages | |
| 7 from protorpc import message_types | |
| 8 from protorpc import remote | |
| 9 | |
| 10 from components import auth | |
| 11 from components import utils | |
| 12 import gae_ts_mon | |
| 13 | |
| 14 import acl | |
| 15 import config | |
| 16 | |
| 17 | |
| 18 def swarmbucket_api_method( | |
| 19 request_message_class, response_message_class, **kwargs): | |
| 20 """Defines a swarmbucket API method.""" | |
| 21 | |
| 22 endpoints_decorator = auth.endpoints_method( | |
| 23 request_message_class, response_message_class, **kwargs) | |
| 24 | |
| 25 def decorator(fn): | |
| 26 fn = auth.public(fn) | |
| 27 fn = endpoints_decorator(fn) | |
| 28 fn = ndb.toplevel(fn) | |
| 29 def ts_mon_time(): | |
| 30 return utils.datetime_to_timestamp(utils.utcnow()) / 1000000.0 | |
| 31 fn = gae_ts_mon.instrument_endpoint(time_fn=ts_mon_time)(fn) | |
| 32 return fn | |
| 33 | |
| 34 return decorator | |
| 35 | |
| 36 | |
| 37 class BuilderMessage(messages.Message): | |
| 38 name = messages.StringField(1) | |
| 39 category = messages.StringField(2) | |
| 40 | |
| 41 | |
| 42 class BucketMessage(messages.Message): | |
| 43 # Bucket name. Unique per buildbucket instance. | |
| 44 name = messages.StringField(1) | |
| 45 builders = messages.MessageField(BuilderMessage, 2, repeated=True) | |
| 46 | |
| 47 | |
| 48 class GetBuildersResponseMessage(messages.Message): | |
| 49 buckets = messages.MessageField(BucketMessage, 1, repeated=True) | |
| 50 | |
| 51 | |
| 52 @auth.endpoints_api( | |
| 53 name='swarmbucket', version='v1', | |
| 54 title='Buildbucket-Swarming integration') | |
| 55 class SwarmbucketApi(remote.Service): | |
| 56 """API specific to swarmbucket.""" | |
| 57 | |
| 58 @swarmbucket_api_method( | |
| 59 message_types.VoidMessage, | |
| 60 GetBuildersResponseMessage, | |
| 61 path='builders', http_method='GET') | |
| 62 def get_builders(self, _request): | |
|
Vadim Sh.
2016/05/24 19:22:59
no arguments? How would we support different proje
nodir
2016/05/24 19:36:54
I added "bucket" parameter initially, and then del
| |
| 63 """Returns defined swarmbucket builders. | |
| 64 | |
| 65 Can be used by code review tool to discover builders. | |
| 66 """ | |
| 67 buckets = config.get_buckets_async().get_result() | |
| 68 available = acl.get_available_buckets() | |
| 69 if available is not None: | |
| 70 available = set(available) | |
| 71 buckets = [b for b in buckets if b.name in available] | |
| 72 | |
| 73 res = GetBuildersResponseMessage() | |
| 74 for bucket in buckets: | |
| 75 if not bucket.swarming or not bucket.swarming.builders: | |
| 76 continue | |
| 77 res.buckets.append(BucketMessage( | |
| 78 name=bucket.name, | |
| 79 builders=[ | |
| 80 BuilderMessage( | |
| 81 name=builder.name, | |
| 82 category=builder.category, | |
| 83 ) | |
| 84 for builder in bucket.swarming.builders | |
| 85 ], | |
| 86 )) | |
| 87 return res | |
| OLD | NEW |