@@ -17,14 +17,10 @@ limitations under the License.
1717package config
1818
1919import (
20- "fmt"
21-
2220 api "github.com/hyperledger/fabric/common/configvalues"
2321 mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
24- cb "github.com/hyperledger/fabric/protos/common"
2522 pb "github.com/hyperledger/fabric/protos/peer"
2623
27- "github.com/golang/protobuf/proto"
2824 logging "github.com/op/go-logging"
2925)
3026
@@ -34,82 +30,66 @@ const (
3430 AnchorPeersKey = "AnchorPeers"
3531)
3632
37- type applicationOrgConfig struct {
38- anchorPeers [] * pb.AnchorPeer
33+ type ApplicationOrgProtos struct {
34+ AnchorPeers * pb.AnchorPeers
3935}
4036
41- // SharedConfigImpl is an implementation of Manager and configtx.ConfigHandler
42- // In general, it should only be referenced as an Impl for the configtx.Manager
4337type ApplicationOrgConfig struct {
44- * OrganizationGroup
45- pendingConfig * applicationOrgConfig
46- config * applicationOrgConfig
38+ * OrganizationConfig
39+ protos * ApplicationOrgProtos
40+
41+ applicationOrgGroup * ApplicationOrgGroup
42+ }
4743
48- mspConfig * mspconfig.MSPConfigHandler
44+ // ApplicationOrgGroup defines the configuration for an application org
45+ type ApplicationOrgGroup struct {
46+ * Proposer
47+ * OrganizationGroup
48+ * ApplicationOrgConfig
4949}
5050
51- // NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
52- func NewApplicationOrgConfig (id string , mspConfig * mspconfig.MSPConfigHandler ) * ApplicationOrgConfig {
53- return & ApplicationOrgConfig {
51+ // NewApplicationOrgGroup creates a new ApplicationOrgGroup
52+ func NewApplicationOrgGroup (id string , mspConfig * mspconfig.MSPConfigHandler ) * ApplicationOrgGroup {
53+ aog := & ApplicationOrgGroup {
5454 OrganizationGroup : NewOrganizationGroup (id , mspConfig ),
55- config : & applicationOrgConfig {},
5655 }
56+ aog .Proposer = NewProposer (aog )
57+ return aog
5758}
5859
5960// AnchorPeers returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
60- func (oc * ApplicationOrgConfig ) AnchorPeers () []* pb.AnchorPeer {
61- return oc . config . anchorPeers
61+ func (aog * ApplicationOrgConfig ) AnchorPeers () []* pb.AnchorPeer {
62+ return aog . protos . AnchorPeers . AnchorPeers
6263}
6364
64- // BeginValueProposals is used to start a new config proposal
65- func (oc * ApplicationOrgConfig ) BeginValueProposals (groups []string ) ([]api.ValueProposer , error ) {
66- logger .Debugf ("Beginning a possible new org config" )
67- if len (groups ) != 0 {
68- return nil , fmt .Errorf ("ApplicationGroup does not support subgroups" )
69- }
70- if oc .pendingConfig != nil {
71- logger .Panicf ("Programming error, cannot call begin in the middle of a proposal" )
72- }
73- oc .pendingConfig = & applicationOrgConfig {}
74- return oc .OrganizationGroup .BeginValueProposals (groups )
65+ func (aog * ApplicationOrgGroup ) Allocate () Values {
66+ return NewApplicationOrgConfig (aog )
7567}
7668
77- // RollbackProposals is used to abandon a new config proposal
78- func (oc * ApplicationOrgConfig ) RollbackProposals () {
79- logger .Debugf ("Rolling back proposed org config" )
80- oc .pendingConfig = nil
81- oc .OrganizationGroup .RollbackProposals ()
69+ func (aoc * ApplicationOrgConfig ) Commit () {
70+ aoc .applicationOrgGroup .ApplicationOrgConfig = aoc
71+ aoc .OrganizationConfig .Commit ()
8272}
8373
84- // CommitProposals is used to commit a new config proposal
85- func (oc * ApplicationOrgConfig ) CommitProposals () {
86- logger .Debugf ("Committing new org config" )
87- if oc .pendingConfig == nil {
88- logger .Panicf ("Programming error, cannot call commit without an existing proposal" )
89- }
90- oc .config = oc .pendingConfig
91- oc .pendingConfig = nil
92- oc .OrganizationGroup .CommitProposals ()
93- }
74+ func NewApplicationOrgConfig (aog * ApplicationOrgGroup ) * ApplicationOrgConfig {
75+ aoc := & ApplicationOrgConfig {
76+ protos : & ApplicationOrgProtos {},
77+ OrganizationConfig : NewOrganizationConfig (aog .OrganizationGroup ),
9478
95- // ProposeValue is used to add new config to the config proposal
96- func (oc * ApplicationOrgConfig ) ProposeValue (key string , configValue * cb.ConfigValue ) error {
97- switch key {
98- case AnchorPeersKey :
99- anchorPeers := & pb.AnchorPeers {}
100- if err := proto .Unmarshal (configValue .Value , anchorPeers ); err != nil {
101- return fmt .Errorf ("Unmarshaling error for %s: %s" , key , err )
102- }
103- if logger .IsEnabledFor (logging .DEBUG ) {
104- logger .Debugf ("Setting %s to %v" , key , anchorPeers .AnchorPeers )
105- }
106- oc .pendingConfig .anchorPeers = anchorPeers .AnchorPeers
107- default :
108- return oc .OrganizationGroup .ProposeValue (key , configValue )
79+ applicationOrgGroup : aog ,
80+ }
81+ var err error
82+ aoc .standardValues , err = NewStandardValues (aoc .protos , aoc .OrganizationConfig .protos )
83+ if err != nil {
84+ logger .Panicf ("Programming error: %s" , err )
10985 }
11086
111- return nil
87+ return aoc
11288}
11389
114- // PreCommit returns nil
115- func (c * ApplicationOrgConfig ) PreCommit () error { return nil }
90+ func (aoc * ApplicationOrgConfig ) Validate (groups map [string ]api.ValueProposer ) error {
91+ if logger .IsEnabledFor (logging .DEBUG ) {
92+ logger .Debugf ("Anchor peers for org %s are %v" , aoc .applicationOrgGroup .name , aoc .protos .AnchorPeers )
93+ }
94+ return aoc .OrganizationConfig .Validate (groups )
95+ }
0 commit comments