incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [3/3] git commit: Changed the create database steps to be create from a single create-schema.sql and then apply database modifications
Date Thu, 01 Nov 2012 20:40:43 GMT
Changed the create database steps to be create from a single create-schema.sql and then apply
database modifications


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/772f660c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/772f660c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/772f660c

Branch: refs/heads/javelin
Commit: 772f660c33162f628c03f36b8f357e5cfca65c60
Parents: 3423c5d
Author: Alex Huang <alex.huang@citrix.com>
Authored: Fri Oct 26 17:34:24 2012 -0700
Committer: Alex Huang <alex.huang@citrix.com>
Committed: Thu Nov 1 13:40:15 2012 -0700

----------------------------------------------------------------------
 developer/pom.xml                                  |  206 ++++++++++-----
 platform/api/pom.xml                               |    2 +-
 .../platform/cloud/entity/api/NetworkEntity.java   |    1 +
 .../cloud/entity/api/VirtualMachineEntity.java     |    4 +-
 server/src/com/cloud/upgrade/DatabaseCreator.java  |   95 +++++---
 5 files changed, 205 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/772f660c/developer/pom.xml
----------------------------------------------------------------------
diff --git a/developer/pom.xml b/developer/pom.xml
index 2d39233..3eb493d 100644
--- a/developer/pom.xml
+++ b/developer/pom.xml
@@ -1,13 +1,13 @@
-<!-- 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. -->
+<?xml version="1.0" encoding="UTF-8"?><!-- 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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
@@ -34,16 +34,63 @@
 
   <profiles>
     <profile>
-      <id>deploydb2</id>
+      <id>deploydb</id>
       <activation>
         <property>
-          <name>deploydb2</name>
+          <name>deploydb</name>
         </property>
       </activation>
       <build>
         <plugins>
           <plugin>
             <groupId>org.codehaus.mojo</groupId>
+            <artifactId>properties-maven-plugin</artifactId>
+            <version>1.0-alpha-2</version>
+            <executions>
+              <execution>
+                <phase>initialize</phase>
+                <goals>
+                  <goal>read-project-properties</goal>
+                </goals>
+                <configuration>
+                  <files>
+                    <file>${project.parent.basedir}/utils/conf/db.properties</file>
+                    <file>${project.parent.basedir}/utils/conf/db.properties.override</file>
+                  </files>
+                  <quiet>true</quiet>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+          <plugin>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <version>1.7</version>
+            <executions>
+              <execution>
+                <phase>generate-resources</phase>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+                <configuration>
+                  <target>
+                    <filter token="VERSION" value="${project.version}" />
+                    <copy todir="${basedir}/target/db" filtering="true">
+                      <fileset dir="${project.basedir}/../setup/db/" />
+
+                    </copy>
+                    <copy todir="${basedir}/target/db" filtering="true">
+                      <fileset
+                        dir="${project.basedir}/../awsapi-setup/db/mysql/">
+                        <include name="**/*.sql" />
+                      </fileset>
+                    </copy>
+                  </target>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+          <plugin>
+            <groupId>org.codehaus.mojo</groupId>
             <artifactId>exec-maven-plugin</artifactId>
             <version>1.2.1</version>
             <dependencies>
@@ -81,8 +128,8 @@
             </dependencies>
             <executions>
               <execution>
-                <phase>package</phase>
-                <id>create-database-2</id>
+                <phase>process-test-resources</phase>
+                <id>create-schema</id>
                 <goals>
                   <goal>java</goal>
                 </goals>
@@ -96,16 +143,91 @@
                 <artifactId>cloud-server</artifactId>
               </executableDependency>
               <mainClass>com.cloud.upgrade.DatabaseCreator</mainClass>
+              <arguments>
+                <argument>${basedir}/target/db/create-schema.sql</argument>
+                <argument>${basedir}/target/db/create-schema-premium.sql</argument>
+                <argument>com.cloud.upgrade.DatabaseUpgradeChecker</argument>
+              </arguments>
             </configuration>
           </plugin>
