Browse Source

AMBARI-12189. hive.security.authorization.enabled is not being handled properly during Ambari upgrade (smohanty)

Sumit Mohanty 10 years ago
parent
commit
cebcfdee0a

+ 3 - 0
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java

@@ -1213,17 +1213,20 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
                   && RangerHiveConfig.getProperties().containsKey("ranger-hive-plugin-enabled")
                   && RangerHiveConfig.getProperties().containsKey("ranger-hive-plugin-enabled")
                   && cluster.getDesiredConfigByType("hive-env") != null) {
                   && cluster.getDesiredConfigByType("hive-env") != null) {
             Map<String, String> newHiveEnvProperties = new HashMap<String, String>();
             Map<String, String> newHiveEnvProperties = new HashMap<String, String>();
+            Map<String, String> newHiveServerProperties = new HashMap<String, String>();
             Set<String> removeRangerHiveProperties = new HashSet<String>();
             Set<String> removeRangerHiveProperties = new HashSet<String>();
             removeRangerHiveProperties.add("ranger-hive-plugin-enabled");
             removeRangerHiveProperties.add("ranger-hive-plugin-enabled");
 
 
             if (RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled") != null
             if (RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled") != null
                     && RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled").equalsIgnoreCase("yes")) {
                     && RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled").equalsIgnoreCase("yes")) {
               newHiveEnvProperties.put("hive_security_authorization", "Ranger");
               newHiveEnvProperties.put("hive_security_authorization", "Ranger");
+              newHiveServerProperties.put("hive.security.authorization.enabled", "true");
             } else {
             } else {
               newHiveEnvProperties.put("hive_security_authorization", "None");
               newHiveEnvProperties.put("hive_security_authorization", "None");
             }
             }
             boolean updateProperty = cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive_security_authorization");
             boolean updateProperty = cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive_security_authorization");
             updateConfigurationPropertiesForCluster(cluster, "hive-env", newHiveEnvProperties, updateProperty, true);
             updateConfigurationPropertiesForCluster(cluster, "hive-env", newHiveEnvProperties, updateProperty, true);
+            updateConfigurationPropertiesForCluster(cluster, "hiveserver2-site", newHiveServerProperties, updateProperty, true);
             updateConfigurationPropertiesForCluster(cluster, "ranger-hive-plugin-properties", new HashMap<String, String>(),
             updateConfigurationPropertiesForCluster(cluster, "ranger-hive-plugin-properties", new HashMap<String, String>(),
                     removeRangerHiveProperties, false, true);
                     removeRangerHiveProperties, false, true);
           }
           }

+ 12 - 0
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java

@@ -37,6 +37,7 @@ import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Statement;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.HashSet;
@@ -49,6 +50,7 @@ import com.google.inject.AbstractModule;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.ServiceConfigVersionResponse;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
 import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -236,10 +238,12 @@ public class UpgradeCatalog210Test {
 
 
     final Config mockRangerPlugin = easyMockSupport.createNiceMock(Config.class);
     final Config mockRangerPlugin = easyMockSupport.createNiceMock(Config.class);
     final Config mockHiveEnv = easyMockSupport.createNiceMock(Config.class);
     final Config mockHiveEnv = easyMockSupport.createNiceMock(Config.class);
+    final Config mockHiveServer = easyMockSupport.createNiceMock(Config.class);
 
 
     final Map<String, String> propertiesExpectedRangerPlugin = new HashMap<String, String>();
     final Map<String, String> propertiesExpectedRangerPlugin = new HashMap<String, String>();
     propertiesExpectedRangerPlugin.put("ranger-hive-plugin-enabled", "yes");
     propertiesExpectedRangerPlugin.put("ranger-hive-plugin-enabled", "yes");
     final Map<String, String> propertiesExpectedHiveEnv = new HashMap<String, String>();
     final Map<String, String> propertiesExpectedHiveEnv = new HashMap<String, String>();
+    final Map<String, String> propertiesExpectedHiveServer2 = new HashMap<String, String>();
     final Injector mockInjector = Guice.createInjector(new AbstractModule() {
     final Injector mockInjector = Guice.createInjector(new AbstractModule() {
       @Override
       @Override
       protected void configure() {
       protected void configure() {
@@ -259,8 +263,16 @@ public class UpgradeCatalog210Test {
 
 
     expect(mockClusterExpected.getDesiredConfigByType("ranger-hive-plugin-properties")).andReturn(mockRangerPlugin).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("ranger-hive-plugin-properties")).andReturn(mockRangerPlugin).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hive-env")).andReturn(mockHiveEnv).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hive-env")).andReturn(mockHiveEnv).atLeastOnce();
+    expect(mockClusterExpected.getDesiredConfigByType("hiveserver2-site")).andReturn(mockHiveServer).atLeastOnce();
     expect(mockRangerPlugin.getProperties()).andReturn(propertiesExpectedRangerPlugin).anyTimes();
     expect(mockRangerPlugin.getProperties()).andReturn(propertiesExpectedRangerPlugin).anyTimes();
     expect(mockHiveEnv.getProperties()).andReturn(propertiesExpectedHiveEnv).anyTimes();
     expect(mockHiveEnv.getProperties()).andReturn(propertiesExpectedHiveEnv).anyTimes();
+    expect(mockHiveServer.getProperties()).andReturn(propertiesExpectedHiveServer2).anyTimes();
+
+    ServiceConfigVersionResponse r = null;
+    expect(mockClusterExpected.getConfig(anyObject(String.class), anyObject(String.class))).
+        andReturn(mockHiveServer).anyTimes();
+    expect(mockClusterExpected.addDesiredConfig("ambari-upgrade", Collections.singleton(mockHiveServer))).
+        andReturn(r).times(3);
 
 
     easyMockSupport.replayAll();
     easyMockSupport.replayAll();
     mockInjector.getInstance(UpgradeCatalog210.class).updateRangerHiveConfigs();
     mockInjector.getInstance(UpgradeCatalog210.class).updateRangerHiveConfigs();