You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2017/11/29 17:52:32 UTC

ambari git commit: AMBARI-22539. Cannot add host with host_name in request body

Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 6b5b1cac2 -> f7ef0b37c


AMBARI-22539. Cannot add host with host_name in request body


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

Branch: refs/heads/branch-2.6
Commit: f7ef0b37cd58ce1003af805ba9bb4169d01a18d2
Parents: 6b5b1ca
Author: Doroszlai, Attila <ad...@hortonworks.com>
Authored: Wed Nov 29 09:02:30 2017 +0100
Committer: Doroszlai, Attila <ad...@hortonworks.com>
Committed: Wed Nov 29 18:47:22 2017 +0100

----------------------------------------------------------------------
 .../internal/HostResourceProvider.java          |  2 +-
 .../internal/ScaleClusterRequest.java           | 15 +--------
 .../internal/ScaleClusterRequestTest.java       | 32 ++++++++++++++++----
 3 files changed, 28 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f7ef0b37/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index 0df8f13..a3499df 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
@@ -997,7 +997,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
    *
    * @return the host name for the host request
    */
-  private String getHostNameFromProperties(Map<String, Object> properties) {
+  public static String getHostNameFromProperties(Map<String, Object> properties) {
     String hostname = (String) properties.get(HOST_HOST_NAME_PROPERTY_ID);
 
     return hostname != null ? hostname :

http://git-wip-us.apache.org/repos/asf/ambari/blob/f7ef0b37/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
index ad90a25..9434f3b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
@@ -119,7 +119,7 @@ public class ScaleClusterRequest extends BaseClusterRequest {
           "Currently, a scaling request may only refer to a single blueprint");
     }
 
-    String hostName = getHostNameFromProperties(properties);
+    String hostName = HostResourceProvider.getHostNameFromProperties(properties);
     boolean containsHostCount = properties.containsKey(HostResourceProvider.HOST_COUNT_PROPERTY_ID);
     boolean containsHostPredicate = properties.containsKey(HostResourceProvider.HOST_PREDICATE_PROPERTY_ID);
 
@@ -210,19 +210,6 @@ public class ScaleClusterRequest extends BaseClusterRequest {
   }
 
   /**
-   * Get the host name from the request properties.
-   *
-   * @param properties  request properties
-   * @return host name
-   */
-  //todo: this was copied exactly from HostResourceProvider
-  private String getHostNameFromProperties(Map<String, Object> properties) {
-    String hostName = (String) properties.get(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
-
-    return hostName;
-  }
-
-  /**
    * Get the total number of requested hosts for the request.
    * @return  total requested host count
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/f7ef0b37/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
index b839557..3f96944 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
@@ -102,12 +102,17 @@ public class ScaleClusterRequestTest {
 
   @Test
   public void test_basic_hostName() throws Exception {
+    Map<String, Object> props = createScaleClusterPropertiesGroup1_HostName(CLUSTER_NAME, BLUEPRINT_NAME);
+    addSingleHostByName(props);
+    addSingleHostByName(replaceWithPlainHostNameKey(props));
+  }
+
+  private void addSingleHostByName(Map<String, Object> props) throws InvalidTopologyTemplateException {
     // reset default host resource provider expectations to none since no host predicate is used
     reset(hostResourceProvider);
     replay(hostResourceProvider);
 
-    ScaleClusterRequest scaleClusterRequest = new ScaleClusterRequest(Collections.singleton(
-        createScaleClusterPropertiesGroup1_HostName(CLUSTER_NAME, BLUEPRINT_NAME)));
+    ScaleClusterRequest scaleClusterRequest = new ScaleClusterRequest(Collections.singleton(props));
 
     assertEquals(TopologyRequest.Type.SCALE, scaleClusterRequest.getType());
     assertEquals(String.format("Scale Cluster '%s' (+%s hosts)", CLUSTER_NAME, "1"),
@@ -129,13 +134,21 @@ public class ScaleClusterRequestTest {
 
   @Test
   public void testMultipleHostNames() throws Exception {
-    // reset default host resource provider expectations to none since no host predicate is used
-    reset(hostResourceProvider);
-    replay(hostResourceProvider);
-
     Set<Map<String, Object>> propertySet = new HashSet<>();
     propertySet.add(createScaleClusterPropertiesGroup1_HostName(CLUSTER_NAME, BLUEPRINT_NAME));
     propertySet.add(createScaleClusterPropertiesGroup1_HostName2(CLUSTER_NAME, BLUEPRINT_NAME));
+    addMultipleHostsByName(propertySet);
+
+    for (Map<String, Object> props : propertySet) {
+      replaceWithPlainHostNameKey(props);
+    }
+    addMultipleHostsByName(propertySet);
+  }
+
+  private void addMultipleHostsByName(Set<Map<String, Object>> propertySet) throws InvalidTopologyTemplateException {
+    // reset default host resource provider expectations to none since no host predicate is used
+    reset(hostResourceProvider);
+    replay(hostResourceProvider);
 
     ScaleClusterRequest scaleClusterRequest = new ScaleClusterRequest(propertySet);
 
@@ -341,6 +354,13 @@ public class ScaleClusterRequestTest {
     return properties;
   }
 
+  // include host name under "host_name" key instead of "Hosts/host_name"
+  private static Map<String, Object> replaceWithPlainHostNameKey(Map<String, Object> properties) {
+    Object value = properties.remove(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
+    properties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, value);
+    return properties;
+  }
+
   public static Map<String, Object> createScaleClusterPropertiesGroup1_HostCount(String clusterName, String blueprintName) {
     Map<String, Object> properties = new LinkedHashMap<>();