You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/06/05 19:12:06 UTC

svn commit: r1489966 - in /incubator/ambari/trunk/ambari-server/src: main/python/ambari-server.py test/java/org/apache/ambari/server/utils/TestVersionUtils.java test/python/TestAmbaryServer.py

Author: smohanty
Date: Wed Jun  5 17:12:05 2013
New Revision: 1489966

URL: http://svn.apache.org/r1489966
Log:
AMBARI-2290. Ambari Upgrade prcoess should preserve the old configs and add the new config options to the old config files. (Dmitry Sen via smohanty)

Added:
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java
Modified:
    incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
    incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py

Modified: incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py?rev=1489966&r1=1489965&r2=1489966&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py Wed Jun  5 17:12:05 2013
@@ -798,11 +798,6 @@ def update_ambari_properties():
   old_properties = None
   new_properties = None
 
-  prop_dict = {JDBC_USER_NAME_PROPERTY : None,
-               JDBC_PASSWORD_FILE_PROPERTY : None,
-               JAVA_HOME_PROPERTY : None,
-               OS_TYPE_PROPERTY : None}
-
   try:
     old_properties = Properties()
     old_properties.load(open(prev_conf_file))
@@ -810,18 +805,12 @@ def update_ambari_properties():
     print 'Could not read "%s": %s' % (prev_conf_file, e)
     return -1
 
-  for prop_key in prop_dict.keys():
-    value = old_properties.get_property(prop_key)
-    if value:
-      prop_dict[prop_key] = value
-
   try:
     new_properties = Properties()
     new_properties.load(open(conf_file))
 
