Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 25847627d -> d6abb5ce8


AMBARI-18863 - Upgrade Type Is Incorrectly Quoted When Serialized 
(jonathanhurley)


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

Branch: refs/heads/branch-2.5
Commit: d6abb5ce84b837a0e4e0da95336cd0613a81d05c
Parents: 2584762
Author: Jonathan Hurley <jhur...@hortonworks.com>
Authored: Fri Nov 11 10:29:43 2016 -0500
Committer: Jonathan Hurley <jhur...@hortonworks.com>
Committed: Fri Nov 11 13:27:29 2016 -0500

----------------------------------------------------------------------
 .../server/controller/internal/UpgradeResourceProvider.java  | 8 ++++++--
 .../controller/internal/UpgradeResourceProviderTest.java     | 7 +++++--
 2 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d6abb5ce/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 840e1d4..2c65c51 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -126,6 +126,7 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -1402,8 +1403,11 @@ public class UpgradeResourceProvider extends 
AbstractControllerResourceProvider
 
     Map<String, String> commandParams = getNewParameterMap(request);
     if (null != context.getType()) {
-      // use the serialized attributes of the enum to convert it to a string
-      commandParams.put(COMMAND_PARAM_UPGRADE_TYPE, 
s_gson.toJson(context.getType()));
+      // use the serialized attributes of the enum to convert it to a string,
+      // but first we must convert it into an element so that we don't get a
+      // quoted string - using toString() actually returns a quoted stirng 
which is bad
+      JsonElement json = s_gson.toJsonTree(context.getType());
+      commandParams.put(COMMAND_PARAM_UPGRADE_TYPE, json.getAsString());
     }
 
     commandParams.put(COMMAND_PARAM_VERSION, context.getVersion());

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6abb5ce/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 30dd644..d69bdbe 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -1246,10 +1246,13 @@ public class UpgradeResourceProviderTest {
     List<StageEntity> stageEntities = 
stageDAO.findByRequestId(entity.getRequestId());
     Gson gson = new Gson();
     for (StageEntity se : stageEntities) {
-      Map<String, String> map = gson.<Map<String, String>> 
fromJson(se.getCommandParamsStage(),
-          Map.class);
+      Map<String, String> map = gson.<Map<String, String>> 
fromJson(se.getCommandParamsStage(),Map.class);
       assertTrue(map.containsKey("upgrade_direction"));
       assertEquals("upgrade", map.get("upgrade_direction"));
+      
+      if(map.containsKey("upgrade_type")){
+        assertEquals("rolling_upgrade", map.get("upgrade_type"));
+      }
     }
 
     List<UpgradeGroupEntity> upgradeGroups = entity.getUpgradeGroups();

Reply via email to