Skip to content

Commit

Permalink
bug fix: install bash (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
caseone committed Mar 15, 2021
1 parent 692b146 commit 14517b1
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
public class AccountTopicAuthEntity extends BaseEntity {

@NotBlank
@Column(name = "user_name")
@Column(name = "user_name", columnDefinition = "varchar(200)")
private String userName;

@Column(name = "topic_name")
@Column(name = "topic_name", columnDefinition = "varchar(128)")
private String topicName;

@Column(name = "permission")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ public MqttConnAckMessage processConnect(MqttConnectMessage msg, SessionContext
MqttConnAckMessage rsp = (MqttConnAckMessage) this.connect.processConnect(msg, sessionData);
// if accept
if (rsp.variableHeader().connectReturnCode() == MqttConnectReturnCode.CONNECTION_ACCEPTED) {
AuthorSessions sessionsParam = AuthorSessions.builder().clientId(sessionData.getClientId())
.userName("user").build();
AuthorSessions sessionsParam = AuthorSessions.builder().clientId(sessionData.getClientId()).userName(msg.payload().userName()).build();
this.authorSessions.put(sessionData.getSessionId(), sessionsParam);
}
return rsp;
Expand Down Expand Up @@ -213,6 +212,7 @@ public Optional<MqttMessage> process(MqttMessage req, String sessionId, String r
boolean isAuth = false;
String topicName = ((MqttPublishVariableHeader) req.variableHeader()).topicName();
String userName = this.authorSessions.get(sessionId).getUserName();

List<AccountTopicAuthEntity> entities = accountTopicAuthRepository.findAllByUserName(userName);
for (AccountTopicAuthEntity entity : entities) {
if (entity.getTopicName().equals(topicName) && (entity.getPermission() == SUB_PUB || entity.getPermission() == SUB)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
spring.datasource.dbcp2.max-wait-millis=10000
Expand Down
8 changes: 4 additions & 4 deletions weevent-broker/src/main/resources/script/broker_h2.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
drop table IF EXISTS t_account;
drop table IF EXISTS t_user_topic_auth;
drop table IF EXISTS t_account_topic_auth;

create TABLE t_account (
id INTEGER generated BY DEFAULT AS identity,
Expand All @@ -13,13 +13,13 @@ create TABLE t_account (

create TABLE t_account_topic_auth(
id INTEGER generated BY DEFAULT AS identity,
user_name VARCHAR (255),
topic_name VARCHAR (255),
user_name VARCHAR (200),
topic_name VARCHAR (128),
permission INTEGER,
create_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
)

alter table t_account add CONSTRAINT userName UNIQUE (user_name);
alter table t_user_topic_auth add CONSTRAINT userNameTopicName UNIQUE (user_name, topic_name);
alter table t_account_topic_auth add CONSTRAINT userNameTopicName UNIQUE (user_name, topic_name);
19 changes: 10 additions & 9 deletions weevent-broker/src/main/resources/script/broker_mysql.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
drop table IF EXISTS t_account;
drop table IF EXISTS t_user_topic_auth;
drop table IF EXISTS t_account_topic_auth;

create TABLE t_account (
id INTEGER generated BY DEFAULT AS identity,
id INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
user_name VARCHAR (255) COMMENT '用户名',
password VARCHAR (255) COMMENT '密码',
create_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
delete_at BIGINT NOT NULL,
PRIMARY KEY (id)
);
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='账户表';

create TABLE t_user_topic_auth(
id INTEGER generated BY DEFAULT AS identity,
user_name VARCHAR (255) COMMENT '用户名',
topic_name VARCHAR (256) COMMENT '主题名称',
create TABLE t_account_topic_auth (
id INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
user_name VARCHAR (200) COMMENT '用户名',
topic_name VARCHAR (128) COMMENT '主题名称',
permission INTEGER COMMENT '权限(0:订阅,发布,1:发布,2:订阅)',
delete_at BIGINT NOT NULL DEFAULT 0 COMMENT '0 表示 未删除, 时间戳 表示 已经被删除',
create_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='账户主题权限表';

alter table t_account add CONSTRAINT userName UNIQUE (user_name);
alter table t_user_topic_auth add CONSTRAINT userNameTopicName UNIQUE (user_name, topic_name);
alter table t_account_topic_auth add CONSTRAINT userNameTopicName UNIQUE (user_name, topic_name);
5 changes: 4 additions & 1 deletion weevent-build/install-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function install_module(){

yellow_echo "install module broker"
cd ${current_path}/modules/broker
./install-broker.sh --out_path ${out_path}/broker --listen_port ${broker_port} --block_chain_node_path ${block_chain_node_path} --version ${block_chain_version} --zookeeper_connect_string ${zookeeper_connect_string} --fisco_config_file ${fisco_config_file}
./install-broker.sh --out_path ${out_path}/broker --listen_port ${broker_port} --block_chain_node_path ${block_chain_node_path} --version ${block_chain_version} --zookeeper_connect_string ${zookeeper_connect_string} --fisco_config_file ${fisco_config_file} --database_type ${database_type} --mysql_ip ${mysql_ip} --mysql_port ${mysql_port} --mysql_user ${mysql_user} --mysql_pwd ${mysql_password}
check_result "install broker"

if [[ ${governance_enable} = "true" ]];then
Expand Down Expand Up @@ -190,6 +190,9 @@ function config_java_home(){
if [[ -e ${current_path}/modules/broker/deploy-fabric-topic-control.sh ]];then
sed -i "/JAVA_HOME=/cJAVA_HOME=${java_home_path}" ${current_path}/modules/broker/deploy-fabric-topic-control.sh
fi
if [[ -e ${current_path}/modules/broker/init-broker.sh ]];then
sed -i "/JAVA_HOME=/cJAVA_HOME=${java_home_path}" ${current_path}/modules/broker/init-broker.sh
fi
if [[ -e ${current_path}/modules/governance/governance.sh ]];then
sed -i "/JAVA_HOME=/cJAVA_HOME=${java_home_path}" ${current_path}/modules/governance/governance.sh
fi
Expand Down
46 changes: 37 additions & 9 deletions weevent-build/modules/broker/install-broker.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
#!/bin/bash

# usage
if [[ $# -lt 2 ]]; then
echo "Usage:"
echo " $0 --out_path /data/app/weevent-install/broker "
echo " --server_port --database_type --mysql_ip --mysql_port --mysql_user --mysql_pwd "
exit 1
fi

#get parameter
para=""
current_path=$(pwd)
database_type=""
mysql_ip=""
mysql_port=""
mysql_user=""
mysql_pwd=""

while [[ $# -ge 2 ]] ; do
case "$1" in
--out_path) para="$1 = $2;";out_path="$2";shift 2;;
--listen_port) para="$1 = $2;";listen_port="$2";shift 2;;
--database_type) para="$1 = $2;";database_type="$2";shift 2;;
--mysql_ip) para="$1 = $2;";mysql_ip="$2";shift 2;;
--mysql_port) para="$1 = $2;";mysql_port="$2";shift 2;;
--mysql_user) para="$1 = $2;";mysql_user="$2";shift 2;;
--mysql_pwd) para="$1 = $2;";mysql_pwd="$2";shift 2;;
--block_chain_node_path) para="$1 = $2;";block_chain_node_path="$2";shift 2;;
--version) para="$1 = $2;";version="$2";shift 2;;
--zookeeper_connect_string) para="$1 = $2;";zookeeper_connect_string="$2";shift 2;;
Expand All @@ -21,6 +40,11 @@ echo "param version: ${version}"
echo "param block_chain_node_path: ${block_chain_node_path}"
echo "param zookeeper_connect_string: ${zookeeper_connect_string}"
echo "param fisco_config_file: ${fisco_config_file}"
echo "param database_type: ${database_type}"
echo "param mysql_ip: ${mysql_ip}"
echo "param mysql_port: ${mysql_port}"
echo "param mysql_user: ${mysql_user}"
echo "param mysql_pwd: ${mysql_pwd}"


#copy file
Expand Down Expand Up @@ -61,18 +85,30 @@ else
exit 1
fi

application_properties=${out_path}/conf/application-prod.properties

cd ${current_path}

if [[ ${listen_port} -gt 0 ]]; then
sed -i "/server.port=/cserver.port=${listen_port}" ${out_path}/conf/application-prod.properties
sed -i "/server.port=/cserver.port=${listen_port}" ${application_properties}
else
echo "listen_port is err"
exit 1
fi
echo "set lister_port 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
}


if [[ ${database_type} != "h2" ]];then
switch_database_to_mysql "${application_properties}"
echo "switch_database_to_mysql ok"

if [[ -z ${mysql_ip} ]];then
echo "mysql_ip is empty."
Expand Down Expand Up @@ -129,12 +165,4 @@ if [[ $? -ne 0 ]];then
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"
2 changes: 0 additions & 2 deletions weevent-processor/src/main/resources/cep_rule_h2.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


DROP TABLE IF EXISTS QRTZ_CRON_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_SIMPROP_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_BLOB_TRIGGERS;
Expand Down
12 changes: 11 additions & 1 deletion weevent-processor/src/main/resources/cep_rule_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@
In your Quartz properties file, you'll need to set
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
*/

DROP TABLE IF EXISTS QRTZ_CRON_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_SIMPROP_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_BLOB_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_CALENDARS;
DROP TABLE IF EXISTS QRTZ_PAUSED_TRIGGER_GRPS;
DROP TABLE IF EXISTS QRTZ_FIRED_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_SCHEDULER_STATE;
DROP TABLE IF EXISTS QRTZ_LOCKS;
DROP TABLE IF EXISTS QRTZ_SIMPLE_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_TRIGGERS;
DROP TABLE IF EXISTS QRTZ_JOB_DETAILS;
CREATE TABLE QRTZ_JOB_DETAILS
(
SCHED_NAME VARCHAR(120) NOT NULL,
Expand Down

0 comments on commit 14517b1

Please sign in to comment.