2020-08-21 15:01:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-08-22 11:03:45 +00:00
|
|
|
"fmt"
|
2020-08-21 15:01:59 +00:00
|
|
|
"net"
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/accounting"
|
|
|
|
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container"
|
2020-08-21 15:01:59 +00:00
|
|
|
container "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
|
2020-08-22 11:03:45 +00:00
|
|
|
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-08-21 15:01:59 +00:00
|
|
|
object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
|
2020-08-22 14:36:34 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
|
|
sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
|
2020-08-22 11:03:45 +00:00
|
|
|
containerTransport "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc"
|
|
|
|
objectTransport "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
|
|
|
|
sessionTransport "github.com/nspcc-dev/neofs-node/pkg/network/transport/session/grpc"
|
2020-08-21 15:01:59 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2020-08-22 14:36:34 +00:00
|
|
|
type accountingSvcExec struct{}
|
2020-08-21 15:01:59 +00:00
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
type sessionSvc struct{}
|
2020-08-21 15:01:59 +00:00
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
type containerSvc struct{}
|
2020-08-21 15:01:59 +00:00
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
type objectSvc struct{}
|
2020-08-21 15:01:59 +00:00
|
|
|
|
|
|
|
func unimplementedErr(srv, call string) error {
|
2020-08-22 11:03:45 +00:00
|
|
|
return errors.Errorf("unimplemented API service call %s.%s", srv, call)
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 14:36:34 +00:00
|
|
|
func (s *accountingSvcExec) Balance(context.Context, *accounting.BalanceRequestBody) (*accounting.BalanceResponseBody, error) {
|
|
|
|
return new(accounting.BalanceResponseBody), nil
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 14:36:34 +00:00
|
|
|
func (s *sessionSvc) Create(context.Context, *session.CreateRequest) (*session.CreateResponse, error) {
|
2020-08-21 15:01:59 +00:00
|
|
|
return nil, unimplementedErr("Session", "Create")
|
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) Put(context.Context, *containerGRPC.PutRequest) (*containerGRPC.PutResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "Put")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) Delete(context.Context, *containerGRPC.DeleteRequest) (*containerGRPC.DeleteResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "Delete")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) Get(context.Context, *containerGRPC.GetRequest) (*containerGRPC.GetResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "Get")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) List(context.Context, *containerGRPC.ListRequest) (*containerGRPC.ListResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "List")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) SetExtendedACL(context.Context, *containerGRPC.SetExtendedACLRequest) (*containerGRPC.SetExtendedACLResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "SetExtendedACL")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) GetExtendedACL(context.Context, *containerGRPC.GetExtendedACLRequest) (*containerGRPC.GetExtendedACLResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "GetExtendedACL")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *objectSvc) Get(context.Context, *objectGRPC.GetRequest) (objectGRPC.GetObjectStreamer, error) {
|
|
|
|
return nil, unimplementedErr("Object", "Get")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *objectSvc) Put(context.Context) (objectGRPC.PutObjectStreamer, error) {
|
|
|
|
return nil, unimplementedErr("Object", "Put")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *objectSvc) Head(context.Context, *objectGRPC.HeadRequest) (*objectGRPC.HeadResponse, error) {
|
|
|
|
return nil, unimplementedErr("Object", "Put")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *objectSvc) Search(context.Context, *objectGRPC.SearchRequest) (objectGRPC.SearchObjectStreamer, error) {
|
|
|
|
return nil, unimplementedErr("Object", "Search")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *objectSvc) Delete(context.Context, *objectGRPC.DeleteRequest) (*objectGRPC.DeleteResponse, error) {
|
|
|
|
return nil, unimplementedErr("Object", "Delete")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *objectSvc) GetRange(context.Context, *objectGRPC.GetRangeRequest) (objectGRPC.GetRangeObjectStreamer, error) {
|
|
|
|
return nil, unimplementedErr("Object", "GetRange")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *objectSvc) GetRangeHash(context.Context, *objectGRPC.GetRangeHashRequest) (*objectGRPC.GetRangeHashResponse, error) {
|
2020-08-21 15:01:59 +00:00
|
|
|
return nil, unimplementedErr("Object", "GetRangeHash")
|
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func serveGRPC(c *cfg) {
|
2020-08-21 15:01:59 +00:00
|
|
|
lis, err := net.Listen("tcp", c.grpcAddr)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
2020-08-22 15:20:47 +00:00
|
|
|
c.grpcSrv = grpc.NewServer()
|
|
|
|
|
|
|
|
initAccountingService(c)
|
|
|
|
|
|
|
|
container.RegisterContainerServiceServer(c.grpcSrv, containerTransport.New(new(containerSvc)))
|
|
|
|
sessionGRPC.RegisterSessionServiceServer(c.grpcSrv, sessionTransport.New(new(sessionSvc)))
|
|
|
|
object.RegisterObjectServiceServer(c.grpcSrv, objectTransport.New(new(objectSvc)))
|
2020-08-22 11:03:45 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
c.wg.Add(1)
|
|
|
|
defer func() {
|
|
|
|
c.wg.Done()
|
|
|
|
}()
|
|
|
|
|
2020-08-22 15:20:47 +00:00
|
|
|
if err := c.grpcSrv.Serve(lis); err != nil {
|
2020-08-22 11:03:45 +00:00
|
|
|
fmt.Println("gRPC server error", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
c.wg.Add(1)
|
|
|
|
defer func() {
|
|
|
|
fmt.Println("gRPC server stopped gracefully")
|
|
|
|
fmt.Println("net listener stopped", lis.Addr())
|
|
|
|
c.wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
<-c.ctx.Done()
|
|
|
|
|
2020-08-22 15:20:47 +00:00
|
|
|
c.grpcSrv.GracefulStop()
|
2020-08-22 11:03:45 +00:00
|
|
|
}()
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|