diff --git a/weevent-broker/src/main/java/com/webank/weevent/broker/db/InitialDb.java b/weevent-broker/src/main/java/com/webank/weevent/broker/db/InitialDb.java index 6a9ad8b01bcebf62f9a2d76d174a98fe12cd9b9d..cc754749fbe47807a6eaa8f43e94991c907f42f2 100644 --- a/weevent-broker/src/main/java/com/webank/weevent/broker/db/InitialDb.java +++ b/weevent-broker/src/main/java/com/webank/weevent/broker/db/InitialDb.java @@ -47,13 +47,15 @@ public class InitialDb implements AutoCloseable { if (flag) { databaseType = "mysql"; } - // first use dbself database - int first = goalUrl.lastIndexOf("/"); - int end = goalUrl.lastIndexOf("?"); - this.dbName = flag ? goalUrl.substring(first + 1, end) : goalUrl.substring(first + 1); + int first = goalUrl.lastIndexOf("/") + 1; + int endTag = goalUrl.indexOf("?"); + if (endTag == -1) { + endTag = goalUrl.length(); + } + this.dbName = goalUrl.substring(first, endTag); // get mysql default url like jdbc:mysql://127.0.0.1:3306 String defaultUrl = flag ? goalUrl.substring(0, first) : goalUrl; - + log.info("dbName:{},defaultUrl:{}, {}", this.dbName, defaultUrl, databaseType); Class.forName(driverName); List tableSqlList = readSql(); diff --git a/weevent-broker/src/main/resources/application-dev.properties b/weevent-broker/src/main/resources/application-dev.properties index 207f91be5ccf40917a026587923826c162af318d..5d8f8dcbdb649f2b99bf9a4a91b996727ce070f6 100644 --- a/weevent-broker/src/main/resources/application-dev.properties +++ b/weevent-broker/src/main/resources/application-dev.properties @@ -20,6 +20,14 @@ spring.pid.fail-on-write-error=true spring.pid.file=./logs/${spring.application.name}.pid spring.resources.add-mappings=false +#mysql database config +#spring.jpa.database=mysql +#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/WeEvent_broker?useUnicode=true&characterEncoding=utf-8&useSSL=false +#spring.datasource.driver-class-name=org.mariadb.jdbc.Driver +#spring.datasource.username=xxxx +#spring.datasource.password=yyyy +#h2 database config +spring.jpa.database=h2 spring.datasource.url=jdbc:h2:./WeEvent_broker spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=root diff --git a/weevent-broker/src/main/resources/application-prod.properties b/weevent-broker/src/main/resources/application-prod.properties index 207f91be5ccf40917a026587923826c162af318d..5d8f8dcbdb649f2b99bf9a4a91b996727ce070f6 100644 --- a/weevent-broker/src/main/resources/application-prod.properties +++ b/weevent-broker/src/main/resources/application-prod.properties @@ -20,6 +20,14 @@ spring.pid.fail-on-write-error=true spring.pid.file=./logs/${spring.application.name}.pid spring.resources.add-mappings=false +#mysql database config +#spring.jpa.database=mysql +#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/WeEvent_broker?useUnicode=true&characterEncoding=utf-8&useSSL=false +#spring.datasource.driver-class-name=org.mariadb.jdbc.Driver +#spring.datasource.username=xxxx +#spring.datasource.password=yyyy +#h2 database config +spring.jpa.database=h2 spring.datasource.url=jdbc:h2:./WeEvent_broker spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=root diff --git a/weevent-build/modules/broker/install-broker.sh b/weevent-build/modules/broker/install-broker.sh index c825f5e3aa9fd5515491359793ab439ba07ffe61..b53c9aa1631443ff2e2f474752a001879e285b11 100644 --- a/weevent-build/modules/broker/install-broker.sh +++ b/weevent-build/modules/broker/install-broker.sh @@ -71,6 +71,46 @@ else fi echo "set lister_port success" +if [[ ${database_type} != "h2" ]];then + switch_database_to_mysql "${application_properties}" + + if [[ -z ${mysql_ip} ]];then + echo "mysql_ip is empty." + echo "set mysql_ip failed" + exit 1 + else + sed -i "s/127.0.0.1:3306/${mysql_ip}:3306/" ${application_properties} + fi + echo "set mysql_ip success" + + if [[ -z ${mysql_port} ]];then + echo "mysql_port is empty." + echo "set mysql_port failed" + exit 1 + else + sed -i "s/3306/${mysql_port}/" ${application_properties} + fi + echo "set mysql_port success" + + if [[ -z ${mysql_user} ]];then + echo "mysql_user is empty." + echo "set mysql_user failed" + exit 1 + else + sed -i "s/xxxx/${mysql_user}/" ${application_properties} + fi + echo "set mysql_user success" + + if [[ -z ${mysql_pwd} ]];then + echo "mysql_pwd is empty" + echo "set mysql_pwd failed" + exit 1 + else + sed -i "s/yyyy/${mysql_pwd}/" ${application_properties} + fi + echo "set mysql_pwd success" +fi + if [[ -n ${zookeeper_connect_string} ]];then sed -i "/spring.cloud.zookeeper.connect-string=/cspring.cloud.zookeeper.connect-string=${zookeeper_connect_string}" ${out_path}/conf/application-prod.properties else @@ -79,4 +119,22 @@ else fi echo "set zookeeper_connect_string success" +# init db, create database and tables +cd ${out_path} +./init-broker.sh +if [[ $? -ne 0 ]];then + + echo "Error,init mysql fail" + exit 1 +fi +echo "init db success" + +function switch_database_to_mysql() { + mysql_config_line=$(cat -n $1|grep 'spring.jpa.database=mysql'|awk '{print $1}'|head -1) + sed -i ''$mysql_config_line','$((mysql_config_line+4))'s/^#//' $1 + + h2_config_line=$(cat -n $1|grep 'spring.jpa.database=h2'|awk '{print $1}'|head -1) + sed -i ''$h2_config_line','$((h2_config_line+4))'s/^/#/' $1 +} + echo "broker module install success" diff --git a/weevent-governance/src/main/java/com/webank/weevent/governance/initial/InitialDb.java b/weevent-governance/src/main/java/com/webank/weevent/governance/initial/InitialDb.java index f5db466d5433a4d424caa1a2abc21b827b6ff4c6..11d01c715ff4f52e34a48b634de73ab9707bd890 100644 --- a/weevent-governance/src/main/java/com/webank/weevent/governance/initial/InitialDb.java +++ b/weevent-governance/src/main/java/com/webank/weevent/governance/initial/InitialDb.java @@ -47,13 +47,15 @@ public class InitialDb implements AutoCloseable { if (flag) { databaseType = "mysql"; } - // first use dbself database - int first = goalUrl.lastIndexOf("/"); - int end = goalUrl.lastIndexOf("?"); - this.dbName = flag ? goalUrl.substring(first + 1, end) : goalUrl.substring(first + 1); + int first = goalUrl.lastIndexOf("/") + 1; + int endTag = goalUrl.indexOf("?"); + if (endTag == -1) { + endTag = goalUrl.length(); + } + this.dbName = goalUrl.substring(first, endTag); // get mysql default url like jdbc:mysql://127.0.0.1:3306 String defaultUrl = flag ? goalUrl.substring(0, first) : goalUrl; - + log.info("dbName:{},defaultUrl:{}, {}", this.dbName, defaultUrl, databaseType); Class.forName(driverName); List tableSqlList = readSql(); diff --git a/weevent-governance/src/main/resources/application-dev.properties b/weevent-governance/src/main/resources/application-dev.properties index 55c7243432ebe7ed2ad9597d3992988f444a1abd..f14a4de8e6e16d7a6409117ba32ffe3997d29bba 100644 --- a/weevent-governance/src/main/resources/application-dev.properties +++ b/weevent-governance/src/main/resources/application-dev.properties @@ -1,6 +1,14 @@ spring.application.name=weevent-governance server.port=7009 logging.config=classpath:log4j2.xml +#mysql database config +#spring.jpa.database=mysql +#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/WeEvent_governance?useUnicode=true&characterEncoding=utf-8&useSSL=false +#spring.datasource.driver-class-name=org.mariadb.jdbc.Driver +#spring.datasource.username=xxxx +#spring.datasource.password=yyyy +#h2 database config +spring.jpa.database=h2 spring.datasource.url=jdbc:h2:./WeEvent_governance spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=root diff --git a/weevent-governance/src/main/resources/application-prod.properties b/weevent-governance/src/main/resources/application-prod.properties index 17d2b813ef7c0a657a0234d2a6a258abe4586f5d..b50f84605c10430616e2bf6595f6ae5dfa04ef05 100644 --- a/weevent-governance/src/main/resources/application-prod.properties +++ b/weevent-governance/src/main/resources/application-prod.properties @@ -1,6 +1,14 @@ spring.application.name=weevent-governance server.port=7009 logging.config=classpath:log4j2.xml +#mysql database config +#spring.jpa.database=mysql +#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/WeEvent_governance?useUnicode=true&characterEncoding=utf-8&useSSL=false +#spring.datasource.driver-class-name=org.mariadb.jdbc.Driver +#spring.datasource.username=xxxx +#spring.datasource.password=yyyy +#h2 database config +spring.jpa.database=h2 spring.datasource.url=jdbc:h2:./WeEvent_governance spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=root diff --git a/weevent-governance/web/src/components/fileTranspoart.vue b/weevent-governance/web/src/components/fileTranspoart.vue index b79aab8dae401a8391c1c1131770fcc7dc22b310..cd168ee524b704d95d6d053fb836b64f257c755e 100644 --- a/weevent-governance/web/src/components/fileTranspoart.vue +++ b/weevent-governance/web/src/components/fileTranspoart.vue @@ -490,11 +490,11 @@ export default { if (e.role === '0') { vm.downLoadList[name] = setInterval(fun => { vm.downStatus(e) - }, 1000) + }, 2000) } else { vm.downLoadList[name] = setInterval(fun => { vm.upStatus(e) - }, 1000) + }, 2000) } } }, diff --git a/weevent-processor/src/main/java/com/webank/weevent/processor/db/InitialDb.java b/weevent-processor/src/main/java/com/webank/weevent/processor/db/InitialDb.java index bd4cda5265b55e8d90d088baf10cecd8c12a679d..3add6a21f55896b4e18a3d4580f5fd9f5dc9411a 100644 --- a/weevent-processor/src/main/java/com/webank/weevent/processor/db/InitialDb.java +++ b/weevent-processor/src/main/java/com/webank/weevent/processor/db/InitialDb.java @@ -40,29 +40,28 @@ public class InitialDb implements AutoCloseable { } private void createDataBase() throws Exception { - try { - String goalUrl = properties.getProperty("spring.datasource.url"); - this.user = properties.getProperty("spring.datasource.username"); - this.password = properties.getProperty("spring.datasource.password"); - String driverName = properties.getProperty("spring.datasource.driverClassName"); - boolean flag = driverName.contains("mariadb"); - if (flag) { - databaseType = "mysql"; - } - int first = goalUrl.lastIndexOf("/") + 1; - this.dbName = goalUrl.substring(first); - // get mysql default url like jdbc:mysql://127.0.0.1:3306 - String defaultUrl = flag ? goalUrl.substring(0, first) : goalUrl; - Class.forName(driverName); - - List tableSqlList = readCEPSql(); - - runScript(defaultUrl, flag, tableSqlList); - } catch (Exception e) { - log.error("create database error,{}", e.getMessage()); - throw e; + String goalUrl = properties.getProperty("spring.datasource.url"); + this.user = properties.getProperty("spring.datasource.username"); + this.password = properties.getProperty("spring.datasource.password"); + String driverName = properties.getProperty("spring.datasource.driver-class-name"); + boolean flag = driverName.contains("mariadb"); + if (flag) { + databaseType = "mysql"; } + int first = goalUrl.lastIndexOf("/") + 1; + int endTag = goalUrl.indexOf("?"); + if (endTag == -1) { + endTag = goalUrl.length(); + } + this.dbName = goalUrl.substring(first, endTag); + // get mysql default url like jdbc:mysql://127.0.0.1:3306 + String defaultUrl = flag ? goalUrl.substring(0, first) : goalUrl; + log.info("dbName:{},defaultUrl:{}, {}", this.dbName, defaultUrl, databaseType); + Class.forName(driverName); + + List tableSqlList = readSql(); + runScript(defaultUrl, flag, tableSqlList); } private Properties getProperties() throws Exception { @@ -74,7 +73,7 @@ public class InitialDb implements AutoCloseable { } - private static List readCEPSql() throws IOException { + private static List readSql() throws IOException { InputStream resourceAsStream = InitialDb.class.getResourceAsStream("/cep_rule_" + databaseType + ".sql"); StringBuffer sqlBuffer = new StringBuffer(); List sqlList = new ArrayList<>(); diff --git a/weevent-processor/src/main/resources/application-dev.properties b/weevent-processor/src/main/resources/application-dev.properties index a9f4e16034e27d50e5efdfb19556815c73b0e75c..18e162963bf7103daf7f3872d4a6048fb06808ec 100644 --- a/weevent-processor/src/main/resources/application-dev.properties +++ b/weevent-processor/src/main/resources/application-dev.properties @@ -12,8 +12,17 @@ spring.http.encoding.force=true spring.messages.encoding=UTF-8 spring.pid.fail-on-write-error=true spring.pid.file=./logs/${spring.application.name}.pid + +#mysql database config +#spring.jpa.database=mysql +#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/WeEvent_processor?useUnicode=true&characterEncoding=utf-8&useSSL=false +#spring.datasource.driver-class-name=org.mariadb.jdbc.Driver +#spring.datasource.username=xxxx +#spring.datasource.password=yyyy +#h2 database config +spring.jpa.database=h2 spring.datasource.url=jdbc:h2:./WeEvent_processor -spring.datasource.driverClassName=org.h2.Driver +spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=root spring.datasource.password=123456 spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource diff --git a/weevent-processor/src/main/resources/application-prod.properties b/weevent-processor/src/main/resources/application-prod.properties index a9f4e16034e27d50e5efdfb19556815c73b0e75c..18e162963bf7103daf7f3872d4a6048fb06808ec 100644 --- a/weevent-processor/src/main/resources/application-prod.properties +++ b/weevent-processor/src/main/resources/application-prod.properties @@ -12,8 +12,17 @@ spring.http.encoding.force=true spring.messages.encoding=UTF-8 spring.pid.fail-on-write-error=true spring.pid.file=./logs/${spring.application.name}.pid + +#mysql database config +#spring.jpa.database=mysql +#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/WeEvent_processor?useUnicode=true&characterEncoding=utf-8&useSSL=false +#spring.datasource.driver-class-name=org.mariadb.jdbc.Driver +#spring.datasource.username=xxxx +#spring.datasource.password=yyyy +#h2 database config +spring.jpa.database=h2 spring.datasource.url=jdbc:h2:./WeEvent_processor -spring.datasource.driverClassName=org.h2.Driver +spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=root spring.datasource.password=123456 spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource