From 1491559578200f0c2a0d2553df07e2a5170b0e7b Mon Sep 17 00:00:00 2001 From: Sandra Vrtikapa Date: Mon, 5 Mar 2018 15:06:22 -0500 Subject: [PATCH] [FAB-8863]: Rename WithProposalProcessor to WithTargets Change-Id: I784bf7f41a0c48d17eb28d1b7dad64d2a54eb890 Signed-off-by: Sandra Vrtikapa --- pkg/client/channel/api.go | 12 ++++++------ pkg/client/channel/chclient.go | 2 +- pkg/client/channel/chclient_test.go | 6 ++---- pkg/client/channel/invoke/api.go | 6 +++--- pkg/client/channel/invoke/txnhandler.go | 8 ++++---- pkg/client/channel/invoke/txnhandler_test.go | 16 ++++++++-------- .../dynamicselection/ccpolicyprovider.go | 2 +- test/integration/orgs/multiple_orgs_test.go | 12 ++++++------ 8 files changed, 31 insertions(+), 33 deletions(-) diff --git a/pkg/client/channel/api.go b/pkg/client/channel/api.go index c3eb59c80c..4ad440c24a 100644 --- a/pkg/client/channel/api.go +++ b/pkg/client/channel/api.go @@ -29,9 +29,9 @@ type Registration interface { // opts allows the user to specify more advanced options type opts struct { - ProposalProcessors []fab.ProposalProcessor // targets - Timeout time.Duration - Retry retry.Opts + Targets []fab.Peer // targets + Timeout time.Duration + Retry retry.Opts } //Option func for each Opts argument @@ -62,10 +62,10 @@ func WithTimeout(timeout time.Duration) Option { } } -//WithProposalProcessor encapsulates ProposalProcessors to Option -func WithProposalProcessor(proposalProcessors ...fab.ProposalProcessor) Option { +//WithTargets encapsulates ProposalProcessors to Option +func WithTargets(targets []fab.Peer) Option { return func(o *opts) error { - o.ProposalProcessors = proposalProcessors + o.Targets = targets return nil } } diff --git a/pkg/client/channel/chclient.go b/pkg/client/channel/chclient.go index 4a81859406..0b3a8bc36b 100644 --- a/pkg/client/channel/chclient.go +++ b/pkg/client/channel/chclient.go @@ -139,7 +139,7 @@ func (cc *Client) resolveRetry(ctx *invoke.RequestContext, o opts) bool { cc.greylist.Greylist(e) // Reset context parameters - ctx.Opts.ProposalProcessors = o.ProposalProcessors + ctx.Opts.Targets = o.Targets ctx.Error = nil ctx.Response = invoke.Response{} diff --git a/pkg/client/channel/chclient_test.go b/pkg/client/channel/chclient_test.go index 344ad44565..3d2944ac38 100644 --- a/pkg/client/channel/chclient_test.go +++ b/pkg/client/channel/chclient_test.go @@ -171,10 +171,8 @@ func TestQueryWithOptTarget(t *testing.T) { peers := []fab.Peer{testPeer} - targets := peer.PeersToTxnProcessors(peers) - response, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", - Args: [][]byte{[]byte("query"), []byte("b")}}, WithProposalProcessor(targets...)) + Args: [][]byte{[]byte("query"), []byte("b")}}, WithTargets(peers)) if err != nil { t.Fatalf("Failed to invoke test cc: %s", err) } @@ -251,7 +249,7 @@ type customEndorsementHandler struct { } func (h *customEndorsementHandler) Handle(requestContext *invoke.RequestContext, clientContext *invoke.ClientContext) { - transactionProposalResponses, txnID, err := createAndSendTestTransactionProposal(h.transactor, &requestContext.Request, requestContext.Opts.ProposalProcessors) + transactionProposalResponses, txnID, err := createAndSendTestTransactionProposal(h.transactor, &requestContext.Request, peer.PeersToTxnProcessors(requestContext.Opts.Targets)) requestContext.Response.TransactionID = txnID diff --git a/pkg/client/channel/invoke/api.go b/pkg/client/channel/invoke/api.go index 1c94b68c7f..0aca754f20 100644 --- a/pkg/client/channel/invoke/api.go +++ b/pkg/client/channel/invoke/api.go @@ -18,9 +18,9 @@ import ( // Opts allows the user to specify more advanced options type Opts struct { - ProposalProcessors []fab.ProposalProcessor // targets - Timeout time.Duration - Retry retry.Opts + Targets []fab.Peer // targets + Timeout time.Duration + Retry retry.Opts } // Request contains the parameters to execute transaction diff --git a/pkg/client/channel/invoke/txnhandler.go b/pkg/client/channel/invoke/txnhandler.go index b3c3fd6dd1..f82fd25bd7 100644 --- a/pkg/client/channel/invoke/txnhandler.go +++ b/pkg/client/channel/invoke/txnhandler.go @@ -30,13 +30,13 @@ type EndorsementHandler struct { //Handle for endorsing transactions func (e *EndorsementHandler) Handle(requestContext *RequestContext, clientContext *ClientContext) { - if len(requestContext.Opts.ProposalProcessors) == 0 { + if len(requestContext.Opts.Targets) == 0 { requestContext.Error = status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "targets were not provided", nil) return } // Endorse Tx - transactionProposalResponses, proposal, err := createAndSendTransactionProposal(clientContext.Transactor, &requestContext.Request, requestContext.Opts.ProposalProcessors) + transactionProposalResponses, proposal, err := createAndSendTransactionProposal(clientContext.Transactor, &requestContext.Request, peer.PeersToTxnProcessors(requestContext.Opts.Targets)) requestContext.Response.Proposal = proposal requestContext.Response.TransactionID = proposal.TxnID // TODO: still needed? @@ -66,7 +66,7 @@ type ProposalProcessorHandler struct { func (h *ProposalProcessorHandler) Handle(requestContext *RequestContext, clientContext *ClientContext) { //Get proposal processor, if not supplied then use discovery service to get available peers as endorser //If selection service available then get endorser peers for this chaincode - if len(requestContext.Opts.ProposalProcessors) == 0 { + if len(requestContext.Opts.Targets) == 0 { // Use discovery service to figure out proposal processors peers, err := clientContext.Discovery.GetPeers() if err != nil { @@ -81,7 +81,7 @@ func (h *ProposalProcessorHandler) Handle(requestContext *RequestContext, client return } } - requestContext.Opts.ProposalProcessors = peer.PeersToTxnProcessors(endorsers) + requestContext.Opts.Targets = endorsers } //Delegate to next step if any diff --git a/pkg/client/channel/invoke/txnhandler_test.go b/pkg/client/channel/invoke/txnhandler_test.go index 9a34be3cba..004a91c419 100644 --- a/pkg/client/channel/invoke/txnhandler_test.go +++ b/pkg/client/channel/invoke/txnhandler_test.go @@ -153,7 +153,7 @@ func TestExecuteTxHandlerErrors(t *testing.T) { func TestEndorsementHandler(t *testing.T) { request := Request{ChaincodeID: "test", Fcn: "invoke", Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}} - requestContext := prepareRequestContext(request, Opts{ProposalProcessors: []fab.ProposalProcessor{fcmocks.NewMockPeer("p2", "")}}, t) + requestContext := prepareRequestContext(request, Opts{Targets: []fab.Peer{fcmocks.NewMockPeer("p2", "")}}, t) clientContext := setupChannelClientContext(nil, nil, nil, t) handler := NewEndorsementHandler() @@ -183,23 +183,23 @@ func TestProposalProcessorHandler(t *testing.T) { if requestContext.Error != nil { t.Fatalf("Got error: %s", requestContext.Error) } - if len(requestContext.Opts.ProposalProcessors) != len(discoveryPeers) { - t.Fatalf("Expecting %d proposal processors but got %d", len(discoveryPeers), len(requestContext.Opts.ProposalProcessors)) + if len(requestContext.Opts.Targets) != len(discoveryPeers) { + t.Fatalf("Expecting %d proposal processors but got %d", len(discoveryPeers), len(requestContext.Opts.Targets)) } - if requestContext.Opts.ProposalProcessors[0] != peer1 || requestContext.Opts.ProposalProcessors[1] != peer2 { + if requestContext.Opts.Targets[0] != peer1 || requestContext.Opts.Targets[1] != peer2 { t.Fatalf("Didn't get expected peers") } // Directly pass in the proposal processors. In this case it should use those directly - requestContext = prepareRequestContext(request, Opts{ProposalProcessors: []fab.ProposalProcessor{peer2}}, t) + requestContext = prepareRequestContext(request, Opts{Targets: []fab.Peer{peer2}}, t) handler.Handle(requestContext, setupChannelClientContext(nil, nil, discoveryPeers, t)) if requestContext.Error != nil { t.Fatalf("Got error: %s", requestContext.Error) } - if len(requestContext.Opts.ProposalProcessors) != 1 { - t.Fatalf("Expecting 1 proposal processor but got %d", len(requestContext.Opts.ProposalProcessors)) + if len(requestContext.Opts.Targets) != 1 { + t.Fatalf("Expecting 1 proposal processor but got %d", len(requestContext.Opts.Targets)) } - if requestContext.Opts.ProposalProcessors[0] != peer2 { + if requestContext.Opts.Targets[0] != peer2 { t.Fatalf("Didn't get expected peers") } } diff --git a/pkg/client/common/selection/dynamicselection/ccpolicyprovider.go b/pkg/client/common/selection/dynamicselection/ccpolicyprovider.go index d3e1895369..7647e6b2b4 100644 --- a/pkg/client/common/selection/dynamicselection/ccpolicyprovider.go +++ b/pkg/client/common/selection/dynamicselection/ccpolicyprovider.go @@ -149,7 +149,7 @@ func (dp *ccPolicyProvider) queryChaincode(ccID string, ccFcn string, ccArgs [][ Args: ccArgs, } - resp, err := client.Query(request, channel.WithProposalProcessor(peer)) + resp, err := client.Query(request, channel.WithTargets([]fab.Peer{peer})) if err != nil { queryErrors = append(queryErrors, err.Error()) continue diff --git a/test/integration/orgs/multiple_orgs_test.go b/test/integration/orgs/multiple_orgs_test.go index b758b11148..60cb75d5d8 100644 --- a/test/integration/orgs/multiple_orgs_test.go +++ b/test/integration/orgs/multiple_orgs_test.go @@ -176,7 +176,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int { t.Fatalf("Failed to create new ledger client: %s", err) } - channelCfg, err := ledgerClient.QueryConfig(ledger.WithTargets(orgTestPeer0.(fab.Peer), orgTestPeer1.(fab.Peer)), ledger.WithMinTargets(2)) + channelCfg, err := ledgerClient.QueryConfig(ledger.WithTargets(orgTestPeer0, orgTestPeer1), ledger.WithMinTargets(2)) if err != nil { t.Fatalf("QueryConfig return error: %v", err) } @@ -188,7 +188,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int { t.Fatalf("Expecting %s, got %s", expectedOrderer, channelCfg.Orderers()[0]) } - ledgerInfoBefore, err := ledgerClient.QueryInfo(ledger.WithTargets(orgTestPeer0.(fab.Peer), orgTestPeer1.(fab.Peer)), ledger.WithMinTargets(2), ledger.WithMaxTargets(3)) + ledgerInfoBefore, err := ledgerClient.QueryInfo(ledger.WithTargets(orgTestPeer0, orgTestPeer1), ledger.WithMinTargets(2), ledger.WithMaxTargets(3)) if err != nil { t.Fatalf("QueryInfo return error: %v", err) } @@ -203,7 +203,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int { } // Org2 user moves funds on org2 peer - response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithProposalProcessor(orgTestPeer1)) + response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer1})) if err != nil { t.Fatalf("Failed to move funds: %s", err) } @@ -267,13 +267,13 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int { } // Org2 user moves funds on org2 peer (cc policy fails since both Org1 and Org2 peers should participate) - response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithProposalProcessor(orgTestPeer1)) + response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer1})) if err == nil { t.Fatalf("Should have failed to move funds due to cc policy") } // Org2 user moves funds (cc policy ok since we have provided peers for both Orgs) - response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithProposalProcessor(orgTestPeer0, orgTestPeer1)) + response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer0, orgTestPeer1})) if err != nil { t.Fatalf("Failed to move funds: %s", err) } @@ -331,7 +331,7 @@ func verifyValue(t *testing.T, chClient *channel.Client, expected int) { var valueInt int for i := 0; i < pollRetries; i++ { // Query final value on org1 peer - response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithProposalProcessor(orgTestPeer0)) + response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer0})) if err != nil { t.Fatalf("Failed to query funds after transaction: %s", err) }