Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | 1 # Copyright 2014 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 backend handlers.""" | 5 """Main entry point for Swarming backend handlers.""" |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 | 9 |
| 10 import webapp2 | 10 import webapp2 |
| 11 from google.appengine.api import app_identity | 11 from google.appengine.api import app_identity |
| 12 from google.appengine.api import datastore_errors | 12 from google.appengine.api import datastore_errors |
| 13 from google.appengine.api import taskqueue | 13 from google.appengine.api import taskqueue |
| 14 | 14 |
| 15 import mapreduce_jobs | 15 import mapreduce_jobs |
| 16 from components import decorators | 16 from components import decorators |
| 17 from components import machine_provider | 17 from components import machine_provider |
| 18 from server import bot_management | |
| 18 from server import config | 19 from server import config |
| 19 from server import lease_management | 20 from server import lease_management |
| 20 from server import stats | 21 from server import stats |
| 21 from server import task_scheduler | 22 from server import task_scheduler |
| 22 | 23 |
| 23 | 24 |
| 24 class CronBotDiedHandler(webapp2.RequestHandler): | 25 class CronBotDiedHandler(webapp2.RequestHandler): |
| 25 @decorators.require_cronjob | 26 @decorators.require_cronjob |
| 26 def get(self): | 27 def get(self): |
| 27 try: | 28 try: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 91 |
| 91 @decorators.require_cronjob | 92 @decorators.require_cronjob |
| 92 def get(self): | 93 def get(self): |
| 93 if not config.settings().mp.enabled: | 94 if not config.settings().mp.enabled: |
| 94 logging.info('MP support is disabled') | 95 logging.info('MP support is disabled') |
| 95 return | 96 return |
| 96 | 97 |
| 97 lease_management.clean_up_bots() | 98 lease_management.clean_up_bots() |
| 98 | 99 |
| 99 | 100 |
| 101 class CronBotDimensionAggregationHandler(webapp2.RequestHandler): | |
| 102 """Aggregate all bot dimensions (except id) in the fleet.""" | |
|
M-A Ruel
2016/08/05 14:36:05
Aggregates
bots
kjlubick
2016/08/05 17:38:58
Done.
| |
| 103 | |
| 104 @decorators.require_cronjob | |
| 105 def get(self): | |
| 106 seen = {} | |
|
M-A Ruel
2016/08/05 14:36:04
add:
now = utils.utcnow()
kjlubick
2016/08/05 17:38:58
Done.
| |
| 107 for b in bot_management.BotInfo.query(): | |
| 108 for i in b.dimensions_flat: | |
| 109 k, v = i.split(':', 1) | |
| 110 if k == 'id': | |
|
M-A Ruel
2016/08/05 14:36:04
if k != 'id':
seen.setdefault(k, set()).add(v)
kjlubick
2016/08/05 17:38:57
Done. The electrons spared rejoiced.
| |
| 111 continue | |
| 112 seen.setdefault(k, set()).add(v) | |
| 113 dims = [] | |
| 114 for k, values in sorted(seen.iteritems()): | |
| 115 dims.append(bot_management.DimensionValues( | |
| 116 dimension=k, | |
| 117 values=sorted(list(values)))) | |
| 118 logging.info('Saw dimensions %s', dims) | |
| 119 aggregate = bot_management.DimensionAggregation( | |
| 120 id='current', | |
| 121 dimensions=dims) | |
|
M-A Ruel
2016/08/05 14:36:04
and save ts=now here so it's at when the query sta
kjlubick
2016/08/05 17:38:58
Done.
| |
| 122 aggregate.put() | |
| 123 | |
| 124 | |
| 100 class CronMachineProviderPubSubHandler(webapp2.RequestHandler): | 125 class CronMachineProviderPubSubHandler(webapp2.RequestHandler): |
| 101 """Listens for Pub/Sub communication from Machine Provider.""" | 126 """Listens for Pub/Sub communication from Machine Provider.""" |
| 102 | 127 |
| 103 @decorators.require_cronjob | 128 @decorators.require_cronjob |
| 104 def get(self): | 129 def get(self): |
| 105 if not config.settings().mp.enabled: | 130 if not config.settings().mp.enabled: |
| 106 logging.info('MP support is disabled') | 131 logging.info('MP support is disabled') |
| 107 return | 132 return |
| 108 | 133 |
| 109 taskqueue.add( | 134 taskqueue.add( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 # Cron jobs. | 188 # Cron jobs. |
| 164 # TODO(maruel): Rename cron.yaml job url. Doing so is a bit annoying since | 189 # TODO(maruel): Rename cron.yaml job url. Doing so is a bit annoying since |
| 165 # the app version has to be running an already compatible version already. | 190 # the app version has to be running an already compatible version already. |
| 166 ('/internal/cron/abort_bot_died', CronBotDiedHandler), | 191 ('/internal/cron/abort_bot_died', CronBotDiedHandler), |
| 167 ('/internal/cron/handle_bot_died', CronBotDiedHandler), | 192 ('/internal/cron/handle_bot_died', CronBotDiedHandler), |
| 168 ('/internal/cron/abort_expired_task_to_run', | 193 ('/internal/cron/abort_expired_task_to_run', |
| 169 CronAbortExpiredShardToRunHandler), | 194 CronAbortExpiredShardToRunHandler), |
| 170 | 195 |
| 171 ('/internal/cron/stats/update', stats.InternalStatsUpdateHandler), | 196 ('/internal/cron/stats/update', stats.InternalStatsUpdateHandler), |
| 172 ('/internal/cron/trigger_cleanup_data', CronTriggerCleanupDataHandler), | 197 ('/internal/cron/trigger_cleanup_data', CronTriggerCleanupDataHandler), |
| 198 ('/internal/cron/aggregate_bot_dimensions', | |
| 199 CronBotDimensionAggregationHandler), | |
| 173 ('/internal/cron/machine_provider', CronMachineProviderBotHandler), | 200 ('/internal/cron/machine_provider', CronMachineProviderBotHandler), |
| 174 ('/internal/cron/machine_provider_cleanup', | 201 ('/internal/cron/machine_provider_cleanup', |
| 175 CronMachineProviderCleanUpHandler), | 202 CronMachineProviderCleanUpHandler), |
| 176 ('/internal/cron/machine_provider_pubsub', | 203 ('/internal/cron/machine_provider_pubsub', |
| 177 CronMachineProviderPubSubHandler), | 204 CronMachineProviderPubSubHandler), |
| 178 | 205 |
| 179 # Task queues. | 206 # Task queues. |
| 180 ('/internal/taskqueue/cleanup_data', TaskCleanupDataHandler), | 207 ('/internal/taskqueue/cleanup_data', TaskCleanupDataHandler), |
| 181 (r'/internal/taskqueue/pubsub/<task_id:[0-9a-f]+>', TaskSendPubSubMessage), | 208 (r'/internal/taskqueue/pubsub/<task_id:[0-9a-f]+>', TaskSendPubSubMessage), |
| 182 ('/internal/taskqueue/pubsub/machine_provider', | 209 ('/internal/taskqueue/pubsub/machine_provider', |
| 183 TaskMachineProviderPubSubHandler), | 210 TaskMachineProviderPubSubHandler), |
| 184 | 211 |
| 185 # Mapreduce related urls. | 212 # Mapreduce related urls. |
| 186 (r'/internal/taskqueue/mapreduce/launch/<job_id:[^\/]+>', | 213 (r'/internal/taskqueue/mapreduce/launch/<job_id:[^\/]+>', |
| 187 InternalLaunchMapReduceJobWorkerHandler), | 214 InternalLaunchMapReduceJobWorkerHandler), |
| 188 ] | 215 ] |
| 189 return [webapp2.Route(*a) for a in routes] | 216 return [webapp2.Route(*a) for a in routes] |
| OLD | NEW |