Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-21674 7a3ba0fa5 -> daa1b7961


AMBARI-22403. Read the JAVA_HOME depending on the OS family during Service 
install (action & command) and upgrade (Yussuf Shaikh via ncole)


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

Branch: refs/heads/branch-feature-AMBARI-21674
Commit: daa1b7961fcae125a9f18a67e0a6d632eda251d5
Parents: 7a3ba0f
Author: Nate Cole <[email protected]>
Authored: Thu Jan 4 10:35:32 2018 -0500
Committer: Nate Cole <[email protected]>
Committed: Thu Jan 4 10:35:32 2018 -0500

----------------------------------------------------------------------
 .../server/configuration/Configuration.java     |  14 ++
 .../controller/AmbariActionExecutionHelper.java |   8 +
 .../AmbariCustomCommandExecutionHelper.java     |  15 ++
 .../AmbariManagementControllerImpl.java         |   5 +
 .../internal/ClientConfigResourceProvider.java  |   2 +
 .../apache/ambari/server/utils/StageUtils.java  |   1 -
 .../server/configuration/ConfigurationTest.java |  11 ++
 .../AmbariCustomCommandExecutionHelperTest.java |  41 +++-
 .../AmbariManagementControllerImplTest.java     |   2 +-
 .../AmbariManagementControllerTest.java         | 197 +++++++++++++++++++
 .../ClientConfigResourceProviderTest.java       |  10 +-
 ...ClusterStackVersionResourceProviderTest.java |   5 +
 .../HostStackVersionResourceProviderTest.java   |   9 +-
 .../ambari/server/utils/StageUtilsTest.java     |   4 +-
 14 files changed, 310 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 182cd58..1430513 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -3068,6 +3068,20 @@ public class Configuration {
   }
 
   /**
+   * Get the Java Home property value for the given os_type. If the value is 
not
+   * found then get the default Java Home property value
+   * @param os_type OS type of the host
+   * @return the Java Home path value for given OS type
+   */
+  public String getJavaHomeForOs(String os_type) {
+    String returnValue = getPropertyForced(JAVA_HOME.getKey() + "." + os_type);
+    if (returnValue == null) {
+      returnValue = getJavaHome();
+    }
+    return returnValue;
+  }
+
+  /**
    * Gets a copy of all of the configuration properties that back this
    * {@link Configuration} instance.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
index c0a7a7b..dc484f7 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
@@ -22,6 +22,7 @@ import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STA
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STACK_RETRY_ON_UNAVAILABILITY;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMPONENT_CATEGORY;
+import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT_TYPE;
 
@@ -456,6 +457,7 @@ public class AmbariActionExecutionHelper {
         resourceFilter.getComponentName() : componentName);
 
       Map<String, String> hostLevelParams = execCmd.getHostLevelParams();
+
       hostLevelParams.put(AGENT_STACK_RETRY_ON_UNAVAILABILITY, 
configs.isAgentStackRetryOnInstallEnabled());
       hostLevelParams.put(AGENT_STACK_RETRY_COUNT, 
configs.getAgentStackRetryOnInstallCount());
       for (Map.Entry<String, String> dbConnectorName : 
configs.getDatabaseConnectorNames().entrySet()) {
@@ -493,6 +495,12 @@ public class AmbariActionExecutionHelper {
         cluster.addSuspendedUpgradeParameters(commandParams, roleParams);
       }
 
+      // set java home for each host depending on os type; if not found 
default will be used
+      String javaHomeValue = 
configs.getJavaHomeForOs(clusters.getHost(hostName).getOsType());
+      commandParams.put(JAVA_HOME, javaHomeValue);
+      hostLevelParams.put(JAVA_HOME, javaHomeValue);
+      roleParams.put(JAVA_HOME, javaHomeValue);
+
       execCmd.setCommandParams(commandParams);
       execCmd.setRoleParams(roleParams);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index c4df0b1..b331453 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -29,6 +29,7 @@ import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_NAME;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GPL_LICENSE_ACCEPTED;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GROUP_LIST;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOST_SYS_PREPPED;
+import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.MYSQL_JDBC_URL;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.NOT_MANAGED_HDFS_PATH_LIST;
@@ -437,6 +438,10 @@ public class AmbariCustomCommandExecutionHelper {
       String notManagedHdfsPathList = gson.toJson(notManagedHdfsPathSet);
       hostLevelParams.put(NOT_MANAGED_HDFS_PATH_LIST, notManagedHdfsPathList);
 
+      // set java home for each host depending on os type; if not found 
default will be used
+      String javaHomeValue = configs.getJavaHomeForOs(host.getOsType());
+      hostLevelParams.put(JAVA_HOME, javaHomeValue);
+
       execCmd.setHostLevelParams(hostLevelParams);
 
       Map<String, String> commandParams = new TreeMap<>();
@@ -744,6 +749,16 @@ public class AmbariCustomCommandExecutionHelper {
     ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostname,
         smokeTestRole).getExecutionCommand();
 
+    // set java home for each host depending on os type; if not found default 
will be used
+    String javaHomeValue = 
configs.getJavaHomeForOs(clusters.getHost(hostname).getOsType());
+    if (execCmd.getHostLevelParams() == null) {
+      Map<String,String> hostLevelParams = new TreeMap<>();
+      hostLevelParams.put(JAVA_HOME, javaHomeValue);
+      execCmd.setHostLevelParams(hostLevelParams);
+    } else {
+      execCmd.getHostLevelParams().put(JAVA_HOME, javaHomeValue);
+    }
+
     // if the command should fetch brand new configuration tags before
     // execution, then we don't need to fetch them now
     if(actionParameters != null && 
actionParameters.containsKey(KeyNames.REFRESH_CONFIG_TAGS_BEFORE_EXECUTION)){

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
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 198b617..7df38a6 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
@@ -28,6 +28,7 @@ import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_T
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CUSTOM_FOLDER;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_DRIVER_FILENAME;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GROUP_LIST;
+import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.MAX_DURATION_OF_RETRIES;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.NOT_MANAGED_HDFS_PATH_LIST;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.PACKAGE_LIST;
@@ -2493,6 +2494,10 @@ public class AmbariManagementControllerImpl implements 
AmbariManagementControlle
     // Set/update the unlimited_key_jce_required value as needed
     hostParams.put(UNLIMITED_KEY_JCE_REQUIRED, (unlimitedKeyJCEPolicyRequired) 
? "true" : "false");
 
+    // set java home for each host depending on os type; if not found default 
will be used
+    String javaHomeValue = configs.getJavaHomeForOs(host.getOsType());
+    hostParams.put(JAVA_HOME, javaHomeValue);
+
     execCmd.setHostLevelParams(hostParams);
 
     Map<String, String> roleParams = new TreeMap<>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
index dcafdea..eddebed 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
@@ -24,6 +24,7 @@ import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_NAME;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GPL_LICENSE_ACCEPTED;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GROUP_LIST;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOST_SYS_PREPPED;
+import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.MYSQL_JDBC_URL;
 import static 
org.apache.ambari.server.agent.ExecutionCommand.KeyNames.NOT_MANAGED_HDFS_PATH_LIST;
@@ -370,6 +371,7 @@ public class ClientConfigResourceProvider extends 
AbstractControllerResourceProv
         osFamily = clusters.getHost(hostName).getOsFamily();
 
         TreeMap<String, String> hostLevelParams = new TreeMap<>();
+        hostLevelParams.put(JAVA_HOME, 
configs.getJavaHomeForOs(clusters.getHost(hostName).getOsType()));
         StageUtils.useStackJdkIfExists(hostLevelParams, configs);
         hostLevelParams.put(JDK_LOCATION, 
managementController.getJdkResourceUrl());
         hostLevelParams.put(STACK_NAME, stackId.getStackName());

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java 
b/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
index b6287e6..016978c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
@@ -630,7 +630,6 @@ public class StageUtils {
    */
   public static void useStackJdkIfExists(Map<String, String> hostLevelParams, 
Configuration configuration) {
     // set defaults first
-    hostLevelParams.put(JAVA_HOME, configuration.getJavaHome());
     hostLevelParams.put(JDK_NAME, configuration.getJDKName());
     hostLevelParams.put(JCE_NAME, configuration.getJCEName());
     hostLevelParams.put(JAVA_VERSION, 
String.valueOf(configuration.getJavaVersion()));

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
index e47fcd2..c156c22 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
@@ -319,6 +319,17 @@ public class ConfigurationTest {
   }
 
   @Test
+  public void testGetJavaHomeForOs() throws Exception {
+    final Configuration conf = new Configuration();
+    conf.setProperty("java.home", "default_value");
+    conf.setProperty("java.home.redhat-ppc7", "ppc_value");
+    Assert.assertEquals("ppc_value", conf.getJavaHomeForOs("redhat-ppc7"));
+    Assert.assertEquals("default_value", conf.getJavaHomeForOs("redhat7"));
+    Assert.assertEquals("default_value", conf.getJavaHomeForOs(""));
+    Assert.assertEquals("default_value", conf.getJavaHomeForOs(null));
+  }
+
+  @Test
   public void testGetAmbariBlacklistFile() {
     Properties ambariProperties = new Properties();
     Configuration conf = new Configuration(ambariProperties);

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index 6bece66..00d1384 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -139,7 +139,9 @@ public class AmbariCustomCommandExecutionHelperTest {
     clusters = injector.getInstance(Clusters.class);
 
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
-    StageUtils.setConfiguration(injector.getInstance(Configuration.class));
+    Configuration configuration = injector.getInstance(Configuration.class);
+    configuration.setProperty("java.home.redhat-ppc7", "ppc_java_home_path");
+    StageUtils.setConfiguration(configuration);
 
     
SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
     createClusterFixture("c1", new StackId("HDP-2.0.6"), "2.0.6-1234", "c1");
@@ -534,6 +536,43 @@ public class AmbariCustomCommandExecutionHelperTest {
   }
 
   @Test
+  public void testAddExecutionCommandsToStageWithJavaHomeValue() throws 
Exception {
+
+    clusters.getHost("c1-c6401").setState(HostState.HEALTHY);
+    clusters.getHost("c1-c6401").setOsType("redhat-ppc7");
+
+    Map<String, String> requestProperties = new HashMap<String, String>() {
+      {
+        put(REQUEST_CONTEXT_PROPERTY, "Refresh YARN Capacity Scheduler");
+        put("command", "REFRESHQUEUES");
+      }
+    };
+    ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", 
"REFRESHQUEUES",
+            new HashMap<String, String>() {
+              {
+                put("forceRefreshConfigTags", "capacity-scheduler");
+              }
+            }, false);
+    actionRequest.getResourceFilters().add(new RequestResourceFilter("YARN", 
"RESOURCEMANAGER", Collections.singletonList("c1-c6401")));
+    EasyMock.replay(hostRoleCommand, actionManager, configHelper);
+
+    ambariManagementController.createAction(actionRequest, requestProperties);
+
+    Request request = requestCapture.getValue();
+    Stage stage = request.getStages().iterator().next();
+    List<ExecutionCommandWrapper> commands = 
stage.getExecutionCommands("c1-c6401");
+    ExecutionCommand command = commands.get(0).getExecutionCommand();
+
+    
Assert.assertTrue(command.getHostLevelParams().containsValue("ppc_java_home_path"));
+
+    // ZK is the only service that is versionable
+    Assert.assertFalse(MapUtils.isEmpty(command.getComponentVersionMap()));
+    Assert.assertEquals(1, command.getComponentVersionMap().size());
+    
Assert.assertTrue(command.getComponentVersionMap().containsKey("ZOOKEEPER"));
+  }
+
+
+  @Test
   public void testAvailableServicesMapContainsVersions() throws Exception {
 
     Map<String, String> requestProperties = new HashMap<String, String>() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index e795d28..28d3446 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -2123,7 +2123,7 @@ public class AmbariManagementControllerImplTest {
 
     Map<String, String> defaultHostParams = 
helper.createDefaultHostParams(cluster, repositoryVersionEntity.getStackId());
 
-    assertEquals(16, defaultHostParams.size());
+    assertEquals(15, defaultHostParams.size());
     assertEquals(MYSQL_JAR, defaultHostParams.get(DB_DRIVER_FILENAME));
     assertEquals(SOME_STACK_NAME, defaultHostParams.get(STACK_NAME));
     assertEquals(SOME_STACK_VERSION, defaultHostParams.get(STACK_VERSION));

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index a1f28f1..8a68680 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -306,6 +306,8 @@ public class AmbariManagementControllerTest {
         new StackId("HDP-2.2.0"), "2.2.0-1234");
 
     repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
+
+    configuration.setProperty("java.home.redhat-ppc7", "ppc_java_home_path");
   }
 
   @After
@@ -1249,6 +1251,30 @@ public class AmbariManagementControllerTest {
     assertEquals("false", ec.getCommandParams().get("command_retry_enabled"));
   }
 
+  @Test
+  public void testGetExecutionCommandWithJavaHomeValue() throws Exception{
+
+      String cluster1 = "cluster11234";
+      final String host1 = getUniqueName();
+      final String host2 = getUniqueName();
+      String serviceName = "HDFS";
+      createServiceComponentHostSimple(cluster1, host1, host2);
+      clusters.getHost(host1).setState(HostState.HEALTHY);
+      clusters.getHost(host1).setOsType("redhat-ppc7");
+
+      Cluster cluster = clusters.getCluster(cluster1);
+      Service s1 = cluster.getService(serviceName);
+
+      ServiceComponentHost 
scHost=s1.getServiceComponent("DATANODE").getServiceComponentHost(host1);
+
+      installService(cluster1, serviceName, false, false);
+
+      ExecutionCommand ec = controller.getExecutionCommand(cluster, scHost, 
RoleCommand.START);
+
+      assertTrue(ec.getHostLevelParams().containsValue("ppc_java_home_path"));
+
+    }
+
 
   @Test
   public void testGetExecutionCommand() throws Exception {
@@ -4056,6 +4082,104 @@ public class AmbariManagementControllerTest {
   }
 
   @Test
+  public void 
testAddExecutionCommandsToStageWithJavaHomeValueForAmbariActionExecutionHelper()
 throws Exception {
+    final String cluster1 = getUniqueName();
+    final String host1 = "a" + getUniqueName();
+    final String host2 = "b" + getUniqueName();
+    final String host3 = "c" + getUniqueName();
+
+    setupClusterWithHosts(cluster1, "HDP-2.0.6",
+        new ArrayList<String>() {{
+          add(host1);
+          add(host2);
+          add(host3);
+        }},
+        "centos6");
+
+    clusters.getHost(host1).setState(HostState.HEALTHY);
+    clusters.getHost(host1).setOsType("redhat-ppc7");
+
+    Cluster cluster = clusters.getCluster(cluster1);
+    cluster.setDesiredStackVersion(new StackId("HDP-2.0.6"));
+    cluster.setCurrentStackVersion(new StackId("HDP-2.0.6"));
+
+    ConfigFactory cf = injector.getInstance(ConfigFactory.class);
+    Config config1 = cf.createNew(cluster, "global", "version1",
+        new HashMap<String, String>() {{
+          put("key1", "value1");
+        }}, new HashMap<>());
+
+    Config config2 = cf.createNew(cluster, "core-site", "version1",
+        new HashMap<String, String>() {{
+          put("key1", "value1");
+        }}, new HashMap<>());
+
+    Config config3 = cf.createNew(cluster, "yarn-site", "version1",
+        new HashMap<String, String>() {{
+          put("test.password", "supersecret");
+        }}, new HashMap<>());
+
+    RepositoryVersionEntity repositoryVersion = repositoryVersion206;
+
+    Service hdfs = cluster.addService("HDFS", repositoryVersion);
+    Service mapred = cluster.addService("YARN", repositoryVersion);
+
+    hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
+    hdfs.addServiceComponent(Role.NAMENODE.name());
+    hdfs.addServiceComponent(Role.DATANODE.name());
+
+    mapred.addServiceComponent(Role.RESOURCEMANAGER.name());
+
+    
hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1);
+    
hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1);
+    
hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(host1);
+    
hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(host2);
+
+    String actionDef1 = getUniqueName();
+    String actionDef2 = getUniqueName();
+
+    ActionDefinition a1 = new ActionDefinition(actionDef1, ActionType.SYSTEM,
+        "test,[optional1]", "", "", "Does file exist", 
TargetHostType.SPECIFIC, Short.valueOf("100"), null);
+    controller.getAmbariMetaInfo().addActionDefinition(a1);
+    controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
+        actionDef2, ActionType.SYSTEM, "", "HDFS", "DATANODE", "Does file 
exist",
+        TargetHostType.ALL, Short.valueOf("1000"), null));
+
+    Map<String, String> params = new HashMap<String, String>() {{
+      put("test", "test");
+      put("pwd", "SECRET:yarn-site:1:test.password");
+    }};
+
+    Map<String, String> requestProperties = new HashMap<>();
+    requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");
+    requestProperties.put("datanode", "abc");
+
+    ArrayList<String> hosts = new ArrayList<String>() {{add(host1);}};
+    RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS", 
"DATANODE", hosts);
+    List<RequestResourceFilter> resourceFilters = new ArrayList<>();
+    resourceFilters.add(resourceFilter);
+
+    ExecuteActionRequest actionRequest = new ExecuteActionRequest(cluster1, 
null, actionDef1, resourceFilters, null, params, false);
+    RequestStatusResponse response = controller.createAction(actionRequest, 
requestProperties);
+    assertEquals(1, response.getTasks().size());
+    ShortTaskStatus taskStatus = response.getTasks().get(0);
+    Assert.assertEquals(host1, taskStatus.getHostName());
+
+    List<HostRoleCommand> storedTasks = 
actionDB.getRequestTasks(response.getRequestId());
+    Stage stage = actionDB.getAllStages(response.getRequestId()).get(0);
+    Assert.assertNotNull(stage);
+
+    Assert.assertEquals(1, storedTasks.size());
+    HostRoleCommand task = storedTasks.get(0);
+    Assert.assertEquals(RoleCommand.ACTIONEXECUTE, task.getRoleCommand());
+    Assert.assertEquals(actionDef1, task.getRole().name());
+    Assert.assertEquals(host1, task.getHostName());
+    ExecutionCommand cmd = 
task.getExecutionCommandWrapper().getExecutionCommand();
+
+    assertTrue(cmd.getHostLevelParams().containsValue("ppc_java_home_path"));
+  }
+
+  @Test
   public void testComponentCategorySentWithRestart() throws Exception, 
