Skip to content

Commit ed8864d

Browse files
committed
[FAB-4411] Enable orderer to report version info
The orderer shim currently does not report any version information. The following functionality has been implemented: - Add CLI for orderer which supports "start" and "version" commands. Note that the "start" cmd is the default so need not be specified. This ensures that starting the orderer with ./orderer still works - Version info is also printed at start up - Given the above, removed a duplicate log message from server.go as well Change-Id: Ia4c3a82b9844391823107d10b51dd7136689d4c8 Signed-off-by: Gari Singh <[email protected]>
1 parent 88d4845 commit ed8864d

File tree

4 files changed

+94
-13
lines changed

4 files changed

+94
-13
lines changed

orderer/main.go

+33-11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/hyperledger/fabric/orderer/kafka"
3535
"github.com/hyperledger/fabric/orderer/ledger"
3636
"github.com/hyperledger/fabric/orderer/localconfig"
37+
"github.com/hyperledger/fabric/orderer/metadata"
3738
"github.com/hyperledger/fabric/orderer/multichain"
3839
"github.com/hyperledger/fabric/orderer/solo"
3940
cb "github.com/hyperledger/fabric/protos/common"
@@ -44,22 +45,43 @@ import (
4445
"github.com/hyperledger/fabric/common/localmsp"
4546
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
4647
logging "github.com/op/go-logging"
48+
"gopkg.in/alecthomas/kingpin.v2"
4749
)
4850

4951
var logger = logging.MustGetLogger("orderer/main")
5052

53+
//command line flags
54+
var (
55+
app = kingpin.New("orderer", "Hyperledger Fabric orderer node")
56+
57+
start = app.Command("start", "Start the orderer node").Default()
58+
version = app.Command("version", "Show version information")
59+
)
60+
5161
func main() {
52-
conf := config.Load()
53-
initializeLoggingLevel(conf)
54-
initializeProfilingService(conf)
55-
grpcServer := initializeGrpcServer(conf)
56-
initializeLocalMsp(conf)
57-
signer := localmsp.NewSigner()
58-
manager := initializeMultiChainManager(conf, signer)
59-
server := NewServer(manager, signer)
60-
ab.RegisterAtomicBroadcastServer(grpcServer.Server(), server)
61-
logger.Info("Beginning to serve requests")
62-
grpcServer.Start()
62+
63+
kingpin.Version("0.0.1")
64+
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
65+
66+
// "start" command
67+
case start.FullCommand():
68+
logger.Infof("Starting %s", metadata.GetVersionInfo())
69+
conf := config.Load()
70+
initializeLoggingLevel(conf)
71+
initializeProfilingService(conf)
72+
grpcServer := initializeGrpcServer(conf)
73+
initializeLocalMsp(conf)
74+
signer := localmsp.NewSigner()
75+
manager := initializeMultiChainManager(conf, signer)
76+
server := NewServer(manager, signer)
77+
ab.RegisterAtomicBroadcastServer(grpcServer.Server(), server)
78+
logger.Info("Beginning to serve requests")
79+
grpcServer.Start()
80+
// "version" command
81+
case version.FullCommand():
82+
fmt.Println(metadata.GetVersionInfo())
83+
}
84+
6385
}
6486

6587
// Set the logging level

orderer/metadata/metadata.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package metadata
8+
9+
import (
10+
"fmt"
11+
"runtime"
12+
13+
common "github.com/hyperledger/fabric/common/metadata"
14+
)
15+
16+
// package-scoped variables
17+
18+
// Package version
19+
var Version string
20+
21+
// package-scoped constants
22+
23+
// Program name
24+
const ProgramName = "orderer"
25+
26+
func GetVersionInfo() string {
27+
Version = common.Version
28+
if Version == "" {
29+
Version = "development build"
30+
}
31+
32+
return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
33+
ProgramName, Version, runtime.Version(),
34+
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
35+
}

orderer/metadata/metadata_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package metadata_test
8+
9+
import (
10+
"fmt"
11+
"runtime"
12+
"testing"
13+
14+
"github.com/hyperledger/fabric/common/tools/cryptogen/metadata"
15+
"github.com/stretchr/testify/assert"
16+
)
17+
18+
func TestGetVersionInfo(t *testing.T) {
19+
testVersion := "TestVersion"
20+
metadata.Version = testVersion
21+
22+
expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
23+
metadata.ProgramName, testVersion, runtime.Version(),
24+
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
25+
assert.Equal(t, expected, metadata.GetVersionInfo())
26+
}

orderer/server.go

-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ type server struct {
5757

5858
// NewServer creates an ab.AtomicBroadcastServer based on the broadcast target and ledger Reader
5959
func NewServer(ml multichain.Manager, signer crypto.LocalSigner) ab.AtomicBroadcastServer {
60-
logger.Infof("Starting orderer")
61-
6260
s := &server{
6361
dh: deliver.NewHandlerImpl(deliverSupport{Manager: ml}),
6462
bh: broadcast.NewHandlerImpl(broadcastSupport{

0 commit comments

Comments
 (0)