Java Code Examples for org.apache.nifi.reporting.Bulletin#getSourceType()

The following examples show how to use org.apache.nifi.reporting.Bulletin#getSourceType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private boolean authorizeBulletin(final Bulletin bulletin) {
    final String sourceId = bulletin.getSourceId();
    final ComponentType type = bulletin.getSourceType();

    final Authorizable authorizable;
    try {
        switch (type) {
            case PROCESSOR:
                authorizable = authorizableLookup.getProcessor(sourceId).getAuthorizable();
                break;
            case REPORTING_TASK:
                authorizable = authorizableLookup.getReportingTask(sourceId).getAuthorizable();
                break;
            case CONTROLLER_SERVICE:
                authorizable = authorizableLookup.getControllerService(sourceId).getAuthorizable();
                break;
            case FLOW_CONTROLLER:
                authorizable = controllerFacade;
                break;
            case INPUT_PORT:
                authorizable = authorizableLookup.getInputPort(sourceId);
                break;
            case OUTPUT_PORT:
                authorizable = authorizableLookup.getOutputPort(sourceId);
                break;
            case REMOTE_PROCESS_GROUP:
                authorizable = authorizableLookup.getRemoteProcessGroup(sourceId);
                break;
            default:
                throw new WebApplicationException(Response.serverError().entity("An unexpected type of component is the source of this bulletin.").build());
        }
    } catch (final ResourceNotFoundException e) {
        // if the underlying component is gone, disallow
        return false;
    }

    // perform the authorization
    final AuthorizationResult result = authorizable.checkAuthorization(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    return Result.Approved.equals(result.getResult());
}
 
Example 2
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private String getBulletinStoreKey(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
            return CONTROLLER_BULLETIN_STORE_KEY;
        case CONTROLLER_SERVICE:
            return SERVICE_BULLETIN_STORE_KEY;
        case REPORTING_TASK:
            return REPORTING_TASK_BULLETIN_STORE_KEY;
        default:
            return bulletin.getGroupId();
    }
}
 
Example 3
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private boolean isControllerBulletin(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
        case CONTROLLER_SERVICE:
        case REPORTING_TASK:
            return true;
        default:
            return false;
    }
}
 
Example 4
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 5 votes vote down vote up
private String getBulletinStoreKey(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
            return CONTROLLER_BULLETIN_STORE_KEY;
        case CONTROLLER_SERVICE:
            return SERVICE_BULLETIN_STORE_KEY;
        case REPORTING_TASK:
            return REPORTING_TASK_BULLETIN_STORE_KEY;
        default:
            return bulletin.getGroupId();
    }
}
 
Example 5
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 5 votes vote down vote up
private boolean isControllerBulletin(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
        case CONTROLLER_SERVICE:
        case REPORTING_TASK:
            return true;
        default:
            return false;
    }
}
 
Example 6
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(final BulletinQuery bulletinQuery) {
    final Filter<Bulletin> filter = new Filter<Bulletin>() {
        @Override
        public boolean select(final Bulletin bulletin) {
            final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);
            if (bulletin.getTimestamp().getTime() < fiveMinutesAgo) {
                return false;
            }

            // only include bulletins after the specified id
            if (bulletinQuery.getAfter() != null && bulletin.getId() <= bulletinQuery.getAfter()) {
                return false;
            }

            // if group pattern was specified see if it should be excluded
            if (bulletinQuery.getGroupIdPattern() != null) {
                // exclude if this bulletin doesnt have a group or if it doesnt match
                if (bulletin.getGroupId() == null || !bulletinQuery.getGroupIdPattern().matcher(bulletin.getGroupId()).find()) {
                    return false;
                }
            }

            // if a message pattern was specified see if it should be excluded
            if (bulletinQuery.getMessagePattern() != null) {
                // exclude if this bulletin doesnt have a message or if it doesnt match
                if (bulletin.getMessage() == null || !bulletinQuery.getMessagePattern().matcher(bulletin.getMessage()).find()) {
                    return false;
                }
            }

            // if a name pattern was specified see if it should be excluded
            if (bulletinQuery.getNamePattern() != null) {
                // exclude if this bulletin doesnt have a source name or if it doesnt match
                if (bulletin.getSourceName() == null || !bulletinQuery.getNamePattern().matcher(bulletin.getSourceName()).find()) {
                    return false;
                }
            }

            // if a source id was specified see if it should be excluded
            if (bulletinQuery.getSourceIdPattern() != null) {
                // exclude if this bulletin doesn't have a source id or if it doesn't match
                if (bulletin.getSourceId() == null || !bulletinQuery.getSourceIdPattern().matcher(bulletin.getSourceId()).find()) {
                    return false;
                }
            }

            // if a source component type was specified see if it should be excluded
            if (bulletinQuery.getSourceType() != null) {
                // exclude if this bulletin source type doesn't match
                if (bulletin.getSourceType() == null || !bulletinQuery.getSourceType().equals(bulletin.getSourceType())) {
                    return false;
                }
            }

            return true;
        }
    };

    final List<Bulletin> selected = new ArrayList<>();
    int max = bulletinQuery.getLimit() == null ? Integer.MAX_VALUE : bulletinQuery.getLimit();

    for (final ConcurrentMap<String, RingBuffer<Bulletin>> componentMap : bulletinStoreMap.values()) {
        for (final RingBuffer<Bulletin> ringBuffer : componentMap.values()) {
            final List<Bulletin> bulletinsForComponent = ringBuffer.getSelectedElements(filter, max);
            selected.addAll(bulletinsForComponent);
            max -= bulletinsForComponent.size();
            if (max <= 0) {
                break;
            }
        }
    }

    // sort by descending ID
    Collections.sort(selected);

    return selected;
}
 
