| OLD | NEW |
| 1 # Copyright 2015 The Swarming Authors. All rights reserved. | 1 # Copyright 2015 The Swarming 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 textwrap | 10 import textwrap |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 quarantined. | 149 quarantined. |
| 150 | 150 |
| 151 Does one DB synchronous GET. | 151 Does one DB synchronous GET. |
| 152 | 152 |
| 153 Returns: | 153 Returns: |
| 154 tuple(request, bot_id, version, state, dimensions, quarantined_msg) | 154 tuple(request, bot_id, version, state, dimensions, quarantined_msg) |
| 155 """ | 155 """ |
| 156 request = self.parse_body() | 156 request = self.parse_body() |
| 157 version = request.get('version', None) | 157 version = request.get('version', None) |
| 158 | 158 |
| 159 dimensions = request.get('dimensions', {}) | 159 dimensions = request.get('dimensions') or {} |
| 160 state = request.get('state', {}) | 160 state = request.get('state') or {} |
| 161 bot_id = None | 161 bot_id = None |
| 162 if dimensions.get('id'): | 162 if dimensions.get('id'): |
| 163 dimension_id = dimensions['id'] | 163 dimension_id = dimensions['id'] |
| 164 if (isinstance(dimension_id, list) and len(dimension_id) == 1 | 164 if (isinstance(dimension_id, list) and len(dimension_id) == 1 |
| 165 and isinstance(dimension_id[0], unicode)): | 165 and isinstance(dimension_id[0], unicode)): |
| 166 bot_id = dimensions['id'][0] | 166 bot_id = dimensions['id'][0] |
| 167 | 167 |
| 168 # The bot may decide to "self-quarantine" itself. Accept both via | 168 # The bot may decide to "self-quarantine" itself. Accept both via |
| 169 # dimensions or via state. See bot_management._BotCommon.quarantined for | 169 # dimensions or via state. See bot_management._BotCommon.quarantined for |
| 170 # more details. | 170 # more details. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 182 break | 182 break |
| 183 | 183 |
| 184 quarantined_msg = has_missing_keys( | 184 quarantined_msg = has_missing_keys( |
| 185 self.REQUIRED_STATE_KEYS, state, 'state') | 185 self.REQUIRED_STATE_KEYS, state, 'state') |
| 186 if quarantined_msg: | 186 if quarantined_msg: |
| 187 break | 187 break |
| 188 | 188 |
| 189 if not bot_id: | 189 if not bot_id: |
| 190 quarantined_msg = 'Missing bot id' | 190 quarantined_msg = 'Missing bot id' |
| 191 break | 191 break |
| 192 if not dimensions.get('pool'): |
| 193 quarantined_msg = 'Missing \'pool\' dimension' |
| 194 break |
| 192 | 195 |
| 193 if not all( | 196 if not all( |
| 194 isinstance(key, unicode) and | 197 isinstance(key, unicode) and |
| 195 isinstance(values, list) and | 198 isinstance(values, list) and |
| 196 all(isinstance(value, unicode) for value in values) | 199 all(isinstance(value, unicode) for value in values) |
| 197 for key, values in dimensions.iteritems()): | 200 for key, values in dimensions.iteritems()): |
| 198 quarantined_msg = ( | 201 quarantined_msg = ( |
| 199 'Invalid dimensions type:\n%s' % json.dumps(dimensions, | 202 'Invalid dimensions type:\n%s' % json.dumps(dimensions, |
| 200 sort_keys=True, indent=2, separators=(',', ': '))) | 203 sort_keys=True, indent=2, separators=(',', ': '))) |
| 201 break | 204 break |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 ('/swarming/api/v1/bot/poll', BotPollHandler), | 611 ('/swarming/api/v1/bot/poll', BotPollHandler), |
| 609 ('/swarming/api/v1/bot/server_ping', ServerPingHandler), | 612 ('/swarming/api/v1/bot/server_ping', ServerPingHandler), |
| 610 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler), | 613 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler), |
| 611 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>', | 614 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>', |
| 612 BotTaskUpdateHandler), | 615 BotTaskUpdateHandler), |
| 613 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler), | 616 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler), |
| 614 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>', | 617 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>', |
| 615 BotTaskErrorHandler), | 618 BotTaskErrorHandler), |
| 616 ] | 619 ] |
| 617 return [webapp2.Route(*i) for i in routes] | 620 return [webapp2.Route(*i) for i in routes] |
| OLD | NEW |