2021-01-13 13:46:39 +00:00
|
|
|
package control
|
2021-01-13 12:49:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
2021-01-13 12:49:46 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HealthCheck returns health status of the local node.
|
|
|
|
//
|
|
|
|
// If request is unsigned or signed by disallowed key, permission error returns.
|
2021-01-13 13:46:39 +00:00
|
|
|
func (s *Server) HealthCheck(_ context.Context, req *control.HealthCheckRequest) (*control.HealthCheckResponse, error) {
|
2021-01-13 12:49:46 +00:00
|
|
|
// verify request
|
|
|
|
if err := s.isValidRequest(req); err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// create and fill response
|
2021-01-13 13:46:39 +00:00
|
|
|
resp := new(control.HealthCheckResponse)
|
2021-01-13 12:49:46 +00:00
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
body := new(control.HealthCheckResponse_Body)
|
2021-01-13 12:49:46 +00:00
|
|
|
resp.SetBody(body)
|
|
|
|
|
2021-01-15 09:42:31 +00:00
|
|
|
body.SetNetmapStatus(s.healthChecker.NetmapStatus())
|
2021-01-15 10:22:44 +00:00
|
|
|
body.SetHealthStatus(s.healthChecker.HealthStatus())
|
2021-01-13 12:49:46 +00:00
|
|
|
|
|
|
|
// sign the response
|
|
|
|
if err := SignMessage(s.key, resp); err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|