Skip to content

Commit

Permalink
[FAB-9900] WithOrdererURL & WithTargetURLs renaming
Browse files Browse the repository at this point in the history
- WithOrdererURL renamed to WithOrdererEndpoint
- WithTargetURLs renamed to WithTargetEndppoints
- No logic changes


Change-Id: I7024f395e3c72784448dff95a0e59ab6d422e5e6
Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed May 7, 2018
1 parent 914555e commit da948b4
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 95 deletions.
10 changes: 5 additions & 5 deletions pkg/client/channel/api.go
Expand Up @@ -64,17 +64,17 @@ func WithTargets(targets ...fab.Peer) RequestOption {
}
}

// WithTargetURLs allows overriding of the target peers for the request.
// Targets are specified by URL, and the SDK will create the underlying peer
// WithTargetEndpoints allows overriding of the target peers for the request.
// Targets are specified by name or URL, and the SDK will create the underlying peer
// objects.
func WithTargetURLs(urls ...string) RequestOption {
func WithTargetEndpoints(keys ...string) RequestOption {
return func(ctx context.Client, opts *requestOptions) error {

var targets []fab.Peer

for _, url := range urls {
for _, url := range keys {

peerCfg, err := comm.NetworkPeerConfigFromURL(ctx.EndpointConfig(), url)
peerCfg, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), url)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/channel/api_test.go
Expand Up @@ -19,7 +19,7 @@ import (

func TestWithTargetURLsInvalid(t *testing.T) {
ctx := setupMockTestContext("test", "Org1MSP")
opt := WithTargetURLs("invalid")
opt := WithTargetEndpoints("invalid")

mockConfig := &fcmocks.MockConfig{}

Expand All @@ -37,7 +37,7 @@ func TestWithTargetURLsInvalid(t *testing.T) {

func TestWithTargetURLsValid(t *testing.T) {
ctx := setupMockTestContext("test", "Org1MSP")
opt := WithTargetURLs("127.0.0.1:7050")
opt := WithTargetEndpoints("127.0.0.1:7050")

mockConfig := &fcmocks.MockConfig{}

Expand Down
10 changes: 5 additions & 5 deletions pkg/client/ledger/opts.go
Expand Up @@ -61,16 +61,16 @@ func WithTargets(targets ...fab.Peer) RequestOption {
}
}

// WithTargetURLs allows overriding of the target peers per request.
// Targets are specified by URL, and the SDK will create the underlying peer objects.
func WithTargetURLs(urls ...string) RequestOption {
// WithTargetEndpoints allows overriding of the target peers per request.
// Targets are specified by name or URL, and the SDK will create the underlying peer objects.
func WithTargetEndpoints(keys ...string) RequestOption {
return func(ctx context.Client, opts *requestOptions) error {

var targets []fab.Peer

for _, url := range urls {
for _, url := range keys {

peerCfg, err := comm.NetworkPeerConfigFromURL(ctx.EndpointConfig(), url)
peerCfg, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), url)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/ledger/opts_test.go
Expand Up @@ -18,7 +18,7 @@ import (

func TestWithTargetURLsInvalid(t *testing.T) {
ctx := setupTestContext("test", "Org1MSP")
opt := WithTargetURLs("invalid")
opt := WithTargetEndpoints("invalid")

mockConfig := &fcmocks.MockConfig{}

Expand All @@ -36,7 +36,7 @@ func TestWithTargetURLsInvalid(t *testing.T) {

func TestWithTargetURLsValid(t *testing.T) {
ctx := setupTestContext("test", "Org1MSP")
opt := WithTargetURLs("127.0.0.1:7050")
opt := WithTargetEndpoints("127.0.0.1:7050")

mockConfig := &fcmocks.MockConfig{}

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/resmgmt/example_test.go
Expand Up @@ -211,7 +211,7 @@ func ExampleClient_SaveChannel() {
// Output: Saved channel
}

func ExampleClient_SaveChannel_withOrdererURL() {
func ExampleClient_SaveChannel_withOrdererEndpoint() {

c, err := New(mockClientProvider())
if err != nil {
Expand All @@ -224,7 +224,7 @@ func ExampleClient_SaveChannel_withOrdererURL() {
}
defer r.Close()

resp, err := c.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r}, WithOrdererURL("example.com"))
resp, err := c.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r}, WithOrdererEndpoint("example.com"))
if err != nil {
fmt.Printf("failed to save channel: %v", err)
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/client/resmgmt/opts.go
Expand Up @@ -33,17 +33,17 @@ func WithTargets(targets ...fab.Peer) RequestOption {
}
}

// WithTargetURLs allows overriding of the target peers for the request.
// Targets are specified by URL, and the SDK will create the underlying peer
// WithTargetEndpoints allows overriding of the target peers for the request.
// Targets are specified by name or URL, and the SDK will create the underlying peer
// objects.
func WithTargetURLs(urls ...string) RequestOption {
func WithTargetEndpoints(keys ...string) RequestOption {
return func(ctx context.Client, opts *requestOptions) error {

var targets []fab.Peer

for _, url := range urls {
for _, url := range keys {

peerCfg, err := comm.NetworkPeerConfigFromURL(ctx.EndpointConfig(), url)
peerCfg, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), url)
if err != nil {
return err
}
Expand Down Expand Up @@ -80,15 +80,16 @@ func WithTimeout(timeoutType fab.TimeoutType, timeout time.Duration) RequestOpti
}
}

// WithOrdererURL allows an orderer to be specified for the request.
// The orderer will be looked-up based on the name/url argument.
func WithOrdererURL(nameOrURL string) RequestOption {
// WithOrdererEndpoint allows an orderer to be specified for the request.
// The orderer will be looked-up based on the key argument.
// key argument can be a name or url
func WithOrdererEndpoint(key string) RequestOption {

return func(ctx context.Client, opts *requestOptions) error {

ordererCfg, err := ctx.EndpointConfig().OrdererConfig(nameOrURL)
ordererCfg, err := ctx.EndpointConfig().OrdererConfig(key)
if err != nil {
return errors.Wrapf(err, "orderer not found for url : %s", nameOrURL)
return errors.Wrapf(err, "orderer not found for url : %s", key)
}

orderer, err := ctx.InfraProvider().CreateOrdererFromConfig(ordererCfg)
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/resmgmt/opts_test.go
Expand Up @@ -18,7 +18,7 @@ import (

func TestWithTargetURLsInvalid(t *testing.T) {
ctx := setupTestContext("test", "Org1MSP")
opt := WithTargetURLs("invalid")
opt := WithTargetEndpoints("invalid")

mockConfig := &fcmocks.MockConfig{}

Expand All @@ -36,7 +36,7 @@ func TestWithTargetURLsInvalid(t *testing.T) {

func TestWithTargetURLsValid(t *testing.T) {
ctx := setupTestContext("test", "Org1MSP")
opt := WithTargetURLs("127.0.0.1:7050")
opt := WithTargetEndpoints("127.0.0.1:7050")

mockConfig := &fcmocks.MockConfig{}

Expand Down
16 changes: 8 additions & 8 deletions pkg/client/resmgmt/resmgmt_test.go
Expand Up @@ -252,7 +252,7 @@ func TestJoinChannelWithOptsRequiredParameters(t *testing.T) {
}

// Test targets only
err = rc.JoinChannel("mychannel", WithTargets(peers...), WithOrdererURL("orderer.example.com"))
err = rc.JoinChannel("mychannel", WithTargets(peers...), WithOrdererEndpoint("orderer.example.com"))
if err != nil {
t.Fatalf(err.Error())
}
Expand Down Expand Up @@ -1186,12 +1186,12 @@ func TestSaveChannelSuccess(t *testing.T) {
assert.Contains(t, err.Error(), "reading channel config file failed")

// Test valid Save Channel request (success)
resp, err := cc.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r}, WithOrdererURL("example.com"))
resp, err := cc.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r}, WithOrdererEndpoint("example.com"))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, resp.TransactionID, "transaction ID should be populated")

// Test valid Save Channel request (success / filename)
resp, err = cc.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfigPath: channelConfig}, WithOrdererURL("example.com"))
resp, err = cc.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfigPath: channelConfig}, WithOrdererEndpoint("example.com"))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, resp.TransactionID, "transaction ID should be populated")
}
Expand Down Expand Up @@ -1250,7 +1250,7 @@ func TestSaveChannelWithOpts(t *testing.T) {
req := SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r1}

// Test empty option (default order is random orderer from config)
opts := WithOrdererURL("")
opts := WithOrdererEndpoint("")
resp, err := cc.SaveChannel(req, opts)
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, resp.TransactionID, "transaction ID should be populated")
Expand All @@ -1262,7 +1262,7 @@ func TestSaveChannelWithOpts(t *testing.T) {

req = SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r2}

opts = WithOrdererURL("orderer.example.com")
opts = WithOrdererEndpoint("orderer.example.com")
resp, err = cc.SaveChannel(req, opts)
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, resp.TransactionID, "transaction ID should be populated")
Expand All @@ -1279,7 +1279,7 @@ func TestSaveChannelWithOpts(t *testing.T) {

cc = setupResMgmtClient(t, ctx)

opts = WithOrdererURL("Invalid")
opts = WithOrdererEndpoint("Invalid")
_, err = cc.SaveChannel(req, opts)
assert.NotNil(t, err, "Should have failed for invalid orderer ID")
assert.Contains(t, err.Error(), "failed to read opts in resmgmt: orderer not found for url")
Expand All @@ -1288,7 +1288,7 @@ func TestSaveChannelWithOpts(t *testing.T) {
func TestJoinChannelWithInvalidOpts(t *testing.T) {

cc := setupDefaultResMgmtClient(t)
opts := WithOrdererURL("Invalid")
opts := WithOrdererEndpoint("Invalid")
err := cc.JoinChannel("mychannel", opts)
assert.NotNil(t, err, "Should have failed for invalid orderer ID")
assert.Contains(t, err.Error(), "failed to read opts in resmgmt: orderer not found for url")
Expand Down Expand Up @@ -1331,7 +1331,7 @@ func TestSaveChannelWithMultipleSigningIdenities(t *testing.T) {

secondCtx := fcmocks.NewMockContext(mspmocks.NewMockSigningIdentity("second", "second"))
req = SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r2, SigningIdentities: []msp.SigningIdentity{cc.ctx, secondCtx}}
resp, err = cc.SaveChannel(req, WithOrdererURL(""))
resp, err = cc.SaveChannel(req, WithOrdererEndpoint(""))
assert.Nil(t, err, "Failed to save channel with multiple signing identities: %s", err)
assert.NotEmpty(t, resp.TransactionID, "transaction ID should be populated")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/fab/comm/network.go
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/pkg/errors"
)

// NetworkPeerConfigFromURL fetches the peer configuration based on a URL.
func NetworkPeerConfigFromURL(cfg fab.EndpointConfig, url string) (*fab.NetworkPeer, error) {
peerCfg, err := cfg.PeerConfig(url)
// NetworkPeerConfig fetches the peer configuration based on a key (name or URL).
func NetworkPeerConfig(cfg fab.EndpointConfig, key string) (*fab.NetworkPeer, error) {
peerCfg, err := cfg.PeerConfig(key)
if err != nil {
return nil, errors.WithMessage(err, "peer not found")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/fab/comm/network_test.go
Expand Up @@ -30,15 +30,15 @@ func TestNetworkPeerConfigFromURL(t *testing.T) {
t.Fatalf("Unexpected error reading config: %v", err)
}

_, err = NetworkPeerConfigFromURL(sampleConfig, "invalid")
_, err = NetworkPeerConfig(sampleConfig, "invalid")
assert.NotNil(t, err, "invalid url should return err")

np, err := NetworkPeerConfigFromURL(sampleConfig, "peer0.org2.example.com:8051")
np, err := NetworkPeerConfig(sampleConfig, "peer0.org2.example.com:8051")
assert.Nil(t, err, "valid url should not return err")
assert.Equal(t, "peer0.org2.example.com:8051", np.URL, "wrong URL")
assert.Equal(t, "Org2MSP", np.MSPID, "wrong MSP")

np, err = NetworkPeerConfigFromURL(sampleConfig, "peer0.org1.example.com:7051")
np, err = NetworkPeerConfig(sampleConfig, "peer0.org1.example.com:7051")
assert.Nil(t, err, "valid url should not return err")
assert.Equal(t, "peer0.org1.example.com:7051", np.URL, "wrong URL")
assert.Equal(t, "Org1MSP", np.MSPID, "wrong MSP")
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/endpointconfig.go
Expand Up @@ -254,7 +254,7 @@ func (c *EndpointConfig) PeersConfig(org string) ([]fab.PeerConfig, error) {
return peers, nil
}

// PeerConfig Retrieves a specific peer from the configuration by org and name
// PeerConfig Retrieves a specific peer from the configuration by name or url
func (c *EndpointConfig) PeerConfig(nameOrURL string) (*fab.PeerConfig, error) {
networkConfig, err := c.NetworkConfig()
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/fab/events/deliverclient/deliverclient_test.go
Expand Up @@ -449,10 +449,6 @@ func newMockConfig() *mockConfig {
}
}

func (c *mockConfig) PeerConfigByURL(url string) (*fab.PeerConfig, error) {
return &fab.PeerConfig{}, nil
}

func newMockContext() *fabmocks.MockContext {
ctx := fabmocks.NewMockContextWithCustomDiscovery(
mspmocks.NewMockSigningIdentity("user1", "test1"),
Expand Down
14 changes: 0 additions & 14 deletions pkg/fab/events/endpoint/endpoint_test.go
Expand Up @@ -26,12 +26,7 @@ var p1 = fabmocks.NewMockPeer("p1", url1)
var p2 = fabmocks.NewMockPeer("p2", url2)
var p3 = fabmocks.NewMockPeer("p3", url3)

var pc1 = fab.PeerConfig{URL: url1}
var pc2 = fab.PeerConfig{URL: url2}
var pc3 = fab.PeerConfig{URL: url3}

var peers = []fab.Peer{p1, p2, p3}
var peerConfigs = []fab.PeerConfig{pc1, pc2, pc3}

func TestEndpoint(t *testing.T) {
expectedEventURL := "localhost:7053"
Expand Down Expand Up @@ -146,15 +141,6 @@ func newMockConfig(channelPeers ...fab.ChannelPeer) *mockConfig {
}
}

func (c *mockConfig) PeerConfigByURL(url string) (*fab.PeerConfig, error) {
for _, pc := range peerConfigs {
if pc.URL == url {
return &pc, nil
}
}
return nil, nil
}

func (c *mockConfig) ChannelPeers(name string) ([]fab.ChannelPeer, error) {
fmt.Printf("mockConfig.ChannelPeers - returning %#v", c.channelPeers)
return c.channelPeers, nil
Expand Down
4 changes: 2 additions & 2 deletions test/integration/e2e/end_to_end.go
Expand Up @@ -133,7 +133,7 @@ func createChannelAndCC(t *testing.T, sdk *fabsdk.FabricSDK) {
}

// Org peers join channel
if err = orgResMgmt.JoinChannel(channelID, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com")); err != nil {
if err = orgResMgmt.JoinChannel(channelID, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com")); err != nil {
t.Fatalf("Org peers failed to JoinChannel: %s", err)
}

Expand Down Expand Up @@ -204,7 +204,7 @@ func createChannel(sdk *fabsdk.FabricSDK, t *testing.T, resMgmtClient *resmgmt.C
req := resmgmt.SaveChannelRequest{ChannelID: channelID,
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
SigningIdentities: []msp.SigningIdentity{adminIdentity}}
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com"))
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com"))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")
}
2 changes: 1 addition & 1 deletion test/integration/expiredpeer/expired_certificate_test.go
Expand Up @@ -77,7 +77,7 @@ func TestExpiredPeersCert(t *testing.T) {
req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com"))
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com"))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")

Expand Down

0 comments on commit da948b4

Please sign in to comment.