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

Side by Side Diff: milo/buildsource/rawpresentation/build.go

Issue 2977863002: [milo] Refactor all html knowledge out of backends. (Closed)
Patch Set: now with case insensitivity Created 3 years, 5 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/buildsource/id.go ('k') | milo/buildsource/rawpresentation/html.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 2016 The LUCI Authors. 1 // Copyright 2016 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package rawpresentation 15 package rawpresentation
16 16
17 import ( 17 import (
18 » "errors" 18 » "strings"
19 » "fmt"
20 "time" 19 "time"
21 20
21 "github.com/golang/protobuf/proto"
22 "golang.org/x/net/context"
23
24 "github.com/luci/luci-go/common/errors"
22 log "github.com/luci/luci-go/common/logging" 25 log "github.com/luci/luci-go/common/logging"
23 "github.com/luci/luci-go/common/proto/google" 26 "github.com/luci/luci-go/common/proto/google"
24 miloProto "github.com/luci/luci-go/common/proto/milo" 27 miloProto "github.com/luci/luci-go/common/proto/milo"
25 "github.com/luci/luci-go/logdog/api/logpb" 28 "github.com/luci/luci-go/logdog/api/logpb"
26 "github.com/luci/luci-go/logdog/client/coordinator" 29 "github.com/luci/luci-go/logdog/client/coordinator"
27 "github.com/luci/luci-go/logdog/common/types" 30 "github.com/luci/luci-go/logdog/common/types"
28 "github.com/luci/luci-go/logdog/common/viewer" 31 "github.com/luci/luci-go/logdog/common/viewer"
29 "github.com/luci/luci-go/luci_config/common/cfgtypes" 32 "github.com/luci/luci-go/luci_config/common/cfgtypes"
30 "github.com/luci/luci-go/milo/api/resp" 33 "github.com/luci/luci-go/milo/api/resp"
31 "github.com/luci/luci-go/milo/buildsource/rawpresentation/internal" 34 "github.com/luci/luci-go/milo/buildsource/rawpresentation/internal"
32 35 » "github.com/luci/luci-go/milo/common"
33 » "github.com/golang/protobuf/proto"
34 » "golang.org/x/net/context"
35 ) 36 )
36 37
37 const ( 38 const (
38 // intermediateCacheLifetime is the amount of time to cache intermediate (non- 39 // intermediateCacheLifetime is the amount of time to cache intermediate (non-
39 // terminal) annotation streams. Terminal annotation streams are cached 40 // terminal) annotation streams. Terminal annotation streams are cached
40 // indefinitely. 41 // indefinitely.
41 intermediateCacheLifetime = 10 * time.Second 42 intermediateCacheLifetime = 10 * time.Second
42 43
43 // defaultLogDogHost is the default LogDog host, if one isn't specified via 44 // defaultLogDogHost is the default LogDog host, if one isn't specified via
44 // query string. 45 // query string.
45 defaultLogDogHost = "luci-logdog.appspot.com" 46 defaultLogDogHost = "luci-logdog.appspot.com"
46 ) 47 )
47 48
48 // AnnotationStream represents a LogDog annotation protobuf stream. 49 // AnnotationStream represents a LogDog annotation protobuf stream.
49 type AnnotationStream struct { 50 type AnnotationStream struct {
50 Project cfgtypes.ProjectName 51 Project cfgtypes.ProjectName
51 Path types.StreamPath 52 Path types.StreamPath
52 53
53 // Client is the HTTP client to use for LogDog communication. 54 // Client is the HTTP client to use for LogDog communication.
54 Client *coordinator.Client 55 Client *coordinator.Client
55 56
56 // cs is the unmarshalled annotation stream Step and associated data. 57 // cs is the unmarshalled annotation stream Step and associated data.
57 cs internal.CachedStep 58 cs internal.CachedStep
58 } 59 }
59 60
60 // Normalize validates and normalizes the stream's parameters. 61 // Normalize validates and normalizes the stream's parameters.
61 func (as *AnnotationStream) Normalize() error { 62 func (as *AnnotationStream) Normalize() error {
62 if err := as.Project.Validate(); err != nil { 63 if err := as.Project.Validate(); err != nil {
63 » » return fmt.Errorf("Invalid project name: %s", as.Project) 64 » » return errors.Annotate(err, "Invalid project name: %s", as.Proje ct).Tag(common.CodeParameterError).Err()
64 } 65 }
65 66
66 if err := as.Path.Validate(); err != nil { 67 if err := as.Path.Validate(); err != nil {
67 » » return fmt.Errorf("Invalid log stream path %q: %s", as.Path, err ) 68 » » return errors.Annotate(err, "Invalid log stream path %q", as.Pat h).Tag(common.CodeParameterError).Err()
68 } 69 }
69 70
70 return nil 71 return nil
71 } 72 }
72 73
73 var errNotMilo = errors.New("Requested stream is not a Milo annotation protobuf" ) 74 var errNotMilo = errors.New("Requested stream is not a Milo annotation protobuf" )
74 var errNotDatagram = errors.New("Requested stream is not a datagram stream") 75 var errNotDatagram = errors.New("Requested stream is not a datagram stream")
75 var errNoEntries = errors.New("Log stream has no annotation entries") 76 var errNoEntries = errors.New("Log stream has no annotation entries")
76 77
77 // Fetch loads the annotation stream from LogDog. 78 // Fetch loads the annotation stream from LogDog.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if link.Label == "" { 225 if link.Label == "" {
225 link.Label = "unnamed" 226 link.Label = "unnamed"
226 } 227 }
227 return link 228 return link
228 229
229 default: 230 default:
230 // Don't know how to render. 231 // Don't know how to render.
231 return nil 232 return nil
232 } 233 }
233 } 234 }
235
236 // BuildID implements buildsource.ID.
237 type BuildID struct {
238 Host string
239 Project cfgtypes.ProjectName
240 Path types.StreamPath
241 }
242
243 // GetLog implements buildsource.ID.
244 func (b *BuildID) GetLog(context.Context, string) (string, bool, error) { panic( "not implemented") }
245
246 // Get implements buildsource.ID.
247 func (b *BuildID) Get(c context.Context) (*resp.MiloBuild, error) {
248 as := AnnotationStream{
249 Project: b.Project,
250 Path: b.Path,
251 }
252 if err := as.Normalize(); err != nil {
253 return nil, err
254 }
255
256 // Setup our LogDog client.
257 var err error
258 if as.Client, err = NewClient(c, b.Host); err != nil {
259 return nil, errors.Annotate(err, "generating LogDog Client").Err ()
260 }
261
262 // Load the Milo annotation protobuf from the annotation stream.
263 switch _, err := as.Fetch(c); errors.Unwrap(err) {
264 case nil, errNoEntries:
265
266 case coordinator.ErrNoSuchStream:
267 return nil, common.CodeNotFound.Tag().Apply(err)
268
269 case coordinator.ErrNoAccess:
270 return nil, common.CodeNoAccess.Tag().Apply(err)
271
272 case errNotMilo, errNotDatagram:
273 // The user requested a LogDog url that isn't a Milo annotation.
274 return nil, common.CodeParameterError.Tag().Apply(err)
275
276 default:
277 return nil, errors.Annotate(err, "failed to load stream").Err()
278 }
279
280 return as.toMiloBuild(c), nil
281 }
282
283 // NewBuildID generates a new un-validated BuildID.
284 func NewBuildID(host, project, path string) *BuildID {
285 return &BuildID{
286 strings.TrimSpace(host),
287 cfgtypes.ProjectName(project),
288 types.StreamPath(strings.Trim(path, "/")),
289 }
290 }
OLDNEW
« no previous file with comments | « milo/buildsource/id.go ('k') | milo/buildsource/rawpresentation/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698