github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/common/configvalues/channel/application/sharedconfig.go (about) 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 application 18 19 import ( 20 api "github.com/hyperledger/fabric/common/configvalues" 21 "github.com/hyperledger/fabric/common/configvalues/channel/common/organization" 22 "github.com/hyperledger/fabric/common/configvalues/msp" 23 cb "github.com/hyperledger/fabric/protos/common" 24 25 "github.com/op/go-logging" 26 ) 27 28 const ( 29 // GroupKey is the group name for the Application config 30 GroupKey = "Application" 31 ) 32 33 var orgSchema = &cb.ConfigGroupSchema{ 34 Groups: map[string]*cb.ConfigGroupSchema{}, 35 Values: map[string]*cb.ConfigValueSchema{ 36 AnchorPeersKey: nil, 37 organization.MSPKey: nil, // TODO, consolidate into a constant once common org code exists 38 }, 39 Policies: map[string]*cb.ConfigPolicySchema{ 40 // TODO, set appropriately once hierarchical policies are implemented 41 }, 42 } 43 44 var Schema = &cb.ConfigGroupSchema{ 45 Groups: map[string]*cb.ConfigGroupSchema{ 46 "": orgSchema, 47 }, 48 Values: map[string]*cb.ConfigValueSchema{}, 49 Policies: map[string]*cb.ConfigPolicySchema{ 50 // TODO, set appropriately once hierarchical policies are implemented 51 }, 52 } 53 54 var logger = logging.MustGetLogger("common/configtx/handlers/application") 55 56 type sharedConfig struct { 57 orgs map[string]api.ApplicationOrg 58 } 59 60 // SharedConfigImpl is an implementation of Manager and configtx.ConfigHandler 61 // In general, it should only be referenced as an Impl for the configtx.Manager 62 type SharedConfigImpl struct { 63 pendingConfig *sharedConfig 64 config *sharedConfig 65 66 mspConfig *msp.MSPConfigHandler 67 } 68 69 // NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper 70 func NewSharedConfigImpl(mspConfig *msp.MSPConfigHandler) *SharedConfigImpl { 71 return &SharedConfigImpl{ 72 config: &sharedConfig{}, 73 mspConfig: mspConfig, 74 } 75 } 76 77 // BeginValueProposals is used to start a new config proposal 78 func (di *SharedConfigImpl) BeginValueProposals(groups []string) ([]api.ValueProposer, error) { 79 logger.Debugf("Beginning a possible new peer shared config") 80 if di.pendingConfig != nil { 81 logger.Panicf("Programming error, cannot call begin in the middle of a proposal") 82 } 83 di.pendingConfig = &sharedConfig{ 84 orgs: make(map[string]api.ApplicationOrg), 85 } 86 orgHandlers := make([]api.ValueProposer, len(groups)) 87 for i, group := range groups { 88 org, ok := di.pendingConfig.orgs[group] 89 if !ok { 90 org = NewApplicationOrgConfig(group, di.mspConfig) 91 di.pendingConfig.orgs[group] = org 92 } 93 orgHandlers[i] = org.(*ApplicationOrgConfig) 94 } 95 return orgHandlers, nil 96 } 97 98 // RollbackProposals is used to abandon a new config proposal 99 func (di *SharedConfigImpl) RollbackProposals() { 100 logger.Debugf("Rolling back proposed peer shared config") 101 di.pendingConfig = nil 102 } 103 104 // CommitProposals is used to commit a new config proposal 105 func (di *SharedConfigImpl) CommitProposals() { 106 logger.Debugf("Committing new peer shared config") 107 if di.pendingConfig == nil { 108 logger.Panicf("Programming error, cannot call commit without an existing proposal") 109 } 110 di.config = di.pendingConfig 111 di.pendingConfig = nil 112 } 113 114 // ProposeValue is used to add new config to the config proposal 115 func (di *SharedConfigImpl) ProposeValue(key string, configValue *cb.ConfigValue) error { 116 logger.Warningf("Uknown Peer config item with key %s", key) 117 return nil 118 } 119 120 // Organizations returns a map of org ID to ApplicationOrg 121 func (di *SharedConfigImpl) Organizations() map[string]api.ApplicationOrg { 122 return di.config.orgs 123 } 124 125 // PreCommit returns nil 126 func (di *SharedConfigImpl) PreCommit() error { return nil }