Search in sources :

Example 1 with ControllerBulletinsEntity

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

the class StandardNiFiServiceFacade method getControllerBulletins.

@Override
public ControllerBulletinsEntity getControllerBulletins() {
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final ControllerBulletinsEntity controllerBulletinsEntity = new ControllerBulletinsEntity();
    final List<BulletinEntity> controllerBulletinEntities = new ArrayList<>();
    final Authorizable controllerAuthorizable = authorizableLookup.getController();
    final boolean authorized = controllerAuthorizable.isAuthorized(authorizer, RequestAction.READ, user);
    final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForController());
    controllerBulletinEntities.addAll(bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, authorized)).collect(Collectors.toList()));
    // get the controller service bulletins
    final BulletinQuery controllerServiceQuery = new BulletinQuery.Builder().sourceType(ComponentType.CONTROLLER_SERVICE).build();
    final List<Bulletin> allControllerServiceBulletins = bulletinRepository.findBulletins(controllerServiceQuery);
    final List<BulletinEntity> controllerServiceBulletinEntities = new ArrayList<>();
    for (final Bulletin bulletin : allControllerServiceBulletins) {
        try {
            final Authorizable controllerServiceAuthorizable = authorizableLookup.getControllerService(bulletin.getSourceId()).getAuthorizable();
            final boolean controllerServiceAuthorized = controllerServiceAuthorizable.isAuthorized(authorizer, RequestAction.READ, user);
            final BulletinEntity controllerServiceBulletin = entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin), controllerServiceAuthorized);
            controllerServiceBulletinEntities.add(controllerServiceBulletin);
            controllerBulletinEntities.add(controllerServiceBulletin);
        } catch (final ResourceNotFoundException e) {
        // controller service missing.. skip
        }
    }
    controllerBulletinsEntity.setControllerServiceBulletins(controllerServiceBulletinEntities);
    // get the reporting task bulletins
    final BulletinQuery reportingTaskQuery = new BulletinQuery.Builder().sourceType(ComponentType.REPORTING_TASK).build();
    final List<Bulletin> allReportingTaskBulletins = bulletinRepository.findBulletins(reportingTaskQuery);
    final List<BulletinEntity> reportingTaskBulletinEntities = new ArrayList<>();
    for (final Bulletin bulletin : allReportingTaskBulletins) {
        try {
            final Authorizable reportingTaskAuthorizable = authorizableLookup.getReportingTask(bulletin.getSourceId()).getAuthorizable();
            final boolean reportingTaskAuthorizableAuthorized = reportingTaskAuthorizable.isAuthorized(authorizer, RequestAction.READ, user);
            final BulletinEntity reportingTaskBulletin = entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin), reportingTaskAuthorizableAuthorized);
            reportingTaskBulletinEntities.add(reportingTaskBulletin);
            controllerBulletinEntities.add(reportingTaskBulletin);
        } catch (final ResourceNotFoundException e) {
        // reporting task missing.. skip
        }
    }
    controllerBulletinsEntity.setReportingTaskBulletins(reportingTaskBulletinEntities);
    controllerBulletinsEntity.setBulletins(pruneAndSortBulletins(controllerBulletinEntities, BulletinRepository.MAX_BULLETINS_FOR_CONTROLLER));
    return controllerBulletinsEntity;
}
Also used : ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) BulletinQuery(org.apache.nifi.reporting.BulletinQuery) ArrayList(java.util.ArrayList) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Bulletin(org.apache.nifi.reporting.Bulletin) Authorizable(org.apache.nifi.authorization.resource.Authorizable) BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO)

Example 2 with ControllerBulletinsEntity

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

