Search in sources :

Example 1 with ReportingTasksEntity

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

the class ReportingTasksEndpointMerger method merge.

@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
    if (!canHandle(uri, method)) {
        throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
    }
    final ReportingTasksEntity responseEntity = clientResponse.getClientResponse().readEntity(ReportingTasksEntity.class);
    final Set<ReportingTaskEntity> reportingTasksEntities = responseEntity.getReportingTasks();
    final Map<String, Map<NodeIdentifier, ReportingTaskEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final ReportingTasksEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ReportingTasksEntity.class);
        final Set<ReportingTaskEntity> nodeReportingTaskEntities = nodeResponseEntity.getReportingTasks();
        for (final ReportingTaskEntity nodeReportingTaskEntity : nodeReportingTaskEntities) {
            final NodeIdentifier nodeId = nodeResponse.getNodeId();
            Map<NodeIdentifier, ReportingTaskEntity> innerMap = entityMap.get(nodeId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodeReportingTaskEntity.getId(), innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodeReportingTaskEntity);
        }
    }
    ReportingTasksEntityMerger.mergeReportingTasks(reportingTasksEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : ReportingTasksEntity(org.apache.nifi.web.api.entity.ReportingTasksEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) Map(java.util.Map) HashMap(java.util.HashMap) ReportingTaskEntity(org.apache.nifi.web.api.entity.ReportingTaskEntity)

Example 2 with ReportingTasksEntity

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

the class FlowResource method getReportingTasks.

// ---------------
// reporting-tasks
// ---------------
/**
 * Retrieves all the of reporting tasks in this NiFi.
 *
 * @return A reportingTasksEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("reporting-tasks")
@ApiOperation(value = "Gets all reporting tasks", response = ReportingTasksEntity.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 getReportingTasks() {
    authorizeFlow();
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // get all the reporting tasks
    final Set<ReportingTaskEntity> reportingTasks = serviceFacade.getReportingTasks();
    reportingTaskResource.populateRemainingReportingTaskEntitiesContent(reportingTasks);
    // create the response entity
    final ReportingTasksEntity entity = new ReportingTasksEntity();
    entity.setReportingTasks(reportingTasks);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ReportingTasksEntity(org.apache.nifi.web.api.entity.ReportingTasksEntity) ReportingTaskEntity(org.apache.nifi.web.api.entity.ReportingTaskEntity) 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

ReportingTaskEntity (org.apache.nifi.web.api.entity.ReportingTaskEntity)2 ReportingTasksEntity (org.apache.nifi.web.api.entity.ReportingTasksEntity)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 Map (java.util.Map)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 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1