[#13] neofs-node: Use execution Object service in app

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-25 17:44:41 +03:00 committed by Alex Vanin
parent 486aeef5df
commit cd19183d3e
2 changed files with 71 additions and 93 deletions

View file

@ -1,104 +1,12 @@
package main
import (
"context"
"fmt"
"io"
"net"
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container"
"github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
type containerSvc struct{}
type objectSvc struct{}
func unimplementedErr(srv, call string) error {
return errors.Errorf("unimplemented API service call %s.%s", srv, call)
}
func (s *containerSvc) Put(context.Context, *containerGRPC.PutRequest) (*containerGRPC.PutResponse, error) {
return nil, unimplementedErr("Container", "Put")
}
func (s *containerSvc) Delete(context.Context, *containerGRPC.DeleteRequest) (*containerGRPC.DeleteResponse, error) {
return nil, unimplementedErr("Container", "Delete")
}
func (s *containerSvc) Get(context.Context, *containerGRPC.GetRequest) (*containerGRPC.GetResponse, error) {
return nil, unimplementedErr("Container", "Get")
}
func (s *containerSvc) List(context.Context, *containerGRPC.ListRequest) (*containerGRPC.ListResponse, error) {
return nil, unimplementedErr("Container", "List")
}
func (s *containerSvc) SetExtendedACL(context.Context, *containerGRPC.SetExtendedACLRequest) (*containerGRPC.SetExtendedACLResponse, error) {
return nil, unimplementedErr("Container", "SetExtendedACL")
}
func (s *containerSvc) GetExtendedACL(context.Context, *containerGRPC.GetExtendedACLRequest) (*containerGRPC.GetExtendedACLResponse, error) {
return nil, unimplementedErr("Container", "GetExtendedACL")
}
func (s *objectSvc) Get(context.Context, *object.GetRequest) (object.GetObjectStreamer, error) {
return nil, unimplementedErr("Object", "Get")
}
func (s *objectSvc) Put(context.Context) (object.PutObjectStreamer, error) {
return nil, unimplementedErr("Object", "Put")
}
func (s *objectSvc) Head(context.Context, *object.HeadRequest) (*object.HeadResponse, error) {
return nil, unimplementedErr("Object", "Put")
}
type simpleSearchStreamer struct {
count int
}
func (s *simpleSearchStreamer) Recv() (*object.SearchResponse, error) {
resp := new(object.SearchResponse)
body := new(object.SearchResponseBody)
resp.SetBody(body)
id := new(refs.ObjectID)
body.SetIDList([]*refs.ObjectID{id})
if s.count == 0 {
id.SetValue([]byte{1})
} else if s.count == 1 {
id.SetValue([]byte{2})
} else {
return nil, io.EOF
}
s.count++
return resp, nil
}
func (s *objectSvc) Search(context.Context, *object.SearchRequest) (object.SearchObjectStreamer, error) {
return new(simpleSearchStreamer), nil
}
func (s *objectSvc) Delete(context.Context, *object.DeleteRequest) (*object.DeleteResponse, error) {
return nil, unimplementedErr("Object", "Delete")
}
func (s *objectSvc) GetRange(context.Context, *object.GetRangeRequest) (object.GetRangeObjectStreamer, error) {
return nil, unimplementedErr("Object", "GetRange")
}
func (s *objectSvc) GetRangeHash(context.Context, *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
return nil, unimplementedErr("Object", "GetRangeHash")
}
func initGRPC(c *cfg) {
var err error

View file

@ -1,17 +1,87 @@
package main
import (
"context"
"io"
"github.com/nspcc-dev/neofs-api-go/v2/object"
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/session"
objectTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
objectService "github.com/nspcc-dev/neofs-node/pkg/services/object"
)
type simpleSearchBodyStreamer struct {
count int
}
type objectExecutor struct {
count int
}
func (*objectExecutor) Get(context.Context, *object.GetRequestBody) (objectService.GetObjectBodyStreamer, error) {
panic("implement me")
}
func (*objectExecutor) Put(context.Context) (object.PutObjectStreamer, error) {
panic("implement me")
}
func (*objectExecutor) Head(context.Context, *object.HeadRequestBody) (*object.HeadResponseBody, error) {
panic("implement me")
}
func (s *objectExecutor) Search(ctx context.Context, body *object.SearchRequestBody) (objectService.SearchObjectBodyStreamer, error) {
return new(simpleSearchBodyStreamer), nil
}
func (*objectExecutor) Delete(context.Context, *object.DeleteRequestBody) (*object.DeleteResponseBody, error) {
panic("implement me")
}
func (*objectExecutor) GetRange(context.Context, *object.GetRangeRequestBody) (objectService.GetRangeObjectBodyStreamer, error) {
panic("implement me")
}
func (*objectExecutor) GetRangeHash(context.Context, *object.GetRangeHashRequestBody) (*object.GetRangeHashResponseBody, error) {
panic("implement me")
}
func (s *simpleSearchBodyStreamer) Recv() (*object.SearchResponseBody, error) {
body := new(object.SearchResponseBody)
id := new(refs.ObjectID)
body.SetIDList([]*refs.ObjectID{id})
if s.count == 0 {
id.SetValue([]byte{1})
} else if s.count == 1 {
id.SetValue([]byte{2})
} else {
return nil, io.EOF
}
s.count++
return body, nil
}
func initObjectService(c *cfg) {
metaHdr := new(session.ResponseMetaHeader)
xHdr := new(session.XHeader)
xHdr.SetKey("test X-Header key for Object service")
xHdr.SetValue("test X-Header value for Object service")
metaHdr.SetXHeaders([]*session.XHeader{xHdr})
objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server,
objectTransportGRPC.New(
objectService.NewSignService(
c.key,
new(objectSvc),
objectService.NewExecutionService(
new(objectExecutor),
metaHdr,
),
),
),
)