You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by am...@apache.org on 2017/12/12 15:14:44 UTC
[23/24] ambari git commit: AMBARI-22539. Cannot add host with
host_name in request body
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/d80db805
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d80db805
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d80db805
Branch: refs/heads/branch-feature-AMBARI-22008-isilon
Commit: d80db805e5e6a7060c1b06cf3ee670452df092f4
Parents: 486501b
Author: Doroszlai, Attila <ad...@hortonworks.com>
Authored: Wed Nov 29 09:02:30 2017 +0100
Committer: Attila Magyar <am...@hortonworks.com>
Committed: Tue Dec 12 16:13:59 2017 +0100
----------------------------------------------------------------------
.../internal/HostResourceProvider.java | 2 +-
.../internal/ScaleClusterRequest.java | 17 +--------
.../internal/ScaleClusterRequestTest.java | 38 +++++++++++++++-----
3 files changed, 31 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/d80db805/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 f683afd..776be0c 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
@@ -1066,7 +1066,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/d80db805/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 fe33f93..5e5eec8 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);
@@ -212,21 +212,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);
- if (hostName == null) {
- hostName = (String) properties.get(HostResourceProvider.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/d80db805/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 2a03b1f..b9f32a0 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);
@@ -294,7 +307,7 @@ public class ScaleClusterRequestTest {
public void test_NoHostNameOrHostCount() throws Exception {
Map<String, Object> properties = createScaleClusterPropertiesGroup1_HostName(CLUSTER_NAME, BLUEPRINT_NAME);
// remove host name
- properties.remove("host_name");
+ properties.remove(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
// reset default host resource provider expectations to none
reset(hostResourceProvider);
@@ -336,8 +349,15 @@ public class ScaleClusterRequestTest {
properties.put(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID, clusterName);
properties.put(HostResourceProvider.BLUEPRINT_PROPERTY_ID, blueprintName);
properties.put(HostResourceProvider.HOST_GROUP_PROPERTY_ID, GROUP1_NAME);
- properties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, HOST1_NAME);
+ properties.put(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID, HOST1_NAME);
+
+ 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;
}
@@ -381,7 +401,7 @@ public class ScaleClusterRequestTest {
properties.put(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID, clusterName);
properties.put(HostResourceProvider.BLUEPRINT_PROPERTY_ID, blueprintName);
properties.put(HostResourceProvider.HOST_GROUP_PROPERTY_ID, GROUP1_NAME);
- properties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, HOST2_NAME);
+ properties.put(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID, HOST2_NAME);
return properties;
}