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-14517 Database version check doesn't work in case of existing database from older Ambari version (dsen)
Date Tue, 29 Dec 2015 15:48:36 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a487e5018 -> 48c0df464


AMBARI-14517 Database version check doesn't work in case of existing database from older Ambari
version (dsen)


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

Branch: refs/heads/trunk
Commit: 48c0df464f915438f8eaad35b4c2a443ca9e9aed
Parents: a487e50
Author: Dmytro Sen <dsen@apache.org>
Authored: Tue Dec 29 17:48:27 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Tue Dec 29 17:48:27 2015 +0200

----------------------------------------------------------------------
 .../ambari/server/controller/AmbariServer.java  |  1 +
 .../controller/utilities/DatabaseChecker.java   | 23 +++++++++++-----
 .../utilities/DatabaseCheckerTest.java          | 28 +++++++++++---------
 3 files changed, 34 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/48c0df46/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index cc69134..353a972 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -833,6 +833,7 @@ public class AmbariServer {
       setupProxyAuth();
 
       injector.getInstance(GuiceJpaInitializer.class);
+      DatabaseChecker.checkDBVersion();
       server = injector.getInstance(AmbariServer.class);
       CertificateManager certMan = injector.getInstance(CertificateManager.class);
       certMan.initRootCert();

http://git-wip-us.apache.org/repos/asf/ambari/blob/48c0df46/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java
index 4839d21..190a6a7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java
@@ -18,9 +18,12 @@
 
 package org.apache.ambari.server.controller.utilities;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Scanner;
 import java.util.Map;
 
 import org.apache.ambari.server.AmbariException;
@@ -259,23 +262,31 @@ public class DatabaseChecker {
   public static void checkDBVersion() throws AmbariException {
 
     LOG.info("Checking DB store version");
-    if (ambariMetaInfo == null) {
-      ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
-    }
     if (metainfoDAO == null) {
       metainfoDAO = injector.getInstance(MetainfoDAO.class);
     }
 
     MetainfoEntity schemaVersionEntity = metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY);
     String schemaVersion = null;
-    String serverVersion = null;
 
     if (schemaVersionEntity != null) {
       schemaVersion = schemaVersionEntity.getMetainfoValue();
-      serverVersion = ambariMetaInfo.getServerVersion();
     }
 
-    if (schemaVersionEntity==null || VersionUtils.compareVersions(schemaVersion, serverVersion,
3) != 0) {
+    Configuration conf = injector.getInstance(Configuration.class);
+    File versionFile = new File(conf.getServerVersionFilePath());
+    if (!versionFile.exists()) {
+      throw new AmbariException("Server version file does not exist.");
+    }
+    String serverVersion = null;
+    try (Scanner scanner = new Scanner(versionFile)) {
+      serverVersion = scanner.useDelimiter("\\Z").next();
+
+    } catch (IOException ioe) {
+      throw new AmbariException("Unable to read server version file.");
+    }
+
+    if (schemaVersionEntity==null || VersionUtils.compareVersions(schemaVersion, serverVersion,
4) != 0) {
       String error = "Current database store version is not compatible with " +
         "current server version"
         + ", serverVersion=" + serverVersion

http://git-wip-us.apache.org/repos/asf/ambari/blob/48c0df46/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/DatabaseCheckerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/DatabaseCheckerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/DatabaseCheckerTest.java
index 03d3661..63baafe 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/DatabaseCheckerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/DatabaseCheckerTest.java
@@ -30,6 +30,7 @@ import org.apache.ambari.server.orm.dao.MetainfoDAO;
 import org.apache.ambari.server.orm.entities.MetainfoEntity;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import static org.easymock.EasyMock.createMock;
@@ -38,15 +39,19 @@ import static org.easymock.EasyMock.replay;
 import static org.junit.Assert.fail;
 
 public class DatabaseCheckerTest {
-  private Injector injector;
+  private static Injector injector;
 
   @Inject
   private AmbariMetaInfo ambariMetaInfo;
 
-  @Before
-  public void setup() throws Exception {
+  @BeforeClass
+  public static void setupClass() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
+  }
+
+  @Before
+  public void setup() throws Exception {
     injector.injectMembers(this);
   }
 
@@ -66,11 +71,15 @@ public class DatabaseCheckerTest {
     replay(metainfoDAO);
     DatabaseChecker.metainfoDAO = metainfoDAO;
     DatabaseChecker.ambariMetaInfo = ambariMetaInfo;
-    DatabaseChecker.checkDBVersion();
+    try {
+      DatabaseChecker.checkDBVersion();
+    } catch (AmbariException ae) {
+      fail("DB versions check failed.");
+    }
   }
 
-  @Test
-  public void testCheckDBVersion_Invalid() throws Exception {
+  @Test(expected = AmbariException.class)
+  public void testCheckDBVersionInvalid() throws Exception {
     MetainfoDAO metainfoDAO =  createMock(MetainfoDAO.class);
     MetainfoEntity metainfoEntity = new MetainfoEntity();
     metainfoEntity.setMetainfoName(Configuration.SERVER_VERSION_KEY);
@@ -81,11 +90,6 @@ public class DatabaseCheckerTest {
     DatabaseChecker.metainfoDAO = metainfoDAO;
     DatabaseChecker.ambariMetaInfo = ambariMetaInfo;
 
-    try {
-      DatabaseChecker.checkDBVersion();
-      fail();
-    } catch(AmbariException e) {
-      // Expected
-    }
+    DatabaseChecker.checkDBVersion();
   }
 }


Mime
View raw message