ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-15348 Ambari upgrade/start commands should detect any ambari-server hotfix and fail upgrade/start from proceeding (dsen)
Date Mon, 14 Mar 2016 12:39:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 3b487edf4 -> 1760ef283


AMBARI-15348 Ambari upgrade/start commands should detect any ambari-server hotfix and fail
upgrade/start from proceeding (dsen)


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

Branch: refs/heads/branch-2.2
Commit: 1760ef283c1323e4eb237d70fc17faa39c54df08
Parents: 3b487ed
Author: Dmytro Sen <dsen@apache.org>
Authored: Mon Mar 14 14:39:41 2016 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Mon Mar 14 14:39:41 2016 +0200

----------------------------------------------------------------------
 ambari-server/pom.xml                           |  4 --
 .../src/main/package/deb/control/preinst        | 15 +++++
 .../src/main/package/rpm/preinstall.sh          | 15 +++++
 .../python/ambari_server/serverClassPath.py     | 60 ++++++++++++++----
 .../src/test/python/TestServerClassPath.py      | 66 +++++++++++++++++++-
 5 files changed, 144 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1760ef28/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index f6c9e87..f4d3c67 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1760,10 +1760,6 @@
     </dependency>
     <dependency>
       <groupId>org.apache.ant</groupId>
-      <artifactId>ant</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.ant</groupId>
       <artifactId>ant-launcher</artifactId>
     </dependency>
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1760ef28/ambari-server/src/main/package/deb/control/preinst
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/package/deb/control/preinst b/ambari-server/src/main/package/deb/control/preinst
index f640adb..34795c0 100644
--- a/ambari-server/src/main/package/deb/control/preinst
+++ b/ambari-server/src/main/package/deb/control/preinst
@@ -32,6 +32,9 @@ AMBARI_KRB_JAAS_LOGIN_FILE_OLD="$AMBARI_KRB_JAAS_LOGIN_FILE.rpmsave"
 AMBARI_VIEWS_FOLDER="/var/lib/ambari-server/resources/views"
 AMBARI_VIEWS_BACKUP_FOLDER="$AMBARI_VIEWS_FOLDER/backups"
 
+AMBARI_SERVER_JAR_FILES="/usr/lib/ambari-server/ambari-server-*.jar"
+AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER="/usr/lib/ambari-server-backups"
+
 if [ -d "/etc/ambari-server/conf.save" ]
 then
     mv /etc/ambari-server/conf.save /etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save