+          <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>sql-maven-plugin</artifactId>
+            <version>1.5</version>
+            <dependencies>
+              <!-- specify the dependent jdbc driver here -->
+              <dependency>
+                <groupId>mysql</groupId>
+                <artifactId>mysql-connector-java</artifactId>
+                <version>${cs.mysql.version}</version>
+              </dependency>
+            </dependencies>
+            <configuration>
+              <driver>org.gjt.mm.mysql.Driver</driver>
+              <url>jdbc:mysql://${db.cloud.host}:${db.cloud.port}/cloud</url>
+              <username>${db.cloud.username}</username>
+              <password>${db.cloud.password}</password>
+              <!--all executions are ignored if -Dmaven.test.skip=true -->
+              <skip>${maven.test.skip}</skip>
+              <forceMojoExecution>true</forceMojoExecution>
+            </configuration>
+            <executions>
+              <execution>
+                <id>create-other-schema</id>
+                <phase>process-test-resources</phase>
+                <goals>
+                  <goal>execute</goal>
+                </goals>
+                <configuration>
+                  <srcFiles>
+                    <srcFile>${basedir}/target/db/templates.sql</srcFile>
+                    <srcFile>${basedir}/target/db/create-index-fk.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_schema.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_multipart.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_index.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_multipart_alter.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_bucketpolicy.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_policy_alter.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_offering.sql</srcFile>
+                    <srcFile>${basedir}/target/db/cloudbridge_offering_alter.sql</srcFile>
+                  </srcFiles>
+                </configuration>
+              </execution>
+              <execution>
+                <id>prefill-schema</id>
+                <phase>process-test-resources</phase>
+                <goals>
+                  <goal>execute</goal>
+                </goals>
+                <configuration>
+                  <sqlCommand>INSERT INTO `cloud`.`domain` (id, name,
+                    parent, path, owner) VALUES (1, 'ROOT', NULL, '/',
+                    2)</sqlCommand>
+                </configuration>
+              </execution>
+              <execution>
+                <id>prefill-configuration</id>
+                <phase>process-test-resources</phase>
+                <goals>
+                  <goal>execute</goal>
+                </goals>
+                <configuration>
+                  <sqlCommand>INSERT INTO `cloud`.`configuration`
+                    (category, instance, component, name, value) VALUES
+                    ('Hidden', 'DEFAULT', 'management-server', 'init',
+                    'false')</sqlCommand>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
         </plugins>
       </build>
     </profile>
     <profile>
-      <id>deploydb</id>
+      <id>cleandb</id>
       <activation>
         <property>
-          <name>deploydb</name>
+          <name>cleandb</name>
         </property>
       </activation>
       <build>
@@ -143,8 +265,8 @@
                   <target>
                     <filter token="VERSION" value="${project.version}" />
                     <copy todir="${basedir}/target/db" filtering="true">
-                      <fileset dir="${project.basedir}/../setup/db/">
-                      </fileset>
+                      <fileset dir="${project.basedir}/../setup/db/" />
+
                     </copy>
                     <copy todir="${basedir}/target/db" filtering="true">
                       <fileset
@@ -348,54 +470,6 @@
                     '${db.cloud.password}';</sqlCommand>
                 </configuration>
               </execution>
-              <execution>
-                <id>create-schema</id>
-                <phase>process-test-resources</phase>
-                <goals>
-                  <goal>execute</goal>
-                </goals>
-                <configuration>
-                  <srcFiles>
-                    <srcFile>${basedir}/target/db/create-schema.sql</srcFile>
-                    <srcFile>${basedir}/target/db/create-schema-premium.sql</srcFile>
-                    <srcFile>${basedir}/target/db/templates.sql</srcFile>
-                    <srcFile>${basedir}/target/db/create-index-fk.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_schema.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_multipart.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_index.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_multipart_alter.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_bucketpolicy.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_policy_alter.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_offering.sql</srcFile>
-                    <srcFile>${basedir}/target/db/cloudbridge_offering_alter.sql</srcFile>
-                  </srcFiles>
-                </configuration>
-              </execution>
-              <execution>
-                <id>prefill-schema</id>
-                <phase>process-test-resources</phase>
-                <goals>
-                  <goal>execute</goal>
-                </goals>
-                <configuration>
-                  <sqlCommand>INSERT INTO `cloud`.`domain` (id, name,
-                    parent, path, owner) VALUES (1, 'ROOT', NULL, '/',
-                    2)</sqlCommand>
-                </configuration>
-              </execution>
-              <execution>
-                <id>prefill-configuration</id>
-                <phase>process-test-resources</phase>
-                <goals>
-                  <goal>execute</goal>
-                </goals>
-                <configuration>
-                  <sqlCommand>INSERT INTO `cloud`.`configuration`
-                    (category, instance, component, name, value) VALUES
-                    ('Hidden', 'DEFAULT', 'management-server', 'init',
-                    'false')</sqlCommand>
-                </configuration>
-              </execution>
             </executions>
           </plugin>
         </plugins>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/772f660c/platform/api/pom.xml
