2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-14 18:47:22 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package overlay
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-02-28 19:55:27 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2019-01-14 18:47:22 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Inspector is a gRPC service for inspecting overlay cache internals
|
|
|
|
type Inspector struct {
|
|
|
|
cache *Cache
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewInspector creates an Inspector
|
|
|
|
func NewInspector(cache *Cache) *Inspector {
|
|
|
|
return &Inspector{cache: cache}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CountNodes returns the number of nodes in the cache
|
|
|
|
func (srv *Inspector) CountNodes(ctx context.Context, req *pb.CountNodesRequest) (*pb.CountNodesResponse, error) {
|
|
|
|
overlayKeys, err := srv.cache.Inspect(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pb.CountNodesResponse{
|
|
|
|
Count: int64(len(overlayKeys)),
|
|
|
|
}, nil
|
|
|
|
}
|
2019-02-28 19:55:27 +00:00
|
|
|
|
|
|
|
// DumpNodes returns all of the nodes in the overlay cachea
|
|
|
|
func (srv *Inspector) DumpNodes(ctx context.Context, req *pb.DumpNodesRequest) (*pb.DumpNodesResponse, error) {
|
|
|
|
return &pb.DumpNodesResponse{}, errs.New("Not Implemented")
|
|
|
|
}
|
2019-03-25 22:25:09 +00:00
|
|
|
|
|
|
|
// GetStats returns the stats for a particular node ID
|
|
|
|
func (srv *Inspector) GetStats(ctx context.Context, req *pb.GetStatsRequest) (*pb.GetStatsResponse, error) {
|
2019-04-04 17:34:36 +01:00
|
|
|
node, err := srv.cache.Get(ctx, req.NodeId)
|
2019-03-25 22:25:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pb.GetStatsResponse{
|
2019-04-22 10:07:50 +01:00
|
|
|
AuditCount: node.Reputation.AuditCount,
|
|
|
|
AuditRatio: node.Reputation.AuditSuccessRatio,
|
|
|
|
UptimeCount: node.Reputation.UptimeCount,
|
|
|
|
UptimeRatio: node.Reputation.UptimeRatio,
|
2019-03-25 22:25:09 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateStats creates a node with specified stats
|
|
|
|
func (srv *Inspector) CreateStats(ctx context.Context, req *pb.CreateStatsRequest) (*pb.CreateStatsResponse, error) {
|
|
|
|
stats := &NodeStats{
|
|
|
|
AuditCount: req.AuditCount,
|
|
|
|
AuditSuccessCount: req.AuditSuccessCount,
|
|
|
|
UptimeCount: req.UptimeCount,
|
|
|
|
UptimeSuccessCount: req.UptimeSuccessCount,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := srv.cache.Create(ctx, req.NodeId, stats)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pb.CreateStatsResponse{}, nil
|
|
|
|
}
|