You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rl...@apache.org on 2018/11/08 18:57:02 UTC
[ambari] branch trunk updated: [AMBARI-24869] Request
configurations when needed during server-side actions rather than rely on
configuration data from the execution command
This is an automated email from the ASF dual-hosted git repository.
rlevas pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 9f25b46 [AMBARI-24869] Request configurations when needed during server-side actions rather than rely on configuration data from the execution command
9f25b46 is described below
commit 9f25b46514c790109cb99db0d5abc09b8e52ea3d
Author: Robert Levas <rl...@users.noreply.github.com>
AuthorDate: Thu Nov 8 13:56:56 2018 -0500
[AMBARI-24869] Request configurations when needed during server-side actions rather than rely on configuration data from the execution command
* [AMBARI-24869] Request configurations when needed during server-side actions rather than rely on configuration data from the execution command
* [AMBARI-24869] Removed unused import
---
.../server/serveraction/AbstractServerAction.java | 23 ----------------
.../kerberos/DestroyPrincipalsServerAction.java | 2 +-
.../kerberos/KerberosServerAction.java | 31 +++++++++++++++++++++-
.../kerberos/KerberosServerActionTest.java | 31 ++++++++++++++++++++++
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..c635cca 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,34 @@ 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 7878ca2..e49ecfd 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,12 @@ 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();
@@ -281,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();
+ }
}