github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/peer/node/status.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package node
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/golang/protobuf/ptypes/empty"
    23  	"github.com/hyperledger/fabric/peer/common"
    24  	pb "github.com/hyperledger/fabric/protos/peer"
    25  	"github.com/spf13/cobra"
    26  	"golang.org/x/net/context"
    27  )
    28  
    29  func statusCmd() *cobra.Command {
    30  	return nodeStatusCmd
    31  }
    32  
    33  var nodeStatusCmd = &cobra.Command{
    34  	Use:   "status",
    35  	Short: "Returns status of the node.",
    36  	Long:  `Returns the status of the running node.`,
    37  	RunE: func(cmd *cobra.Command, args []string) error {
    38  		return status()
    39  	},
    40  }
    41  
    42  func status() (err error) {
    43  
    44  	adminClient, err := common.GetAdminClient()
    45  	if err != nil {
    46  		logger.Warningf("%s", err)
    47  		fmt.Println(&pb.ServerStatus{Status: pb.ServerStatus_UNKNOWN})
    48  		return err
    49  	}
    50  
    51  	status, err := adminClient.GetStatus(context.Background(), &empty.Empty{})
    52  	if err != nil {
    53  		logger.Infof("Error trying to get status from local peer: %s", err)
    54  		err = fmt.Errorf("Error trying to connect to local peer: %s", err)
    55  		fmt.Println(&pb.ServerStatus{Status: pb.ServerStatus_UNKNOWN})
    56  		return err
    57  	}
    58  	fmt.Println(status)
    59  	return nil
    60  }