From commits-return-53456-archive-asf-public=cust-asf.ponee.io@ambari.apache.org Fri Jul 20 17:39:22 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id CF3BC180663 for ; Fri, 20 Jul 2018 17:39:21 +0200 (CEST) Received: (qmail 95306 invoked by uid 500); 20 Jul 2018 15:39:20 -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 95297 invoked by uid 99); 20 Jul 2018 15:39:20 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jul 2018 15:39:20 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 4DEC3850E4; Fri, 20 Jul 2018 15:39:20 +0000 (UTC) Date: Fri, 20 Jul 2018 15:39:20 +0000 To: "commits@ambari.apache.org" Subject: =?utf-8?q?=5Bambari=5D_branch_trunk_updated=3A_AMBARI-24322=2E_L?= =?utf-8?q?og_Search_/_Ambari_upgrade=3A_db_config_consistency_chec?= =?utf-8?b?4oCmICgjMTgyMSk=?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <153210116012.16767.4916524323521625989@gitbox.apache.org> From: oleewere@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: ambari X-Git-Refname: refs/heads/trunk X-Git-Reftype: branch X-Git-Oldrev: 6d106605782466eaa03a613bd3ca28d0c20463f3 X-Git-Newrev: 5fb83e5a9e1e542444b6da045b93f6ea33a080d7 X-Git-Rev: 5fb83e5a9e1e542444b6da045b93f6ea33a080d7 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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ó 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 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);