You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2015/12/22 11:46:49 UTC

ambari git commit: AMBARI-14410. It failed to change the host name from Upper to Lower case for the cluster.(vbrodetskyi)

Repository: ambari
Updated Branches:
  refs/heads/trunk 878f71a76 -> a4a530ab3


AMBARI-14410. It failed to change the host name from Upper to Lower case for the cluster.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: a4a530ab36abffa90c523b0ad898b237fa4fc7e9
Parents: 878f71a
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Tue Dec 22 12:46:20 2015 +0200
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Tue Dec 22 12:46:20 2015 +0200

----------------------------------------------------------------------
 .../ambari/server/update/HostUpdateHelper.java  | 13 +++++++++-
 .../server/update/HostUpdateHelperTest.java     | 27 ++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a4a530ab/ambari-server/src/main/java/org/apache/ambari/server/update/HostUpdateHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/update/HostUpdateHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/update/HostUpdateHelper.java
index ec4921d..44a45f9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/update/HostUpdateHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/update/HostUpdateHelper.java
@@ -338,7 +338,7 @@ public class HostUpdateHelper {
   /*
   * Method initialize Map with json data from file
   * */
-  private void initHostChangesFileMap() throws AmbariException {
+  protected void initHostChangesFileMap() throws AmbariException {
     JsonObject hostChangesJsonObject = configuration.getHostChangesJson(hostChangesFile);
     hostChangesFileMap = new HashMap<>();
 
@@ -350,6 +350,17 @@ public class HostUpdateHelper {
         throw new AmbariException("Error occurred during mapping Json to Map structure. Please check json structure in file.", e);
       }
     }
+
+    // put current host names to lower case
+    Map<String, Map<String,String>> newHostChangesFileMap = new HashMap<>();
+    for (Map.Entry<String, Map<String,String>> clusterHosts : hostChangesFileMap.entrySet()) {
+      Map<String,String> newHostPairs = new HashMap<>();
+      for (Map.Entry<String, String> hostPair : clusterHosts.getValue().entrySet()) {
+        newHostPairs.put(hostPair.getKey().toLowerCase(), hostPair.getValue());
+      }
+      newHostChangesFileMap.put(clusterHosts.getKey(), newHostPairs);
+    }
+    hostChangesFileMap = newHostChangesFileMap;
   }
 
   /*

http://git-wip-us.apache.org/repos/asf/ambari/blob/a4a530ab/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
index c59aac2..4f08a9a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
@@ -18,11 +18,14 @@
 package org.apache.ambari.server.update;
 
 
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import junit.framework.Assert;
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
@@ -504,6 +507,30 @@ public class HostUpdateHelperTest {
     easyMockSupport.verifyAll();
   }
 
+  @Test
+  public void testInitHostChangesFileMap_SUCCESS() throws AmbariException {
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final Configuration mockConfiguration = easyMockSupport.createNiceMock(Configuration.class);
+    JsonObject cluster = new JsonObject();
+    JsonObject hostPairs = new JsonObject();
+    hostPairs.add("Host1", new JsonPrimitive("hos11"));
+    hostPairs.add("Host2", new JsonPrimitive("hos22"));
+    cluster.add("cl1", hostPairs);
+
+    expect(mockConfiguration.getHostChangesJson(null)).andReturn(cluster).once();
+
+    HostUpdateHelper hostUpdateHelper = new HostUpdateHelper(null, mockConfiguration, null);
+
+    easyMockSupport.replayAll();
+    hostUpdateHelper.initHostChangesFileMap();
+    easyMockSupport.verifyAll();
+
+    Map<String, Map<String,String>> hostChangesFileMap = hostUpdateHelper.getHostChangesFileMap();
+    Assert.assertTrue(hostChangesFileMap.get("cl1").containsKey("host1"));
+    Assert.assertTrue(hostChangesFileMap.get("cl1").containsKey("host2"));
+
+  }
+
 
 }