Search in sources :

Example 1 with ComponentStateDTO

use of org.apache.nifi.web.api.dto.ComponentStateDTO in project nifi by apache.

the class ComponentStateEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ComponentStateDTO clientDto, Map<NodeIdentifier, ComponentStateDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    List<StateEntryDTO> localStateEntries = new ArrayList<>();
    int totalStateEntries = 0;
    for (final Map.Entry<NodeIdentifier, ComponentStateDTO> nodeEntry : dtoMap.entrySet()) {
        final ComponentStateDTO nodeComponentState = nodeEntry.getValue();
        final NodeIdentifier nodeId = nodeEntry.getKey();
        final String nodeAddress = nodeId.getApiAddress() + ":" + nodeId.getApiPort();
        final StateMapDTO nodeLocalStateMap = nodeComponentState.getLocalState();
        if (nodeLocalStateMap.getState() != null) {
            totalStateEntries += nodeLocalStateMap.getTotalEntryCount();
            for (final StateEntryDTO nodeStateEntry : nodeLocalStateMap.getState()) {
                if (nodeStateEntry.getClusterNodeId() == null || nodeStateEntry.getClusterNodeAddress() == null) {
                    nodeStateEntry.setClusterNodeId(nodeId.getId());
                    nodeStateEntry.setClusterNodeAddress(nodeAddress);
                }
                localStateEntries.add(nodeStateEntry);
            }
        }
    }
    // ensure appropriate sort
    Collections.sort(localStateEntries, SortedStateUtils.getEntryDtoComparator());
    // sublist if necessary
    if (localStateEntries.size() > SortedStateUtils.MAX_COMPONENT_STATE_ENTRIES) {
        localStateEntries = localStateEntries.subList(0, SortedStateUtils.MAX_COMPONENT_STATE_ENTRIES);
    }
    // add all the local state entries
    clientDto.getLocalState().setTotalEntryCount(totalStateEntries);
    clientDto.getLocalState().setState(localStateEntries);
}
Also used : StateEntryDTO(org.apache.nifi.web.api.dto.StateEntryDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ArrayList(java.util.ArrayList) StateMapDTO(org.apache.nifi.web.api.dto.StateMapDTO) Map(java.util.Map) ComponentStateDTO(org.apache.nifi.web.api.dto.ComponentStateDTO)

Example 2 with ComponentStateDTO

use of org.apache.nifi.web.api.dto.ComponentStateDTO in project nifi by apache.

the class ControllerServiceResource method getState.

/**
 * Gets the state for a controller service.
 *
 * @param id The id of the controller service
 * @return a componentStateEntity
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/state")
@ApiOperation(value = "Gets the state for a controller service", response = ComponentStateEntity.class, authorizations = { @Authorization(value = "Write - /controller-services/{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 getState(@ApiParam(value = "The controller service id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable controllerService = lookup.getControllerService(id).getAuthorizable();
        controllerService.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    });
    // get the component state
    final ComponentStateDTO state = serviceFacade.getControllerServiceState(id);
    // generate the response entity
    final ComponentStateEntity entity = new ComponentStateEntity();
    entity.setComponentState(state);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ComponentStateDTO(org.apache.nifi.web.api.dto.ComponentStateDTO) ComponentStateEntity(org.apache.nifi.web.api.entity.ComponentStateEntity) 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 ComponentStateDTO

use of org.apache.nifi.web.api.dto.ComponentStateDTO in project nifi by apache.

the class ProcessorResource method getState.

/**
 * Gets the state for a processor.
 *
 * @param id The id of the processor
 * @return a componentStateEntity
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/state")
@ApiOperation(value = "Gets the state for a processor", response = ComponentStateEntity.class, authorizations = { @Authorization(value = "Write - /processors/{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 getState(@ApiParam(value = "The processor id.", required = true) @PathParam("id") final String id) throws InterruptedException {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable processor = lookup.getProcessor(id).getAuthorizable();
        processor.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    });
    // get the component state
    final ComponentStateDTO state = serviceFacade.getProcessorState(id);
    // generate the response entity
    final ComponentStateEntity entity = new ComponentStateEntity();
    entity.setComponentState(state);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ComponentStateDTO(org.apache.nifi.web.api.dto.ComponentStateDTO) ComponentStateEntity(org.apache.nifi.web.api.entity.ComponentStateEntity) 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 4 with ComponentStateDTO

use of org.apache.nifi.web.api.dto.ComponentStateDTO in project nifi by apache.

the class ReportingTaskResource method getState.

/**
 * Gets the state for a reporting task.
 *
 * @param id The id of the reporting task
 * @return a componentStateEntity
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/state")
@ApiOperation(value = "Gets the state for a reporting task", response = ComponentStateEntity.class, authorizations = { @Authorization(value = "Write - /reporting-tasks/{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 getState(@ApiParam(value = "The reporting task id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable reportingTask = lookup.getReportingTask(id).getAuthorizable();
        reportingTask.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    });
    // get the component state
    final ComponentStateDTO state = serviceFacade.getReportingTaskState(id);
    // generate the response entity
    final ComponentStateEntity entity = new ComponentStateEntity();
    entity.setComponentState(state);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ComponentStateDTO(org.apache.nifi.web.api.dto.ComponentStateDTO) ComponentStateEntity(org.apache.nifi.web.api.entity.ComponentStateEntity) 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

ComponentStateDTO (org.apache.nifi.web.api.dto.ComponentStateDTO)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ComponentAuthorizable (org.apache.nifi.authorization.ComponentAuthorizable)3 Authorizable (org.apache.nifi.authorization.resource.Authorizable)3 ComponentStateEntity (org.apache.nifi.web.api.entity.ComponentStateEntity)3 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 StateEntryDTO (org.apache.nifi.web.api.dto.StateEntryDTO)1 StateMapDTO (org.apache.nifi.web.api.dto.StateMapDTO)1