diff --git a/setup/db/create-schema-simulator.sql b/setup/db/create-schema-simulator.sql new file mode 100644 index 00000000000..e106d1a4d88 --- /dev/null +++ b/setup/db/create-schema-simulator.sql @@ -0,0 +1,87 @@ +DROP TABLE IF EXISTS `cloud`.`mockhost`; +DROP TABLE IF EXISTS `cloud`.`mocksecstorage`; +DROP TABLE IF EXISTS `cloud`.`mockstoragepool`; +DROP TABLE IF EXISTS `cloud`.`mockvm`; +DROP TABLE IF EXISTS `cloud`.`mockvolume`; + +CREATE TABLE `cloud`.`mockhost` ( + `id` bigint unsigned NOT NULL auto_increment, + `name` varchar(255) NOT NULL, + `private_ip_address` char(40), + `private_mac_address` varchar(17), + `private_netmask` varchar(15), + `storage_ip_address` char(40), + `storage_netmask` varchar(15), + `storage_mac_address` varchar(17), + `public_ip_address` char(40), + `public_netmask` varchar(15), + `public_mac_address` varchar(17), + `guid` varchar(255) UNIQUE, + `version` varchar(40) NOT NULL, + `data_center_id` bigint unsigned NOT NULL, + `pod_id` bigint unsigned, + `cluster_id` bigint unsigned COMMENT 'foreign key to cluster', + `cpus` int(10) unsigned, + `speed` int(10) unsigned, + `ram` bigint unsigned, + `capabilities` varchar(255) COMMENT 'host capabilities in comma separated list', + `vm_id` bigint unsigned, + `resource` varchar(255) DEFAULT NULL COMMENT 'If it is a local resource, this is the class name', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`mocksecstorage` ( + `id` bigint unsigned NOT NULL auto_increment, + `url` varchar(255), + `capacity` bigint unsigned, + `mount_point` varchar(255), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`mockstoragepool` ( + `id` bigint unsigned NOT NULL auto_increment, + `guid` varchar(255), + `mount_point` varchar(255), + `capacity` bigint, + `pool_type` varchar(40), + `hostguid` varchar(255) UNIQUE, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`mockvm` ( + `id` bigint unsigned NOT NULL auto_increment, + `name` varchar(255), + `host_id` bigint unsigned, + `type` varchar(40), + `state` varchar(40), + `vnc_port` bigint unsigned, + `memory` bigint unsigned, + `cpu` bigint unsigned, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`mockvolume` ( + `id` bigint unsigned NOT NULL auto_increment, + `name` varchar(255), + `size` bigint unsigned, + `path` varchar(255), + `pool_id` bigint unsigned, + `type` varchar(40), + `status` varchar(40), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`mockconfiguration` ( + `id` bigint unsigned NOT NULL auto_increment, + `data_center_id` bigint unsigned, + `pod_id` bigint unsigned, + `cluster_id` bigint unsigned, + `host_id` bigint unsigned, + `name` varchar(255), + `values` varchar(4095), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/setup/db/deploy-db-simulator.sh b/setup/db/deploy-db-simulator.sh new file mode 100644 index 00000000000..d90a9c0f5d2 --- /dev/null +++ b/setup/db/deploy-db-simulator.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash + + + + # + # Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + # + # This software is licensed under the GNU General Public License v3 or later. + # + # It is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation, either version 3 of the License, or any later version. + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program. If not, see . + # + + +# deploy-db.sh -- deploys the database configuration. +# +# set -x + +if [ "$1" == "" ]; then + printf "Usage: %s [path to server-setup.xml] [path to additional sql] [root password]\n" $(basename $0) >&2 + exit 1; +fi + +if [ ! -f $1 ]; then + echo "Error: Unable to find $1" + exit 2 +fi + +if [ "$2" != "" ]; then + if [ ! -f $2 ]; then + echo "Error: Unable to find $2" + exit 3 + fi +fi + +if [ ! -f create-database.sql ]; then + printf "Error: Unable to find create-database.sql\n" + exit 4 +fi + +if [ ! -f create-schema.sql ]; then + printf "Error: Unable to find create-schema.sql\n" + exit 5 +fi + +if [ ! -f create-index-fk.sql ]; then + printf "Error: Unable to find create-index-fk.sql\n" + exit 6; +fi + +PATHSEP=':' +if [[ $OSTYPE == "cygwin" ]] ; then + export CATALINA_HOME=`cygpath -m $CATALINA_HOME` + PATHSEP=';' +fi + +echo "Recreating Database." +mysql --user=root --password=$3 < create-database.sql > /dev/null 2>/dev/null +mysqlout=$? +if [ $mysqlout -eq 1 ]; then + printf "Please enter root password for MySQL.\n" + mysql --user=root --password < create-database.sql + if [ $? -ne 0 ]; then + printf "Error: Cannot execute create-database.sql\n" + exit 10 + fi +elif [ $mysqlout -eq 127 ]; then + printf "Error: Cannot execute create-database.sql - mysql command not found.\n" + exit 11 +elif [ $mysqlout -ne 0 ]; then + printf "Error: Cannot execute create-database.sql\n" + exit 11 +fi + +mysql --user=cloud --password=cloud cloud < create-schema.sql +if [ $? -ne 0 ]; then + printf "Error: Cannot execute create-schema.sql\n" + exit 11 +fi + +mysql --user=cloud --password=cloud cloud < create-schema-simulator.sql +if [ $? -ne 0 ]; then + printf "Error: Cannot execute create-schema-simulator.sql\n" + exit 11 +fi + +CP=./ + +CP=${CP}$PATHSEP$CATALINA_HOME/conf + +for file in $CATALINA_HOME/webapps/client/WEB-INF/lib/*.jar +do + CP=${CP}$PATHSEP$file +done + +for file in $CATALINA_HOME/lib/*.jar; do + CP=${CP}$PATHSEP$file +done + +echo CP is $CP + +java -cp $CP com.cloud.test.DatabaseConfig $* + +if [ $? -ne 0 ] +then + exit 1 +fi + +if [ "$2" != "" ]; then + mysql --user=cloud --password=cloud cloud < $2 + if [ $? -ne 0 ]; then + printf "Error: Cannot execute $2\n" + exit 12 + fi +fi + + +echo "Creating Indice and Foreign Keys" +mysql --user=cloud --password=cloud cloud < create-index-fk.sql +if [ $? -ne 0 ]; then + printf "Error: Cannot execute create-index-fk.sql\n" + exit 13 +fi