Search in sources :

Example 1 with ProcessGroupStatusEntity

use of org.apache.nifi.web.api.entity.ProcessGroupStatusEntity in project nifi by apache.

the class EntityFactory method createProcessGroupStatusEntity.

public ProcessGroupStatusEntity createProcessGroupStatusEntity(final ProcessGroupStatusDTO status, final PermissionsDTO permissions) {
    final ProcessGroupStatusEntity entity = new ProcessGroupStatusEntity();
    entity.setCanRead(permissions.getCanRead());
    // always set the status, as it's always allowed... just need to provide permission context for merging responses
    entity.setProcessGroupStatus(status);
    return entity;
}
Also used : ProcessGroupStatusEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusEntity) RemoteProcessGroupStatusEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity)

Example 2 with ProcessGroupStatusEntity

use of org.apache.nifi.web.api.entity.ProcessGroupStatusEntity in project nifi by apache.

the class GroupStatusEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ProcessGroupStatusEntity clientEntity, Map<NodeIdentifier, ProcessGroupStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final ProcessGroupStatusDTO mergedProcessGroupStatus = clientEntity.getProcessGroupStatus();
    mergedProcessGroupStatus.setNodeSnapshots(new ArrayList<>());
    final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
    final NodeProcessGroupStatusSnapshotDTO selectedNodeSnapshot = new NodeProcessGroupStatusSnapshotDTO();
    selectedNodeSnapshot.setStatusSnapshot(mergedProcessGroupStatus.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedProcessGroupStatus.getNodeSnapshots().add(selectedNodeSnapshot);
    for (final Map.Entry<NodeIdentifier, ProcessGroupStatusEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final ProcessGroupStatusEntity nodeProcessGroupStatusEntity = entry.getValue();
        final ProcessGroupStatusDTO nodeProcessGroupStatus = nodeProcessGroupStatusEntity.getProcessGroupStatus();
        if (nodeProcessGroupStatus == mergedProcessGroupStatus) {
            continue;
        }
        mergeStatus(mergedProcessGroupStatus, clientEntity.getCanRead(), nodeProcessGroupStatus, nodeProcessGroupStatusEntity.getCanRead(), nodeId);
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) NodeProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeProcessGroupStatusSnapshotDTO) ProcessGroupStatusEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusEntity) URI(java.net.URI) Pattern(java.util.regex.Pattern) ComponentEntityStatusMerger(org.apache.nifi.cluster.manager.ComponentEntityStatusMerger) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ArrayList(java.util.ArrayList) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessGroupStatusEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusEntity) Map(java.util.Map) NodeProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeProcessGroupStatusSnapshotDTO)

Example 3 with ProcessGroupStatusEntity

use of org.apache.nifi.web.api.entity.ProcessGroupStatusEntity in project nifi by apache.

the class FlowResource method getProcessGroupStatus.

/**
 * Retrieves the status report for this NiFi.
 *
 * @param recursive Optional recursive flag that defaults to false. If set to true, all descendant groups and the status of their content will be included.
 * @param groupId   The group id
 * @return A processGroupStatusEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("process-groups/{id}/status")
@ApiOperation(value = "Gets the status for a process group", notes = "The status for a process group includes status for all descendent components. When invoked on the root group with " + "recursive set to true, it will return the current status of every component in the flow.", response = ProcessGroupStatusEntity.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 = 404, message = "The specified resource could not be found."), @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 getProcessGroupStatus(@ApiParam(value = "Whether all descendant groups and the status of their content will be included. Optional, defaults to false", required = false) @QueryParam("recursive") @DefaultValue(RECURSIVE) Boolean recursive, @ApiParam(value = "Whether or not to include the breakdown per node. Optional, defaults to false", required = false) @QueryParam("nodewise") @DefaultValue(NODEWISE) Boolean nodewise, @ApiParam(value = "The id of the node where to get the status.", required = false) @QueryParam("clusterNodeId") String clusterNodeId, @ApiParam(value = "The process group id.", required = true) @PathParam("id") String groupId) throws InterruptedException {
    authorizeFlow();
    // ensure a valid request
    if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) {
        throw new IllegalArgumentException("Nodewise requests cannot be directed at a specific node.");
    }
    if (isReplicateRequest()) {
        // determine where this request should be sent
        if (clusterNodeId == null) {
            final NodeResponse nodeResponse = replicateNodeResponse(HttpMethod.GET);
            final ProcessGroupStatusEntity entity = (ProcessGroupStatusEntity) nodeResponse.getUpdatedEntity();
            // ensure there is an updated entity (result of merging) and prune the response as necessary
            if (entity != null && !nodewise) {
                entity.getProcessGroupStatus().setNodeSnapshots(null);
            }
            return nodeResponse.getResponse();
        } else {
            return replicate(HttpMethod.GET, clusterNodeId);
        }
    }
    // get the status
    final ProcessGroupStatusEntity entity = serviceFacade.getProcessGroupStatus(groupId, recursive);
    return generateOkResponse(entity).build();
}
Also used : NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) RemoteProcessGroupStatusEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity) ProcessGroupStatusEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusEntity) 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

ProcessGroupStatusEntity (org.apache.nifi.web.api.entity.ProcessGroupStatusEntity)3 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)2 RemoteProcessGroupStatusEntity (org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)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 ComponentEntityStatusMerger (org.apache.nifi.cluster.manager.ComponentEntityStatusMerger)1 StatusMerger (org.apache.nifi.cluster.manager.StatusMerger)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 NodeProcessGroupStatusSnapshotDTO (org.apache.nifi.web.api.dto.status.NodeProcessGroupStatusSnapshotDTO)1 ProcessGroupStatusDTO (org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO)1