Search in sources :

Example 1 with StatusHistoryEntity

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

the class FlowResource method getRemoteProcessGroupStatusHistory.

/**
 * Retrieves the specified remote process groups status history.
 *
 * @param id The id of the remote process group to retrieve the status fow.
 * @return A statusHistoryEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("remote-process-groups/{id}/status/history")
@ApiOperation(value = "Gets the status history", response = StatusHistoryEntity.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 getRemoteProcessGroupStatusHistory(@ApiParam(value = "The remote process group id.", required = true) @PathParam("id") String id) throws InterruptedException {
    authorizeFlow();
    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // get the specified processor status history
    final StatusHistoryEntity entity = serviceFacade.getRemoteProcessGroupStatusHistory(id);
    return generateOkResponse(entity).build();
}
Also used : StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) 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 StatusHistoryEntity

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

the class EntityFactory method createStatusHistoryEntity.

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

Example 3 with StatusHistoryEntity

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

the class StatusHistoryEndpointMerger method merge.

@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, NodeResponse clientResponse) {
    final Map<String, MetricDescriptor<?>> metricDescriptors = getStandardMetricDescriptors(uri);
    final StatusHistoryEntity responseEntity = clientResponse.getClientResponse().readEntity(StatusHistoryEntity.class);
    final Set<StatusDescriptorDTO> fieldDescriptors = new LinkedHashSet<>();
    boolean includeCounters = true;
    StatusHistoryDTO lastStatusHistory = null;
    final List<NodeStatusSnapshotsDTO> nodeStatusSnapshots = new ArrayList<>(successfulResponses.size());
    LinkedHashMap<String, String> noReadPermissionsComponentDetails = null;
    for (final NodeResponse nodeResponse : successfulResponses) {
        final StatusHistoryEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(StatusHistoryEntity.class);
        final StatusHistoryDTO nodeStatus = nodeResponseEntity.getStatusHistory();
        lastStatusHistory = nodeStatus;
        if (noReadPermissionsComponentDetails == null && !nodeResponseEntity.getCanRead()) {
            // If component details from a history with no read permissions is encountered for the first time, hold on to them to be used in the merged response
            noReadPermissionsComponentDetails = nodeStatus.getComponentDetails();
        }
        if (!Boolean.TRUE.equals(nodeResponseEntity.getCanRead())) {
            includeCounters = false;
        }
        final NodeIdentifier nodeId = nodeResponse.getNodeId();
        final NodeStatusSnapshotsDTO nodeStatusSnapshot = new NodeStatusSnapshotsDTO();
        nodeStatusSnapshot.setNodeId(nodeId.getId());
        nodeStatusSnapshot.setAddress(nodeId.getApiAddress());
        nodeStatusSnapshot.setApiPort(nodeId.getApiPort());
        nodeStatusSnapshot.setStatusSnapshots(nodeStatus.getAggregateSnapshots());
        nodeStatusSnapshots.add(nodeStatusSnapshot);
        final List<StatusDescriptorDTO> descriptors = nodeStatus.getFieldDescriptors();
        if (descriptors != null) {
            fieldDescriptors.addAll(descriptors);
        }
    }
    // the user is not authorized, we want to assume that the user is, in fact, not authorized.
    if (includeCounters) {
        for (final StatusDescriptorDTO descriptorDto : fieldDescriptors) {
            final String fieldName = descriptorDto.getField();
            if (!metricDescriptors.containsKey(fieldName)) {
                final ValueMapper<ProcessorStatus> valueMapper = s -> {
                    final Map<String, Long> counters = s.getCounters();
                    if (counters == null) {
                        return 0L;
                    }
                    return counters.getOrDefault(descriptorDto.getField(), 0L);
                };
                final MetricDescriptor<ProcessorStatus> metricDescriptor = new StandardMetricDescriptor<>(descriptorDto.getField(), descriptorDto.getLabel(), descriptorDto.getDescription(), Formatter.COUNT, valueMapper);
                metricDescriptors.put(fieldName, metricDescriptor);
            }
        }
    }
    final StatusHistoryDTO clusterStatusHistory = new StatusHistoryDTO();
    clusterStatusHistory.setAggregateSnapshots(mergeStatusHistories(nodeStatusSnapshots, metricDescriptors));
    clusterStatusHistory.setGenerated(new Date());
    clusterStatusHistory.setNodeSnapshots(nodeStatusSnapshots);
    if (lastStatusHistory != null) {
        clusterStatusHistory.setComponentDetails(noReadPermissionsComponentDetails == null ? lastStatusHistory.getComponentDetails() : noReadPermissionsComponentDetails);
    }
    clusterStatusHistory.setFieldDescriptors(new ArrayList<>(fieldDescriptors));
    final StatusHistoryEntity clusterEntity = new StatusHistoryEntity();
    clusterEntity.setStatusHistory(clusterStatusHistory);
    clusterEntity.setCanRead(noReadPermissionsComponentDetails == null);
    return new NodeResponse(clientResponse, clusterEntity);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) ValueMapper(org.apache.nifi.controller.status.history.ValueMapper) StatusSnapshotDTO(org.apache.nifi.web.api.dto.status.StatusSnapshotDTO) Date(java.util.Date) HashMap(java.util.HashMap) StandardMetricDescriptor(org.apache.nifi.controller.status.history.StandardMetricDescriptor) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ProcessorStatusDescriptor(org.apache.nifi.controller.status.history.ProcessorStatusDescriptor) URI(java.net.URI) RemoteProcessGroupStatusDescriptor(org.apache.nifi.controller.status.history.RemoteProcessGroupStatusDescriptor) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) LinkedHashSet(java.util.LinkedHashSet) Formatter(org.apache.nifi.controller.status.history.MetricDescriptor.Formatter) StatusHistoryUtil(org.apache.nifi.controller.status.history.StatusHistoryUtil) StatusSnapshot(org.apache.nifi.controller.status.history.StatusSnapshot) StandardStatusSnapshot(org.apache.nifi.controller.status.history.StandardStatusSnapshot) Set(java.util.Set) EndpointResponseMerger(org.apache.nifi.cluster.coordination.http.EndpointResponseMerger) List(java.util.List) TreeMap(java.util.TreeMap) MetricDescriptor(org.apache.nifi.controller.status.history.MetricDescriptor) ConnectionStatusDescriptor(org.apache.nifi.controller.status.history.ConnectionStatusDescriptor) ProcessGroupStatusDescriptor(org.apache.nifi.controller.status.history.ProcessGroupStatusDescriptor) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) NodeStatusSnapshotsDTO(org.apache.nifi.web.api.dto.status.NodeStatusSnapshotsDTO) Pattern(java.util.regex.Pattern) StatusDescriptorDTO(org.apache.nifi.web.api.dto.status.StatusDescriptorDTO) NodeStatusSnapshotsDTO(org.apache.nifi.web.api.dto.status.NodeStatusSnapshotsDTO) ArrayList(java.util.ArrayList) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Date(java.util.Date) StatusDescriptorDTO(org.apache.nifi.web.api.dto.status.StatusDescriptorDTO) StandardMetricDescriptor(org.apache.nifi.controller.status.history.StandardMetricDescriptor) MetricDescriptor(org.apache.nifi.controller.status.history.MetricDescriptor) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) StandardMetricDescriptor(org.apache.nifi.controller.status.history.StandardMetricDescriptor) StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with StatusHistoryEntity

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

the class FlowResource method getProcessGroupStatusHistory.

/**
 * Retrieves the specified remote process groups status history.
 *
 * @param groupId The group id
 * @return A processorEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("process-groups/{id}/status/history")
@ApiOperation(value = "Gets status history for a remote process group", response = StatusHistoryEntity.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 getProcessGroupStatusHistory(@ApiParam(value = "The process group id.", required = true) @PathParam("id") String groupId) throws InterruptedException {
    authorizeFlow();
    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // get the specified processor status history
    final StatusHistoryEntity entity = serviceFacade.getProcessGroupStatusHistory(groupId);
    return generateOkResponse(entity).build();
}
Also used : StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) 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 5 with StatusHistoryEntity

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

the class FlowResource method getProcessorStatusHistory.

// --------------
// status history
// --------------
/**
 * Retrieves the specified processor status history.
 *
 * @param id The id of the processor history to retrieve.
 * @return A statusHistoryEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("processors/{id}/status/history")
@ApiOperation(value = "Gets status history for a processor", response = StatusHistoryEntity.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 getProcessorStatusHistory(@ApiParam(value = "The processor id.", required = true) @PathParam("id") String id) throws InterruptedException {
    authorizeFlow();
    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // get the specified processor status history
    final StatusHistoryEntity entity = serviceFacade.getProcessorStatusHistory(id);
    return generateOkResponse(entity).build();
}
Also used : StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) 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

StatusHistoryEntity (org.apache.nifi.web.api.entity.StatusHistoryEntity)6 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Consumes (javax.ws.rs.Consumes)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Pattern (java.util.regex.Pattern)1 EndpointResponseMerger (org.apache.nifi.cluster.coordination.http.EndpointResponseMerger)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1