You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2013/01/18 03:25:37 UTC
git commit: DatabaseCreator: Process db props,
sql and upgrade classes separately
Updated Branches:
refs/heads/javelin 17a94b20e -> b45cdef5d
DatabaseCreator: Process db props, sql and upgrade classes separately
Signed-off-by: Rohit Yadav <bh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/b45cdef5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/b45cdef5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/b45cdef5
Branch: refs/heads/javelin
Commit: b45cdef5d9185d21ab30d7a81b075622a4e184eb
Parents: 17a94b2
Author: Rohit Yadav <bh...@apache.org>
Authored: Thu Jan 17 16:51:59 2013 -0800
Committer: Rohit Yadav <bh...@apache.org>
Committed: Thu Jan 17 18:25:27 2013 -0800
----------------------------------------------------------------------
developer/pom.xml | 3 +
server/src/com/cloud/upgrade/DatabaseCreator.java | 120 +++++++++-------
2 files changed, 73 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b45cdef5/developer/pom.xml
----------------------------------------------------------------------
diff --git a/developer/pom.xml b/developer/pom.xml
index ff1dcd4..95dfb9f 100644
--- a/developer/pom.xml
+++ b/developer/pom.xml
@@ -340,6 +340,9 @@
</executableDependency>
<mainClass>com.cloud.upgrade.DatabaseCreator</mainClass>
<arguments>
+ <!-- db properties file -->
+ <argument>${project.parent.basedir}/utils/conf/db.properties</argument>
+ <argument>${project.parent.basedir}/utils/conf/db.properties.override</argument>
<!-- Create default schema and db table views -->
<argument>${basedir}/target/db/create-schema.sql</argument>
<argument>${basedir}/target/db/create-schema-premium.sql</argument>
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b45cdef5/server/src/com/cloud/upgrade/DatabaseCreator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/DatabaseCreator.java b/server/src/com/cloud/upgrade/DatabaseCreator.java
index 4bc2038..5dde057 100755
--- a/server/src/com/cloud/upgrade/DatabaseCreator.java
+++ b/server/src/com/cloud/upgrade/DatabaseCreator.java
@@ -24,6 +24,8 @@ import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
import com.cloud.utils.PropertiesUtil;
@@ -39,74 +41,92 @@ public class DatabaseCreator {
"DatabaseCreator creates the database schema by removing the \n" +
"previous schema, creating the schema, and running \n" +
"through the database updaters.");
- System.out.println("Usage: " + cmd + " [schema files] [database upgrade class]");
+ System.out.println("Usage: " + cmd + " [db.properties files] [schema.sql files] [database upgrade class]");
}
public static void main(String[] args) {
- if (args.length < 2) {
+ List<String> dbPropFiles = new ArrayList<String>();
+ List<String> sqlFiles = new ArrayList<String>();
+ List<String> upgradeClasses = new ArrayList<String>();
+
+ for (String arg: args) {
+ if (arg.endsWith(".sql")) {
+ sqlFiles.add(arg);
+ } else if (arg.endsWith(".properties") || arg.endsWith("properties.override")) {
+ dbPropFiles.add(arg);
+ } else {
+ upgradeClasses.add(arg);
+ }
+ }
+
+ if ((dbPropFiles.size() == 0)
+ || (sqlFiles.size() == 0) && upgradeClasses.size() == 0) {
printHelp("DatabaseCreator");
System.exit(1);
}
- for (int i = 0; i < args.length; i++) {
-
- if (args[i].endsWith("sql")) {
+ // Process db.properties files
+ for (String dbPropFile: dbPropFiles) {
- File sqlScript = PropertiesUtil.findConfigFile(args[i]);
- if (sqlScript == null) {
- System.err.println("Unable to find " + args[i]);
- printHelp("DatabaseCreator");
- System.exit(1);
- }
+ }
- System.out.println("=============> Processing SQL file at " + sqlScript.getAbsolutePath());
+ // Process sql files
+ for (String sqlFile: sqlFiles) {
+ File sqlScript = PropertiesUtil.findConfigFile(sqlFile);
+ if (sqlScript == null) {
+ System.err.println("Unable to find " + sqlFile);
+ printHelp("DatabaseCreator");
+ System.exit(1);
+ }
- Connection conn = Transaction.getStandaloneConnection();
- try {
+ System.out.println("=============> Processing SQL file at " + sqlScript.getAbsolutePath());
- ScriptRunner runner = new ScriptRunner(conn, false, true);
- FileReader reader = null;
- try {
- reader = new FileReader(sqlScript);
- } catch (FileNotFoundException e) {
- System.err.println("Unable to read " + args[i] + ": " + e.getMessage());
- System.exit(1);
- }
- try {
- runner.runScript(reader);
- } catch (IOException e) {
- System.err.println("Unable to read " + args[i] + ": " + e.getMessage());
- System.exit(1);
- } catch (SQLException e) {
- System.err.println("Unable to execute " + args[i] + ": " + e.getMessage());
- System.exit(1);
- }
- } finally {
+ Connection conn = Transaction.getStandaloneConnection();
+ try {
- try {
- conn.close();
- } catch (SQLException e) {
- System.err.println("Unable to close DB connection: " + e.getMessage());
- }
+ ScriptRunner runner = new ScriptRunner(conn, false, true);
+ FileReader reader = null;
+ try {
+ reader = new FileReader(sqlScript);
+ } catch (FileNotFoundException e) {
+ System.err.println("Unable to read " + sqlFile + ": " + e.getMessage());
+ System.exit(1);
}
-
- } else {
- System.out.println("=============> Processing upgrade: " + args[i]);
- Class<?> clazz = null;
try {
- clazz = Class.forName(args[i]);
- if (!SystemIntegrityChecker.class.isAssignableFrom(clazz)) {
- System.err.println("The class must be of SystemIntegrityChecker: " + clazz.getName());
- System.exit(1);
- }
- } catch (ClassNotFoundException e) {
- System.err.println("Unable to find " + args[i] + ": " + e.getMessage());
+ runner.runScript(reader);
+ } catch (IOException e) {
+ System.err.println("Unable to read " + sqlFile + ": " + e.getMessage());
System.exit(1);
+ } catch (SQLException e) {
+ System.err.println("Unable to execute " + sqlFile + ": " + e.getMessage());
+ System.exit(1);
+ }
+ } finally {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ System.err.println("Unable to close DB connection: " + e.getMessage());
}
+ }
+ }
- //SystemIntegrityChecker checker = (SystemIntegrityChecker)ComponentLocator.inject(clazz);
- //checker.check();
+ // 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);
+ }
+ } catch (ClassNotFoundException e) {
+ System.err.println("Unable to find " + upgradeClass + ": " + e.getMessage());
+ System.exit(1);
}
+
+ //SystemIntegrityChecker checker = (SystemIntegrityChecker)ComponentLocator.inject(clazz);
+ //checker.check();
}
}
}