ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgerg...@apache.org
Subject ambari git commit: AMBARI-21881. Fix Log Search upgrade to 3.0.0 (mgergely)
Date Wed, 06 Sep 2017 08:52:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 6e69f214c -> 0034da609


AMBARI-21881. Fix Log Search upgrade to 3.0.0 (mgergely)

Change-Id: I5557892cfd528616697a6c8ffa4b5b2b6f4fc80a


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

Branch: refs/heads/trunk
Commit: 0034da609c3587df662278d2bf613b3ca92c276e
Parents: 6e69f21
Author: Miklos Gergely <mgergely@hortonworks.com>
Authored: Wed Sep 6 10:52:41 2017 +0200
Committer: Miklos Gergely <mgergely@hortonworks.com>
Committed: Wed Sep 6 10:52:41 2017 +0200

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog300.java       | 21 ++++++-----
 .../server/upgrade/UpgradeCatalog300Test.java   | 37 ++++++++------------
 2 files changed, 25 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0034da60/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java
index 9255163..bfe2a13 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java
@@ -23,7 +23,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -45,6 +44,7 @@ import org.apache.ambari.server.orm.entities.StageEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -238,21 +238,15 @@ public class UpgradeCatalog300 extends AbstractUpgradeCatalog {
     if (clusters != null) {
       Map<String, Cluster> clusterMap = clusters.getClusters();
 
+      ConfigHelper configHelper = injector.getInstance(ConfigHelper.class);
       if (clusterMap != null && !clusterMap.isEmpty()) {
         for (final Cluster cluster : clusterMap.values()) {
           Collection<Config> configs = cluster.getAllConfigs();
           for (Config config : configs) {
             String configType = config.getType();
-            if (!configType.endsWith("-logsearch-conf")) {
-              continue;
+            if (configType.endsWith("-logsearch-conf")) {
+              configHelper.removeConfigsByType(cluster, configType);
             }
-
-            Set<String> removeProperties = new HashSet<>();
-            removeProperties.add("service_name");
-            removeProperties.add("component_mappings");
-            removeProperties.add("content");
-
-            removeConfigurationPropertiesFromCluster(cluster, configType, removeProperties);
           }
 
           Config logSearchEnv = cluster.getDesiredConfigByType("logsearch-env");
@@ -267,6 +261,11 @@ public class UpgradeCatalog300 extends AbstractUpgradeCatalog {
           Config logSearchProperties = cluster.getDesiredConfigByType("logsearch-properties");
           Config logFeederProperties = cluster.getDesiredConfigByType("logfeeder-properties");
           if (logSearchProperties != null && logFeederProperties != null) {
+            configHelper.createConfigType(cluster, cluster.getDesiredStackVersion(), ambariManagementController,
+                "logsearch-common-properties", Collections.emptyMap(), "ambari-upgrade",
+                String.format("Updated logsearch-common-properties during Ambari Upgrade
from %s to %s",
+                    getSourceVersion(), getTargetVersion()));
+            
             String defaultLogLevels = logSearchProperties.getProperties().get("logsearch.logfeeder.include.default.level");
 
             Set<String> removeProperties = Sets.newHashSet("logsearch.logfeeder.include.default.level");
@@ -341,7 +340,7 @@ public class UpgradeCatalog300 extends AbstractUpgradeCatalog {
                 "      \"splits_interval_mins\": \"{{logsearch_audit_logs_split_interval_mins}}\",\n",
                 "      \"type\": \"audit\",\n");
 
-            updateConfigurationPropertiesForCluster(cluster, "logsearch-output-config", Collections.singletonMap("content",
content), true, true);
+            updateConfigurationPropertiesForCluster(cluster, "logfeeder-output-config", Collections.singletonMap("content",
content), true, true);
           }
         }
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0034da60/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
index 53518dd..25e9dbf 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
@@ -32,14 +32,12 @@ import static org.easymock.EasyMock.newCapture;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.reset;
 import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 
 import javax.persistence.EntityManager;
@@ -53,10 +51,10 @@ import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.Capture;
-import org.easymock.CaptureType;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockRunner;
 import org.easymock.EasyMockSupport;
@@ -200,10 +198,15 @@ public class UpgradeCatalog300Test {
         .addMockedMethod("createConfiguration")
         .addMockedMethod("getClusters", new Class[]{})
         .addMockedMethod("createConfig")
-        .withConstructor(actionManager, clusters, injector)
         .createNiceMock();
+    ConfigHelper configHelper = createMockBuilder(ConfigHelper.class)
+        .addMockedMethod("removeConfigsByType")
+        .addMockedMethod("createConfigType", Cluster.class, StackId.class, AmbariManagementController.class,
+            String.class, Map.class, String.class, String.class)
+        .createMock();
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
+    expect(injector2.getInstance(ConfigHelper.class)).andReturn(configHelper).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
 
     Config confSomethingElse1 = easyMockSupport.createNiceMock(Config.class);
@@ -215,21 +218,17 @@ public class UpgradeCatalog300Test {
     Config confLogSearchConf2 = easyMockSupport.createNiceMock(Config.class);
     expect(confLogSearchConf2.getType()).andReturn("service-2-logsearch-conf");
 
-    Map<String, String> oldLogSearchConf = ImmutableMap.of(
-        "service_name", "Service",
-        "component_mappings", "Component Mappings",
-        "content", "Content");
-
     Collection<Config> configs = Arrays.asList(confSomethingElse1, confLogSearchConf1,
confSomethingElse2, confLogSearchConf2);
 
     expect(cluster.getAllConfigs()).andReturn(configs).atLeastOnce();
-    expect(cluster.getDesiredConfigByType("service-1-logsearch-conf")).andReturn(confLogSearchConf1).once();
-    expect(cluster.getDesiredConfigByType("service-2-logsearch-conf")).andReturn(confLogSearchConf2).once();
-    expect(confLogSearchConf1.getProperties()).andReturn(oldLogSearchConf).once();
-    expect(confLogSearchConf2.getProperties()).andReturn(oldLogSearchConf).once();
-    Capture<Map<String, String>> logSearchConfCapture = EasyMock.newCapture(CaptureType.ALL);
-    expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(),
capture(logSearchConfCapture), anyString(),
-        EasyMock.anyObject())).andReturn(config).times(2);
+    configHelper.removeConfigsByType(cluster,"service-1-logsearch-conf");
+    expectLastCall().once();
+    configHelper.removeConfigsByType(cluster,"service-2-logsearch-conf");
+    expectLastCall().once();
+    configHelper.createConfigType(anyObject(Cluster.class), anyObject(StackId.class), eq(controller),
+        eq("logsearch-common-properties"), eq(Collections.emptyMap()), eq("ambari-upgrade"),
+        eq("Updated logsearch-common-properties during Ambari Upgrade from 2.6.0 to 3.0.0"));
+    expectLastCall().once();
 
     Map<String, String> oldLogSearchProperties = ImmutableMap.of(
         "logsearch.logfeeder.include.default.level", "FATAL,ERROR,WARN"
@@ -344,12 +343,6 @@ public class UpgradeCatalog300Test {
     new UpgradeCatalog300(injector2).updateLogSearchConfigs();
     easyMockSupport.verifyAll();
 
-    List<Map<String, String>> updatedLogSearchConfs = logSearchConfCapture.getValues();
-    assertEquals(updatedLogSearchConfs.size(), 2);
-    for (Map<String, String> updatedLogSearchConf : updatedLogSearchConfs) {
-      assertTrue(Maps.difference(Collections.emptyMap(), updatedLogSearchConf).areEqual());
-    }
-
     Map<String,String> newLogFeederProperties = logFeederPropertiesCapture.getValue();
     assertTrue(Maps.difference(expectedLogFeederProperties, newLogFeederProperties).areEqual());
 


Mime
View raw message