Java Code Examples for org.apache.nifi.controller.status.ConnectionStatus#getOutputCount()

The following examples show how to use org.apache.nifi.controller.status.ConnectionStatus#getOutputCount() . 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: ControllerStatusReportingTask.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void printConnectionStatus(final ProcessGroupStatus groupStatus, final StringBuilder builder, final boolean showDeltas) {
    final List<ConnectionStatus> connectionStatuses = new ArrayList<>();
    populateConnectionStatuses(groupStatus, connectionStatuses);
    Collections.sort(connectionStatuses, new Comparator<ConnectionStatus>() {
        @Override
        public int compare(final ConnectionStatus o1, final ConnectionStatus o2) {
            if (o1 == null && o2 == null) {
                return 0;
            }
            if (o1 == null) {
                return 1;
            }
            if (o2 == null) {
                return -1;
            }

            return -Long.compare(o1.getQueuedBytes(), o2.getQueuedBytes());
        }
    });

    for (final ConnectionStatus connectionStatus : connectionStatuses) {
        final String input = connectionStatus.getInputCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getInputBytes());
        final String output = connectionStatus.getOutputCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getOutputBytes());
        final String queued = connectionStatus.getQueuedCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getQueuedBytes());

        final String inputDiff;
        final String outputDiff;
        final String queuedDiff;

        final ConnectionStatus lastStatus = lastConnectionStatus.get(connectionStatus.getId());
        if (showDeltas && lastStatus != null) {
            inputDiff = toDiff(lastStatus.getInputCount(), lastStatus.getInputBytes(), connectionStatus.getInputCount(), connectionStatus.getInputBytes());
            outputDiff = toDiff(lastStatus.getOutputCount(), lastStatus.getOutputBytes(), connectionStatus.getOutputCount(), connectionStatus.getOutputBytes());
            queuedDiff = toDiff(lastStatus.getQueuedCount(), lastStatus.getQueuedBytes(), connectionStatus.getQueuedCount(), connectionStatus.getQueuedBytes());
        } else {
            inputDiff = toDiff(0L, 0L, connectionStatus.getInputCount(), connectionStatus.getInputBytes());
            outputDiff = toDiff(0L, 0L, connectionStatus.getOutputCount(), connectionStatus.getOutputBytes());
            queuedDiff = toDiff(0L, 0L, connectionStatus.getQueuedCount(), connectionStatus.getQueuedBytes());
        }

        if (showDeltas) {
            builder.append(String.format(connectionLineFormat,
                    connectionStatus.getId(),
                    connectionStatus.getSourceName(),
                    connectionStatus.getName(),
                    connectionStatus.getDestinationName(),
                    input + inputDiff,
                    output + outputDiff,
                    queued + queuedDiff));
        } else {
            builder.append(String.format(connectionLineFormat,
                    connectionStatus.getId(),
                    connectionStatus.getSourceName(),
                    connectionStatus.getName(),
                    connectionStatus.getDestinationName(),
                    input,
                    output,
                    queued));
        }

        lastConnectionStatus.put(connectionStatus.getId(), connectionStatus);
    }
}
 
