Skip to content

Commit b609bf0

Browse files
author
Jason Yellick
committed
[FAB-2477] Move application config to Proposer
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 <[email protected]>
1 parent c8ff4b1 commit b609bf0

File tree

11 files changed

+127
-193
lines changed

11 files changed

+127
-193
lines changed

common/configtx/test/helper.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/hyperledger/fabric/common/configtx"
2424
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
2525
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
26-
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
2726
configtxmsp "github.com/hyperledger/fabric/common/configvalues/msp"
2827
config "github.com/hyperledger/fabric/common/configvalues/root"
2928
"github.com/hyperledger/fabric/common/genesis"
@@ -95,7 +94,7 @@ func ApplicationOrgTemplate() configtx.Template {
9594
if err != nil {
9695
logger.Panicf("Could not load sample MSP config: %s", err)
9796
}
98-
return configtx.NewSimpleTemplate(configtxmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey, sampleOrgID}, mspConf))
97+
return configtx.NewSimpleTemplate(configtxmsp.TemplateGroupMSP([]string{config.ApplicationGroupKey, sampleOrgID}, mspConf))
9998
}
10099

101100
// OrdererOrgTemplate returns the SAMPLE org with MSP template

common/configtx/tool/provisional/provisional.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/hyperledger/fabric/common/cauthdsl"
2323
"github.com/hyperledger/fabric/common/configtx"
2424
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
25-
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
2625
configvaluesmsp "github.com/hyperledger/fabric/common/configvalues/msp"
2726
config "github.com/hyperledger/fabric/common/configvalues/root"
2827
"github.com/hyperledger/fabric/common/genesis"
@@ -140,26 +139,26 @@ func New(conf *genesisconfig.Profile) Generator {
140139

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

152+
bs.applicationGroups = append(bs.applicationGroups, configvaluesmsp.TemplateGroupMSP([]string{config.ApplicationGroupKey, org.Name}, mspConfig))
154153
var anchorProtos []*pb.AnchorPeer
155154
for _, anchorPeer := range org.AnchorPeers {
156155
anchorProtos = append(anchorProtos, &pb.AnchorPeer{
157156
Host: anchorPeer.Host,
158157
Port: int32(anchorPeer.Port),
159158
})
160-
}
161159

162-
bs.applicationGroups = append(bs.applicationGroups, configtxapplication.TemplateAnchorPeers(org.Name, anchorProtos))
160+
bs.applicationGroups = append(bs.applicationGroups, config.TemplateAnchorPeers(org.Name, anchorProtos))
161+
}
163162
}
164163

165164
}

common/configvalues/channel/application/sharedconfig.go

-126
This file was deleted.
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package config
18+
19+
import (
20+
"fmt"
21+
22+
api "github.com/hyperledger/fabric/common/configvalues"
23+
"github.com/hyperledger/fabric/common/configvalues/msp"
24+
)
25+
26+
const (
27+
// ApplicationGroupKey is the group name for the Application config
28+
ApplicationGroupKey = "Application"
29+
)
30+
31+
// ApplicationGroup represents the application config group
32+
type ApplicationGroup struct {
33+
*Proposer
34+
*ApplicationConfig
35+
mspConfig *msp.MSPConfigHandler
36+
}
37+
38+
type ApplicationConfig struct {
39+
*standardValues
40+
41+
applicationGroup *ApplicationGroup
42+
applicationOrgs map[string]api.ApplicationOrg
43+
}
44+
45+
// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
46+
func NewApplicationGroup(mspConfig *msp.MSPConfigHandler) *ApplicationGroup {
47+
ag := &ApplicationGroup{
48+
mspConfig: mspConfig,
49+
}
50+
ag.Proposer = NewProposer(ag)
51+
52+
return ag
53+
}
54+
55+
func (ag *ApplicationGroup) NewGroup(name string) (api.ValueProposer, error) {
56+
return NewApplicationOrgConfig(name, ag.mspConfig), nil
57+
}
58+
59+
// Allocate returns the
60+
func (ag *ApplicationGroup) Allocate() Values {
61+
return NewApplicationConfig(ag)
62+
}
63+
64+
func NewApplicationConfig(ag *ApplicationGroup) *ApplicationConfig {
65+
sv, err := NewStandardValues(&(struct{}{}))
66+
if err != nil {
67+
logger.Panicf("Programming error: %s", err)
68+
}
69+
70+
return &ApplicationConfig{
71+
applicationGroup: ag,
72+
73+
// Currently there are no config values
74+
standardValues: sv,
75+
}
76+
}
77+
78+
func (ac *ApplicationConfig) Validate(groups map[string]api.ValueProposer) error {
79+
ac.applicationOrgs = make(map[string]api.ApplicationOrg)
80+
var ok bool
81+
for key, value := range groups {
82+
ac.applicationOrgs[key], ok = value.(*ApplicationOrgConfig)
83+
if !ok {
84+
return fmt.Errorf("Application sub-group %s was not an ApplicationOrgGroup, actually %T", key, value)
85+
}
86+
}
87+
return nil
88+
}
89+
90+
func (ac *ApplicationConfig) Commit() {
91+
ac.applicationGroup.ApplicationConfig = ac
92+
}
93+
94+
// Organizations returns a map of org ID to ApplicationOrg
95+
func (ac *ApplicationConfig) Organizations() map[string]api.ApplicationOrg {
96+
return ac.applicationOrgs
97+
}

