Search in sources :

Example 1 with ProcessorStatusEntity

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

the class FlowResource method getProcessorStatus.

// ------
// status
// ------
/**
 * Retrieves the specified processor status.
 *
 * @param id The id of the processor history to retrieve.
 * @return A processorStatusEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("processors/{id}/status")
@ApiOperation(value = "Gets status for a processor", response = ProcessorStatusEntity.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 getProcessorStatus(@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 processor id.", required = true) @PathParam("id") String id) 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 ProcessorStatusEntity entity = (ProcessorStatusEntity) nodeResponse.getUpdatedEntity();
            // ensure there is an updated entity (result of merging) and prune the response as necessary
            if (entity != null && !nodewise) {
                entity.getProcessorStatus().setNodeSnapshots(null);
            }
            return nodeResponse.getResponse();
        } else {
            return replicate(HttpMethod.GET, clusterNodeId);
        }
    }
    // get the specified processor status
    final ProcessorStatusEntity entity = serviceFacade.getProcessorStatus(id);
    return generateOkResponse(entity).build();
}
Also used : ProcessorStatusEntity(org.apache.nifi.web.api.entity.ProcessorStatusEntity) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) 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)

Example 2 with ProcessorStatusEntity

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

the class ProcessorStatusEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ProcessorStatusEntity clientEntity, Map<NodeIdentifier, ProcessorStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final ProcessorStatusDTO mergedProcessorStatus = clientEntity.getProcessorStatus();
    mergedProcessorStatus.setNodeSnapshots(new ArrayList<>());
    final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
    final NodeProcessorStatusSnapshotDTO selectedNodeSnapshot = new NodeProcessorStatusSnapshotDTO();
    selectedNodeSnapshot.setStatusSnapshot(mergedProcessorStatus.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedProcessorStatus.getNodeSnapshots().add(selectedNodeSnapshot);
    // merge the other nodes
    for (final Map.Entry<NodeIdentifier, ProcessorStatusEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final ProcessorStatusEntity nodeProcessorStatusEntity = entry.getValue();
        final ProcessorStatusDTO nodeProcessorStatus = nodeProcessorStatusEntity.getProcessorStatus();
        if (nodeProcessorStatus == mergedProcessorStatus) {
            continue;
        }
        mergeStatus(mergedProcessorStatus, clientEntity.getCanRead(), nodeProcessorStatus, nodeProcessorStatusEntity.getCanRead(), nodeId);
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeProcessorStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeProcessorStatusSnapshotDTO) ProcessorStatusEntity(org.apache.nifi.web.api.entity.ProcessorStatusEntity) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) 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) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) ProcessorStatusEntity(org.apache.nifi.web.api.entity.ProcessorStatusEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) NodeProcessorStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeProcessorStatusSnapshotDTO)

Example 3 with ProcessorStatusEntity

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

the class EntityFactory method createProcessorStatusEntity.

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

Aggregations

ProcessorStatusEntity (org.apache.nifi.web.api.entity.ProcessorStatusEntity)3 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)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 NodeProcessorStatusSnapshotDTO (org.apache.nifi.web.api.dto.status.NodeProcessorStatusSnapshotDTO)1 ProcessorStatusDTO (org.apache.nifi.web.api.dto.status.ProcessorStatusDTO)1