blob: 3e252aac3551a82fd7b90ad69a60b90baae99902 [file] [log] [blame]
xixuanbea010f2017-03-27 10:10:19 -07001# 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 Wud55ac6e2019-03-14 10:56:39 -07007import collections
xixuanbea010f2017-03-27 10:10:19 -07008import logging
9import os
10
Xixuan Wu5d6063e2017-09-05 16:15:07 -070011from google.appengine.api import app_identity
12
xixuanbea010f2017-03-27 10:10:19 -070013# Namedtuple for storing rest client info.
Xixuan Wud55ac6e2019-03-14 10:56:39 -070014RestClientInfo = collections.namedtuple(
xixuanbea010f2017-03-27 10:10:19 -070015 'RestClientInfo', 'scopes, service_name, service_version')
16
xixuanbea010f2017-03-27 10:10:19 -070017# 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 Wu5d6063e2017-09-05 16:15:07 -070021
22
Xixuan Wud55ac6e2019-03-14 10:56:39 -070023class StorageBucket(object):
24 """Constants refer to Google storage bucket."""
25
26 PROD_SUITE_SCHEDULER = 'suite-scheduler.google.com.a.appspot.com'
27
28
Xixuan Wu27a61f82017-09-14 11:42:37 -070029class AppID(object):
30 """Constants refer to app id."""
31
32 PROD_APP = 'suite-scheduler'
33 STAGING_APP = 'suite-scheduler-staging'
34
Xinan Linc9f01152020-02-05 22:05:13 -080035class 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 Wu27a61f82017-09-14 11:42:37 -070043
Xinan Lincd6d40b2019-08-09 15:53:43 -070044class 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 Prabhu9adfa632020-02-21 10:39:24 -080053 # Source of truth:
54 # https://chrome-internal.googlesource.com/chromeos/infra/config/+/8f12edac54383831aaed9ed1819ef909a66ecc97/testplatform/main.star#90
Dhanya Ganesha4ce38e2021-10-26 15:45:47 +000055 MAX_BUILDBUCKET_TIMEOUT_MINS = (39*60 + 30)
Xinan Lin3ba18a02019-08-13 15:44:55 -070056 MAX_RETRY = 3
57
Xinan Lin1ec52062019-12-17 18:41:53 -080058 # TODO(crbug.com/1034166): this is a workaround to reduce the child task count
59 # in swarming.
60 MULTIREQUEST_SIZE = 25
Xinan Lincd6d40b2019-08-09 15:53:43 -070061
Xinan Linea1efcb2019-12-30 23:46:42 -080062
63class BaseEvent(object):
64 """Constants used for base_event."""
65
66 # The new build may not get inserted to BQ right after they are
Xinan Lin3330d672020-03-03 14:52:36 -080067 # created(crbug/1038729). DELAY_MINUTES delays the period of
68 # the builds suite scheduler queries, to ensure the most of the target
Xinan Linea1efcb2019-12-30 23:46:42 -080069 # builds exist in BQ.
Xinan Lin3330d672020-03-03 14:52:36 -080070 DELAY_MINUTES = 30
Xinan Linea1efcb2019-12-30 23:46:42 -080071
72
Xixuan Wu27a61f82017-09-14 11:42:37 -070073class 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 Wu5d6063e2017-09-05 16:15:07 -070090class 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 Wu6f117e92017-10-27 10:51:58 -0700116 STACKDRIVER_CLIENT = RestClientInfo._make(
117 ['https://www.googleapis.com/auth/logging.read',
118 'logging',
119 'v2'])
120
Xixuan Wu7d142a92019-04-26 12:03:02 -0700121 BIGQUERY_CLIENT = RestClientInfo._make(
122 ['https://www.googleapis.com/auth/bigquery',
123 'bigquery',
124 'v2'])
125
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700126
127class 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
140class Priorities(object):
141 """Constants related to task priority."""
142
143 # weekly task's priority
Alex Zamorzaev172024e2019-09-25 17:06:58 -0700144 WEEKLY = 230
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700145
146 # daily task's priority
Alex Zamorzaev172024e2019-09-25 17:06:58 -0700147 DAILY = 200
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700148
149 # postbuild task's priority
Alex Zamorzaev172024e2019-09-25 17:06:58 -0700150 POSTBUILD = 170
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700151
152 # the default task priority
Alex Zamorzaev172024e2019-09-25 17:06:58 -0700153 DEFAULT = 140
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700154
155
156def 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 Wu8c173c32017-11-06 11:23:06 -0800166def application_id(parse=True):
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700167 """Get current running application id.
168
Xixuan Wu8c173c32017-11-06 11:23:06 -0800169 Args:
170 parse: whether to parse prefix of application id.
171
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700172 Returns:
Xixuan Wu8c173c32017-11-06 11:23:06 -0800173 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 Wu5d6063e2017-09-05 16:15:07 -0700177 """
178 app_id = app_identity.get_application_id()
179 logging.info('app_id: %s', app_id)
Xixuan Wu8c173c32017-11-06 11:23:06 -0800180 if app_id == 'None':
181 return None
182
183 if not parse:
184 return app_id
185
Xixuan Wu5d6063e2017-09-05 16:15:07 -0700186 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 Wu69a5e782017-11-06 14:32:05 -0800190
191
192def 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()