You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by br...@apache.org on 2023/07/25 11:57:31 UTC

[ambari] branch branch-2.7 updated: AMBARI-25962: Host apps metadata is not synced to other collectors when multiple collectors are installed (#3719)

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

brahma 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 9cced38faa AMBARI-25962: Host apps metadata is not synced to other collectors when multiple collectors are installed (#3719)
9cced38faa is described below

commit 9cced38faa34678428de3d487202b2324eecb737
Author: Mohammad Arshad <ar...@apache.org>
AuthorDate: Tue Jul 25 17:27:23 2023 +0530

    AMBARI-25962: Host apps metadata is not synced to other collectors when multiple collectors are installed (#3719)
    
    Signed-off-by: Brahma Reddy Battula <br...@apache.org>
---
 .../discovery/TimelineMetricMetadataSync.java      |  3 +-
 .../core/timeline/discovery/TestMetadataSync.java  | 39 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/timeline/discovery/TimelineMetricMetadataSync.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/timeline/discovery/TimelineMetricMetadataSync.java
index 0ffff76eba..b3b8d5c334 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/timeline/discovery/TimelineMetricMetadataSync.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/timeline/discovery/TimelineMetricMetadataSync.java
@@ -200,7 +200,8 @@ public class TimelineMetricMetadataSync implements Runnable {
       Map<String, TimelineMetricHostMetadata> cachedData = cacheManager.getHostedAppsCache();
 
       for (Map.Entry<String, TimelineMetricHostMetadata> storeEntry : hostedAppsDataFromStore.entrySet()) {
-        if (!cachedData.containsKey(storeEntry.getKey())) {
+        if (!cachedData.containsKey(storeEntry.getKey()) ||
+                !cachedData.get(storeEntry.getKey()).getHostedApps().keySet().containsAll(storeEntry.getValue().getHostedApps().keySet())) {
           cachedData.put(storeEntry.getKey(), storeEntry.getValue());
         }
       }
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/ambari/metrics/core/timeline/discovery/TestMetadataSync.java b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/ambari/metrics/core/timeline/discovery/TestMetadataSync.java
index 80eb89e828..a00a788135 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/ambari/metrics/core/timeline/discovery/TestMetadataSync.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/ambari/metrics/core/timeline/discovery/TestMetadataSync.java
@@ -19,6 +19,7 @@ package org.apache.ambari.metrics.core.timeline.discovery;
 
 import junit.framework.Assert;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetricMetadata;
 import org.apache.ambari.metrics.core.timeline.PhoenixHBaseAccessor;
 import org.junit.Test;
@@ -27,6 +28,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import static com.mongodb.util.MyAsserts.assertNotNull;
 import static org.apache.hadoop.metrics2.sink.timeline.TimelineMetricMetadata.MetricType.GAUGE;
 import static org.apache.ambari.metrics.core.timeline.TimelineMetricConfiguration.TIMELINE_METRIC_METADATA_FILTERS;
 import static org.easymock.EasyMock.createNiceMock;
@@ -123,4 +125,41 @@ public class TestMetadataSync {
     Assert.assertEquals(1, metadata.size());
     Assert.assertEquals("xxx.pqr.zzz", metadata.keySet().iterator().next().getMetricName());
   }
+
+  @Test
+  public void testRefreshHostAppsOnWrite() throws Exception {
+    Configuration configuration = createNiceMock(Configuration.class);
+    PhoenixHBaseAccessor hBaseAccessor = createNiceMock(PhoenixHBaseAccessor.class);
+    Map<String, TimelineMetricHostMetadata> hostedApps = new HashMap<String, TimelineMetricHostMetadata>() {{
+      put("host1", new TimelineMetricHostMetadata(new HashSet<>(Arrays.asList("app1", "app2", "app3"))));
+    }};
+
+    expect(configuration.get("timeline.metrics.service.operation.mode")).andReturn("distributed");
+    expect(hBaseAccessor.getHostedAppsMetadata()).andReturn(hostedApps);
+    replay(configuration, hBaseAccessor);
+
+    // register host1 --> (app1,app2)
+    TimelineMetricMetadataManager metadataManager = new TimelineMetricMetadataManager(configuration, hBaseAccessor);
+    TimelineMetric tm1=new TimelineMetric("metric1","host1","app1",null );
+    TimelineMetric tm2=new TimelineMetric("metric2","host1","app2",null );
+    byte[] uuid1 = metadataManager.getUuid(tm1, true);
+    assertNotNull(uuid1);
+    byte[] uuid2 = metadataManager.getUuid(tm2, true);
+    assertNotNull(uuid2);
+    metadataManager.markSuccessOnSyncHostedAppsMetadata();
+
+    hostedApps = metadataManager.getHostedAppsCache();
+    // Before other collector's host app data is synced
+    Assert.assertEquals(2, hostedApps.get("host1").getHostedApps().size());
+
+    metadataManager.metricMetadataSync = new TimelineMetricMetadataSync(metadataManager);
+    metadataManager.metricMetadataSync.run();
+
+    verify(configuration, hBaseAccessor);
+
+    hostedApps = metadataManager.getHostedAppsCache();
+    Assert.assertEquals(1, hostedApps.size());
+    // After other collector's host app data is synced
+    Assert.assertEquals("Host app list is not synced properly",3, hostedApps.get("host1").getHostedApps().size());
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org