@@ -72,4 +75,16 @@ then
     cp -u $AMBARI_VIEWS_FOLDER/*.jar $AMBARI_VIEWS_BACKUP_FOLDER/
 fi
 
+for f in $AMBARI_SERVER_JAR_FILES;
+do
+    if [ -f "$f" ]
+    then
+        if [ ! -d "$AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER" ]
+        then
+            mkdir -p "$AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER"
+        fi
+        mv -f $f $AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER/
+    fi
+done
+
 exit 0

http://git-wip-us.apache.org/repos/asf/ambari/blob/1760ef28/ambari-server/src/main/package/rpm/preinstall.sh
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/package/rpm/preinstall.sh b/ambari-server/src/main/package/rpm/preinstall.sh
index 313a169..c315368 100644
--- a/ambari-server/src/main/package/rpm/preinstall.sh
+++ b/ambari-server/src/main/package/rpm/preinstall.sh
@@ -22,6 +22,9 @@ COMMON_SERVICES_FOLDER_OLD=/var/lib/ambari-server/resources/common-services_$(da
 AMBARI_VIEWS_FOLDER="/var/lib/ambari-server/resources/views"
 AMBARI_VIEWS_BACKUP_FOLDER="$AMBARI_VIEWS_FOLDER/backups"
 
+AMBARI_SERVER_JAR_FILES="/usr/lib/ambari-server/ambari-server-*.jar"
+AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER="/usr/lib/ambari-server-backups"
+
 if [ -d "/etc/ambari-server/conf.save" ]
 then
     mv /etc/ambari-server/conf.save /etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save
@@ -47,4 +50,16 @@ then
     cp -u $AMBARI_VIEWS_FOLDER/*.jar $AMBARI_VIEWS_BACKUP_FOLDER/
 fi
 
+for f in $AMBARI_SERVER_JAR_FILES;
+do
+    if [ -f "$f" ]
+    then
+        if [ ! -d "$AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER" ]
+        then
+            mkdir -p "$AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER"
+        fi
+        mv -f $f $AMBARI_SERVER_JAR_FILES_BACKUP_FOLDER/
+    fi
+done
+
 exit 0

http://git-wip-us.apache.org/repos/asf/ambari/blob/1760ef28/ambari-server/src/main/python/ambari_server/serverClassPath.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverClassPath.py b/ambari-server/src/main/python/ambari_server/serverClassPath.py
index d3ade3e..d0e6795 100644
--- a/ambari-server/src/main/python/ambari_server/serverClassPath.py
+++ b/ambari-server/src/main/python/ambari_server/serverClassPath.py
@@ -17,26 +17,21 @@ 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.
 '''
-
-import datetime
 import glob
+
 import os
-import re
-import shutil
-import stat
-import string
-import sys
-import tempfile
 
 import ambari_server
-from ambari_commons.logging_utils import print_info_msg
+import re
+from ambari_commons.exceptions import FatalException
+from ambari_commons.logging_utils import print_info_msg, print_error_msg
 from resource_management.core.shell import quote_bash_args
 AMBARI_CONF_VAR = "AMBARI_CONF_DIR"
 SERVER_CLASSPATH_KEY = "SERVER_CLASSPATH"
 LIBRARY_PATH_KEY = "LD_LIBRARY_PATH"
 AMBARI_SERVER_LIB = "AMBARI_SERVER_LIB"
 JDBC_DRIVER_PATH_PROPERTY = "server.jdbc.driver.path"
-
+JAR_FILE_PATTERN = re.compile(r'^(.*)(-\d.*\.jar$)')
 
 
 class ServerClassPath():
@@ -94,7 +89,7 @@ class ServerClassPath():
 
   def get_full_ambari_classpath_escaped_for_shell(self):
     class_path = self._get_ambari_classpath()
-
+    self._validate_classpath(class_path)
     # When classpath is required we should also set native libs os env variable
     # This is required for some jdbc (ex. sqlAnywhere)
     self.set_native_libs_path()
@@ -113,3 +108,46 @@ class ServerClassPath():
           native_libs_path = os.environ[LIBRARY_PATH_KEY] + os.pathsep + native_libs_path
         os.environ[LIBRARY_PATH_KEY] = native_libs_path
 
+  def _validate_classpath(self, classpath):
+    """
+    Check if  java class path contains multiple versions of the same jar
+    archives, if yes - raise FatalException()
+
+    Keyword arguments:
+      classpath - java class path
+    """
+    jars = self._find_all_jars(classpath)
+    jar_names = {}
+
+    for jar in jars:
+      match = JAR_FILE_PATTERN.match(os.path.basename(jar))
+      if match:
+        for group in match.groups():
+          if group in jar_names:
+            err = "Multiple versions of {0}.jar found in java class path " \
+                  "({1} and {2}). \n Make sure that you include only one " \
+                  "{0}.jar in the java class path '{3}'."\
+                  .format(group, jar, jar_names[group], classpath)
+            raise FatalException(1, err)
+          else:
+            jar_names[group] = jar
+            break
+
+  def _find_all_jars(self, classpath):
+    """
+    Return the list of absolute paths to jars in classpath.
+    Raise FatalException() if classpath isn't set
+
+    Keyword arguments:
+      classpath - java class path
+    """
+    if classpath:
+      jars = []
+      for wildcard in classpath.split(os.pathsep):
+        for path in glob.glob(wildcard):
+          if os.path.isfile(path) and path.endswith(".jar"):
+            jars.append(path)
+      return jars
+    else:
+      raise FatalException(1, "No classpath specified.")
+    pass

http://git-wip-us.apache.org/repos/asf/ambari/blob/1760ef28/ambari-server/src/test/python/TestServerClassPath.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestServerClassPath.py b/ambari-server/src/test/python/TestServerClassPath.py
index e6c5ca8..684837c 100644
--- a/ambari-server/src/test/python/TestServerClassPath.py
+++ b/ambari-server/src/test/python/TestServerClassPath.py
@@ -17,6 +17,9 @@ limitations under the License.
 '''
 
 import os
+import shutil
+import tempfile
+from ambari_commons.exceptions import FatalException
 from mock.mock import patch, MagicMock
 from unittest import TestCase
 from ambari_server.properties import Properties
@@ -26,7 +29,6 @@ from ambari_server.serverClassPath import ServerClassPath, AMBARI_SERVER_LIB,
SE
 
 class TestConfigs(TestCase):
 
-
   @patch("ambari_server.serverConfiguration.get_conf_dir")
   def test_server_class_path_default(self, get_conf_dir_mock):
     properties = Properties()
@@ -87,3 +89,65 @@ class TestConfigs(TestCase):
     actual_classpath = serverClassPath.get_full_ambari_classpath_escaped_for_shell()
     self.assertEquals(expected_classpath, actual_classpath)
 
+  @patch("ambari_server.serverConfiguration.get_conf_dir")
+  def test_server_class_path_find_all_jars(self, get_conf_dir_mock):
+    temp_dir = tempfile.mkdtemp()
+    sub_dir = tempfile.mkdtemp(dir=temp_dir)
+    serverClassPath = ServerClassPath(None, None)
+    jar0 = tempfile.NamedTemporaryFile(suffix='.jar')
+    jar1 = tempfile.NamedTemporaryFile(suffix='.jar', dir=temp_dir)
+    jar2 = tempfile.NamedTemporaryFile(suffix='.jar', dir=temp_dir)
+    jar3 = tempfile.NamedTemporaryFile(suffix='.jar', dir=sub_dir)
+    # test /dir/*:file.jar
+    classpath = str(temp_dir) + os.path.sep + "*" + os.path.pathsep + jar0.name
+    jars = serverClassPath._find_all_jars(classpath)
+    self.assertEqual(len(jars), 3)
+    self.assertTrue(jar0.name in jars)
+    self.assertTrue(jar1.name in jars)
+    self.assertTrue(jar2.name in jars)
+    self.assertFalse(jar3.name in jars)
+
+    # test no classpath specified
+    try:
+      serverClassPath._find_all_jars(None)
+      self.fail()
+    except FatalException as fe:
+      pass
+
+    shutil.rmtree(temp_dir)
+
+  @patch.object(ServerClassPath, "_find_all_jars")
+  @patch("ambari_server.serverConfiguration.get_conf_dir")
+  def test_server_class_path_validate_classpath(self, get_conf_dir_mock,
+                                                find_jars_mock):
+    serverClassPath = ServerClassPath(None, None)
+
+    # No jars
+    find_jars_mock.return_value = []
+    try:
+      serverClassPath._validate_classpath(None)
+    except:
+      self.fail()
+
+    # Correct jars list
+    find_jars_mock.return_value = ["ambari-metrics-common-2.1.1.236.jar",
+                                   "ambari-server-2.1.1.236.jar",
+                                   "jetty-client-8.1.17.v20150415.jar",
+                                   "spring-core-3.0.7.RELEASE.jar"]
+    try:
+      serverClassPath._validate_classpath(None)
+    except:
+      self.fail()
+
+    # Incorrect jars list
+    find_jars_mock.return_value = ["ambari-metrics-common-2.1.1.236.jar",
+                                   "ambari-server-2.1.1.236.jar",
+                                   "ambari-server-2.1.1.hotfixed.jar",
+                                   "jetty-client-8.1.17.v20150415.jar",
+                                   "spring-core-3.0.7.RELEASE.jar"]
+    try:
+      serverClassPath._validate_classpath(None)
+      self.fail()
+    except:
+      pass
+


Mime
View raw message