在API中增加接口,可以通过API获取当前组网中的共识节点数目和非共识节点数目。

This commit is contained in:
wuwei1972 2019-09-06 15:45:08 +08:00
parent b0cf9baffb
commit 860564e602
2 changed files with 22 additions and 1 deletions

View File

@ -58,6 +58,7 @@ object RestActor {
val contractOperationMode = SystemProfile.getContractOperationMode
case object ChainInfo
case object NodeNumber
case class SystemStart(cout: Int)
case class SystemStop(from: Int, to: Int)
@ -290,5 +291,11 @@ class RestActor(moduleName: String) extends ModuleBase(moduleName) {
val cij = JsonFormat.toJson(sr.getBlockChainInfo)
sender ! QueryResult(Option(cij))
case NodeNumber =>
val stablenode = pe.getNodeMgr.getStableNodes.size
val snode = pe.getNodeMgr.getNodes.size
val rs = "{\"consensus nodes\":\""+stablenode+"\",\"nodes\":\""+snode+"\"}"
sender ! QueryResult(Option(JsonMethods.parse(string2JsonInput(rs))))
}
}

View File

@ -66,7 +66,7 @@ class ChainService(ra: ActorRef)(implicit executionContext: ExecutionContext)
implicit val formats = DefaultFormats
implicit val timeout = Timeout(20.seconds)
val route = getBlockChainInfo
val route = getBlockChainInfo ~ getNodeNumber
@ApiOperation(value = "返回块链信息", notes = "", nickname = "getChainInfo", httpMethod = "GET")
@ApiResponses(Array(
@ -80,6 +80,20 @@ class ChainService(ra: ActorRef)(implicit executionContext: ExecutionContext)
}
}
}
@Path("/node")
@ApiOperation(value = "返回组网节点数量", notes = "", nickname = "getNodeNumber", httpMethod = "GET")
@ApiResponses(Array(
new ApiResponse(code = 200, message = "返回组网节点数量", response = classOf[QueryResult])))
def getNodeNumber =
path("chaininfo" / "node") {
get {
extractClientIP { ip =>
RepLogger.debug(RepLogger.APIAccess_Logger, s"remoteAddr=${ip} get node number")
complete { (ra ? NodeNumber).mapTo[QueryResult] }
}
}
}
}
/**