github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/core/admin.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 core
    18  
    19  import (
    20  	"github.com/golang/protobuf/ptypes/empty"
    21  	"github.com/hyperledger/fabric/common/flogging"
    22  	pb "github.com/hyperledger/fabric/protos/peer"
    23  	"golang.org/x/net/context"
    24  )
    25  
    26  var log = flogging.MustGetLogger("server")
    27  
    28  // NewAdminServer creates and returns a Admin service instance.
    29  func NewAdminServer() *ServerAdmin {
    30  	s := new(ServerAdmin)
    31  	return s
    32  }
    33  
    34  // ServerAdmin implementation of the Admin service for the Peer
    35  type ServerAdmin struct {
    36  }
    37  
    38  // GetStatus reports the status of the server
    39  func (*ServerAdmin) GetStatus(context.Context, *empty.Empty) (*pb.ServerStatus, error) {
    40  	status := &pb.ServerStatus{Status: pb.ServerStatus_STARTED}
    41  	log.Debugf("returning status: %s", status)
    42  	return status, nil
    43  }
    44  
    45  // StartServer starts the server
    46  func (*ServerAdmin) StartServer(context.Context, *empty.Empty) (*pb.ServerStatus, error) {
    47  	status := &pb.ServerStatus{Status: pb.ServerStatus_STARTED}
    48  	log.Debugf("returning status: %s", status)
    49  	return status, nil
    50  }
    51  
    52  // GetModuleLogLevel gets the current logging level for the specified module
    53  // TODO Modify the signature so as to remove the error return - it's always been nil
    54  func (*ServerAdmin) GetModuleLogLevel(ctx context.Context, request *pb.LogLevelRequest) (*pb.LogLevelResponse, error) {
    55  	logLevelString := flogging.GetModuleLevel(request.LogModule)
    56  	logResponse := &pb.LogLevelResponse{LogModule: request.LogModule, LogLevel: logLevelString}
    57  	return logResponse, nil
    58  }
    59  
    60  // SetModuleLogLevel sets the logging level for the specified module
    61  func (*ServerAdmin) SetModuleLogLevel(ctx context.Context, request *pb.LogLevelRequest) (*pb.LogLevelResponse, error) {
    62  	logLevelString, err := flogging.SetModuleLevel(request.LogModule, request.LogLevel)
    63  	logResponse := &pb.LogLevelResponse{LogModule: request.LogModule, LogLevel: logLevelString}
    64  	return logResponse, err
    65  }
    66  
    67  // RevertLogLevels reverts the log levels for all modules to the level
    68  // defined at the end of peer startup.
    69  func (*ServerAdmin) RevertLogLevels(context.Context, *empty.Empty) (*empty.Empty, error) {
    70  	err := flogging.RevertToPeerStartupLevels()
    71  
    72  	return &empty.Empty{}, err
    73  }