Search in sources :

Example 1 with StatusSnapshotDTO

use of org.apache.nifi.web.api.dto.status.StatusSnapshotDTO in project nifi by apache.

the class StatusHistoryEndpointMerger method aggregate.

private List<StatusSnapshotDTO> aggregate(Map<Date, List<StatusSnapshot>> snapshotsToAggregate) {
    // Aggregate the snapshots
    final List<StatusSnapshotDTO> aggregatedSnapshotDtos = new ArrayList<>();
    for (final Map.Entry<Date, List<StatusSnapshot>> entry : snapshotsToAggregate.entrySet()) {
        final List<StatusSnapshot> snapshots = entry.getValue();
        final StatusSnapshot reducedSnapshot = snapshots.get(0).getValueReducer().reduce(snapshots);
        final StatusSnapshotDTO dto = new StatusSnapshotDTO();
        dto.setTimestamp(reducedSnapshot.getTimestamp());
        dto.setStatusMetrics(StatusHistoryUtil.createStatusSnapshotDto(reducedSnapshot).getStatusMetrics());
        aggregatedSnapshotDtos.add(dto);
    }
    return aggregatedSnapshotDtos;
}
Also used : StatusSnapshotDTO(org.apache.nifi.web.api.dto.status.StatusSnapshotDTO) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) StatusSnapshot(org.apache.nifi.controller.status.history.StatusSnapshot) StandardStatusSnapshot(org.apache.nifi.controller.status.history.StandardStatusSnapshot) Date(java.util.Date)

Example 2 with StatusSnapshotDTO

use of org.apache.nifi.web.api.dto.status.StatusSnapshotDTO in project nifi by apache.

the class StatusHistoryUtil method createStatusHistoryDTO.

public static StatusHistoryDTO createStatusHistoryDTO(final StatusHistory statusHistory) {
    final List<StatusSnapshotDTO> snapshotDtos = new ArrayList<>();
    final Set<MetricDescriptor<?>> metricDescriptors = new LinkedHashSet<>();
    final LinkedHashMap<String, String> componentDetails = new LinkedHashMap<>(statusHistory.getComponentDetails());
    final Set<String> metricNames = new HashSet<>();
    for (final StatusSnapshot snapshot : statusHistory.getStatusSnapshots()) {
        final StatusSnapshotDTO snapshotDto = StatusHistoryUtil.createStatusSnapshotDto(snapshot);
        snapshotDtos.add(snapshotDto);
        metricNames.addAll(snapshotDto.getStatusMetrics().keySet());
        metricDescriptors.addAll(snapshot.getStatusMetrics().keySet());
    }
    // So for any metric that has is not in the aggregate snapshot, add it with a value of 0
    for (final StatusSnapshotDTO snapshotDto : snapshotDtos) {
        final Map<String, Long> metrics = snapshotDto.getStatusMetrics();
        for (final String metricName : metricNames) {
            if (!metrics.containsKey(metricName)) {
                metrics.put(metricName, 0L);
            }
        }
    }
    final StatusHistoryDTO dto = new StatusHistoryDTO();
    dto.setGenerated(new Date());
    dto.setComponentDetails(componentDetails);
    dto.setFieldDescriptors(StatusHistoryUtil.createFieldDescriptorDtos(metricDescriptors));
    dto.setAggregateSnapshots(snapshotDtos);
    return dto;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) StatusSnapshotDTO(org.apache.nifi.web.api.dto.status.StatusSnapshotDTO) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with StatusSnapshotDTO

use of org.apache.nifi.web.api.dto.status.StatusSnapshotDTO in project nifi by apache.

the class StatusHistoryUtil method createStatusSnapshotDto.

