Skip to content

Commit

Permalink
[FAB-2152] Migrate app config to ConfigGroup
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2152

The ConfigItem proto is deprecated, pending removal.  This CR migrates
the application config to the newer ConfigGroup mechanism.

Change-Id: Ic48125dd4930afccae42cffda02211718559311e
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 12, 2017
1 parent 63e54d1 commit f5ab160
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 40 deletions.
2 changes: 1 addition & 1 deletion common/configtx/handlers/application/sharedconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var Schema = &cb.ConfigGroupSchema{

// Peer config keys
const (
// AnchorPeersKey is the cb.ConfigItem type key name for the AnchorPeers message
// AnchorPeersKey is the key name for the AnchorPeers ConfigValue
AnchorPeersKey = "AnchorPeers"
)

Expand Down
9 changes: 6 additions & 3 deletions common/configtx/handlers/application/sharedconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ func makeInvalidConfigValue() *cb.ConfigValue {
}
}

func itemToValue(configItem *cb.ConfigItem) (string, *cb.ConfigValue) {
return configItem.Key, &cb.ConfigValue{Value: configItem.Value}
func groupToKeyValue(configGroup *cb.ConfigGroup) (string, *cb.ConfigValue) {
for key, value := range configGroup.Groups[GroupKey].Values {
return key, value
}
panic("No value encoded")
}

func TestInterface(t *testing.T) {
Expand Down Expand Up @@ -92,7 +95,7 @@ func TestAnchorPeers(t *testing.T) {
t.Fatalf("Should have failed on invalid message")
}

err = m.ProposeConfig(itemToValue(validMessage))
err = m.ProposeConfig(groupToKeyValue(validMessage))
if err != nil {
t.Fatalf("Error applying valid config: %s", err)
}
Expand Down
19 changes: 12 additions & 7 deletions common/configtx/handlers/application/sharedconfig_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ import (

var defaultAnchorPeers = []*pb.AnchorPeer{}

// TemplateAnchorPeers creates a headerless config item representing the anchor peers
func TemplateAnchorPeers(anchorPeers []*pb.AnchorPeer) *cb.ConfigItem {
return &cb.ConfigItem{
Type: cb.ConfigItem_PEER,
Key: AnchorPeersKey,
Value: utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}),
func configGroup(key string, value []byte) *cb.ConfigGroup {
result := cb.NewConfigGroup()
result.Groups[GroupKey] = cb.NewConfigGroup()
result.Groups[GroupKey].Values[key] = &cb.ConfigValue{
Value: value,
}
return result
}

// TemplateAnchorPeers creates a headerless config item representing the anchor peers
func TemplateAnchorPeers(anchorPeers []*pb.AnchorPeer) *cb.ConfigGroup {
return configGroup(AnchorPeersKey, utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}))
}

// DefaultAnchorPeers creates a headerless config item for the default orderer addresses
func DefaultAnchorPeers() *cb.ConfigItem {
func DefaultAnchorPeers() *cb.ConfigGroup {
return TemplateAnchorPeers(defaultAnchorPeers)
}
28 changes: 0 additions & 28 deletions common/configtx/handlers/application/template_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion peer/channel/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func sendCreateChainTransaction(cf *ChannelCmdFactory) error {
//TODO this is a temporary hack until `orderer.template` and 'msp.template' is supplied from the CLI
oTemplate := configtxtest.OrdererTemplate()
mspTemplate := configtxtest.MSPTemplate()
gossTemplate := configtx.NewSimpleTemplate(configtxapplication.TemplateAnchorPeers(anchorPeers))
gossTemplate := configtx.NewSimpleTemplateNext(configtxapplication.TemplateAnchorPeers(anchorPeers))
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, mspTemplate, gossTemplate)

signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()
Expand Down

0 comments on commit f5ab160

Please sign in to comment.