From bb0df712d67010996461bfbcfc99d469c3b1222f Mon Sep 17 00:00:00 2001 From: Kostas Christidis Date: Mon, 27 Mar 2017 21:51:48 -0400 Subject: [PATCH] [FAB-2937] Fix minor issues in localconfig 1. Remove unnecessary struct 2. Bring it inline with const/init declarations I did in `common/configtx/tool/localconfig` (By the way, the periods in the exported comments is not OCD but actually a guideline: https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences) Change-Id: If2d4394ffafaf1ae3e15fa228b4e40abc0dea47b Signed-off-by: Kostas Christidis --- common/configtx/tool/localconfig/config.go | 2 +- orderer/localconfig/config.go | 73 ++++++++++++---------- protos/common/common.proto | 4 +- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/common/configtx/tool/localconfig/config.go b/common/configtx/tool/localconfig/config.go index dedffddcd83..70412e4c3fe 100644 --- a/common/configtx/tool/localconfig/config.go +++ b/common/configtx/tool/localconfig/config.go @@ -171,7 +171,7 @@ func (p *Profile) completeInitialization() { func Load(profile string) *Profile { config := viper.New() - config.SetConfigName("configtx") + config.SetConfigName(configName) var cfgPath string // Candidate paths to look for the config file in, based on GOPATH diff --git a/orderer/localconfig/config.go b/orderer/localconfig/config.go index e700cb4f3b6..5b7d274b278 100644 --- a/orderer/localconfig/config.go +++ b/orderer/localconfig/config.go @@ -17,12 +17,12 @@ limitations under the License. package config import ( - "fmt" "os" "path/filepath" "strings" "time" + "github.com/hyperledger/fabric/common/flogging" "github.com/hyperledger/fabric/common/viperutil" "github.com/Shopify/sarama" @@ -32,16 +32,29 @@ import ( bccsp "github.com/hyperledger/fabric/bccsp/factory" ) -var logger = logging.MustGetLogger("orderer/config") +const ( + pkgLogID = "orderer/config" + + // Prefix identifies the prefix for the orderer-related ENV vars. + Prefix = "ORDERER" +) + +var ( + logger *logging.Logger + + configName string + configFileName string +) func init() { - logging.SetLevel(logging.ERROR, "") -} + logger = flogging.MustGetLogger(pkgLogID) + flogging.SetModuleLevel(pkgLogID, "error") -// Prefix is the default config prefix for the orderer -const Prefix string = "ORDERER" + configName = strings.ToLower(Prefix) + configFileName = configName + ".yaml" +} -// General contains config which should be common among all orderer types +// General contains config which should be common among all orderer types. type General struct { LedgerType string ListenAddress string @@ -57,7 +70,7 @@ type General struct { BCCSP *bccsp.FactoryOpts } -//TLS contains config used to configure TLS +// TLS contains config for TLS connections. type TLS struct { Enabled bool PrivateKey string @@ -68,41 +81,41 @@ type TLS struct { } // Genesis is a deprecated structure which was used to put -// values into the genesis block, but this is now handled elsewhere +// values into the genesis block, but this is now handled elsewhere. // SBFT did not reference these values via the genesis block however -// so it is being left here for backwards compatibility purposes +// so it is being left here for backwards compatibility purposes. type Genesis struct { DeprecatedBatchTimeout time.Duration DeprecatedBatchSize uint32 SbftShared SbftShared } -// Profile contains configuration for Go pprof profiling +// Profile contains configuration for Go pprof profiling. type Profile struct { Enabled bool Address string } -// RAMLedger contains config for the RAM ledger +// RAMLedger contains configuration for the RAM ledger. type RAMLedger struct { HistorySize uint } -// FileLedger contains config for the File ledger +// FileLedger contains configuration for the file-based ledger. type FileLedger struct { Location string Prefix string } -// Kafka contains config for the Kafka orderer +// Kafka contains configuration for the Kafka-based orderer. type Kafka struct { Retry Retry Verbose bool - Version sarama.KafkaVersion + Version sarama.KafkaVersion // TODO Move this to global config TLS TLS } -// SbftLocal contains config for the SBFT peer/replica +// SbftLocal contains configuration for the SBFT peer/replica. type SbftLocal struct { PeerCommAddr string CertFile string @@ -110,7 +123,7 @@ type SbftLocal struct { DataDir string } -// SbftShared contains config for the SBFT network +// SbftShared contains config for the SBFT network. type SbftShared struct { N uint64 F uint64 @@ -118,18 +131,13 @@ type SbftShared struct { Peers map[string]string // Address to Cert mapping } -// Retry contains config for the reconnection attempts to the Kafka brokers +// Retry contains config for the reconnection attempts to the Kafka brokers. type Retry struct { Period time.Duration Stop time.Duration } -type RuntimeAndGenesis struct { - runtime *TopLevel - genesis *Genesis -} - -// TopLevel directly corresponds to the orderer config yaml +// TopLevel directly corresponds to the orderer config YAML. // Note, for non 1-1 mappings, you may append // something like `mapstructure:"weirdFoRMat"` to // modify the default mapping, see the "Unmarshal" @@ -257,22 +265,23 @@ func (c *TopLevel) completeInitialization() { func Load() *TopLevel { config := viper.New() - config.SetConfigName("orderer") + config.SetConfigName(configName) + cfgPath := os.Getenv("ORDERER_CFG_PATH") if cfgPath == "" { - logger.Infof("No orderer cfg path set, assuming development environment, deriving from go path") + logger.Infof("No ORDERER_CFG_PATH set, assuming development environment, deriving from Go path.") // Path to look for the config file in based on GOPATH gopath := os.Getenv("GOPATH") for _, p := range filepath.SplitList(gopath) { ordererPath := filepath.Join(p, "src/github.com/hyperledger/fabric/orderer/") - if _, err := os.Stat(filepath.Join(ordererPath, "orderer.yaml")); err != nil { - // The yaml file does not exist in this component of the go src + if _, err := os.Stat(filepath.Join(ordererPath, configFileName)); err != nil { + // The YAML file does not exist in this component of the go src continue } cfgPath = ordererPath } if cfgPath == "" { - logger.Fatalf("Could not find orderer.yaml, try setting ORDERER_CFG_PATH or GOPATH correctly") + logger.Fatalf("Could not find %s, try setting ORDERER_CFG_PATH or GOPATH correctly.", configFileName) } logger.Infof("Setting ORDERER_CFG_PATH to: %s", cfgPath) os.Setenv("ORDERER_CFG_PATH", cfgPath) @@ -287,16 +296,14 @@ func Load() *TopLevel { err := config.ReadInConfig() if err != nil { - panic(fmt.Errorf("Error reading %s plugin config: %s", Prefix, err)) + logger.Panicf("Error reading configuration from %s in %s: %s", configFileName, cfgPath, err) } var uconf TopLevel - err = viperutil.EnhancedExactUnmarshal(config, &uconf) if err != nil { - panic(fmt.Errorf("Error unmarshaling into structure: %s", err)) + logger.Panicf("Error unmarshaling config into struct: %s", err) } - uconf.completeInitialization() return &uconf diff --git a/protos/common/common.proto b/protos/common/common.proto index d4a56bd5b47..3a98ba71c44 100644 --- a/protos/common/common.proto +++ b/protos/common/common.proto @@ -48,8 +48,8 @@ enum HeaderType { // This enum enlists indexes of the block metadata array enum BlockMetadataIndex { SIGNATURES = 0; // Block metadata array position for block signatures - LAST_CONFIG = 1; // Block metadata array poistion to store last configuration block sequence number - TRANSACTIONS_FILTER = 2; // Block metadata array poistion to store serialized bit array filter of invalid transactions + LAST_CONFIG = 1; // Block metadata array position to store last configuration block sequence number + TRANSACTIONS_FILTER = 2; // Block metadata array position to store serialized bit array filter of invalid transactions ORDERER = 3; // Block metadata array position to store operational metadata for orderers // e.g. For Kafka, this is where we store the last offset written to the local ledger. }