mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Added a database creator class. not working yet. Edison will look at it
This commit is contained in:
parent
c272cf6b69
commit
a388a748d0
@ -32,6 +32,73 @@
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>deploydb2</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>deploydb2</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<dependencies>
|
||||
<!-- specify the dependent jdbc driver here -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${cs.mysql.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>${cs.dbcp.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-pool</groupId>
|
||||
<artifactId>commons-pool</artifactId>
|
||||
<version>${cs.pool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jasypt</groupId>
|
||||
<artifactId>jasypt</artifactId>
|
||||
<version>${cs.jasypt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<id>create-database-2</id>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<arguments>
|
||||
<argument>-classpath</argument>
|
||||
<classpath><dependency>org.apache.cloudstack:cloud-server</dependency></classpath>
|
||||
<argument>com.cloud.upgrade.DatabaseCreator</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>deploydb</id>
|
||||
<activation>
|
||||
|
||||
87
server/src/com/cloud/upgrade/DatabaseCreator.java
Executable file
87
server/src/com/cloud/upgrade/DatabaseCreator.java
Executable file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, 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.
|
||||
*/
|
||||
package com.cloud.upgrade;
|
||||
|
||||
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 com.cloud.utils.PropertiesUtil;
|
||||
import com.cloud.utils.db.ScriptRunner;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
/**
|
||||
* Creates the CloudStack Database
|
||||
*/
|
||||
public class DatabaseCreator {
|
||||
protected static void printHelp(String cmd) {
|
||||
System.out.println(
|
||||
"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 + " [initial schema file] [database upgrade class]");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
public static void main2(String[] args) {
|
||||
if (args.length < 2) {
|
||||
printHelp("DatabaseCreator");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
File cleanScript = PropertiesUtil.findConfigFile(args[0]);
|
||||
if (cleanScript == null) {
|
||||
System.err.println("Unable to find " + args[0]);
|
||||
printHelp("DatabaseCreator");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Connection conn = Transaction.getStandaloneConnection();
|
||||
|
||||
ScriptRunner runner = new ScriptRunner(conn, true, true);
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(cleanScript);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("Unable to read " + args[0] + ": " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
runner.runScript(reader);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Unable to read " + args[0] + ": " + e.getMessage());
|
||||
System.exit(1);
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Unable to execute " + args[0] + ": " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Unable to close DB connection: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user