You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by av...@apache.org on 2016/10/04 18:32:44 UTC
[3/3] ambari git commit: AMBARI-18518 : Sinks should not try to read
collector hosts from Zk if AMS is in embedded mode. (avijayan)
AMBARI-18518 : Sinks should not try to read collector hosts from Zk if AMS is in embedded mode. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/98efb571
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/98efb571
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/98efb571
Branch: refs/heads/trunk
Commit: 98efb571d63a17973bb62a510593c2041c14dcf6
Parents: c10053b
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Oct 4 11:23:32 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Tue Oct 4 11:23:32 2016 -0700
----------------------------------------------------------------------
.../availability/MetricCollectorHAHelper.java | 10 +++++-
.../availability/MetricCollectorHATest.java | 34 +++++++++++++++++++-
2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/98efb571/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHAHelper.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHAHelper.java b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHAHelper.java
index 2254362..e7f7cfd 100644
--- a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHAHelper.java
+++ b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHAHelper.java
@@ -25,6 +25,7 @@ import org.apache.curator.RetryPolicy;
import org.apache.curator.retry.BoundedExponentialBackoffRetry;
import org.apache.curator.retry.RetryUntilElapsed;
import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.data.Stat;
import java.util.Collection;
import java.util.HashSet;
@@ -44,7 +45,8 @@ public class MetricCollectorHAHelper {
private static final int CONNECTION_TIMEOUT = 2000;
private static final int SESSION_TIMEOUT = 10000;
- private static final String ZK_PATH = "/ambari-metrics-cluster/LIVEINSTANCES";
+ private static final String ZNODE = "/ambari-metrics-cluster";
+ private static final String ZK_PATH = ZNODE + "/LIVEINSTANCES";
private static final String INSTANCE_NAME_DELIMITER = "_";
@@ -72,6 +74,12 @@ public class MetricCollectorHAHelper {
try {
client.start();
+ //Check if Znode exists
+ Stat stat = client.getZooKeeper().exists(ZNODE, false);
+ if (stat == null) {
+ LOG.info("/ambari-metrics-cluster znode does not exist. Skipping requesting live instances from zookeeper");
+ return collectors;
+ }
liveInstances = RetryLoop.callWithRetry(client, new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
http://git-wip-us.apache.org/repos/asf/ambari/blob/98efb571/ambari-metrics/ambari-metrics-common/src/test/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHATest.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-common/src/test/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHATest.java b/ambari-metrics/ambari-metrics-common/src/test/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHATest.java
index ac1f52d..3d00270 100644
--- a/ambari-metrics/ambari-metrics-common/src/test/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHATest.java
+++ b/ambari-metrics/ambari-metrics-common/src/test/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricCollectorHATest.java
@@ -20,9 +20,13 @@ package org.apache.hadoop.metrics2.sink.timeline.availability;
import com.google.gson.Gson;
import junit.framework.Assert;
import org.apache.commons.io.IOUtils;
+import org.apache.curator.CuratorZookeeperClient;
+import org.apache.curator.retry.BoundedExponentialBackoffRetry;
import org.apache.hadoop.metrics2.sink.timeline.AbstractTimelineMetricsSink;
+import org.apache.zookeeper.ZooKeeper;
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;
import java.io.IOException;
@@ -34,13 +38,14 @@ import java.util.Arrays;
import java.util.Collection;
import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
import static org.powermock.api.easymock.PowerMock.createNiceMock;
import static org.powermock.api.easymock.PowerMock.expectNew;
import static org.powermock.api.easymock.PowerMock.replayAll;
import static org.powermock.api.easymock.PowerMock.verifyAll;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({AbstractTimelineMetricsSink.class, URL.class, HttpURLConnection.class})
+@PrepareForTest({AbstractTimelineMetricsSink.class, URL.class, HttpURLConnection.class, MetricCollectorHAHelper.class})
public class MetricCollectorHATest {
@Test
@@ -71,6 +76,33 @@ public class MetricCollectorHATest {
}
+
+ @Test
+ public void testEmbeddedModeCollectorZK() throws Exception {
+
+
+ BoundedExponentialBackoffRetry retryPolicyMock = PowerMock.createMock(BoundedExponentialBackoffRetry.class);
+ expectNew(BoundedExponentialBackoffRetry.class, 1000, 10000, 1).andReturn(retryPolicyMock);
+
+ CuratorZookeeperClient clientMock = PowerMock.createMock(CuratorZookeeperClient.class);
+ expectNew(CuratorZookeeperClient.class, "zkQ", 10000, 2000, null, retryPolicyMock)
+ .andReturn(clientMock);
+
+ clientMock.start();
+ expectLastCall().once();
+
+ ZooKeeper zkMock = PowerMock.createMock(ZooKeeper.class);
+ expect(clientMock.getZooKeeper()).andReturn(zkMock).once();
+
+ expect(zkMock.exists("/ambari-metrics-cluster", false)).andReturn(null).once();
+
+ replayAll();
+ MetricCollectorHAHelper metricCollectorHAHelper = new MetricCollectorHAHelper("zkQ", 1, 1000);
+ Collection<String> liveInstances = metricCollectorHAHelper.findLiveCollectorHostsFromZNode();
+ verifyAll();
+ Assert.assertTrue(liveInstances.isEmpty());
+ }
+
@Test
public void findCollectorUsingKnownCollectorTest() throws Exception {
HttpURLConnection connection = createNiceMock(HttpURLConnection.class);