Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 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 """Main entry point for Swarming service. | 5 """Main entry point for Swarming service. |
| 6 | 6 |
| 7 This file contains the URL handlers for all the Swarming service URLs, | 7 This file contains the URL handlers for all the Swarming service URLs, |
| 8 implemented using the webapp2 framework. | 8 implemented using the webapp2 framework. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 if not request or not result: | 609 if not request or not result: |
| 610 self.abort(404, '%s not found.' % key.id()) | 610 self.abort(404, '%s not found.' % key.id()) |
| 611 if not request.has_access: | 611 if not request.has_access: |
| 612 self.abort(403, '%s is not accessible.' % key.id()) | 612 self.abort(403, '%s is not accessible.' % key.id()) |
| 613 return request, result | 613 return request, result |
| 614 | 614 |
| 615 | 615 |
| 616 class TaskHandler(BaseTaskHandler): | 616 class TaskHandler(BaseTaskHandler): |
| 617 """Show the full text of a task request and its result.""" | 617 """Show the full text of a task request and its result.""" |
| 618 | 618 |
| 619 class PinInfo(object): | |
| 620 def __init__(self, pkg, pin): | |
| 621 assert pin is None or pkg.path == pin.path | |
| 622 self.pkg = pkg | |
| 623 self.pin = pin | |
| 624 | |
| 625 | |
| 626 @staticmethod | |
| 627 def pininfos_grouped_by_path(inputs, outputs): | |
| 628 """Returns sorted [(path, [PinInfo, ...])]. | |
| 629 | |
| 630 PinInfo is a namedtuple with two fields 'pkg' and 'pin'. 'pkg' is the | |
| 631 CipdPackage that was specified in the task request. 'pin' is the CipdPackage | |
| 632 that was resolved by the bot at runtime, and contains a full package name as | |
| 633 well as a package instance id. | |
| 634 | |
| 635 If pinning information is unavailable pin is None. | |
| 636 | |
| 637 Used by user_task.html. | |
| 638 """ | |
| 639 packages = inputs.packages | |
| 640 pins = None | |
| 641 if outputs: | |
| 642 pins = outputs.packages | |
|
M-A Ruel
2016/08/26 23:19:51
this code assumes the order is the same but this w
iannucci
2016/08/29 22:08:40
sgtm, I considered this, but thought you might pre
| |
| 643 | |
| 644 assert pins is None or len(pins) == len(packages) | |
|
M-A Ruel
2016/08/26 23:19:51
This assert should be done at the time the entity
iannucci
2016/08/29 22:08:40
yep, done
| |
| 645 pinned = pins is not None | |
| 646 | |
| 647 retval = collections.defaultdict(list) | |
| 648 for i, pkg in enumerate(packages): | |
| 649 retval[pkg.path].append(TaskHandler.PinInfo( | |
| 650 pkg, pins[i] if pinned else None)) | |
| 651 for pkgs in retval.itervalues(): | |
| 652 pkgs.sort() | |
|
M-A Ruel
2016/08/26 23:19:51
see comment in task_request.py
| |
| 653 return sorted(retval.iteritems()) | |
| 654 | |
| 619 @auth.autologin | 655 @auth.autologin |
| 620 @auth.require(acl.is_user) | 656 @auth.require(acl.is_user) |
| 621 def get(self, task_id): | 657 def get(self, task_id): |
| 622 request, result = self.get_request_and_result(task_id) | 658 request, result = self.get_request_and_result(task_id) |
| 623 parent_task_future = None | 659 parent_task_future = None |
| 624 if request.parent_task_id: | 660 if request.parent_task_id: |
| 625 parent_key = task_pack.unpack_run_result_key(request.parent_task_id) | 661 parent_key = task_pack.unpack_run_result_key(request.parent_task_id) |
| 626 parent_task_future = parent_key.get_async() | 662 parent_task_future = parent_key.get_async() |
| 627 children_tasks_futures = [ | 663 children_tasks_futures = [ |
| 628 task_pack.unpack_result_summary_key(c).get_async() | 664 task_pack.unpack_result_summary_key(c).get_async() |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 656 | 692 |
| 657 previous_task = None | 693 previous_task = None |
| 658 if previous_task_future: | 694 if previous_task_future: |
| 659 previous_task = previous_task_future.get_result() | 695 previous_task = previous_task_future.get_result() |
| 660 | 696 |
| 661 parent_task = None | 697 parent_task = None |
| 662 if parent_task_future: | 698 if parent_task_future: |
| 663 parent_task = parent_task_future.get_result() | 699 parent_task = parent_task_future.get_result() |
| 664 children_tasks = [c.get_result() for c in children_tasks_futures] | 700 children_tasks = [c.get_result() for c in children_tasks_futures] |
| 665 | 701 |
| 702 cipd = None | |
| 703 cipd_pinned = False | |
| 704 if request.properties.cipd_input: | |
| 705 cipd_pinned = result.cipd_pins is not None | |
|
M-A Ruel
2016/08/26 23:19:51
do one for input, one for pinned without mixing bo
| |
| 706 cipd = { | |
| 707 'server': request.properties.cipd_input.server, | |
| 708 'client_package': TaskHandler.PinInfo( | |
| 709 request.properties.cipd_input.client_package, | |
| 710 result.cipd_pins.client_package if cipd_pinned else None), | |
| 711 'packages': self.pininfos_grouped_by_path(request.properties.cipd_input, | |
| 712 result.cipd_pins), | |
| 713 } | |
| 714 | |
| 666 params = { | 715 params = { |
| 667 'bot': bot_future.get_result() if bot_future else None, | 716 'bot': bot_future.get_result() if bot_future else None, |
| 668 'children_tasks': children_tasks, | 717 'children_tasks': children_tasks, |
| 718 'cipd': cipd, | |
| 719 'cipd_pinned': cipd_pinned, | |
| 669 'is_admin': acl.is_admin(), | 720 'is_admin': acl.is_admin(), |
| 670 'is_gae_admin': users.is_current_user_admin(), | 721 'is_gae_admin': users.is_current_user_admin(), |
| 671 'is_privileged_user': acl.is_privileged_user(), | 722 'is_privileged_user': acl.is_privileged_user(), |
| 672 'following_task': following_task, | 723 'following_task': following_task, |
| 673 'full_appid': os.environ['APPLICATION_ID'], | 724 'full_appid': os.environ['APPLICATION_ID'], |
| 674 'host_url': self.request.host_url, | 725 'host_url': self.request.host_url, |
| 675 'is_running': result.state == task_result.State.RUNNING, | 726 'is_running': result.state == task_result.State.RUNNING, |
| 676 'parent_task': parent_task, | 727 'parent_task': parent_task, |
| 677 'previous_task': previous_task, | 728 'previous_task': previous_task, |
| 678 'request': request, | 729 'request': request, |
| 679 'task': result, | 730 'task': result, |
| 680 'xsrf_token': self.generate_xsrf_token(), | 731 'xsrf_token': self.generate_xsrf_token(), |
| 681 } | 732 } |
| 733 | |
|
M-A Ruel
2016/08/26 23:19:51
remove
| |
| 682 self.response.write(template.render('swarming/user_task.html', params)) | 734 self.response.write(template.render('swarming/user_task.html', params)) |
| 683 | 735 |
| 684 | 736 |
| 685 class TaskCancelHandler(BaseTaskHandler): | 737 class TaskCancelHandler(BaseTaskHandler): |
| 686 """Cancel a task.""" | 738 """Cancel a task.""" |
| 687 | 739 |
| 688 @auth.require(acl.is_user) | 740 @auth.require(acl.is_user) |
| 689 def post(self, task_id): | 741 def post(self, task_id): |
| 690 request, result = self.get_request_and_result(task_id) | 742 request, result = self.get_request_and_result(task_id) |
| 691 if not task_scheduler.cancel_task(request, result.key)[0]: | 743 if not task_scheduler.cancel_task(request, result.key)[0]: |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 | 868 |
| 817 # If running on a local dev server, allow bots to connect without prior | 869 # If running on a local dev server, allow bots to connect without prior |
| 818 # groups configuration. Useful when running smoke test. | 870 # groups configuration. Useful when running smoke test. |
| 819 if utils.is_local_dev_server(): | 871 if utils.is_local_dev_server(): |
| 820 acl.bootstrap_dev_server_acls() | 872 acl.bootstrap_dev_server_acls() |
| 821 | 873 |
| 822 routes.extend(handlers_backend.get_routes()) | 874 routes.extend(handlers_backend.get_routes()) |
| 823 routes.extend(handlers_bot.get_routes()) | 875 routes.extend(handlers_bot.get_routes()) |
| 824 routes.extend(handlers_endpoints.get_routes()) | 876 routes.extend(handlers_endpoints.get_routes()) |
| 825 return webapp2.WSGIApplication(routes, debug=debug) | 877 return webapp2.WSGIApplication(routes, debug=debug) |
| OLD | NEW |