the class ControllerBulletinsEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ControllerBulletinsEntity clientEntity, Map<NodeIdentifier, ControllerBulletinsEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final Map<NodeIdentifier, List<BulletinEntity>> bulletinDtos = new HashMap<>();
    final Map<NodeIdentifier, List<BulletinEntity>> controllerServiceBulletinDtos = new HashMap<>();
    final Map<NodeIdentifier, List<BulletinEntity>> reportingTaskBulletinDtos = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, ControllerBulletinsEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeIdentifier = entry.getKey();
        final ControllerBulletinsEntity entity = entry.getValue();
        final String nodeAddress = nodeIdentifier.getApiAddress() + ":" + nodeIdentifier.getApiPort();
        // consider the bulletins if present and authorized
        if (entity.getBulletins() != null) {
            entity.getBulletins().forEach(bulletin -> {
                if (bulletin.getNodeAddress() == null) {
                    bulletin.setNodeAddress(nodeAddress);
                }
                bulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
            });
        }
        if (entity.getControllerServiceBulletins() != null) {
            entity.getControllerServiceBulletins().forEach(bulletin -> {
                if (bulletin.getNodeAddress() == null) {
                    bulletin.setNodeAddress(nodeAddress);
                }
                controllerServiceBulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
            });
        }
        if (entity.getReportingTaskBulletins() != null) {
            entity.getReportingTaskBulletins().forEach(bulletin -> {
                if (bulletin.getNodeAddress() == null) {
                    bulletin.setNodeAddress(nodeAddress);
                }
                reportingTaskBulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
            });
        }
    }
    clientEntity.setBulletins(BulletinMerger.mergeBulletins(bulletinDtos, entityMap.size()));
    clientEntity.setControllerServiceBulletins(BulletinMerger.mergeBulletins(controllerServiceBulletinDtos, entityMap.size()));
    clientEntity.setReportingTaskBulletins(BulletinMerger.mergeBulletins(reportingTaskBulletinDtos, entityMap.size()));
    // sort the bulletins
    Collections.sort(clientEntity.getBulletins(), BULLETIN_COMPARATOR);
    Collections.sort(clientEntity.getControllerServiceBulletins(), BULLETIN_COMPARATOR);
    Collections.sort(clientEntity.getReportingTaskBulletins(), BULLETIN_COMPARATOR);
    // prune the response to only include the max number of bulletins
    if (clientEntity.getBulletins().size() > MAX_BULLETINS_FOR_CONTROLLER) {
        clientEntity.setBulletins(clientEntity.getBulletins().subList(0, MAX_BULLETINS_FOR_CONTROLLER));
    }
    if (clientEntity.getControllerServiceBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
        clientEntity.setControllerServiceBulletins(clientEntity.getControllerServiceBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
    }
    if (clientEntity.getReportingTaskBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
        clientEntity.setReportingTaskBulletins(clientEntity.getReportingTaskBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
    }
}
Also used : ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) BULLETIN_COMPARATOR(org.apache.nifi.cluster.manager.BulletinMerger.BULLETIN_COMPARATOR) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Set(java.util.Set) HashMap(java.util.HashMap) EndpointResponseMerger(org.apache.nifi.cluster.coordination.http.EndpointResponseMerger) ArrayList(java.util.ArrayList) List(java.util.List) BulletinMerger(org.apache.nifi.cluster.manager.BulletinMerger) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Map(java.util.Map) MAX_BULLETINS_PER_COMPONENT(org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_PER_COMPONENT) URI(java.net.URI) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) MAX_BULLETINS_FOR_CONTROLLER(org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_FOR_CONTROLLER) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ControllerBulletinsEntity

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

the class FlowResource method getBulletins.

/**
 * Retrieves the controller level bulletins.
 *
 * @return A controllerBulletinsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("controller/bulletins")
@ApiOperation(value = "Retrieves Controller level bulletins", response = ControllerBulletinsEntity.class, authorizations = { @Authorization(value = "Read - /flow"), @Authorization(value = "Read - /controller - For controller bulletins"), @Authorization(value = "Read - /controller-services/{uuid} - For controller service bulletins"), @Authorization(value = "Read - /reporting-tasks/{uuid} - For reporting task bulletins") })
@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 getBulletins() {
    authorizeFlow();
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    final ControllerBulletinsEntity entity = serviceFacade.getControllerBulletins();
    return generateOkResponse(entity).build();
}
Also used : ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) 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

ControllerBulletinsEntity (org.apache.nifi.web.api.entity.ControllerBulletinsEntity)3 ArrayList (java.util.ArrayList)2 BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)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 Authorizable (org.apache.nifi.authorization.resource.Authorizable)1 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)1 EndpointResponseMerger (org.apache.nifi.cluster.coordination.http.EndpointResponseMerger)1 BulletinMerger (org.apache.nifi.cluster.manager.BulletinMerger)1