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

Removed adapters #1149

Closed
Closed
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
3 changes: 1 addition & 2 deletions pkg/networkservice/chains/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/setlogoption"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/updatepath"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)
Expand All @@ -55,7 +54,7 @@ func NewClient(ctx context.Context, clientOpts ...Option) networkservice.Network
return chain.NewNetworkServiceClient(
append(
[]networkservice.NetworkServiceClient{
adapters.NewServerToClient(setlogoption.NewServer(map[string]string{"name": opts.name})),
setlogoption.NewClient(map[string]string{"name": opts.name}),
updatepath.NewClient(opts.name),
begin.NewClient(),
metadata.NewClient(),
Expand Down
5 changes: 2 additions & 3 deletions pkg/networkservice/chains/nsmgr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package nsmgr

import (
"context"
"fmt"
"net/url"
"time"

Expand Down Expand Up @@ -168,15 +167,15 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
}

nsRegistry = registrychain.NewNetworkServiceRegistryServer(
setlogoption.NewNetworkServiceRegistryServer(map[string]string{"name": opts.name}),
registryserialize.NewNetworkServiceRegistryServer(),
setlogoption.NewNetworkServiceRegistryServer(map[string]string{"name": "NetworkServiceRegistryServer." + opts.name}),
nsRegistry,
)

var nseInMemoryRegistry = memory.NewNetworkServiceEndpointRegistryServer()

var nseRegistry = registrychain.NewNetworkServiceEndpointRegistryServer(
setlogoption.NewNetworkServiceEndpointRegistryServer(map[string]string{"name": fmt.Sprintf("NetworkServiceRegistryServer.%v", opts.name)}),
setlogoption.NewNetworkServiceEndpointRegistryServer(map[string]string{"name": opts.name}),
registryclientinfo.NewNetworkServiceEndpointRegistryServer(),
registryserialize.NewNetworkServiceEndpointRegistryServer(),
expire.NewNetworkServiceEndpointRegistryServer(ctx, time.Minute),
Expand Down
49 changes: 49 additions & 0 deletions pkg/networkservice/common/setlogoption/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2021 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 setlogoption

import (
"context"

"google.golang.org/grpc"

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

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

type setLogOptionClient struct {
options map[string]string
}

// NewClient - construct a new set log option server to override some logging capabilities for context.
func NewClient(options map[string]string) networkservice.NetworkServiceClient {
return &setLogOptionClient{
options: options,
}
}

func (s *setLogOptionClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
ctx = withFields(ctx, s.options)
return next.Client(ctx).Request(ctx, request, opts...)
}

func (s *setLogOptionClient) Close(ctx context.Context, connection *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
ctx = withFields(ctx, s.options)
return next.Client(ctx).Close(ctx, connection, opts...)
}
35 changes: 35 additions & 0 deletions pkg/networkservice/common/setlogoption/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2021 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 setlogoption

import (
"context"

"github.com/networkservicemesh/sdk/pkg/tools/log"
)

func withFields(ctx context.Context, options map[string]string) context.Context {
fields := log.Fields(ctx)
fields["type"] = "NetworkService"
for k, v := range options {
fields[k] = v
}

ctx = log.WithFields(ctx, fields)

return ctx
}
22 changes: 2 additions & 20 deletions pkg/networkservice/common/setlogoption/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/log"
)

type setLogOptionServer struct {
Expand All @@ -39,28 +38,11 @@ func NewServer(options map[string]string) networkservice.NetworkServiceServer {
}

func (s *setLogOptionServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
ctx = s.withFields(ctx)
ctx = withFields(ctx, s.options)
return next.Server(ctx).Request(ctx, request)
}

func (s *setLogOptionServer) withFields(ctx context.Context) context.Context {
ctxFields := log.Fields(ctx)
fields := make(map[string]interface{})
for k, v := range ctxFields {
fields[k] = v
}

fields["type"] = "NetworkService"
for k, v := range s.options {
fields[k] = v
}
if len(fields) > 0 {
ctx = log.WithFields(ctx, fields)
}
return ctx
}

func (s *setLogOptionServer) Close(ctx context.Context, connection *networkservice.Connection) (*empty.Empty, error) {
ctx = s.withFields(ctx)
ctx = withFields(ctx, s.options)
return next.Server(ctx).Close(ctx, connection)
}
3 changes: 1 addition & 2 deletions pkg/registry/chains/client/ns_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/registry/common/connect"
"github.com/networkservicemesh/sdk/pkg/registry/common/heal"
"github.com/networkservicemesh/sdk/pkg/registry/common/setlogoption"
"github.com/networkservicemesh/sdk/pkg/registry/core/adapters"
"github.com/networkservicemesh/sdk/pkg/registry/core/chain"
)

Expand All @@ -38,7 +37,7 @@ func NewNetworkServiceRegistryClient(ctx context.Context, connectTo *url.URL, op

c := new(registry.NetworkServiceRegistryClient)
*c = chain.NewNetworkServiceRegistryClient(
adapters.NetworkServiceServerToClient(setlogoption.NewNetworkServiceRegistryServer(map[string]string{})),
setlogoption.NewNetworkServiceRegistryClient(map[string]string{}),
connect.NewNetworkServiceRegistryClient(ctx, connectTo,
connect.WithNSAdditionalFunctionality(
append(
Expand Down
3 changes: 1 addition & 2 deletions pkg/registry/chains/client/nse_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
"github.com/networkservicemesh/sdk/pkg/registry/common/serialize"
"github.com/networkservicemesh/sdk/pkg/registry/common/setlogoption"
"github.com/networkservicemesh/sdk/pkg/registry/core/adapters"
"github.com/networkservicemesh/sdk/pkg/registry/core/chain"
)

Expand All @@ -42,7 +41,7 @@ func NewNetworkServiceEndpointRegistryClient(ctx context.Context, connectTo *url

c := new(registry.NetworkServiceEndpointRegistryClient)
*c = chain.NewNetworkServiceEndpointRegistryClient(
adapters.NetworkServiceEndpointServerToClient(setlogoption.NewNetworkServiceEndpointRegistryServer(map[string]string{})),
setlogoption.NewNetworkServiceEndpointRegistryClient(map[string]string{}),
serialize.NewNetworkServiceEndpointRegistryClient(),
refresh.NewNetworkServiceEndpointRegistryClient(ctx),
connect.NewNetworkServiceEndpointRegistryClient(ctx, connectTo,
Expand Down
58 changes: 58 additions & 0 deletions pkg/registry/common/setlogoption/ns_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2020-2021 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 setlogoption

import (
"context"

"google.golang.org/grpc"

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

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

const (
nsRegistryClient = "NetworkServiceRegistryClient"
)

type setNSLogOptionClient struct {
options map[string]string
}

func (s *setNSLogOptionClient) Register(ctx context.Context, ns *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) {
ctx = withFields(ctx, s.options, nsRegistryClient)
return next.NetworkServiceRegistryClient(ctx).Register(ctx, ns, opts...)
}

func (s *setNSLogOptionClient) Find(ctx context.Context, query *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) {
ctx = withFields(ctx, s.options, nsRegistryClient)
return next.NetworkServiceRegistryClient(ctx).Find(ctx, query, opts...)
}

func (s *setNSLogOptionClient) Unregister(ctx context.Context, ns *registry.NetworkService, opts ...grpc.CallOption) (*empty.Empty, error) {
ctx = withFields(ctx, s.options, nsRegistryClient)
return next.NetworkServiceRegistryClient(ctx).Unregister(ctx, ns, opts...)
}

// NewNetworkServiceRegistryClient creates new instance of NetworkServiceRegistryClient which sets the passed options
func NewNetworkServiceRegistryClient(options map[string]string) registry.NetworkServiceRegistryClient {
return &setNSLogOptionClient{
options: options,
}
}
8 changes: 4 additions & 4 deletions pkg/registry/common/setlogoption/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
registryType = "NetworkServiceRegistry"
nsRegistryServer = "NetworkServiceRegistryServer"
)

type setNSLogOption struct {
Expand All @@ -47,17 +47,17 @@ func (s *setLogOptionFindServer) Context() context.Context {
}

func (s *setNSLogOption) Register(ctx context.Context, ns *registry.NetworkService) (*registry.NetworkService, error) {
ctx = withFields(ctx, s.options, registryType)
ctx = withFields(ctx, s.options, nsRegistryServer)
return next.NetworkServiceRegistryServer(ctx).Register(ctx, ns)
}

func (s *setNSLogOption) Find(query *registry.NetworkServiceQuery, server registry.NetworkServiceRegistry_FindServer) error {
ctx := withFields(server.Context(), s.options, registryType)
ctx := withFields(server.Context(), s.options, nsRegistryServer)
return next.NetworkServiceRegistryServer(ctx).Find(query, &setLogOptionFindServer{ctx: ctx, NetworkServiceRegistry_FindServer: server})
}

func (s *setNSLogOption) Unregister(ctx context.Context, ns *registry.NetworkService) (*empty.Empty, error) {
ctx = withFields(ctx, s.options, registryType)
ctx = withFields(ctx, s.options, nsRegistryServer)
return next.NetworkServiceRegistryServer(ctx).Unregister(ctx, ns)
}

Expand Down
59 changes: 59 additions & 0 deletions pkg/registry/common/setlogoption/nse_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2020-2021 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 setlogoption implements a chain element to set log options before full chain
package setlogoption

import (
"context"

"google.golang.org/grpc"

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

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

const (
nseRegistryClient = "NetworkServiceEndpointRegistryClient"
)

type setNSELogOptionClient struct {
options map[string]string
}

func (s *setNSELogOptionClient) Register(ctx context.Context, endpoint *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) {
ctx = withFields(ctx, s.options, nseRegistryClient)
return next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, endpoint, opts...)
}

func (s *setNSELogOptionClient) Find(ctx context.Context, query *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) {
ctx = withFields(ctx, s.options, nseRegistryClient)
return next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, query, opts...)
}

func (s *setNSELogOptionClient) Unregister(ctx context.Context, endpoint *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*empty.Empty, error) {
ctx = withFields(ctx, s.options, nseRegistryClient)
return next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, endpoint, opts...)
}

// NewNetworkServiceEndpointRegistryClient creates new instance of NetworkServiceEndpointRegistryClient which sets the passed options
func NewNetworkServiceEndpointRegistryClient(options map[string]string) registry.NetworkServiceEndpointRegistryClient {
return &setNSELogOptionClient{
options: options,
}
}
8 changes: 4 additions & 4 deletions pkg/registry/common/setlogoption/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

const (
endpointRegistryType = "NetworkServiceEndpointRegistry"
nseRegistryServer = "NetworkServiceEndpointRegistryServer"
)

type setNSELogOption struct {
Expand All @@ -48,17 +48,17 @@ func (s *setNSELogOptionFindServer) Context() context.Context {
}

func (s *setNSELogOption) Register(ctx context.Context, endpoint *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, error) {
ctx = withFields(ctx, s.options, endpointRegistryType)
ctx = withFields(ctx, s.options, nseRegistryServer)
return next.NetworkServiceEndpointRegistryServer(ctx).Register(ctx, endpoint)
}

func (s *setNSELogOption) Find(query *registry.NetworkServiceEndpointQuery, server registry.NetworkServiceEndpointRegistry_FindServer) error {
ctx := withFields(server.Context(), s.options, endpointRegistryType)
ctx := withFields(server.Context(), s.options, nseRegistryServer)
return next.NetworkServiceEndpointRegistryServer(ctx).Find(query, &setNSELogOptionFindServer{ctx: ctx, NetworkServiceEndpointRegistry_FindServer: server})
}

func (s *setNSELogOption) Unregister(ctx context.Context, endpoint *registry.NetworkServiceEndpoint) (*empty.Empty, error) {
ctx = withFields(ctx, s.options, endpointRegistryType)
ctx = withFields(ctx, s.options, nseRegistryServer)
return next.NetworkServiceEndpointRegistryServer(ctx).Unregister(ctx, endpoint)
}

Expand Down