Updated Branches: refs/heads/trunk 7bee7da4d -> 67b7c76fd
AMBARI-4394 : Temporal Host metrics can get overwritten. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/67b7c76f Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/67b7c76f Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/67b7c76f Branch: refs/heads/trunk Commit: 67b7c76fd71e73768ef6def81187041246f07f35 Parents: 7bee7da Author: tbeerbower <[email protected]> Authored: Thu Jan 23 13:46:29 2014 -0500 Committer: tbeerbower <[email protected]> Committed: Thu Jan 23 14:09:21 2014 -0500 ---------------------------------------------------------------------- .../ganglia/GangliaPropertyProvider.java | 9 +- .../ganglia/GangliaPropertyProviderTest.java | 33 +- .../resources/host_temporal_ganglia_data.txt | 511 +++++++++++++++++++ 3 files changed, 549 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/67b7c76f/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java index 1914875..6940861 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java @@ -337,11 +337,11 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider { private static Object getValue(GangliaMetric metric, boolean isTemporal) { Number[][] dataPoints = metric.getDatapoints(); + int length = dataPoints.length; if (isTemporal) { - return dataPoints; + return length > 0 ? dataPoints : null; } else { // return the value of the last data point - int length = dataPoints.length; return length > 0 ? dataPoints[length - 1][0] : 0; } } @@ -604,7 +604,10 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider { ++i; } } - resource.setProperty(propertyId, getValue(gangliaMetric, temporalInfo != null)); + Object value = getValue(gangliaMetric, temporalInfo != null); + if (value != null) { + resource.setProperty(propertyId, value); + } } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/67b7c76f/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java index f981e98..4e827ab 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java @@ -28,7 +28,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import org.apache.ambari.server.configuration.ComponentSSLConfiguration; @@ -250,6 +249,38 @@ public class GangliaPropertyProviderTest { } + @Test + public void testPopulateResources_checkHost() throws Exception { + TestStreamProvider streamProvider = new TestStreamProvider("host_temporal_ganglia_data.txt"); + TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); + + GangliaPropertyProvider propertyProvider = new GangliaHostPropertyProvider( + PropertyHelper.getGangliaPropertyIds(Resource.Type.Host), + streamProvider, + configuration, + hostProvider, + CLUSTER_NAME_PROPERTY_ID, + HOST_NAME_PROPERTY_ID + ); + + // host + Resource resource = new ResourceImpl(Resource.Type.Host); + resource.setProperty(HOST_NAME_PROPERTY_ID, "corp-hadoopda05.client.ext"); + + // only ask for one property + Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); + temporalInfoMap.put("metrics/process/proc_total", new TemporalInfoImpl(10L, 20L, 1L)); + Request request = PropertyHelper.getReadRequest(Collections.singleton("metrics/process/proc_total"), temporalInfoMap); + + Set<Resource> populateResources = propertyProvider.populateResources(Collections.singleton(resource), request, null); + + Assert.assertEquals(1, populateResources.size()); + + Resource res = populateResources.iterator().next(); + + Number[][] val = (Number[][]) res.getPropertyValue("metrics/process/proc_total"); + Assert.assertEquals(226, val.length); + } @Test public void testPopulateManyResources() throws Exception { http://git-wip-us.apache.org/repos/asf/ambari/blob/67b7c76f/ambari-server/src/test/resources/host_temporal_ganglia_data.txt ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/resources/host_temporal_ganglia_data.txt b/ambari-server/src/test/resources/host_temporal_ganglia_data.txt new file mode 100644 index 0000000..5e153fc --- /dev/null +++ b/ambari-server/src/test/resources/host_temporal_ganglia_data.txt @@ -0,0 +1,511 @@ +1389142901.0 +sum +HDPJobTracker +corp-hadoopda05.client.ext +proc_total +1389121200 +15 +[~EOM] +sum +HDPJobTracker +corp-hadoopda05.client.ext +proc_run +1389121200 +15 +[~EOM] +sum +HDPHBaseMaster +corp-hadoopda05.client.ext +proc_total +1389121200 +15 +[~EOM] +sum +HDPHBaseMaster +corp-hadoopda05.client.ext +proc_run +1389121200 +15 +[~EOM] +sum +HDPSlaves +corp-hadoopda05.client.ext +proc_total +1389121200 +15 +521.666666667 +523.0 +523.0 +523.0 +523.0 +523.0 +520.6 +519.0 +519.0 +519.0 +519.0 +519.0 +519.0 +519.0 +519.0 +519.0 +522.6 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +566.333333333 +587.0 +587.0 +587.0 +587.0 +569.4 +563.0 +563.0 +563.0 +563.0 +563.0 +539.533333333 +531.0 +531.0 +531.0 +531.0 +564.733333333 +577.0 +577.0 +577.0 +577.0 +547.666666667 +533.0 +533.0 +533.0 +533.0 +533.0 +530.866666667 +529.0 +529.0 +529.0 +529.0 +569.8 +597.0 +597.0 +597.0 +597.0 +580.8 +570.0 +570.0 +570.0 +570.0 +570.0 +627.0 +665.0 +665.0 +665.0 +665.0 +621.666666667 +600.0 +600.0 +600.0 +600.0 +559.2 +532.0 +532.0 +532.0 +532.0 +532.0 +532.0 +532.0 +532.0 +532.0 +532.0 +525.933333333 +525.0 +525.0 +525.0 +525.0 +525.0 +823.666666667 +845.0 +845.0 +845.0 +845.0 +582.733333333 +564.0 +564.0 +564.0 +564.0 +534.133333333 +532.0 +532.0 +532.0 +532.0 +532.0 +525.933333333 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +525.0 +523.266666667 +523.0 +523.0 +523.0 +523.0 +523.0 +522.2 +522.0 +522.0 +522.0 +522.0 +523.8 +525.0 +525.0 +525.0 +525.0 +551.4 +569.0 +569.0 +569.0 +569.0 +547.4 +533.0 +533.0 +533.0 +533.0 +533.0 +534.333333333 +535.0 +535.0 +535.0 +535.0 +533.8 +533.0 +533.0 +533.0 +533.0 +530.866666667 +529.0 +529.0 +529.0 +529.0 +529.0 +717.8 +883.0 +883.0 +883.0 +883.0 +960.0 +1048.0 +1048.0 +1048.0 +1048.0 +1069.0 +1111.0 +1111.0 +1111.0 +1111.0 +1126.73333333 +1170.0 +1170.0 +1170.0 +1170.0 +1170.0 +1116.13333333 +968.0 +968.0 +968.0 +968.0 +925.6 +862.0 +862.0 +862.0 +862.0 +862.0 +862.4 +863.0 +863.0 +863.0 +863.0 +810.0 +704.0 +704.0 +704.0 +704.0 +662.333333333 +579.0 +[~EOM] +sum +HDPSlaves +corp-hadoopda05.client.ext +proc_run +1389121200 +15 +1.0 +1.0 +1.0 +1.0 +1.0 +1.0 +1.0 +1.0 +1.0 +1.0 +1.0 +0.4 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.733333333333 +1.0 +1.0 +1.0 +1.0 +0.4 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.733333333333 +1.0 +1.0 +1.0 +1.0 +1.0 +0.266666666667 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.533333333333 +1.0 +1.0 +1.0 +1.0 +0.4 +0.0 +0.0 +0.0 +0.0 +0.6 +1.0 +1.0 +1.0 +1.0 +1.0 +3.4 +5.0 +5.0 +5.0 +5.0 +3.0 +2.0 +2.0 +2.0 +2.0 +0.8 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +10.2666666667 +11.0 +11.0 +11.0 +11.0 +1.66666666667 +1.0 +1.0 +1.0 +1.0 +0.0666666666667 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.866666666667 +1.0 +1.0 +1.0 +1.0 +1.0 +0.2 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.6 +1.0 +1.0 +1.0 +1.0 +1.0 +0.333333333333 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +4.8 +9.0 +9.0 +9.0 +9.0 +8.53333333333 +8.0 +8.0 +8.0 +8.0 +6.33333333333 +3.0 +3.0 +3.0 +3.0 +3.26666666667 +4.0 +4.0 +4.0 +4.0 +4.0 +6.13333333333 +12.0 +12.0 +12.0 +12.0 +12.0 +12.0 +12.0 +12.0 +12.0 +12.0 +12.4 +13.0 +13.0 +13.0 +13.0 +8.66666666667 +0.0 +0.0 +0.0 +0.0 +0.666666666667 +2.0 +[~EOM] +sum +HDPNameNode +corp-hadoopda05.client.ext +proc_total +1389121200 +15 +[~EOM] +sum +HDPNameNode +corp-hadoopda05.client.ext +proc_run +1389121200 +15 +[~EOM] +[~EOF] +1389142901.0 \ No newline at end of file
