ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-13882 Flume agent does not display metrics (dsen)
Date Fri, 13 Nov 2015 15:22:52 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 090905be3 -> 52346faba


AMBARI-13882 Flume agent does not display metrics (dsen)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/52346fab
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/52346fab
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/52346fab

Branch: refs/heads/trunk
Commit: 52346faba7af51f326ff7c35f0942019fe6c137d
Parents: 090905b
Author: Dmytro Sen <dsen@apache.org>
Authored: Fri Nov 13 17:22:40 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Fri Nov 13 17:22:40 2015 +0200

----------------------------------------------------------------------
 .../timeline/AbstractTimelineMetricsSink.java   |  2 +-
 .../sink/flume/FlumeTimelineMetricsSink.java    |  4 ++
 .../flume/FlumeTimelineMetricsSinkTest.java     | 61 ++++++++++++++++++++
 .../kafka/KafkaTimelineMetricsReporter.java     |  4 ++
 .../storm/StormTimelineMetricsReporter.java     |  4 ++
 .../sink/storm/StormTimelineMetricsSink.java    |  4 ++
 .../webapp/TimelineWebServices.java             |  5 +-
 7 files changed, 79 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/52346fab/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
index 5aba016..78d9210 100644
--- a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
+++ b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
@@ -37,8 +37,8 @@ public abstract class AbstractTimelineMetricsSink {
   public static final String METRICS_POST_TIMEOUT_SECONDS = "timeout";
   public static final String COLLECTOR_HOST_PROPERTY = "collector";
   public static final String COLLECTOR_PORT_PROPERTY = "port";
+  public static final int DEFAULT_POST_TIMEOUT_SECONDS = 10;
 
-  protected static final int DEFAULT_POST_TIMEOUT_SECONDS = 10;
   protected final Log LOG;
   private HttpClient httpClient = new HttpClient();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/52346fab/ambari-metrics/ambari-metrics-flume-sink/src/main/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSink.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-flume-sink/src/main/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSink.java
b/ambari-metrics/ambari-metrics-flume-sink/src/main/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSink.java
index 530c8c1..0257ada 100644
--- a/ambari-metrics/ambari-metrics-flume-sink/src/main/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSink.java
+++ b/ambari-metrics/ambari-metrics-flume-sink/src/main/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSink.java
@@ -80,6 +80,10 @@ public class FlumeTimelineMetricsSink extends AbstractTimelineMetricsSink
implem
     LOG.info("Context parameters " + context);
     try {
       hostname = InetAddress.getLocalHost().getHostName();
+      //If not FQDN , call  DNS
+      if ((hostname == null) || (!hostname.contains("."))) {
+        hostname = InetAddress.getLocalHost().getCanonicalHostName();
+      }
     } catch (UnknownHostException e) {
       LOG.error("Could not identify hostname.");
       throw new FlumeException("Could not identify hostname.", e);

http://git-wip-us.apache.org/repos/asf/ambari/blob/52346fab/ambari-metrics/ambari-metrics-flume-sink/src/test/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSinkTest.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-flume-sink/src/test/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSinkTest.java
b/ambari-metrics/ambari-metrics-flume-sink/src/test/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSinkTest.java
index fa1ca21..eca742d 100644
--- a/ambari-metrics/ambari-metrics-flume-sink/src/test/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSinkTest.java
+++ b/ambari-metrics/ambari-metrics-flume-sink/src/test/java/org/apache/hadoop/metrics2/sink/flume/FlumeTimelineMetricsSinkTest.java
@@ -18,19 +18,28 @@
 
 package org.apache.hadoop.metrics2.sink.flume;
 
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
 import static org.powermock.api.easymock.PowerMock.mockStatic;
 import static org.powermock.api.easymock.PowerMock.replay;
+import static org.powermock.api.easymock.PowerMock.replayAll;
+import static org.powermock.api.easymock.PowerMock.resetAll;
 import static org.powermock.api.easymock.PowerMock.verifyAll;
 
+import java.net.InetAddress;
 import java.util.Collections;
 
 import org.apache.commons.httpclient.HttpClient;
+import org.apache.flume.Context;
 import org.apache.flume.instrumentation.util.JMXPollUtil;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
 import org.apache.hadoop.metrics2.sink.timeline.cache.TimelineMetricsCache;
+import org.apache.hadoop.metrics2.sink.timeline.configuration.Configuration;
 import org.easymock.EasyMock;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
@@ -104,4 +113,56 @@ public class FlumeTimelineMetricsSinkTest {
     collector.run();
     verifyAll();
   }
+
+  @Test
+  @PrepareForTest({Configuration.class, FlumeTimelineMetricsSink.class})
+  public void testGettingFqdn() throws Exception {
+    FlumeTimelineMetricsSink flumeTimelineMetricsSink = new FlumeTimelineMetricsSink();
+    Configuration config = createNiceMock(Configuration.class);
+
+    expect(config.getProperty(anyString(), anyString()))
+      .andReturn("60")
+      .anyTimes();
+    expect(config.getProperty(anyString()))
+      .andReturn("60")
+      .anyTimes();
+    replay(config);
+
+    PowerMock.expectNew(Configuration.class, anyString())
+      .andReturn(config);
+    replay(Configuration.class);
+
+    // getHostName() returned FQDN
+    InetAddress address = createNiceMock(InetAddress.class);
+    expect(address.getHostName()).andReturn("hostname.domain").once();
+    replay(address);
+
+    mockStatic(InetAddress.class);
+    expect(InetAddress.getLocalHost()).andReturn(address).once();
+    replay(InetAddress.class);
+
+    flumeTimelineMetricsSink.configure(new Context());
+    verifyAll();
+
+    resetAll();
+
+    PowerMock.expectNew(Configuration.class, anyString())
+      .andReturn(config);
+    replay(Configuration.class);
+
+    // getHostName() returned short hostname, getCanonicalHostName() called
+    address = createNiceMock(InetAddress.class);
+    expect(address.getHostName()).andReturn("hostname").once();
+    expect(address.getCanonicalHostName()).andReturn("hostname.domain").once();
+    replay(address);
+
+    mockStatic(InetAddress.class);
+    expect(InetAddress.getLocalHost()).andReturn(address).times(2);
+    replay(InetAddress.class);
+
+    flumeTimelineMetricsSink.configure(new Context());
+    verifyAll();
+
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/52346fab/ambari-metrics/ambari-metrics-kafka-sink/src/main/java/org/apache/hadoop/metrics2/sink/kafka/KafkaTimelineMetricsReporter.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-kafka-sink/src/main/java/org/apache/hadoop/metrics2/sink/kafka/KafkaTimelineMetricsReporter.java
b/ambari-metrics/ambari-metrics-kafka-sink/src/main/java/org/apache/hadoop/metrics2/sink/kafka/KafkaTimelineMetricsReporter.java
index dd7604b..1d1b6df 100644
--- a/ambari-metrics/ambari-metrics-kafka-sink/src/main/java/org/apache/hadoop/metrics2/sink/kafka/KafkaTimelineMetricsReporter.java
+++ b/ambari-metrics/ambari-metrics-kafka-sink/src/main/java/org/apache/hadoop/metrics2/sink/kafka/KafkaTimelineMetricsReporter.java
@@ -108,6 +108,10 @@ public class KafkaTimelineMetricsReporter extends AbstractTimelineMetricsSink
         LOG.info("Initializing Kafka Timeline Metrics Sink");
         try {
           hostname = InetAddress.getLocalHost().getHostName();
+          //If not FQDN , call  DNS
+          if ((hostname == null) || (!hostname.contains("."))) {
+            hostname = InetAddress.getLocalHost().getCanonicalHostName();
+          }
         } catch (UnknownHostException e) {
           LOG.error("Could not identify hostname.");
           throw new RuntimeException("Could not identify hostname.", e);

http://git-wip-us.apache.org/repos/asf/ambari/blob/52346fab/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsReporter.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsReporter.java
b/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsReporter.java
index 5e27cf8..73e3de8 100644
--- a/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsReporter.java
+++ b/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsReporter.java
@@ -71,6 +71,10 @@ public class StormTimelineMetricsReporter extends AbstractTimelineMetricsSink
     try {
       try {
         hostname = InetAddress.getLocalHost().getHostName();
+        //If not FQDN , call  DNS
+        if ((hostname == null) || (!hostname.contains("."))) {
+          hostname = InetAddress.getLocalHost().getCanonicalHostName();
+        }
       } catch (UnknownHostException e) {
         LOG.error("Could not identify hostname.");
         throw new RuntimeException("Could not identify hostname.", e);

http://git-wip-us.apache.org/repos/asf/ambari/blob/52346fab/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsSink.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsSink.java
b/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsSink.java
index 3a49e0a..0edc342 100644
--- a/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsSink.java
+++ b/ambari-metrics/ambari-metrics-storm-sink/src/main/java/org/apache/hadoop/metrics2/sink/storm/StormTimelineMetricsSink.java
@@ -62,6 +62,10 @@ public class StormTimelineMetricsSink extends AbstractTimelineMetricsSink
implem
     LOG.info("Preparing Storm Metrics Sink");
     try {
       hostname = InetAddress.getLocalHost().getHostName();
+      //If not FQDN , call  DNS
+      if ((hostname == null) || (!hostname.contains("."))) {
+        hostname = InetAddress.getLocalHost().getCanonicalHostName();
+      }
     } catch (UnknownHostException e) {
       LOG.error("Could not identify hostname.");
       throw new RuntimeException("Could not identify hostname.", e);

http://git-wip-us.apache.org/repos/asf/ambari/blob/52346fab/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TimelineWebServices.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TimelineWebServices.java
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TimelineWebServices.java
index ecfbe78..a13086a 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TimelineWebServices.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TimelineWebServices.java
@@ -319,12 +319,9 @@ public class TimelineWebServices {
         "or hours");
     } catch (IllegalArgumentException iae) {
       throw new BadRequestException(iae.getMessage());
-    } catch (SQLException sql) {
+    } catch (SQLException | IOException sql) {
       throw new WebApplicationException(sql,
         Response.Status.INTERNAL_SERVER_ERROR);
-    } catch (IOException io) {
-      throw new WebApplicationException(io,
-        Response.Status.INTERNAL_SERVER_ERROR);
     }
   }
 


Mime
View raw message