Search in sources :

Example 1 with DropFlowFileState

use of org.apache.nifi.controller.queue.DropFlowFileState in project nifi by apache.

the class DropRequestEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(DropRequestDTO clientDto, Map<NodeIdentifier, DropRequestDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    boolean nodeWaiting = false;
    int originalCount = 0;
    long originalSize = 0;
    int currentCount = 0;
    long currentSize = 0;
    int droppedCount = 0;
    long droppedSize = 0;
    DropFlowFileState state = null;
    boolean allFinished = true;
    String failureReason = null;
    for (final Map.Entry<NodeIdentifier, DropRequestDTO> nodeEntry : dtoMap.entrySet()) {
        final DropRequestDTO nodeDropRequest = nodeEntry.getValue();
        if (!nodeDropRequest.isFinished()) {
            allFinished = false;
        }
        if (nodeDropRequest.getFailureReason() != null) {
            failureReason = nodeDropRequest.getFailureReason();
        }
        currentCount += nodeDropRequest.getCurrentCount();
        currentSize += nodeDropRequest.getCurrentSize();
        droppedCount += nodeDropRequest.getDroppedCount();
        droppedSize += nodeDropRequest.getDroppedSize();
        if (nodeDropRequest.getOriginalCount() == null) {
            nodeWaiting = true;
        } else {
            originalCount += nodeDropRequest.getOriginalCount();
            originalSize += nodeDropRequest.getOriginalSize();
        }
        final DropFlowFileState nodeState = DropFlowFileState.valueOfDescription(nodeDropRequest.getState());
        if (state == null || state.ordinal() > nodeState.ordinal()) {
            state = nodeState;
        }
    }
    clientDto.setCurrentCount(currentCount);
    clientDto.setCurrentSize(currentSize);
    clientDto.setCurrent(FormatUtils.formatCount(currentCount) + " / " + FormatUtils.formatDataSize(currentSize));
    clientDto.setDroppedCount(droppedCount);
    clientDto.setDroppedSize(droppedSize);
    clientDto.setDropped(FormatUtils.formatCount(droppedCount) + " / " + FormatUtils.formatDataSize(droppedSize));
    clientDto.setFinished(allFinished);
    clientDto.setFailureReason(failureReason);
    if (originalCount == 0) {
        clientDto.setPercentCompleted(allFinished ? 100 : 0);
    } else {
        clientDto.setPercentCompleted((int) ((double) droppedCount / (double) originalCount * 100D));
    }
    if (!nodeWaiting) {
        clientDto.setOriginalCount(originalCount);
        clientDto.setOriginalSize(originalSize);
        clientDto.setOriginal(FormatUtils.formatCount(originalCount) + " / " + FormatUtils.formatDataSize(originalSize));
    }
    if (state != null) {
        clientDto.setState(state.toString());
    }
}
Also used : DropRequestDTO(org.apache.nifi.web.api.dto.DropRequestDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) DropFlowFileState(org.apache.nifi.controller.queue.DropFlowFileState) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 DropFlowFileState (org.apache.nifi.controller.queue.DropFlowFileState)1 DropRequestDTO (org.apache.nifi.web.api.dto.DropRequestDTO)1