本文整理匯總了Golang中github.com/evergreen-ci/evergreen/model.FindTask函數的典型用法代碼示例。如果您正苦於以下問題:Golang FindTask函數的具體用法?Golang FindTask怎麽用?Golang FindTask使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FindTask函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: dBTestsWildcard
// dBTestsWildcard are the database verification tests for globbed file execution
func dBTestsWildcard() {
task, err := model.FindTask("mocktaskid")
So(err, ShouldBeNil)
So(len(task.TestResults), ShouldEqual, TotalResultCount)
Convey("along with the proper logs", func() {
// junit_1.xml
tl := dBFindOneTestLog("pkg1.test.test_things.test_params_func:2")
So(tl.Lines[0], ShouldContainSubstring, "FAILURE")
So(tl.Lines[6], ShouldContainSubstring, "AssertionError")
tl = dBFindOneTestLog("pkg1.test.test_things.SomeTests.test_skippy")
So(tl.Lines[0], ShouldContainSubstring, "SKIPPED")
// junit_2.xml
tl = dBFindOneTestLog("tests.ATest.fail")
So(tl.Lines[0], ShouldContainSubstring, "FAILURE")
So(tl.Lines[1], ShouldContainSubstring, "AssertionFailedError")
// junit_3.xml
tl = dBFindOneTestLog(
"test.test_threads_replica_set_client.TestThreadsReplicaSet.test_safe_update",
)
So(tl.Lines[0], ShouldContainSubstring, "SKIPPED")
tl = dBFindOneTestLog("test.test_bson.TestBSON.test_basic_encode")
So(tl.Lines[0], ShouldContainSubstring, "AssertionError")
})
}
示例2: TestTaskExecTimeout
func TestTaskExecTimeout(t *testing.T) {
setupTlsConfigs(t)
for tlsString, tlsConfig := range tlsConfigs {
Convey("With agent running a slow test and live API server over "+tlsString, t, func() {
testTask, _, err := setupAPITestData(testConfig, "exec_timeout_task", "linux-64", NoPatch, t)
testutil.HandleTestingErr(err, t, "Failed to find test task")
testServer, err := apiserver.CreateTestServer(testConfig, tlsConfig, plugin.APIPlugins, Verbose)
testutil.HandleTestingErr(err, t, "Couldn't create apiserver: %v", err)
testAgent, err := New(testServer.URL, testTask.Id, testTask.Secret, "", testConfig.Expansions["api_httpscert"])
So(err, ShouldBeNil)
So(testAgent, ShouldNotBeNil)
Convey("after the slow test runs beyond the timeout threshold", func() {
// actually run the task.
// this function won't return until the whole thing is done.
testAgent.RunTask()
testAgent.APILogger.Flush()
time.Sleep(5 * time.Second)
printLogsForTask(testTask.Id)
Convey("the test should be marked as failed and timed out", func() {
So(scanLogsForTask(testTask.Id, "executing the pre-run script"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "executing the post-run script!"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "executing the task-timeout script!"), ShouldBeTrue)
testTask, err = model.FindTask(testTask.Id)
So(testTask.Status, ShouldEqual, evergreen.TaskFailed)
So(testTask.Details.TimedOut, ShouldBeTrue)
So(testTask.Details.Description, ShouldEqual, "shell.exec")
})
})
})
}
}
示例3: checkTask
func (as *APIServer) checkTask(checkSecret bool, next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
taskId := mux.Vars(r)["taskId"]
if taskId == "" {
as.LoggedError(w, r, http.StatusBadRequest, fmt.Errorf("missing task id"))
return
}
task, err := model.FindTask(taskId)
if err != nil {
as.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
if task == nil {
as.LoggedError(w, r, http.StatusNotFound, fmt.Errorf("task not found"))
return
}
if checkSecret {
secret := r.Header.Get(evergreen.TaskSecretHeader)
// Check the secret - if it doesn't match, write error back to the client
if secret != task.Secret {
evergreen.Logger.Logf(slogger.ERROR, "Wrong secret sent for task %v: Expected %v but got %v", taskId, task.Secret, secret)
http.Error(w, "wrong secret!", http.StatusConflict)
return
}
}
context.Set(r, apiTaskKey, task)
// also set the task in the context visible to plugins
plugin.SetTask(r, task)
next(w, r)
}
}
示例4: TestPatchPluginAPI
func TestPatchPluginAPI(t *testing.T) {
testConfig := evergreen.TestConfig()
Convey("With a running api server and installed plugin", t, func() {
registry := plugin.NewSimpleRegistry()
gitPlugin := &GitPlugin{}
err := registry.Register(gitPlugin)
testutil.HandleTestingErr(err, t, "Couldn't register patch plugin")
server, err := apiserver.CreateTestServer(testConfig, nil, plugin.APIPlugins, false)
testutil.HandleTestingErr(err, t, "Couldn't set up testing server")
taskConfig, _ := plugintest.CreateTestConfig("testdata/plugin_patch.yml", t)
testCommand := GitApplyPatchCommand{"dir"}
_, _, err = plugintest.SetupAPITestData("testTask", true, t)
testutil.HandleTestingErr(err, t, "Couldn't set up test documents")
testTask, err := model.FindTask("testTaskId")
testutil.HandleTestingErr(err, t, "Couldn't set up test patch task")
sliceAppender := &evergreen.SliceAppender{[]*slogger.Log{}}
logger := agent.NewTestLogger(sliceAppender)
Convey("calls to existing tasks with patches should succeed", func() {
httpCom := plugintest.TestAgentCommunicator(testTask.Id, testTask.Secret, server.URL)
pluginCom := &agent.TaskJSONCommunicator{gitPlugin.Name(), httpCom}
patch, err := testCommand.GetPatch(taskConfig, pluginCom, logger)
So(err, ShouldBeNil)
So(patch, ShouldNotBeNil)
testutil.HandleTestingErr(db.Clear(version.Collection), t,
"unable to clear versions collection")
})
Convey("calls to non-existing tasks should fail", func() {
v := version.Version{Id: ""}
testutil.HandleTestingErr(v.Insert(), t, "Couldn't insert dummy version")
httpCom := plugintest.TestAgentCommunicator("BAD_TASK_ID", "", server.URL)
pluginCom := &agent.TaskJSONCommunicator{gitPlugin.Name(), httpCom}
patch, err := testCommand.GetPatch(taskConfig, pluginCom, logger)
So(err.Error(), ShouldContainSubstring, "not found")
So(err, ShouldNotBeNil)
So(patch, ShouldBeNil)
testutil.HandleTestingErr(db.Clear(version.Collection), t,
"unable to clear versions collection")
})
Convey("calls to existing tasks without patches should fail", func() {
noPatchTask := model.Task{Id: "noPatchTask", BuildId: "a"}
testutil.HandleTestingErr(noPatchTask.Insert(), t, "Couldn't insert patch task")
noPatchVersion := version.Version{Id: "noPatchVersion", BuildIds: []string{"a"}}
testutil.HandleTestingErr(noPatchVersion.Insert(), t, "Couldn't insert patch version")
v := version.Version{Id: ""}
testutil.HandleTestingErr(v.Insert(), t, "Couldn't insert dummy version")
httpCom := plugintest.TestAgentCommunicator(noPatchTask.Id, "", server.URL)
pluginCom := &agent.TaskJSONCommunicator{gitPlugin.Name(), httpCom}
patch, err := testCommand.GetPatch(taskConfig, pluginCom, logger)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "no patch found for task")
So(patch, ShouldBeNil)
testutil.HandleTestingErr(db.Clear(version.Collection), t,
"unable to clear versions collection")
})
})
}
示例5: TestTaskEndEndpoint
func TestTaskEndEndpoint(t *testing.T) {
setupTlsConfigs(t)
for tlsString, tlsConfig := range tlsConfigs {
testTask, _, err := setupAPITestData(testConfig, "random", "linux-64", NoPatch, t)
testutil.HandleTestingErr(err, t, "Couldn't make test data: %v", err)
Convey("With a live api server, agent, and test task over "+tlsString, t, func() {
testServer, err := apiserver.CreateTestServer(testConfig, tlsConfig, plugin.APIPlugins, Verbose)
testutil.HandleTestingErr(err, t, "Couldn't create apiserver: %v", err)
testAgent, err := createAgent(testServer, testTask)
testutil.HandleTestingErr(err, t, "failed to create agent: %v")
testAgent.heartbeater.Interval = 10 * time.Second
testAgent.StartBackgroundActions(&NoopSignalHandler{})
Convey("calling end() should update task's/host's status properly "+
"and start running the next task", func() {
subsequentTaskId := testTask.Id + "Two"
details := &apimodels.TaskEndDetail{Status: evergreen.TaskSucceeded}
taskEndResp, err := testAgent.End(details)
time.Sleep(1 * time.Second)
So(err, ShouldBeNil)
taskUpdate, err := model.FindTask(testTask.Id)
So(err, ShouldBeNil)
So(taskUpdate.Status, ShouldEqual, evergreen.TaskSucceeded)
testHost, err := host.FindOne(host.ById(testTask.HostId))
So(err, ShouldBeNil)
So(testHost.RunningTask, ShouldEqual, subsequentTaskId)
taskUpdate, err = model.FindTask(subsequentTaskId)
So(err, ShouldBeNil)
So(taskUpdate.Status, ShouldEqual, evergreen.TaskDispatched)
So(taskEndResp, ShouldNotBeNil)
So(taskEndResp.RunNext, ShouldBeTrue)
So(taskEndResp.TaskId, ShouldEqual, subsequentTaskId)
})
})
}
}
示例6: TestPatchTask
func TestPatchTask(t *testing.T) {
setupTlsConfigs(t)
testConfig := evergreen.TestConfig()
db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(testConfig))
patchModes := []patchTestMode{InlinePatch, ExternalPatch}
testutil.ConfigureIntegrationTest(t, testConfig, "TestPatchTask")
for tlsString, tlsConfig := range tlsConfigs {
for _, testSetup := range testSetups {
Convey(testSetup.testSpec, t, func() {
Convey("With agent running a patched 'compile'"+tlsString, func() {
for _, mode := range patchModes {
Convey(fmt.Sprintf("Using patch mode %v", mode.String()), func() {
testTask, _, err := setupAPITestData(testConfig, "compile", "linux-64", mode, t)
testutil.HandleTestingErr(err, t, "Error setting up test data: %v", err)
testServer, err := apiserver.CreateTestServer(testConfig, tlsConfig, plugin.APIPlugins, Verbose)
testutil.HandleTestingErr(err, t, "Couldn't create apiserver: %v", err)
testAgent, err := New(testServer.URL, testTask.Id, testTask.Secret, "", testConfig.Expansions["api_httpscert"])
// actually run the task.
// this function won't return until the whole thing is done.
testAgent.RunTask()
time.Sleep(100 * time.Millisecond)
testAgent.APILogger.FlushAndWait()
printLogsForTask(testTask.Id)
Convey("all scripts in task should have been run successfully", func() {
So(scanLogsForTask(testTask.Id, "executing the pre-run script"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "executing the post-run script!"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "Cloning into") || // git 1.8
scanLogsForTask(testTask.Id, "Initialized empty Git repository"), // git 1.7
ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "i am patched!"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "i am a patched module"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "i am compiling!"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "i am sanity testing!"), ShouldBeTrue)
testTask, err = model.FindTask(testTask.Id)
testutil.HandleTestingErr(err, t, "Error finding test task: %v", err)
So(testTask.Status, ShouldEqual, evergreen.TaskSucceeded)
})
})
}
})
})
}
}
}
示例7: TestAttachResults
func TestAttachResults(t *testing.T) {
resetTasks(t)
testConfig := evergreen.TestConfig()
Convey("With attachResults plugin installed into plugin registry", t, func() {
registry := plugin.NewSimpleRegistry()
attachPlugin := &AttachPlugin{}
err := registry.Register(attachPlugin)
testutil.HandleTestingErr(err, t, "Couldn't register plugin: %v")
server, err := apiserver.CreateTestServer(testConfig, nil, plugin.APIPlugins, true)
testutil.HandleTestingErr(err, t, "Couldn't set up testing server")
httpCom := plugintest.TestAgentCommunicator("mocktaskid", "mocktasksecret", server.URL)
configFile := "testdata/plugin_attach_results.yml"
resultsLoc := "testdata/plugin_attach_results.json"
taskConfig, err := plugintest.CreateTestConfig(configFile, t)
testutil.HandleTestingErr(err, t, "failed to create test config: %v")
taskConfig.WorkDir = "."
sliceAppender := &evergreen.SliceAppender{[]*slogger.Log{}}
logger := agent.NewTestLogger(sliceAppender)
Convey("all commands in test project should execute successfully", func() {
for _, task := range taskConfig.Project.Tasks {
So(len(task.Commands), ShouldNotEqual, 0)
for _, command := range task.Commands {
pluginCmds, err := registry.GetCommands(command, taskConfig.Project.Functions)
testutil.HandleTestingErr(err, t, "Couldn't get plugin command: %v")
So(pluginCmds, ShouldNotBeNil)
So(err, ShouldBeNil)
pluginCom := &agent.TaskJSONCommunicator{pluginCmds[0].Plugin(), httpCom}
err = pluginCmds[0].Execute(logger, pluginCom, taskConfig, make(chan bool))
So(err, ShouldBeNil)
task, err := model.FindTask(httpCom.TaskId)
testutil.HandleTestingErr(err, t, "Couldn't find task")
So(task, ShouldNotBeNil)
// ensure test results are exactly as expected
// attempt to open the file
reportFile, err := os.Open(resultsLoc)
testutil.HandleTestingErr(err, t, "Couldn't open report file: '%v'", err)
results := &model.TestResults{}
err = util.ReadJSONInto(reportFile, results)
testutil.HandleTestingErr(err, t, "Couldn't read report file: '%v'", err)
testResults := *results
So(task.TestResults, ShouldResemble, testResults.Results)
testutil.HandleTestingErr(err, t, "Couldn't clean up test temp dir")
}
}
})
})
}
示例8: DispatchTaskForHost
// DispatchTaskForHost assigns the task at the head of the task queue to the
// given host, dequeues the task and then marks it as dispatched for the host
func DispatchTaskForHost(taskQueue *model.TaskQueue, assignedHost *host.Host) (
nextTask *model.Task, err error) {
if assignedHost == nil {
return nil, fmt.Errorf("can not assign task to a nil host")
}
// only proceed if there are pending tasks left
for !taskQueue.IsEmpty() {
queueItem := taskQueue.NextTask()
// pin the task to the given host and fetch the full task document from
// the database
nextTask, err = model.FindTask(queueItem.Id)
if err != nil {
return nil, fmt.Errorf("error finding task with id %v: %v",
queueItem.Id, err)
}
if nextTask == nil {
return nil, fmt.Errorf("refusing to move forward because queued "+
"task with id %v does not exist", queueItem.Id)
}
// dequeue the task from the queue
if err = taskQueue.DequeueTask(nextTask.Id); err != nil {
return nil, fmt.Errorf("error pulling task with id %v from "+
"queue for distro %v: %v", nextTask.Id,
nextTask.DistroId, err)
}
// validate that the task can be run, if not fetch the next one in
// the queue
if shouldSkipTask(nextTask) {
evergreen.Logger.Logf(slogger.WARN, "Skipping task %v, which was "+
"picked up to be run but is not runnable - "+
"status (%v) activated (%v)", nextTask.Id, nextTask.Status,
nextTask.Activated)
continue
}
// record that the task was dispatched on the host
err = nextTask.MarkAsDispatched(assignedHost, time.Now())
if err != nil {
return nil, fmt.Errorf("error marking task %v as dispatched "+
"on host %v: %v", nextTask.Id, assignedHost.Id, err)
}
return nextTask, nil
}
return nil, nil
}
示例9: dBTests
// dBTests are the database verification tests for standard one file execution
func dBTests() {
task, err := model.FindTask("mocktaskid")
So(err, ShouldBeNil)
So(len(task.TestResults), ShouldNotEqual, 0)
Convey("along with the proper logs", func() {
// junit_3.xml
tl := dBFindOneTestLog(
"test.test_threads_replica_set_client.TestThreadsReplicaSet.test_safe_update",
)
So(tl.Lines[0], ShouldContainSubstring, "SKIPPED")
tl = dBFindOneTestLog("test.test_bson.TestBSON.test_basic_encode")
So(tl.Lines[0], ShouldContainSubstring, "AssertionError")
})
}
示例10: TestTaskFailures
func TestTaskFailures(t *testing.T) {
setupTlsConfigs(t)
testutil.ConfigureIntegrationTest(t, testConfig, "TestTaskFailures")
for tlsString, tlsConfig := range tlsConfigs {
for _, testSetup := range testSetups {
Convey(testSetup.testSpec, t, func() {
Convey("With agent running a failing test and live API server over "+tlsString, func() {
testTask, _, err := setupAPITestData(testConfig, "failing_task",
"linux-64", NoPatch, t)
testutil.HandleTestingErr(err, t, "Couldn't create test data: %v", err)
testServer, err := apiserver.CreateTestServer(testConfig, tlsConfig, plugin.APIPlugins, Verbose)
testutil.HandleTestingErr(err, t, "Couldn't create apiserver: %v", err)
testAgent, err := createAgent(testServer, testTask)
testutil.HandleTestingErr(err, t, "failed to create agent: %v")
// actually run the task.
// this function won't return until the whole thing is done.
testAgent.RunTask()
time.Sleep(100 * time.Millisecond)
testAgent.APILogger.FlushAndWait()
printLogsForTask(testTask.Id)
Convey("the pre and post-run scripts should have run", func() {
So(scanLogsForTask(testTask.Id, "executing the pre-run script"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "executing the post-run script!"), ShouldBeTrue)
Convey("the task should have run up until its first failure", func() {
So(scanLogsForTask(testTask.Id, "starting failing_task!"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "done with failing_task!"), ShouldBeFalse)
})
Convey("the tasks's final status should be FAILED", func() {
testTask, err = model.FindTask(testTask.Id)
testutil.HandleTestingErr(err, t, "Failed to find test task")
So(testTask.Status, ShouldEqual, evergreen.TaskFailed)
So(testTask.Details.Status, ShouldEqual, evergreen.TaskFailed)
So(testTask.Details.Description, ShouldEqual, "failing shell command")
So(testTask.Details.TimedOut, ShouldBeFalse)
So(testTask.Details.Type, ShouldEqual, model.SystemCommandType)
})
})
})
})
}
}
}
示例11: TestTaskAbortion
func TestTaskAbortion(t *testing.T) {
setupTlsConfigs(t)
testutil.ConfigureIntegrationTest(t, testConfig, "TestTaskAbortion")
for tlsString, tlsConfig := range tlsConfigs {
for _, testSetup := range testSetups {
Convey(testSetup.testSpec, t, func() {
Convey("With agent running a slow test and live API server over "+tlsString, func() {
testTask, _, err := setupAPITestData(testConfig, "very_slow_task", "linux-64", NoPatch, t)
testutil.HandleTestingErr(err, t, "Failed to find test task")
testServer, err := apiserver.CreateTestServer(testConfig, tlsConfig, plugin.APIPlugins, Verbose)
testutil.HandleTestingErr(err, t, "Couldn't create apiserver: %v", err)
testAgent, err := createAgent(testServer, testTask)
testutil.HandleTestingErr(err, t, "failed to create agent: %v")
Convey("when the abort signal is triggered on the task", func() {
go func() {
// Wait for a few seconds, then switch the task to aborted!
time.Sleep(3 * time.Second)
err := testTask.Abort("", true)
testutil.HandleTestingErr(err, t, "Failed to abort test task")
fmt.Println("aborted task.")
}()
// actually run the task.
// this function won't return until the whole thing is done.
_, err := testAgent.RunTask()
So(err, ShouldBeNil)
testAgent.APILogger.Flush()
time.Sleep(1 * time.Second)
printLogsForTask(testTask.Id)
Convey("the pre and post-run scripts should have run", func() {
So(scanLogsForTask(testTask.Id, "executing the pre-run script"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "executing the post-run script!"), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "Received abort signal - stopping."), ShouldBeTrue)
So(scanLogsForTask(testTask.Id, "done with very_slow_task!"), ShouldBeFalse)
testTask, err = model.FindTask(testTask.Id)
testutil.HandleTestingErr(err, t, "Failed to find test task")
So(testTask.Status, ShouldEqual, evergreen.TaskUndispatched)
})
})
})
})
}
}
}
示例12: getTaskStatus
// Returns a JSON response with the status of the specified task.
// The keys of the object are the test names.
func (restapi restAPI) getTaskStatus(w http.ResponseWriter, r *http.Request) {
taskId := mux.Vars(r)["task_id"]
task, err := model.FindTask(taskId)
if err != nil || task == nil {
msg := fmt.Sprintf("Error finding task '%v'", taskId)
statusCode := http.StatusNotFound
if err != nil {
evergreen.Logger.Logf(slogger.ERROR, "%v: %v", msg, err)
statusCode = http.StatusInternalServerError
}
restapi.WriteJSON(w, statusCode, responseError{Message: msg})
return
}
result := taskStatusContent{
Id: taskId,
Name: task.DisplayName,
Status: task.Status,
}
// Copy over the status details
result.StatusDetails.TimedOut = task.StatusDetails.TimedOut
result.StatusDetails.TimeoutStage = task.StatusDetails.TimeoutStage
// Copy over the test results
result.Tests = make(taskStatusByTest, len(task.TestResults))
for _, _testResult := range task.TestResults {
numSecs := _testResult.EndTime - _testResult.StartTime
testResult := taskTestResult{
Status: _testResult.Status,
TimeTaken: time.Duration(numSecs * float64(time.Second)),
Logs: taskTestLogURL{_testResult.URL},
}
result.Tests[_testResult.TestFile] = testResult
}
restapi.WriteJSON(w, http.StatusOK, result)
return
}
示例13: hostPage
func (uis *UIServer) hostPage(w http.ResponseWriter, r *http.Request) {
projCtx := MustHaveProjectContext(r)
vars := mux.Vars(r)
id := vars["host_id"]
h, err := host.FindOne(host.ById(id))
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
if h == nil {
http.Error(w, "Host not found", http.StatusNotFound)
return
}
events, err := event.Find(event.MostRecentHostEvents(id, 50))
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
runningTask := &model.Task{}
if h.RunningTask != "" {
runningTask, err = model.FindTask(h.RunningTask)
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
}
flashes := PopFlashes(uis.CookieStore, r, w)
uis.WriteHTML(w, http.StatusOK, struct {
Flashes []interface{}
Events []event.Event
Host *host.Host
RunningTask *model.Task
User *user.DBUser
ProjectData projectContext
}{flashes, events, h, runningTask, GetUser(r), projCtx},
"base", "host.html", "base_angular.html", "menu.html")
}
示例14: populateTaskBuildVersion
// populateTaskBuildVersion takes a task, build, and version ID and populates a projectContext
// with as many of the task, build, and version documents as possible.
// If any of the provided IDs is blank, they will be inferred from the more selective ones.
// Returns the project ID of the data found, which may be blank if the IDs are empty.
func (pc *projectContext) populateTaskBuildVersion(taskId, buildId, versionId string) (string, error) {
projectId := ""
var err error
// Fetch task if there's a task ID present; if we find one, populate build/version IDs from it
if len(taskId) > 0 {
pc.Task, err = model.FindTask(taskId)
if err != nil {
return "", err
}
if pc.Task != nil {
// override build and version ID with the ones this task belongs to
buildId = pc.Task.BuildId
versionId = pc.Task.Version
projectId = pc.Task.Project
}
}
// Fetch build if there's a build ID present; if we find one, populate version ID from it
if len(buildId) > 0 {
pc.Build, err = build.FindOne(build.ById(buildId))
if err != nil {
return "", err
}
if pc.Build != nil {
versionId = pc.Build.Version
projectId = pc.Build.Project
}
}
if len(versionId) > 0 {
pc.Version, err = version.FindOne(version.ById(versionId))
if err != nil {
return "", err
}
if pc.Version != nil {
projectId = pc.Version.Identifier
}
}
return projectId, nil
}
示例15: getHostsData
func getHostsData(includeSpawnedHosts bool) (*hostsData, error) {
data := &hostsData{}
// get all of the hosts
var dbHosts []host.Host
var err error
if includeSpawnedHosts {
dbHosts, err = host.Find(host.IsRunning)
} else {
dbHosts, err = host.Find(host.ByUserWithRunningStatus(evergreen.User))
}
if err != nil {
return nil, err
}
// convert the hosts to the ui models
uiHosts := make([]uiHost, len(dbHosts))
for idx, dbHost := range dbHosts {
// we only need the distro id for the hosts page
dbHost.Distro = distro.Distro{Id: dbHost.Distro.Id}
host := uiHost{
Host: dbHost,
RunningTask: nil,
}
uiHosts[idx] = host
// get the task running on this host
task, err := model.FindTask(dbHost.RunningTask)
if err != nil {
return nil, err
}
if task != nil {
uiHosts[idx].RunningTask = task
}
}
data.Hosts = uiHosts
return data, nil
}