Search in sources :

Example 1 with PortStatusEntity

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

the class FlowResource method getInputPortStatus.

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

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

the class FlowResource method getOutputPortStatus.

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

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

the class EntityFactory method createPortStatusEntity.

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

Example 4 with PortStatusEntity

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

the class PortStatusEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(PortStatusEntity clientEntity, Map<NodeIdentifier, PortStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final PortStatusDTO mergedPortStatus = clientEntity.getPortStatus();
    mergedPortStatus.setNodeSnapshots(new ArrayList<>());
    final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
    if (selectedNodeId == null) {
        throw new IllegalArgumentException("Attempted to merge Status request but could not find the appropriate Node Identifier");
    }
    final NodePortStatusSnapshotDTO selectedNodeSnapshot = new NodePortStatusSnapshotDTO();
    selectedNodeSnapshot.setStatusSnapshot(mergedPortStatus.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedPortStatus.getNodeSnapshots().add(selectedNodeSnapshot);
    // merge the other nodes
    for (final Map.Entry<NodeIdentifier, PortStatusEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final PortStatusEntity nodePortStatusEntity = entry.getValue();
        final PortStatusDTO nodePortStatus = nodePortStatusEntity.getPortStatus();
        if (nodePortStatus == mergedPortStatus) {
            continue;
        }
        mergeStatus(mergedPortStatus, clientEntity.getCanRead(), nodePortStatus, nodePortStatusEntity.getCanRead(), nodeId);
    }
}
Also used : PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PortStatusEntity(org.apache.nifi.web.api.entity.PortStatusEntity) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) NodePortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO) 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) NodePortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO) PortStatusEntity(org.apache.nifi.web.api.entity.PortStatusEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) Map(java.util.Map)

Aggregations

PortStatusEntity (org.apache.nifi.web.api.entity.PortStatusEntity)4 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 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 ComponentEntityStatusMerger (org.apache.nifi.cluster.manager.ComponentEntityStatusMerger)1 StatusMerger (org.apache.nifi.cluster.manager.StatusMerger)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 NodePortStatusSnapshotDTO (org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO)1 PortStatusDTO (org.apache.nifi.web.api.dto.status.PortStatusDTO)1