Skip to content

Commit

Permalink
[FAB-4411] Enable orderer to report version info
Browse files Browse the repository at this point in the history
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 <gari.r.singh@gmail.com>
  • Loading branch information
mastersingh24 committed Jun 6, 2017
1 parent 88d4845 commit ed8864d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 13 deletions.
44 changes: 33 additions & 11 deletions orderer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/hyperledger/fabric/orderer/kafka"
"github.com/hyperledger/fabric/orderer/ledger"
"github.com/hyperledger/fabric/orderer/localconfig"
"github.com/hyperledger/fabric/orderer/metadata"
"github.com/hyperledger/fabric/orderer/multichain"
"github.com/hyperledger/fabric/orderer/solo"
cb "github.com/hyperledger/fabric/protos/common"
Expand All @@ -44,22 +45,43 @@ import (
"github.com/hyperledger/fabric/common/localmsp"
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
logging "github.com/op/go-logging"
"gopkg.in/alecthomas/kingpin.v2"
)

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

//command line flags
var (
app = kingpin.New("orderer", "Hyperledger Fabric orderer node")

start = app.Command("start", "Start the orderer node").Default()
version = app.Command("version", "Show version information")
)

func main() {
conf := config.Load()
initializeLoggingLevel(conf)
initializeProfilingService(conf)
grpcServer := initializeGrpcServer(conf)
initializeLocalMsp(conf)
signer := localmsp.NewSigner()
manager := initializeMultiChainManager(conf, signer)
server := NewServer(manager, signer)
ab.RegisterAtomicBroadcastServer(grpcServer.Server(), server)
logger.Info("Beginning to serve requests")
grpcServer.Start()

kingpin.Version("0.0.1")
switch kingpin.MustParse(app.Parse(os.Args[1:])) {

// "start" command
case start.FullCommand():
logger.Infof("Starting %s", metadata.GetVersionInfo())
conf := config.Load()
initializeLoggingLevel(conf)
initializeProfilingService(conf)
grpcServer := initializeGrpcServer(conf)
initializeLocalMsp(conf)
signer := localmsp.NewSigner()
manager := initializeMultiChainManager(conf, signer)
server := NewServer(manager, signer)
ab.RegisterAtomicBroadcastServer(grpcServer.Server(), server)
logger.Info("Beginning to serve requests")
grpcServer.Start()
// "version" command
case version.FullCommand():
fmt.Println(metadata.GetVersionInfo())
}

}

// Set the logging level
Expand Down
35 changes: 35 additions & 0 deletions orderer/metadata/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package metadata

import (
"fmt"
"runtime"

common "github.com/hyperledger/fabric/common/metadata"
)

// package-scoped variables

// Package version
var Version string

// package-scoped constants

// Program name
const ProgramName = "orderer"

func GetVersionInfo() string {
Version = common.Version
if Version == "" {
Version = "development build"
}

return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
}
26 changes: 26 additions & 0 deletions orderer/metadata/metadata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package metadata_test

import (
"fmt"
"runtime"
"testing"

"github.com/hyperledger/fabric/common/tools/cryptogen/metadata"
"github.com/stretchr/testify/assert"
)

func TestGetVersionInfo(t *testing.T) {
testVersion := "TestVersion"
metadata.Version = testVersion

expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, testVersion, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
assert.Equal(t, expected, metadata.GetVersionInfo())
}
2 changes: 0 additions & 2 deletions orderer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ type server struct {

// NewServer creates an ab.AtomicBroadcastServer based on the broadcast target and ledger Reader
func NewServer(ml multichain.Manager, signer crypto.LocalSigner) ab.AtomicBroadcastServer {
logger.Infof("Starting orderer")

s := &server{
dh: deliver.NewHandlerImpl(deliverSupport{Manager: ml}),
bh: broadcast.NewHandlerImpl(broadcastSupport{
Expand Down

0 comments on commit ed8864d

Please sign in to comment.