Skip to content

Commit

Permalink
[FAB-18047] Implement kafka brokers removal function (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: Arturo Cabre <[email protected]>

Signed-off-by: Tiffany Harris <[email protected]>

Co-authored-by: Tiffany Harris <[email protected]>
  • Loading branch information
r2roC and stephyee authored Jul 9, 2020
1 parent 26dfec1 commit 7beda2c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
22 changes: 22 additions & 0 deletions configtx/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 6 additions & 0 deletions configtx/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 54 additions & 0 deletions configtx/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 7beda2c

Please sign in to comment.