| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 | 9 |
| 10 "github.com/luci/luci-go/common/config" | |
| 11 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" | 10 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" |
| 12 "github.com/luci/luci-go/logdog/common/types" | 11 "github.com/luci/luci-go/logdog/common/types" |
| 12 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 13 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 14 ) | 14 ) |
| 15 | 15 |
| 16 // ListResult is a single returned list entry. | 16 // ListResult is a single returned list entry. |
| 17 type ListResult struct { | 17 type ListResult struct { |
| 18 // Project is the project that this result is bound to. | 18 // Project is the project that this result is bound to. |
| 19 » Project config.ProjectName | 19 » Project cfgtypes.ProjectName |
| 20 // PathBase is the base part of the list path. This will match the base
that | 20 // PathBase is the base part of the list path. This will match the base
that |
| 21 // the list was pulled from. | 21 // the list was pulled from. |
| 22 PathBase types.StreamPath | 22 PathBase types.StreamPath |
| 23 // Name is the name of this component, relative to PathBase. | 23 // Name is the name of this component, relative to PathBase. |
| 24 Name string | 24 Name string |
| 25 // Stream is true if this list component is a stream component. Otherwis
e, | 25 // Stream is true if this list component is a stream component. Otherwis
e, |
| 26 // it's an intermediate path component. | 26 // it's an intermediate path component. |
| 27 Stream bool | 27 Stream bool |
| 28 | 28 |
| 29 // State is the state of the log stream. This will be populated if this
is a | 29 // State is the state of the log stream. This will be populated if this
is a |
| (...skipping 23 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 // Purged, if true, requests that purged log streams are included in the
list | 54 // Purged, if true, requests that purged log streams are included in the
list |
| 55 // results. This will result in an error if the user is not privileged t
o see | 55 // results. This will result in an error if the user is not privileged t
o see |
| 56 // purged logs. | 56 // purged logs. |
| 57 Purged bool | 57 Purged bool |
| 58 } | 58 } |
| 59 | 59 |
| 60 // List executes a log stream hierarchy listing for the specified path. | 60 // List executes a log stream hierarchy listing for the specified path. |
| 61 // | 61 // |
| 62 // If project is the empty string, a top-level project listing will be returned. | 62 // If project is the empty string, a top-level project listing will be returned. |
| 63 func (c *Client) List(ctx context.Context, project config.ProjectName, pathBase
string, o ListOptions, cb ListCallback) error { | 63 func (c *Client) List(ctx context.Context, project cfgtypes.ProjectName, pathBas
e string, o ListOptions, cb ListCallback) error { |
| 64 req := logdog.ListRequest{ | 64 req := logdog.ListRequest{ |
| 65 Project: string(project), | 65 Project: string(project), |
| 66 PathBase: pathBase, | 66 PathBase: pathBase, |
| 67 StreamOnly: o.StreamsOnly, | 67 StreamOnly: o.StreamsOnly, |
| 68 State: o.State, | 68 State: o.State, |
| 69 IncludePurged: o.Purged, | 69 IncludePurged: o.Purged, |
| 70 } | 70 } |
| 71 | 71 |
| 72 for { | 72 for { |
| 73 resp, err := c.C.List(ctx, &req) | 73 resp, err := c.C.List(ctx, &req) |
| 74 if err != nil { | 74 if err != nil { |
| 75 return normalizeError(err) | 75 return normalizeError(err) |
| 76 } | 76 } |
| 77 | 77 |
| 78 for _, s := range resp.Components { | 78 for _, s := range resp.Components { |
| 79 lr := ListResult{ | 79 lr := ListResult{ |
| 80 » » » » Project: config.ProjectName(resp.Project), | 80 » » » » Project: cfgtypes.ProjectName(resp.Project), |
| 81 PathBase: types.StreamPath(resp.PathBase), | 81 PathBase: types.StreamPath(resp.PathBase), |
| 82 Name: s.Name, | 82 Name: s.Name, |
| 83 } | 83 } |
| 84 switch s.Type { | 84 switch s.Type { |
| 85 case logdog.ListResponse_Component_PATH: | 85 case logdog.ListResponse_Component_PATH: |
| 86 break | 86 break |
| 87 | 87 |
| 88 case logdog.ListResponse_Component_STREAM: | 88 case logdog.ListResponse_Component_STREAM: |
| 89 lr.Stream = true | 89 lr.Stream = true |
| 90 if s.State != nil { | 90 if s.State != nil { |
| 91 lr.State, err = loadLogStream(resp.Proje
ct, lr.FullPath(), s.State, s.Desc) | 91 lr.State, err = loadLogStream(resp.Proje
ct, lr.FullPath(), s.State, s.Desc) |
| 92 if err != nil { | 92 if err != nil { |
| 93 return fmt.Errorf("failed to loa
d stream state: %v", err) | 93 return fmt.Errorf("failed to loa
d stream state: %v", err) |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 case logdog.ListResponse_Component_PROJECT: | 97 case logdog.ListResponse_Component_PROJECT: |
| 98 » » » » lr.Project = config.ProjectName(lr.Name) | 98 » » » » lr.Project = cfgtypes.ProjectName(lr.Name) |
| 99 } | 99 } |
| 100 | 100 |
| 101 if !cb(&lr) { | 101 if !cb(&lr) { |
| 102 return nil | 102 return nil |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 if resp.Next == "" { | 106 if resp.Next == "" { |
| 107 return nil | 107 return nil |
| 108 } | 108 } |
| 109 req.Next = resp.Next | 109 req.Next = resp.Next |
| 110 } | 110 } |
| 111 } | 111 } |
| OLD | NEW |