forked from evergreen-ci/evergreen
/
interface.go
292 lines (239 loc) · 13.8 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package data
import (
"context"
"encoding/json"
"io"
"net/http"
"time"
"github.com/docker/docker/api/types"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/apimodels"
"github.com/evergreen-ci/evergreen/cloud"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/evergreen/model/build"
"github.com/evergreen-ci/evergreen/model/distro"
"github.com/evergreen-ci/evergreen/model/event"
"github.com/evergreen-ci/evergreen/model/host"
"github.com/evergreen-ci/evergreen/model/manifest"
"github.com/evergreen-ci/evergreen/model/patch"
"github.com/evergreen-ci/evergreen/model/reliability"
"github.com/evergreen-ci/evergreen/model/stats"
"github.com/evergreen-ci/evergreen/model/task"
"github.com/evergreen-ci/evergreen/model/testresult"
"github.com/evergreen-ci/evergreen/model/user"
restModel "github.com/evergreen-ci/evergreen/rest/model"
"github.com/evergreen-ci/gimlet"
"github.com/google/go-github/github"
"github.com/mongodb/amboy"
)
// Connector is an interface that contains all of the methods which
// connect to the service layer of evergreen. These methods abstract the link
// between the service and the API layers, allowing for changes in the
// service architecture without forcing changes to the API.
type Connector interface {
// Get and Set SuperUsers provide access to the list of API super users.
GetSuperUsers() []string
SetSuperUsers([]string)
// Get and Set URL provide access to the main url string of the API.
GetURL() string
SetURL(string)
// Get and Set Prefix provide access to the prefix that prepends all of the
// URL paths.
GetPrefix() string
SetPrefix(string)
// FindTaskById is a method to find a specific task given its ID.
FindTaskById(string) (*task.Task, error)
FindTaskWithinTimePeriod(time.Time, time.Time, string, []string) ([]task.Task, error)
FindOldTasksByIDWithDisplayTasks(string) ([]task.Task, error)
FindTasksByIds([]string) ([]task.Task, error)
SetTaskPriority(*task.Task, string, int64) error
SetTaskActivated(string, string, bool) error
ResetTask(string, string) error
AbortTask(string, string) error
CheckTaskSecret(string, *http.Request) (int, error)
// FindTasksByBuildId is a method to find a set of tasks which all have the same
// BuildId. It takes the buildId being queried for as its first parameter,
// as well as a taskId, status, and limit for paginating through the results.
FindTasksByBuildId(string, string, string, int, int) ([]task.Task, error)
// FindBuildById is a method to find the build matching the same BuildId.
FindBuildById(string) (*build.Build, error)
// GetManifestByTask is a method to get the manifest for the given task.
GetManifestByTask(string) (*manifest.Manifest, error)
// SetBuildPriority and SetBuildActivated change the status of the input build
SetBuildPriority(string, int64) error
SetBuildActivated(string, string, bool) error
// AbortBuild is a method to abort the build matching the same BuildId.
AbortBuild(string, string) error
// RestartBuild is a method to restart the build matching the same BuildId.
RestartBuild(string, string) error
// Find project variables matching given projectId.
FindProjectVarsById(string) (*restModel.APIProjectVars, error)
// UpdateProjectVars updates the project using the variables given in the model.
// If successful, updates the given projectVars with the updated projectVars.
UpdateProjectVars(string, *restModel.APIProjectVars) error
// CopyProjectVars copies the variables for the first project to the second
CopyProjectVars(string, string) error
// Find the project matching the given ProjectId.
FindProjectById(string) (*model.ProjectRef, error)
// Create/Update a project the given projectRef
CreateProject(projectRef *model.ProjectRef) error
UpdateProject(projectRef *model.ProjectRef) error
// EnableWebhooks creates a webhook for the project's owner/repo if one does not exist.
// If unable to setup the new webhook, returns false but no error.
EnableWebhooks(context.Context, *model.ProjectRef) (bool, error)
// EnablePRTesting determines if PR testing can be enabled for the given project.
EnablePRTesting(*model.ProjectRef) error
// UpdateProjectRevision updates the given project's revision
UpdateProjectRevision(string, string) error
// FindProjects is a method to find projects as ordered by name
FindProjects(string, int, int) ([]model.ProjectRef, error)
// FindProjectByBranch is a method to find the projectref given a branch name.
FindProjectByBranch(string) (*model.ProjectRef, error)
GetProjectWithCommitQueueByOwnerRepoAndBranch(string, string, string) (*model.ProjectRef, error)
// GetVersionsAndVariants returns recent versions for a project
GetVersionsAndVariants(int, int, *model.Project) (*restModel.VersionVariantData, error)
GetProjectEventLog(string, time.Time, int) ([]restModel.APIProjectEvent, error)
CreateVersionFromConfig(context.Context, string, []byte, *user.DBUser, string, bool) (*model.Version, error)
GetVersionsInProject(string, string, int, int) ([]restModel.APIVersion, error)
// FindByProjectAndCommit is a method to find a set of tasks which ran as part of
// certain version in a project. It takes the projectId, commit hash, and a taskId
// for paginating through the results.
FindTasksByProjectAndCommit(string, string, string, string, int) ([]task.Task, error)
// FindTestsByTaskId is a method to find a set of tests that correspond to
// a given task. It takes a taskId, testName to start from, test status to filter,
// limit, and sort to provide additional control over the results.
FindTestsByTaskId(string, string, string, int, int) ([]testresult.TestResult, error)
// FindUserById is a method to find a specific user given its ID.
FindUserById(string) (gimlet.User, error)
// FindHostsById is a method to find a sorted list of hosts given an ID to
// start from.
FindHostsById(string, string, string, int) ([]host.Host, error)
FindHostById(string) (*host.Host, error)
// FindHostByIdWithOwner finds a host with given host ID that was
// started by the given user. If the given user is a super-user,
// the host will also be returned regardless of who the host was
// started by
FindHostByIdWithOwner(string, gimlet.User) (*host.Host, error)
FindHostsByDistroID(string) ([]host.Host, error)
// NewIntentHost is a method to insert an intent host given a distro and the name of a saved public key
NewIntentHost(*restModel.HostRequestOptions, *user.DBUser) (*host.Host, error)
// FetchContext is a method to fetch a context given a series of identifiers.
FetchContext(string, string, string, string, string) (model.Context, error)
// FindDistroById is a method to find the distro matching the given distroId.
FindDistroById(string) (*distro.Distro, error)
// FindAllDistros is a method to find a sorted list of all distros.
FindAllDistros() ([]distro.Distro, error)
// UpdateDistro is a method that updates a given distro
UpdateDistro(distro *distro.Distro) error
// FindDistroById is a method to delete the distro matching the given distroId.
DeleteDistroById(string) error
// CreateDistro is a method to insert a given distro.
CreateDistro(distro *distro.Distro) error
// FindCostByVersionId returns cost data of a version given its ID.
FindCostByVersionId(string) (*task.VersionCost, error)
// FindCostByDistroId returns cost data of a distro given its ID and a time range.
// Interested time range is given as a start time and duration.
FindCostByDistroId(string, time.Time, time.Duration) (*task.DistroCost, error)
// ClearTaskQueue deletes all tasks from the task queue for a distro
ClearTaskQueue(string) error
// FindVersionById returns version given its ID.
FindVersionById(string) (*model.Version, error)
// FindPatchesByProject provides access to the patches corresponding to the input project ID
// as ordered by creation time.
FindPatchesByProject(string, time.Time, int) ([]patch.Patch, error)
// FindPatchByUser finds patches for the input user as ordered by creation time
FindPatchesByUser(string, time.Time, int) ([]patch.Patch, error)
// FindPatchById fetches the patch corresponding to the input patch ID.
FindPatchById(string) (*patch.Patch, error)
// AbortVersion aborts all tasks of a version given its ID.
AbortVersion(string, string) error
// AbortPatch aborts the patch corresponding to the input patch ID and deletes if not finalized.
AbortPatch(string, string) error
// AbortPatchesFromPullRequest aborts patches with the same PR Number,
// in the same repository, at the pull request's close time
AbortPatchesFromPullRequest(*github.PullRequestEvent) error
// RestartVersion restarts all completed tasks of a version given its ID and the caller.
RestartVersion(string, string) error
// SetPatchPriority and SetPatchActivated change the status of the input patch
SetPatchPriority(string, int64) error
SetPatchActivated(string, string, bool) error
// GetEvergreenSettings/SetEvergreenSettings retrieves/sets the system-wide settings document
GetEvergreenSettings() (*evergreen.Settings, error)
GetBanner() (string, string, error)
SetEvergreenSettings(*restModel.APIAdminSettings, *evergreen.Settings, *user.DBUser, bool) (*evergreen.Settings, error)
// SetAdminBanner sets set the banner in the system-wide settings document
SetAdminBanner(string, *user.DBUser) error
// SetBannerTheme sets set the banner theme in the system-wide settings document
SetBannerTheme(string, *user.DBUser) error
// SetAdminBanner sets set the service flags in the system-wide settings document
SetServiceFlags(evergreen.ServiceFlags, *user.DBUser) error
RestartFailedTasks(amboy.Queue, model.RestartOptions) (*restModel.RestartResponse, error)
//RestartFailedCommitQueueVersions takes in a time range
RestartFailedCommitQueueVersions(opts model.RestartOptions) (*restModel.RestartResponse, error)
RevertConfigTo(string, string) error
GetAdminEventLog(time.Time, int) ([]restModel.APIAdminEvent, error)
FindCostTaskByProject(string, string, time.Time, time.Time, int, int) ([]task.Task, error)
// FindRecentTasks finds tasks that have recently finished.
FindRecentTasks(int) ([]task.Task, *task.ResultCounts, error)
FindRecentTaskListDistro(int) (*restModel.APIRecentTaskStatsList, error)
FindRecentTaskListProject(int) (*restModel.APIRecentTaskStatsList, error)
// GetHostStatsByDistro returns host stats broken down by distro
GetHostStatsByDistro() ([]host.StatsByDistro, error)
AddPublicKey(*user.DBUser, string, string) error
DeletePublicKey(*user.DBUser, string) error
UpdateSettings(*user.DBUser, user.UserSettings) error
SubmitFeedback(restModel.APIFeedbackSubmission) error
AddPatchIntent(patch.Intent, amboy.Queue) error
SetHostStatus(*host.Host, string, string) error
SetHostExpirationTime(*host.Host, time.Time) error
// TerminateHost terminates the given host via the cloud provider's API
TerminateHost(context.Context, *host.Host, string) error
CheckHostSecret(*http.Request) (int, error)
// FindProjectAliases queries the database to find all aliases.
FindProjectAliases(string) ([]restModel.APIProjectAlias, error)
// CopyProjectAliases copies aliases from the first project for the second project.
CopyProjectAliases(string, string) error
// UpdateProjectAliases upserts/deletes aliases for the given project
UpdateProjectAliases(string, []restModel.APIProjectAlias) error
// TriggerRepotracker creates an amboy job to get the commits from a
// Github Push Event
TriggerRepotracker(amboy.Queue, string, *github.PushEvent) error
// GetCLIUpdate fetches the current cli version and the urls to download
GetCLIUpdate() (*restModel.APICLIUpdate, error)
// GenerateTasks parses JSON files for `generate.tasks` and creates the new builds and tasks.
GenerateTasks(context.Context, string, []json.RawMessage, amboy.QueueGroup) error
// GeneratePoll checks to see if a `generate.tasks` job has finished.
GeneratePoll(context.Context, string, amboy.QueueGroup) (bool, []string, error)
// SaveSubscriptions saves a set of notification subscriptions
SaveSubscriptions(string, []restModel.APISubscription) error
// GetSubscriptions returns the subscriptions that belong to a user
GetSubscriptions(string, event.OwnerType) ([]restModel.APISubscription, error)
DeleteSubscriptions(string, []string) error
// CopyProjectSubscriptions copies subscriptions from the first project for the second project.
CopyProjectSubscriptions(string, string) error
// Notifications
GetNotificationsStats() (*restModel.APIEventStats, error)
// ListHostsForTask lists running hosts scoped to the task or the task's build.
ListHostsForTask(string) ([]host.Host, error)
MakeIntentHost(string, string, string, apimodels.CreateHost) (*host.Host, error)
CreateHostsFromTask(*task.Task, user.DBUser, string) error
// Get test execution statistics
GetTestStats(stats.StatsFilter) ([]restModel.APITestStats, error)
GetTaskStats(stats.StatsFilter) ([]restModel.APITaskStats, error)
// Get task reliability scores
GetTaskReliabilityScores(reliability.TaskReliabilityFilter) ([]restModel.APITaskReliability, error)
// Commit queue methods
// GetGithubPR takes the owner, repo, and PR number.
GetGitHubPR(context.Context, string, string, int) (*github.PullRequest, error)
EnqueueItem(string, restModel.APICommitQueueItem) (int, error)
FindCommitQueueByID(string) (*restModel.APICommitQueue, error)
EnableCommitQueue(*model.ProjectRef, model.CommitQueueParams) error
CommitQueueRemoveItem(string, string) (bool, error)
IsItemOnCommitQueue(string, string) (bool, error)
CommitQueueClearAll() (int, error)
IsAuthorizedToPatchAndMerge(context.Context, *evergreen.Settings, UserRepoInfo) (bool, error)
// GetDockerLogs returns logs for the given docker container
GetDockerLogs(context.Context, string, *host.Host, *evergreen.Settings, types.ContainerLogsOptions) (io.Reader, error)
// GetDockerStatus returns the status of the given docker container
GetDockerStatus(context.Context, string, *host.Host, *evergreen.Settings) (*cloud.ContainerStatus, error)
}