This is an automated email from the ASF dual-hosted git repository. swagle pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new 3a52f27 AMBARI-23015 Added NaN handling to JSON handling in MetricsRetrievalService.java (#396) 3a52f27 is described below commit 3a52f278961406d198f4e89c30e49f989f26c143 Author: majorendre <34535487+majoren...@users.noreply.github.com> AuthorDate: Fri Feb 16 22:05:55 2018 +0100 AMBARI-23015 Added NaN handling to JSON handling in MetricsRetrievalService.java (#396) [AMBARI-23015] Added NaN handling to JSON handling in MetricsRetrievalService --- .../state/services/MetricsRetrievalService.java | 2 ++ .../services/MetricsRetrievalServiceTest.java | 36 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/services/MetricsRetrievalService.java b/ambari-server/src/main/java/org/apache/ambari/server/state/services/MetricsRetrievalService.java index 72ef1c0..10f2b05 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/services/MetricsRetrievalService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/services/MetricsRetrievalService.java @@ -39,6 +39,7 @@ import org.apache.ambari.server.controller.jmx.JMXMetricHolder; import org.apache.ambari.server.controller.utilities.ScalingThreadPoolExecutor; import org.apache.ambari.server.controller.utilities.StreamProvider; import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectReader; @@ -182,6 +183,7 @@ public class MetricsRetrievalService extends AbstractService { public MetricsRetrievalService() { ObjectMapper jmxObjectMapper = new ObjectMapper(); jmxObjectMapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false); + jmxObjectMapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true); m_jmxObjectReader = jmxObjectMapper.reader(JMXMetricHolder.class); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/services/MetricsRetrievalServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/services/MetricsRetrievalServiceTest.java index e6a6f81..4017a8e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/services/MetricsRetrievalServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/services/MetricsRetrievalServiceTest.java @@ -196,6 +196,42 @@ public class MetricsRetrievalServiceTest extends EasyMockSupport { } /** + * Tests handling NaN in JSON. + */ + @Test + public void testJsonNaN() throws Exception { + + InputStream jmxInputStream = IOUtils.toInputStream("{ \"beans\": [ " + + " {\n" + + " \"name\" : \"Hadoop:service=HBase,name=RegionServer,sub=Server\",\n" + + " \"modelerType\" : \"RegionServer,sub=Server\", \"l1CacheMissCount\" : 0,\n" + + " \"l1CacheHitRatio\" : NaN,\n" + + " \"l1CacheMissRatio\" : NaN,\n" + + " \"l2CacheHitCount\" : 0" + + " }] " + + "}"); + + StreamProvider streamProvider = createNiceMock(StreamProvider.class); + + EasyMock.expect(streamProvider.readFrom(JMX_URL)).andReturn(jmxInputStream).once(); + + replayAll(); + + m_service.startAsync(); + m_service.awaitRunning(METRICS_SERVICE_TIMEOUT, TimeUnit.SECONDS); + + // make the service synchronous + m_service.setThreadPoolExecutor(new SynchronousThreadPoolExecutor()); + + JMXMetricHolder jmxMetricHolder = m_service.getCachedJMXMetric(JMX_URL); + Assert.assertNull(jmxMetricHolder); + + m_service.submitRequest(MetricSourceType.JMX, streamProvider, JMX_URL); + jmxMetricHolder = m_service.getCachedJMXMetric(JMX_URL); + Assert.assertNotNull(jmxMetricHolder); + } + + /** * Tests that many requests to the same URL do not invoke the stream provider * more than once. */ -- To stop receiving notification emails like this one, please contact swa...@apache.org.