Example 7
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(final BulletinQuery bulletinQuery) {
    final Filter<Bulletin> filter = new Filter<Bulletin>() {
        @Override
        public boolean select(final Bulletin bulletin) {
            final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);
            if (bulletin.getTimestamp().getTime() < fiveMinutesAgo) {
                return false;
            }

            // only include bulletins after the specified id
            if (bulletinQuery.getAfter() != null && bulletin.getId() <= bulletinQuery.getAfter()) {
                return false;
            }

            // if group pattern was specified see if it should be excluded
            if (bulletinQuery.getGroupIdPattern() != null) {
                // exclude if this bulletin doesnt have a group or if it doesnt match
                if (bulletin.getGroupId() == null || !bulletinQuery.getGroupIdPattern().matcher(bulletin.getGroupId()).find()) {
                    return false;
                }
            }

            // if a message pattern was specified see if it should be excluded
            if (bulletinQuery.getMessagePattern() != null) {
                // exclude if this bulletin doesnt have a message or if it doesnt match
                if (bulletin.getMessage() == null || !bulletinQuery.getMessagePattern().matcher(bulletin.getMessage()).find()) {
                    return false;
                }
            }

            // if a name pattern was specified see if it should be excluded
            if (bulletinQuery.getNamePattern() != null) {
                // exclude if this bulletin doesnt have a source name or if it doesnt match
                if (bulletin.getSourceName() == null || !bulletinQuery.getNamePattern().matcher(bulletin.getSourceName()).find()) {
                    return false;
                }
            }

            // if a source id was specified see if it should be excluded
            if (bulletinQuery.getSourceIdPattern() != null) {
                // exclude if this bulletin doesn't have a source id or if it doesn't match
                if (bulletin.getSourceId() == null || !bulletinQuery.getSourceIdPattern().matcher(bulletin.getSourceId()).find()) {
                    return false;
                }
            }

            // if a source component type was specified see if it should be excluded
            if (bulletinQuery.getSourceType() != null) {
                // exclude if this bulletin source type doesn't match
                if (bulletin.getSourceType() == null || !bulletinQuery.getSourceType().equals(bulletin.getSourceType())) {
                    return false;
                }
            }

            return true;
        }
    };

    final Set<Bulletin> selected = new TreeSet<>();
    int max = bulletinQuery.getLimit() == null ? Integer.MAX_VALUE : bulletinQuery.getLimit();

    for (final ConcurrentMap<String, RingBuffer<Bulletin>> componentMap : bulletinStoreMap.values()) {
        for (final RingBuffer<Bulletin> ringBuffer : componentMap.values()) {
            final List<Bulletin> bulletinsForComponent = ringBuffer.getSelectedElements(filter, max);
            selected.addAll(bulletinsForComponent);
            max -= bulletinsForComponent.size();
            if (max <= 0) {
                break;
            }
        }
    }

    return new ArrayList<>(selected);
}