Skip to content

Commit

Permalink
[FAB-2937] Fix minor issues in localconfig
Browse files Browse the repository at this point in the history
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 <kostas@christidis.io>
  • Loading branch information
kchristidis committed Apr 21, 2017
1 parent 441b308 commit bb0df71
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion common/configtx/tool/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 40 additions & 33 deletions orderer/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -68,68 +81,63 @@ 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
KeyFile string
DataDir string
}

// SbftShared contains config for the SBFT network
// SbftShared contains config for the SBFT network.
type SbftShared struct {
N uint64
F uint64
RequestTimeoutNsec uint64
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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions protos/common/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down

0 comments on commit bb0df71

Please sign in to comment.