Skip to content

Commit

Permalink
Merge "FAB-16715 Add overrides to ConnectionCriteria" into release-1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
yacovm authored and Gerrit Code Review committed Sep 30, 2019
2 parents 04d7258 + 994f15c commit be3de21
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/deliverservice/deliveryclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ type ConnectionCriteria struct {
Organizations []string
// OrdererEndpointsByOrg specifies the endpoints of the ordering service grouped by orgs.
OrdererEndpointsByOrg map[string][]string
// OrdererEndpointOverrides specifies a map of endpoints to override. The map
// key is the configured endpoint address to match and the value is the
// endpoint to use instead.
OrdererEndpointOverrides map[string]string
}

func (cc ConnectionCriteria) toEndpointCriteria() []comm.EndpointCriteria {
Expand All @@ -122,6 +126,10 @@ func (cc ConnectionCriteria) toEndpointCriteria() []comm.EndpointCriteria {
}

for _, endpoint := range endpoints {
// check if we need to override the endpoint
if override, ok := cc.OrdererEndpointOverrides[endpoint]; ok {
endpoint = override
}
res = append(res, comm.EndpointCriteria{
Organizations: []string{org},
Endpoint: endpoint,
Expand All @@ -135,6 +143,10 @@ func (cc ConnectionCriteria) toEndpointCriteria() []comm.EndpointCriteria {
}

for _, endpoint := range cc.OrdererEndpoints {
// check if we need to override the endpoint
if override, ok := cc.OrdererEndpointOverrides[endpoint]; ok {
endpoint = override
}
res = append(res, comm.EndpointCriteria{
Organizations: cc.Organizations,
Endpoint: endpoint,
Expand Down
35 changes: 35 additions & 0 deletions core/deliverservice/deliveryclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,21 @@ func TestToEndpointCriteria(t *testing.T) {
{Organizations: []string{"foo", "bar"}, Endpoint: "c"},
},
},
{
description: "globally defined endpoints with overrides",
input: ConnectionCriteria{
Organizations: []string{"foo", "bar"},
OrdererEndpoints: []string{"a", "b", "c"},
OrdererEndpointOverrides: map[string]string{
"b": "d",
},
},
expectedOut: []comm.EndpointCriteria{
{Organizations: []string{"foo", "bar"}, Endpoint: "a"},
{Organizations: []string{"foo", "bar"}, Endpoint: "d"},
{Organizations: []string{"foo", "bar"}, Endpoint: "c"},
},
},
{
description: "per org defined endpoints",
input: ConnectionCriteria{
Expand All @@ -800,6 +815,26 @@ func TestToEndpointCriteria(t *testing.T) {
{Organizations: []string{"bar"}, Endpoint: "c"},
},
},
{
description: "per org defined endpoints with overrides",
input: ConnectionCriteria{
Organizations: []string{"foo", "bar"},
// Even if OrdererEndpoints are defined, the OrdererEndpointsByOrg take precedence.
OrdererEndpoints: []string{"a", "b", "c"},
OrdererEndpointsByOrg: map[string][]string{
"foo": {"a", "b"},
"bar": {"c"},
},
OrdererEndpointOverrides: map[string]string{
"b": "d",
},
},
expectedOut: []comm.EndpointCriteria{
{Organizations: []string{"foo"}, Endpoint: "a"},
{Organizations: []string{"foo"}, Endpoint: "d"},
{Organizations: []string{"bar"}, Endpoint: "c"},
},
},
} {
t.Run(testCase.description, func(t *testing.T) {
assert.Equal(t, testCase.expectedOut, testCase.input.toEndpointCriteria())
Expand Down

0 comments on commit be3de21

Please sign in to comment.