| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package services | 5 package services |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 ds "github.com/luci/gae/service/datastore" | 8 ds "github.com/luci/gae/service/datastore" |
| 9 "github.com/luci/luci-go/appengine/logdog/coordinator" | 9 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 10 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" | 10 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" |
| 11 "github.com/luci/luci-go/common/clock" |
| 11 "github.com/luci/luci-go/common/grpcutil" | 12 "github.com/luci/luci-go/common/grpcutil" |
| 12 "github.com/luci/luci-go/common/logdog/types" | 13 "github.com/luci/luci-go/common/logdog/types" |
| 13 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
| 15 "github.com/luci/luci-go/common/proto/google" |
| 14 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
| 15 "google.golang.org/grpc/codes" | 17 "google.golang.org/grpc/codes" |
| 16 ) | 18 ) |
| 17 | 19 |
| 18 // LoadStream loads the log stream state. | 20 // LoadStream loads the log stream state. |
| 19 func (b *Server) LoadStream(c context.Context, req *logdog.LoadStreamRequest) (*
logdog.LoadStreamResponse, error) { | 21 func (s *Server) LoadStream(c context.Context, req *logdog.LoadStreamRequest) (*
logdog.LoadStreamResponse, error) { |
| 20 » if err := Auth(c); err != nil { | 22 » svc := s.GetServices() |
| 23 » if err := Auth(c, svc); err != nil { |
| 21 return nil, err | 24 return nil, err |
| 22 } | 25 } |
| 23 | 26 |
| 24 path := types.StreamPath(req.Path) | 27 path := types.StreamPath(req.Path) |
| 25 if err := path.Validate(); err != nil { | 28 if err := path.Validate(); err != nil { |
| 26 return nil, grpcutil.Errf(codes.InvalidArgument, "Invalid path (
%s): %s", path, err) | 29 return nil, grpcutil.Errf(codes.InvalidArgument, "Invalid path (
%s): %s", path, err) |
| 27 } | 30 } |
| 28 log.Fields{ | 31 log.Fields{ |
| 29 "path": path, | 32 "path": path, |
| 30 }.Infof(c, "Loading log stream state.") | 33 }.Infof(c, "Loading log stream state.") |
| 31 | 34 |
| 32 ls := coordinator.LogStreamFromPath(path) | 35 ls := coordinator.LogStreamFromPath(path) |
| 33 switch err := ds.Get(c).Get(ls); err { | 36 switch err := ds.Get(c).Get(ls); err { |
| 34 case nil: | 37 case nil: |
| 35 // The log stream loaded successfully. | 38 // The log stream loaded successfully. |
| 36 resp := logdog.LoadStreamResponse{ | 39 resp := logdog.LoadStreamResponse{ |
| 37 State: loadLogStreamState(ls), | 40 State: loadLogStreamState(ls), |
| 38 } | 41 } |
| 39 if req.Desc { | 42 if req.Desc { |
| 40 resp.Desc = ls.Descriptor | 43 resp.Desc = ls.Descriptor |
| 41 } | 44 } |
| 45 resp.ArchivalKey = ls.ArchivalKey |
| 46 resp.Age = google.NewDuration(ds.RoundTime(clock.Now(c)).Sub(ls.
Created)) |
| 47 |
| 48 log.Fields{ |
| 49 "path": path, |
| 50 "hash": ls.HashID, |
| 51 "terminalIndex": resp.State.TerminalIndex, |
| 52 "archived": resp.State.Archived, |
| 53 "purged": resp.State.Purged, |
| 54 "age": resp.Age.Duration(), |
| 55 "archivalKeySize": len(resp.ArchivalKey), |
| 56 }.Infof(c, "Successfully loaded log stream state.") |
| 42 return &resp, nil | 57 return &resp, nil |
| 43 | 58 |
| 44 case ds.ErrNoSuchEntity: | 59 case ds.ErrNoSuchEntity: |
| 45 return nil, grpcutil.Errf(codes.NotFound, "Log stream was not fo
und.") | 60 return nil, grpcutil.Errf(codes.NotFound, "Log stream was not fo
und.") |
| 46 | 61 |
| 47 default: | 62 default: |
| 48 log.WithError(err).Errorf(c, "Failed to load log stream.") | 63 log.WithError(err).Errorf(c, "Failed to load log stream.") |
| 49 return nil, grpcutil.Internal | 64 return nil, grpcutil.Internal |
| 50 } | 65 } |
| 51 } | 66 } |
| OLD | NEW |