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

Side by Side Diff: appengine/cmd/dm/deps/service.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: self review Created 4 years, 6 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
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 deps 5 package deps
6 6
7 import ( 7 import (
8 "github.com/golang/protobuf/proto" 8 "github.com/golang/protobuf/proto"
9 "github.com/luci/luci-go/appengine/cmd/dm/distributor"
9 "github.com/luci/luci-go/appengine/tumble" 10 "github.com/luci/luci-go/appengine/tumble"
10 dm "github.com/luci/luci-go/common/api/dm/service/v1" 11 dm "github.com/luci/luci-go/common/api/dm/service/v1"
11 "github.com/luci/luci-go/common/grpcutil" 12 "github.com/luci/luci-go/common/grpcutil"
12 "github.com/luci/luci-go/common/logging" 13 "github.com/luci/luci-go/common/logging"
13 "github.com/luci/luci-go/server/prpc" 14 "github.com/luci/luci-go/server/prpc"
14 "golang.org/x/net/context" 15 "golang.org/x/net/context"
15 "google.golang.org/grpc" 16 "google.golang.org/grpc"
16 "google.golang.org/grpc/codes" 17 "google.golang.org/grpc/codes"
17 ) 18 )
18 19
19 const ek = logging.ErrorKey 20 const ek = logging.ErrorKey
20 21
21 type deps struct{} 22 type deps struct{}
22 23
23 var _ dm.DepsServer = (*deps)(nil) 24 var _ dm.DepsServer = (*deps)(nil)
24 25
25 func depsServerPrelude(c context.Context, methodName string, req proto.Message) (context.Context, error) { 26 func depsServerPrelude(reg distributor.Registry) func(context.Context, string, p roto.Message) (context.Context, error) {
26 » // Many of the DM request messages can be Normalize'd. This checks them for 27 » return func(c context.Context, methodName string, req proto.Message) (co ntext.Context, error) {
27 » // basic validity and normalizes cases where multiple representations ca n mean 28 » » // Many of the DM request messages can be Normalize'd. This chec ks them for
28 » // the same thing so that the service handlers only need to check for th e 29 » » // basic validity and normalizes cases where multiple representa tions can mean
29 » // canonical representation. 30 » » // the same thing so that the service handlers only need to chec k for the
30 » if norm, ok := req.(interface { 31 » » // canonical representation.
31 » » Normalize() error 32 » » if norm, ok := req.(interface {
32 » }); ok { 33 » » » Normalize() error
33 » » if err := norm.Normalize(); err != nil { 34 » » }); ok {
34 » » » return nil, grpcutil.MaybeLogErr(c, err, codes.InvalidAr gument, "invalid request") 35 » » » if err := norm.Normalize(); err != nil {
36 » » » » return nil, grpcutil.MaybeLogErr(c, err, codes.I nvalidArgument, "invalid request")
37 » » » }
35 } 38 }
39 c = distributor.WithRegistry(c, reg)
40 return c, nil
36 } 41 }
37 return c, nil
38 } 42 }
39 43
40 func newDecoratedDeps() dm.DepsServer { 44 func newDecoratedDeps(reg distributor.Registry) dm.DepsServer {
41 » return &dm.DecoratedDeps{Service: &deps{}, Prelude: depsServerPrelude} 45 » return &dm.DecoratedDeps{
46 » » Service: &deps{},
47 » » Prelude: depsServerPrelude(reg),
48 » }
42 } 49 }
43 50
44 // RegisterDepsServer registers an implementation of the dm.DepsServer with 51 // RegisterDepsServer registers an implementation of the dm.DepsServer with
45 // the provided Registrar. 52 // the provided Registrar.
46 func RegisterDepsServer(svr prpc.Registrar) { 53 func RegisterDepsServer(svr prpc.Registrar, reg distributor.Registry) {
47 » dm.RegisterDepsServer(svr, newDecoratedDeps()) 54 » dm.RegisterDepsServer(svr, newDecoratedDeps(reg))
48 } 55 }
49 56
50 // tumbleNow will run the mutation immediately, converting any non grpc errors 57 // tumbleNow will run the mutation immediately, converting any non grpc errors
51 // to codes.Internal. 58 // to codes.Internal.
52 func tumbleNow(c context.Context, m tumble.Mutation) error { 59 func tumbleNow(c context.Context, m tumble.Mutation) error {
53 err := tumble.RunMutation(c, m) 60 err := tumble.RunMutation(c, m)
54 if grpc.Code(err) == codes.Unknown { 61 if grpc.Code(err) == codes.Unknown {
55 logging.WithError(err).Errorf(c, "unknown error while applying m utation %v", m) 62 logging.WithError(err).Errorf(c, "unknown error while applying m utation %v", m)
56 err = grpcutil.Internal 63 err = grpcutil.Internal
57 } 64 }
65 logging.Fields{"root": m.Root(c)}.Infof(c, "tumbleNow success")
58 return err 66 return err
59 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698