OLD | NEW |
1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 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 """This module facilitates conversion from dictionaries to ProtoRPC messages. | 5 """This module facilitates conversion from dictionaries to ProtoRPC messages. |
6 | 6 |
7 Given a dictionary whose keys' names and values' types comport with the | 7 Given a dictionary whose keys' names and values' types comport with the |
8 fields defined for a protorpc.messages.Message subclass, this module tries to | 8 fields defined for a protorpc.messages.Message subclass, this module tries to |
9 generate a Message instance that corresponds to the provided dictionary. The | 9 generate a Message instance that corresponds to the provided dictionary. The |
10 "normal" use case is for ndb.Models which need to be represented as a | 10 "normal" use case is for ndb.Models which need to be represented as a |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 return utils.timestamp_to_datetime(value*1000000.) | 69 return utils.timestamp_to_datetime(value*1000000.) |
70 except OverflowError as e: | 70 except OverflowError as e: |
71 raise ValueError(e) | 71 raise ValueError(e) |
72 | 72 |
73 | 73 |
74 def bot_info_to_rpc(entity, now, deleted=False): | 74 def bot_info_to_rpc(entity, now, deleted=False): |
75 """"Returns a swarming_rpcs.BotInfo from a bot.BotInfo.""" | 75 """"Returns a swarming_rpcs.BotInfo from a bot.BotInfo.""" |
76 return _ndb_to_rpc( | 76 return _ndb_to_rpc( |
77 swarming_rpcs.BotInfo, | 77 swarming_rpcs.BotInfo, |
78 entity, | 78 entity, |
| 79 bot_id=entity.id, |
| 80 deleted=deleted, |
79 dimensions=_string_list_pairs_from_dict(entity.dimensions), | 81 dimensions=_string_list_pairs_from_dict(entity.dimensions), |
80 is_dead=entity.is_dead(now), | 82 is_dead=entity.is_dead(now), |
81 bot_id=entity.id, | 83 machine_type=entity.machine_type, |
82 deleted=deleted, | |
83 state=json.dumps(entity.state, sort_keys=True, separators=(',', ':'))) | 84 state=json.dumps(entity.state, sort_keys=True, separators=(',', ':'))) |
84 | 85 |
85 | 86 |
86 def bot_event_to_rpc(entity): | 87 def bot_event_to_rpc(entity): |
87 """"Returns a swarming_rpcs.BotEvent from a bot.BotEvent.""" | 88 """"Returns a swarming_rpcs.BotEvent from a bot.BotEvent.""" |
88 return _ndb_to_rpc( | 89 return _ndb_to_rpc( |
89 swarming_rpcs.BotEvent, | 90 swarming_rpcs.BotEvent, |
90 entity, | 91 entity, |
91 dimensions=_string_list_pairs_from_dict(entity.dimensions), | 92 dimensions=_string_list_pairs_from_dict(entity.dimensions), |
92 state=json.dumps(entity.state, sort_keys=True, separators=(',', ':')), | 93 state=json.dumps(entity.state, sort_keys=True, separators=(',', ':')), |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 kwargs['run_id'] = entity.task_id | 259 kwargs['run_id'] = entity.task_id |
259 else: | 260 else: |
260 assert entity.__class__ is task_result.TaskResultSummary, entity | 261 assert entity.__class__ is task_result.TaskResultSummary, entity |
261 kwargs['properties_hash'] = ( | 262 kwargs['properties_hash'] = ( |
262 entity.properties_hash.encode('hex') | 263 entity.properties_hash.encode('hex') |
263 if entity.properties_hash else None) | 264 if entity.properties_hash else None) |
264 # This returns the right value for deduped tasks too. | 265 # This returns the right value for deduped tasks too. |
265 k = entity.run_result_key | 266 k = entity.run_result_key |
266 kwargs['run_id'] = task_pack.pack_run_result_key(k) if k else None | 267 kwargs['run_id'] = task_pack.pack_run_result_key(k) if k else None |
267 return _ndb_to_rpc(swarming_rpcs.TaskResult, entity, **kwargs) | 268 return _ndb_to_rpc(swarming_rpcs.TaskResult, entity, **kwargs) |
OLD | NEW |