Chromium Code Reviews| Index: appengine/cmd/milo/swarming/build.go |
| diff --git a/appengine/cmd/milo/swarming/build.go b/appengine/cmd/milo/swarming/build.go |
| index f102bd75995a5e1ce051d83f9110fde21e5c8cef..6dceef53752f50e76020bddf10d7b3abc074ac4a 100644 |
| --- a/appengine/cmd/milo/swarming/build.go |
| +++ b/appengine/cmd/milo/swarming/build.go |
| @@ -23,8 +23,6 @@ import ( |
| swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" |
| "github.com/luci/luci-go/common/clock" |
| "github.com/luci/luci-go/common/logdog/types" |
| - "github.com/luci/luci-go/common/logging" |
| - miloProto "github.com/luci/luci-go/common/proto/milo" |
| "github.com/luci/luci-go/common/transport" |
| ) |
| @@ -48,11 +46,14 @@ const ( |
| func resolveServer(server string) string { |
| // TODO(hinoka): configure this map in luci-config |
| - if server == "" || server == "default" || server == "dev" { |
| + switch server { |
| + case "", "default", "dev": |
| return "chromium-swarm-dev.appspot.com" |
| - } else if server == "prod" { |
| + |
| + case "prod": |
| return "chromium-swarm.appspot.com" |
| - } else { |
| + |
| + default: |
| return server |
| } |
| } |
| @@ -153,98 +154,6 @@ func getSwarming(c context.Context, server string, taskID string) ( |
| return sr, log, errLog |
| } |
| -// TODO(hinoka): This should go in a more generic file, when milo has more |
| -// than one page. |
| -func getNavi(taskID string, URL string) *resp.Navigation { |
| - navi := &resp.Navigation{} |
| - navi.PageTitle = &resp.Link{ |
| - Label: taskID, |
| - URL: URL, |
| - } |
| - navi.SiteTitle = &resp.Link{ |
| - Label: "Milo", |
| - URL: "/", |
| - } |
| - return navi |
| -} |
| - |
| -// Given a logdog/milo step, translate it to a BuildComponent struct. |
| -func miloBuildStep( |
| - c context.Context, url string, anno *miloProto.Step, name string) *resp.BuildComponent { |
| - url = strings.TrimSuffix(url, "/") |
| - comp := &resp.BuildComponent{} |
| - asc := anno.GetStepComponent() |
| - comp.Label = asc.Name |
| - switch asc.Status { |
| - case miloProto.Status_RUNNING: |
| - comp.Status = resp.Running |
| - |
| - case miloProto.Status_SUCCESS: |
| - comp.Status = resp.Success |
| - |
| - case miloProto.Status_FAILURE: |
| - if anno.GetFailureDetails() != nil { |
| - switch anno.GetFailureDetails().Type { |
| - case miloProto.FailureDetails_INFRA: |
| - comp.Status = resp.InfraFailure |
| - |
| - case miloProto.FailureDetails_DM_DEPENDENCY_FAILED: |
| - comp.Status = resp.DependencyFailure |
| - |
| - default: |
| - comp.Status = resp.Failure |
| - } |
| - } else { |
| - comp.Status = resp.Failure |
| - } |
| - |
| - case miloProto.Status_EXCEPTION: |
| - comp.Status = resp.InfraFailure |
| - |
| - // Missing the case of waiting on unfinished dependency... |
| - default: |
| - comp.Status = resp.NotRun |
| - } |
| - // Sub link is for one link per log that isn't stdio. |
| - for _, link := range asc.GetOtherLinks() { |
| - lds := link.GetLogdogStream() |
| - if lds == nil { |
| - logging.Warningf(c, "Warning: %v of %v has an empty logdog stream.", link, asc) |
| - continue // DNE??? |
| - } |
| - shortName := lds.Name[5 : len(lds.Name)-2] |
| - if strings.HasSuffix(lds.Name, "annotations") || strings.HasSuffix(lds.Name, "stdio") { |
| - // Skip the special ones. |
| - continue |
| - } |
| - newLink := &resp.Link{ |
| - Label: shortName, |
| - URL: url + "/" + lds.Name, |
| - } |
| - comp.SubLink = append(comp.SubLink, newLink) |
| - } |
| - |
| - // Main link is a link to the stdio. |
| - comp.MainLink = &resp.Link{ |
| - Label: "stdio", |
| - URL: strings.Join([]string{url, name, "stdio"}, "/"), |
| - } |
| - |
| - // This should always be a step. |
| - comp.Type = resp.Step |
| - |
| - // This should always be 0 |
| - comp.LevelsDeep = 0 |
| - |
| - // Timeswamapts |
| - comp.Started = asc.Started.Time().Format(time.RFC3339) |
| - |
| - // This should be the exact same thing. |
| - comp.Text = asc.Text |
| - |
| - return comp |
| -} |
| - |
| func taskProperties(sr *swarming.SwarmingRpcsTaskResult) *resp.PropertyGroup { |
| props := &resp.PropertyGroup{GroupName: "Swarming"} |
| if len(sr.CostsUsd) == 1 { |
| @@ -280,8 +189,16 @@ func tagsToProperties(tags []string) *resp.PropertyGroup { |
| return props |
| } |
| -func taskToBuild(c context.Context, sr *swarming.SwarmingRpcsTaskResult) (*resp.MiloBuild, error) { |
| - build := &resp.MiloBuild{} |
| +func taskToBuild(c context.Context, server string, sr *swarming.SwarmingRpcsTaskResult) (*resp.MiloBuild, error) { |
| + build := &resp.MiloBuild{ |
| + Summary: resp.BuildComponent{ |
| + Source: &resp.Link{ |
| + Label: "swarming task", |
|
Ryan Tseng
2016/06/22 19:14:45
Label should be the taskID, or "Task %s"
nodir
2016/06/22 20:40:08
Done.
|
| + URL: taskPageURL(server, sr.TaskId), |
| + }, |
| + }, |
| + } |
| + |
| switch sr.State { |
| case TaskRunning: |
| build.Summary.Status = resp.Running |
| @@ -319,6 +236,13 @@ func taskToBuild(c context.Context, sr *swarming.SwarmingRpcsTaskResult) (*resp. |
| build.PropertyGroup = append(build.PropertyGroup, props) |
| } |
| + if sr.BotId != "" { |
| + build.Summary.Bot = &resp.Link{ |
| + Label: "swarming bot", |
|
Ryan Tseng
2016/06/22 19:14:45
Label should just be the botID
nodir
2016/06/22 20:40:08
Done.
|
| + URL: botPageURL(server, sr.BotId), |
| + } |
| + } |
| + |
| // Build times. Swarming timestamps are UTC RFC3339Nano, but without the |
| // timezone information. Make them valid RFC3339Nano. |
| build.Summary.Started = sr.StartedTs + "Z" |
| @@ -384,7 +308,7 @@ func swarmingBuildImpl(c context.Context, URL string, server string, taskID stri |
| return nil, fmt.Errorf("Not A Milo Job") |
| } |
| - build, err := taskToBuild(c, sr) |
| + build, err := taskToBuild(c, server, sr) |
| if err != nil { |
| return nil, err |
| } |
| @@ -401,7 +325,7 @@ func swarmingBuildImpl(c context.Context, URL string, server string, taskID stri |
| Status: resp.InfraFailure, |
| SubLink: []*resp.Link{{ |
| Label: "swarming task", |
| - URL: taskPageURL(resolveServer(server), taskID), |
| + URL: taskPageURL(server, taskID), |
| }}, |
| }} |
| } else { |
| @@ -412,6 +336,13 @@ func swarmingBuildImpl(c context.Context, URL string, server string, taskID stri |
| } |
| // taskPageURL returns a URL to a human-consumable page of a swarming task. |
| +// Supports server aliases. |
| func taskPageURL(swarmingHostname, taskID string) string { |
| - return fmt.Sprintf("https://%s/user/task/%s", swarmingHostname, taskID) |
| + return fmt.Sprintf("https://%s/user/task/%s", resolveServer(swarmingHostname), taskID) |
| +} |
| + |
| +// botPageURL returns a URL to a human-consumable page of a swarming bot. |
| +// Supports server aliases. |
| +func botPageURL(swarmingHostname, botID string) string { |
| + return fmt.Sprintf("https://%s/restricted/bot/%s", resolveServer(swarmingHostname), botID) |
| } |