You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2018/08/06 15:49:45 UTC
[ambari] branch trunk updated: AMBARI-24322. Copy db config
consistency fix to UpgradeCatalog271 as well. (#1971)
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 c952a90 AMBARI-24322. Copy db config consistency fix to UpgradeCatalog271 as well. (#1971)
c952a90 is described below
commit c952a9090d1cbc3e18a6608f7e4db7791c7d83e8
Author: Olivér Szabó <ol...@gmail.com>
AuthorDate: Mon Aug 6 17:49:43 2018 +0200
AMBARI-24322. Copy db config consistency fix to UpgradeCatalog271 as well. (#1971)
---
.../ambari/server/upgrade/UpgradeCatalog271.java | 23 ++++++++++++++++++
.../server/upgrade/UpgradeCatalog271Test.java | 28 ++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog271.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog271.java
index 010ab62..b8abb3c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog271.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog271.java
@@ -32,6 +32,7 @@ import javax.persistence.TypedQuery;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.dao.DaoUtils;
import org.apache.ambari.server.orm.entities.ServiceConfigEntity;
import org.apache.ambari.server.state.Cluster;
@@ -52,6 +53,9 @@ public class UpgradeCatalog271 extends AbstractUpgradeCatalog {
*/
private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog271.class);
+ private static final String SERVICE_CONFIG_MAPPING_TABLE = "serviceconfigmapping";
+ private static final String CLUSTER_CONFIG_TABLE = "clusterconfig";
+
@Inject
DaoUtils daoUtils;
@@ -105,6 +109,7 @@ public class UpgradeCatalog271 extends AbstractUpgradeCatalog {
updateRangerLogDirConfigs();
updateRangerKmsDbUrl();
renameAmbariInfraInConfigGroups();
+ removeLogSearchPatternConfigs();
}
/**
@@ -237,4 +242,22 @@ public class UpgradeCatalog271 extends AbstractUpgradeCatalog {
entityManager.getEntityManagerFactory().getCache().evictAll();
clusters.invalidateAllClusters();
}
+
+ /**
+ * Removes config types with -logsearch-conf suffix
+ */
+ protected void removeLogSearchPatternConfigs() throws SQLException {
+ DBAccessor dba = dbAccessor != null ? dbAccessor : injector.getInstance(DBAccessor.class); // for testing
+ 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);
+
+ dba.executeQuery(serviceConfigMappingRemoveSQL);
+ dba.executeQuery(clusterConfigRemoveSQL);
+ }
}
\ No newline at end of file
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java
index 8d397f0..a1780d7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java
@@ -26,6 +26,7 @@ import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.startsWith;
import static org.easymock.EasyMock.verify;
import java.lang.reflect.Method;
@@ -35,6 +36,7 @@ import java.util.Map;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
+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;
@@ -56,12 +58,14 @@ public class UpgradeCatalog271Test {
Method updateRangerLogDirConfigs = UpgradeCatalog271.class.getDeclaredMethod("updateRangerLogDirConfigs");
Method updateRangerKmsDbUrl = UpgradeCatalog271.class.getDeclaredMethod("updateRangerKmsDbUrl");
Method renameAmbariInfraInConfigGroups = UpgradeCatalog271.class.getDeclaredMethod("renameAmbariInfraInConfigGroups");
+ Method removeLogSearchPatternConfigs = UpgradeCatalog271.class.getDeclaredMethod("removeLogSearchPatternConfigs");
UpgradeCatalog271 upgradeCatalog271 = createMockBuilder(UpgradeCatalog271.class)
.addMockedMethod(updateRangerKmsDbUrl)
.addMockedMethod(updateRangerLogDirConfigs)
.addMockedMethod(addNewConfigurationsFromXml)
.addMockedMethod(renameAmbariInfraInConfigGroups)
+ .addMockedMethod(removeLogSearchPatternConfigs)
.createMock();
upgradeCatalog271.addNewConfigurationsFromXml();
@@ -76,12 +80,36 @@ public class UpgradeCatalog271Test {
upgradeCatalog271.renameAmbariInfraInConfigGroups();
expectLastCall().once();
+ upgradeCatalog271.removeLogSearchPatternConfigs();
+ expectLastCall().once();
+
replay(upgradeCatalog271);
upgradeCatalog271.executeDMLUpdates();
verify(upgradeCatalog271);
}
@Test
+ public void testRemoveLogSearchPatternConfigs() throws Exception {
+ // GIVEN
+ EasyMockSupport easyMockSupport = new EasyMockSupport();
+ Injector injector = easyMockSupport.createNiceMock(Injector.class);
+ DBAccessor dbAccessor = easyMockSupport.createNiceMock(DBAccessor.class);
+ expect(injector.getInstance(DBAccessor.class)).andReturn(dbAccessor).anyTimes();
+ String serviceConfigMapping = "serviceconfigmapping";
+ String clusterConfig = "clusterconfig";
+ dbAccessor.executeQuery(startsWith("DELETE FROM "+ serviceConfigMapping));
+ expectLastCall().once();
+ dbAccessor.executeQuery(startsWith("DELETE FROM "+ clusterConfig));
+ expectLastCall().once();
+ replay(dbAccessor, injector);
+ // WHEN
+ new UpgradeCatalog271(injector).removeLogSearchPatternConfigs();
+ // THEN
+ easyMockSupport.verifyAll();
+
+ }
+
+ @Test
public void testUpdateRangerLogDirConfigs() throws Exception {
Map<String, Service> installedServices = new HashMap<String, Service>() {