Skip to content

Commit

Permalink
Merge pull request #33 from cyjseagull/feature-milestone2
Browse files Browse the repository at this point in the history
fix start problems
  • Loading branch information
fqliao authored Sep 1, 2024
2 parents 89a39e4 + 32ca537 commit 31cd399
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 150 deletions.
1 change: 1 addition & 0 deletions db/scripts/init/wedpr_sql.list
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
source ../../wedpr_ddl.sql
source ../../tables_quartz.sql
source ../../wedpr_dml.sql
4 changes: 3 additions & 1 deletion wedpr-adm/conf/wedpr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ wedpr.uuid.generator.worker.id=10
# TODO: add this option
# use dpm or not
wedpr.enable.dpm = false
wedpr.crypto.symmetric.key=12345678
wedpr.crypto.symmetric.iv=123456

### the mybatis related configuration

Expand All @@ -22,7 +24,7 @@ wedpr.enable.dpm = false

wedpr.mybatis.mapperLocations=classpath*:mapper/*Mapper.xml
# Note: the basePackage can't set to com.webank.wedpr simply for the mybatis will scan the Service
wedpr.mybatis.BasePackage=com.webank.wedpr.components.meta.resource.follower.dao,com.webank.wedpr.components.meta.sys.config.dao,com.webank.wedpr.components.project.dao,com.webank.wedpr.components.meta.setting.template.dao,com.webank.wedpr.components.sync.dao,com.webank.wedpr.components.authorization.dao,com.webank.wedpr.components.dataset.mapper,com.webank.wedpr.components.user.mapper,com.webank.wedpr.components.meta.agency.dao
wedpr.mybatis.BasePackage=com.webank.wedpr.components.meta.resource.follower.dao,com.webank.wedpr.components.meta.sys.config.dao,com.webank.wedpr.components.project.dao,com.webank.wedpr.components.meta.setting.template.dao,com.webank.wedpr.components.sync.dao,com.webank.wedpr.components.authorization.dao,com.webank.wedpr.components.dataset.mapper,com.webank.wedpr.components.user.mapper,com.webank.wedpr.components.meta.agency.dao,com.webank.wedpr.components.api.credential.dao,com.webank.wedpr.components.integration.jupyter.dao
# wedpr.mybatis.typeAliasesPackage=

### the blockchain configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
<result column="create_time" property="createTime"/>
<result column="last_update_time" property="lastUpdateTime"/>
</resultMap>
<insert id="insertCredential" parameterType="ApiCredentialDO">
<insert id="insertCredential" parameterType="com.webank.wedpr.components.api.credential.dao.ApiCredentialDO">
insert into `wedpr_api_credential_table`(`id`, `access_key_id`,`access_key_secret`,
`owner`, `status`, `desc`, `create_time`) values
(#{credential.id}, #{credential.accessKeyID}, #{credential.accessKeySecret}, #{credential.owner},
#{credential.status}, #{credential.desc}, NOW())
</insert>
<update id="updateCredential" parameterType="ApiCredentialDO">
<update id="updateCredential" parameterType="com.webank.wedpr.components.api.credential.dao.ApiCredentialDO">
update `wedpr_api_credential_table`
<set>
<if test="credential.status != null and credential.status !=''">
Expand All @@ -55,7 +55,7 @@
and `owner` = #{credential.owner},
</if>
</update>
<delete id="deleteCredentialByCondition" parameterType="ApiCredentialDO">
<delete id="deleteCredentialByCondition" parameterType="com.webank.wedpr.components.api.credential.dao.ApiCredentialDO">
delete from `wedpr_api_credential_table` where 1 = 1
<if test="condition.id != null and condition.id !=''">
and `id` = #{condition.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class CryptoToolkitConfig {
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
@ConditionalOnMissingBean
public CryptoToolkit cryptoToolkit() throws Exception {
logger.info("create cryptoToolkit");
return CryptoToolkitFactory.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
<result column="create_time" property="createTime"/>
<result column="last_update_time" property="lastUpdateTime"/>
</resultMap>
<insert id="insertJupyterInfo" parameterType="JupyterInfoDO">
<insert id="insertJupyterInfo" parameterType="com.webank.wedpr.components.integration.jupyter.dao.JupyterInfoDO">
insert into wedpr_jupyter_table(`id`, `owner`,
`agency`, `access_entrypoint`, `setting`, `status`, `create_time`) values
(#{jupyterInfo.id}, #{jupyterInfo.owner}, #{jupyterInfo.agency}, #{jupyterInfo.accessEntry},
#{jupyterInfo.setting}, #{jupyterInfo.status}, NOW())
</insert>
<update id="updateJupyterInfo" parameterType="JupyterInfoDO">
<update id="updateJupyterInfo" parameterType="com.webank.wedpr.components.integration.jupyter.dao.JupyterInfoDO">
update `wedpr_jupyter_table`
<set>
<if test="updatedInfo.accessEntry != null and updatedInfo.accessEntry !=''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.webank.wedpr.components.hook;

import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -40,7 +41,7 @@ public enum Action {
DELETE_USER
}

private Map<String, UserCallback> callbacks;
private Map<String, UserCallback> callbacks = new HashMap<>();

public synchronized void registerUserCallback(String module, UserCallback callback) {
callbacks.put(module, callback);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017-2025 [webank-wedpr]
*
* 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.
*
*/

