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

Unified Diff: appengine/swarming/handlers_endpoints.py

Issue 2661173004: Make deleted bots still show up when searched for by id (Closed)
Patch Set: Address comments Created 3 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/swarming/handlers_endpoints_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/handlers_endpoints.py
diff --git a/appengine/swarming/handlers_endpoints.py b/appengine/swarming/handlers_endpoints.py
index 629d4a1198484ea9dcbf946e9c4cbb5c82c250df..fda8571aaa1b4f5e477902c6e09846b60aa63781 100644
--- a/appengine/swarming/handlers_endpoints.py
+++ b/appengine/swarming/handlers_endpoints.py
@@ -555,8 +555,35 @@ class SwarmingBotService(remote.Service):
task.
"""
logging.info('%s', request)
- bot = get_or_raise(bot_management.get_info_key(request.bot_id))
- return message_conversion.bot_info_to_rpc(bot, utils.utcnow())
+ bot_id = request.bot_id
+ bot = bot_management.get_info_key(bot_id).get()
+ deleted = False
+ if not bot:
+ # If there is not BotInfo, look if there are BotEvent child of this
+ # entity. If this is the case, it means the bot was deleted but it's
+ # useful to show information about it to the user even if the bot was
+ # deleted. For example, it could be an machine-provider bot.
+ events = bot_management.get_events_query(bot_id, True).fetch(1)
+ if not events:
+ raise endpoints.NotFoundException('%s not found.' % bot_id)
+ bot = bot_management.BotInfo(
+ key=bot_management.get_info_key(bot_id),
+ dimensions_flat=bot_management.dimensions_to_flat(
+ events[0].dimensions),
+ state=events[0].state,
+ external_ip=events[0].external_ip,
+ authenticated_as=events[0].authenticated_as,
+ version=events[0].version,
+ quarantined=events[0].quarantined,
+ task_id=events[0].task_id,
+ last_seen_ts=events[0].ts,
+ lease_id=events[0].lease_id,
+ lease_expiration_ts=events[0].lease_expiration_ts,
+ machine_type=events[0].machine_type)
+ deleted = True
+
+ return message_conversion.bot_info_to_rpc(bot, utils.utcnow(),
+ deleted=deleted)
@gae_ts_mon.instrument_endpoint()
@auth.endpoints_method(
« no previous file with comments | « no previous file | appengine/swarming/handlers_endpoints_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698