public static StatusSnapshotDTO createStatusSnapshotDto(final StatusSnapshot statusSnapshot) {
    final StatusSnapshotDTO dto = new StatusSnapshotDTO();
    dto.setTimestamp(statusSnapshot.getTimestamp());
    final Map<String, Long> statusMetrics = new HashMap<>();
    for (final Map.Entry<MetricDescriptor<?>, Long> entry : statusSnapshot.getStatusMetrics().entrySet()) {
        statusMetrics.put(entry.getKey().getField(), entry.getValue());
    }
    dto.setStatusMetrics(statusMetrics);
    return dto;
}
Also used : StatusSnapshotDTO(org.apache.nifi.web.api.dto.status.StatusSnapshotDTO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with StatusSnapshotDTO

use of org.apache.nifi.web.api.dto.status.StatusSnapshotDTO in project nifi by apache.

the class StatusHistoryEndpointMerger method mergeStatusHistories.

private List<StatusSnapshotDTO> mergeStatusHistories(final List<NodeStatusSnapshotsDTO> nodeStatusSnapshots, final Map<String, MetricDescriptor<?>> metricDescriptors) {
    // We want a Map<Date, List<StatusSnapshot>>, which is a Map of "normalized Date" (i.e., a time range, essentially)
    // to all Snapshots for that time. The list will contain one snapshot for each node. However, we can have the case
    // where the NCM has a different value for the componentStatusSnapshotMillis than the nodes have. In this case,
    // we end up with multiple entries in the List<StatusSnapshot> for the same node/timestamp, which skews our aggregate
    // results. In order to avoid this, we will use only the latest snapshot for a node that falls into the the time range
    // of interest.
    // To accomplish this, we have an intermediate data structure, which is a Map of "normalized Date" to an inner Map
    // of Node Identifier to StatusSnapshot. We then will flatten this Map and aggregate the results.
    final Map<Date, Map<String, StatusSnapshot>> dateToNodeSnapshots = new TreeMap<>();
    // group status snapshot's for each node by date
    for (final NodeStatusSnapshotsDTO nodeStatusSnapshot : nodeStatusSnapshots) {
        for (final StatusSnapshotDTO snapshotDto : nodeStatusSnapshot.getStatusSnapshots()) {
            final StatusSnapshot snapshot = createSnapshot(snapshotDto, metricDescriptors);
            final Date normalizedDate = normalizeStatusSnapshotDate(snapshot.getTimestamp(), componentStatusSnapshotMillis);
            Map<String, StatusSnapshot> nodeToSnapshotMap = dateToNodeSnapshots.get(normalizedDate);
            if (nodeToSnapshotMap == null) {
                nodeToSnapshotMap = new HashMap<>();
                dateToNodeSnapshots.put(normalizedDate, nodeToSnapshotMap);
            }
            nodeToSnapshotMap.put(nodeStatusSnapshot.getNodeId(), snapshot);
        }
    }
    // aggregate the snapshots by (normalized) timestamp
    final Map<Date, List<StatusSnapshot>> snapshotsToAggregate = new TreeMap<>();
    for (final Map.Entry<Date, Map<String, StatusSnapshot>> entry : dateToNodeSnapshots.entrySet()) {
        final Date normalizedDate = entry.getKey();
        final Map<String, StatusSnapshot> nodeToSnapshot = entry.getValue();
        final List<StatusSnapshot> snapshotsForTimestamp = new ArrayList<>(nodeToSnapshot.values());
        snapshotsToAggregate.put(normalizedDate, snapshotsForTimestamp);
    }
    final List<StatusSnapshotDTO> aggregatedSnapshots = aggregate(snapshotsToAggregate);
    return aggregatedSnapshots;
}
Also used : NodeStatusSnapshotsDTO(org.apache.nifi.web.api.dto.status.NodeStatusSnapshotsDTO) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) StatusSnapshot(org.apache.nifi.controller.status.history.StatusSnapshot) StandardStatusSnapshot(org.apache.nifi.controller.status.history.StandardStatusSnapshot) Date(java.util.Date) StatusSnapshotDTO(org.apache.nifi.web.api.dto.status.StatusSnapshotDTO) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)4 StatusSnapshotDTO (org.apache.nifi.web.api.dto.status.StatusSnapshotDTO)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 List (java.util.List)2 TreeMap (java.util.TreeMap)2 StandardStatusSnapshot (org.apache.nifi.controller.status.history.StandardStatusSnapshot)2 StatusSnapshot (org.apache.nifi.controller.status.history.StatusSnapshot)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 NodeStatusSnapshotsDTO (org.apache.nifi.web.api.dto.status.NodeStatusSnapshotsDTO)1 StatusHistoryDTO (org.apache.nifi.web.api.dto.status.StatusHistoryDTO)1