Search in sources :

Example 1 with ClusteSummaryEntity

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();
}
Also used : ClusteSummaryEntity(org.apache.nifi.web.api.entity.ClusteSummaryEntity) ClusterSummaryDTO(org.apache.nifi.web.api.dto.ClusterSummaryDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ClusterCoordinator(org.apache.nifi.cluster.coordination.ClusterCoordinator) ArrayList(java.util.ArrayList) List(java.util.List) NodeConnectionState(org.apache.nifi.cluster.coordination.node.NodeConnectionState) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)1 NodeConnectionState (org.apache.nifi.cluster.coordination.node.NodeConnectionState)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 ClusterSummaryDTO (org.apache.nifi.web.api.dto.ClusterSummaryDTO)1 ClusteSummaryEntity (org.apache.nifi.web.api.entity.ClusteSummaryEntity)1