| 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 by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Internal bot API handlers.""" | 5 """Internal bot API handlers.""" |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import re | 10 import re |
| 11 import textwrap | 11 import textwrap |
| 12 | 12 |
| 13 import webob | 13 import webob |
| 14 import webapp2 | 14 import webapp2 |
| 15 | 15 |
| 16 from google.appengine.api import app_identity | 16 from google.appengine.api import app_identity |
| 17 from google.appengine.api import datastore_errors | 17 from google.appengine.api import datastore_errors |
| 18 from google.appengine.datastore import datastore_query | 18 from google.appengine.datastore import datastore_query |
| 19 from google.appengine import runtime | 19 from google.appengine import runtime |
| 20 from google.appengine.ext import ndb | 20 from google.appengine.ext import ndb |
| 21 | 21 |
| 22 from components import auth | 22 from components import auth |
| 23 from components import ereporter2 | 23 from components import ereporter2 |
| 24 from components import utils | 24 from components import utils |
| 25 from proto import config_pb2 |
| 25 from server import acl | 26 from server import acl |
| 26 from server import bot_code | 27 from server import bot_code |
| 27 from server import bot_management | 28 from server import bot_management |
| 28 from server import stats | 29 from server import stats |
| 29 from server import task_pack | 30 from server import task_pack |
| 30 from server import task_request | 31 from server import task_request |
| 31 from server import task_result | 32 from server import task_result |
| 32 from server import task_scheduler | 33 from server import task_scheduler |
| 33 from server import task_to_run | 34 from server import task_to_run |
| 34 | 35 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 # TODO(maruel): Note the task if possible and hand it out on next poll. | 373 # TODO(maruel): Note the task if possible and hand it out on next poll. |
| 373 # https://code.google.com/p/swarming/issues/detail?id=130 | 374 # https://code.google.com/p/swarming/issues/detail?id=130 |
| 374 self.abort(500, 'Deadline') | 375 self.abort(500, 'Deadline') |
| 375 | 376 |
| 376 def _cmd_run(self, request, run_result_key, bot_id): | 377 def _cmd_run(self, request, run_result_key, bot_id): |
| 377 cmd = None | 378 cmd = None |
| 378 if request.properties.commands: | 379 if request.properties.commands: |
| 379 cmd = request.properties.commands[0] | 380 cmd = request.properties.commands[0] |
| 380 elif request.properties.command: | 381 elif request.properties.command: |
| 381 cmd = request.properties.command | 382 cmd = request.properties.command |
| 383 |
| 384 cipd_settings = None |
| 385 if request.properties.cipd_input: |
| 386 cipd_settings = config_pb2.CipdSettings() |
| 387 cipd_settings.MergeFromString(request.properties.cipd_input.settings) |
| 388 |
| 382 out = { | 389 out = { |
| 383 'cmd': 'run', | 390 'cmd': 'run', |
| 384 'manifest': { | 391 'manifest': { |
| 385 'bot_id': bot_id, | 392 'bot_id': bot_id, |
| 393 'cipd_input': { |
| 394 'packages': [ |
| 395 { |
| 396 'package_name': p.package_name, |
| 397 'version': p.version, |
| 398 } |
| 399 for p in request.properties.cipd_input.packages |
| 400 ], |
| 401 'settings': { |
| 402 'server_host': cipd_settings.server_host, |
| 403 'client_package_name': cipd_settings.client_package_name, |
| 404 'client_package_version': cipd_settings.client_package_version, |
| 405 }, |
| 406 } if request.properties.cipd_input else None, |
| 386 'command': cmd, | 407 'command': cmd, |
| 387 'dimensions': request.properties.dimensions, | 408 'dimensions': request.properties.dimensions, |
| 388 'env': request.properties.env, | 409 'env': request.properties.env, |
| 389 'extra_args': request.properties.extra_args, | 410 'extra_args': request.properties.extra_args, |
| 390 'grace_period': request.properties.grace_period_secs, | 411 'grace_period': request.properties.grace_period_secs, |
| 391 'hard_timeout': request.properties.execution_timeout_secs, | 412 'hard_timeout': request.properties.execution_timeout_secs, |
| 392 'host': utils.get_versioned_hosturl(), | 413 'host': utils.get_versioned_hosturl(), |
| 393 'io_timeout': request.properties.io_timeout_secs, | 414 'io_timeout': request.properties.io_timeout_secs, |
| 394 'isolated': { | 415 'isolated': { |
| 395 'input': request.properties.inputs_ref.isolated, | 416 'input': request.properties.inputs_ref.isolated, |
| 417 'namespace': request.properties.inputs_ref.namespace, |
| 396 'server': request.properties.inputs_ref.isolatedserver, | 418 'server': request.properties.inputs_ref.isolatedserver, |
| 397 'namespace': request.properties.inputs_ref.namespace, | |
| 398 } if request.properties.inputs_ref else None, | 419 } if request.properties.inputs_ref else None, |
| 399 'packages': [ | |
| 400 { | |
| 401 'package_name': p.package_name, | |
| 402 'version': p.version, | |
| 403 } | |
| 404 for p in request.properties.packages | |
| 405 ], | |
| 406 'task_id': task_pack.pack_run_result_key(run_result_key), | 420 'task_id': task_pack.pack_run_result_key(run_result_key), |
| 407 }, | 421 }, |
| 408 } | 422 } |
| 409 self.send_response(utils.to_json_encodable(out)) | 423 self.send_response(utils.to_json_encodable(out)) |
| 410 | 424 |
| 411 def _cmd_sleep(self, sleep_streak, quarantined): | 425 def _cmd_sleep(self, sleep_streak, quarantined): |
| 412 out = { | 426 out = { |
| 413 'cmd': 'sleep', | 427 'cmd': 'sleep', |
| 414 'duration': task_scheduler.exponential_backoff(sleep_streak), | 428 'duration': task_scheduler.exponential_backoff(sleep_streak), |
| 415 'quarantined': quarantined, | 429 'quarantined': quarantined, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 ('/swarming/api/v1/bot/poll', BotPollHandler), | 689 ('/swarming/api/v1/bot/poll', BotPollHandler), |
| 676 ('/swarming/api/v1/bot/server_ping', ServerPingHandler), | 690 ('/swarming/api/v1/bot/server_ping', ServerPingHandler), |
| 677 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler), | 691 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler), |
| 678 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>', | 692 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>', |
| 679 BotTaskUpdateHandler), | 693 BotTaskUpdateHandler), |
| 680 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler), | 694 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler), |
| 681 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>', | 695 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>', |
| 682 BotTaskErrorHandler), | 696 BotTaskErrorHandler), |
| 683 ] | 697 ] |
| 684 return [webapp2.Route(*i) for i in routes] | 698 return [webapp2.Route(*i) for i in routes] |
| OLD | NEW |