Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: milo/appengine/swarming/build.go

Issue 2765383002: Milo: Move instance configuration to luci-config (Closed)
Patch Set: Review Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « milo/appengine/buildbucket/html.go ('k') | milo/appengine/swarming/buildinfo.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package swarming 5 package swarming
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "net/http" 10 "net/http"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // TaskTimedOut means task started, but took too long. 50 // TaskTimedOut means task started, but took too long.
51 TaskTimedOut = "TIMED_OUT" 51 TaskTimedOut = "TIMED_OUT"
52 // TaskBotDied means task started but bot died. 52 // TaskBotDied means task started but bot died.
53 TaskBotDied = "BOT_DIED" 53 TaskBotDied = "BOT_DIED"
54 // TaskCanceled means the task was canceled. See CompletedTs to determin e whether it was started. 54 // TaskCanceled means the task was canceled. See CompletedTs to determin e whether it was started.
55 TaskCanceled = "CANCELED" 55 TaskCanceled = "CANCELED"
56 // TaskCompleted means task is complete. 56 // TaskCompleted means task is complete.
57 TaskCompleted = "COMPLETED" 57 TaskCompleted = "COMPLETED"
58 ) 58 )
59 59
60 func getSwarmingClient(c context.Context, server string) (*swarming.Service, err or) { 60 func getSwarmingClient(c context.Context, host string) (*swarming.Service, error ) {
61 c, _ = context.WithTimeout(c, 60*time.Second) 61 c, _ = context.WithTimeout(c, 60*time.Second)
62 t, err := auth.GetRPCTransport(c, auth.AsSelf) 62 t, err := auth.GetRPCTransport(c, auth.AsSelf)
63 if err != nil { 63 if err != nil {
64 return nil, err 64 return nil, err
65 } 65 }
66 sc, err := swarming.New(&http.Client{Transport: t}) 66 sc, err := swarming.New(&http.Client{Transport: t})
67 if err != nil { 67 if err != nil {
68 return nil, err 68 return nil, err
69 } 69 }
70 » sc.BasePath = fmt.Sprintf("https://%s/_ah/api/swarming/v1/", server) 70 » sc.BasePath = fmt.Sprintf("https://%s/_ah/api/swarming/v1/", host)
71 return sc, nil 71 return sc, nil
72 } 72 }
73 73
74 // swarmingService is an interface that fetches data from Swarming. 74 // swarmingService is an interface that fetches data from Swarming.
75 // 75 //
76 // In production, this is fetched from a Swarming server. For testing, this can 76 // In production, this is fetched from a Swarming server. For testing, this can
77 // be replaced with a mock. 77 // be replaced with a mock.
78 type swarmingService interface { 78 type swarmingService interface {
79 getHost() string 79 getHost() string
80 getSwarmingResult(c context.Context, taskID string) (*swarming.SwarmingR pcsTaskResult, error) 80 getSwarmingResult(c context.Context, taskID string) (*swarming.SwarmingR pcsTaskResult, error)
81 getSwarmingRequest(c context.Context, taskID string) (*swarming.Swarming RpcsTaskRequest, error) 81 getSwarmingRequest(c context.Context, taskID string) (*swarming.Swarming RpcsTaskRequest, error)
82 getTaskOutput(c context.Context, taskID string) (string, error) 82 getTaskOutput(c context.Context, taskID string) (string, error)
83 } 83 }
84 84
85 type prodSwarmingService struct { 85 type prodSwarmingService struct {
86 host string 86 host string
87 client *swarming.Service 87 client *swarming.Service
88 } 88 }
89 89
90 func newProdService(c context.Context, server string) (*prodSwarmingService, err or) { 90 func newProdService(c context.Context, host string) (*prodSwarmingService, error ) {
91 » client, err := getSwarmingClient(c, server) 91 » client, err := getSwarmingClient(c, host)
92 if err != nil { 92 if err != nil {
93 return nil, err 93 return nil, err
94 } 94 }
95 return &prodSwarmingService{ 95 return &prodSwarmingService{
96 » » host: server, 96 » » host: host,
97 client: client, 97 client: client,
98 }, nil 98 }, nil
99 } 99 }
100 100
101 func (svc *prodSwarmingService) getHost() string { return svc.host } 101 func (svc *prodSwarmingService) getHost() string { return svc.host }
102 102
103 func (svc *prodSwarmingService) getSwarmingResult(c context.Context, taskID stri ng) (*swarming.SwarmingRpcsTaskResult, error) { 103 func (svc *prodSwarmingService) getSwarmingResult(c context.Context, taskID stri ng) (*swarming.SwarmingRpcsTaskResult, error) {
104 return svc.client.Task.Result(taskID).Context(c).Do() 104 return svc.client.Task.Result(taskID).Context(c).Do()
105 } 105 }
106 106
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 for _, tag := range v { 734 for _, tag := range v {
735 var value string 735 var value string
736 parts := strings.SplitN(tag, ":", 2) 736 parts := strings.SplitN(tag, ":", 2)
737 if len(parts) == 2 { 737 if len(parts) == 2 {
738 value = parts[1] 738 value = parts[1]
739 } 739 }
740 res[parts[0]] = value 740 res[parts[0]] = value
741 } 741 }
742 return res 742 return res
743 } 743 }
OLDNEW
« no previous file with comments | « milo/appengine/buildbucket/html.go ('k') | milo/appengine/swarming/buildinfo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698