You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2013/10/31 15:11:21 UTC
git commit: updated refs/heads/master to a3cec38
Updated Branches:
refs/heads/master 58179d288 -> a3cec3802
Commit 1460196496d73e0db25c7beb2392cfaf9d591ed7 changed db.properties
loading, this also affects the database creator. This make the database
creator use the new loading completely instead of partially.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a3cec380
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a3cec380
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a3cec380
Branch: refs/heads/master
Commit: a3cec3802c4c56173c33ccc1e08af059547fe90e
Parents: 58179d2
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Thu Oct 31 15:07:36 2013 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Thu Oct 31 15:08:25 2013 +0100
----------------------------------------------------------------------
.../src/com/cloud/upgrade/DatabaseCreator.java | 76 +++++++++-----------
1 file changed, 35 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a3cec380/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java b/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java
index 4ed389e..3db14d8 100755
--- a/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java
+++ b/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java
@@ -19,7 +19,6 @@
package com.cloud.upgrade;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
@@ -37,6 +36,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.SystemIntegrityChecker;
+import com.cloud.utils.db.DbProperties;
import com.cloud.utils.db.ScriptRunner;
import com.cloud.utils.db.TransactionLegacy;
@@ -47,7 +47,7 @@ public class DatabaseCreator {
protected static void printHelp(String cmd) {
System.out.println(
"\nDatabaseCreator creates the database schema by removing the \n" +
- "previous schema, creating the schema, and running \n" +
+ "previous schema, creating the schema, and running \n" +
"through the database updaters.");
System.out.println("Usage: " + cmd + " [options] [db.properties file] [schema.sql files] [database upgrade class]\nOptions:"
+ "\n --database=a,b comma separate databases to initialize, use the db name in db.properties defined as db.xyz.host, xyz should be passed"
@@ -94,13 +94,7 @@ public class DatabaseCreator {
}
private static void initDB(String dbPropsFile, String rootPassword, String[] databases, boolean dryRun) {
- Properties dbProperties = new Properties();
- try {
- dbProperties.load(new FileInputStream(new File(dbPropsFile)));
- } catch (IOException e) {
- System.out.println("IOError: unable to load/read db properties file: " + e);
- System.exit(1);
- }
+ Properties dbProperties = DbProperties.getDbProperties();
for (String database: databases) {
String host = dbProperties.getProperty(String.format("db.%s.host", database));
@@ -123,11 +117,11 @@ public class DatabaseCreator {
}
public static void main(String[] args) {
-
- ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
- new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"});
- appContext.getBean(ComponentContext.class);
-
+
+ ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
+ new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"});
+ appContext.getBean(ComponentContext.class);
+
String dbPropsFile = "";
List<String> sqlFiles = new ArrayList<String>();
List<String> upgradeClasses = new ArrayList<String>();
@@ -152,12 +146,12 @@ public class DatabaseCreator {
} else if (arg.endsWith(".sql")) {
sqlFiles.add(arg);
} else if (arg.endsWith(".sql.override")) {
- if (fileExists(arg)) {
- int index = arg.lastIndexOf(".override");
- String fileToOverride = arg.substring(0, index);
- sqlFiles.remove(fileToOverride);
- sqlFiles.add(arg);
- }
+ if (fileExists(arg)) {
+ int index = arg.lastIndexOf(".override");
+ String fileToOverride = arg.substring(0, index);
+ sqlFiles.remove(fileToOverride);
+ sqlFiles.add(arg);
+ }
} else if (arg.endsWith(".properties")) {
if (!dbPropsFile.endsWith("properties.override") && fileExists(arg))
dbPropsFile = arg;
@@ -209,30 +203,30 @@ public class DatabaseCreator {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
try {
- // Process db upgrade classes
- for (String upgradeClass: upgradeClasses) {
- System.out.println("========> Processing upgrade: " + upgradeClass);
- Class<?> clazz = null;
- try {
- clazz = Class.forName(upgradeClass);
- if (!SystemIntegrityChecker.class.isAssignableFrom(clazz)) {
- System.err.println("The class must be of SystemIntegrityChecker: " + clazz.getName());
+ // Process db upgrade classes
+ for (String upgradeClass: upgradeClasses) {
+ System.out.println("========> Processing upgrade: " + upgradeClass);
+ Class<?> clazz = null;
+ try {
+ clazz = Class.forName(upgradeClass);
+ if (!SystemIntegrityChecker.class.isAssignableFrom(clazz)) {
+ System.err.println("The class must be of SystemIntegrityChecker: " + clazz.getName());
+ System.exit(1);
+ }
+ SystemIntegrityChecker checker = (SystemIntegrityChecker)clazz.newInstance();
+ checker.check();
+ } catch (ClassNotFoundException e) {
+ System.err.println("Unable to find " + upgradeClass + ": " + e.getMessage());
+ System.exit(1);
+ } catch (InstantiationException e) {
+ System.err.println("Unable to instantiate " + upgradeClass + ": " + e.getMessage());
+ System.exit(1);
+ } catch (IllegalAccessException e) {
+ System.err.println("Unable to access " + upgradeClass + ": " + e.getMessage());
System.exit(1);
}
- SystemIntegrityChecker checker = (SystemIntegrityChecker)clazz.newInstance();
- checker.check();
- } catch (ClassNotFoundException e) {
- System.err.println("Unable to find " + upgradeClass + ": " + e.getMessage());
- System.exit(1);
- } catch (InstantiationException e) {
- System.err.println("Unable to instantiate " + upgradeClass + ": " + e.getMessage());
- System.exit(1);
- } catch (IllegalAccessException e) {
- System.err.println("Unable to access " + upgradeClass + ": " + e.getMessage());
- System.exit(1);
- }
- }
+ }
} finally {
txn.close();
}