Skip to content

Commit

Permalink
[FAB-2162] Move orderer genesis to common
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2162

This CR moves genesis configuration for the orderer to the common
configtx package.

Change-Id: I875692e75cb5429ddc747239acf6dab070f586d4
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 13, 2017
1 parent 4dd8559 commit a061e6d
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 155 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ build/image/peer/payload: build/docker/bin/peer \
build/image/orderer/payload: build/docker/bin/orderer \
build/msp-sampleconfig.tar.bz2 \
orderer/orderer.yaml \
orderer/genesis.yaml
common/configtx/tool/genesis.yaml
build/image/testenv/payload: build/gotools.tar.bz2 \
build/docker/bin/orderer \
orderer/orderer.yaml \
orderer/genesis.yaml \
common/configtx/tool/genesis.yaml \
build/docker/bin/peer \
peer/core.yaml \
build/msp-sampleconfig.tar.bz2 \
Expand Down
File renamed without changes.
159 changes: 159 additions & 0 deletions common/configtx/tool/localconfig/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
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 localconfig

import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/hyperledger/fabric/common/viperutil"

"github.com/op/go-logging"
"github.com/spf13/viper"
)

var logger = logging.MustGetLogger("configtx/tool/localconfig")

func init() {
logging.SetLevel(logging.ERROR, "")
}

// Prefix is the default config prefix for the orderer
const Prefix string = "CONFIGTX"

// TopLevel contains the genesis structures for use by the provisional bootstrapper
type TopLevel struct {
Orderer Orderer
}

// Orderer contains config which is used for orderer genesis by the provisional bootstrapper
type Orderer struct {
OrdererType string
Addresses []string
BatchTimeout time.Duration
BatchSize BatchSize
Kafka Kafka
}

// BatchSize contains configuration affecting the size of batches
type BatchSize struct {
MaxMessageCount uint32
AbsoluteMaxBytes uint32
PreferredMaxBytes uint32
}

// Kafka contains config for the Kafka orderer
type Kafka struct {
Brokers []string
}

var genesisDefaults = TopLevel{
Orderer: Orderer{
OrdererType: "solo",
Addresses: []string{"127.0.0.1:7050"},
BatchTimeout: 10 * time.Second,
BatchSize: BatchSize{
MaxMessageCount: 10,
AbsoluteMaxBytes: 100000000,
PreferredMaxBytes: 512 * 1024,
},
Kafka: Kafka{
Brokers: []string{"127.0.0.1:9092"},
},
},
}

func (g *TopLevel) completeInitialization() {
for {
switch {
case g.Orderer.OrdererType == "":
logger.Infof("Orderer.OrdererType unset, setting to %s", genesisDefaults.Orderer.OrdererType)
g.Orderer.OrdererType = genesisDefaults.Orderer.OrdererType
case g.Orderer.Addresses == nil:
logger.Infof("Orderer.Addresses unset, setting to %s", genesisDefaults.Orderer.Addresses)
g.Orderer.Addresses = genesisDefaults.Orderer.Addresses
case g.Orderer.BatchTimeout == 0:
logger.Infof("Orderer.BatchTimeout unset, setting to %s", genesisDefaults.Orderer.BatchTimeout)
g.Orderer.BatchTimeout = genesisDefaults.Orderer.BatchTimeout
case g.Orderer.BatchTimeout == 0:
logger.Infof("Orderer.BatchTimeout unset, setting to %s", genesisDefaults.Orderer.BatchTimeout)
g.Orderer.BatchTimeout = genesisDefaults.Orderer.BatchTimeout
case g.Orderer.BatchSize.MaxMessageCount == 0:
logger.Infof("Orderer.BatchSize.MaxMessageCount unset, setting to %s", genesisDefaults.Orderer.BatchSize.MaxMessageCount)
g.Orderer.BatchSize.MaxMessageCount = genesisDefaults.Orderer.BatchSize.MaxMessageCount
case g.Orderer.BatchSize.AbsoluteMaxBytes == 0:
logger.Infof("Orderer.BatchSize.AbsoluteMaxBytes unset, setting to %s", genesisDefaults.Orderer.BatchSize.AbsoluteMaxBytes)
g.Orderer.BatchSize.AbsoluteMaxBytes = genesisDefaults.Orderer.BatchSize.AbsoluteMaxBytes
case g.Orderer.BatchSize.PreferredMaxBytes == 0:
logger.Infof("Orderer.BatchSize.PreferredMaxBytes unset, setting to %s", genesisDefaults.Orderer.BatchSize.PreferredMaxBytes)
g.Orderer.BatchSize.PreferredMaxBytes = genesisDefaults.Orderer.BatchSize.PreferredMaxBytes
case g.Orderer.Kafka.Brokers == nil:
logger.Infof("Orderer.Kafka.Brokers unset, setting to %v", genesisDefaults.Orderer.Kafka.Brokers)
g.Orderer.Kafka.Brokers = genesisDefaults.Orderer.Kafka.Brokers
default:
return
}
}
}