AuthorizationException {
     final String cluster1 = getUniqueName();
     final String host1 = getUniqueName();
@@ -4546,6 +4670,79 @@ public class AmbariManagementControllerTest {
     controller.createUsers(new HashSet<>(Collections.singleton(request)));
   }
 
+  @SuppressWarnings("serial")
+  @Test
+  public void testAddServiceCheckActionWithJavaHomeValue() throws Exception {
+    final String cluster1 = getUniqueName();
+    final String host1 = getUniqueName();
+    final String host2 = getUniqueName();
+
+    setupClusterWithHosts(cluster1, "HDP-0.1",
+        new ArrayList<String>() {{
+          add(host1);
+          add(host2);
+        }},
+        "centos5");
+
+    Cluster cluster = clusters.getCluster(cluster1);
+    cluster.setDesiredStackVersion(new StackId("HDP-0.1"));
+    cluster.setCurrentStackVersion(new StackId("HDP-0.1"));
+
+    clusters.getHost(host1).setState(HostState.HEALTHY);
+    clusters.getHost(host1).setOsType("redhat-ppc7");
+
+    RepositoryVersionEntity repositoryVersion = repositoryVersion01;
+
+    ConfigFactory cf = injector.getInstance(ConfigFactory.class);
+    Config config1 = cf.createNew(cluster, "global", "version1",
+        new HashMap<String, String>(){{ put("key1", "value1"); }}, new 
HashMap<>());
+    config1.setPropertiesAttributes(new HashMap<String, Map<String, 
String>>(){{ put("attr1", new HashMap<>()); }});
+
+    Config config2 = cf.createNew(cluster, "core-site", "version1",
+        new HashMap<String, String>(){{ put("key1", "value1"); }}, new 
HashMap<>());
+    config2.setPropertiesAttributes(new HashMap<String, Map<String, 
String>>(){{ put("attr2", new HashMap<>()); }});
+
+    cluster.addDesiredConfig("_test", Collections.singleton(config1));
+    cluster.addDesiredConfig("_test", Collections.singleton(config2));
+
+    Service hdfs = cluster.addService("HDFS", repositoryVersion);
+    Service mapReduce = cluster.addService("MAPREDUCE", repositoryVersion);
+
+    hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
+    mapReduce.addServiceComponent(Role.MAPREDUCE_CLIENT.name());
+
+    
hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1);
+    
mapReduce.getServiceComponent(Role.MAPREDUCE_CLIENT.name()).addServiceComponentHost(host2);
+
+    Map<String, String> params = new HashMap<String, String>() {{
+      put("test", "test");
+    }};
+    ExecuteActionRequest actionRequest = new ExecuteActionRequest(cluster1, 
Role.HDFS_SERVICE_CHECK.name(), params, false);
+    RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS", 
null, null);
+    actionRequest.getResourceFilters().add(resourceFilter);
+
+    Map<String, String> requestProperties = new HashMap<>();
+    requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");
+
+    RequestStatusResponse response = controller.createAction(actionRequest, 
requestProperties);
+
+    assertEquals(1, response.getTasks().size());
+    ShortTaskStatus task = response.getTasks().get(0);
+
+    List<HostRoleCommand> storedTasks = 
actionDB.getRequestTasks(response.getRequestId());
+    Stage stage = actionDB.getAllStages(response.getRequestId()).get(0);
+
+    //Check configs not stored with execution command
+    ExecutionCommandDAO executionCommandDAO = 
injector.getInstance(ExecutionCommandDAO.class);
+    ExecutionCommandEntity commandEntity = 
executionCommandDAO.findByPK(task.getTaskId());
+
+    Gson gson = new Gson();
+    ExecutionCommand executionCommand = gson.fromJson(new StringReader(
+        new String(commandEntity.getCommand())), ExecutionCommand.class);
+
+    
assertTrue(executionCommand.getHostLevelParams().containsValue("ppc_java_home_path"));
+  }
+
   @Test
   public void testCreateAndGetUsers() throws Exception {
     createUser("user1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
index c5994c5..07d614b 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
@@ -264,7 +264,8 @@ public class ClientConfigResourceProviderTest {
     
expect(configMap.get(Configuration.AMBARI_PYTHON_WRAP.getKey())).andReturn(Configuration.AMBARI_PYTHON_WRAP.getDefaultValue());
     expect(configuration.getConfigsMap()).andReturn(returnConfigMap);
     expect(configuration.getResourceDirPath()).andReturn(stackRoot);
-    expect(configuration.getJavaHome()).andReturn("dummy_java_home");
+    expect(host.getOsType()).andReturn("redhat7");
+    
expect(configuration.getJavaHomeForOs("redhat7")).andReturn("dummy_java_home");
     expect(configuration.getJDKName()).andReturn(null);
     expect(configuration.getJCEName()).andReturn(null);
     expect(configuration.getJavaVersion()).andReturn(8);
@@ -314,7 +315,7 @@ public class ClientConfigResourceProviderTest {
     expect(cluster.getConfig("hive-site", null)).andReturn(clusterConfig);
     expect(clusterConfig.getType()).andReturn("hive-site").anyTimes();
     expect(cluster.getDesiredConfigs()).andReturn(desiredConfigMap);
-    expect(clusters.getHost(hostName)).andReturn(host);
+    expect(clusters.getHost(hostName)).andReturn(host).anyTimes();
 
     expect(cluster.getService(serviceName)).andReturn(service).atLeastOnce();
     
expect(service.getServiceComponent(componentName)).andReturn(serviceComponent).atLeastOnce();
@@ -520,7 +521,8 @@ public class ClientConfigResourceProviderTest {
     
expect(configMap.get(Configuration.AMBARI_PYTHON_WRAP.getKey())).andReturn(Configuration.AMBARI_PYTHON_WRAP.getDefaultValue());
     expect(configuration.getConfigsMap()).andReturn(returnConfigMap);
     
expect(configuration.getResourceDirPath()).andReturn("/var/lib/ambari-server/src/main/resources");
-    expect(configuration.getJavaHome()).andReturn("dummy_java_home");
+    expect(host.getOsType()).andReturn("redhat7");
+    
expect(configuration.getJavaHomeForOs("redhat7")).andReturn("dummy_java_home");
     expect(configuration.getJDKName()).andReturn(null);
     expect(configuration.getJCEName()).andReturn(null);
     expect(configuration.getJavaVersion()).andReturn(8);
@@ -571,7 +573,7 @@ public class ClientConfigResourceProviderTest {
     expect(cluster.getConfig("hive-site", null)).andReturn(clusterConfig);
     expect(clusterConfig.getType()).andReturn("hive-site").anyTimes();
     expect(cluster.getDesiredConfigs()).andReturn(desiredConfigMap);
-    expect(clusters.getHost(hostName)).andReturn(host);
+    expect(clusters.getHost(hostName)).andReturn(host).anyTimes();
 
     expect(cluster.getService(serviceName)).andReturn(service).atLeastOnce();
     
expect(service.getServiceComponent(componentName)).andReturn(serviceComponent).atLeastOnce();

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
index 51035ba..2e07505 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
@@ -244,6 +244,7 @@ public class ClusterStackVersionResourceProviderTest {
           MaintenanceState.OFF).anyTimes();
       expect(host.getAllHostVersions()).andReturn(
           Collections.emptyList()).anyTimes();
+      expect(clusters.getHost(hostname)).andReturn(host).anyTimes();
 
       replay(host);
       hostsForCluster.put(hostname, host);
@@ -634,6 +635,7 @@ public class ClusterStackVersionResourceProviderTest {
           MaintenanceState.OFF).anyTimes();
       expect(host.getAllHostVersions()).andReturn(
           Collections.emptyList()).anyTimes();
+      expect(clusters.getHost(hostname)).andReturn(host).anyTimes();
 
       replay(host);
       hostsForCluster.put(hostname, host);
@@ -871,6 +873,7 @@ public class ClusterStackVersionResourceProviderTest {
           MaintenanceState.OFF).anyTimes();
       expect(host.getAllHostVersions()).andReturn(
           Collections.emptyList()).anyTimes();
+      expect(clusters.getHost(hostname)).andReturn(host).anyTimes();
 
       replay(host);
       hostsForCluster.put(hostname, host);
@@ -1486,6 +1489,7 @@ public class ClusterStackVersionResourceProviderTest {
             .put("os_release_version", "7.2")
             .build()
           ).anyTimes();
+      expect(clusters.getHost(hostname)).andReturn(host).anyTimes();
       replay(host);
       hostsForCluster.put(hostname, host);
     }
@@ -1987,6 +1991,7 @@ public class ClusterStackVersionResourceProviderTest {
        expect(host.getAllHostVersions()).andReturn(
            Collections.<HostVersionEntity>emptyList()).anyTimes();
        expect(host.getHostAttributes()).andReturn(new HashMap<String, 
String>()).anyTimes();
+       expect(clusters.getHost(hostname)).andReturn(host).anyTimes();
        replay(host);
        hostsForCluster.put(hostname, host);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
index 670c187..1eb5111 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
@@ -134,13 +134,13 @@ public class HostStackVersionResourceProviderTest {
     repositoryVersionDAOMock = createNiceMock(RepositoryVersionDAO.class);
     hostVersionDAOMock = createNiceMock(HostVersionDAO.class);
     configHelper = createNiceMock(ConfigHelper.class);
+    clusters = createNiceMock(Clusters.class);
     // Initialize injector
     InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
     injector = Guice.createInjector(Modules.override(module).with(new 
MockModule()));
     injector.getInstance(GuiceJpaInitializer.class);
     ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
     managementController = createMock(AmbariManagementController.class);
-    clusters = createNiceMock(Clusters.class);
     cluster = createNiceMock(Cluster.class);
     response = createNiceMock(RequestStatusResponse.class);
     resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
@@ -236,7 +236,7 @@ public class HostStackVersionResourceProviderTest {
         eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
-    expect(clusters.getHost(anyObject(String.class))).andReturn(host1);
+    
expect(clusters.getHost(anyObject(String.class))).andReturn(host1).anyTimes();
     
expect(cluster.getHosts()).andReturn(hostsForCluster.values()).atLeastOnce();
     expect(cluster.getServices()).andReturn(new HashMap<>()).anyTimes();
     expect(cluster.getCurrentStackVersion()).andReturn(stackId);
@@ -330,7 +330,7 @@ public class HostStackVersionResourceProviderTest {
       eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
-    expect(clusters.getHost(anyObject(String.class))).andReturn(host1);
+    
expect(clusters.getHost(anyObject(String.class))).andReturn(host1).anyTimes();
     
expect(cluster.getHosts()).andReturn(hostsForCluster.values()).atLeastOnce();
     expect(cluster.getServices()).andReturn(new HashMap<>()).anyTimes();
     expect(cluster.getCurrentStackVersion()).andReturn(stackId);
@@ -426,7 +426,7 @@ public class HostStackVersionResourceProviderTest {
             
eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
-    expect(clusters.getHost(anyObject(String.class))).andReturn(host1);
+    
expect(clusters.getHost(anyObject(String.class))).andReturn(host1).anyTimes();
     
expect(cluster.getHosts()).andReturn(hostsForCluster.values()).atLeastOnce();
     expect(cluster.getServices()).andReturn(new HashMap<>()).anyTimes();
     expect(cluster.getCurrentStackVersion()).andReturn(stackId);
@@ -491,6 +491,7 @@ public class HostStackVersionResourceProviderTest {
       bind(RepositoryVersionDAO.class).toInstance(repositoryVersionDAOMock);
       bind(HostVersionDAO.class).toInstance(hostVersionDAOMock);
       bind(ConfigHelper.class).toInstance(configHelper);
+      bind(Clusters.class).toInstance(clusters);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/daa1b796/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
index b90295d..0ac1279 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
@@ -708,16 +708,14 @@ public class StageUtilsTest extends EasyMockSupport {
     // GIVEN
     Map<String, String> hostLevelParams = new HashMap<>();
     Configuration configuration = new Configuration();
-    configuration.setProperty("java.home", "myJavaHome");
     configuration.setProperty("jdk.name", "myJdkName");
     configuration.setProperty("jce.name", "myJceName");
     // WHEN
     StageUtils.useStackJdkIfExists(hostLevelParams, configuration);
     // THEN
-    assertEquals("myJavaHome", hostLevelParams.get("java_home"));
     assertEquals("myJdkName", hostLevelParams.get("jdk_name"));
     assertEquals("myJceName", hostLevelParams.get("jce_name"));
-    assertEquals(4, hostLevelParams.size());
+    assertEquals(3, hostLevelParams.size());
   }
 
   private void checkServiceHostIndexes(Map<String, Set<String>> info, String 
componentName, String mappedComponentName,

Reply via email to