| OLD | NEW |
| 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 coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "time" | 10 "time" |
| 11 | 11 |
| 12 "github.com/luci/luci-go/common/config" | |
| 13 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" | 12 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" |
| 14 "github.com/luci/luci-go/logdog/api/logpb" | 13 "github.com/luci/luci-go/logdog/api/logpb" |
| 15 "github.com/luci/luci-go/logdog/common/types" | 14 "github.com/luci/luci-go/logdog/common/types" |
| 15 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 16 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
| 17 ) | 17 ) |
| 18 | 18 |
| 19 // StreamState represents the client-side state of the log stream. | 19 // StreamState represents the client-side state of the log stream. |
| 20 // | 20 // |
| 21 // It is a type-promoted version of logdog.LogStreamState. | 21 // It is a type-promoted version of logdog.LogStreamState. |
| 22 type StreamState struct { | 22 type StreamState struct { |
| 23 // Created is the time, represented as a UTC RFC3339 string, when the lo
g | 23 // Created is the time, represented as a UTC RFC3339 string, when the lo
g |
| 24 // stream was created. | 24 // stream was created. |
| 25 Created time.Time | 25 Created time.Time |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 ArchiveDataURL string | 47 ArchiveDataURL string |
| 48 | 48 |
| 49 // Purged indicates the purged state of a log. A log that has been purge
d is | 49 // Purged indicates the purged state of a log. A log that has been purge
d is |
| 50 // only acknowledged to administrative clients. | 50 // only acknowledged to administrative clients. |
| 51 Purged bool | 51 Purged bool |
| 52 } | 52 } |
| 53 | 53 |
| 54 // LogStream is returned metadata about a log stream. | 54 // LogStream is returned metadata about a log stream. |
| 55 type LogStream struct { | 55 type LogStream struct { |
| 56 // Project is the log stream's project. | 56 // Project is the log stream's project. |
| 57 » Project config.ProjectName | 57 » Project cfgtypes.ProjectName |
| 58 // Path is the path of the log stream. | 58 // Path is the path of the log stream. |
| 59 Path types.StreamPath | 59 Path types.StreamPath |
| 60 | 60 |
| 61 // Desc is the log stream's descriptor. | 61 // Desc is the log stream's descriptor. |
| 62 Desc logpb.LogStreamDescriptor | 62 Desc logpb.LogStreamDescriptor |
| 63 | 63 |
| 64 // State is the stream's current state. | 64 // State is the stream's current state. |
| 65 State StreamState | 65 State StreamState |
| 66 } | 66 } |
| 67 | 67 |
| 68 func loadLogStream(proj string, path types.StreamPath, s *logdog.LogStreamState,
d *logpb.LogStreamDescriptor) ( | 68 func loadLogStream(proj string, path types.StreamPath, s *logdog.LogStreamState,
d *logpb.LogStreamDescriptor) ( |
| 69 *LogStream, error) { | 69 *LogStream, error) { |
| 70 switch { | 70 switch { |
| 71 case s == nil: | 71 case s == nil: |
| 72 return nil, errors.New("missing required log state") | 72 return nil, errors.New("missing required log state") |
| 73 case d == nil: | 73 case d == nil: |
| 74 return nil, errors.New("missing required descriptor") | 74 return nil, errors.New("missing required descriptor") |
| 75 } | 75 } |
| 76 | 76 |
| 77 ls := LogStream{ | 77 ls := LogStream{ |
| 78 » » Project: config.ProjectName(proj), | 78 » » Project: cfgtypes.ProjectName(proj), |
| 79 Path: path, | 79 Path: path, |
| 80 Desc: *d, | 80 Desc: *d, |
| 81 State: StreamState{ | 81 State: StreamState{ |
| 82 Created: s.Created.Time(), | 82 Created: s.Created.Time(), |
| 83 TerminalIndex: types.MessageIndex(s.TerminalIndex), | 83 TerminalIndex: types.MessageIndex(s.TerminalIndex), |
| 84 Purged: s.Purged, | 84 Purged: s.Purged, |
| 85 }, | 85 }, |
| 86 } | 86 } |
| 87 if a := s.Archive; a != nil { | 87 if a := s.Archive; a != nil { |
| 88 ls.State.Archived = true | 88 ls.State.Archived = true |
| 89 ls.State.ArchiveIndexURL = a.IndexUrl | 89 ls.State.ArchiveIndexURL = a.IndexUrl |
| 90 ls.State.ArchiveStreamURL = a.StreamUrl | 90 ls.State.ArchiveStreamURL = a.StreamUrl |
| 91 ls.State.ArchiveDataURL = a.DataUrl | 91 ls.State.ArchiveDataURL = a.DataUrl |
| 92 } | 92 } |
| 93 return &ls, nil | 93 return &ls, nil |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Stream is an interface to Coordinator stream-level commands. It is bound to | 96 // Stream is an interface to Coordinator stream-level commands. It is bound to |
| 97 // and operates on a single log stream path. | 97 // and operates on a single log stream path. |
| 98 type Stream struct { | 98 type Stream struct { |
| 99 // c is the Coordinator instance that this Stream is bound to. | 99 // c is the Coordinator instance that this Stream is bound to. |
| 100 c *Client | 100 c *Client |
| 101 | 101 |
| 102 // project is this stream's project. | 102 // project is this stream's project. |
| 103 » project config.ProjectName | 103 » project cfgtypes.ProjectName |
| 104 // path is the log stream's prefix. | 104 // path is the log stream's prefix. |
| 105 path types.StreamPath | 105 path types.StreamPath |
| 106 } | 106 } |
| 107 | 107 |
| 108 // State fetches the LogStreamDescriptor for a given log stream. | 108 // State fetches the LogStreamDescriptor for a given log stream. |
| 109 func (s *Stream) State(ctx context.Context) (*LogStream, error) { | 109 func (s *Stream) State(ctx context.Context) (*LogStream, error) { |
| 110 req := logdog.GetRequest{ | 110 req := logdog.GetRequest{ |
| 111 Project: string(s.project), | 111 Project: string(s.project), |
| 112 Path: string(s.path), | 112 Path: string(s.path), |
| 113 State: true, | 113 State: true, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 | 314 |
| 315 ls, err := loadLogStream(resp.Project, resp.Desc.Path(), resp.State, res
p.Desc) | 315 ls, err := loadLogStream(resp.Project, resp.Desc.Path(), resp.State, res
p.Desc) |
| 316 if err != nil { | 316 if err != nil { |
| 317 return fmt.Errorf("failde to load stream state: %v", err) | 317 return fmt.Errorf("failde to load stream state: %v", err) |
| 318 } | 318 } |
| 319 | 319 |
| 320 *stateP = *ls | 320 *stateP = *ls |
| 321 return nil | 321 return nil |
| 322 } | 322 } |
| OLD | NEW |