func Load() *TopLevel {
config := viper.New()

config.SetConfigName("genesis")

var cfgPath string

// Path to look for the config file in based on ORDERER_CFG_PATH and GOPATH
searchPath := os.Getenv("ORDERER_CFG_PATH") + ":" + os.Getenv("GOPATH")
for _, p := range filepath.SplitList(searchPath) {
genesisPath := filepath.Join(p, "src/github.com/hyperledger/fabric/common/configtx/tool/")
if _, err := os.Stat(filepath.Join(genesisPath, "genesis.yaml")); err != nil {
// The yaml file does not exist in this component of the go src
continue
}
cfgPath = genesisPath
}
if cfgPath == "" {
logger.Fatalf("Could not find genesis.yaml, try setting GOPATH correctly")
}
config.AddConfigPath(cfgPath) // Path to look for the config file in

// for environment variables
config.SetEnvPrefix(Prefix)
config.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
config.SetEnvKeyReplacer(replacer)

err := config.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Error reading %s plugin config from %s: %s", Prefix, cfgPath, err))
}

var uconf TopLevel

err = viperutil.EnhancedExactUnmarshal(config, &uconf)
if err != nil {
panic(fmt.Errorf("Error unmarshaling into structure: %s", err))
}

uconf.completeInitialization()

return &uconf
}
4 changes: 2 additions & 2 deletions orderer/common/bootstrap/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"github.com/hyperledger/fabric/common/configtx"
configtxchannel "github.com/hyperledger/fabric/common/configtx/handlers/channel"
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/common/genesis"
"github.com/hyperledger/fabric/orderer/common/bootstrap"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
)
Expand Down Expand Up @@ -65,7 +65,7 @@ type bootstrapper struct {
}

// New returns a new provisional bootstrap helper.
func New(conf *config.GenesisTopLevel) Generator {
func New(conf *genesisconfig.TopLevel) Generator {
bs := &bootstrapper{
minimalGroups: []*cb.ConfigGroup{
// Chain Config Types
Expand Down
12 changes: 6 additions & 6 deletions orderer/common/bootstrap/provisional/provisional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import (
"bytes"
"testing"

"github.com/hyperledger/fabric/orderer/localconfig"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
)

var confSolo, confKafka *config.GenesisTopLevel
var testCases []*config.GenesisTopLevel
var confSolo, confKafka *genesisconfig.TopLevel
var testCases []*genesisconfig.TopLevel

func init() {
confSolo = config.LoadGenesis()
confKafka = config.LoadGenesis()
confSolo = genesisconfig.Load()
confKafka = genesisconfig.Load()
confKafka.Orderer.OrdererType = ConsensusTypeKafka
testCases = []*config.GenesisTopLevel{confSolo, confKafka}
testCases = []*genesisconfig.TopLevel{confSolo, confKafka}
}

func TestGenesisBlockHeader(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions orderer/common/deliver/deliver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"time"

configtxapi "github.com/hyperledger/fabric/common/configtx/api"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
mockconfigtxorderer "github.com/hyperledger/fabric/common/mocks/configtx/handlers/orderer"
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
ordererledger "github.com/hyperledger/fabric/orderer/ledger"
ramledger "github.com/hyperledger/fabric/orderer/ledger/ram"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
"github.com/hyperledger/fabric/protos/utils"
Expand All @@ -44,7 +44,7 @@ const ledgerSize = 10

func init() {
logging.SetLevel(logging.DEBUG, "")
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock()
}

type mockD struct {
Expand Down
10 changes: 9 additions & 1 deletion orderer/kafka/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/Shopify/sarama"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
)
Expand All @@ -37,9 +38,16 @@ var (
testTimePadding = 200 * time.Millisecond
)

var testGenesisConf = &genesisconfig.TopLevel{
Orderer: genesisconfig.Orderer{
Kafka: genesisconfig.Kafka{
Brokers: []string{"127.0.0.1:9092"},
},
},
}

var testConf = &config.TopLevel{
Kafka: config.Kafka{
Brokers: []string{"127.0.0.1:9092"},
Retry: config.Retry{
Period: 3 * time.Second,
Stop: 60 * time.Second,
Expand Down
2 changes: 1 addition & 1 deletion orderer/kafka/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
var cp = newChainPartition(provisional.TestChainID, rawPartition)

func newMockSharedConfigManager() *mockconfigtxorderer.SharedConfig {
return &mockconfigtxorderer.SharedConfig{KafkaBrokersVal: testConf.Kafka.Brokers}
return &mockconfigtxorderer.SharedConfig{KafkaBrokersVal: testGenesisConf.Orderer.Kafka.Brokers}
}

type mockConsenterImpl struct {
Expand Down
4 changes: 2 additions & 2 deletions orderer/ledger/file/fileledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"os"
"testing"

genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
ordererledger "github.com/hyperledger/fabric/orderer/ledger"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

Expand All @@ -35,7 +35,7 @@ var genesisBlock *cb.Block

func init() {
logging.SetLevel(logging.DEBUG, "")
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock()
}

type testEnv struct {
Expand Down
4 changes: 2 additions & 2 deletions orderer/ledger/fileledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ import (
"io/ioutil"
"os"

genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
. "github.com/hyperledger/fabric/orderer/ledger"
fileledger "github.com/hyperledger/fabric/orderer/ledger/file"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
)

var genesisBlock *cb.Block

func init() {
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock()
testables = append(testables, &fileLedgerTestEnv{})
}

Expand Down
4 changes: 2 additions & 2 deletions orderer/ledger/ram/ramledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package ramledger
import (
"testing"

genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"

logging "github.com/op/go-logging"
Expand All @@ -30,7 +30,7 @@ var genesisBlock *cb.Block

func init() {
logging.SetLevel(logging.DEBUG, "")
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock()
}

func NewTestChain(maxSize int) *ramLedger {
Expand Down
Loading

0 comments on commit a061e6d

Please sign in to comment.