----------------------------------------------------------------------
diff --git a/platform/api/pom.xml b/platform/api/pom.xml
index 66f7755..ce0344a 100644
--- a/platform/api/pom.xml
+++ b/platform/api/pom.xml
@@ -37,6 +37,6 @@
   <build>
     <defaultGoal>install</defaultGoal>
     <sourceDirectory>src</sourceDirectory>
-    <!-- <testSourceDirectory>test</testSourceDirectory> -->
+    <testSourceDirectory>test</testSourceDirectory>
   </build>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/772f660c/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java
b/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java
index ce7be7c..6a91cc1 100755
--- a/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java
+++ b/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java
@@ -23,4 +23,5 @@ import org.apache.cloudstack.platform.entity.api.CloudEntity;
 import com.cloud.network.Network;
 
 public interface NetworkEntity extends CloudEntity, Network {
+    void connectTo(NetworkEntity network);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/772f660c/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java
b/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java
index 23d1dad..7ed3db5 100755
--- a/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java
+++ b/platform/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java
@@ -110,11 +110,11 @@ public interface VirtualMachineEntity extends VirtualMachine, CloudEntity
{
      * @param network network to attach
      * @param deviceId device id to use when a nic is created
      */
-    void connectTo(NetworkEntity network, short deviceId);
+    void connectTo(NetworkEntity network, short nicId);
 
     /**
      * Disconnect the VM from this network
      * @param netowrk network to disconnect from
      */
-    void disconnectFrom(NetworkEntity netowrk);
+    void disconnectFrom(NetworkEntity netowrk, short nicId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/772f660c/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 89e4b6b..f6a5017 100755
--- a/server/src/com/cloud/upgrade/DatabaseCreator.java
+++ b/server/src/com/cloud/upgrade/DatabaseCreator.java
@@ -26,11 +26,14 @@ import java.sql.Connection;
 import java.sql.SQLException;
 
 import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.component.SystemIntegrityChecker;
 import com.cloud.utils.db.ScriptRunner;
 import com.cloud.utils.db.Transaction;
 
 /**
- * Creates the CloudStack Database
+ * Creates the CloudStack Database by using the 4.0 schema and apply 
+ * upgrade steps to it.
  */
 public class DatabaseCreator {
     protected static void printHelp(String cmd) {
@@ -42,46 +45,70 @@ public class DatabaseCreator {
     }
 
     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);
-        }
+        for (int i = 0; i < args.length; i++) {
 
-        Connection conn = Transaction.getStandaloneConnection();
+            if (args[i].endsWith("sql")) {
 
-        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);
-        }
+                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());
+
+                Connection conn = Transaction.getStandaloneConnection();
+                try {
+
+                    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 {
 
-        try {
-            conn.close();
-        } catch (SQLException e) {
-            System.err.println("Unable to close DB connection: " + e.getMessage());
+                    try {
+                        conn.close();
+                    } catch (SQLException e) {
+                        System.err.println("Unable to close DB connection: " + e.getMessage());
+                    }
+                }
+
+            } 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());
+                    System.exit(1);
+                }
+
+                SystemIntegrityChecker checker = (SystemIntegrityChecker)ComponentLocator.inject(clazz);
+                checker.check();
+            }
         }
     }
-
-}
+}
\ No newline at end of file


Mime
View raw message