From 7beda2c830d8d474eda0b187ef9cd8ecb3195724 Mon Sep 17 00:00:00 2001 From: r2roC <67290864+r2roC@users.noreply.github.com> Date: Thu, 9 Jul 2020 15:53:17 -0400 Subject: [PATCH] [FAB-18047] Implement kafka brokers removal function (#33) Signed-off-by: Arturo Cabre Signed-off-by: Tiffany Harris Co-authored-by: Tiffany Harris --- configtx/example_test.go | 22 ++++++++++++++++ configtx/orderer.go | 6 +++++ configtx/orderer_test.go | 54 ++++++++++++++++++++++++++++++++++++++++ go.mod | 1 - 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/configtx/example_test.go b/configtx/example_test.go index 0815543..8bc92c6 100644 --- a/configtx/example_test.go +++ b/configtx/example_test.go @@ -584,6 +584,28 @@ func ExampleConsortiumOrg_SetMSP() { } } +func ExampleOrdererGroup_RemoveLegacyKafkaBrokers() { + + baseConfig := fetchChannelConfig() + c := configtx.New(baseConfig) + ordererConfig, err := c.Orderer().Configuration() + if err != nil { + panic(err) + } + ordererConfig.OrdererType = orderer.ConsensusTypeEtcdRaft + ordererConfig.EtcdRaft = orderer.EtcdRaft{ + Consenters: []orderer.Consenter{ + {Address: orderer.EtcdAddress{ + Host: "host1", + Port: 7050}, + ClientTLSCert: generateCert(), + ServerTLSCert: generateCert(), + }, + }, + } + c.Orderer().RemoveLegacyKafkaBrokers() +} + // fetchChannelConfig mocks retrieving the config transaction from the most recent configuration block. func fetchChannelConfig() *cb.Config { return &cb.Config{ diff --git a/configtx/orderer.go b/configtx/orderer.go index e18a530..ff0c45e 100644 --- a/configtx/orderer.go +++ b/configtx/orderer.go @@ -539,6 +539,12 @@ func (o *OrdererOrg) Policies() (map[string]Policy, error) { return getPolicies(o.orgGroup.Policies) } +// RemoveLegacyKafkaBrokers removes the legacy kafka brokers config key and value from config. +// In fabric 2.0, kafka was deprecated as a consensus type. +func (o *OrdererGroup) RemoveLegacyKafkaBrokers() { + delete(o.ordererGroup.Values, orderer.KafkaBrokersKey) +} + // newOrdererGroup returns the orderer component of the channel configuration. // It defines parameters of the ordering service about how large blocks should be, // how frequently they should be emitted, etc. as well as the organizations of the ordering network. diff --git a/configtx/orderer_test.go b/configtx/orderer_test.go index 8fb260e..d6cf7b5 100644 --- a/configtx/orderer_test.go +++ b/configtx/orderer_test.go @@ -20,6 +20,7 @@ import ( "github.com/hyperledger/fabric-config/protolator" "github.com/hyperledger/fabric-config/protolator/protoext/ordererext" cb "github.com/hyperledger/fabric-protos-go/common" + ob "github.com/hyperledger/fabric-protos-go/orderer" . "github.com/onsi/gomega" ) @@ -3928,6 +3929,59 @@ func TestUpdateOrdererMSPFailure(t *testing.T) { } } +func TestRemoveLegacyKafkaBrokers(t *testing.T) { + t.Parallel() + + gt := NewGomegaWithT(t) + + channelGroup, _, err := baseOrdererChannelGroup(t, orderer.ConsensusTypeKafka) + gt.Expect(err).NotTo(HaveOccurred()) + + config := &cb.Config{ + ChannelGroup: channelGroup, + } + + c := New(config) + + c.Orderer().RemoveLegacyKafkaBrokers() + + expectedConfigValue := map[string]*cb.ConfigValue{ + orderer.ConsensusTypeKey: { + ModPolicy: AdminsPolicyKey, + Value: marshalOrPanic(&ob.ConsensusType{ + Type: orderer.ConsensusTypeKafka, + }), + }, + orderer.ChannelRestrictionsKey: { + ModPolicy: AdminsPolicyKey, + }, + CapabilitiesKey: { + ModPolicy: AdminsPolicyKey, + Value: marshalOrPanic(&cb.Capabilities{ + Capabilities: map[string]*cb.Capability{ + "V1_3": {}, + }, + }), + }, + orderer.BatchTimeoutKey: { + ModPolicy: AdminsPolicyKey, + Value: marshalOrPanic(&ob.BatchTimeout{ + Timeout: "0s", + }), + }, + orderer.BatchSizeKey: { + ModPolicy: AdminsPolicyKey, + Value: marshalOrPanic(&ob.BatchSize{ + MaxMessageCount: 100, + AbsoluteMaxBytes: 100, + PreferredMaxBytes: 100, + }), + }, + } + + gt.Expect(c.Orderer().ordererGroup.Values).To(Equal(expectedConfigValue)) +} + func baseOrdererOfType(t *testing.T, ordererType string) (Orderer, []*ecdsa.PrivateKey) { switch ordererType { case orderer.ConsensusTypeKafka: diff --git a/go.mod b/go.mod index b1e3080..4aec4db 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,4 @@ require ( github.com/golang/protobuf v1.3.3 github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e github.com/onsi/gomega v1.9.0 - golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 )