Skip to content

Commit

Permalink
[FAB-2477] Move application config to Proposer
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2477

This CR continues the cleanup of the assorted config handlers, this time
for the application config.  There is a noticable reduction in code
complexity as the application config currently has no values, only
sub-groups.

Change-Id: I40295c7c46a51284ddbaca317bc8ba494c04a628
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Mar 7, 2017
1 parent c8ff4b1 commit b609bf0
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 193 deletions.
3 changes: 1 addition & 2 deletions common/configtx/test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/hyperledger/fabric/common/configtx"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
configtxmsp "github.com/hyperledger/fabric/common/configvalues/msp"
config "github.com/hyperledger/fabric/common/configvalues/root"
"github.com/hyperledger/fabric/common/genesis"
Expand Down Expand Up @@ -95,7 +94,7 @@ func ApplicationOrgTemplate() configtx.Template {
if err != nil {
logger.Panicf("Could not load sample MSP config: %s", err)
}
return configtx.NewSimpleTemplate(configtxmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey, sampleOrgID}, mspConf))
return configtx.NewSimpleTemplate(configtxmsp.TemplateGroupMSP([]string{config.ApplicationGroupKey, sampleOrgID}, mspConf))
}

// OrdererOrgTemplate returns the SAMPLE org with MSP template
Expand Down
13 changes: 6 additions & 7 deletions common/configtx/tool/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/configtx"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
configvaluesmsp "github.com/hyperledger/fabric/common/configvalues/msp"
config "github.com/hyperledger/fabric/common/configvalues/root"
"github.com/hyperledger/fabric/common/genesis"
Expand Down Expand Up @@ -140,26 +139,26 @@ func New(conf *genesisconfig.Profile) Generator {

bs.applicationGroups = []*cb.ConfigGroup{
// Initialize the default Reader/Writer/Admins application policies
policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.ReadersPolicyKey),
policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.WritersPolicyKey),
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.AdminsPolicyKey),
policies.TemplateImplicitMetaAnyPolicy([]string{config.ApplicationGroupKey}, configvaluesmsp.ReadersPolicyKey),
policies.TemplateImplicitMetaAnyPolicy([]string{config.ApplicationGroupKey}, configvaluesmsp.WritersPolicyKey),
policies.TemplateImplicitMetaMajorityPolicy([]string{config.ApplicationGroupKey}, configvaluesmsp.AdminsPolicyKey),
}
for _, org := range conf.Application.Organizations {
mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.BCCSP, org.ID)
if err != nil {
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
}
bs.applicationGroups = append(bs.applicationGroups, configvaluesmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey, org.Name}, mspConfig))

bs.applicationGroups = append(bs.applicationGroups, configvaluesmsp.TemplateGroupMSP([]string{config.ApplicationGroupKey, org.Name}, mspConfig))
var anchorProtos []*pb.AnchorPeer
for _, anchorPeer := range org.AnchorPeers {
anchorProtos = append(anchorProtos, &pb.AnchorPeer{
Host: anchorPeer.Host,
Port: int32(anchorPeer.Port),
})
}

bs.applicationGroups = append(bs.applicationGroups, configtxapplication.TemplateAnchorPeers(org.Name, anchorProtos))
bs.applicationGroups = append(bs.applicationGroups, config.TemplateAnchorPeers(org.Name, anchorProtos))
}
}

}
Expand Down
126 changes: 0 additions & 126 deletions common/configvalues/channel/application/sharedconfig.go

This file was deleted.

97 changes: 97 additions & 0 deletions common/configvalues/root/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
Copyright IBM Corp. 2017 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

import (
"fmt"

api "github.com/hyperledger/fabric/common/configvalues"
"github.com/hyperledger/fabric/common/configvalues/msp"
)

const (
// ApplicationGroupKey is the group name for the Application config
ApplicationGroupKey = "Application"
)

// ApplicationGroup represents the application config group
type ApplicationGroup struct {
*Proposer
*ApplicationConfig
mspConfig *msp.MSPConfigHandler
}

type ApplicationConfig struct {
*standardValues

applicationGroup *ApplicationGroup
applicationOrgs map[string]api.ApplicationOrg
}

// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
func NewApplicationGroup(mspConfig *msp.MSPConfigHandler) *ApplicationGroup {
ag := &ApplicationGroup{
mspConfig: mspConfig,
}
ag.Proposer = NewProposer(ag)

return ag
}

