Repository: ambari
Updated Branches:
  refs/heads/trunk e3c9aa7a4 -> 321cdbf36


AMBARI-8955. Upgrading to Ambari 1.6.1 with external postgres DB breaks Hive 
metastore startup.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: 321cdbf3673430c6578011cd5c4541938cca0e24
Parents: e3c9aa7
Author: Vitaly Brodetskyi <vbrodets...@hortonworks.com>
Authored: Tue Dec 30 21:07:56 2014 +0200
Committer: Vitaly Brodetskyi <vbrodets...@hortonworks.com>
Committed: Tue Dec 30 21:07:56 2014 +0200

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog200.java       | 54 ++++++++++++++---
 .../server/upgrade/UpgradeCatalog200Test.java   | 64 ++++++++++----------
 2 files changed, 80 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/321cdbf3/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
index e18331f..e86ca1a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
@@ -18,12 +18,10 @@
 
 package org.apache.ambari.server.upgrade;
 
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
+import com.google.inject.Inject;
+import com.google.inject.Injector;
 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.DBAccessor.DBColumnInfo;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
@@ -40,13 +38,19 @@ import 
org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import 
org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
 import 
org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntityPK;
 import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.SecurityState;
 import org.apache.ambari.server.state.UpgradeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.inject.Inject;
-import com.google.inject.Injector;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -255,6 +259,42 @@ public class UpgradeCatalog200 extends 
AbstractUpgradeCatalog {
   protected void executeDMLUpdates() throws AmbariException, SQLException {
     // remove NAGIOS to make way for the new embedded alert framework
     removeNagiosService();
+    updateHiveDatabaseType();
+  }
+
+  protected void updateHiveDatabaseType() throws AmbariException {
+    final String PROPERTY_NAME = "hive_database_type";
+    final String PROPERTY_VALUE_OLD = "postgresql";
+    final String PROPERTY_VALUE_NEW = "postgres";
+    final String PROPERTY_CONFIG_NAME = "hive-env";
+
+    AmbariManagementController ambariManagementController = 
injector.getInstance(
+            AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = clusters.getClusters();
+      Map<String, String> prop = new HashMap<String, String>();
+      String hive_database_type = null;
+
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (final Cluster cluster : clusterMap.values()) {
+          hive_database_type = null;
+
+          if (cluster.getDesiredConfigByType(PROPERTY_CONFIG_NAME) != null) {
+            hive_database_type = cluster.getDesiredConfigByType(
+                    PROPERTY_CONFIG_NAME).getProperties().get(PROPERTY_NAME);
+          }
+
+          if (hive_database_type != null && !hive_database_type.isEmpty() &&
+                  hive_database_type.equals(PROPERTY_VALUE_OLD)) {
+            prop.put(PROPERTY_NAME, PROPERTY_VALUE_NEW);
+            updateConfigurationPropertiesForCluster(cluster, 
PROPERTY_CONFIG_NAME, prop, true, false);
+          }
+        }
+      }
+
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/321cdbf3/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
index cd68dc1..b89b31c 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
@@ -18,30 +18,12 @@
 
 package org.apache.ambari.server.upgrade;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createMockBuilder;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
+import com.google.inject.persist.PersistService;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
@@ -67,12 +49,28 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.inject.Binder;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Module;
-import com.google.inject.Provider;
-import com.google.inject.persist.PersistService;
+import javax.persistence.EntityManager;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
 
 /**
  * {@link UpgradeCatalog200} unit tests.
@@ -271,12 +269,16 @@ public class UpgradeCatalog200Test {
   @Test
   public void testExecuteDMLUpdates() throws Exception {
     Method removeNagiosService = 
UpgradeCatalog200.class.getDeclaredMethod("removeNagiosService");
+    Method updateHiveDatabaseType = 
UpgradeCatalog200.class.getDeclaredMethod("updateHiveDatabaseType");
 
     UpgradeCatalog200 upgradeCatalog = createMockBuilder(
-        
UpgradeCatalog200.class).addMockedMethod(removeNagiosService).createMock();
+        
UpgradeCatalog200.class).addMockedMethod(removeNagiosService).addMockedMethod(updateHiveDatabaseType).createMock();
 
     upgradeCatalog.removeNagiosService();
     expectLastCall().once();
+    upgradeCatalog.updateHiveDatabaseType();
+    expectLastCall().once();
+
 
     replay(upgradeCatalog);
 

Reply via email to