Skip to content

Commit

Permalink
Merge pull request #1357 from lehors/issue-1158
Browse files Browse the repository at this point in the history
Issue 1158 - Peer command usage
  • Loading branch information
srderson committed May 12, 2016
2 parents e108db6 + d6dfda6 commit 216fb39
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ membersrvc:

unit-test: peer-image
@echo "Running unit-tests"
$(eval CID := $(shell docker run -dit -p 30303:30303 hyperledger-peer peer peer))
$(eval CID := $(shell docker run -dit -p 30303:30303 hyperledger-peer peer node start))
@go test -timeout=20m $(shell go list $(PKGNAME)/... | grep -v /vendor/ | grep -v /examples/)
@docker kill $(CID)
@touch .peerimage-dummy
Expand Down
2 changes: 1 addition & 1 deletion bddtests/compose-defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ vp:
# TODO: This is currently required due to BUG in variant logic based upon log level.
- CORE_LOGGING_LEVEL=DEBUG
# Startup of peer must be delayed to allow membersrvc to come up first
command: sh -c "sleep 5; peer peer"
command: sh -c "sleep 5; peer node start"

membersrvc:
image: membersrvc
Expand Down
2 changes: 1 addition & 1 deletion bddtests/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def after_scenario(context, scenario):

# stop any running peer that could get in the way before starting the tests
def before_all(context):
cli_call(context, ["../peer/peer", "stop"], expect_success=False)
cli_call(context, ["../peer/peer", "node", "stop"], expect_success=False)
2 changes: 1 addition & 1 deletion bddtests/peer_basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#@chaincodeImagesUpToDate
Feature: lanching 3 peers
As a HyperLedger developer
I want to be able to launch a 3 peers
I want to be able to launch 3 peers

