storj/storagenode/multinode/storage.go
Egon Elbre 86e698f572 pb: use *UnimplementedServer to avoid breaking API changes
Change-Id: I99a34eeb37ac4453411f273511710562a519f57a
2021-03-29 12:26:10 +03:00

62 lines
1.6 KiB
Go

// 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 {
multinodepb.DRPCStorageUnimplementedServer
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
}