package com.webank.wedpr.components.hook.config;

import com.webank.wedpr.components.hook.UserHook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
public class UserHookConfig {
private static final Logger logger = LoggerFactory.getLogger(UserHookConfig.class);

@Bean(name = "userHook")
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
@ConditionalOnMissingBean
public UserHook userHook() {
return new UserHook();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.webank.wedpr.core.utils.WeDPRException;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
import lombok.SneakyThrows;
Expand All @@ -37,7 +38,7 @@ public static DataSource build(Properties dataSourceConfig) {
}
}

public static DataSource build() {
public static DataSource build() throws Exception {
logger.info(
"Begin Build DataSource, url: {}, user: {}",
MybatisConfig.WEDPR_MYBATIS_DATASOURCE_URL,
Expand All @@ -63,10 +64,19 @@ public static DataSource build() {
dataSource.setRemoveAbandoned(MybatisConfig.WEDPR_MYBATIS_REMOVE_ABANDONED_ENABLE);
dataSource.setRemoveAbandonedTimeoutMillis(
MybatisConfig.WEDPR_MYBATIS_REMOVE_ABANDONED_TIMEOUT);
if (MybatisConfig.MYBATIS_CONNECTION_PROPERTIES != null) {
dataSource.setConnectionProperties(MybatisConfig.MYBATIS_CONNECTION_PROPERTIES);
}
if (MybatisConfig.MYBATIS_FILTERS != null) {
dataSource.setFilters(MybatisConfig.MYBATIS_FILTERS);
}
dataSource.init();
Map<String, Object> statData = dataSource.getStatData();
logger.info(
"Build DataSource success, url: {}, user: {}",
"Build DataSource success, url: {}, user: {}, statData: {}",
MybatisConfig.WEDPR_MYBATIS_DATASOURCE_URL,
MybatisConfig.WEDPR_MYBATIS_USER_NAME);
MybatisConfig.WEDPR_MYBATIS_USER_NAME,
statData);
return dataSource;
}
}
Original file line number Diff line number Diff line change
@@ -1,139 +1,39 @@
package com.webank.wedpr.components.mybatis;

import com.alibaba.druid.pool.DruidDataSource;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DataSourceConfig {
private static final Logger logger = LoggerFactory.getLogger(DataSourceConfig.class);

@Value("${spring.datasource.url}")
private String url;

@Value("${spring.datasource.username}")
private String username;

@Value("${spring.datasource.password}")
private String password;

@Value("${spring.datasource.driverClassName}")
private String driverClassName;

@Value("${spring.datasource.defaultAutoCommit}")
private boolean defaultAutoCommit;

@Value("${spring.datasource.initialSize}")
private int initialSize;

@Value("${spring.datasource.maxActive}")
private int maxActive;

@Value("${spring.datasource.maxIdle}")
private int maxIdle;

@Value("${spring.datasource.minIdle}")
private int minIdle;

@Value("${spring.datasource.queryTimeout}")
private int queryTimeout = 0;

@Value("${spring.datasource.keepAlive}")
private boolean keepAlive;

@Value("${spring.datasource.testOnBorrow}")
private boolean testOnBorrow;

@Value("${spring.datasource.testOnReturn}")
private boolean testOnReturn;

@Value("${spring.datasource.testWhileIdle}")
private boolean testWhileIdle;

@Value("${spring.datasource.maxWait}")
private long maxWait;

@Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
private long timeBetweenEvictionRunsMillis;

@Value("${spring.datasource.minEvictableIdleTimeMillis}")
private long minEvictableIdleTimeMillis;

@Value("${spring.datasource.validationQuery}")
private String validationQuery;

@Value("${spring.datasource.validationQueryTimeout}")
private int validationQueryTimeout;

@Value("${spring.datasource.removeAbandoned}")
private boolean removeAbandoned;

@Value("${spring.datasource.logAbandoned}")
private boolean logAbandoned;

@Value("${spring.datasource.removeAbandonedTimeout}")
private int removeAbandonedTimeout;

@Value("${spring.datasource.poolPreparedStatements}")
private boolean poolPreparedStatements;

@Value("${spring.datasource.connectionProperties}")
private String connectionProperties;

@Value("${spring.datasource.filters}")
private String filters;

@Bean(name = "dataSource", destroyMethod = "close")
public DruidDataSource dataSource() throws Exception {

logger.info("dataSource dbUrl:{}", url);
logger.info("dataSource dbUsername:{}", username);
logger.info("dataSource driverClassName:{}", driverClassName);
logger.info("dataSource queryTimeout:{}", queryTimeout);

// https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7%BD%AE

DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
datasource.setDefaultAutoCommit(defaultAutoCommit);
// configuration
datasource.setInitialSize(initialSize);
datasource.setMaxActive(maxActive);
datasource.setMinIdle(maxIdle);
datasource.setMinIdle(minIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setValidationQuery(validationQuery);
datasource.setValidationQueryTimeout(validationQueryTimeout);
datasource.setQueryTimeout(queryTimeout);
//
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
// datasource.setMaxEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setKeepAlive(keepAlive);

datasource.setRemoveAbandoned(removeAbandoned);
datasource.setLogAbandoned(logAbandoned);
datasource.setRemoveAbandonedTimeout(removeAbandonedTimeout);

datasource.setMaxWait(maxWait);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setConnectionProperties(connectionProperties);
datasource.setFilters(filters);

datasource.init();
Map<String, Object> statData = datasource.getStatData();

logger.info("create druid datasource successfully: {}", statData);

return datasource;
}
}
/*
* Copyright 2017-2025 [webank-wedpr]
*
* 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.
*
*/

package com.webank.wedpr.components.mybatis;

import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DataSourceConfig {
private static final Logger logger = LoggerFactory.getLogger(DataSourceConfig.class);

@Bean(name = "dataSource", destroyMethod = "close")
@ConditionalOnMissingBean
public DataSource dataSource() throws Exception {
logger.info("Load DataSource");
if (MybatisConfig.MYBATIS_CONFIG != null) {
DataSource dataSource = DataSourceBuilder.build(MybatisConfig.MYBATIS_CONFIG);
logger.info("Load DataSource from configuration success");
return dataSource;
}
return DataSourceBuilder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class MybatisConfig {
WeDPRConfig.apply("wedpr.mybatis.configLocation", "classpath:mybatis-config.xml");
private static final String MYBATIS_BASEPACKAGE =
WeDPRConfig.apply("wedpr.mybatis.BasePackage", "");
public static final String MYBATIS_FILTERS = WeDPRConfig.apply("wedpr.mybatis.filters", null);
public static final String MYBATIS_CONNECTION_PROPERTIES =
WeDPRConfig.apply("wedpr.mybatis.connection.properties", null);

static {
// load configuration from the config file is the file exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class QuartzBindJobConfig {
@Autowired private QuartzJobFactory quartzJobFactory;
@Autowired private Scheduler scheduler;

@Value("${quartz-cron-report-job}")
@Value("${quartz-cron-report-job:0/2 * * * * ? *}")
private String quartzCronReportJob;

private final String jobGroup = "wedpr";
Expand Down

0 comments on commit 31cd399

Please sign in to comment.