ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject [ambari] branch trunk updated: AMBARI-24322. Log Search / Ambari upgrade: db config consistency chec… (#1821)
Date Fri, 20 Jul 2018 15:39:20 GMT
This is an automated email from the ASF dual-hosted git repository.

oleewere pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 5fb83e5  AMBARI-24322. Log Search / Ambari upgrade: db config consistency chec…
(#1821)
5fb83e5 is described below

commit 5fb83e5a9e1e542444b6da045b93f6ea33a080d7
Author: Olivér Szabó <oleewere@gmail.com>
AuthorDate: Fri Jul 20 17:39:17 2018 +0200

    AMBARI-24322. Log Search / Ambari upgrade: db config consistency chec… (#1821)
    
    * AMBARI-24322. Log Search / Ambari upgrade: db config consistency check has warnings
(*-logearch-conf configs).
    
    * AMBARI-24322. Remove unused variable.
    
    * AMBARI-24322. Fix comment.
---
 .../ambari/server/upgrade/UpgradeCatalog270.java   | 27 +++++++++++++++-----
 .../server/upgrade/UpgradeCatalog270Test.java      | 29 +++++++---------------
 2 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
index bdeebfa..320bfd7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
@@ -259,6 +259,9 @@ public class UpgradeCatalog270 extends AbstractUpgradeCatalog {
   public static final String AMBARI_INFRA_OLD_NAME = "AMBARI_INFRA";
   public static final String AMBARI_INFRA_NEW_NAME = "AMBARI_INFRA_SOLR";
 
+  public static final String SERVICE_CONFIG_MAPPING_TABLE = "serviceconfigmapping";
+  public static final String CLUSTER_CONFIG_TABLE = "clusterconfig";
+
   // Broken constraints added by Views
   public static final String FK_HOSTCOMPONENTDESIREDSTATE_COMPONENT_NAME = "fk_hostcomponentdesiredstate_component_name";
   public static final String FK_HOSTCOMPONENTSTATE_COMPONENT_NAME = "fk_hostcomponentstate_component_name";
@@ -1429,7 +1432,7 @@ public class UpgradeCatalog270 extends AbstractUpgradeCatalog {
    *
    * @throws AmbariException
    */
-  protected void updateLogSearchConfigs() throws AmbariException {
+  protected void updateLogSearchConfigs() throws AmbariException, SQLException {
     AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
     Clusters clusters = ambariManagementController.getClusters();
     if (clusters != null) {
@@ -1438,11 +1441,6 @@ public class UpgradeCatalog270 extends AbstractUpgradeCatalog {
       ConfigHelper configHelper = injector.getInstance(ConfigHelper.class);
       if (clusterMap != null && !clusterMap.isEmpty()) {
         for (final Cluster cluster : clusterMap.values()) {
-          cluster.getAllConfigs().stream()
-                  .map(Config::getType)
-                  .filter(configType -> configType.endsWith("-logsearch-conf"))
-                  .collect(Collectors.toSet())
-          .forEach(configType -> configHelper.removeConfigsByType(cluster, configType));
 
           Config logSearchEnv = cluster.getDesiredConfigByType("logsearch-env");
 
@@ -1522,11 +1520,28 @@ public class UpgradeCatalog270 extends AbstractUpgradeCatalog {
 
             updateConfigurationPropertiesForCluster(cluster, "logfeeder-output-config", Collections.singletonMap("content",
content), true, true);
           }
+          DBAccessor dba = dbAccessor != null ? dbAccessor : injector.getInstance(DBAccessor.class);
// for testing
+          removeLogSearchPatternConfigs(dba);
         }
       }
     }
   }
 
+  private void removeLogSearchPatternConfigs(DBAccessor dbAccessor) throws SQLException {
+    // remove config types with -logsearch-conf suffix
+    String configSuffix = "-logsearch-conf";
+    String serviceConfigMappingRemoveSQL = String.format(
+      "DELETE FROM %s WHERE config_id IN (SELECT config_id from %s where type_name like '%%%s')",
+      SERVICE_CONFIG_MAPPING_TABLE, CLUSTER_CONFIG_TABLE, configSuffix);
+
+    String clusterConfigRemoveSQL = String.format(
+      "DELETE FROM %s WHERE type_name like '%%%s'",
+      CLUSTER_CONFIG_TABLE, configSuffix);
+
+    dbAccessor.executeQuery(serviceConfigMappingRemoveSQL);
+    dbAccessor.executeQuery(clusterConfigRemoveSQL);
+  }
+
   private void removeAdminHandlersFrom(Cluster cluster, String configType) throws AmbariException
{
     Config logSearchServiceLogsConfig = cluster.getDesiredConfigByType(configType);
     if (logSearchServiceLogsConfig != null) {
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
index 477da85..d91c21f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
@@ -155,7 +155,6 @@ import java.sql.Timestamp;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -998,31 +997,15 @@ public class UpgradeCatalog270Test {
         .addMockedMethod("createConfig")
         .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(injector2.getInstance(DBAccessor.class)).andReturn(dbAccessor).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
 
-    Config confSomethingElse1 = easyMockSupport.createNiceMock(Config.class);
-    expect(confSomethingElse1.getType()).andReturn("something-else-1");
-    Config confSomethingElse2 = easyMockSupport.createNiceMock(Config.class);
-    expect(confSomethingElse2.getType()).andReturn("something-else-2");
-    Config confLogSearchConf1 = easyMockSupport.createNiceMock(Config.class);
-    expect(confLogSearchConf1.getType()).andReturn("service-1-logsearch-conf");
-    Config confLogSearchConf2 = easyMockSupport.createNiceMock(Config.class);
-    expect(confLogSearchConf2.getType()).andReturn("service-2-logsearch-conf");
-
-    Collection<Config> configs = Arrays.asList(confSomethingElse1, confLogSearchConf1,
confSomethingElse2, confLogSearchConf2);
-
-    expect(cluster.getAllConfigs()).andReturn(configs).atLeastOnce();
-    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"));
@@ -1131,9 +1114,15 @@ public class UpgradeCatalog270Test {
     expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(),
capture(logFeederOutputConfCapture), anyString(),
         EasyMock.anyObject())).andReturn(config).once();
 
-    replay(clusters, cluster);
+    String serviceConfigMapping = "serviceconfigmapping";
+    String clusterConfig = "clusterconfig";
+    dbAccessor.executeQuery(startsWith("DELETE FROM "+ serviceConfigMapping));
+    expectLastCall().once();
+    dbAccessor.executeQuery(startsWith("DELETE FROM "+ clusterConfig));
+    expectLastCall().once();
+
+    replay(clusters, cluster, dbAccessor);
     replay(controller, injector2);
-    replay(confSomethingElse1, confSomethingElse2, confLogSearchConf1, confLogSearchConf2);
     replay(logSearchPropertiesConf, logFeederPropertiesConf);
     replay(logFeederLog4jConf, logSearchLog4jConf);
     replay(logSearchServiceLogsConf, logSearchAuditLogsConf);


Mime
View raw message