ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-13629 Oozie service have required, empty configs:oozie.authentication.kerberos.name.rules (after upgrade from 2.1.1 to 2.1.2.1) (dsen)
Date Fri, 30 Oct 2015 17:29:03 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1.2 f3bbecabb -> 4eb2b31ff


AMBARI-13629 Oozie service have required, empty configs:oozie.authentication.kerberos.name.rules
(after upgrade from 2.1.1 to 2.1.2.1) (dsen)


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

Branch: refs/heads/branch-2.1.2
Commit: 4eb2b31ff076dd64a3d5db809b883f21663e6acd
Parents: f3bbeca
Author: Dmytro Sen <dsen@apache.org>
Authored: Fri Oct 30 19:23:04 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Fri Oct 30 19:23:04 2015 +0200

----------------------------------------------------------------------
 .../server/upgrade/AbstractUpgradeCatalog.java  | 14 ++++
 .../server/upgrade/UpgradeCatalog2121.java      | 25 +++++++
 .../server/upgrade/UpgradeCatalog2121Test.java  | 70 ++++++++++++++++----
 3 files changed, 96 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4eb2b31f/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
index db1a023..92cc9e6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
@@ -341,6 +341,20 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog
{
   }
 
   /**
+   * This method returns Map of clusters.
+   * Map can be empty or with some objects, but never be null.
+   */
+  protected Map<String, Cluster> getCheckedClusterMap(Clusters clusters) {
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = clusters.getClusters();
+      if (clusterMap != null) {
+        return clusterMap;
+      }
+    }
+    return new HashMap<>();
+  }
+
+  /**
    * Create a new cluster scoped configuration with the new properties added
    * with the values from the coresponding xml files.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/4eb2b31f/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121.java
index ac06bb1..be88597 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121.java
@@ -27,13 +27,17 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.StackId;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.sql.SQLException;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * Upgrade catalog for version 2.1.2.1
@@ -48,6 +52,9 @@ public class UpgradeCatalog2121 extends AbstractUpgradeCatalog {
   @Inject
   DaoUtils daoUtils;
 
+  private static final String OOZIE_SITE_CONFIG = "oozie-site";
+  private static final String OOZIE_AUTHENTICATION_KERBEROS_NAME_RULES = "oozie.authentication.kerberos.name.rules";
+
   // ----- Constructors ------------------------------------------------------
 
   /**
@@ -104,6 +111,7 @@ public class UpgradeCatalog2121 extends AbstractUpgradeCatalog {
   @Override
   protected void executeDMLUpdates() throws AmbariException, SQLException {
     updatePHDConfigs();
+    updateOozieConfigs();
   }
 
   /**
@@ -165,5 +173,22 @@ public class UpgradeCatalog2121 extends AbstractUpgradeCatalog {
       }
     }
   }
+
+  protected void updateOozieConfigs() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    for (final Cluster cluster : getCheckedClusterMap(ambariManagementController.getClusters()).values())
{
+      Config oozieSiteProps = cluster.getDesiredConfigByType(OOZIE_SITE_CONFIG);
+      if (oozieSiteProps != null) {
+        // Remove oozie.authentication.kerberos.name.rules if empty
+        String oozieAuthKerbRules = oozieSiteProps.getProperties().get(OOZIE_AUTHENTICATION_KERBEROS_NAME_RULES);
+        if (StringUtils.isBlank(oozieAuthKerbRules)) {
+          Set<String> removeProperties = new HashSet<String>();
+          removeProperties.add(OOZIE_AUTHENTICATION_KERBEROS_NAME_RULES);
+          updateConfigurationPropertiesForCluster(cluster, OOZIE_SITE_CONFIG, null, removeProperties,
true, false);
+        }
+      }
+    }
+
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/4eb2b31f/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121Test.java
index f6b1c78..3bef3a3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog2121Test.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.upgrade;
 
 import static junit.framework.Assert.assertEquals;
 import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createMockBuilder;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.createStrictMock;
@@ -31,44 +30,38 @@ 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.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 
 import javax.persistence.EntityManager;
 
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.configuration.Configuration;
 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.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.DaoUtils;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.*;
 import org.apache.ambari.server.state.stack.OsFamily;
-import org.easymock.Capture;
 import org.easymock.EasyMockSupport;
+import org.easymock.internal.MockBuilder;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 import com.google.inject.AbstractModule;
-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.powermock.core.classloader.annotations.PrepareForTest;
 
-
+@PrepareForTest(UpgradeCatalog2121.class)
 public class UpgradeCatalog2121Test {
   private Injector injector;
   private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class);
@@ -100,13 +93,17 @@ public class UpgradeCatalog2121Test {
   @Test
   public void testExecuteDMLUpdates() throws Exception {
     Method updatePHDConfigs = UpgradeCatalog2121.class.getDeclaredMethod("updatePHDConfigs");
+    Method updateOozieConfigs = UpgradeCatalog2121.class.getDeclaredMethod("updateOozieConfigs");
 
     UpgradeCatalog2121 upgradeCatalog2121 = createMockBuilder(UpgradeCatalog2121.class)
         .addMockedMethod(updatePHDConfigs)
+        .addMockedMethod(updateOozieConfigs)
         .createMock();
 
     upgradeCatalog2121.updatePHDConfigs();
     expectLastCall().once();
+    upgradeCatalog2121.updateOozieConfigs();
+    expectLastCall().once();
 
     replay(upgradeCatalog2121);
 
@@ -114,5 +111,52 @@ public class UpgradeCatalog2121Test {
 
     verify(upgradeCatalog2121);
   }
+
+  @Test
+  public void testUpdateOozieConfigs() throws Exception {
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class);
+    final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
+    final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class);
+    final Map<String, String> propertiesOozieSite = new HashMap<String, String>()
{{
+      put("oozie.authentication.kerberos.name.rules", " ");
+    }};
+    final Config oozieSiteConf = easyMockSupport.createNiceMock(Config.class);
+    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
+        bind(Clusters.class).toInstance(mockClusters);
+        bind(EntityManager.class).toInstance(entityManager);
+
+        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);
+    }}).atLeastOnce();
+    expect(mockClusterExpected.getDesiredConfigByType("oozie-site")).andReturn(oozieSiteConf).atLeastOnce();
+
+    expect(oozieSiteConf.getProperties()).andReturn(propertiesOozieSite).once();
+
+    UpgradeCatalog2121 upgradeCatalog2121 = createMockBuilder(UpgradeCatalog2121.class)
+            .withConstructor(Injector.class)
+            .withArgs(mockInjector)
+            .addMockedMethod("updateConfigurationPropertiesForCluster", Cluster.class, String.class,
+                    Map.class, Set.class, boolean.class, boolean.class)
+            .createMock();
+    upgradeCatalog2121.updateConfigurationPropertiesForCluster(mockClusterExpected,
+            "oozie-site", null, Collections.singleton("oozie.authentication.kerberos.name.rules"),
+            true, false);
+    expectLastCall().once();
+
+    easyMockSupport.replayAll();
+    replay(upgradeCatalog2121);
+    upgradeCatalog2121.updateOozieConfigs();
+    easyMockSupport.verifyAll();
+
+  }
 }
 


Mime
View raw message