[#1342] neofs-node: Use the default endpoint for tree service
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
8844d9b2db
commit
36e24f7f78
6 changed files with 5 additions and 101 deletions
|
@ -1,39 +0,0 @@
|
||||||
package treeconfig
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GRPCConfig is a wrapper over "grpc" config section which provides access
|
|
||||||
// to gRPC configuration of control service.
|
|
||||||
type GRPCConfig struct {
|
|
||||||
cfg *config.Config
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
subsection = "tree"
|
|
||||||
grpcSubsection = "grpc"
|
|
||||||
|
|
||||||
// GRPCEndpointDefault is a default endpoint of gRPC Control service.
|
|
||||||
GRPCEndpointDefault = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
// GRPC returns structure that provides access to "grpc" subsection of
|
|
||||||
// "tree" section.
|
|
||||||
func GRPC(c *config.Config) GRPCConfig {
|
|
||||||
return GRPCConfig{
|
|
||||||
c.Sub(subsection).Sub(grpcSubsection),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Endpoint returns value of "endpoint" config parameter.
|
|
||||||
//
|
|
||||||
// Returns GRPCEndpointDefault if value is not a non-empty string.
|
|
||||||
func (g GRPCConfig) Endpoint() string {
|
|
||||||
v := config.String(g.cfg, "endpoint")
|
|
||||||
if v != "" {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
return GRPCEndpointDefault
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package treeconfig_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
||||||
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
|
||||||
treeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/tree"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestControlSection(t *testing.T) {
|
|
||||||
t.Run("defaults", func(t *testing.T) {
|
|
||||||
empty := configtest.EmptyConfig()
|
|
||||||
|
|
||||||
require.Equal(t, treeconfig.GRPCEndpointDefault, treeconfig.GRPC(empty).Endpoint())
|
|
||||||
})
|
|
||||||
|
|
||||||
const path = "../../../../config/example/node"
|
|
||||||
|
|
||||||
var fileConfigTest = func(c *config.Config) {
|
|
||||||
require.Equal(t, "127.0.0.1:8091", treeconfig.GRPC(c).Endpoint())
|
|
||||||
}
|
|
||||||
|
|
||||||
configtest.ForEachFileType(path, fileConfigTest)
|
|
||||||
|
|
||||||
t.Run("ENV", func(t *testing.T) {
|
|
||||||
configtest.ForEnvFileType(path, fileConfigTest)
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -2,19 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
|
||||||
|
|
||||||
treeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/tree"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/tree"
|
"github.com/nspcc-dev/neofs-node/pkg/services/tree"
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func initTreeService(c *cfg) {
|
func initTreeService(c *cfg) {
|
||||||
endpoint := treeconfig.GRPC(c.appCfg).Endpoint()
|
|
||||||
if endpoint == treeconfig.GRPCEndpointDefault {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
treeSvc := tree.New(
|
treeSvc := tree.New(
|
||||||
tree.WithContainerSource(c.cfgObject.cnrSource),
|
tree.WithContainerSource(c.cfgObject.cnrSource),
|
||||||
tree.WithNetmapSource(c.netMapSource),
|
tree.WithNetmapSource(c.netMapSource),
|
||||||
|
@ -22,20 +14,13 @@ func initTreeService(c *cfg) {
|
||||||
tree.WithLogger(c.log),
|
tree.WithLogger(c.log),
|
||||||
tree.WithStorage(c.cfgObject.cfgLocalStorage.localStorage))
|
tree.WithStorage(c.cfgObject.cfgLocalStorage.localStorage))
|
||||||
|
|
||||||
treeServer := grpc.NewServer()
|
for _, srv := range c.cfgGRPC.servers {
|
||||||
|
tree.RegisterTreeServiceServer(srv, treeSvc)
|
||||||
c.onShutdown(func() {
|
}
|
||||||
stopGRPC("NeoFS Tree Service API", treeServer, c.log)
|
|
||||||
treeSvc.Shutdown()
|
|
||||||
})
|
|
||||||
|
|
||||||
lis, err := net.Listen("tcp", endpoint)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
tree.RegisterTreeServiceServer(treeServer, treeSvc)
|
|
||||||
|
|
||||||
c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
|
c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
|
||||||
treeSvc.Start(ctx)
|
treeSvc.Start(ctx)
|
||||||
fatalOnErr(treeServer.Serve(lis))
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
c.onShutdown(treeSvc.Shutdown)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,9 +46,6 @@ NEOFS_GRPC_1_TLS_ENABLED=false
|
||||||
NEOFS_CONTROL_AUTHORIZED_KEYS="035839e45d472a3b7769a2a1bd7d54c4ccd4943c3b40f547870e83a8fcbfb3ce11 028f42cfcb74499d7b15b35d9bff260a1c8d27de4f446a627406a382d8961486d6"
|
NEOFS_CONTROL_AUTHORIZED_KEYS="035839e45d472a3b7769a2a1bd7d54c4ccd4943c3b40f547870e83a8fcbfb3ce11 028f42cfcb74499d7b15b35d9bff260a1c8d27de4f446a627406a382d8961486d6"
|
||||||
NEOFS_CONTROL_GRPC_ENDPOINT=localhost:8090
|
NEOFS_CONTROL_GRPC_ENDPOINT=localhost:8090
|
||||||
|
|
||||||
# Tree service section
|
|
||||||
NEOFS_TREE_GRPC_ENDPOINT=127.0.0.1:8091
|
|
||||||
|
|
||||||
# Contracts section
|
# Contracts section
|
||||||
NEOFS_CONTRACTS_BALANCE=5263abba1abedbf79bb57f3e40b50b4425d2d6cd
|
NEOFS_CONTRACTS_BALANCE=5263abba1abedbf79bb57f3e40b50b4425d2d6cd
|
||||||
NEOFS_CONTRACTS_CONTAINER=5d084790d7aa36cea7b53fe897380dab11d2cd3c
|
NEOFS_CONTRACTS_CONTAINER=5d084790d7aa36cea7b53fe897380dab11d2cd3c
|
||||||
|
|
|
@ -84,11 +84,6 @@
|
||||||
"endpoint": "localhost:8090"
|
"endpoint": "localhost:8090"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tree": {
|
|
||||||
"grpc": {
|
|
||||||
"endpoint": "127.0.0.1:8091"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"contracts": {
|
"contracts": {
|
||||||
"balance": "5263abba1abedbf79bb57f3e40b50b4425d2d6cd",
|
"balance": "5263abba1abedbf79bb57f3e40b50b4425d2d6cd",
|
||||||
"container": "5d084790d7aa36cea7b53fe897380dab11d2cd3c",
|
"container": "5d084790d7aa36cea7b53fe897380dab11d2cd3c",
|
||||||
|
|
|
@ -66,10 +66,6 @@ control:
|
||||||
grpc:
|
grpc:
|
||||||
endpoint: localhost:8090 # endpoint that is listened by the Control Service
|
endpoint: localhost:8090 # endpoint that is listened by the Control Service
|
||||||
|
|
||||||
tree:
|
|
||||||
grpc:
|
|
||||||
endpoint: 127.0.0.1:8091 # endpoint that is listened by the Tree Service
|
|
||||||
|
|
||||||
contracts: # side chain NEOFS contract script hashes; optional, override values retrieved from NNS contract
|
contracts: # side chain NEOFS contract script hashes; optional, override values retrieved from NNS contract
|
||||||
balance: 5263abba1abedbf79bb57f3e40b50b4425d2d6cd
|
balance: 5263abba1abedbf79bb57f3e40b50b4425d2d6cd
|
||||||
container: 5d084790d7aa36cea7b53fe897380dab11d2cd3c
|
container: 5d084790d7aa36cea7b53fe897380dab11d2cd3c
|
||||||
|
|
Loading…
Reference in a new issue