# @wip
Scenario: Peers list test, single peer issue #827
Expand Down
21 changes: 9 additions & 12 deletions docs/API/CoreAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ You will see output similar to the example below (**NOTE:** rootcommand below is
peer [command]
Available Commands:
peer Runs the peer.
status Returns status of the peer.
stop Stops the running peer.
login Logs in a user on CLI.
network Lists all network peers.
node node specific commands.
network network specific commands.
chaincode chaincode specific commands.
help Help about any command
Expand All @@ -52,11 +49,11 @@ below:

Command | **stdout** result in the event of success
--- | ---
`peer` | N/A
`status` | String form of [StatusCode](https://github.com/hyperledger/fabric/blob/master/protos/server_admin.proto#L36)
`stop` | String form of [StatusCode](https://github.com/hyperledger/fabric/blob/master/protos/server_admin.proto#L36)
`login` | N/A
`vm` | String form of [StatusCode](https://github.com/hyperledger/fabric/blob/master/protos/server_admin.proto#L36)
`node start` | N/A
`node status` | String form of [StatusCode](https://github.com/hyperledger/fabric/blob/master/protos/server_admin.proto#L36)
`node stop` | String form of [StatusCode](https://github.com/hyperledger/fabric/blob/master/protos/server_admin.proto#L36)
`network login` | N/A
`network list` | The list of network connections to the peer node.
`chaincode deploy` | The chaincode container name (hash) required for subsequent `chaincode invoke` and `chaincode query` commands
`chaincode invoke` | The transaction ID (UUID)
`chaincode query` | By default, the query result is formatted as a printable string. Command line options support writing this value as raw bytes (-r, --raw), or formatted as the hexadecimal representation of the raw bytes (-x, --hex). If the query response is empty then nothing is output.
Expand Down Expand Up @@ -654,7 +651,7 @@ For additional information on the REST endpoints and more detailed examples, ple
```
cd /opt/gopath/src/github.com/hyperledger/fabric
./peer
./peer node start
```
8. If you need to construct a test blockchain on the local peer node, run the the TestServerOpenchain_API_GetBlockCount test implemented inside [api_test.go](https://github.com/hyperledger/fabric/blob/master/core/rest/api_test.go). This test will create a blockchain with 5 blocks. Subsequently restart the peer process.
Expand Down Expand Up @@ -686,7 +683,7 @@ You can interface with the peer process from a Node.js application. One way to a
2. Run a local peer node only (not a complete network) with:
`cd peer; ./peer`
`cd peer; ./peer node start`
3. Set up a test blockchain data structure (with 5 blocks only) by running a test from within Vagrant as follows. Subsequently restart the peer process.
Expand Down
6 changes: 3 additions & 3 deletions docs/API/SandboxSetup.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Build and run the peer process to enable security and privacy after setting <b>s
cd $GOPATH/src/github.com/hyperledger/fabric
make peer
cd ./peer
./peer peer --peer-chaincodedev
./peer node start --peer-chaincodedev

Alternatively, enable security and privacy on the peer with environment variables:

CORE_SECURITY_ENABLED=true CORE_SECURITY_PRIVACY=true ./peer peer --peer-chaincodedev
CORE_SECURITY_ENABLED=true CORE_SECURITY_PRIVACY=true ./peer node start --peer-chaincodedev

###Vagrant Terminal 2 (chaincode)

Expand Down Expand Up @@ -85,7 +85,7 @@ From your command line terminal, move to the `devenv` subdirectory of your works
Register the user though the CLI, substituting for `<username>` appropriately:

cd $GOPATH/src/github.com/hyperledger/fabric/peer
./peer login <username>
./peer network login <username>

The command will prompt for a password, which must match the <b>enrollmentPW</b> listed for the target user in the 'users' section of the [membersrvc.yaml](https://github.com/hyperledger/fabric/blob/master/membersrvc/membersrvc.yaml) file. If the password entered does not match the <b>enrollmentPW</b>, an error will result.

Expand Down
6 changes: 3 additions & 3 deletions docs/dev-setup/devnet-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ By default, we are using a consensus plugin called `NOOPS`, which doesn't really
#### Start up the first validating peer:

```
docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp0 -e CORE_PEER_ADDRESSAUTODETECT=true hyperledger-peer peer peer
docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp0 -e CORE_PEER_ADDRESSAUTODETECT=true hyperledger-peer peer node start
```

If started with security, enviroment variables regarding security enabling, CA address and peer's ID and password have to be changed:

```
docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp0 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_SECURITY_ENABLED=true -e CORE_SECURITY_PRIVACY=true -e CORE_PEER_PKI_ECA_PADDR=172.17.0.1:50051 -e CORE_PEER_PKI_TCA_PADDR=172.17.0.1:50051 -e CORE_PEER_PKI_TLSCA_PADDR=172.17.0.1:50051 -e CORE_SECURITY_ENROLLID=vp0 -e CORE_SECURITY_ENROLLSECRET=XX hyperledger-peer peer peer
docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp0 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_SECURITY_ENABLED=true -e CORE_SECURITY_PRIVACY=true -e CORE_PEER_PKI_ECA_PADDR=172.17.0.1:50051 -e CORE_PEER_PKI_TCA_PADDR=172.17.0.1:50051 -e CORE_PEER_PKI_TLSCA_PADDR=172.17.0.1:50051 -e CORE_SECURITY_ENROLLID=vp0 -e CORE_SECURITY_ENROLLSECRET=XX hyperledger-peer peer node start
```

Additionally, validating peer (enrollID vp0 and enrollSecret XX) has to be added to membersrvc.yaml file (in fabric/membersrvc).
Expand All @@ -62,7 +62,7 @@ Additionally, validating peer (enrollID vp0 and enrollSecret XX) has to be added
We need to get the IP address of the first validating peer, which will act as the root node that the new peer will connect to. The address is printed out on the terminal window of the first peer (eg 172.17.0.2). We'll use "vp2" as the ID for the second validating peer.

```
docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp1 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_PEER_DISCOVERY_ROOTNODE=172.17.0.2:30303 hyperledger-peer peer peer
docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp1 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_PEER_DISCOVERY_ROOTNODE=172.17.0.2:30303 hyperledger-peer peer node start
```

You can start up a few more validating peers in the similar manner as you wish. Remember to change the ID.
Expand Down
23 changes: 18 additions & 5 deletions docs/dev-setup/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ You should see some output similar to below (**NOTE**: The root command below is
Available Commands:
peer Runs the peer.
status Returns status of the peer.
stop Stops the running peer.
login Logs in a user on CLI.
network Lists all network peers.
node node specific commands.
network network specific commands.
chaincode chaincode specific commands.
help Help about any command
Expand All @@ -58,7 +56,22 @@ You should see some output similar to below (**NOTE**: The root command below is
```

The `peer` command will initiate a peer process, with which one can interact by executing other commands. For example, the `status` command will return the status of the running peer.
The `node start` command will initiate a peer process, with which one can interact by executing other commands. For example, the `node status` command will return the status of the running peer. The full list of commands is the following:

```
node
start Starts the node.
status Returns status of the node.
stop Stops the running node.
network
login Logs in user to CLI.
list Lists all network peers.
chaincode
deploy Deploy the specified chaincode to the network.
invoke Invoke the specified chaincode.
query Query using the specified chaincode.
help Help about any command
```

#### 3. Test
New code must be accompanied by test cases both in unit and Behave tests.
Expand Down
2 changes: 1 addition & 1 deletion docs/dev-setup/logging-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ check whether logging modules actually do or will exist.
The logging level of the `peer` command can be controlled from the command
line for each invocation using the `--logging-level` flag, for example

peer peer --logging-level=debug
peer node start --logging-level=debug

The default logging level for each individual `peer` subcommand can also
be set in the **openchain.yaml** file. For example the key `logging.peer` sets
Expand Down
2 changes: 1 addition & 1 deletion peer/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ logging:
# defined at runtime and are not checked for validity during option
# processing.

# Default logging levels are specified here for each of the obc-peer
# Default logging levels are specified here for each of the peer
# commands. For commands that have subcommands, the defaults also apply to
# all subcommands of the command. These logging levels can be overridden
# on the command line using the --logging-level command-line option, or by
Expand Down
89 changes: 49 additions & 40 deletions peer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var logger = logging.MustGetLogger("main")

// Constants go here.
const fabric = "hyperledger"
const nodeFuncName = "node"
const networkFuncName = "network"
const chainFuncName = "chaincode"
const cmdRoot = "core"
const undefinedParamValue = ""
Expand All @@ -76,25 +78,28 @@ var mainCmd = &cobra.Command{
},
}

var peerCmd = &cobra.Command{
Use: "peer",
Short: "Runs the peer.",
Long: `Runs a peer that interacts with the network.`,
var nodeCmd = &cobra.Command{
Use: nodeFuncName,
Short: fmt.Sprintf("%s specific commands.", nodeFuncName),
Long: fmt.Sprintf("%s specific commands.", nodeFuncName),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
core.LoggingInit("peer")
core.LoggingInit(nodeFuncName)
},
}

var nodeStartCmd = &cobra.Command{
Use: "start",
Short: "Starts the node.",
Long: `Starts a node that interacts with the network.`,
RunE: func(cmd *cobra.Command, args []string) error {
return serve(args)
},
}

var statusCmd = &cobra.Command{
var nodeStatusCmd = &cobra.Command{
Use: "status",
Short: "Returns status of the peer.",
Long: `Returns the status of the currently running peer.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
core.LoggingInit("status")
},
Short: "Returns status of the node.",
Long: `Returns the status of the running node.`,
Run: func(cmd *cobra.Command, args []string) {
status()
},
Expand All @@ -104,27 +109,30 @@ var (
stopPidFile string
)

var stopCmd = &cobra.Command{
var nodeStopCmd = &cobra.Command{
Use: "stop",
Short: "Stops the running peer.",
Long: `Stops the currently running peer, disconnecting from the network.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
core.LoggingInit("stop")
},
Short: "Stops the running node.",
Long: `Stops the running node, disconnecting from the network.`,
Run: func(cmd *cobra.Command, args []string) {
stop()
},
}

var loginCmd = &cobra.Command{
Use: "login",
Short: "Logs in a user on CLI.",
Long: `Logs in the local user on CLI. Must supply username as a parameter.`,
var networkCmd = &cobra.Command{
Use: networkFuncName,
Short: fmt.Sprintf("%s specific commands.", networkFuncName),
Long: fmt.Sprintf("%s specific commands.", networkFuncName),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
core.LoggingInit("login")
core.LoggingInit(networkFuncName)
},
}

var networkLoginCmd = &cobra.Command{
Use: "login",
Short: "Logs in user to CLI.",
Long: `Logs in the local user to CLI. Must supply username as a parameter.`,
RunE: func(cmd *cobra.Command, args []string) error {
return login(args)
return networkLogin(args)
},
}

Expand All @@ -146,15 +154,12 @@ var loginCmd = &cobra.Command{
// },
// }

var networkCmd = &cobra.Command{
Use: "network",
var networkListCmd = &cobra.Command{
Use: "list",
Short: "Lists all network peers.",
Long: `Returns a list of all existing network connections for the target peer node, includes both validating and non-validating peers.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
core.LoggingInit("network")
},
RunE: func(cmd *cobra.Command, args []string) error {
return network()
return networkList()
},
}

Expand Down Expand Up @@ -223,14 +228,14 @@ func main() {
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)

// Define command-line flags that are valid for all obc-peer commands and
// Define command-line flags that are valid for all peer commands and
// subcommands.
mainFlags := mainCmd.PersistentFlags()
mainFlags.String("logging-level", "", "Default logging level and overrides, see core.yaml for full syntax")
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))

// Set the flags on the peer command.
flags := peerCmd.Flags()
// Set the flags on the node start command.
flags := nodeStartCmd.Flags()
flags.Bool("peer-tls-enabled", false, "Connection uses TLS if true, else plain TCP")
flags.String("peer-tls-cert-file", "testdata/server1.pem", "TLS cert file")
flags.String("peer-tls-key-file", "testdata/server1.key", "TLS key file")
Expand Down Expand Up @@ -262,20 +267,24 @@ func main() {
panic(fmt.Errorf("Fatal error when reading %s config file: %s\n", cmdRoot, err))
}

mainCmd.AddCommand(peerCmd)
mainCmd.AddCommand(statusCmd)
nodeCmd.AddCommand(nodeStartCmd)
nodeCmd.AddCommand(nodeStatusCmd)

stopCmd.Flags().StringVarP(&stopPidFile, "stop-peer-pid-file", "", viper.GetString("peer.fileSystemPath"), "Location of peer pid local file, for forces kill")
mainCmd.AddCommand(stopCmd)
nodeStopCmd.Flags().StringVarP(&stopPidFile, "stop-peer-pid-file", "", viper.GetString("peer.fileSystemPath"), "Location of peer pid local file, for forces kill")
nodeCmd.AddCommand(nodeStopCmd)

mainCmd.AddCommand(nodeCmd)

// Set the flags on the login command.
loginCmd.PersistentFlags().StringVarP(&loginPW, "password", "p", undefinedParamValue, "The password for user. You will be requested to enter the password if this flag is not specified.")
networkLoginCmd.PersistentFlags().StringVarP(&loginPW, "password", "p", undefinedParamValue, "The password for user. You will be requested to enter the password if this flag is not specified.")

mainCmd.AddCommand(loginCmd)
networkCmd.AddCommand(networkLoginCmd)

// vmCmd.AddCommand(vmPrimeCmd)
// mainCmd.AddCommand(vmCmd)

networkCmd.AddCommand(networkListCmd)

mainCmd.AddCommand(networkCmd)

chaincodeCmd.PersistentFlags().StringVarP(&chaincodeLang, "lang", "l", "golang", fmt.Sprintf("Language the %s is written in", chainFuncName))
Expand Down Expand Up @@ -594,7 +603,7 @@ func stop() (err error) {

// login confirms the enrollmentID and secret password of the client with the
// CA and stores the enrollment certificate and key in the Devops server.
func login(args []string) (err error) {
func networkLogin(args []string) (err error) {
logger.Info("CLI client login...")

// Check for username argument
Expand Down Expand Up @@ -957,7 +966,7 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool) (err

// Show a list of all existing network connections for the target peer node,
// includes both validating and non-validating peers
func network() (err error) {
func networkList() (err error) {
clientConn, err := peer.NewPeerClientConnection()
if err != nil {
err = fmt.Errorf("Error trying to connect to local peer: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion sdk/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ To run the unit tests follow the instructions below.
```
cd $GOPATH/src/github.com/hyperledger/fabric/peer
go build
./peer peer
./peer node start
```
3. Switch to the HCL directory and install the necessary Node.js module dependencies.
Expand Down

0 comments on commit 216fb39

Please sign in to comment.