github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/apiv3/servicecontext/servicecontext.go (about) 1 package servicecontext 2 3 import ( 4 "github.com/evergreen-ci/evergreen/auth" 5 "github.com/evergreen-ci/evergreen/model" 6 "github.com/evergreen-ci/evergreen/model/host" 7 "github.com/evergreen-ci/evergreen/model/task" 8 ) 9 10 // ServiceContext is an interface that contains all of the methods which 11 // connect to the service layer of evergreen. These methods abstract the link 12 // between the service and the API layers, allowing for changes in the 13 // service architecture without forcing changes to the API. 14 type ServiceContext interface { 15 // Get and Set SuperUsers provide access to the list of API super users. 16 GetSuperUsers() []string 17 SetSuperUsers([]string) 18 19 // Get and Set URL provide access to the main url string of the API. 20 GetURL() string 21 SetURL(string) 22 23 // Get and Set Prefix provide access to the prefix that prepends all of the 24 // URL paths. 25 GetPrefix() string 26 SetPrefix(string) 27 28 // FindTaskById is a method to find a specific task given its ID. 29 FindTaskById(string) (*task.Task, error) 30 FindTasksByIds([]string) ([]task.Task, error) 31 SetTaskPriority(*task.Task, int64) error 32 SetTaskActivated(string, string, bool) error 33 ResetTask(string, string, *model.Project) error 34 35 // FindTasksByBuildId is a method to find a set of tasks which all have the same 36 // BuildId. It takes the buildId being queried for as its first parameter, 37 // as well as a taskId and limit for paginating through the results. 38 // It returns a list of tasks which match. 39 FindTasksByBuildId(string, string, string, int, int) ([]task.Task, error) 40 41 // FindByProjectAndCommit is a method to find a set of tasks which ran as part of 42 // certain version in a project. It takes the projectId, commit hash, and a taskId 43 // for paginating through the results. 44 FindTasksByProjectAndCommit(string, string, string, string, int, int) ([]task.Task, error) 45 46 // FindTestsByTaskId is a methodd to find a set of tests that correspond to 47 // a given task. It takes a taskId, testName to start from, test status to filter, 48 // limit, and sort to provide additional control over the results. 49 FindTestsByTaskId(string, string, string, int, int) ([]task.TestResult, error) 50 51 // FindUserById is a method to find a specific user given its ID. 52 FindUserById(string) (auth.APIUser, error) 53 54 // FindHostsById is a method to find a sorted list of hosts given an ID to 55 // start from. 56 FindHostsById(string, string, int, int) ([]host.Host, error) 57 58 // FetchContext is a method to fetch a context given a series of identifiers. 59 FetchContext(string, string, string, string, string) (model.Context, error) 60 } 61 62 // DBServiceContext is a struct that implements all of the methods which 63 // connect to the service layer of evergreen. These methods abstract the link 64 // between the service and the API layers, allowing for changes in the 65 // service architecture without forcing changes to the API. 66 type DBServiceContext struct { 67 superUsers []string 68 URL string 69 Prefix string 70 71 DBUserConnector 72 DBTaskConnector 73 DBContextConnector 74 DBHostConnector 75 DBTestConnector 76 } 77 78 func (ctx *DBServiceContext) GetSuperUsers() []string { 79 return ctx.superUsers 80 } 81 func (ctx *DBServiceContext) SetSuperUsers(su []string) { 82 ctx.superUsers = su 83 } 84 func (ctx *DBServiceContext) GetURL() string { 85 return ctx.URL 86 } 87 func (ctx *DBServiceContext) SetURL(url string) { 88 ctx.URL = url 89 } 90 func (ctx *DBServiceContext) GetPrefix() string { 91 return ctx.Prefix 92 } 93 func (ctx *DBServiceContext) SetPrefix(prefix string) { 94 ctx.Prefix = prefix 95 } 96 97 type MockServiceContext struct { 98 superUsers []string 99 URL string 100 Prefix string 101 102 MockUserConnector 103 MockTaskConnector 104 MockContextConnector 105 MockHostConnector 106 MockTestConnector 107 } 108 109 func (ctx *MockServiceContext) GetSuperUsers() []string { 110 return ctx.superUsers 111 } 112 func (ctx *MockServiceContext) SetSuperUsers(su []string) { 113 ctx.superUsers = su 114 } 115 func (ctx *MockServiceContext) GetURL() string { 116 return ctx.URL 117 } 118 func (ctx *MockServiceContext) SetURL(url string) { 119 ctx.URL = url 120 } 121 func (ctx *MockServiceContext) GetPrefix() string { 122 return ctx.Prefix 123 } 124 func (ctx *MockServiceContext) SetPrefix(prefix string) { 125 ctx.Prefix = prefix 126 }