use of org.apache.nifi.web.api.entity.ClusteSummaryEntity in project nifi by apache.
the class FlowResource method getClusterSummary.
/**
* Retrieves the cluster summary for this NiFi.
*
* @return A clusterSummaryEntity.
* @throws InterruptedException if interrupted
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("cluster/summary")
@ApiOperation(value = "The cluster summary for this NiFi", response = ClusteSummaryEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getClusterSummary() throws InterruptedException {
authorizeFlow();
final ClusterSummaryDTO clusterConfiguration = new ClusterSummaryDTO();
final ClusterCoordinator clusterCoordinator = getClusterCoordinator();
if (clusterCoordinator != null && clusterCoordinator.isConnected()) {
final Map<NodeConnectionState, List<NodeIdentifier>> stateMap = clusterCoordinator.getConnectionStates();
int totalNodeCount = 0;
for (final List<NodeIdentifier> nodeList : stateMap.values()) {
totalNodeCount += nodeList.size();
}
final List<NodeIdentifier> connectedNodeIds = stateMap.get(NodeConnectionState.CONNECTED);
final int connectedNodeCount = (connectedNodeIds == null) ? 0 : connectedNodeIds.size();
clusterConfiguration.setConnectedNodeCount(connectedNodeCount);
clusterConfiguration.setTotalNodeCount(totalNodeCount);
clusterConfiguration.setConnectedNodes(connectedNodeCount + " / " + totalNodeCount);
}
clusterConfiguration.setClustered(isClustered());
clusterConfiguration.setConnectedToCluster(isConnectedToCluster());
// create the response entity
final ClusteSummaryEntity entity = new ClusteSummaryEntity();
entity.setClusterSummary(clusterConfiguration);
// generate the response
return generateOkResponse(entity).build();
}
Aggregations