@@ -17,12 +17,12 @@ limitations under the License.
17
17
package config
18
18
19
19
import (
20
- "fmt"
21
20
"os"
22
21
"path/filepath"
23
22
"strings"
24
23
"time"
25
24
25
+ "github.com/hyperledger/fabric/common/flogging"
26
26
"github.com/hyperledger/fabric/common/viperutil"
27
27
28
28
"github.com/Shopify/sarama"
@@ -32,16 +32,29 @@ import (
32
32
bccsp "github.com/hyperledger/fabric/bccsp/factory"
33
33
)
34
34
35
- var logger = logging .MustGetLogger ("orderer/config" )
35
+ const (
36
+ pkgLogID = "orderer/config"
37
+
38
+ // Prefix identifies the prefix for the orderer-related ENV vars.
39
+ Prefix = "ORDERER"
40
+ )
41
+
42
+ var (
43
+ logger * logging.Logger
44
+
45
+ configName string
46
+ configFileName string
47
+ )
36
48
37
49
func init () {
38
- logging . SetLevel ( logging . ERROR , "" )
39
- }
50
+ logger = flogging . MustGetLogger ( pkgLogID )
51
+ flogging . SetModuleLevel ( pkgLogID , "error" )
40
52
41
- // Prefix is the default config prefix for the orderer
42
- const Prefix string = "ORDERER"
53
+ configName = strings .ToLower (Prefix )
54
+ configFileName = configName + ".yaml"
55
+ }
43
56
44
- // General contains config which should be common among all orderer types
57
+ // General contains config which should be common among all orderer types.
45
58
type General struct {
46
59
LedgerType string
47
60
ListenAddress string
@@ -57,7 +70,7 @@ type General struct {
57
70
BCCSP * bccsp.FactoryOpts
58
71
}
59
72
60
- //TLS contains config used to configure TLS
73
+ // TLS contains config for TLS connections.
61
74
type TLS struct {
62
75
Enabled bool
63
76
PrivateKey string
@@ -68,68 +81,63 @@ type TLS struct {
68
81
}
69
82
70
83
// Genesis is a deprecated structure which was used to put
71
- // values into the genesis block, but this is now handled elsewhere
84
+ // values into the genesis block, but this is now handled elsewhere.
72
85
// SBFT did not reference these values via the genesis block however
73
- // so it is being left here for backwards compatibility purposes
86
+ // so it is being left here for backwards compatibility purposes.
74
87
type Genesis struct {
75
88
DeprecatedBatchTimeout time.Duration
76
89
DeprecatedBatchSize uint32
77
90
SbftShared SbftShared
78
91
}
79
92
80
- // Profile contains configuration for Go pprof profiling
93
+ // Profile contains configuration for Go pprof profiling.
81
94
type Profile struct {
82
95
Enabled bool
83
96
Address string
84
97
}
85
98
86
- // RAMLedger contains config for the RAM ledger
99
+ // RAMLedger contains configuration for the RAM ledger.
87
100
type RAMLedger struct {
88
101
HistorySize uint
89
102
}
90
103
91
- // FileLedger contains config for the File ledger
104
+ // FileLedger contains configuration for the file-based ledger.
92
105
type FileLedger struct {
93
106
Location string
94
107
Prefix string
95
108
}
96
109
97
- // Kafka contains config for the Kafka orderer
110
+ // Kafka contains configuration for the Kafka-based orderer.
98
111
type Kafka struct {
99
112
Retry Retry
100
113
Verbose bool
101
- Version sarama.KafkaVersion
114
+ Version sarama.KafkaVersion // TODO Move this to global config
102
115
TLS TLS
103
116
}
104
117
105
- // SbftLocal contains config for the SBFT peer/replica
118
+ // SbftLocal contains configuration for the SBFT peer/replica.
106
119
type SbftLocal struct {
107
120
PeerCommAddr string
108
121
CertFile string
109
122
KeyFile string
110
123
DataDir string
111
124
}
112
125
113
- // SbftShared contains config for the SBFT network
126
+ // SbftShared contains config for the SBFT network.
114
127
type SbftShared struct {
115
128
N uint64
116
129
F uint64
117
130
RequestTimeoutNsec uint64
118
131
Peers map [string ]string // Address to Cert mapping
119
132
}
120
133
121
- // Retry contains config for the reconnection attempts to the Kafka brokers
134
+ // Retry contains config for the reconnection attempts to the Kafka brokers.
122
135
type Retry struct {
123
136
Period time.Duration
124
137
Stop time.Duration
125
138
}
126
139
127
- type RuntimeAndGenesis struct {
128
- runtime * TopLevel
129
- genesis * Genesis
130
- }
131
-
132
- // TopLevel directly corresponds to the orderer config yaml
140
+ // TopLevel directly corresponds to the orderer config YAML.
133
141
// Note, for non 1-1 mappings, you may append
134
142
// something like `mapstructure:"weirdFoRMat"` to
135
143
// modify the default mapping, see the "Unmarshal"
@@ -257,22 +265,23 @@ func (c *TopLevel) completeInitialization() {
257
265
func Load () * TopLevel {
258
266
config := viper .New ()
259
267
260
- config .SetConfigName ("orderer" )
268
+ config .SetConfigName (configName )
269
+
261
270
cfgPath := os .Getenv ("ORDERER_CFG_PATH" )
262
271
if cfgPath == "" {
263
- logger .Infof ("No orderer cfg path set, assuming development environment, deriving from go path" )
272
+ logger .Infof ("No ORDERER_CFG_PATH set, assuming development environment, deriving from Go path. " )
264
273
// Path to look for the config file in based on GOPATH
265
274
gopath := os .Getenv ("GOPATH" )
266
275
for _ , p := range filepath .SplitList (gopath ) {
267
276
ordererPath := filepath .Join (p , "src/github.com/hyperledger/fabric/orderer/" )
268
- if _ , err := os .Stat (filepath .Join (ordererPath , "orderer.yaml" )); err != nil {
269
- // The yaml file does not exist in this component of the go src
277
+ if _ , err := os .Stat (filepath .Join (ordererPath , configFileName )); err != nil {
278
+ // The YAML file does not exist in this component of the go src
270
279
continue
271
280
}
272
281
cfgPath = ordererPath
273
282
}
274
283
if cfgPath == "" {
275
- logger .Fatalf ("Could not find orderer.yaml , try setting ORDERER_CFG_PATH or GOPATH correctly" )
284
+ logger .Fatalf ("Could not find %s , try setting ORDERER_CFG_PATH or GOPATH correctly." , configFileName )
276
285
}
277
286
logger .Infof ("Setting ORDERER_CFG_PATH to: %s" , cfgPath )
278
287
os .Setenv ("ORDERER_CFG_PATH" , cfgPath )
@@ -287,16 +296,14 @@ func Load() *TopLevel {
287
296
288
297
err := config .ReadInConfig ()
289
298
if err != nil {
290
- panic ( fmt . Errorf ("Error reading %s plugin config : %s" , Prefix , err ) )
299
+ logger . Panicf ("Error reading configuration from %s in %s : %s" , configFileName , cfgPath , err )
291
300
}
292
301
293
302
var uconf TopLevel
294
-
295
303
err = viperutil .EnhancedExactUnmarshal (config , & uconf )
296
304
if err != nil {
297
- panic ( fmt . Errorf ("Error unmarshaling into structure : %s" , err ) )
305
+ logger . Panicf ("Error unmarshaling config into struct : %s" , err )
298
306
}
299
-
300
307
uconf .completeInitialization ()
301
308
302
309
return & uconf
0 commit comments