xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 1 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Module containing the constants to be reused throughout suite_scheduler.""" |
| 6 | |
Xixuan Wu | d55ac6e | 2019-03-14 10:56:39 -0700 | [diff] [blame] | 7 | import collections |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 8 | import logging |
| 9 | import os |
| 10 | |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 11 | from google.appengine.api import app_identity |
| 12 | |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 13 | # Namedtuple for storing rest client info. |
Xixuan Wu | d55ac6e | 2019-03-14 10:56:39 -0700 | [diff] [blame] | 14 | RestClientInfo = collections.namedtuple( |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 15 | 'RestClientInfo', 'scopes, service_name, service_version') |
| 16 | |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 17 | # Constants for detecting the running environment. |
| 18 | _RUNNING_ENV = 'SERVER_SOFTWARE' |
| 19 | _ENV_DEVELOPMENT_STR = 'Development' |
| 20 | _ENV_APP_ENGINE_STR = 'Google App Engine/' |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 21 | |
| 22 | |
Xixuan Wu | d55ac6e | 2019-03-14 10:56:39 -0700 | [diff] [blame] | 23 | class StorageBucket(object): |
| 24 | """Constants refer to Google storage bucket.""" |
| 25 | |
| 26 | PROD_SUITE_SCHEDULER = 'suite-scheduler.google.com.a.appspot.com' |
| 27 | |
| 28 | |
Xixuan Wu | 27a61f8 | 2017-09-14 11:42:37 -0700 | [diff] [blame] | 29 | class AppID(object): |
| 30 | """Constants refer to app id.""" |
| 31 | |
| 32 | PROD_APP = 'suite-scheduler' |
| 33 | STAGING_APP = 'suite-scheduler-staging' |
| 34 | |
Xinan Lin | c9f0115 | 2020-02-05 22:05:13 -0800 | [diff] [blame] | 35 | class Metrics(object): |
| 36 | """Constants for uplading analytic metrics.""" |
| 37 | |
| 38 | PROJECT_ID_STAGING = 'google.com:suite-scheduler-staging' |
| 39 | PROJECT_ID = 'google.com:suite-scheduler' |
| 40 | DATASET = 'metrics' |
| 41 | TRIGGER_EVENT_TABLE = 'trigger_events' |
| 42 | EXECUTION_TASK_TABLE = 'execution_tasks' |
Xixuan Wu | 27a61f8 | 2017-09-14 11:42:37 -0700 | [diff] [blame] | 43 | |
Xinan Lin | cd6d40b | 2019-08-09 15:53:43 -0700 | [diff] [blame] | 44 | class Buildbucket(object): |
| 45 | """Constants used when making buildbucket calls.""" |
| 46 | |
| 47 | HOST = 'cr-buildbucket.appspot.com' |
| 48 | PROJECT = 'chromeos' |
| 49 | BUCKET = 'testplatform' |
| 50 | PROD_BUILDER = 'cros_test_platform' |
| 51 | STAGING_BUILDER = 'cros_test_platform-dev' |
| 52 | |
Prathmesh Prabhu | 9adfa63 | 2020-02-21 10:39:24 -0800 | [diff] [blame] | 53 | # Source of truth: |
| 54 | # https://chrome-internal.googlesource.com/chromeos/infra/config/+/8f12edac54383831aaed9ed1819ef909a66ecc97/testplatform/main.star#90 |
Dhanya Ganesh | a4ce38e | 2021-10-26 15:45:47 +0000 | [diff] [blame] | 55 | MAX_BUILDBUCKET_TIMEOUT_MINS = (39*60 + 30) |
Xinan Lin | 3ba18a0 | 2019-08-13 15:44:55 -0700 | [diff] [blame] | 56 | MAX_RETRY = 3 |
| 57 | |
Xinan Lin | 1ec5206 | 2019-12-17 18:41:53 -0800 | [diff] [blame] | 58 | # TODO(crbug.com/1034166): this is a workaround to reduce the child task count |
| 59 | # in swarming. |
| 60 | MULTIREQUEST_SIZE = 25 |
Xinan Lin | cd6d40b | 2019-08-09 15:53:43 -0700 | [diff] [blame] | 61 | |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 62 | |
| 63 | class BaseEvent(object): |
| 64 | """Constants used for base_event.""" |
| 65 | |
| 66 | # The new build may not get inserted to BQ right after they are |
Xinan Lin | 3330d67 | 2020-03-03 14:52:36 -0800 | [diff] [blame] | 67 | # created(crbug/1038729). DELAY_MINUTES delays the period of |
| 68 | # the builds suite scheduler queries, to ensure the most of the target |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 69 | # builds exist in BQ. |
Xinan Lin | 3330d67 | 2020-03-03 14:52:36 -0800 | [diff] [blame] | 70 | DELAY_MINUTES = 30 |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 71 | |
| 72 | |
Xixuan Wu | 27a61f8 | 2017-09-14 11:42:37 -0700 | [diff] [blame] | 73 | class CalendarID(object): |
| 74 | """Constants refer to calendar id.""" |
| 75 | |
| 76 | PROD_NEW_BUILD = ( |
| 77 | 'google.com_8n9gndgp0o642d7ta7dakbiiso@group.calendar.google.com') |
| 78 | PROD_NIGHTLY = ( |
| 79 | 'google.com_e8p3i4pk80lt6snfb57fdgff3g@group.calendar.google.com') |
| 80 | PROD_WEEKLY = ( |
| 81 | 'google.com_9es5a7m1r9til9uf5qc8mpr6p4@group.calendar.google.com') |
| 82 | STAGING_NEW_BUILD = ( |
| 83 | 'google.com_pjlsd9371ic158vdgcacspu0m4@group.calendar.google.com') |
| 84 | STAGING_NIGHTLY = ( |
| 85 | 'google.com_lu3v13kr4if93l9embsvb5llj4@group.calendar.google.com') |
| 86 | STAGING_WEEKLY = ( |
| 87 | 'google.com_9l29i5ncfk24e5aktjr6gaerp8@group.calendar.google.com') |
| 88 | |
| 89 | |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 90 | class RestClient(object): |
| 91 | """Constants related to rest clients to google service.""" |
| 92 | |
| 93 | # client info for connecting to android build API. |
| 94 | ANDROID_BUILD_CLIENT = RestClientInfo._make( |
| 95 | ['https://www.googleapis.com/auth/androidbuild.internal', |
| 96 | 'androidbuildinternal', |
| 97 | 'v2beta1']) |
| 98 | |
| 99 | # client info for connecting to google storage API. |
| 100 | STORAGE_CLIENT = RestClientInfo._make( |
| 101 | ['https://www.googleapis.com/auth/devstorage.full_control', |
| 102 | 'storage', |
| 103 | 'v1']) |
| 104 | |
| 105 | # client info for connecting to google calendar API. |
| 106 | CALENDAR_CLIENT = RestClientInfo._make( |
| 107 | ['https://www.googleapis.com/auth/calendar', |
| 108 | 'calendar', |
| 109 | 'v3']) |
| 110 | |
| 111 | SWARMING_CLIENT = RestClientInfo._make( |
| 112 | ['https://www.googleapis.com/auth/userinfo.email', |
| 113 | 'swarming', |
| 114 | 'v1']) |
| 115 | |
Xixuan Wu | 6f117e9 | 2017-10-27 10:51:58 -0700 | [diff] [blame] | 116 | STACKDRIVER_CLIENT = RestClientInfo._make( |
| 117 | ['https://www.googleapis.com/auth/logging.read', |
| 118 | 'logging', |
| 119 | 'v2']) |
| 120 | |
Xixuan Wu | 7d142a9 | 2019-04-26 12:03:02 -0700 | [diff] [blame] | 121 | BIGQUERY_CLIENT = RestClientInfo._make( |
| 122 | ['https://www.googleapis.com/auth/bigquery', |
| 123 | 'bigquery', |
| 124 | 'v2']) |
| 125 | |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 126 | |
| 127 | class RunningEnv(object): |
| 128 | """Constants related to app engine running environment.""" |
| 129 | |
| 130 | # Running this GAE project locally with python. |
| 131 | ENV_STANDALONE = 0 |
| 132 | |
| 133 | # Running this GAE project with local development server. |
| 134 | ENV_DEVELOPMENT_SERVER = 1 |
| 135 | |
| 136 | # Running this GAE project in app-engine production. |
| 137 | ENV_PROD = 2 |
| 138 | |
| 139 | |
| 140 | class Priorities(object): |
| 141 | """Constants related to task priority.""" |
| 142 | |
| 143 | # weekly task's priority |
Alex Zamorzaev | 172024e | 2019-09-25 17:06:58 -0700 | [diff] [blame] | 144 | WEEKLY = 230 |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 145 | |
| 146 | # daily task's priority |
Alex Zamorzaev | 172024e | 2019-09-25 17:06:58 -0700 | [diff] [blame] | 147 | DAILY = 200 |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 148 | |
| 149 | # postbuild task's priority |
Alex Zamorzaev | 172024e | 2019-09-25 17:06:58 -0700 | [diff] [blame] | 150 | POSTBUILD = 170 |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 151 | |
| 152 | # the default task priority |
Alex Zamorzaev | 172024e | 2019-09-25 17:06:58 -0700 | [diff] [blame] | 153 | DEFAULT = 140 |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 154 | |
| 155 | |
| 156 | def environment(): |
| 157 | """Return proper environment settings.""" |
| 158 | if os.getenv(_RUNNING_ENV, '').startswith(_ENV_DEVELOPMENT_STR): |
| 159 | return RunningEnv.ENV_DEVELOPMENT_SERVER |
| 160 | elif os.getenv(_RUNNING_ENV, '').startswith(_ENV_APP_ENGINE_STR): |
| 161 | return RunningEnv.ENV_PROD |
| 162 | else: |
| 163 | return RunningEnv.ENV_STANDALONE |
| 164 | |
| 165 | |
Xixuan Wu | 8c173c3 | 2017-11-06 11:23:06 -0800 | [diff] [blame] | 166 | def application_id(parse=True): |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 167 | """Get current running application id. |
| 168 | |
Xixuan Wu | 8c173c3 | 2017-11-06 11:23:06 -0800 | [diff] [blame] | 169 | Args: |
| 170 | parse: whether to parse prefix of application id. |
| 171 | |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 172 | Returns: |
Xixuan Wu | 8c173c3 | 2017-11-06 11:23:06 -0800 | [diff] [blame] | 173 | If the id == 'None', return None; |
| 174 | If it's a Google internal GAE whose id format is 'google.com:<name>' and |
| 175 | parse is specified as True, return <name>; |
| 176 | Otherwise, return the full id. |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 177 | """ |
| 178 | app_id = app_identity.get_application_id() |
| 179 | logging.info('app_id: %s', app_id) |
Xixuan Wu | 8c173c3 | 2017-11-06 11:23:06 -0800 | [diff] [blame] | 180 | if app_id == 'None': |
| 181 | return None |
| 182 | |
| 183 | if not parse: |
| 184 | return app_id |
| 185 | |
Xixuan Wu | 5d6063e | 2017-09-05 16:15:07 -0700 | [diff] [blame] | 186 | if app_id is not None and len(app_id.split(':')) > 1: |
| 187 | return app_id.split(':')[1] |
| 188 | else: |
| 189 | return app_id |
Xixuan Wu | 69a5e78 | 2017-11-06 14:32:05 -0800 | [diff] [blame] | 190 | |
| 191 | |
| 192 | def server_name(): |
| 193 | """Return server name. |
| 194 | |
| 195 | Returns: |
| 196 | If this instance is running locally, return 'localhost:xxxx'. |
| 197 | If this instance is running on GAE, return '***.googleplex.com' or |
| 198 | '***.appspot.com'. |
| 199 | """ |
| 200 | return app_identity.get_default_version_hostname() |