-
Notifications
You must be signed in to change notification settings - Fork 88
/
action_cache_server.go
66 lines (60 loc) · 2.23 KB
/
action_cache_server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package grpcservers
import (
"context"
remoteexecution "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2"
"github.com/buildbarn/bb-storage/pkg/blobstore"
"github.com/buildbarn/bb-storage/pkg/blobstore/buffer"
"github.com/buildbarn/bb-storage/pkg/digest"
"github.com/buildbarn/bb-storage/pkg/util"
)
type actionCacheServer struct {
blobAccess blobstore.BlobAccess
maximumMessageSizeBytes int
}
// NewActionCacheServer creates a GRPC service for serving the contents
// of a Bazel Action Cache (AC) to Bazel.
func NewActionCacheServer(blobAccess blobstore.BlobAccess, maximumMessageSizeBytes int) remoteexecution.ActionCacheServer {
return &actionCacheServer{
blobAccess: blobAccess,
maximumMessageSizeBytes: maximumMessageSizeBytes,
}
}
func (s *actionCacheServer) GetActionResult(ctx context.Context, in *remoteexecution.GetActionResultRequest) (*remoteexecution.ActionResult, error) {
instanceName, err := digest.NewInstanceName(in.InstanceName)
if err != nil {
return nil, util.StatusWrapf(err, "Invalid instance name %#v", in.InstanceName)
}
digestFunction, err := instanceName.GetDigestFunction(in.DigestFunction, len(in.ActionDigest.GetHash()))
if err != nil {
return nil, err
}
digest, err := digestFunction.NewDigestFromProto(in.ActionDigest)
if err != nil {
return nil, err
}
actionResult, err := s.blobAccess.Get(ctx, digest).ToProto(
&remoteexecution.ActionResult{},
s.maximumMessageSizeBytes)
if err != nil {
return nil, err
}
return actionResult.(*remoteexecution.ActionResult), nil
}
func (s *actionCacheServer) UpdateActionResult(ctx context.Context, in *remoteexecution.UpdateActionResultRequest) (*remoteexecution.ActionResult, error) {
instanceName, err := digest.NewInstanceName(in.InstanceName)
if err != nil {
return nil, util.StatusWrapf(err, "Invalid instance name %#v", in.InstanceName)
}
digestFunction, err := instanceName.GetDigestFunction(in.DigestFunction, len(in.ActionDigest.GetHash()))
if err != nil {
return nil, err
}
digest, err := digestFunction.NewDigestFromProto(in.ActionDigest)
if err != nil {
return nil, err
}
return in.ActionResult, s.blobAccess.Put(
ctx,
digest,
buffer.NewProtoBufferFromProto(in.ActionResult, buffer.UserProvided))
}