Skip to content

Commit 7144508

Browse files
committed
[FAB-1938] add orderer endpoint param to peer cli
Currently peer cli receives ordering service endpoint via environmental variable CORE_PEER_COMMITTER_LEDGER_ORDERER. Because ordering service endpoint will be provided with configuration transaction in the ledger block the env. variable will be depricate. This commit is 1 out of 3, takes care to switch peer cli to use new command line parameter, for example: peer channel create -o ordering_host:port .... Change-Id: I82fcb4f425d80489cb815b706b2d2d01b5e26827 Signed-off-by: Artem Barger <[email protected]>
1 parent be91ccc commit 7144508

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

examples/ccchecker/ccchecker.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ func CCCheckerInit() {
9090
}
9191

9292
//CCCheckerRun main loops that will run the tests and cleanup
93-
func CCCheckerRun(report bool, verbose bool) error {
93+
func CCCheckerRun(orderingEndpoint string, report bool, verbose bool) error {
9494
//connect with Broadcast client
95-
bc, err := common.GetBroadcastClient()
95+
bc, err := common.GetBroadcastClient(orderingEndpoint)
9696
if err != nil {
9797
return err
9898
}

examples/ccchecker/main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ var mainCmd = &cobra.Command{
4040
},
4141
}
4242

43+
var orderingEndpoint string
44+
4345
func main() {
4446
mainFlags := mainCmd.PersistentFlags()
45-
47+
mainFlags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint")
4648
//initialize the env
4749
InitCCCheckerEnv(mainFlags)
4850

@@ -56,7 +58,7 @@ func main() {
5658
func run(args []string) {
5759
CCCheckerInit()
5860
//TODO make parameters out of report and verbose
59-
CCCheckerRun(true, true)
61+
CCCheckerRun(orderingEndpoint, true, true)
6062
fmt.Printf("Test complete\n")
6163
return
6264
}

peer/chaincode/chaincode.go

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func AddFlags(cmd *cobra.Command) {
5656
fmt.Sprint("The name of the endorsement system chaincode to be used for this chaincode"))
5757
flags.StringVarP(&vscc, "vscc", "V", common.UndefinedParamValue,
5858
fmt.Sprint("The name of the verification system chaincode to be used for this chaincode"))
59+
flags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint")
5960
}
6061

6162
// Cmd returns the cobra command for Chaincode
@@ -88,6 +89,7 @@ var (
8889
escc string
8990
vscc string
9091
policyMarhsalled []byte
92+
orderingEndpoint string
9193
)
9294

9395
var chaincodeCmd = &cobra.Command{

peer/chaincode/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func InitCmdFactory() (*ChaincodeCmdFactory, error) {
229229
return nil, fmt.Errorf("Error getting default signer: %s", err)
230230
}
231231

232-
broadcastClient, err := common.GetBroadcastClient()
232+
broadcastClient, err := common.GetBroadcastClient(orderingEndpoint)
233233
if err != nil {
234234
return nil, fmt.Errorf("Error getting broadcast client: %s", err)
235235
}

peer/channel/channel.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package channel
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"github.com/hyperledger/fabric/msp"
2324
"github.com/hyperledger/fabric/peer/common"
2425
ab "github.com/hyperledger/fabric/protos/orderer"
2526
pb "github.com/hyperledger/fabric/protos/peer"
2627
"github.com/op/go-logging"
2728
"github.com/spf13/cobra"
28-
"github.com/spf13/viper"
2929
"golang.org/x/net/context"
3030
"google.golang.org/grpc"
3131
)
@@ -39,17 +39,13 @@ var (
3939
genesisBlockPath string
4040

4141
// create related variables
42-
chainID string
43-
channelTxFile string
42+
chainID string
43+
channelTxFile string
44+
orderingEndpoint string
4445
)
4546

4647
// Cmd returns the cobra command for Node
4748
func Cmd(cf *ChannelCmdFactory) *cobra.Command {
48-
//the "peer.committer.enabled" flag should really go away...
49-
//basically we need the orderer for create and join
50-
if !viper.GetBool("peer.committer.enabled") || viper.GetString("peer.committer.ledger.orderer") == "" {
51-
panic("orderer not provided")
52-
}
5349

5450
AddFlags(channelCmd)
5551
channelCmd.AddCommand(joinCmd(cf))
@@ -66,6 +62,7 @@ func AddFlags(cmd *cobra.Command) {
6662
flags.StringVarP(&genesisBlockPath, "blockpath", "b", common.UndefinedParamValue, "Path to file containing genesis block")
6763
flags.StringVarP(&chainID, "chain", "c", common.UndefinedParamValue, "In case of a newChain command, the chain ID to create.")
6864
flags.StringVarP(&channelTxFile, "file", "f", "", "Configuration transaction file generated by a tool such as configtxgen for submitting to orderer")
65+
flags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint")
6966
}
7067

7168
var channelCmd = &cobra.Command{
@@ -97,7 +94,7 @@ func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) {
9794
}
9895

9996
cmdFact.BroadcastFactory = func() (common.BroadcastClient, error) {
100-
return common.GetBroadcastClient()
97+
return common.GetBroadcastClient(orderingEndpoint)
10198
}
10299

103100
if err != nil {
@@ -111,8 +108,12 @@ func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) {
111108
return nil, fmt.Errorf("Error getting endorser client %s: %s", channelFuncName, err)
112109
}
113110
} else {
114-
orderer := viper.GetString("peer.committer.ledger.orderer")
115-
conn, err := grpc.Dial(orderer, grpc.WithInsecure())
111+
112+
if len(strings.Split(orderingEndpoint, ":")) != 2 {
113+
return nil, fmt.Errorf("Ordering service endpoint %s is not valid or missing", orderingEndpoint)
114+
}
115+
116+
conn, err := grpc.Dial(orderingEndpoint, grpc.WithInsecure())
116117
if err != nil {
117118
return nil, err
118119
}

peer/channel/create_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626

2727
"github.com/golang/protobuf/proto"
2828

29+
"errors"
30+
2931
"github.com/hyperledger/fabric/msp/mgmt/testtools"
3032
"github.com/hyperledger/fabric/peer/common"
3133
cb "github.com/hyperledger/fabric/protos/common"
@@ -103,7 +105,7 @@ func TestCreateChain(t *testing.T) {
103105

104106
AddFlags(cmd)
105107

106-
args := []string{"-c", mockchain}
108+
args := []string{"-c", mockchain, "-o", "localhost:7050"}
107109
cmd.SetArgs(args)
108110

109111
if err := cmd.Execute(); err != nil {
@@ -134,7 +136,7 @@ func TestCreateChainWithDefaultAnchorPeers(t *testing.T) {
134136

135137
AddFlags(cmd)
136138

137-
args := []string{"-c", mockchain}
139+
args := []string{"-c", mockchain, "-o", "localhost:7050"}
138140
cmd.SetArgs(args)
139141

140142
if err := cmd.Execute(); err != nil {
@@ -155,7 +157,7 @@ func TestCreateChainBCFail(t *testing.T) {
155157
t.Fatalf("Get default signer error: %v", err)
156158
}
157159

158-
sendErr := fmt.Errorf("send create tx failed")
160+
sendErr := errors.New("send create tx failed")
159161

160162
mockCF := &ChannelCmdFactory{
161163
BroadcastFactory: func() (common.BroadcastClient, error) {
@@ -169,7 +171,7 @@ func TestCreateChainBCFail(t *testing.T) {
169171

170172
AddFlags(cmd)
171173

172-
args := []string{"-c", mockchain}
174+
args := []string{"-c", mockchain, "-o", "localhost:7050"}
173175
cmd.SetArgs(args)
174176

175177
expectedErrMsg := sendErr.Error()
@@ -206,7 +208,7 @@ func TestCreateChainDeliverFail(t *testing.T) {
206208

207209
AddFlags(cmd)
208210

209-
args := []string{"-c", mockchain}
211+
args := []string{"-c", mockchain, "-o", "localhost:7050"}
210212
cmd.SetArgs(args)
211213

212214
expectedErrMsg := recvErr.Error()
@@ -277,7 +279,7 @@ func TestCreateChainFromTx(t *testing.T) {
277279

278280
AddFlags(cmd)
279281

280-
args := []string{"-c", mockchannel, "-f", file}
282+
args := []string{"-c", mockchannel, "-f", file, "-o", "localhost:7050"}
281283
cmd.SetArgs(args)
282284

283285
if _, err = createTxFile(file, cb.HeaderType_CONFIG_UPDATE, mockchannel); err != nil {
@@ -321,7 +323,7 @@ func TestCreateChainInvalidTx(t *testing.T) {
321323

322324
AddFlags(cmd)
323325

324-
args := []string{"-c", mockchannel, "-f", file}
326+
args := []string{"-c", mockchannel, "-f", file, "-o", "localhost:7050"}
325327
cmd.SetArgs(args)
326328

327329
//bad type CONFIG

peer/common/ordererclient.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ package common
1818

1919
import (
2020
"fmt"
21+
"strings"
2122
"time"
2223

2324
cb "github.com/hyperledger/fabric/protos/common"
2425
ab "github.com/hyperledger/fabric/protos/orderer"
25-
"github.com/spf13/viper"
2626
"golang.org/x/net/context"
2727
"google.golang.org/grpc"
2828
)
@@ -39,29 +39,25 @@ type broadcastClient struct {
3939
}
4040

4141
// GetBroadcastClient creates a simple instance of the BroadcastClient interface
42-
func GetBroadcastClient() (BroadcastClient, error) {
43-
var orderer string
44-
if viper.GetBool("peer.committer.enabled") {
45-
orderer = viper.GetString("peer.committer.ledger.orderer")
46-
}
42+
func GetBroadcastClient(orderingEndpoint string) (BroadcastClient, error) {
4743

48-
if orderer == "" {
49-
return nil, fmt.Errorf("Can't get orderer address")
44+
if len(strings.Split(orderingEndpoint, ":")) != 2 {
45+
return nil, fmt.Errorf("Ordering service endpoint %s is not valid or missing", orderingEndpoint)
5046
}
5147

5248
var opts []grpc.DialOption
5349
opts = append(opts, grpc.WithInsecure())
5450
opts = append(opts, grpc.WithTimeout(3*time.Second))
5551
opts = append(opts, grpc.WithBlock())
5652

57-
conn, err := grpc.Dial(orderer, opts...)
53+
conn, err := grpc.Dial(orderingEndpoint, opts...)
5854
if err != nil {
59-
return nil, fmt.Errorf("Error connecting to %s due to %s", orderer, err)
55+
return nil, fmt.Errorf("Error connecting to %s due to %s", orderingEndpoint, err)
6056
}
6157
client, err := ab.NewAtomicBroadcastClient(conn).Broadcast(context.TODO())
6258
if err != nil {
6359
conn.Close()
64-
return nil, fmt.Errorf("Error connecting to %s due to %s", orderer, err)
60+
return nil, fmt.Errorf("Error connecting to %s due to %s", orderingEndpoint, err)
6561
}
6662

6763
return &broadcastClient{conn: conn, client: client}, nil

0 commit comments

Comments
 (0)