| 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 defines Swarming Server endpoints handlers.""" | 5 """This module defines Swarming Server endpoints handlers.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 | 9 |
| 10 from google.appengine.api import datastore_errors | 10 from google.appengine.api import datastore_errors |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 path='{bot_id}/get', | 548 path='{bot_id}/get', |
| 549 http_method='GET') | 549 http_method='GET') |
| 550 @auth.require(acl.is_privileged_user) | 550 @auth.require(acl.is_privileged_user) |
| 551 def get(self, request): | 551 def get(self, request): |
| 552 """Returns information about a known bot. | 552 """Returns information about a known bot. |
| 553 | 553 |
| 554 This includes its state and dimensions, and if it is currently running a | 554 This includes its state and dimensions, and if it is currently running a |
| 555 task. | 555 task. |
| 556 """ | 556 """ |
| 557 logging.info('%s', request) | 557 logging.info('%s', request) |
| 558 bot = get_or_raise(bot_management.get_info_key(request.bot_id)) | 558 bot_id = request.bot_id |
| 559 return message_conversion.bot_info_to_rpc(bot, utils.utcnow()) | 559 bot = bot_management.get_info_key(bot_id).get() |
| 560 deleted = False |
| 561 if not bot: |
| 562 # If there is not BotInfo, look if there are BotEvent child of this |
| 563 # entity. If this is the case, it means the bot was deleted but it's |
| 564 # useful to show information about it to the user even if the bot was |
| 565 # deleted. For example, it could be an machine-provider bot. |
| 566 events = bot_management.get_events_query(bot_id, True).fetch(1) |
| 567 if not events: |
| 568 raise endpoints.NotFoundException('%s not found.' % bot_id) |
| 569 bot = bot_management.BotInfo( |
| 570 key=bot_management.get_info_key(bot_id), |
| 571 dimensions_flat=bot_management.dimensions_to_flat( |
| 572 events[0].dimensions), |
| 573 state=events[0].state, |
| 574 external_ip=events[0].external_ip, |
| 575 authenticated_as=events[0].authenticated_as, |
| 576 version=events[0].version, |
| 577 quarantined=events[0].quarantined, |
| 578 task_id=events[0].task_id, |
| 579 last_seen_ts=events[0].ts, |
| 580 lease_id=events[0].lease_id, |
| 581 lease_expiration_ts=events[0].lease_expiration_ts, |
| 582 machine_type=events[0].machine_type) |
| 583 deleted = True |
| 584 |
| 585 return message_conversion.bot_info_to_rpc(bot, utils.utcnow(), |
| 586 deleted=deleted) |
| 560 | 587 |
| 561 @gae_ts_mon.instrument_endpoint() | 588 @gae_ts_mon.instrument_endpoint() |
| 562 @auth.endpoints_method( | 589 @auth.endpoints_method( |
| 563 BotId, swarming_rpcs.DeletedResponse, | 590 BotId, swarming_rpcs.DeletedResponse, |
| 564 name='delete', | 591 name='delete', |
| 565 path='{bot_id}/delete') | 592 path='{bot_id}/delete') |
| 566 @auth.require(acl.is_admin) | 593 @auth.require(acl.is_admin) |
| 567 def delete(self, request): | 594 def delete(self, request): |
| 568 """Deletes the bot corresponding to a provided bot_id. | 595 """Deletes the bot corresponding to a provided bot_id. |
| 569 | 596 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 def get_routes(): | 800 def get_routes(): |
| 774 return ( | 801 return ( |
| 775 endpoints_webapp2.api_routes(SwarmingServerService) + | 802 endpoints_webapp2.api_routes(SwarmingServerService) + |
| 776 endpoints_webapp2.api_routes(SwarmingTaskService) + | 803 endpoints_webapp2.api_routes(SwarmingTaskService) + |
| 777 endpoints_webapp2.api_routes(SwarmingTasksService) + | 804 endpoints_webapp2.api_routes(SwarmingTasksService) + |
| 778 endpoints_webapp2.api_routes(SwarmingBotService) + | 805 endpoints_webapp2.api_routes(SwarmingBotService) + |
| 779 endpoints_webapp2.api_routes(SwarmingBotsService) + | 806 endpoints_webapp2.api_routes(SwarmingBotsService) + |
| 780 # components.config endpoints for validation and configuring of luci-config | 807 # components.config endpoints for validation and configuring of luci-config |
| 781 # service URL. | 808 # service URL. |
| 782 endpoints_webapp2.api_routes(config.ConfigApi)) | 809 endpoints_webapp2.api_routes(config.ConfigApi)) |
| OLD | NEW |