func (ag *ApplicationGroup) NewGroup(name string) (api.ValueProposer, error) {
return NewApplicationOrgConfig(name, ag.mspConfig), nil
}

// Allocate returns the
func (ag *ApplicationGroup) Allocate() Values {
return NewApplicationConfig(ag)
}

func NewApplicationConfig(ag *ApplicationGroup) *ApplicationConfig {
sv, err := NewStandardValues(&(struct{}{}))
if err != nil {
logger.Panicf("Programming error: %s", err)
}

return &ApplicationConfig{
applicationGroup: ag,

// Currently there are no config values
standardValues: sv,
}
}

func (ac *ApplicationConfig) Validate(groups map[string]api.ValueProposer) error {
ac.applicationOrgs = make(map[string]api.ApplicationOrg)
var ok bool
for key, value := range groups {
ac.applicationOrgs[key], ok = value.(*ApplicationOrgConfig)
if !ok {
return fmt.Errorf("Application sub-group %s was not an ApplicationOrgGroup, actually %T", key, value)
}
}
return nil
}

func (ac *ApplicationConfig) Commit() {
ac.applicationGroup.ApplicationConfig = ac
}

// Organizations returns a map of org ID to ApplicationOrg
func (ac *ApplicationConfig) Organizations() map[string]api.ApplicationOrg {
return ac.applicationOrgs
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package application
package config

import (
"testing"
Expand All @@ -29,37 +29,5 @@ func init() {
}

func TestApplicationInterface(t *testing.T) {
_ = api.Application(NewSharedConfigImpl(nil))
}

func TestApplicationDoubleBegin(t *testing.T) {
defer func() {
if err := recover(); err == nil {
t.Fatalf("Should have panicked on multiple begin configs")
}
}()

m := NewSharedConfigImpl(nil)
m.BeginValueProposals(nil)
m.BeginValueProposals(nil)
}

func TestApplicationCommitWithoutBegin(t *testing.T) {
defer func() {
if err := recover(); err == nil {
t.Fatalf("Should have panicked on multiple begin configs")
}
}()

m := NewSharedConfigImpl(nil)
m.CommitProposals()
}

func TestApplicationRollback(t *testing.T) {
m := NewSharedConfigImpl(nil)
m.pendingConfig = &sharedConfig{}
m.RollbackProposals()
if m.pendingConfig != nil {
t.Fatalf("Should have cleared pending config on rollback")
}
_ = api.Application((*ApplicationGroup)(nil))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package application
package config

import (
cb "github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
)

func configGroup(orgID string, key string, value []byte) *cb.ConfigGroup {
func applicationConfigGroup(orgID string, key string, value []byte) *cb.ConfigGroup {
result := cb.NewConfigGroup()
result.Groups[GroupKey] = cb.NewConfigGroup()
result.Groups[GroupKey].Groups[orgID] = cb.NewConfigGroup()
result.Groups[GroupKey].Groups[orgID].Values[key] = &cb.ConfigValue{
result.Groups[ApplicationGroupKey] = cb.NewConfigGroup()
result.Groups[ApplicationGroupKey].Groups[orgID] = cb.NewConfigGroup()
result.Groups[ApplicationGroupKey].Groups[orgID].Values[key] = &cb.ConfigValue{
Value: value,
}
return result
}

// TemplateAnchorPeers creates a headerless config item representing the anchor peers
func TemplateAnchorPeers(orgID string, anchorPeers []*pb.AnchorPeer) *cb.ConfigGroup {
return configGroup(orgID, AnchorPeersKey, utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}))
return applicationConfigGroup(orgID, AnchorPeersKey, utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package application
package config

import (
"fmt"

"github.com/hyperledger/fabric/common/configvalues"
api "github.com/hyperledger/fabric/common/configvalues"
"github.com/hyperledger/fabric/common/configvalues/channel/common/organization"
mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (oc *ApplicationOrgConfig) AnchorPeers() []*pb.AnchorPeer {
}

// BeginValueProposals is used to start a new config proposal
func (oc *ApplicationOrgConfig) BeginValueProposals(groups []string) ([]config.ValueProposer, error) {
func (oc *ApplicationOrgConfig) BeginValueProposals(groups []string) ([]api.ValueProposer, error) {
logger.Debugf("Beginning a possible new org config")
if len(groups) != 0 {
return nil, fmt.Errorf("ApplicationGroup does not support subgroups")
Expand Down
Loading

0 comments on commit b609bf0

Please sign in to comment.