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

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

Issue 2667363002: milo: Add a build info Swarming implementation. (Closed)
Patch Set: Created 3 years, 10 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/buildinfo/service.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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return sc, nil 66 return sc, nil
67 } 67 }
68 68
69 // swarmingService is an interface that fetches data from Swarming. 69 // swarmingService is an interface that fetches data from Swarming.
70 // 70 //
71 // In production, this is fetched from a Swarming server. For testing, this can 71 // In production, this is fetched from a Swarming server. For testing, this can
72 // be replaced with a mock. 72 // be replaced with a mock.
73 type swarmingService interface { 73 type swarmingService interface {
74 getHost() string 74 getHost() string
75 getSwarmingResult(c context.Context, taskID string) (*swarming.SwarmingR pcsTaskResult, error) 75 getSwarmingResult(c context.Context, taskID string) (*swarming.SwarmingR pcsTaskResult, error)
76 getSwarmingRequest(c context.Context, taskID string) (*swarming.Swarming RpcsTaskRequest, error)
76 getTaskOutput(c context.Context, taskID string) (string, error) 77 getTaskOutput(c context.Context, taskID string) (string, error)
77 } 78 }
78 79
79 type prodSwarmingService struct { 80 type prodSwarmingService struct {
80 host string 81 host string
81 client *swarming.Service 82 client *swarming.Service
82 } 83 }
83 84
84 func newProdService(c context.Context, server string) (*prodSwarmingService, err or) { 85 func newProdService(c context.Context, server string) (*prodSwarmingService, err or) {
85 client, err := getSwarmingClient(c, server) 86 client, err := getSwarmingClient(c, server)
(...skipping 13 matching lines...) Expand all
99 } 100 }
100 101
101 func (svc *prodSwarmingService) getTaskOutput(c context.Context, taskID string) (string, error) { 102 func (svc *prodSwarmingService) getTaskOutput(c context.Context, taskID string) (string, error) {
102 stdout, err := svc.client.Task.Stdout(taskID).Context(c).Do() 103 stdout, err := svc.client.Task.Stdout(taskID).Context(c).Do()
103 if err != nil { 104 if err != nil {
104 return "", err 105 return "", err
105 } 106 }
106 return stdout.Output, nil 107 return stdout.Output, nil
107 } 108 }
108 109
110 func (svc *prodSwarmingService) getSwarmingRequest(c context.Context, taskID str ing) (*swarming.SwarmingRpcsTaskRequest, error) {
111 return svc.client.Task.Request(taskID).Context(c).Do()
112 }
113
109 type swarmingFetch struct { 114 type swarmingFetch struct {
115 fetchReq bool
116 req *swarming.SwarmingRpcsTaskRequest
117
110 fetchRes bool 118 fetchRes bool
111 res *swarming.SwarmingRpcsTaskResult 119 res *swarming.SwarmingRpcsTaskResult
112 120
113 fetchLog bool 121 fetchLog bool
114 log string 122 log string
115 logErr error 123 logErr error
116 } 124 }
117 125
118 // get fetches (in parallel) the components that it is configured to fetch. 126 // get fetches (in parallel) the components that it is configured to fetch.
119 // 127 //
120 // After fetching, get performs an ACL check to confirm that the user is 128 // After fetching, get performs an ACL check to confirm that the user is
121 // permitted to view the resulting data. If this check fails, get returns 129 // permitted to view the resulting data. If this check fails, get returns
122 // errNotMiloJob. 130 // errNotMiloJob.
123 func (f *swarmingFetch) get(c context.Context, svc swarmingService, taskID strin g) error { 131 func (f *swarmingFetch) get(c context.Context, svc swarmingService, taskID strin g) error {
124 err := parallel.FanOutIn(func(workC chan<- func() error) { 132 err := parallel.FanOutIn(func(workC chan<- func() error) {
133 if f.fetchReq {
134 workC <- func() (err error) {
135 f.req, err = svc.getSwarmingRequest(c, taskID)
136 return
137 }
138 }
139
125 if f.fetchRes { 140 if f.fetchRes {
126 workC <- func() (err error) { 141 workC <- func() (err error) {
127 f.res, err = svc.getSwarmingResult(c, taskID) 142 f.res, err = svc.getSwarmingResult(c, taskID)
128 return 143 return
129 } 144 }
130 } 145 }
131 146
132 if f.fetchLog { 147 if f.fetchLog {
133 workC <- func() error { 148 workC <- func() error {
134 f.log, f.logErr = svc.getTaskOutput(c, taskID) 149 f.log, f.logErr = svc.getTaskOutput(c, taskID)
135 return nil 150 return nil
136 } 151 }
137 } 152 }
138 }) 153 })
139 if err != nil { 154 if err != nil {
140 return err 155 return err
141 } 156 }
142 157
143 // Current ACL implementation: error if this is not a Milo job. 158 // Current ACL implementation: error if this is not a Milo job.
144 switch { 159 switch {
160 case f.fetchReq:
161 if !isMiloJob(f.req.Tags) {
162 return errNotMiloJob
163 }
145 case f.fetchRes: 164 case f.fetchRes:
146 if !isMiloJob(f.res.Tags) { 165 if !isMiloJob(f.res.Tags) {
147 return errNotMiloJob 166 return errNotMiloJob
148 } 167 }
149 default: 168 default:
150 // No metadata to decide if this is a Milo job, so assume that i t is not. 169 // No metadata to decide if this is a Milo job, so assume that i t is not.
151 return errNotMiloJob 170 return errNotMiloJob
152 } 171 }
153 172
154 if f.fetchRes && f.logErr != nil { 173 if f.fetchRes && f.logErr != nil {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 case *miloProto.Link_Url: 541 case *miloProto.Link_Url:
523 return &resp.Link{ 542 return &resp.Link{
524 Label: l.Label, 543 Label: l.Label,
525 URL: t.Url, 544 URL: t.Url,
526 } 545 }
527 546
528 default: 547 default:
529 return nil 548 return nil
530 } 549 }
531 } 550 }
OLDNEW
« no previous file with comments | « milo/appengine/buildinfo/service.go ('k') | milo/appengine/swarming/buildinfo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698