From a794166d2170f68f18cda5b34a7e8bd3f22e5583 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Wed, 4 Jan 2017 13:25:11 -0500 Subject: [PATCH] NIFI-3118 - Sorting the garbage collection stats and content repository entries client side. Opting to not sort server side as the property of the DTO does not allow deterministic sorting. Consequently, order would need to be implemented every time that DTO is (de)serializaed which may happen in a number of places with zero master clustering. This closes #1337. --- .../api/dto/SystemDiagnosticsSnapshotDTO.java | 18 +++++------ .../webapp/js/nf/cluster/nf-cluster-table.js | 15 ++++++--- .../webapp/js/nf/summary/nf-summary-table.js | 32 +++++++++++++------ 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/SystemDiagnosticsSnapshotDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/SystemDiagnosticsSnapshotDTO.java index 05826fc464..1cced18156 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/SystemDiagnosticsSnapshotDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/SystemDiagnosticsSnapshotDTO.java @@ -16,17 +16,15 @@ */ package org.apache.nifi.web.api.dto; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - +import com.wordnik.swagger.annotations.ApiModelProperty; import org.apache.nifi.web.api.dto.util.DateTimeAdapter; import org.apache.nifi.web.api.dto.util.TimeAdapter; -import com.wordnik.swagger.annotations.ApiModelProperty; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Date; +import java.util.LinkedHashSet; +import java.util.Set; /** * The diagnostics of the system this NiFi is running on. @@ -346,13 +344,13 @@ public class SystemDiagnosticsSnapshotDTO implements Cloneable { other.setFlowFileRepositoryStorageUsage(getFlowFileRepositoryStorageUsage().clone()); - final Set contentRepoStorageUsage = new HashSet<>(); + final Set contentRepoStorageUsage = new LinkedHashSet<>(); other.setContentRepositoryStorageUsage(contentRepoStorageUsage); for (final StorageUsageDTO usage : getContentRepositoryStorageUsage()) { contentRepoStorageUsage.add(usage.clone()); } - final Set gcUsage = new HashSet<>(); + final Set gcUsage = new LinkedHashSet<>(); other.setGarbageCollection(gcUsage); for (final GarbageCollectionDTO gcDto : getGarbageCollection()) { gcUsage.add(gcDto.clone()); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/cluster/nf-cluster-table.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/cluster/nf-cluster-table.js index ff9768bc0f..f91d73554d 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/cluster/nf-cluster-table.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/cluster/nf-cluster-table.js @@ -678,6 +678,13 @@ nf.ClusterTable = (function () { var jvmTableRows = []; systemDiagnosticsResponse.systemDiagnostics.nodeSnapshots.forEach(function (nodeSnapshot) { var snapshot = nodeSnapshot.snapshot; + + // sort the garbage collection + var garbageCollection = snapshot.garbageCollection.sort(function (a, b) { + return a.name === b.name ? 0 : a.name > b.name ? 1 : -1; + }); + + // add the node jvm details jvmTableRows.push({ id: nodeSnapshot.nodeId, node: nodeSnapshot.address + ':' + nodeSnapshot.apiPort, @@ -689,10 +696,10 @@ nf.ClusterTable = (function () { maxNonHeap: snapshot.maxNonHeap, totalNonHeap: snapshot.totalNonHeap, usedNonHeap: snapshot.usedNonHeap, - gcOldGen: snapshot.garbageCollection[0].collectionCount + ' times (' + - snapshot.garbageCollection[0].collectionTime + ')', - gcNewGen: snapshot.garbageCollection[1].collectionCount + ' times (' + - snapshot.garbageCollection[1].collectionTime + ')' + gcOldGen: garbageCollection[0].collectionCount + ' times (' + + garbageCollection[0].collectionTime + ')', + gcNewGen: garbageCollection[1].collectionCount + ' times (' + + garbageCollection[1].collectionTime + ')' }); }); jvmTab.rowCount = jvmTableRows.length; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/summary/nf-summary-table.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/summary/nf-summary-table.js index aeaa29595a..fba8b93074 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/summary/nf-summary-table.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/summary/nf-summary-table.js @@ -2260,9 +2260,16 @@ nf.SummaryTable = (function () { // garbage collection var garbageCollectionContainer = $('#garbage-collection-table tbody').empty(); - $.each(aggregateSnapshot.garbageCollection, function (_, garbageCollection) { - addGarbageCollection(garbageCollectionContainer, garbageCollection); - }); + if (nf.Common.isDefinedAndNotNull(aggregateSnapshot.garbageCollection)) { + // sort the garbage collections + var sortedGarbageCollection = aggregateSnapshot.garbageCollection.sort(function(a, b) { + return a.name === b.name ? 0 : a.name > b.name ? 1 : -1; + }); + // add each to the UI + $.each(sortedGarbageCollection, function (_, garbageCollection) { + addGarbageCollection(garbageCollectionContainer, garbageCollection); + }); + } // available processors $('#available-processors').text(aggregateSnapshot.availableProcessors); @@ -2274,15 +2281,22 @@ nf.SummaryTable = (function () { $('#processor-load-average').html(nf.Common.formatValue(aggregateSnapshot.processorLoadAverage)); } - // database storage usage + // flow file storage usage var flowFileRepositoryStorageUsageContainer = $('#flow-file-repository-storage-usage-container').empty(); addStorageUsage(flowFileRepositoryStorageUsageContainer, aggregateSnapshot.flowFileRepositoryStorageUsage); - // database storage usage + // content repo storage usage var contentRepositoryUsageContainer = $('#content-repository-storage-usage-container').empty(); - $.each(aggregateSnapshot.contentRepositoryStorageUsage, function (_, contentRepository) { - addStorageUsage(contentRepositoryUsageContainer, contentRepository); - }); + if (nf.Common.isDefinedAndNotNull(aggregateSnapshot.contentRepositoryStorageUsage)) { + // sort the content repos + var sortedContentRepositoryStorageUsage = aggregateSnapshot.contentRepositoryStorageUsage.sort(function(a, b) { + return a.identifier === b.identifier ? 0 : a.identifier > b.identifier ? 1 : -1; + }); + // add each to the UI + $.each(sortedContentRepositoryStorageUsage, function (_, contentRepository) { + addStorageUsage(contentRepositoryUsageContainer, contentRepository); + }); + } // Version var versionSpanSelectorToFieldMap = { @@ -2318,7 +2332,7 @@ nf.SummaryTable = (function () { */ var addGarbageCollection = function (container, garbageCollection) { var nameTr = $('').appendTo(container); - $('').append(garbageCollection.name + ':').appendTo(nameTr); + $('').text(garbageCollection.name + ':').appendTo(nameTr); var valTr = $('').appendTo(container); $('').append($('').text(garbageCollection.collectionCount + ' times (' + garbageCollection.collectionTime + ')')).appendTo(valTr); $('').text(' ').appendTo(container);