This is an automated email from the ASF dual-hosted git repository.

amagyar pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new 2ec7e26  AMBARI-25304. Request configurations when needed during 
server-side actions rather than rely on configuration data from the execution 
command (amagyar) (#3008)
2ec7e26 is described below

commit 2ec7e26209685afcbcfa58a19775df550bb1a004
Author: Attila Magyar <amag...@hortonworks.com>
AuthorDate: Thu Jun 13 17:04:31 2019 +0200

    AMBARI-25304. Request configurations when needed during server-side actions 
rather than rely on configuration data from the execution command (amagyar) 
(#3008)
    
    * AMBARI-25304. Request configurations when needed during server-side 
actions rather than rely on configuration data from the execution command 
(amagyar)
    
    * AMBARI-25304. Request configurations when needed during server-side 
actions rather than rely on configuration data from the execution command 
(amagyar)
---
 .../server/serveraction/AbstractServerAction.java  | 23 ----------------
 .../kerberos/DestroyPrincipalsServerAction.java    |  2 +-
 .../kerberos/KerberosServerAction.java             | 32 +++++++++++++++++++++-
 .../kerberos/KerberosServerActionTest.java         | 30 ++++++++++++++++++++
 4 files changed, 62 insertions(+), 25 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
index 3c38398..83bc734 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
@@ -173,29 +173,6 @@ public abstract class AbstractServerAction implements 
ServerAction {
     return (commandParameters == null) ? null : 
commandParameters.get(propertyName);
   }
 
-  /**
-   * Returns the configurations value from the ExecutionCommand
-   * <p/>
-   * The returned map should be assumed to be read-only.
-   *
-   * @return the (assumed read-only) configurations value from the 
ExecutionCommand
-   */
-  protected Map<String, Map<String, String>> getConfigurations() {
-    return (executionCommand == null) ? Collections.emptyMap() : 
executionCommand.getConfigurations();
-  }
-
-  /**
-   * Returns the requested configuration Map from the ExecutionCommand
-   * <p/>
-   * The returned map should be assumed to be read-only.
-   *
-   * @param configurationName a String indicating the name of the 
configuration data to retrieve
-   * @return the (assumed read-only) configuration Map from the 
ExecutionCommand, or null if not available
-   */
-  protected Map<String, String> getConfiguration(String configurationName) {
-    return getConfigurations().get(configurationName);
-  }
-
   protected void auditLog(AuditEvent ae) {
     auditLogger.log(ae);
   }
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
index 11deac4..5daec26 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
@@ -110,7 +110,7 @@ public class DestroyPrincipalsServerAction extends 
KerberosServerAction {
     String defaultRealm = getDefaultRealm(commandParameters);
 
     KerberosOperationHandler operationHandler = 
kerberosOperationHandlerFactory.getKerberosOperationHandler(kdcType);
-    Map<String, String> kerberosConfiguration = 
getConfiguration("kerberos-env");
+    Map<String, String> kerberosConfiguration = 
getConfigurationProperties("kerberos-env");
 
     try {
       operationHandler.open(administratorCredential, defaultRealm, 
kerberosConfiguration);
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
index b6876c8..37e63a1 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
@@ -41,6 +41,7 @@ import 
org.apache.ambari.server.serveraction.kerberos.stageutils.ResolvedKerbero
 import 
org.apache.ambari.server.serveraction.kerberos.stageutils.ResolvedKerberosPrincipal;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.kerberos.KerberosIdentityDescriptor;
 import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.io.FileUtils;
@@ -435,7 +436,7 @@ public abstract class KerberosServerAction extends 
AbstractServerAction {
       String defaultRealm = getDefaultRealm(commandParameters);
 
       KerberosOperationHandler handler = 
kerberosOperationHandlerFactory.getKerberosOperationHandler(kdcType);
-      Map<String, String> kerberosConfiguration = 
getConfiguration("kerberos-env");
+      Map<String, String> kerberosConfiguration = 
getConfigurationProperties("kerberos-env");
 
       try {
         handler.open(administratorCredential, defaultRealm, 
kerberosConfiguration);
@@ -605,6 +606,35 @@ public abstract class KerberosServerAction extends 
AbstractServerAction {
         : ambariServerHostEntity.getHostId();
   }
 
+
+  /**
+   * Retrieve the current set of properties for the requested config type for 
the relevant cluster.
+   *
+   * @return a Map of property names to property values for the requested 
config type; or null if no data is found
+   * @throws AmbariException if an error occurs retrieving the relevant 
cluster details
+   */
+  protected Map<String, String> getConfigurationProperties(String configType) 
throws AmbariException {
+    if (StringUtils.isNotEmpty(configType)) {
+      Cluster cluster = getCluster();
+      Config config = (cluster == null) ? null : 
cluster.getDesiredConfigByType(configType);
+      Map<String, String> properties = (config == null) ? null : 
config.getProperties();
+
+      if (properties == null) {
+        LOG.warn("The '{}' configuration data is not available:" +
+                "\n\tcluster: {}" +
+                "\n\tconfig: {}" +
+                "\n\tproperties: null",
+            configType,
+            (cluster == null) ? "null" : "not null",
+            (config == null) ? "null" : "not null");
+      }
+
+      return properties;
+    } else {
+      return null;
+    }
+  }
+
   public static class KerberosCommandParameters {
     private Map<String, String> params;
 
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerActionTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerActionTest.java
index 0e438fb..87b990c 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerActionTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerActionTest.java
@@ -47,6 +47,7 @@ import 
org.apache.ambari.server.serveraction.kerberos.stageutils.ResolvedKerbero
 import 
org.apache.ambari.server.serveraction.kerberos.stageutils.ResolvedKerberosPrincipal;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.kerberos.KerberosIdentityDescriptor;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.EasyMockSupport;
@@ -63,6 +64,8 @@ import junit.framework.Assert;
 
 public class KerberosServerActionTest extends EasyMockSupport {
 
+  private  static final Map<String, String> KERBEROS_ENV_PROPERTIES = 
Collections.singletonMap("admin_server_host", "kdc.example.com");
+
   Map<String, String> commandParams = new HashMap<>();
   File temporaryDirectory;
   private Injector injector;
@@ -72,7 +75,11 @@ public class KerberosServerActionTest extends 
EasyMockSupport {
 
   @Before
   public void setUp() throws Exception {
+    Config kerberosEnvConfig = createMock(Config.class);
+    
expect(kerberosEnvConfig.getProperties()).andReturn(KERBEROS_ENV_PROPERTIES).anyTimes();
+
     cluster = createMock(Cluster.class);
+    
expect(cluster.getDesiredConfigByType("kerberos-env")).andReturn(kerberosEnvConfig).anyTimes();
 
     Clusters clusters = createMock(Clusters.class);
     expect(clusters.getCluster(anyString())).andReturn(cluster).anyTimes();
@@ -282,4 +289,27 @@ public class KerberosServerActionTest extends 
EasyMockSupport {
 
     verifyAll();
   }
+
+  @Test
+  public void testGetConfigurationProperties() throws AmbariException {
+    Config emptyConfig = createMock(Config.class);
+    
expect(emptyConfig.getProperties()).andReturn(Collections.emptyMap()).once();
+
+    Config missingPropertiesConfig = createMock(Config.class);
+    expect(missingPropertiesConfig.getProperties()).andReturn(null).once();
+
+    
expect(cluster.getDesiredConfigByType("invalid-type")).andReturn(null).once();
+    
expect(cluster.getDesiredConfigByType("missing-properties-type")).andReturn(missingPropertiesConfig).once();
+    
expect(cluster.getDesiredConfigByType("empty-type")).andReturn(emptyConfig).once();
+
+    replayAll();
+
+    Assert.assertNull(action.getConfigurationProperties(null));
+    Assert.assertNull(action.getConfigurationProperties("invalid-type"));
+    
Assert.assertNull(action.getConfigurationProperties("missing-properties-type"));
+    Assert.assertEquals(Collections.emptyMap(), 
action.getConfigurationProperties("empty-type"));
+    Assert.assertEquals(KERBEROS_ENV_PROPERTIES, 
action.getConfigurationProperties("kerberos-env"));
+
+    verifyAll();
+  }
 }

Reply via email to