Search in sources :

Example 1 with FunnelsEntity

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

the class ProcessGroupResource method getFunnels.

/**
 * Retrieves all the of funnels in this NiFi.
 *
 * @return A funnelsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/funnels")
@ApiOperation(value = "Gets all funnels", response = FunnelsEntity.class, authorizations = { @Authorization(value = "Read - /process-groups/{uuid}") })
@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 getFunnels(@ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });
    // get all the funnels
    final Set<FunnelEntity> funnels = serviceFacade.getFunnels(groupId);
    // create the response entity
    final FunnelsEntity entity = new FunnelsEntity();
    entity.setFunnels(funnelResource.populateRemainingFunnelEntitiesContent(funnels));
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) FunnelsEntity(org.apache.nifi.web.api.entity.FunnelsEntity) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) TemplateContentsAuthorizable(org.apache.nifi.authorization.TemplateContentsAuthorizable) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) 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 FunnelsEntity

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

the class FunnelsEndpointMerger method merge.

@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, 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 FunnelsEntity responseEntity = clientResponse.getClientResponse().readEntity(FunnelsEntity.class);
    final Set<FunnelEntity> funnelEntities = responseEntity.getFunnels();
    final Map<String, Map<NodeIdentifier, FunnelEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final FunnelsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(FunnelsEntity.class);
        final Set<FunnelEntity> nodeFunnelEntities = nodeResponseEntity.getFunnels();
        for (final FunnelEntity nodeFunnelEntity : nodeFunnelEntities) {
            final String nodeFunnelEntityId = nodeFunnelEntity.getId();
            Map<NodeIdentifier, FunnelEntity> innerMap = entityMap.get(nodeFunnelEntityId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodeFunnelEntityId, innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodeFunnelEntity);
        }
    }
    FunnelsEntityMerger.mergeFunnels(funnelEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) FunnelsEntity(org.apache.nifi.web.api.entity.FunnelsEntity) 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)

Aggregations

FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)2 FunnelsEntity (org.apache.nifi.web.api.entity.FunnelsEntity)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 ComponentAuthorizable (org.apache.nifi.authorization.ComponentAuthorizable)1 ProcessGroupAuthorizable (org.apache.nifi.authorization.ProcessGroupAuthorizable)1 SnippetAuthorizable (org.apache.nifi.authorization.SnippetAuthorizable)1 TemplateContentsAuthorizable (org.apache.nifi.authorization.TemplateContentsAuthorizable)1 Authorizable (org.apache.nifi.authorization.resource.Authorizable)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1