Example 2
Source File: ControllerStatusReportingTask.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void printConnectionStatus(final ProcessGroupStatus groupStatus, final StringBuilder builder, final boolean showDeltas) {
    final List<ConnectionStatus> connectionStatuses = new ArrayList<>();
    populateConnectionStatuses(groupStatus, connectionStatuses);
    Collections.sort(connectionStatuses, new Comparator<ConnectionStatus>() {
        @Override
        public int compare(final ConnectionStatus o1, final ConnectionStatus o2) {
            if (o1 == null && o2 == null) {
                return 0;
            }
            if (o1 == null) {
                return 1;
            }
            if (o2 == null) {
                return -1;
            }

            return -Long.compare(o1.getQueuedBytes(), o2.getQueuedBytes());
        }
    });

    for (final ConnectionStatus connectionStatus : connectionStatuses) {
        final String input = connectionStatus.getInputCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getInputBytes());
        final String output = connectionStatus.getOutputCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getOutputBytes());
        final String queued = connectionStatus.getQueuedCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getQueuedBytes());

        final String inputDiff;
        final String outputDiff;
        final String queuedDiff;

        final ConnectionStatus lastStatus = lastConnectionStatus.get(connectionStatus.getId());
        if (showDeltas && lastStatus != null) {
            inputDiff = toDiff(lastStatus.getInputCount(), lastStatus.getInputBytes(), connectionStatus.getInputCount(), connectionStatus.getInputBytes());
            outputDiff = toDiff(lastStatus.getOutputCount(), lastStatus.getOutputBytes(), connectionStatus.getOutputCount(), connectionStatus.getOutputBytes());
            queuedDiff = toDiff(lastStatus.getQueuedCount(), lastStatus.getQueuedBytes(), connectionStatus.getQueuedCount(), connectionStatus.getQueuedBytes());
        } else {
            inputDiff = toDiff(0L, 0L, connectionStatus.getInputCount(), connectionStatus.getInputBytes());
            outputDiff = toDiff(0L, 0L, connectionStatus.getOutputCount(), connectionStatus.getOutputBytes());
            queuedDiff = toDiff(0L, 0L, connectionStatus.getQueuedCount(), connectionStatus.getQueuedBytes());
        }

        if (showDeltas) {
            builder.append(String.format(connectionLineFormat,
                    connectionStatus.getId(),
                    connectionStatus.getSourceName(),
                    connectionStatus.getName(),
                    connectionStatus.getDestinationName(),
                    input + inputDiff,
                    output + outputDiff,
                    queued + queuedDiff));
        } else {
            builder.append(String.format(connectionLineFormat,
                    connectionStatus.getId(),
                    connectionStatus.getSourceName(),
                    connectionStatus.getName(),
                    connectionStatus.getDestinationName(),
                    input,
                    output,
                    queued));
        }

        lastConnectionStatus.put(connectionStatus.getId(), connectionStatus);
    }
}
 
Example 3
Source File: ConnectionStatusEnumerator.java    From nifi with Apache License 2.0 4 votes vote down vote up
private Object filterColumns(final ConnectionStatus status) {
    if (status == null) {
        return null;
    }

    final Object[] row = new Object[]{
            status.getId(),
            status.getGroupId(),
            status.getName(),
            status.getSourceId(),
            status.getSourceName(),
            status.getDestinationId(),
            status.getDestinationName(),
            status.getBackPressureDataSizeThreshold(),
            status.getBackPressureBytesThreshold(),
            status.getBackPressureObjectThreshold(),
            // isBackPressureEnabled
            ((status.getBackPressureObjectThreshold() > 0 && status.getBackPressureObjectThreshold() <= status.getQueuedCount())
                    || (status.getBackPressureBytesThreshold() > 0 && status.getBackPressureBytesThreshold() <= status.getQueuedBytes())),
            status.getInputCount(),
            status.getInputBytes(),
            status.getQueuedCount(),
            status.getQueuedBytes(),
            status.getOutputCount(),
            status.getOutputBytes(),
            status.getMaxQueuedCount(),
            status.getMaxQueuedBytes()
    };

    // If we want no fields just return null
    if (fields == null) {
        return row;
    }

    // If we want only a single field, then Calcite is going to expect us to return
    // the actual value, NOT a 1-element array of values.
    if (fields.length == 1) {
        final int desiredCellIndex = fields[0];
        return row[desiredCellIndex];
    }

    // Create a new Object array that contains only the desired fields.
    final Object[] filtered = new Object[fields.length];
    for (int i = 0; i < fields.length; i++) {
        final int indexToKeep = fields[i];
        filtered[i] = row[indexToKeep];
    }

    return filtered;
}