common/configvalues/channel/application/sharedconfig_test.go common/configvalues/root/application_test.go

+2-34
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package application
17+
package config
1818

1919
import (
2020
"testing"
@@ -29,37 +29,5 @@ func init() {
2929
}
3030

3131
func TestApplicationInterface(t *testing.T) {
32-
_ = api.Application(NewSharedConfigImpl(nil))
33-
}
34-
35-
func TestApplicationDoubleBegin(t *testing.T) {
36-
defer func() {
37-
if err := recover(); err == nil {
38-
t.Fatalf("Should have panicked on multiple begin configs")
39-
}
40-
}()
41-
42-
m := NewSharedConfigImpl(nil)
43-
m.BeginValueProposals(nil)
44-
m.BeginValueProposals(nil)
45-
}
46-
47-
func TestApplicationCommitWithoutBegin(t *testing.T) {
48-
defer func() {
49-
if err := recover(); err == nil {
50-
t.Fatalf("Should have panicked on multiple begin configs")
51-
}
52-
}()
53-
54-
m := NewSharedConfigImpl(nil)
55-
m.CommitProposals()
56-
}
57-
58-
func TestApplicationRollback(t *testing.T) {
59-
m := NewSharedConfigImpl(nil)
60-
m.pendingConfig = &sharedConfig{}
61-
m.RollbackProposals()
62-
if m.pendingConfig != nil {
63-
t.Fatalf("Should have cleared pending config on rollback")
64-
}
32+
_ = api.Application((*ApplicationGroup)(nil))
6533
}

common/configvalues/channel/application/sharedconfig_util.go common/configvalues/root/application_util.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package application
17+
package config
1818

1919
import (
2020
cb "github.com/hyperledger/fabric/protos/common"
2121
pb "github.com/hyperledger/fabric/protos/peer"
2222
"github.com/hyperledger/fabric/protos/utils"
2323
)
2424

25-
func configGroup(orgID string, key string, value []byte) *cb.ConfigGroup {
25+
func applicationConfigGroup(orgID string, key string, value []byte) *cb.ConfigGroup {
2626
result := cb.NewConfigGroup()
27-
result.Groups[GroupKey] = cb.NewConfigGroup()
28-
result.Groups[GroupKey].Groups[orgID] = cb.NewConfigGroup()
29-
result.Groups[GroupKey].Groups[orgID].Values[key] = &cb.ConfigValue{
27+
result.Groups[ApplicationGroupKey] = cb.NewConfigGroup()
28+
result.Groups[ApplicationGroupKey].Groups[orgID] = cb.NewConfigGroup()
29+
result.Groups[ApplicationGroupKey].Groups[orgID].Values[key] = &cb.ConfigValue{
3030
Value: value,
3131
}
3232
return result
3333
}
3434

3535
// TemplateAnchorPeers creates a headerless config item representing the anchor peers
3636
func TemplateAnchorPeers(orgID string, anchorPeers []*pb.AnchorPeer) *cb.ConfigGroup {
37-
return configGroup(orgID, AnchorPeersKey, utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}))
37+
return applicationConfigGroup(orgID, AnchorPeersKey, utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}))
3838
}

common/configvalues/channel/application/organization.go common/configvalues/root/applicationorg.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package application
17+
package config
1818

1919
import (
2020
"fmt"
2121

22-
"github.com/hyperledger/fabric/common/configvalues"
22+
api "github.com/hyperledger/fabric/common/configvalues"
2323
"github.com/hyperledger/fabric/common/configvalues/channel/common/organization"
2424
mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
2525
cb "github.com/hyperledger/fabric/protos/common"
@@ -63,7 +63,7 @@ func (oc *ApplicationOrgConfig) AnchorPeers() []*pb.AnchorPeer {
6363
}
6464

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

0 commit comments

Comments
 (0)