-    for prop_key,prop_value in prop_dict.items():
-      if not prop_value is None:
-        new_properties.process_pair(prop_key,prop_value)
+    for prop_key, prop_value in old_properties.getPropertyDict().items():
+      new_properties.process_pair(prop_key,prop_value)
 
     new_properties.store(open(conf_file,'w'))
 

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java?rev=1489966&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java Wed Jun  5 17:12:05 2013
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.utils;
+
+import junit.framework.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.junit.rules.ExpectedException;
+
+public class TestVersionUtils {
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Test
+  public void testVersionCompareSuccess() {
+    Assert.assertTrue(VersionUtils.areVersionsEqual("1.2.3", "1.2.3", false));
+    Assert.assertTrue(VersionUtils.areVersionsEqual("1.2.3", "1.2.3", true));
+    Assert.assertTrue(VersionUtils.areVersionsEqual("", "", true));
+    Assert.assertTrue(VersionUtils.areVersionsEqual(null, null, true));
+
+    Assert.assertFalse(VersionUtils.areVersionsEqual("1.2.3.1", "1.2.3", false));
+    Assert.assertFalse(VersionUtils.areVersionsEqual("2.1.3", "1.2.3", false));
+    Assert.assertFalse(VersionUtils.areVersionsEqual("1.2.3.1", "1.2.3", true));
+    Assert.assertFalse(VersionUtils.areVersionsEqual("2.1.3", "1.2.3", true));
+    Assert.assertFalse(VersionUtils.areVersionsEqual("", "1.2.3", true));
+    Assert.assertFalse(VersionUtils.areVersionsEqual("", null, true));
+    Assert.assertFalse(VersionUtils.areVersionsEqual(null, "", true));
+    Assert.assertFalse(VersionUtils.areVersionsEqual(null, "1.2.3", true));
+
+    Assert.assertEquals(-1, VersionUtils.compareVersions("1.2.3", "1.2.4"));
+    Assert.assertEquals(1, VersionUtils.compareVersions("1.2.4", "1.2.3"));
+    Assert.assertEquals(0, VersionUtils.compareVersions("1.2.3", "1.2.3"));
+
+    Assert.assertEquals(-1, VersionUtils.compareVersions("1.2.3", "1.2.4", 3));
+    Assert.assertEquals(1, VersionUtils.compareVersions("1.2.4", "1.2.3", 3));
+    Assert.assertEquals(0, VersionUtils.compareVersions("1.2.3", "1.2.3", 3));
+
+    Assert.assertEquals(-1, VersionUtils.compareVersions("1.2.3.9", "1.2.4.6", 3));
+    Assert.assertEquals(-1, VersionUtils.compareVersions("1.2.3", "1.2.4.6", 3));
+    Assert.assertEquals(-1, VersionUtils.compareVersions("1.2", "1.2.4.6", 3));
+    Assert.assertEquals(1, VersionUtils.compareVersions("1.2.4.8", "1.2.3.6.7", 3));
+    Assert.assertEquals(0, VersionUtils.compareVersions("1.2.3", "1.2.3.4", 3));
+    Assert.assertEquals(0, VersionUtils.compareVersions("1.2.3.6.7", "1.2.3.4", 3));
+    Assert.assertEquals(1, VersionUtils.compareVersions("1.2.3.6.7", "1.2.3.4", 4));
+
+    Assert.assertEquals(1, VersionUtils.compareVersions("1.2.3.1", "1.2.3", true));
+    Assert.assertEquals(1, VersionUtils.compareVersions("2.1.3", "1.2.3", true));
+    Assert.assertEquals(-1, VersionUtils.compareVersions("", "1.2.3", true));
+    Assert.assertEquals(1, VersionUtils.compareVersions("", null, true));
+    Assert.assertEquals(-1, VersionUtils.compareVersions(null, "", true));
+    Assert.assertEquals(-1, VersionUtils.compareVersions(null, "1.2.3", true));
+  }
+
+  @Test
+  public void testVersionCompareError() {
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("version2 cannot be null or empty");
+    VersionUtils.areVersionsEqual("1.2.3", "", false);
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("version1 cannot be null or empty");
+    VersionUtils.areVersionsEqual(null, "", false);
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("version1 cannot be null or empty");
+    VersionUtils.areVersionsEqual("", "1", false);
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("version1 cannot be null or empty");
+    VersionUtils.compareVersions("", "1", 2);
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("maxLengthToCompare cannot be less than 0");
+    VersionUtils.compareVersions("2", "1", -1);
+  }
+}

Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py?rev=1489966&r1=1489965&r2=1489966&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py Wed Jun  5 17:12:05 2013
@@ -1196,6 +1196,9 @@ class TestAmbariServer(TestCase):
       "java.home=/usr/jdk64/jdk1.6.0_31\n",
       "server.os_type=redhat6\n"]
 
+    NEW_PROPERTY = 'some_new_property=some_value\n'
+    CHANGED_VALUE_PROPERTY = 'server.os_type=should_not_overwrite_value\n'
+
     get_conf_dir_mock.return_value = ""
 
     tf1 = tempfile.NamedTemporaryFile()
@@ -1203,6 +1206,10 @@ class TestAmbariServer(TestCase):
     ambari_server.AMBARI_PROPERTIES_RPMSAVE_FILE = tf1.name
     ambari_server.AMBARI_PROPERTIES_FILE = tf2.name
 
+    with open(ambari_server.AMBARI_PROPERTIES_FILE, "w") as f:
+      f.write(NEW_PROPERTY)
+      f.write(CHANGED_VALUE_PROPERTY)
+
     with open(ambari_server.AMBARI_PROPERTIES_RPMSAVE_FILE, 'w') as f:
       for line in properties:
         f.write(line)
@@ -1217,6 +1224,12 @@ class TestAmbariServer(TestCase):
       if not line in ambari_properties_content:
         self.fail()
 
+    if not NEW_PROPERTY in ambari_properties_content:
+      self.fail()
+
+    if CHANGED_VALUE_PROPERTY in ambari_properties_content:
+      self.fail()
+
     pass
 
   def get_sample(self, sample):