This is an automated email from the ASF dual-hosted git repository.

mpapirkovskyy pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new 7388ded  AMBARI-25414. Configure heartbeat timeout. (mpapirkovskyy) 
(#3134)
7388ded is described below

commit 7388dedff41910021cb400a771ec25a8f7bd747e
Author: Myroslav Papirkovskyi <mpapirkovs...@apache.org>
AuthorDate: Fri Nov 22 16:38:42 2019 +0200

    AMBARI-25414. Configure heartbeat timeout. (mpapirkovskyy) (#3134)
---
 .../ambari/server/agent/HeartBeatHandler.java      |  7 +++---
 .../ambari/server/configuration/Configuration.java | 12 +++++++++-
 .../server/agent/HeartbeatProcessorTest.java       |  2 +-
 .../ambari/server/agent/HeartbeatTestHelper.java   |  6 ++++-
 .../ambari/server/agent/TestHeartbeatHandler.java  | 26 +++++++++++-----------
 .../ambari/server/agent/TestHeartbeatMonitor.java  | 25 ++++++++++++++++-----
 .../apache/ambari/server/state/host/HostTest.java  |  4 +++-
 7 files changed, 55 insertions(+), 27 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index 1c225a9..f5e8e06 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -76,8 +76,6 @@ public class HeartBeatHandler {
   private final ActionManager actionManager;
   private HeartbeatMonitor heartbeatMonitor;
   private HeartbeatProcessor heartbeatProcessor;
-
-  @Inject
   private Configuration config;
 
   @Inject
@@ -109,11 +107,12 @@ public class HeartBeatHandler {
   private Map<String, HeartBeatResponse> hostResponses = new 
ConcurrentHashMap<>();
 
   @Inject
-  public HeartBeatHandler(Clusters fsm, ActionManager am,
+  public HeartBeatHandler(Configuration c, Clusters fsm, ActionManager am,
                           Injector injector) {
+    config = c;
     clusterFsm = fsm;
     actionManager = am;
-    heartbeatMonitor = new HeartbeatMonitor(fsm, am, 60000, injector);
+    heartbeatMonitor = new HeartbeatMonitor(fsm, am, 
config.getHeartbeatMonitorInterval(), injector);
     heartbeatProcessor = new HeartbeatProcessor(fsm, am, heartbeatMonitor, 
injector); //TODO modify to match pattern
     injector.injectMembers(this);
   }
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 87549a8..d9353ff 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -323,6 +323,12 @@ public class Configuration {
   // Ambari server log4j file name
   public static final String AMBARI_LOG_FILE = "log4j.properties";
 
+  @Markdown(
+    description = "Interval for heartbeat presence checks.",
+    examples = {"60000","600000"} )
+  public static final ConfigurationProperty<Integer> 
HEARTBEAT_MONITORING_INTERVAL = new ConfigurationProperty<>(
+    "heartbeat.monitoring.interval",60000);
+
   /**
    * The directory on the Ambari Server file system used for storing
    * Ambari Agent bootstrap information such as request responses.
@@ -3358,6 +3364,10 @@ public class Configuration {
     return getProperty(SYS_PREPPED_HOSTS);
   }
 
+  public Integer getHeartbeatMonitorInterval() {
+    return Integer.parseInt(getProperty(HEARTBEAT_MONITORING_INTERVAL));
+  }
+
   /**
    * Return {@code true} if we forced to work with legacy repositories
    *
@@ -5594,7 +5604,7 @@ public class Configuration {
   public int getKerberosServerActionFinalizeTimeout() {
     return 
Integer.parseInt(getProperty(KERBEROS_SERVER_ACTION_FINALIZE_SECONDS));
   }
-  
+
   /**
    * Generates a markdown table which includes:
    * <ul>
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
index 83e7303..c3f9cd2 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
@@ -1046,7 +1046,7 @@ public class HeartbeatProcessorTest {
     hostObject.setIPv6("ipv6");
     hostObject.setOsType(DummyOsType);
 
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am, injector);
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am, injector);
     Register reg = new Register();
     HostInfo hi = new HostInfo();
     hi.setHostName(DummyHostname1);
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
index fd6fc02..bcddf24 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
@@ -44,6 +44,7 @@ import org.apache.ambari.server.actionmanager.Request;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.events.publishers.STOMPUpdatePublisher;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.OrmTestHelper;
@@ -82,6 +83,9 @@ public class HeartbeatTestHelper {
   Clusters clusters;
 
   @Inject
+  Configuration configuration;
+
+  @Inject
   Injector injector;
 
   @Inject
@@ -126,7 +130,7 @@ public class HeartbeatTestHelper {
 
   public HeartBeatHandler getHeartBeatHandler(ActionManager am)
       throws InvalidStateTransitionException, AmbariException {
-    HeartBeatHandler handler = new HeartBeatHandler(clusters, am, injector);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, clusters, 
am, injector);
     Register reg = new Register();
     HostInfo hi = new HostInfo();
     hi.setHostName(DummyHostname1);
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index c5bac8b..f00bf00 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@ -211,7 +211,7 @@ public class TestHeartbeatHandler {
 
     String hostname = hostObject.getHostName();
 
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am, injector);
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am, injector);
     Register reg = new Register();
     HostInfo hi = new HostInfo();
     hi.setHostName(hostname);
@@ -362,7 +362,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
         injector);
     clusters.addHost(DummyHostname1);
     Host hostObject = clusters.getHost(DummyHostname1);
@@ -410,7 +410,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
         injector);
     handler.start();
 
@@ -458,7 +458,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
             injector);
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = addService(cluster, HDFS);
@@ -509,7 +509,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
                                                     injector);
     clusters.addHost(DummyHostname1);
     Host hostObject = clusters.getHost(DummyHostname1);
@@ -542,7 +542,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
         injector);
     clusters.addHost(DummyHostname1);
     Host hostObject = clusters.getHost(DummyHostname1);
@@ -583,7 +583,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
         injector);
     clusters.addHost(DummyHostname1);
     Host hostObject = clusters.getHost(DummyHostname1);
@@ -616,7 +616,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
         injector);
     clusters.addHost(DummyHostname1);
     Host hostObject = clusters.getHost(DummyHostname1);
@@ -645,7 +645,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
             injector);
     clusters.addHost(DummyHostname1);
     Host hostObject = clusters.getHost(DummyHostname1);
@@ -678,7 +678,7 @@ public class TestHeartbeatHandler {
     hostObject.setIPv4("ipv4");
     hostObject.setIPv6("ipv6");
 
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
         injector);
     Register reg = new Register();
     HostInfo hi = new HostInfo();
@@ -766,7 +766,7 @@ public class TestHeartbeatHandler {
     ActionManager am = actionManagerTestHelper.getMockActionManager();
     replay(am);
     Clusters fsm = clusters;
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am,
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am,
         injector);
     handler.setHeartbeatMonitor(hm);
     clusters.addHost(DummyHostname1);
@@ -989,7 +989,7 @@ public class TestHeartbeatHandler {
           add(command);
         }}).anyTimes();
     replay(am);
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am, injector);
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am, injector);
 
     Register reg = new Register();
     HostInfo hi = new HostInfo();
@@ -1070,7 +1070,7 @@ public class TestHeartbeatHandler {
               add(command);
             }}).anyTimes();
     replay(am);
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am, injector);
+    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am, injector);
     HeartbeatProcessor heartbeatProcessor = handler.getHeartbeatProcessor();
 
     Register reg = new Register();
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index 33ea633..281164b 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.sql.SQLException;
 import java.util.Collections;
@@ -117,8 +118,10 @@ public class TestHeartbeatMonitor {
     String hostname = "host1";
     fsm.addHost(hostname);
     ActionManager am = mock(ActionManager.class);
+    Configuration configuration = mock(Configuration.class);
+    when(configuration.getHeartbeatMonitorInterval()).thenReturn(10);
     HeartbeatMonitor hm = new HeartbeatMonitor(fsm, am, 10, injector);
-    HeartBeatHandler handler = new HeartBeatHandler(fsm, am, injector);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, fsm, am, 
injector);
     Register reg = new Register();
     reg.setHostname(hostname);
     reg.setResponseId(12);
@@ -186,7 +189,9 @@ public class TestHeartbeatMonitor {
     ActionManager am = mock(ActionManager.class);
     HeartbeatMonitor hm = new HeartbeatMonitor(clusters, am,
       heartbeatMonitorWakeupIntervalMS, injector);
-    HeartBeatHandler handler = new HeartBeatHandler(clusters, am, injector);
+    Configuration configuration = mock(Configuration.class);
+    when(configuration.getHeartbeatMonitorInterval()).thenReturn(60000);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, clusters, 
am, injector);
     Register reg = new Register();
     reg.setHostname(hostname1);
     reg.setResponseId(12);
@@ -305,7 +310,9 @@ public class TestHeartbeatMonitor {
     ActionManager am = mock(ActionManager.class);
     HeartbeatMonitor hm = new HeartbeatMonitor(clusters, am,
       heartbeatMonitorWakeupIntervalMS, injector);
-    HeartBeatHandler handler = new HeartBeatHandler(clusters, am, injector);
+    Configuration configuration = mock(Configuration.class);
+    when(configuration.getHeartbeatMonitorInterval()).thenReturn(60000);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, clusters, 
am, injector);
     Register reg = new Register();
     reg.setHostname(hostname1);
     reg.setResponseId(12);
@@ -400,7 +407,9 @@ public class TestHeartbeatMonitor {
     ActionManager am = mock(ActionManager.class);
     HeartbeatMonitor hm = new HeartbeatMonitor(clusters, am,
       heartbeatMonitorWakeupIntervalMS, injector);
-    HeartBeatHandler handler = new HeartBeatHandler(clusters, am,
+    Configuration configuration = mock(Configuration.class);
+    when(configuration.getHeartbeatMonitorInterval()).thenReturn(60000);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, clusters, 
am,
         injector);
     Register reg = new Register();
     reg.setHostname(hostname1);
@@ -476,7 +485,9 @@ public class TestHeartbeatMonitor {
 
     ActionManager am = mock(ActionManager.class);
     HeartbeatMonitor hm = new HeartbeatMonitor(clusters, am, 10, injector);
-    HeartBeatHandler handler = new HeartBeatHandler(clusters, am, injector);
+    Configuration configuration = mock(Configuration.class);
+    when(configuration.getHeartbeatMonitorInterval()).thenReturn(10);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, clusters, 
am, injector);
 
     Register reg = new Register();
     reg.setHostname(hostname1);
@@ -598,7 +609,9 @@ public class TestHeartbeatMonitor {
     ActionManager am = mock(ActionManager.class);
     HeartbeatMonitor hm = new HeartbeatMonitor(clusters, am,
       heartbeatMonitorWakeupIntervalMS, injector);
-    HeartBeatHandler handler = new HeartBeatHandler(clusters, am, injector);
+    Configuration configuration = mock(Configuration.class);
+    when(configuration.getHeartbeatMonitorInterval()).thenReturn(60000);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, clusters, 
am, injector);
     Register reg = new Register();
     reg.setHostname(hostname1);
     reg.setResponseId(12);
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java 
b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
index 7d4737b..054d632 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
@@ -38,6 +38,7 @@ import org.apache.ambari.server.agent.DiskInfo;
 import org.apache.ambari.server.agent.HeartBeatHandler;
 import org.apache.ambari.server.agent.HostInfo;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -130,9 +131,10 @@ public class HostTest {
     Clusters clusters = mock(Clusters.class);
     ActionManager manager = mock(ActionManager.class);
     Injector injector = mock(Injector.class);
+    Configuration configuration = mock(Configuration.class);
     doNothing().when(injector).injectMembers(any());
     
when(injector.getInstance(AmbariEventPublisher.class)).thenReturn(mock(AmbariEventPublisher.class));
-    HeartBeatHandler handler = new HeartBeatHandler(clusters, manager, 
injector);
+    HeartBeatHandler handler = new HeartBeatHandler(configuration, clusters, 
manager, injector);
     String os = handler.getOsType("RedHat", "6.1");
     Assert.assertEquals("redhat6", os);
     os = handler.getOsType("RedHat", "6");

Reply via email to