Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B92BB200BA5 for ; Tue, 4 Oct 2016 20:32:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B7E0A160AC7; Tue, 4 Oct 2016 18:32:44 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CE498160ACC for ; Tue, 4 Oct 2016 20:32:43 +0200 (CEST) Received: (qmail 76223 invoked by uid 500); 4 Oct 2016 18:32:43 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 76158 invoked by uid 99); 4 Oct 2016 18:32:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2016 18:32:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C8893E0AD9; Tue, 4 Oct 2016 18:32:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: avijayan@apache.org To: commits@ambari.apache.org Date: Tue, 04 Oct 2016 18:32:44 -0000 Message-Id: <195b5725043342818f0e14952c2cca1f@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/3] ambari git commit: AMBARI-18518 : Sinks should not try to read collector hosts from Zk if AMS is in embedded mode. (avijayan) archived-at: Tue, 04 Oct 2016 18:32:44 -0000 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 Authored: Tue Oct 4 11:23:32 2016 -0700 Committer: Aravindan Vijayan 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>() { @Override public List 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 liveInstances = metricCollectorHAHelper.findLiveCollectorHostsFromZNode(); + verifyAll(); + Assert.assertTrue(liveInstances.isEmpty()); + } + @Test public void findCollectorUsingKnownCollectorTest() throws Exception { HttpURLConnection connection = createNiceMock(HttpURLConnection.class);