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 59eeafe  [AMBARI-23526] Make sure that we update topology cache on 
agent side when Kerberizing the cluster (#951)
59eeafe is described below

commit 59eeafe28eaeff7f07b84e8f3957ebb3780e9d13
Author: smolnar82 <34065904+smolna...@users.noreply.github.com>
AuthorDate: Thu Apr 12 18:30:21 2018 +0200

    [AMBARI-23526] Make sure that we update topology cache on agent side when 
Kerberizing the cluster (#951)
    
    * AMBARI-23526. Make sure that we update topology cache on agent side when 
Kerberizing the cluster
    
    * AMBARI-23526. Added license headers and updated JUnit test
    
    * AMBARI-23526. Injecting TopologyHolder in constructor to enable unit 
testing without creating Guice environment
    
    * AMBARI-23526. Triggering upgrade topology event in the Finalize 
Operations stage
---
 .../controller/AmbariManagementControllerImpl.java | 20 ++++++++--------
 .../server/serveraction/AbstractServerAction.java  |  7 ++++++
 .../kerberos/FinalizeKerberosServerAction.java     | 27 +++++++++++++++++++++-
 .../before-START/scripts/shared_initialization.py  |  4 ++--
 .../kerberos/FinalizeKerberosServerActionTest.java | 13 +++++++++--
 5 files changed, 55 insertions(+), 16 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 0bd6ae0..a68ef89 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -52,7 +52,6 @@ import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_P
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_REPO_INFO;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
-import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.UNLIMITED_KEY_JCE_REQUIRED;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_GROUPS;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_LIST;
 import static 
org.apache.ambari.server.controller.AmbariCustomCommandExecutionHelper.masterToSlaveMappingForDecom;
@@ -2579,16 +2578,6 @@ public class AmbariManagementControllerImpl implements 
AmbariManagementControlle
 
     hostParams.put(CLIENTS_TO_UPDATE_CONFIGS, 
getClientsToUpdateConfigs(componentInfo));
 
-    // If we are starting a component, calculate whether the unlimited key JCE 
policy is
-    // required for the relevant host.  One of the following indicates that 
the unlimited
-    // key JCE policy is required:
-    //
-    //   * The component explicitly requires it whether Kerberos is enabled or 
not (example, SMARTSENSE/HST_SERVER)
-    //   * The component explicitly requires it only when Kerberos is enabled 
AND Kerberos is enabled (example, most components)
-    //
-    // Set/update the unlimited_key_jce_required value as needed
-    hostParams.put(UNLIMITED_KEY_JCE_REQUIRED, 
(getUnlimitedKeyJCERequirement(componentInfo, cluster.getSecurityType())) ? 
"true" : "false");
-
     execCmd.setHostLevelParams(hostParams);
 
     Map<String, String> roleParams = new TreeMap<>();
@@ -5690,6 +5679,15 @@ public class AmbariManagementControllerImpl implements 
AmbariManagementControlle
 
       
statusCommandParams.put(ExecutionCommand.KeyNames.CLIENTS_TO_UPDATE_CONFIGS,
           getClientsToUpdateConfigs(componentInfo));
+
+      // If we are starting a component, calculate whether the unlimited key 
JCE policy is
+      // required for the relevant host.  One of the following indicates that 
the unlimited
+      // key JCE policy is required:
+      //
+      //   * The component explicitly requires it whether Kerberos is enabled 
or not (example, SMARTSENSE/HST_SERVER)
+      //   * The component explicitly requires it only when Kerberos is 
enabled AND Kerberos is enabled (example, most components)
+      //
+      // Set/update the unlimited_key_jce_required value as needed
       
statusCommandParams.put(ExecutionCommand.KeyNames.UNLIMITED_KEY_JCE_REQUIRED,
           Boolean.toString(getUnlimitedKeyJCERequirement(componentInfo, 
clusterSecurityType)));
     }
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 a3286a9..c13eb5b 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
@@ -80,6 +80,13 @@ public abstract class AbstractServerAction implements 
ServerAction {
   }
 
   /**
+   * @return a command report with 0 exit code and COMPLETED HostRoleStatus
+   */
+  protected CommandReport createCompletedCommandReport() {
+    return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", 
actionLog.getStdOut(), actionLog.getStdErr());
+  }
+
+  /**
    * Creates a CommandReport used to report back to Ambari the status of this 
ServerAction.
    *
    * @param exitCode      an integer value declaring the exit code for this 
action - 0 typically
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
index 225e53e..6823d16 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
@@ -26,6 +26,8 @@ import java.util.concurrent.ConcurrentMap;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.agent.CommandReport;
+import org.apache.ambari.server.agent.stomp.TopologyHolder;
+import org.apache.ambari.server.events.TopologyUpdateEvent;
 import 
org.apache.ambari.server.serveraction.kerberos.stageutils.ResolvedKerberosPrincipal;
 import org.apache.ambari.server.utils.ShellCommandUtil;
 import org.apache.ambari.server.utils.StageUtils;
@@ -33,9 +35,18 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.inject.Inject;
+
 public class FinalizeKerberosServerAction extends KerberosServerAction {
   private final static Logger LOG = 
LoggerFactory.getLogger(FinalizeKerberosServerAction.class);
 
+  private final TopologyHolder topologyHolder;
+
+  @Inject
+  public FinalizeKerberosServerAction(TopologyHolder topologyHolder) {
+    this.topologyHolder = topologyHolder;
+  }
+
   /**
    * Processes an identity as necessary.
    * <p/>
@@ -168,7 +179,21 @@ public class FinalizeKerberosServerAction extends 
KerberosServerAction {
     }
     deleteDataDirectory(dataDirectoryPath);
 
-    return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", 
actionLog.getStdOut(), actionLog.getStdErr());
+    return sendTopologyUpdateEvent();
+  }
+
+  private CommandReport sendTopologyUpdateEvent() throws AmbariException, 
InterruptedException {
+    CommandReport commandReport = null;
+    try {
+      final TopologyUpdateEvent updateEvent = topologyHolder.getCurrentData();
+      topologyHolder.updateData(updateEvent);
+    } catch (Exception e) {
+      String message = "Could not send topology update event when enabling 
kerberos";
+      actionLog.writeStdErr(message);
+      LOG.error(message, e);
+      commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", 
actionLog.getStdOut(), actionLog.getStdErr());
+    }
+    return commandReport == null ? createCompletedCommandReport() : 
commandReport;
   }
 
 }
diff --git 
a/ambari-server/src/main/resources/stack-hooks/before-START/scripts/shared_initialization.py
 
b/ambari-server/src/main/resources/stack-hooks/before-START/scripts/shared_initialization.py
index 32870c9..541de9c 100644
--- 
a/ambari-server/src/main/resources/stack-hooks/before-START/scripts/shared_initialization.py
+++ 
b/ambari-server/src/main/resources/stack-hooks/before-START/scripts/shared_initialization.py
@@ -218,10 +218,10 @@ def __setup_unlimited_key_jce_policy(custom_java_home, 
custom_jdk_name, custom_j
     Logger.info("Skipping unlimited key JCE policy check and setup since the 
host is sys prepped")
 
   elif not custom_jdk_name:
-    Logger.debug("Skipping unlimited key JCE policy check and setup since the 
Java VM is not managed by Ambari")
+    Logger.info("Skipping unlimited key JCE policy check and setup since the 
Java VM is not managed by Ambari")
 
   elif not params.unlimited_key_jce_required:
-    Logger.debug("Skipping unlimited key JCE policy check and setup since it 
is not required")
+    Logger.info("Skipping unlimited key JCE policy check and setup since it is 
not required")
 
   else:
     jcePolicyInfo = JcePolicyInfo(custom_java_home)
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerActionTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerActionTest.java
index 2241120..dd45907 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerActionTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerActionTest.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.server.serveraction.kerberos;
 
 import static org.easymock.EasyMock.expect;
+import static org.mockito.Matchers.anyBoolean;
 
 import java.io.File;
 import java.io.IOException;
@@ -39,9 +40,11 @@ import 
org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.agent.CommandReport;
 import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.agent.stomp.TopologyHolder;
 import org.apache.ambari.server.audit.AuditLogger;
 import org.apache.ambari.server.controller.KerberosHelper;
 import org.apache.ambari.server.controller.RootComponent;
+import org.apache.ambari.server.events.TopologyUpdateEvent;
 import org.apache.ambari.server.security.credential.PrincipalKeyCredential;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -65,6 +68,8 @@ public class FinalizeKerberosServerActionTest extends 
EasyMockSupport {
   @Rule
   public TemporaryFolder folder = new TemporaryFolder();
 
+  private final TopologyHolder topologyHolder = 
createNiceMock(TopologyHolder.class);
+
   @Test
   @Ignore("Update accordingly to changes")
   public void executeMITKDCOption() throws Exception {
@@ -90,7 +95,7 @@ public class FinalizeKerberosServerActionTest extends 
EasyMockSupport {
 
     ConcurrentMap<String, Object> requestSharedDataContext = new 
ConcurrentHashMap<>();
 
-    FinalizeKerberosServerAction action = 
injector.getInstance(FinalizeKerberosServerAction.class);
+    FinalizeKerberosServerAction action = new 
FinalizeKerberosServerAction(topologyHolder);
     action.setExecutionCommand(executionCommand);
     action.setHostRoleCommand(hostRoleCommand);
 
@@ -122,7 +127,7 @@ public class FinalizeKerberosServerActionTest extends 
EasyMockSupport {
 
     ConcurrentMap<String, Object> requestSharedDataContext = new 
ConcurrentHashMap<>();
 
-    FinalizeKerberosServerAction action = 
injector.getInstance(FinalizeKerberosServerAction.class);
+    FinalizeKerberosServerAction action = new 
FinalizeKerberosServerAction(topologyHolder);
     action.setExecutionCommand(executionCommand);
     action.setHostRoleCommand(hostRoleCommand);
 
@@ -196,6 +201,10 @@ public class FinalizeKerberosServerActionTest extends 
EasyMockSupport {
     
expect(clusters.getHostsForCluster(clusterName)).andReturn(clusterHostMap).anyTimes();
     expect(clusters.getCluster(clusterName)).andReturn(cluster).anyTimes();
 
+    final TopologyUpdateEvent event = 
createNiceMock(TopologyUpdateEvent.class);
+    expect(topologyHolder.getCurrentData()).andReturn(event).once();
+    expect(topologyHolder.updateData(event)).andReturn(anyBoolean()).once();
+
     return Guice.createInjector(new AbstractModule() {
 
       @Override

-- 
To stop receiving notification emails like this one, please contact
rle...@apache.org.

Reply via email to