Documentation ¶
Overview ¶
Adding to the ServiceContext
The ServiceContext is a very large interface that defines how to access the main state of the database and data central to Evergreen's function. All methods of the ServiceContext are contained in the servicecontext package in files depending on the main type they allow access to (i.e. all test access is contained in servicecontext/test.go).
Extending ServiceContext should only be done when the desired functionality cannot be performed using a combination of the methods it already contains or when such combination would be unseemingly slow or expensive.
To add to the ServiceContext, add the method signature into the interface in servicecontext/servicecontext.go. Next, add the implementation that interacts with the database to the database backed object. These objects are named by the resource they allow access to. The object that allows access to Hosts is called DBHostConnector. Finally, add a mock implementation to the mock object. For Hosts again, this object would be called MockHostConnector.
Implementing database backed methods requires using methods in Evergreen's model package. As much database specific information as possible should be kept out of the these methods. For example, if a new aggregation pipeline is needed to complete the request, it should be defined in the Evergreen model package and used only to aggregate in the method.
Index ¶
- type DBContextConnector
- type DBHostConnector
- type DBServiceContext
- func (ctx *DBServiceContext) GetPrefix() string
- func (ctx *DBServiceContext) GetSuperUsers() []string
- func (ctx *DBServiceContext) GetURL() string
- func (ctx *DBServiceContext) SetPrefix(prefix string)
- func (ctx *DBServiceContext) SetSuperUsers(su []string)
- func (ctx *DBServiceContext) SetURL(url string)
- type DBTaskConnector
- func (tc *DBTaskConnector) FindTaskById(taskId string) (*task.Task, error)
- func (tc *DBTaskConnector) FindTasksByBuildId(buildId, taskId, status string, limit int, sortDir int) ([]task.Task, error)
- func (tc *DBTaskConnector) FindTasksByIds(ids []string) ([]task.Task, error)
- func (tc *DBTaskConnector) ResetTask(taskId, username string, proj *serviceModel.Project) error
- func (tc *DBTaskConnector) SetTaskActivated(taskId, user string, activated bool) error
- func (tc *DBTaskConnector) SetTaskPriority(t *task.Task, priority int64) error
- type DBTestConnector
- type DBUserConnector
- type MockContextConnector
- type MockHostConnector
- type MockServiceContext
- func (ctx *MockServiceContext) GetPrefix() string
- func (ctx *MockServiceContext) GetSuperUsers() []string
- func (ctx *MockServiceContext) GetURL() string
- func (ctx *MockServiceContext) SetPrefix(prefix string)
- func (ctx *MockServiceContext) SetSuperUsers(su []string)
- func (ctx *MockServiceContext) SetURL(url string)
- type MockTaskConnector
- func (mtc *MockTaskConnector) FindTaskById(taskId string) (*task.Task, error)
- func (mdf *MockTaskConnector) FindTasksByBuildId(buildId, startTaskId, status string, limit, sortDir int) ([]task.Task, error)
- func (mdf *MockTaskConnector) FindTasksByIds(taskIds []string) ([]task.Task, error)
- func (mtc *MockTaskConnector) FindTasksByProjectAndCommit(projectId, commitHash, taskId, status string, limit, sortDir int) ([]task.Task, error)
- func (mdf *MockTaskConnector) ResetTask(taskId, username string, proj *serviceModel.Project) error
- func (mdf *MockTaskConnector) SetTaskActivated(taskId, user string, activated bool) error
- func (mdf *MockTaskConnector) SetTaskPriority(it *task.Task, priority int64) error
- type MockTestConnector
- type MockUserConnector
- type ServiceContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBContextConnector ¶
type DBContextConnector struct{}
DBContextConnector is a struct that implements the Context related functions of the ServiceConnector interface through interactions with the backing database.
func (*DBContextConnector) FetchContext ¶
func (dc *DBContextConnector) FetchContext(taskId, buildId, versionId, patchId, projectId string) (model.Context, error)
LoadContext fetches the context through a call to the service layer.
type DBHostConnector ¶
type DBHostConnector struct{}
DBHostConnector is a struct that implements the Host related methods from the ServiceContext through interactions with the backing database.
func (*DBHostConnector) FindHostsById ¶
func (hc *DBHostConnector) FindHostsById(id, status string, limit int, sortDir int) ([]host.Host, error)
FindHosts uses the service layer's host type to query the backing database for the hosts.
type DBServiceContext ¶
type DBServiceContext struct { URL string Prefix string DBUserConnector DBTaskConnector DBContextConnector DBHostConnector DBTestConnector // contains filtered or unexported fields }
DBServiceContext is a struct that implements 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.
func (*DBServiceContext) GetPrefix ¶
func (ctx *DBServiceContext) GetPrefix() string
func (*DBServiceContext) GetSuperUsers ¶
func (ctx *DBServiceContext) GetSuperUsers() []string
func (*DBServiceContext) GetURL ¶
func (ctx *DBServiceContext) GetURL() string
func (*DBServiceContext) SetPrefix ¶
func (ctx *DBServiceContext) SetPrefix(prefix string)
func (*DBServiceContext) SetSuperUsers ¶
func (ctx *DBServiceContext) SetSuperUsers(su []string)
func (*DBServiceContext) SetURL ¶
func (ctx *DBServiceContext) SetURL(url string)
type DBTaskConnector ¶
type DBTaskConnector struct{}
DBTaskConnector is a struct that implements the Task related methods from the ServiceContext through interactions with he backing database.
func (*DBTaskConnector) FindTaskById ¶
func (tc *DBTaskConnector) FindTaskById(taskId string) (*task.Task, error)
FindTaskById uses the service layer's task type to query the backing database for the task with the given taskId.
func (*DBTaskConnector) FindTasksByBuildId ¶
func (tc *DBTaskConnector) FindTasksByBuildId(buildId, taskId, status string, limit int, sortDir int) ([]task.Task, error)
FindTasksByBuildId uses the service layer's task type to query the backing database for a list of task that matches buildId. It accepts the startTaskId and a limit to allow for pagination of the queries. It returns results sorted by taskId.
func (*DBTaskConnector) FindTasksByIds ¶
func (tc *DBTaskConnector) FindTasksByIds(ids []string) ([]task.Task, error)
func (*DBTaskConnector) ResetTask ¶
func (tc *DBTaskConnector) ResetTask(taskId, username string, proj *serviceModel.Project) error
ResetTask sets the task to be in an unexecuted state and prepares it to be run again.
func (*DBTaskConnector) SetTaskActivated ¶
func (tc *DBTaskConnector) SetTaskActivated(taskId, user string, activated bool) error
SetTaskPriority changes the priority value of a task using a call to the service layer function.
func (*DBTaskConnector) SetTaskPriority ¶
func (tc *DBTaskConnector) SetTaskPriority(t *task.Task, priority int64) error
SetTaskPriority changes the priority value of a task using a call to the service layer function.
type DBTestConnector ¶
type DBTestConnector struct{}
DBTestConnector is a struct that implements the Test related methods from the ServiceContext through interactions with the backing database.
func (*DBTestConnector) FindTasksByProjectAndCommit ¶
func (*DBTestConnector) FindTestsByTaskId ¶
func (tc *DBTestConnector) FindTestsByTaskId(taskId, testFilename, status string, limit, sortDir int) ([]task.TestResult, error)
type DBUserConnector ¶
type DBUserConnector struct{}
DBUserConnector is a struct that implements the User related interface of the ServiceContext interface through interactions with the backing database.
func (*DBUserConnector) FindUserById ¶
func (tc *DBUserConnector) FindUserById(userId string) (auth.APIUser, error)
FindUserById uses the service layer's user type to query the backing database for the user with the given Id.
type MockContextConnector ¶
MockContextConnector is a struct that mocks the context methods by storing context to be fetched by its method.
func (*MockContextConnector) FetchContext ¶
func (mc *MockContextConnector) FetchContext(taskId, buildId, versionId, patchId, projectId string) (model.Context, error)
FetchContext returns the context cached within the MockContextConnector.
type MockHostConnector ¶
MockHostConnector is a struct that implements the Host related methods from the ServiceContext through interactions with he backing database.
func (*MockHostConnector) FindHostsById ¶
func (hc *MockHostConnector) FindHostsById(id, status string, limit int, sort int) ([]host.Host, error)
FindHosts uses the service layer's host type to query the backing database for the hosts.
type MockServiceContext ¶
type MockServiceContext struct { URL string Prefix string MockUserConnector MockTaskConnector MockContextConnector MockHostConnector MockTestConnector // contains filtered or unexported fields }
func (*MockServiceContext) GetPrefix ¶
func (ctx *MockServiceContext) GetPrefix() string
func (*MockServiceContext) GetSuperUsers ¶
func (ctx *MockServiceContext) GetSuperUsers() []string
func (*MockServiceContext) GetURL ¶
func (ctx *MockServiceContext) GetURL() string
func (*MockServiceContext) SetPrefix ¶
func (ctx *MockServiceContext) SetPrefix(prefix string)
func (*MockServiceContext) SetSuperUsers ¶
func (ctx *MockServiceContext) SetSuperUsers(su []string)
func (*MockServiceContext) SetURL ¶
func (ctx *MockServiceContext) SetURL(url string)
type MockTaskConnector ¶
MockTaskConnector stores a cached set of tasks that are queried against by the implementations of the ServiceContext interface's Task related functions.
func (*MockTaskConnector) FindTaskById ¶
func (mtc *MockTaskConnector) FindTaskById(taskId string) (*task.Task, error)
FindTaskById provides a mock implementation of the functions for the ServiceContext interface without needing to use a database. It returns results based on the cached tasks in the MockTaskConnector.
func (*MockTaskConnector) FindTasksByBuildId ¶
func (mdf *MockTaskConnector) FindTasksByBuildId(buildId, startTaskId, status string, limit, sortDir int) ([]task.Task, error)
FindTaskByBuildId provides a mock implementation of the function for the ServiceContext interface without needing to use a database. It returns results based on the cached tasks in the MockTaskConnector.
func (*MockTaskConnector) FindTasksByIds ¶
func (mdf *MockTaskConnector) FindTasksByIds(taskIds []string) ([]task.Task, error)
func (*MockTaskConnector) FindTasksByProjectAndCommit ¶
func (mtc *MockTaskConnector) FindTasksByProjectAndCommit(projectId, commitHash, taskId, status string, limit, sortDir int) ([]task.Task, error)
FindTestsBytaskId
func (*MockTaskConnector) ResetTask ¶
func (mdf *MockTaskConnector) ResetTask(taskId, username string, proj *serviceModel.Project) error
func (*MockTaskConnector) SetTaskActivated ¶
func (mdf *MockTaskConnector) SetTaskActivated(taskId, user string, activated bool) error
SetTaskActivated changes the activation value of a task using a call to the service layer function.
func (*MockTaskConnector) SetTaskPriority ¶
func (mdf *MockTaskConnector) SetTaskPriority(it *task.Task, priority int64) error
SetTaskPriority changes the priority value of a task using a call to the service layer function.
type MockTestConnector ¶
type MockTestConnector struct { CachedTests []task.TestResult StoredError error }
MockTaskConnector stores a cached set of tests that are queried against by the implementations of the ServiceContext interface's Test related functions.
func (*MockTestConnector) FindTestsByTaskId ¶
func (mtc *MockTestConnector) FindTestsByTaskId(taskId, testFilename, status string, limit, sortDir int) ([]task.TestResult, error)
FindTestsBytaskId
type MockUserConnector ¶
MockUserConnector stores a cached set of users that are queried against by the implementations of the UserConnector interface's functions.
func (*MockUserConnector) FindUserById ¶
func (muc *MockUserConnector) FindUserById(userId string) (auth.APIUser, error)
FindUserById provides a mock implementation of the User functions from the ServiceContext that does not need to use a database. It returns results based on the cached users in the MockUserConnector.
type ServiceContext ¶
type ServiceContext 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) FindTasksByIds([]string) ([]task.Task, error) SetTaskPriority(*task.Task, int64) error SetTaskActivated(string, string, bool) error ResetTask(string, string, *model.Project) 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 and limit for paginating through the results. // It returns a list of tasks which match. FindTasksByBuildId(string, string, string, int, int) ([]task.Task, 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, int) ([]task.Task, error) // FindTestsByTaskId is a methodd 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) ([]task.TestResult, error) // FindUserById is a method to find a specific user given its ID. FindUserById(string) (auth.APIUser, error) // FindHostsById is a method to find a sorted list of hosts given an ID to // start from. FindHostsById(string, string, int, int) ([]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) }
ServiceContext 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.