From 5edea6a0cdff009f7a4f9326cc0359d229f9397a Mon Sep 17 00:00:00 2001 From: sunqi310 Date: Mon, 5 Sep 2016 15:13:04 +0800 Subject: add init db scripts Change-Id: I565142502e1740666fa810c82ce927ed8a43ce35 Signed-off-by: sunqi310 --- .../assembly/conf/catalog-db-createdb-mysql.sql | 34 -------- .../conf/catalog-resource-createObj-mysql.sql | 75 ----------------- .../conf/catalog-resource-insert-extend-mysql.sql | 17 ---- .../conf/catalog-resource-insert-mysql.sql | 20 ----- .../mysql/openo-common_tosca-catalog-createobj.sql | 95 ++++++++++++++++++++++ .../src/main/assembly/initDB.bat | 42 ++++------ .../catalog-standalone/src/main/assembly/initDB.sh | 29 ++++--- 7 files changed, 128 insertions(+), 184 deletions(-) delete mode 100644 catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-db-createdb-mysql.sql delete mode 100644 catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-createObj-mysql.sql delete mode 100644 catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-extend-mysql.sql delete mode 100644 catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-mysql.sql create mode 100644 catalog-core/distribution/catalog-standalone/src/main/assembly/dbscripts/mysql/openo-common_tosca-catalog-createobj.sql (limited to 'catalog-core') diff --git a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-db-createdb-mysql.sql b/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-db-createdb-mysql.sql deleted file mode 100644 index 9b7ed341..00000000 --- a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-db-createdb-mysql.sql +++ /dev/null @@ -1,34 +0,0 @@ --- --- Copyright 2016 [ZTE] and others. --- --- Licensed 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. --- - -/******************drop old database and user***************************/ -use mysql; -drop database IF EXISTS catalog; -delete from user where User='catalog'; -FLUSH PRIVILEGES; - -/******************create new database and user***************************/ -create database catalog CHARACTER SET utf8; - -GRANT ALL PRIVILEGES ON catalog.* TO 'catalog'@'%' IDENTIFIED BY 'catalog' WITH GRANT OPTION; -GRANT ALL PRIVILEGES ON mysql.* TO 'catalog'@'%' IDENTIFIED BY 'catalog' WITH GRANT OPTION; - -GRANT ALL PRIVILEGES ON catalog.* TO 'catalog'@'localhost' IDENTIFIED BY 'catalog' WITH GRANT OPTION; -GRANT ALL PRIVILEGES ON mysql.* TO 'catalog'@'localhost' IDENTIFIED BY 'catalog' WITH GRANT OPTION; -FLUSH PRIVILEGES; - -use catalog; -set Names 'utf8'; diff --git a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-createObj-mysql.sql b/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-createObj-mysql.sql deleted file mode 100644 index d49e60ba..00000000 --- a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-createObj-mysql.sql +++ /dev/null @@ -1,75 +0,0 @@ --- --- Copyright 2016 [ZTE] and others. --- --- Licensed 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. --- - -use catalog; -DROP TABLE IF EXISTS catalog_package_table; - -CREATE TABLE catalog_package_table ( - CSARID VARCHAR(200) NOT NULL, - DOWNLOADURI VARCHAR(200) NULL, - SIZE VARCHAR(100) NULL, - FORMAT VARCHAR(100) NULL, - CREATETIME VARCHAR(100) NULL, - DELETIONPENDING VARCHAR(100) NULL, - MODIFYTIME VARCHAR(100) NULL, - OPERATIONALSTATE VARCHAR(100) NULL, - USAGESTATE VARCHAR(100) NULL, - ONBOARDSTATE VARCHAR(100) NULL, - NAME VARCHAR(100) NULL, - VERSION VARCHAR(20) NULL, - PROVIDER VARCHAR(300) NULL, - TYPE VARCHAR(300) NULL, - PROCESSSTATE VARCHAR(100) NULL, - CONSTRAINT CATALOG_PACKAGE_TABLE_OID PRIMARY KEY(CSARID) -); - -DROP TABLE IF EXISTS catalog_service_template_table; -CREATE TABLE catalog_service_template_table ( - SERVICETEMPLATEID VARCHAR(200) NOT NULL, - TEMPLATENAME VARCHAR(100) NULL, - TYPE VARCHAR(50) NULL, - VENDOR VARCHAR(100) NULL, - VERSION VARCHAR(20) NULL, - CSARID VARCHAR(100) NULL, - INPUTS LONGTEXT NULL, - ROWDATA LONGTEXT NULL, - OPERATIONS LONGTEXT NULL, - DOWNLOADURI VARCHAR(200) NULL, - - CONSTRAINT CATALOG_SERVICE_TEMPLATE_TABLE_OID PRIMARY KEY(SERVICETEMPLATEID) -); - -DROP TABLE IF EXISTS catalog_node_template_table; -CREATE TABLE catalog_node_template_table ( - NODETEMPLATEID VARCHAR(200) NOT NULL, - NAME VARCHAR(100) NULL, - SERVICETEMPLATEID VARCHAR(200) NULL, - TYPE VARCHAR(50) NULL, - PROPERTIES LONGTEXT NULL, - RELATIONSHIPS LONGTEXT NULL, - - CONSTRAINT catalog_node_template_table PRIMARY KEY(NODETEMPLATEID) -); -DROP TABLE IF EXISTS catalog_model_substitution_mapping_table; -CREATE TABLE catalog_model_substitution_mapping_table ( - MAPPINGID VARCHAR(200) NOT NULL, - NODETYPE VARCHAR(100) NULL, - SERVICETEMPLATEID VARCHAR(200) NULL, - REQUIREMENTS LONGTEXT NULL, - CAPABILITIES LONGTEXT NULL, - - CONSTRAINT catalog_model_substitution_mapping_table PRIMARY KEY(MAPPINGID) -); diff --git a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-extend-mysql.sql b/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-extend-mysql.sql deleted file mode 100644 index 50b0c190..00000000 --- a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-extend-mysql.sql +++ /dev/null @@ -1,17 +0,0 @@ --- --- Copyright 2016 [ZTE] and others. --- --- Licensed 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. --- - --- \ No newline at end of file diff --git a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-mysql.sql b/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-mysql.sql deleted file mode 100644 index d0bd6180..00000000 --- a/catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog-resource-insert-mysql.sql +++ /dev/null @@ -1,20 +0,0 @@ --- --- Copyright 2016 [ZTE] and others. --- --- Licensed 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. --- - -SET autocommit = 0; - -COMMIT; -SET autocommit = 1; \ No newline at end of file diff --git a/catalog-core/distribution/catalog-standalone/src/main/assembly/dbscripts/mysql/openo-common_tosca-catalog-createobj.sql b/catalog-core/distribution/catalog-standalone/src/main/assembly/dbscripts/mysql/openo-common_tosca-catalog-createobj.sql new file mode 100644 index 00000000..308a416a --- /dev/null +++ b/catalog-core/distribution/catalog-standalone/src/main/assembly/dbscripts/mysql/openo-common_tosca-catalog-createobj.sql @@ -0,0 +1,95 @@ +-- +-- Copyright 2016 [ZTE] and others. +-- +-- Licensed 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. +-- + +/******************drop old database and user***************************/ +use mysql; +drop database IF EXISTS catalog; +delete from user where User='catalog'; +FLUSH PRIVILEGES; + +/******************create new database and user***************************/ +create database catalog CHARACTER SET utf8; + +GRANT ALL PRIVILEGES ON catalog.* TO 'catalog'@'%' IDENTIFIED BY 'catalog' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON mysql.* TO 'catalog'@'%' IDENTIFIED BY 'catalog' WITH GRANT OPTION; + +GRANT ALL PRIVILEGES ON catalog.* TO 'catalog'@'localhost' IDENTIFIED BY 'catalog' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON mysql.* TO 'catalog'@'localhost' IDENTIFIED BY 'catalog' WITH GRANT OPTION; +FLUSH PRIVILEGES; + +use catalog; +set Names 'utf8'; +/******************delete old table and create new***************************/ +use catalog; +DROP TABLE IF EXISTS catalog_package_table; + +CREATE TABLE catalog_package_table ( + CSARID VARCHAR(200) NOT NULL, + DOWNLOADURI VARCHAR(200) NULL, + SIZE VARCHAR(100) NULL, + FORMAT VARCHAR(100) NULL, + CREATETIME VARCHAR(100) NULL, + DELETIONPENDING VARCHAR(100) NULL, + MODIFYTIME VARCHAR(100) NULL, + OPERATIONALSTATE VARCHAR(100) NULL, + USAGESTATE VARCHAR(100) NULL, + ONBOARDSTATE VARCHAR(100) NULL, + NAME VARCHAR(100) NULL, + VERSION VARCHAR(20) NULL, + PROVIDER VARCHAR(300) NULL, + TYPE VARCHAR(300) NULL, + PROCESSSTATE VARCHAR(100) NULL, + CONSTRAINT CATALOG_PACKAGE_TABLE_OID PRIMARY KEY(CSARID) +); + +DROP TABLE IF EXISTS catalog_service_template_table; +CREATE TABLE catalog_service_template_table ( + SERVICETEMPLATEID VARCHAR(200) NOT NULL, + TEMPLATENAME VARCHAR(100) NULL, + TYPE VARCHAR(50) NULL, + VENDOR VARCHAR(100) NULL, + VERSION VARCHAR(20) NULL, + CSARID VARCHAR(100) NULL, + INPUTS LONGTEXT NULL, + ROWDATA LONGTEXT NULL, + OPERATIONS LONGTEXT NULL, + DOWNLOADURI VARCHAR(200) NULL, + + CONSTRAINT CATALOG_SERVICE_TEMPLATE_TABLE_OID PRIMARY KEY(SERVICETEMPLATEID) +); + +DROP TABLE IF EXISTS catalog_node_template_table; +CREATE TABLE catalog_node_template_table ( + NODETEMPLATEID VARCHAR(200) NOT NULL, + NAME VARCHAR(100) NULL, + SERVICETEMPLATEID VARCHAR(200) NULL, + TYPE VARCHAR(50) NULL, + PROPERTIES LONGTEXT NULL, + RELATIONSHIPS LONGTEXT NULL, + + CONSTRAINT catalog_node_template_table PRIMARY KEY(NODETEMPLATEID) +); +DROP TABLE IF EXISTS catalog_model_substitution_mapping_table; +CREATE TABLE catalog_model_substitution_mapping_table ( + MAPPINGID VARCHAR(200) NOT NULL, + NODETYPE VARCHAR(100) NULL, + SERVICETEMPLATEID VARCHAR(200) NULL, + REQUIREMENTS LONGTEXT NULL, + CAPABILITIES LONGTEXT NULL, + + CONSTRAINT catalog_model_substitution_mapping_table PRIMARY KEY(MAPPINGID) +); + diff --git a/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.bat b/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.bat index 61a00e69..6663e3d7 100644 --- a/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.bat +++ b/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.bat @@ -1,4 +1,5 @@ @REM +@REM @REM Copyright 2016 [ZTE] and others. @REM @REM Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,28 +16,19 @@ @REM @echo off -title init catalog db - -set RUNHOME=%~dp0 -echo ### RUNHOME: %RUNHOME% - -echo ### init catalog db -rem cd /d %RUNHOME% - -set JAVA="%JAVA_HOME%\bin\java.exe" -set port=8777 -set jvm_opts=-Xms50m -Xmx128m -rem set jvm_opts=%jvm_opts% -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=%port%,server=y,suspend=n -set class_path=%RUNHOME%;%RUNHOME%catalog-service.jar -echo ### jvm_opts: %jvm_opts% -echo ### class_path: %class_path% - -%JAVA% -classpath %class_path% %jvm_opts% org.openo.commontosca.catalog.CatalogApp db migrate %RUNHOME%conf\catalog.yml - -IF ERRORLEVEL 1 goto showerror -exit -:showerror -echo WARNING: Error occurred during startup or Server abnormally stopped by way of killing the process,Please check! -echo After checking, press any key to close -pause -exit \ No newline at end of file +set HOME=%~dp0 +set user=%1 +set password=%2 +set port=%3 +set host=%4 +echo start init catalog db +echo HOME=$HOME +cd /d %HOME% +mysql -u%user% -p%password% -P%port% -h%host% < dbscripts\mysql\openo-common_tosca-catalog-createobj.sql +set "err=%errorlevel%" +if "%err%"=="0" ( + echo init catalog db success + ) else ( + echo failed init catalog db + pause + ) \ No newline at end of file diff --git a/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.sh b/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.sh index b950f88c..2e5cd323 100644 --- a/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.sh +++ b/catalog-core/distribution/catalog-standalone/src/main/assembly/initDB.sh @@ -1,3 +1,5 @@ +#!/bin/bash +# # # Copyright 2016 [ZTE] and others. # @@ -15,17 +17,18 @@ # DIRNAME=`dirname $0` -RUNHOME=`cd $DIRNAME/; pwd` -echo @RUNHOME@ $RUNHOME - -title catalog Database setup - -echo ### Starting catalog Database setup -echo @JAVA_HOME@ $JAVA_HOME -JAVA="$JAVA_HOME/bin/java" -echo @JAVA@ $JAVA - -class_path="$RUNHOME/:$RUNHOME/catalog-service.jar" -echo @class_path@ $class_path +HOME=`cd $DIRNAME/; pwd` +user=$1 +password=$2 +port=$3 +host=$4 +echo "start init catalog db" +mysql -u$user -p$password -P$port -h$host