-
Notifications
You must be signed in to change notification settings - Fork 402
/
storage.go
59 lines (48 loc) · 1.58 KB
/
storage.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
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package multinode
import (
"context"
"go.uber.org/zap"
"storj.io/common/rpc/rpcstatus"
"storj.io/storj/private/multinodepb"
"storj.io/storj/storagenode/apikeys"
"storj.io/storj/storagenode/monitor"
)
var _ multinodepb.DRPCStorageServer = (*StorageEndpoint)(nil)
// StorageEndpoint implements multinode storage endpoint.
//
// architecture: Endpoint
type StorageEndpoint struct {
log *zap.Logger
apiKeys *apikeys.Service
monitor *monitor.Service
}
// NewStorageEndpoint creates new multinode storage endpoint.
func NewStorageEndpoint(log *zap.Logger, apiKeys *apikeys.Service, monitor *monitor.Service) *StorageEndpoint {
return &StorageEndpoint{
log: log,
apiKeys: apiKeys,
monitor: monitor,
}
}
// DiskSpace returns disk space state.
func (storage *StorageEndpoint) DiskSpace(ctx context.Context, req *multinodepb.DiskSpaceRequest) (_ *multinodepb.DiskSpaceResponse, err error) {
defer mon.Task()(&ctx)(&err)
if err = authenticate(ctx, storage.apiKeys, req.GetHeader()); err != nil {
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
}
diskSpace, err := storage.monitor.DiskSpace(ctx)
if err != nil {
storage.log.Error("disk space internal error", zap.Error(err))
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
}
return &multinodepb.DiskSpaceResponse{
Allocated: diskSpace.Allocated,
UsedPieces: diskSpace.UsedForPieces,
UsedTrash: diskSpace.UsedForTrash,
Free: diskSpace.Free,
Available: diskSpace.Available,
Overused: diskSpace.Overused,
}, nil
}