From ab3c719389c37f952ae2b4278ae0c5b0dd2855ba Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 28 Feb 2011 08:43:08 -0800 Subject: [PATCH] run the scripts --- build/developer.xml | 3 -- .../com/cloud/upgrade/dao/VersionDaoImpl.java | 12 ++++- .../cloud/upgrade/dao/VersionDaoImplTest.java | 45 ++----------------- 3 files changed, 13 insertions(+), 47 deletions(-) diff --git a/build/developer.xml b/build/developer.xml index f0a622fdce3..a5417d02a18 100755 --- a/build/developer.xml +++ b/build/developer.xml @@ -232,9 +232,6 @@ --> - - - diff --git a/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java b/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java index 20d744fee9b..5280ab1bf13 100644 --- a/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java +++ b/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java @@ -152,6 +152,10 @@ public class VersionDaoImpl extends GenericDaoBase implements V if (upgrades == null) { throw new ConfigurationException("There is no upgrade path from " + dbVersion + " to " + currentVersion); } + + if (Version.compare(currentVersion, upgrades[upgrades.length - 1].getUpgradedVersion()) == 0) { + throw new ConfigurationException("The end upgrade version is actually at " + upgrades[upgrades.length - 1].getUpgradedVersion() + " but our management server code version is at " + currentVersion); + } boolean supportsRollingUpgrade = true; for (DbUpgrade upgrade : upgrades) { @@ -170,7 +174,9 @@ public class VersionDaoImpl extends GenericDaoBase implements V Transaction txn = Transaction.currentTxn(); txn.start(); File script = upgrade.getPrepareScript(); - runScript(script); + if (script != null) { + runScript(script); + } upgrade.performDataMigration(); VersionVO version = new VersionVO(upgrade.getUpgradedVersion()); persist(version); @@ -183,7 +189,9 @@ public class VersionDaoImpl extends GenericDaoBase implements V Transaction txn = Transaction.currentTxn(); txn.start(); File script = upgrade.getCleanupScript(); - runScript(script); + if (script != null) { + runScript(script); + } version.setStep(Step.Complete); version.setUpdated(new Date()); update(version.getId(), version); diff --git a/server/test/com/cloud/upgrade/dao/VersionDaoImplTest.java b/server/test/com/cloud/upgrade/dao/VersionDaoImplTest.java index d085ef83566..272005f454a 100644 --- a/server/test/com/cloud/upgrade/dao/VersionDaoImplTest.java +++ b/server/test/com/cloud/upgrade/dao/VersionDaoImplTest.java @@ -18,13 +18,6 @@ package com.cloud.upgrade.dao; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; - import javax.naming.ConfigurationException; import junit.framework.TestCase; @@ -34,10 +27,8 @@ import org.junit.After; import org.junit.Before; import com.cloud.upgrade.dao.VersionVO.Step; -import com.cloud.utils.PropertiesUtil; import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.db.ScriptRunner; -import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.DbTestUtils; public class VersionDaoImplTest extends TestCase { private static final Logger s_logger = Logger.getLogger(VersionDaoImplTest.class); @@ -47,39 +38,9 @@ public class VersionDaoImplTest extends TestCase { public void setUp() throws Exception { VersionVO version = new VersionVO("2.1.7"); version.setStep(Step.Cleanup); - executeScript("VersionDaoImplTest/clean-db.sql"); + DbTestUtils.executeScript("VersionDaoImplTest/clean-db.sql", false, true); } - protected void executeScript(String file) { - File cleanScript = PropertiesUtil.findConfigFile(file); - if (cleanScript == null) { - throw new RuntimeException("Unable to clean the database because I can't find " + file); - } - - Connection conn = Transaction.getStandaloneConnection(); - - ScriptRunner runner = new ScriptRunner(conn, false, true); - FileReader reader; - try { - reader = new FileReader(cleanScript); - } catch (FileNotFoundException e) { - throw new RuntimeException("Unable to read " + file, e); - } - try { - runner.runScript(reader); - } catch (IOException e) { - throw new RuntimeException("Unable to read " + file, e); - } catch (SQLException e) { - throw new RuntimeException("Unable to execute " + file, e); - } - - try { - conn.close(); - } catch (SQLException e) { - throw new RuntimeException("Unable to close DB connection", e); - } - } - @Override @After public void tearDown() throws Exception { @@ -87,7 +48,7 @@ public class VersionDaoImplTest extends TestCase { public void test217to22Upgrade() { s_logger.debug("Finding sample data from 2.1.7"); - executeScript("VersionDaoImplTest/2.1.7/2.1.7.sample.sql"); + DbTestUtils.executeScript("VersionDaoImplTest/2.1.7/2.1.7.sample.sql", false, true); VersionDaoImpl dao = ComponentLocator.inject(VersionDaoImpl.class);