Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of nil filters for nsmgr #572

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/networkservice/chains/nsmgr/fd_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ package nsmgr
import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/registry"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
null_registry "github.com/networkservicemesh/sdk/pkg/registry/common/null"
)

// newRecvFD - construct a recvfd server
func newRecvFD() networkservice.NetworkServiceServer {
return nil
return null.NewServer()
}

// newSendFDClient - construct a sendfd server
func newSendFDClient() networkservice.NetworkServiceClient {
return nil
return null.NewClient()
}

// newRecvFDEndpointRegistry - construct a registry server
func newRecvFDEndpointRegistry() registry.NetworkServiceEndpointRegistryServer {
return nil
return null_registry.NewNetworkServiceEndpointRegistryServer()
}
80 changes: 22 additions & 58 deletions pkg/networkservice/chains/nsmgr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,74 +107,38 @@ func NewServer(ctx context.Context, nsmRegistration *registryapi.NetworkServiceE
nsmRegistration.Name,
authzServer,
tokenGenerator,
nilFilter(
discover.NewServer(nsClient, nseClient),
roundrobin.NewServer(),
localbypass.NewServer(&localbypassRegistryServer),
excludedprefixes.NewServer(ctx),
newRecvFD(), // Receive any files passed
interpose.NewServer(nsmRegistration.Name, &interposeRegistry),
filtermechanisms.NewServer(&urlsRegistryServer),
connect.NewServer(
ctx,
client.NewClientFactory(nsmRegistration.Name,
addressof.NetworkServiceClient(
adapters.NewServerToClient(rv)),
tokenGenerator,
nilClientFilter(
newSendFDClient(), // Send passed files.
)...,
),
clientDialOptions...),
)...,
discover.NewServer(nsClient, nseClient),
roundrobin.NewServer(),
localbypass.NewServer(&localbypassRegistryServer),
excludedprefixes.NewServer(ctx),
newRecvFD(), // Receive any files passed
interpose.NewServer(nsmRegistration.Name, &interposeRegistry),
filtermechanisms.NewServer(&urlsRegistryServer),
connect.NewServer(
ctx,
client.NewClientFactory(nsmRegistration.Name,
addressof.NetworkServiceClient(
adapters.NewServerToClient(rv)),
tokenGenerator,
newSendFDClient(), // Send passed files.
),
clientDialOptions...),
)

nsChain := chain_registry.NewNetworkServiceRegistryServer(nsRegistry)
nseChain := chain_registry.NewNetworkServiceEndpointRegistryServer(
nilEndpointFilter(
newRecvFDEndpointRegistry(), // Allow to receive a passed files
urlsRegistryServer,
interposeRegistry, // Store cross connect NSEs
localbypassRegistryServer, // Store endpoint Id to EndpointURL for local access.
seturl.NewNetworkServiceEndpointRegistryServer(nsmRegistration.Url), // Remember endpoint URL
nseRegistry, // Register NSE inside Remote registry with ID assigned
)...,
newRecvFDEndpointRegistry(), // Allow to receive a passed files
urlsRegistryServer,
interposeRegistry, // Store cross connect NSEs
localbypassRegistryServer, // Store endpoint Id to EndpointURL for local access.
seturl.NewNetworkServiceEndpointRegistryServer(nsmRegistration.Url), // Remember endpoint URL
nseRegistry, // Register NSE inside Remote registry with ID assigned
)
rv.Registry = registry.NewServer(nsChain, nseChain)

return rv
}

func nilClientFilter(clients ...networkservice.NetworkServiceClient) []networkservice.NetworkServiceClient {
result := []networkservice.NetworkServiceClient{}
for _, s := range clients {
if s != nil {
result = append(result, s)
}
}
return result
}

func nilEndpointFilter(servers ...registryapi.NetworkServiceEndpointRegistryServer) []registryapi.NetworkServiceEndpointRegistryServer {
result := []registryapi.NetworkServiceEndpointRegistryServer{}
for _, s := range servers {
if s != nil {
result = append(result, s)
}
}
return result
}

