Search in sources :

Example 21 with Bulletin

use of org.apache.nifi.reporting.Bulletin in project nifi by apache.

the class ControllerServiceLogObserver method onLogMessage.

@Override
public void onLogMessage(final LogMessage message) {
    // Map LogLevel.WARN to Severity.WARNING so that we are consistent with the Severity enumeration. Else, just use whatever
    // the LogLevel is (INFO and ERROR map directly and all others we will just accept as they are).
    final String bulletinLevel = message.getLevel() == LogLevel.WARN ? Severity.WARNING.name() : message.getLevel().toString();
    final ProcessGroup pg = serviceNode.getProcessGroup();
    final String groupId = pg == null ? null : pg.getIdentifier();
    final String groupName = pg == null ? null : pg.getName();
    final Bulletin bulletin = BulletinFactory.createBulletin(groupId, groupName, serviceNode.getIdentifier(), ComponentType.CONTROLLER_SERVICE, serviceNode.getName(), "Log Message", bulletinLevel, message.getMessage());
    bulletinRepository.addBulletin(bulletin);
}
Also used : Bulletin(org.apache.nifi.reporting.Bulletin) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 22 with Bulletin

use of org.apache.nifi.reporting.Bulletin in project nifi by apache.

the class SocketProtocolListener method dispatchRequest.

@Override
public void dispatchRequest(final Socket socket) {
    String hostname = null;
    try {
        final StopWatch stopWatch = new StopWatch(true);
        hostname = socket.getInetAddress().getHostName();
        final String requestId = UUID.randomUUID().toString();
        logger.debug("Received request {} from {}", requestId, hostname);
        String requestorDn = getRequestorDN(socket);
        // unmarshall message
        final ProtocolMessageUnmarshaller<ProtocolMessage> unmarshaller = protocolContext.createUnmarshaller();
        final ByteCountingInputStream countingIn = new ByteCountingInputStream(socket.getInputStream());
        InputStream wrappedInStream = countingIn;
        if (logger.isDebugEnabled()) {
            // don't buffer more than 1 MB of the message
            final int maxMsgBuffer = 1024 * 1024;
            final CopyingInputStream copyingInputStream = new CopyingInputStream(wrappedInStream, maxMsgBuffer);
            wrappedInStream = copyingInputStream;
        }
        final ProtocolMessage request;
        try {
            request = unmarshaller.unmarshal(wrappedInStream);
        } finally {
            if (logger.isDebugEnabled() && wrappedInStream instanceof CopyingInputStream) {
                final CopyingInputStream copyingInputStream = (CopyingInputStream) wrappedInStream;
                byte[] receivedMessage = copyingInputStream.getBytesRead();
                logger.debug("Received message: " + new String(receivedMessage));
            }
        }
        request.setRequestorDN(requestorDn);
        // dispatch message to handler
        ProtocolHandler desiredHandler = null;
        final Collection<ProtocolHandler> handlers = getHandlers();
        for (final ProtocolHandler handler : handlers) {
            if (handler.canHandle(request)) {
                desiredHandler = handler;
                break;
            }
        }
        // if no handler found, throw exception; otherwise handle request
        if (desiredHandler == null) {
            logger.error("Received request of type {} but none of the following Protocol Handlers were able to process the request: {}", request.getType(), handlers);
            throw new ProtocolException("No handler assigned to handle message type: " + request.getType());
        } else {
            final ProtocolMessage response = desiredHandler.handle(request);
            if (response != null) {
                try {
                    logger.debug("Sending response for request {}", requestId);
                    // marshal message to output stream
                    final ProtocolMessageMarshaller<ProtocolMessage> marshaller = protocolContext.createMarshaller();
                    marshaller.marshal(response, socket.getOutputStream());
                } catch (final IOException ioe) {
                    throw new ProtocolException("Failed marshalling protocol message in response to message type: " + request.getType() + " due to " + ioe, ioe);
                }
            }
        }
        stopWatch.stop();
        final NodeIdentifier nodeId = getNodeIdentifier(request);
        final String from = nodeId == null ? hostname : nodeId.toString();
        logger.info("Finished processing request {} (type={}, length={} bytes) from {} in {}", requestId, request.getType(), countingIn.getBytesRead(), from, stopWatch.getDuration());
    } catch (final IOException | ProtocolException e) {
        logger.warn("Failed processing protocol message from " + hostname + " due to " + e, e);
        if (bulletinRepository != null) {
            final Bulletin bulletin = BulletinFactory.createBulletin("Clustering", "WARNING", String.format("Failed to process protocol message from %s due to: %s", hostname, e.toString()));
            bulletinRepository.addBulletin(bulletin);
        }
    }
}
Also used : ProtocolException(org.apache.nifi.cluster.protocol.ProtocolException) ByteCountingInputStream(org.apache.nifi.stream.io.ByteCountingInputStream) InputStream(java.io.InputStream) ByteCountingInputStream(org.apache.nifi.stream.io.ByteCountingInputStream) IOException(java.io.IOException) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) StopWatch(org.apache.nifi.util.StopWatch) ProtocolHandler(org.apache.nifi.cluster.protocol.ProtocolHandler) Bulletin(org.apache.nifi.reporting.Bulletin) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier)

Example 23 with Bulletin

use of org.apache.nifi.reporting.Bulletin in project nifi-minifi by apache.

the class StatusRequestParser method transformBulletins.

