Search in sources :

Example 11 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class SiteToSiteStatusReportingTask method serializeProcessGroupStatus.

/**
 * Serialize the ProcessGroupStatus and add it to the JsonArrayBuilder.
 * @param arrayBuilder
 *            The JSON Array builder
 * @param factory
 *            The JSON Builder Factory
 * @param status
 *            The ProcessGroupStatus
 * @param df
 *            A date format
 * @param hostname
 *            The current hostname
 * @param applicationName
 *            The root process group name
 * @param platform
 *            The configured platform
 * @param parentId
 *            The parent's component id
 */
void serializeProcessGroupStatus(final JsonArrayBuilder arrayBuilder, final JsonBuilderFactory factory, final ProcessGroupStatus status, final DateFormat df, final String hostname, final String applicationName, final String platform, final String parentId, final Date currentDate) {
    final JsonObjectBuilder builder = factory.createObjectBuilder();
    final String componentType = (parentId == null) ? "RootProcessGroup" : "ProcessGroup";
    final String componentName = status.getName();
    if (componentMatchesFilters(componentType, componentName)) {
        addCommonFields(builder, df, hostname, applicationName, platform, parentId, currentDate, componentType, componentName);
        addField(builder, "componentId", status.getId());
        addField(builder, "bytesRead", status.getBytesRead());
        addField(builder, "bytesWritten", status.getBytesWritten());
        addField(builder, "bytesReceived", status.getBytesReceived());
        addField(builder, "bytesSent", status.getBytesSent());
        addField(builder, "bytesTransferred", status.getBytesTransferred());
        addField(builder, "flowFilesReceived", status.getFlowFilesReceived());
        addField(builder, "flowFilesSent", status.getFlowFilesSent());
        addField(builder, "flowFilesTransferred", status.getFlowFilesTransferred());
        addField(builder, "inputContentSize", status.getInputContentSize());
        addField(builder, "inputCount", status.getInputCount());
        addField(builder, "outputContentSize", status.getOutputContentSize());
        addField(builder, "outputCount", status.getOutputCount());
        addField(builder, "queuedContentSize", status.getQueuedContentSize());
        addField(builder, "activeThreadCount", status.getActiveThreadCount());
        addField(builder, "queuedCount", status.getQueuedCount());
        arrayBuilder.add(builder.build());
    }
    for (ProcessGroupStatus childGroupStatus : status.getProcessGroupStatus()) {
        serializeProcessGroupStatus(arrayBuilder, factory, childGroupStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (ProcessorStatus processorStatus : status.getProcessorStatus()) {
        serializeProcessorStatus(arrayBuilder, factory, processorStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (ConnectionStatus connectionStatus : status.getConnectionStatus()) {
        serializeConnectionStatus(arrayBuilder, factory, connectionStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (PortStatus portStatus : status.getInputPortStatus()) {
        serializePortStatus("InputPort", arrayBuilder, factory, portStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (PortStatus portStatus : status.getOutputPortStatus()) {
        serializePortStatus("OutputPort", arrayBuilder, factory, portStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (RemoteProcessGroupStatus remoteProcessGroupStatus : status.getRemoteProcessGroupStatus()) {
        serializeRemoteProcessGroupStatus(arrayBuilder, factory, remoteProcessGroupStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) PortStatus(org.apache.nifi.controller.status.PortStatus) JsonObjectBuilder(javax.json.JsonObjectBuilder) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 12 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class TestSiteToSiteStatusReportingTask method generateProcessGroupStatus.

public static ProcessGroupStatus generateProcessGroupStatus(String id, String namePrefix, int maxRecursion, int currentDepth) {
    Collection<ConnectionStatus> cStatus = new ArrayList<>();
    Collection<PortStatus> ipStatus = new ArrayList<>();
    Collection<PortStatus> opStatus = new ArrayList<>();
    Collection<ProcessorStatus> pStatus = new ArrayList<>();
    Collection<RemoteProcessGroupStatus> rpgStatus = new ArrayList<>();
    Collection<ProcessGroupStatus> childPgStatus = new ArrayList<>();
    if (currentDepth < maxRecursion) {
        for (int i = 1; i < 4; i++) {
            childPgStatus.add(generateProcessGroupStatus(id + "." + i, namePrefix + "." + i, maxRecursion, currentDepth + 1));
        }
    }
    for (int i = 1; i < 4; i++) {
        pStatus.add(generateProcessorStatus(id + ".processor." + i, namePrefix + ".processor." + i));
    }
    for (int i = 1; i < 4; i++) {
        cStatus.add(generateConnectionStatus(id + ".connection." + i, namePrefix + ".connection." + i));
    }
    for (int i = 1; i < 4; i++) {
        rpgStatus.add(generateRemoteProcessGroupStatus(id + ".rpg." + i, namePrefix + ".rpg." + i));
    }
    for (int i = 1; i < 4; i++) {
        ipStatus.add(generatePortStatus(id + ".ip." + i, namePrefix + ".ip." + i));
    }
    for (int i = 1; i < 4; i++) {
        opStatus.add(generatePortStatus(id + ".op." + i, namePrefix + ".op." + i));
    }
    ProcessGroupStatus pgStatus = new ProcessGroupStatus();
    pgStatus.setId(id);
    pgStatus.setName(namePrefix + "-" + UUID.randomUUID().toString());
    pgStatus.setInputPortStatus(ipStatus);
    pgStatus.setOutputPortStatus(opStatus);
    pgStatus.setProcessGroupStatus(childPgStatus);
    pgStatus.setRemoteProcessGroupStatus(rpgStatus);
    pgStatus.setProcessorStatus(pStatus);
    pgStatus.setActiveThreadCount(1);
    pgStatus.setBytesRead(2L);
    pgStatus.setBytesReceived(3l);
    pgStatus.setBytesSent(4l);
    pgStatus.setBytesTransferred(5l);
    pgStatus.setBytesWritten(6l);
    pgStatus.setConnectionStatus(cStatus);
    pgStatus.setFlowFilesReceived(7);
    pgStatus.setFlowFilesSent(8);
    pgStatus.setFlowFilesTransferred(9);
    pgStatus.setInputContentSize(10l);
    pgStatus.setInputCount(11);
    pgStatus.setOutputContentSize(12l);
    pgStatus.setOutputCount(13);
    pgStatus.setQueuedContentSize(14l);
    pgStatus.setQueuedCount(15);
    return pgStatus;
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ArrayList(java.util.ArrayList) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 13 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class ControllerStatusReportingTask method printProcessorStatus.

// Recursively the status of all processors in this group.
private void printProcessorStatus(final ProcessGroupStatus groupStatus, final StringBuilder builder, final boolean showDeltas) {
    final List<ProcessorStatus> processorStatuses = new ArrayList<>();
    populateProcessorStatuses(groupStatus, processorStatuses);
    Collections.sort(processorStatuses, new Comparator<ProcessorStatus>() {

        @Override
        public int compare(final ProcessorStatus o1, final ProcessorStatus o2) {
            if (o1 == null && o2 == null) {
                return 0;
            }
            if (o1 == null) {
                return 1;
            }
            if (o2 == null) {
                return -1;
            }
            return -Long.compare(o1.getProcessingNanos(), o2.getProcessingNanos());
        }
    });
    for (final ProcessorStatus processorStatus : processorStatuses) {
        // get the stats
        final String input = processorStatus.getInputCount() + " / " + FormatUtils.formatDataSize(processorStatus.getInputBytes());
        final String output = processorStatus.getOutputCount() + " / " + FormatUtils.formatDataSize(processorStatus.getOutputBytes());
        final String read = FormatUtils.formatDataSize(processorStatus.getBytesRead());
        final String written = FormatUtils.formatDataSize(processorStatus.getBytesWritten());
        final String invocations = String.valueOf(processorStatus.getInvocations());
        final long nanos = processorStatus.getProcessingNanos();
        final String procTime = FormatUtils.formatHoursMinutesSeconds(nanos, TimeUnit.NANOSECONDS);
        String runStatus = "";
        if (processorStatus.getRunStatus() != null) {
            runStatus = processorStatus.getRunStatus().toString();
        }
        final String inputDiff;
        final String outputDiff;
        final String readDiff;
        final String writtenDiff;
        final String invocationsDiff;
        final String procTimeDiff;
        final ProcessorStatus lastStatus = lastProcessorStatus.get(processorStatus.getId());
        if (showDeltas && lastStatus != null) {
            inputDiff = toDiff(lastStatus.getInputCount(), lastStatus.getInputBytes(), processorStatus.getInputCount(), processorStatus.getInputBytes());
            outputDiff = toDiff(lastStatus.getOutputCount(), lastStatus.getOutputBytes(), processorStatus.getOutputCount(), processorStatus.getOutputBytes());
            readDiff = toDiff(lastStatus.getBytesRead(), processorStatus.getBytesRead(), true, false);
            writtenDiff = toDiff(lastStatus.getBytesWritten(), processorStatus.getBytesWritten(), true, false);
            invocationsDiff = toDiff(lastStatus.getInvocations(), processorStatus.getInvocations());
            procTimeDiff = toDiff(lastStatus.getProcessingNanos(), processorStatus.getProcessingNanos(), false, true);
        } else {
            inputDiff = toDiff(0L, 0L, processorStatus.getInputCount(), processorStatus.getInputBytes());
            outputDiff = toDiff(0L, 0L, processorStatus.getOutputCount(), processorStatus.getOutputBytes());
            readDiff = toDiff(0L, processorStatus.getBytesRead(), true, false);
            writtenDiff = toDiff(0L, processorStatus.getBytesWritten(), true, false);
            invocationsDiff = toDiff(0L, processorStatus.getInvocations());
            procTimeDiff = toDiff(0L, processorStatus.getProcessingNanos(), false, true);
        }
        if (showDeltas) {
            builder.append(String.format(processorLineFormat, processorStatus.getName(), processorStatus.getId(), processorStatus.getType(), runStatus, input + inputDiff, output + outputDiff, read + readDiff, written + writtenDiff, invocations + invocationsDiff, procTime + procTimeDiff));
        } else {
            builder.append(String.format(processorLineFormat, processorStatus.getName(), processorStatus.getId(), processorStatus.getType(), runStatus, input, output, read, written, invocations, procTime));
        }
        lastProcessorStatus.put(processorStatus.getId(), processorStatus);
    }
}
Also used : ArrayList(java.util.ArrayList) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 14 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class StatusHistoryEndpointMerger method merge.

@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, NodeResponse clientResponse) {
    final Map<String, MetricDescriptor<?>> metricDescriptors = getStandardMetricDescriptors(uri);
    final StatusHistoryEntity responseEntity = clientResponse.getClientResponse().readEntity(StatusHistoryEntity.class);
    final Set<StatusDescriptorDTO> fieldDescriptors = new LinkedHashSet<>();
    boolean includeCounters = true;
    StatusHistoryDTO lastStatusHistory = null;
    final List<NodeStatusSnapshotsDTO> nodeStatusSnapshots = new ArrayList<>(successfulResponses.size());
    LinkedHashMap<String, String> noReadPermissionsComponentDetails = null;
    for (final NodeResponse nodeResponse : successfulResponses) {
        final StatusHistoryEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(StatusHistoryEntity.class);
        final StatusHistoryDTO nodeStatus = nodeResponseEntity.getStatusHistory();
        lastStatusHistory = nodeStatus;
        if (noReadPermissionsComponentDetails == null && !nodeResponseEntity.getCanRead()) {
            // If component details from a history with no read permissions is encountered for the first time, hold on to them to be used in the merged response
            noReadPermissionsComponentDetails = nodeStatus.getComponentDetails();
        }
        if (!Boolean.TRUE.equals(nodeResponseEntity.getCanRead())) {
            includeCounters = false;
        }
        final NodeIdentifier nodeId = nodeResponse.getNodeId();
        final NodeStatusSnapshotsDTO nodeStatusSnapshot = new NodeStatusSnapshotsDTO();
        nodeStatusSnapshot.setNodeId(nodeId.getId());
        nodeStatusSnapshot.setAddress(nodeId.getApiAddress());
        nodeStatusSnapshot.setApiPort(nodeId.getApiPort());
        nodeStatusSnapshot.setStatusSnapshots(nodeStatus.getAggregateSnapshots());
        nodeStatusSnapshots.add(nodeStatusSnapshot);
        final List<StatusDescriptorDTO> descriptors = nodeStatus.getFieldDescriptors();
        if (descriptors != null) {
            fieldDescriptors.addAll(descriptors);
        }
    }
    // the user is not authorized, we want to assume that the user is, in fact, not authorized.
    if (includeCounters) {
        for (final StatusDescriptorDTO descriptorDto : fieldDescriptors) {
            final String fieldName = descriptorDto.getField();
            if (!metricDescriptors.containsKey(fieldName)) {
                final ValueMapper<ProcessorStatus> valueMapper = s -> {
                    final Map<String, Long> counters = s.getCounters();
                    if (counters == null) {
                        return 0L;
                    }
                    return counters.getOrDefault(descriptorDto.getField(), 0L);
                };
                final MetricDescriptor<ProcessorStatus> metricDescriptor = new StandardMetricDescriptor<>(descriptorDto.getField(), descriptorDto.getLabel(), descriptorDto.getDescription(), Formatter.COUNT, valueMapper);
                metricDescriptors.put(fieldName, metricDescriptor);
            }
        }
    }
    final StatusHistoryDTO clusterStatusHistory = new StatusHistoryDTO();
    clusterStatusHistory.setAggregateSnapshots(mergeStatusHistories(nodeStatusSnapshots, metricDescriptors));
    clusterStatusHistory.setGenerated(new Date());
    clusterStatusHistory.setNodeSnapshots(nodeStatusSnapshots);
    if (lastStatusHistory != null) {
        clusterStatusHistory.setComponentDetails(noReadPermissionsComponentDetails == null ? lastStatusHistory.getComponentDetails() : noReadPermissionsComponentDetails);
    }
    clusterStatusHistory.setFieldDescriptors(new ArrayList<>(fieldDescriptors));
    final StatusHistoryEntity clusterEntity = new StatusHistoryEntity();
    clusterEntity.setStatusHistory(clusterStatusHistory);
    clusterEntity.setCanRead(noReadPermissionsComponentDetails == null);
    return new NodeResponse(clientResponse, clusterEntity);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) ValueMapper(org.apache.nifi.controller.status.history.ValueMapper) StatusSnapshotDTO(org.apache.nifi.web.api.dto.status.StatusSnapshotDTO) Date(java.util.Date) HashMap(java.util.HashMap) StandardMetricDescriptor(org.apache.nifi.controller.status.history.StandardMetricDescriptor) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ProcessorStatusDescriptor(org.apache.nifi.controller.status.history.ProcessorStatusDescriptor) URI(java.net.URI) RemoteProcessGroupStatusDescriptor(org.apache.nifi.controller.status.history.RemoteProcessGroupStatusDescriptor) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) LinkedHashSet(java.util.LinkedHashSet) Formatter(org.apache.nifi.controller.status.history.MetricDescriptor.Formatter) StatusHistoryUtil(org.apache.nifi.controller.status.history.StatusHistoryUtil) StatusSnapshot(org.apache.nifi.controller.status.history.StatusSnapshot) StandardStatusSnapshot(org.apache.nifi.controller.status.history.StandardStatusSnapshot) Set(java.util.Set) EndpointResponseMerger(org.apache.nifi.cluster.coordination.http.EndpointResponseMerger) List(java.util.List) TreeMap(java.util.TreeMap) MetricDescriptor(org.apache.nifi.controller.status.history.MetricDescriptor) ConnectionStatusDescriptor(org.apache.nifi.controller.status.history.ConnectionStatusDescriptor) ProcessGroupStatusDescriptor(org.apache.nifi.controller.status.history.ProcessGroupStatusDescriptor) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) NodeStatusSnapshotsDTO(org.apache.nifi.web.api.dto.status.NodeStatusSnapshotsDTO) Pattern(java.util.regex.Pattern) StatusDescriptorDTO(org.apache.nifi.web.api.dto.status.StatusDescriptorDTO) NodeStatusSnapshotsDTO(org.apache.nifi.web.api.dto.status.NodeStatusSnapshotsDTO) ArrayList(java.util.ArrayList) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Date(java.util.Date) StatusDescriptorDTO(org.apache.nifi.web.api.dto.status.StatusDescriptorDTO) StandardMetricDescriptor(org.apache.nifi.controller.status.history.StandardMetricDescriptor) MetricDescriptor(org.apache.nifi.controller.status.history.MetricDescriptor) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) StandardMetricDescriptor(org.apache.nifi.controller.status.history.StandardMetricDescriptor) StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 15 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi-minifi by apache.

the class StatusConfigReporter method handleProcessorRequest.

private static void handleProcessorRequest(String[] sections, ProcessGroupStatus rootGroupStatus, FlowController flowController, List<ProcessorStatusBean> processorStatusBeanList, Map<String, ProcessorStatus> processorStatusMap, Logger logger) throws StatusRequestException {
    if (processorStatusMap == null) {
        processorStatusMap = transformStatusCollection(rootGroupStatus.getProcessorStatus());
    }
    String rootGroupId = flowController.getRootGroupId();
    if (sections[1].equalsIgnoreCase("all")) {
        if (!processorStatusMap.isEmpty()) {
            for (ProcessorStatus processorStatus : processorStatusMap.values()) {
                Collection<ValidationResult> validationResults = flowController.getGroup(rootGroupId).getProcessor(processorStatus.getId()).getValidationErrors();
                processorStatusBeanList.add(parseProcessorStatusRequest(processorStatus, sections[2], flowController, validationResults));
            }
        }
    } else {
        if (processorStatusMap.containsKey(sections[1])) {
            ProcessorStatus processorStatus = processorStatusMap.get(sections[1]);
            Collection<ValidationResult> validationResults = flowController.getGroup(rootGroupId).getProcessor(processorStatus.getId()).getValidationErrors();
            processorStatusBeanList.add(parseProcessorStatusRequest(processorStatus, sections[2], flowController, validationResults));
        } else {
            logger.warn("Status for processor with key " + sections[1] + " was requested but one does not exist");
            throw new StatusRequestException("No processor with key " + sections[1] + " to report status on");
        }
    }
}
Also used : ValidationResult(org.apache.nifi.components.ValidationResult) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Aggregations

ProcessorStatus (org.apache.nifi.controller.status.ProcessorStatus)31 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)21 ArrayList (java.util.ArrayList)18 ConnectionStatus (org.apache.nifi.controller.status.ConnectionStatus)12 PortStatus (org.apache.nifi.controller.status.PortStatus)9 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)9 Test (org.junit.Test)9 List (java.util.List)6 Map (java.util.Map)6 ProcessorNode (org.apache.nifi.controller.ProcessorNode)6 ProcessGroup (org.apache.nifi.groups.ProcessGroup)6 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 ValidationResult (org.apache.nifi.components.ValidationResult)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4