Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art committed Sep 22, 2023
1 parent 1a5b884 commit c2c4aa3
Show file tree
Hide file tree
Showing 54 changed files with 2,564 additions and 1,602 deletions.
4 changes: 2 additions & 2 deletions pkg/networkservice/chains/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2023 Cisco and/or its affiliates.
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -53,8 +53,8 @@ func NewClient(ctx context.Context, clientOpts ...Option) networkservice.Network
append(
[]networkservice.NetworkServiceClient{
updatepath.NewClient(opts.name),
metadata.NewClient(),
begin.NewClient(),
metadata.NewClient(),
opts.refreshClient,
clienturl.NewClient(opts.clientURL),
clientconn.NewClient(opts.cc),
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/chains/endpoint/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2022 Cisco Systems, Inc.
//
// Copyright (c) 2020-2023 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -121,10 +121,10 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
rv.NetworkServiceServer = chain.NewNetworkServiceServer(
append([]networkservice.NetworkServiceServer{
updatepath.NewServer(opts.name),
metadata.NewServer(),
begin.NewServer(),
updatetoken.NewServer(tokenGenerator),
opts.authorizeServer,
metadata.NewServer(),
timeout.NewServer(ctx),
monitor.NewServer(ctx, &mcsPtr),
trimpath.NewServer(),
Expand Down
8 changes: 1 addition & 7 deletions pkg/networkservice/chains/nsmgr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import (
registryrecvfd "github.com/networkservicemesh/sdk/pkg/registry/common/recvfd"
registrysendfd "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
"github.com/networkservicemesh/sdk/pkg/registry/common/updatepath"
"github.com/networkservicemesh/sdk/pkg/registry/utils/metadata"

registryadapter "github.com/networkservicemesh/sdk/pkg/registry/core/adapters"
"github.com/networkservicemesh/sdk/pkg/registry/core/chain"
Expand Down Expand Up @@ -237,7 +236,6 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
// Use remote registry
nsRegistry = registryconnect.NewNetworkServiceRegistryServer(
chain.NewNetworkServiceRegistryClient(
metadata.NewNetworkServiceClient(),
clienturl.NewNetworkServiceRegistryClient(opts.regURL),
begin.NewNetworkServiceRegistryClient(),
clientconn.NewNetworkServiceRegistryClient(),
Expand All @@ -254,17 +252,14 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
nsRegistry = chain.NewNetworkServiceRegistryServer(
grpcmetadata.NewNetworkServiceRegistryServer(),
updatepath.NewNetworkServiceRegistryServer(tokenGenerator),
metadata.NewNetworkServiceServer(),
opts.authorizeNSRegistryServer,
nsRegistry,
)

var remoteOrLocalRegistry = chain.NewNetworkServiceEndpointRegistryServer(
metadata.NewNetworkServiceEndpointServer(),
localbypass.NewNetworkServiceEndpointRegistryServer(opts.url),
registryconnect.NewNetworkServiceEndpointRegistryServer(
chain.NewNetworkServiceEndpointRegistryClient(
metadata.NewNetworkServiceEndpointClient(),
begin.NewNetworkServiceEndpointRegistryClient(),
clienturl.NewNetworkServiceEndpointRegistryClient(opts.regURL),
clientconn.NewNetworkServiceEndpointRegistryClient(),
Expand All @@ -280,7 +275,6 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options

if opts.regURL == nil {
remoteOrLocalRegistry = chain.NewNetworkServiceEndpointRegistryServer(
metadata.NewNetworkServiceEndpointServer(),
memory.NewNetworkServiceEndpointRegistryServer(),
localbypass.NewNetworkServiceEndpointRegistryServer(opts.url),
)
Expand All @@ -289,7 +283,6 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
var nseRegistry = chain.NewNetworkServiceEndpointRegistryServer(
grpcmetadata.NewNetworkServiceEndpointRegistryServer(),
updatepath.NewNetworkServiceEndpointRegistryServer(tokenGenerator),
metadata.NewNetworkServiceEndpointServer(),
opts.authorizeNSERegistryServer,
begin.NewNetworkServiceEndpointRegistryServer(),
registryclientinfo.NewNetworkServiceEndpointRegistryServer(),
Expand Down Expand Up @@ -338,6 +331,7 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
nsRegistry,
nseRegistry,
)

return rv
}

Expand Down
9 changes: 1 addition & 8 deletions pkg/networkservice/chains/nsmgrproxy/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -50,7 +50,6 @@ import (
registryswapip "github.com/networkservicemesh/sdk/pkg/registry/common/swapip"
"github.com/networkservicemesh/sdk/pkg/registry/common/updatepath"
"github.com/networkservicemesh/sdk/pkg/registry/core/chain"
"github.com/networkservicemesh/sdk/pkg/registry/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/fs"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/log"
Expand Down Expand Up @@ -226,7 +225,6 @@ func NewServer(ctx context.Context, regURL, proxyURL *url.URL, tokenGenerator to
var interdomainBypassNSEServer registryapi.NetworkServiceEndpointRegistryServer

nseClient := chain.NewNetworkServiceEndpointRegistryClient(
metadata.NewNetworkServiceEndpointClient(),
begin.NewNetworkServiceEndpointRegistryClient(),
clienturl.NewNetworkServiceEndpointRegistryClient(regURL),
clientconn.NewNetworkServiceEndpointRegistryClient(),
Expand All @@ -238,7 +236,6 @@ func NewServer(ctx context.Context, regURL, proxyURL *url.URL, tokenGenerator to
)

nsClient := chain.NewNetworkServiceRegistryClient(
metadata.NewNetworkServiceClient(),
begin.NewNetworkServiceRegistryClient(),
clienturl.NewNetworkServiceRegistryClient(regURL),
clientconn.NewNetworkServiceRegistryClient(),
Expand Down Expand Up @@ -274,7 +271,6 @@ func NewServer(ctx context.Context, regURL, proxyURL *url.URL, tokenGenerator to

var nsServerChain = registryconnect.NewNetworkServiceRegistryServer(
chain.NewNetworkServiceRegistryClient(
metadata.NewNetworkServiceClient(),
begin.NewNetworkServiceRegistryClient(),
clienturl.NewNetworkServiceRegistryClient(proxyURL),
clientconn.NewNetworkServiceRegistryClient(),
Expand All @@ -290,15 +286,13 @@ func NewServer(ctx context.Context, regURL, proxyURL *url.URL, tokenGenerator to
nsServerChain = chain.NewNetworkServiceRegistryServer(
grpcmetadata.NewNetworkServiceRegistryServer(),
updatepath.NewNetworkServiceRegistryServer(tokenGenerator),
metadata.NewNetworkServiceServer(),
opts.authorizeNSRegistryServer,
nsServerChain,
)

var nseServerChain = chain.NewNetworkServiceEndpointRegistryServer(
grpcmetadata.NewNetworkServiceEndpointRegistryServer(),
updatepath.NewNetworkServiceEndpointRegistryServer(tokenGenerator),
metadata.NewNetworkServiceEndpointServer(),
opts.authorizeNSERegistryServer,
begin.NewNetworkServiceEndpointRegistryServer(),
clienturl.NewNetworkServiceEndpointRegistryServer(proxyURL),
Expand All @@ -307,7 +301,6 @@ func NewServer(ctx context.Context, regURL, proxyURL *url.URL, tokenGenerator to
registryclusterinfo.NewNetworkServiceEndpointRegistryServer(),
registryconnect.NewNetworkServiceEndpointRegistryServer(
chain.NewNetworkServiceEndpointRegistryClient(
metadata.NewNetworkServiceEndpointClient(),
clientconn.NewNetworkServiceEndpointRegistryClient(),
opts.authorizeNSERegistryClient,
grpcmetadata.NewNetworkServiceEndpointRegistryClient(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -30,7 +30,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkrequest"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

type checkClientSetsMechanismPreferences struct {
Expand All @@ -49,7 +48,6 @@ type checkClientSetsMechanismPreferences struct {
func CheckClientSetsMechanismPreferences(t *testing.T, clientUnderTest networkservice.NetworkServiceClient, mechanismType string, mechanismCheck func(*testing.T, *networkservice.Mechanism)) networkservice.NetworkServiceClient {
rv := &checkClientSetsMechanismPreferences{}
rv.NetworkServiceClient = chain.NewNetworkServiceClient(
metadata.NewClient(),
clientUnderTest,
// Check after the clientUnderTest under test is run to make sure we have the right MechanismPreferences set
checkrequest.NewClient(t,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -28,7 +28,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkcontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkcontextonreturn"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

// CheckClientContextOnReturn - returns a NetworkServiceClient that will check the state of the context.Context
Expand All @@ -40,7 +39,6 @@ import (
// check - function to check the state of the context.Context after the clientUnderTest has returned
func CheckClientContextOnReturn(t *testing.T, clientUnderTest networkservice.NetworkServiceClient, mechanismType string, check func(*testing.T, context.Context)) networkservice.NetworkServiceClient {
return chain.NewNetworkServiceClient(
metadata.NewClient(),
checkcontextonreturn.NewClient(t, check),
clientUnderTest,
adapters.NewServerToClient(mechanisms.NewServer(
Expand All @@ -62,7 +60,6 @@ func CheckClientContextOnReturn(t *testing.T, clientUnderTest networkservice.Net
// (as it cannot know what to do at this stage)
func CheckClientContextAfter(t *testing.T, client networkservice.NetworkServiceClient, mechanismType string, check func(*testing.T, context.Context)) networkservice.NetworkServiceClient {
return chain.NewNetworkServiceClient(
metadata.NewClient(),
client,
checkcontext.NewClient(t, check),
adapters.NewServerToClient(mechanisms.NewServer(
Expand All @@ -82,7 +79,6 @@ func CheckClientContextAfter(t *testing.T, client networkservice.NetworkServiceC
// check - function to check that the serverUnderTest has taken action to implement the Mechanism
func CheckContextAfterServer(t *testing.T, serverUnderTest networkservice.NetworkServiceServer, mechanismType string, check func(*testing.T, context.Context)) networkservice.NetworkServiceServer {
return chain.NewNetworkServiceServer(
metadata.NewServer(),
mechanisms.NewServer(
map[string]networkservice.NetworkServiceServer{
mechanismType: serverUnderTest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -28,7 +28,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkerror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkrequest"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

// ServerSuite - test suite to check that a NetworkServiceServer implementing a Mechanism meets basic contracts
Expand Down Expand Up @@ -100,7 +99,6 @@ func (m *ServerSuite) TestContextAfter() {
// before calling the next chain element have been made
func (m *ServerSuite) TestMechanismAfter() {
contract := chain.NewNetworkServiceServer(
metadata.NewServer(),
mechanisms.NewServer(
map[string]networkservice.NetworkServiceServer{
m.mechanismType: m.serverUnderTest,
Expand Down
5 changes: 2 additions & 3 deletions pkg/networkservice/common/mechanisms/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2023 Doc.ai and/or its affiliates.
// Copyright (c) 2021 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -25,7 +25,6 @@ import (
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

type mechanismsClient struct {
Expand All @@ -38,7 +37,7 @@ func NewClient(mechanisms map[string]networkservice.NetworkServiceClient) networ
mechanisms: make(map[string]networkservice.NetworkServiceClient),
}
for m, c := range mechanisms {
result.mechanisms[m] = chain.NewNetworkServiceClient(metadata.NewClient(), c)
result.mechanisms[m] = chain.NewNetworkServiceClient(c)
}

return result
Expand Down
3 changes: 1 addition & 2 deletions pkg/networkservice/common/mechanisms/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

type mechanismsServer struct {
Expand All @@ -49,7 +48,7 @@ func NewServer(mechanisms map[string]networkservice.NetworkServiceServer) networ
for mechanismType, server := range mechanisms {
// We wrap in a chain here to make sure that if the 'server' is calling next.Server(ctx) it doesn't
// skips past returning here.
rv.mechanisms[mechanismType] = chain.NewNetworkServiceServer(metadata.NewServer(), server)
rv.mechanisms[mechanismType] = chain.NewNetworkServiceServer(server)
}
return rv
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/networkservice/common/passthrough/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -23,13 +23,11 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/passthrough/replacelabels"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/passthrough/replacensename"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

// NewClient returns a combination for passthrough cases
func NewClient(labels map[string]string) networkservice.NetworkServiceClient {
return chain.NewNetworkServiceClient(
metadata.NewClient(),
replacelabels.NewClient(labels),
replacensename.NewClient(),
)
Expand Down
13 changes: 3 additions & 10 deletions pkg/networkservice/core/chain/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020 Cisco Systems, Inc.
//
// Copyright (c) 2021-2023 Doc.ai and/or its affiliates.
// Copyright (c) 2021 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -20,21 +20,14 @@ package chain

import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/sirupsen/logrus"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/debug"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/trace"
)

// NewNetworkServiceClient - chains together a list of networkservice.NetworkServiceClient with tracing or debugging
// NewNetworkServiceClient - chains together a list of networkservice.NetworkServiceClient with tracing
func NewNetworkServiceClient(clients ...networkservice.NetworkServiceClient) networkservice.NetworkServiceClient {
client := trace.NewNetworkServiceClient
if logrus.GetLevel() == logrus.DebugLevel {
client = debug.NewNetworkServiceClient
}

return next.NewNetworkServiceClient(
next.NewWrappedNetworkServiceClient(client, clients...),
next.NewWrappedNetworkServiceClient(trace.NewNetworkServiceClient, clients...),
)
}
13 changes: 3 additions & 10 deletions pkg/networkservice/core/chain/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020 Cisco Systems, Inc.
//
// Copyright (c) 2021-2023 Doc.ai and/or its affiliates.
// Copyright (c) 2021 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -22,21 +22,14 @@ package chain

import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/sirupsen/logrus"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/debug"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/trace"
)

// NewNetworkServiceServer - chains together a list of networkservice.Servers with tracing or debugging
// NewNetworkServiceServer - chains together a list of networkservice.Servers with tracing
func NewNetworkServiceServer(servers ...networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
server := trace.NewNetworkServiceServer
if logrus.GetLevel() == logrus.DebugLevel {
server = debug.NewNetworkServiceServer
}

return next.NewNetworkServiceServer(
next.NewWrappedNetworkServiceServer(server, servers...),
next.NewWrappedNetworkServiceServer(trace.NewNetworkServiceServer, servers...),
)
}
Loading

0 comments on commit c2c4aa3

Please sign in to comment.