func nilFilter(servers ...networkservice.NetworkServiceServer) []networkservice.NetworkServiceServer {
result := []networkservice.NetworkServiceServer{}
for _, s := range servers {
if s != nil {
result = append(result, s)
}
}
return result
}

func newRemoteNSServer(cc grpc.ClientConnInterface) registryapi.NetworkServiceRegistryServer {
if cc != nil {
return adapter_registry.NetworkServiceClientToServer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"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/null"
)

type checkClientSetsMechanismPreferences struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
"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/null"
)

// CheckClientContextOnReturn - returns a NetworkServiceClient that will check the state of the context.Context
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/common/mechanisms/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ import (
"gonum.org/v1/gonum/stat/combin"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/null"
)

type unsupportedMechanismServer struct{}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
//
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,7 +17,8 @@
// limitations under the License.

// Package null provides simple networkservice chain elements that do nothing by call next and returns what comes
// back. This can be very useful in testing.
// back.
// This can be very useful in testing or writing os specific code.
package null

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/core/adapters/networkservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkcontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/null"
)

type contextKeyType string
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/utils/checks/checkerror/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkerror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/null"
)

func TestCheckErrorClient_Nil(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/utils/checks/checkerror/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkerror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/null"
)

func TestCheckErrorServer_Nil(t *testing.T) {
Expand Down
20 changes: 20 additions & 0 deletions pkg/registry/common/null/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package null provides simple registry chain elements that do nothing by call next and returns what comes
// back.
// This can be very useful in testing or writing os specific code.
package null
46 changes: 46 additions & 0 deletions pkg/registry/common/null/ns_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package null

import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/registry"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/registry/core/next"
)

type nullNSClient struct{}

func (n *nullNSClient) Register(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) {
return next.NetworkServiceRegistryClient(ctx).Register(ctx, in, opts...)
}

func (n *nullNSClient) Find(ctx context.Context, in *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) {
return next.NetworkServiceRegistryClient(ctx).Find(ctx, in, opts...)
}

func (n *nullNSClient) Unregister(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*empty.Empty, error) {
return next.NetworkServiceRegistryClient(ctx).Unregister(ctx, in, opts...)
}

// NewNetworkServiceRegistryClient - returns a new null server that does nothing but call next.NetworkServiceRegistryClient(ctx).
func NewNetworkServiceRegistryClient() registry.NetworkServiceRegistryClient {
return new(nullNSClient)
}
45 changes: 45 additions & 0 deletions pkg/registry/common/null/ns_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package null

import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/registry"

"github.com/networkservicemesh/sdk/pkg/registry/core/next"
)

type nullNSServer struct{}

func (n *nullNSServer) Register(ctx context.Context, service *registry.NetworkService) (*registry.NetworkService, error) {
return next.NetworkServiceRegistryServer(ctx).Register(ctx, service)
}

func (n *nullNSServer) Find(query *registry.NetworkServiceQuery, server registry.NetworkServiceRegistry_FindServer) error {
return next.NetworkServiceRegistryServer(server.Context()).Find(query, server)
}

func (n *nullNSServer) Unregister(ctx context.Context, service *registry.NetworkService) (*empty.Empty, error) {
return next.NetworkServiceRegistryServer(ctx).Unregister(ctx, service)
}

// NewNetworkServiceRegistryServer - returns a new null server that does nothing but call next.NetworkServiceRegistryServer(ctx).
func NewNetworkServiceRegistryServer() registry.NetworkServiceRegistryServer {
return new(nullNSServer)
}
46 changes: 46 additions & 0 deletions pkg/registry/common/null/nse_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package null

import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/registry"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/registry/core/next"
)

type nullNSEClient struct{}

func (n *nullNSEClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) {
return next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, in, opts...)
}

func (n *nullNSEClient) Find(ctx context.Context, in *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) {
return next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, in, opts...)
}

func (n *nullNSEClient) Unregister(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*empty.Empty, error) {
return next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, in, opts...)
}

// NewNetworkServiceEndpointRegistryClient - returns a new null client that does nothing but call next.NetworkServiceEndpointRegistryClient(ctx).
func NewNetworkServiceEndpointRegistryClient() registry.NetworkServiceEndpointRegistryClient {
return new(nullNSEClient)
}
Loading