Skip to content

Commit

Permalink
Move translation client implementations to the related places
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Nov 23, 2020
1 parent bb0212c commit 568fd7f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 70 deletions.
38 changes: 38 additions & 0 deletions pkg/networkservice/chains/forwarder/translation_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 forwarder provides common chain elements for the interpose NSEs (a.k.a forwarders)
package forwarder

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

"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect/translation"
)

// NewTranslationClient returns a new translation client for the interpose NSE
func NewTranslationClient() networkservice.NetworkServiceClient {
return new(translation.Builder).
WithRequestOptions(
translation.ReplaceMechanism(),
translation.ReplaceMechanismPreferences(),
).
WithConnectionOptions(
translation.WithContext(),
translation.WithPathSegments(),
).
Build()
}
3 changes: 1 addition & 2 deletions pkg/networkservice/chains/nsmgr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package nsmgr
import (
"context"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect/translation"
"github.com/networkservicemesh/sdk/pkg/registry/common/querycache"
"github.com/networkservicemesh/sdk/pkg/registry/core/next"

Expand Down Expand Up @@ -116,7 +115,7 @@ func NewServer(ctx context.Context, nsmRegistration *registryapi.NetworkServiceE
interpose.NewServer(&interposeRegistry),
filtermechanisms.NewServer(&urlsRegistryServer),
connect.NewServer(ctx,
translation.NewNSMgrClient,
NewTranslationClient,
client.NewClientFactory(
nsmRegistration.Name,
addressof.NetworkServiceClient(adapters.NewServerToClient(rv)),
Expand Down
20 changes: 18 additions & 2 deletions pkg/networkservice/chains/nsmgr/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestNSMGR_PassThroughRemote(t *testing.T) {
clienturl.NewServer(domain.Nodes[i].NSMgr.URL),
connect.NewServer(ctx,
func() networkservice.NetworkServiceClient {
return translation.NewPassThroughClient(
return newPassThroughTranslationClient(
fmt.Sprintf("my-service-remote-%v", k-1),
fmt.Sprintf("endpoint-%v", k-1))
},
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestNSMGR_PassThroughLocal(t *testing.T) {
clienturl.NewServer(domain.Nodes[0].NSMgr.URL),
connect.NewServer(ctx,
func() networkservice.NetworkServiceClient {
return translation.NewPassThroughClient(
return newPassThroughTranslationClient(
fmt.Sprintf("my-service-remote-%v", k-1),
fmt.Sprintf("endpoint-%v", k-1))
},
Expand Down Expand Up @@ -347,6 +347,22 @@ func TestNSMGR_PassThroughLocal(t *testing.T) {
require.Equal(t, 5*(nsesCount-1)+5, len(conn.Path.PathSegments))
}

func newPassThroughTranslationClient(networkService, networkServiceEndpointName string) networkservice.NetworkServiceClient {
return new(translation.Builder).
WithRequestOptions(
func(request *networkservice.NetworkServiceRequest, _ *networkservice.Connection) {
request.Connection.NetworkService = networkService
request.Connection.NetworkServiceEndpointName = networkServiceEndpointName
},
translation.ReplaceMechanismPreferences(),
).
WithConnectionOptions(
translation.WithContext(),
translation.WithPathSegments(),
).
Build()
}

type counterServer struct {
Requests, Closes int32
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/networkservice/chains/nsmgr/translation_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 nsmgr

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

"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect/translation"
)

// NewTranslationClient returns a new translation client for the NSMgr
func NewTranslationClient() networkservice.NetworkServiceClient {
return new(translation.Builder).
WithConnectionOptions(
translation.WithMechanism(),
translation.WithContext(),
translation.WithPathSegments(),
).
Build()
}
4 changes: 2 additions & 2 deletions pkg/networkservice/chains/nsmgrproxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/nsmgr"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect/translation"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/externalips"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/interdomainurl"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/swapip"
Expand All @@ -44,7 +44,7 @@ func NewServer(ctx context.Context, name string, tokenGenerator token.GeneratorF
swapip.NewServer(),
connect.NewServer(
ctx,
translation.NewNSMgrClient,
nsmgr.NewTranslationClient,
client.NewClientFactory(name,
nil,
tokenGenerator),
Expand Down
61 changes: 0 additions & 61 deletions pkg/networkservice/common/connect/translation/clients.go

This file was deleted.

5 changes: 2 additions & 3 deletions pkg/tools/sandbox/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"testing"
"time"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect/translation"

"github.com/networkservicemesh/sdk/pkg/networkservice/chains/forwarder"
"github.com/networkservicemesh/sdk/pkg/tools/spanhelper"

"github.com/google/uuid"
Expand Down Expand Up @@ -316,7 +315,7 @@ func supplyDummyForwarder(ctx context.Context, name string, generateToken token.
// Statically set the url we use to the unix file socket for the NSMgr
clienturl.NewServer(connectTo),
connect.NewServer(ctx,
translation.NewInterposeClient,
forwarder.NewTranslationClient,
client.NewClientFactory(
name,
// What to call onHeal
Expand Down

0 comments on commit 568fd7f

Please sign in to comment.