-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-2428] Move config root to configvalues
https://jira.hyperledger.org/browse/FAB-2428 Presently, there is a bit of a hacky mechanism of creating a config root inside of the configtx.Initializer. This code more appropriately belongs with the configvalues package and is needed there as part of a larger refactor. Change-Id: I1df53ad3af0bff5a1ac3cce9f5ab5d22a0c7a308 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Feb 27, 2017
1 parent
9a09ac0
commit 9379e85
Showing
4 changed files
with
160 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
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" | ||
|
||
configvaluesapi "github.com/hyperledger/fabric/common/configvalues" | ||
"github.com/hyperledger/fabric/common/configvalues/channel" | ||
"github.com/hyperledger/fabric/common/configvalues/channel/application" | ||
"github.com/hyperledger/fabric/common/configvalues/channel/orderer" | ||
"github.com/hyperledger/fabric/common/configvalues/msp" | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
) | ||
|
||
// Root acts as the object which anchors the rest of the config | ||
// Note, yes, this is a stuttering name, but, the intent is to move | ||
// this up one level at the end of refactoring | ||
type Root struct { | ||
channel *channel.Config | ||
orderer *orderer.ManagerImpl | ||
application *application.SharedConfigImpl | ||
mspConfigHandler *msp.MSPConfigHandler | ||
} | ||
|
||
// NewRoot creates a new instance of the configvalues Root | ||
func NewRoot(mspConfigHandler *msp.MSPConfigHandler) *Root { | ||
ordererConfig := orderer.NewManagerImpl(mspConfigHandler) | ||
applicationConfig := application.NewSharedConfigImpl(mspConfigHandler) | ||
|
||
return &Root{ | ||
channel: channel.NewConfig(ordererConfig, applicationConfig), | ||
orderer: ordererConfig, | ||
application: applicationConfig, | ||
mspConfigHandler: mspConfigHandler, | ||
} | ||
} | ||
|
||
// BeginValueProposals is used to start a new config proposal | ||
func (r *Root) BeginValueProposals(groups []string) ([]configvaluesapi.ValueProposer, error) { | ||
if len(groups) != 1 { | ||
return nil, fmt.Errorf("Root config only supports having one base group") | ||
} | ||
if groups[0] != channel.GroupKey { | ||
return nil, fmt.Errorf("Root group must have channel") | ||
} | ||
r.mspConfigHandler.BeginConfig() | ||
return []configvaluesapi.ValueProposer{r.channel}, nil | ||
} | ||
|
||
// RollbackConfig is used to abandon a new config proposal | ||
func (r *Root) RollbackProposals() { | ||
r.mspConfigHandler.RollbackProposals() | ||
} | ||
|
||
// PreCommit is used to verify total configuration before commit | ||
func (r *Root) PreCommit() error { | ||
return r.mspConfigHandler.PreCommit() | ||
} | ||
|
||
// CommitConfig is used to commit a new config proposal | ||
func (r *Root) CommitProposals() { | ||
r.mspConfigHandler.CommitProposals() | ||
} | ||
|
||
// ProposeValue should not be invoked on this object | ||
func (r *Root) ProposeValue(key string, value *cb.ConfigValue) error { | ||
return fmt.Errorf("Programming error, this should never be invoked") | ||
} | ||
|
||
// Channel returns the associated Channel level config | ||
func (r *Root) Channel() *channel.Config { | ||
return r.channel | ||
} | ||
|
||
// Orderer returns the associated Orderer level config | ||
func (r *Root) Orderer() *orderer.ManagerImpl { | ||
return r.orderer | ||
} | ||
|
||
// Application returns the associated Application level config | ||
func (r *Root) Application() *application.SharedConfigImpl { | ||
return r.application | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright IBM Corp. 2016 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 ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric/common/configvalues/channel" | ||
"github.com/hyperledger/fabric/common/configvalues/msp" | ||
|
||
logging "github.com/op/go-logging" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func init() { | ||
logging.SetLevel(logging.DEBUG, "") | ||
} | ||
|
||
func TestBeginBadRoot(t *testing.T) { | ||
r := NewRoot(&msp.MSPConfigHandler{}) | ||
|
||
_, err := r.BeginValueProposals([]string{channel.GroupKey, channel.GroupKey}) | ||
assert.Error(t, err, "Only one root element allowed") | ||
|
||
_, err = r.BeginValueProposals([]string{"foo"}) | ||
assert.Error(t, err, "Non %s group not allowed", channel.GroupKey) | ||
} | ||
|
||
func TestProposeValue(t *testing.T) { | ||
r := NewRoot(&msp.MSPConfigHandler{}) | ||
|
||
err := r.ProposeValue("foo", nil) | ||
assert.Error(t, err, "ProposeValue should return error") | ||
} |