private static List<BulletinStatus> transformBulletins(List<Bulletin> bulletinList) {
    List<BulletinStatus> bulletinStatusList = new LinkedList<>();
    if (!bulletinList.isEmpty()) {
        for (Bulletin bulletin : bulletinList) {
            BulletinStatus bulletinStatus = new BulletinStatus();
            bulletinStatus.setMessage(bulletin.getMessage());
            bulletinStatus.setTimestamp(bulletin.getTimestamp());
            bulletinStatusList.add(bulletinStatus);
        }
    }
    return bulletinStatusList;
}
Also used : Bulletin(org.apache.nifi.reporting.Bulletin) BulletinStatus(org.apache.nifi.minifi.commons.status.common.BulletinStatus) LinkedList(java.util.LinkedList)

Example 24 with Bulletin

use of org.apache.nifi.reporting.Bulletin in project nifi-minifi by apache.

the class StatusRequestParser method parseControllerServiceStatusRequest.

static ControllerServiceStatus parseControllerServiceStatusRequest(ControllerServiceNode controllerServiceNode, String statusTypes, FlowController flowController, Logger logger) {
    ControllerServiceStatus controllerServiceStatus = new ControllerServiceStatus();
    String id = controllerServiceNode.getIdentifier();
    controllerServiceStatus.setName(id);
    String[] statusSplits = statusTypes.split(",");
    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(new BulletinQuery.Builder().sourceIdMatches(id).build());
    for (String statusType : statusSplits) {
        switch(statusType.toLowerCase().trim()) {
            case "health":
                ControllerServiceHealth controllerServiceHealth = new ControllerServiceHealth();
                controllerServiceHealth.setState(controllerServiceNode.getState().name());
                controllerServiceHealth.setHasBulletins(!bulletinList.isEmpty());
                Collection<ValidationResult> validationResults = controllerServiceNode.getValidationErrors();
                controllerServiceHealth.setValidationErrorList(transformValidationResults(validationResults));
                controllerServiceStatus.setControllerServiceHealth(controllerServiceHealth);
                break;
            case "bulletins":
                controllerServiceStatus.setBulletinList(transformBulletins(bulletinList));
                break;
        }
    }
    return controllerServiceStatus;
}
Also used : ControllerServiceHealth(org.apache.nifi.minifi.commons.status.controllerservice.ControllerServiceHealth) ControllerServiceStatus(org.apache.nifi.minifi.commons.status.controllerservice.ControllerServiceStatus) Bulletin(org.apache.nifi.reporting.Bulletin) BulletinQuery(org.apache.nifi.reporting.BulletinQuery) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 25 with Bulletin

use of org.apache.nifi.reporting.Bulletin in project nifi-minifi by apache.

the class StatusRequestParser method parseProcessorStatusRequest.

static ProcessorStatusBean parseProcessorStatusRequest(ProcessorStatus inputProcessorStatus, String statusTypes, FlowController flowController, Collection<ValidationResult> validationResults) {
    ProcessorStatusBean processorStatusBean = new ProcessorStatusBean();
    processorStatusBean.setName(inputProcessorStatus.getName());
    String[] statusSplits = statusTypes.split(",");
    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(new BulletinQuery.Builder().sourceIdMatches(inputProcessorStatus.getId()).build());
    for (String statusType : statusSplits) {
        switch(statusType.toLowerCase().trim()) {
            case "health":
                ProcessorHealth processorHealth = new ProcessorHealth();
                processorHealth.setRunStatus(inputProcessorStatus.getRunStatus().name());
                processorHealth.setHasBulletins(!bulletinList.isEmpty());
                processorHealth.setValidationErrorList(transformValidationResults(validationResults));
                processorStatusBean.setProcessorHealth(processorHealth);
                break;
            case "bulletins":
                processorStatusBean.setBulletinList(transformBulletins(bulletinList));
                break;
            case "stats":
                ProcessorStats processorStats = new ProcessorStats();
                processorStats.setActiveThreads(inputProcessorStatus.getActiveThreadCount());
                processorStats.setFlowfilesReceived(inputProcessorStatus.getFlowFilesReceived());
                processorStats.setBytesRead(inputProcessorStatus.getBytesRead());
                processorStats.setBytesWritten(inputProcessorStatus.getBytesWritten());
                processorStats.setFlowfilesSent(inputProcessorStatus.getFlowFilesSent());
                processorStats.setInvocations(inputProcessorStatus.getInvocations());
                processorStats.setProcessingNanos(inputProcessorStatus.getProcessingNanos());
                processorStatusBean.setProcessorStats(processorStats);
                break;
        }
    }
    return processorStatusBean;
}
Also used : Bulletin(org.apache.nifi.reporting.Bulletin) BulletinQuery(org.apache.nifi.reporting.BulletinQuery) ProcessorStatusBean(org.apache.nifi.minifi.commons.status.processor.ProcessorStatusBean) ProcessorHealth(org.apache.nifi.minifi.commons.status.processor.ProcessorHealth) ProcessorStats(org.apache.nifi.minifi.commons.status.processor.ProcessorStats) SystemProcessorStats(org.apache.nifi.minifi.commons.status.system.SystemProcessorStats)

Aggregations

Bulletin (org.apache.nifi.reporting.Bulletin)45 ArrayList (java.util.ArrayList)29 BulletinQuery (org.apache.nifi.reporting.BulletinQuery)28 Date (java.util.Date)27 ProcessGroup (org.apache.nifi.groups.ProcessGroup)27 BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)27 ValidationResult (org.apache.nifi.components.ValidationResult)26 Arrays (java.util.Arrays)24 Collection (java.util.Collection)24 Collections (java.util.Collections)24 Comparator (java.util.Comparator)24 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 LinkedHashMap (java.util.LinkedHashMap)24 LinkedHashSet (java.util.LinkedHashSet)24 List (java.util.List)24 Map (java.util.Map)24 Set (java.util.Set)24 Function (java.util.function.Function)24 Supplier (java.util.function.Supplier)24