ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlun...@apache.org
Subject ambari git commit: AMBARI-12220: HiveServer2 query fail after RU (jluniya)
Date Thu, 02 Jul 2015 04:09:40 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk dcbd7f5b7 -> c3f8f648e


AMBARI-12220: HiveServer2 query fail after RU (jluniya)


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

Branch: refs/heads/trunk
Commit: c3f8f648ec475a5c36958874fd9d62339a400764
Parents: dcbd7f5
Author: Jayush Luniya <jluniya@hortonworks.com>
Authored: Wed Jul 1 21:09:35 2015 -0700
Committer: Jayush Luniya <jluniya@hortonworks.com>
Committed: Wed Jul 1 21:09:35 2015 -0700

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog210.java       | 34 +++++++-
 .../server/upgrade/UpgradeCatalog210Test.java   | 82 ++++++++++++++++++++
 2 files changed, 114 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c3f8f648/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
index e8e0f2d..e59687d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
@@ -71,6 +71,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
+import java.util.regex.Matcher;
 
 
 /**
@@ -1323,16 +1324,23 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
 
       if (clusterMap != null && !clusterMap.isEmpty()) {
         for (final Cluster cluster : clusterMap.values()) {
-          //hive metastore and client_heapsize are added for HDP2, we should check if it
exists and not add it for HDP1
+          String content = null;
           if(cluster.getDesiredConfigByType("hive-env") != null) {
             Map<String, String> hiveProps = new HashMap<String, String>();
+            // Update logic for setting HIVE_AUX_JARS_PATH in hive-env.sh
+            content = cluster.getDesiredConfigByType("hive-env").getProperties().get("content");
+            if(content != null) {
+              content = updateHiveEnvContent(content);
+              hiveProps.put("content", content);
+            }
+            //hive metastore and client_heapsize are added for HDP2, we should check if it
exists and not add it for HDP1
             if (!cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive.client.heapsize"))
{
               hiveProps.put("hive.client.heapsize", "512m");
             }
             if (!cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive.metastore.heapsize"))
{
               hiveProps.put("hive.metastore.heapsize", "1024m");
             }
-            updateConfigurationPropertiesForCluster(cluster, "hive-env", hiveProps, false,
true);
+            updateConfigurationPropertiesForCluster(cluster, "hive-env", hiveProps, true,
true);
           }
         }
       }
@@ -1365,6 +1373,28 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     }
   }
 
+  protected String updateHiveEnvContent(String hiveEnvContent) {
+    if(hiveEnvContent == null) {
+      return null;
+    }
+
+    String oldAuxJarRegex = "if\\s*\\[\\s*\"\\$\\{HIVE_AUX_JARS_PATH\\}\"\\s*!=\\s*\"\"\\s*];\\s*then\\s*\\n"
+
+        "\\s*export\\s+HIVE_AUX_JARS_PATH\\s*=\\s*\\$\\{HIVE_AUX_JARS_PATH\\}\\s*\\n" +
+        "\\s*elif\\s*\\[\\s*-d\\s*\"/usr/hdp/current/hive-webhcat/share/hcatalog\"\\s*\\];\\s*then\\s*\\n"
+
+        "\\s*export\\s+HIVE_AUX_JARS_PATH\\s*=\\s*/usr/hdp/current/hive-webhcat/share/hcatalog\\s*\n"
+
+        "\\s*fi";
+    String newAuxJarPath = "if [ \"${HIVE_AUX_JARS_PATH}\" != \"\" ]; then\n" +
+        "  if [ -f \"${HIVE_AUX_JARS_PATH}\" ]; then    \n" +
+        "    export HIVE_AUX_JARS_PATH=${HIVE_AUX_JARS_PATH}\n" +
+        "  elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" +
+        "    export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n"
+
+        "  fi\n" +
+        "elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" +
+        "  export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n"
+
+        "fi";
+    return hiveEnvContent.replaceAll(oldAuxJarRegex, Matcher.quoteReplacement(newAuxJarPath));
+  }
+
   protected  void updateStormConfigs() throws  AmbariException {
     AmbariManagementController ambariManagementController = injector.getInstance(
             AmbariManagementController.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3f8f648/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
index 0b1d111..eb240f8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
@@ -281,6 +281,88 @@ public class UpgradeCatalog210Test {
   }
 
   @Test
+  public void testUpdateHiveConfigs() throws Exception {
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final AmbariManagementController  mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class);
+    final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class);
+
+    final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
+    final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class);
+    final Config mockHiveEnv = easyMockSupport.createNiceMock(Config.class);
+
+    final Map<String, String> propertiesExpectedHiveEnv = new HashMap<String, String>();
+    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
+        bind(ConfigHelper.class).toInstance(mockConfigHelper);
+        bind(Clusters.class).toInstance(mockClusters);
+
+        bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
+        bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+      }
+    });
+
+    expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
+    expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
+      put("normal", mockClusterExpected);
+    }}).once();
+
+    expect(mockClusterExpected.getDesiredConfigByType("hive-env")).andReturn(mockHiveEnv).atLeastOnce();
+    expect(mockHiveEnv.getProperties()).andReturn(propertiesExpectedHiveEnv).anyTimes();
+    expect(mockClusterExpected.getConfig(anyObject(String.class), anyObject(String.class))).
+        andReturn(mockHiveEnv).anyTimes();
+    ServiceConfigVersionResponse r = null;
+    expect(mockClusterExpected.addDesiredConfig("ambari-upgrade", Collections.singleton(mockHiveEnv))).
+        andReturn(r).once();
+
+    easyMockSupport.replayAll();
+    mockInjector.getInstance(UpgradeCatalog210.class).updateHiveConfigs();
+    easyMockSupport.verifyAll();
+  }
+
+  @Test
+  public void TestUpdateHiveEnvContent() {
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final AmbariManagementController  mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class);
+    final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class);
+    final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
+
+    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
+        bind(ConfigHelper.class).toInstance(mockConfigHelper);
+        bind(Clusters.class).toInstance(mockClusters);
+
+        bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
+        bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+      }
+    });
+    String content = "# Start HIVE_AUX_JARS_PATH \n" +
+        "if [ \"${HIVE_AUX_JARS_PATH}\" != \"\" ]; then\n" +
+        "  export HIVE_AUX_JARS_PATH=${HIVE_AUX_JARS_PATH}\n" +
+        "elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then \n" +
+        "  export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog\n" +
+        "fi\n" +
+        "#End HIVE_AUX_JARS_PATH";
+    String expectedContent = "# Start HIVE_AUX_JARS_PATH \n" +
+        "if [ \"${HIVE_AUX_JARS_PATH}\" != \"\" ]; then\n" +
+        "  if [ -f \"${HIVE_AUX_JARS_PATH}\" ]; then    \n" +
+        "    export HIVE_AUX_JARS_PATH=${HIVE_AUX_JARS_PATH}\n" +
+        "  elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" +
+        "    export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n"
+
+        "  fi\n" +
+        "elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" +
+        "  export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n"
+
+        "fi\n" +
+        "#End HIVE_AUX_JARS_PATH";
+
+    String modifiedContent = mockInjector.getInstance(UpgradeCatalog210.class).updateHiveEnvContent(content);
+    Assert.assertEquals(modifiedContent, expectedContent);
+  }
+
+  @Test
   public void testInitializeClusterAndServiceWidgets() throws Exception {
     final AmbariManagementController controller = createStrictMock(AmbariManagementController.class);
     final Clusters clusters = createStrictMock(Clusters.class);


Mime
View raw message