Skip to content

Commit

Permalink
Merge pull request #250 from Karenlrx/feature/add-redis
Browse files Browse the repository at this point in the history
add the feature of redis.
  • Loading branch information
yanggang-JV committed Aug 13, 2020
2 parents ce48fb9 + 1dcb9c6 commit 495caab
Show file tree
Hide file tree
Showing 46 changed files with 2,393 additions and 358 deletions.
33 changes: 21 additions & 12 deletions .ci/script/build-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ weid_config=${java_source_code_dir}/src/main/resources/weidentity.properties
export MYSQL_ADDRESS=${1:-0.0.0.0:3306}
export MYSQL_DATABASE=${2:-database}
export MYSQL_USERNAME=${3:-username}
export MYSQL_PASSWORD=${4:-password}
export MYSQL_PASSWORD=${4:-mysqlPassword}
export REDIS_ADDRESS=${5:-0.0.0.0:6379}
export REDIS_PASSWORD=${6:-redisPassword}
export PERSISTENCE_TYPE=${7:-type}

JAVA_OPTS='-Djdk.tls.namedGroups="secp256r1,secp256k1"'

Expand All @@ -19,21 +22,24 @@ function modify_config()

export FISCO_BCOS_VERSION=${FISCO_BCOS_VERSION}
export CNS_PROFILE_ACTIVE=${CNS_PROFILE_ACTIVE}

MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
cp ${app_xml_config} ${java_source_code_dir}/src/test/resources/
# cat $app_xml_config

export ORG_ID=${ORG_ID}
export AMOP_ID=${AMOP_ID}
export MYSQL_ADDRESS=${MYSQL_ADDRESS}
export MYSQL_DATABASE=${MYSQL_DATABASE}
export MYSQL_USERNAME=${MYSQL_USERNAME}
export MYSQL_PASSWORD=${MYSQL_PASSWORD}
export REDIS_ADDRESS=${REDIS_ADDRESS}
export REDIS_PASSWORD=${REDIS_PASSWORD}
export PERSISTENCE_TYPE=${PERSISTENCE_TYPE}
export BLOCKCHIAN_NODE_INFO=${BLOCKCHIAN_NODE_INFO}
NODEVAR='${ORG_ID}:${AMOP_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${BLOCKCHIAN_NODE_INFO}'

NODEVAR='${ORG_ID}:${AMOP_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${REDIS_ADDRESS}:${REDIS_PASSWORD}:${PERSISTENCE_TYPE}:${BLOCKCHIAN_NODE_INFO}'
envsubst ${NODEVAR} < ${weid_config_tpl} >${weid_config}
cp ${weid_config} ${java_source_code_dir}/src/test/resources/

Expand All @@ -59,11 +65,11 @@ function gradle_build_sdk()

export FISCO_BCOS_VERSION="2"
export CNS_PROFILE_ACTIVE="ci"

MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}


content="$NODE_IP"
# content="0.0.0.0:8902"
export BLOCKCHIAN_NODE_INFO=${content}
Expand All @@ -73,7 +79,10 @@ function gradle_build_sdk()
echo $MYSQL_DATABASE
echo $MYSQL_USERNAME
echo $MYSQL_PASSWORD
NODEVAR='${ORG_ID}:${AMOP_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${BLOCKCHIAN_NODE_INFO}'
echo $REDIS_ADDRESS
echo $REDIS_PASSWORD
echo $PERSISTENCE_TYPE
NODEVAR='${ORG_ID}:${AMOP_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${REDIS_ADDRESS}:${REDIS_PASSWORD}:${PERSISTENCE_TYPE}:${BLOCKCHIAN_NODE_INFO}'
envsubst ${NODEVAR} < ${weid_config_tpl} >${weid_config}

echo "Begin to compile java code......"
Expand Down Expand Up @@ -105,7 +114,7 @@ function deploy_contract()
do
CLASSPATH=${CLASSPATH}:${jar_file}
done

chain_id=101
privateKey=18602059553666200379844734388296903882431291027699519961839765914892609749994

Expand All @@ -119,7 +128,7 @@ function install_font()
if [ ! -f NotoSansCJKtc-Regular.ttf ]; then
wget -c https://www.fisco.com.cn/cdn/weevent/weidentity/download/releases/NotoSansCJKtc-Regular.ttf
fi

if [ -f NotoSansCJKtc-Regular.ttf ]; then
sudo mkdir -p /usr/share/fonts/custom&&
sudo cp NotoSansCJKtc-Regular.ttf /usr/share/fonts/custom/&&
Expand All @@ -142,4 +151,4 @@ function main()
modify_config
}

main
main
11 changes: 9 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 3
- name: Start Redis Server
uses: karenlrx/redis-github-action@1.2.0
with:
redis-version: 5
- name: Verify Redis connection
run: |
sudo docker exec redis redis-cli -p 6379 -a 123456 ping
- name: Verify MySQL connection and create CI DB
run: |
sudo systemctl start mysql.service
Expand All @@ -42,7 +49,7 @@ jobs:
export NODE2_IP=127.0.0.1:20201
export PATH=/home/runner/gradle-provision-tmpdir/installs/gradle-5.4.1/bin:$PATH
chmod u+x .ci/script/build-ci.sh
.ci/script/build-ci.sh 127.0.0.1:3306 cidb root root
.ci/script/build-ci.sh 127.0.0.1:3306 cidb root root 127.0.0.1:6379 123456 redis
- name: Run CI
run: |
export PATH=/home/runner/gradle-provision-tmpdir/installs/gradle-5.4.1/bin:$PATH
Expand Down Expand Up @@ -88,7 +95,7 @@ jobs:
export NODE2_IP=127.0.0.1:20201
export PATH=/home/runner/gradle-provision-tmpdir/installs/gradle-5.4.1/bin:$PATH
chmod u+x .ci/script/build-ci.sh
.ci/script/build-ci.sh 127.0.0.1:3306 cidb root root
.ci/script/build-ci.sh 127.0.0.1:3306 cidb root root 127.0.0.1:6379 123456 redis
- name: Checkout and prepare
run: |
git clone https://github.com/WeBankFinTech/weid-sample.git
Expand Down
9 changes: 8 additions & 1 deletion build-tools/bin/run.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ org_id=
#chain id
chain_id=101

#Configure your database information
#Choose your persistence type, mysql or redis.
persistence_type=

#Configure your mysql database information
mysql_address=
mysql_database=
mysql_username=
mysql_password=

#Configure your redis information
redis_address=
redis_password=

#This variable is used to distinguish the environment. You can use "dev" to set the development environment,
#"stg" to set the test environment, "prd" to set the production environment.
#If you do not set it, the system will use allOrg as the environment by default.
Expand Down
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ List mysql_driver = [
"org.apache.commons:commons-dbcp2:2.5.0"
]

List redisson = [
"org.redisson:redisson:3.13.1"
]

List zxing = [
"com.google.zxing:core:3.3.3",
"com.google.zxing:javase:3.3.3"
Expand Down Expand Up @@ -148,7 +152,7 @@ dependencies {
localDeps 'org.projectlombok:lombok:1.18.10'
if (gradleVer.startsWith("4")) {
if (!gradle.startParameter.isOffline()) {
compile logger, lombok, apache_commons, json, mysql_driver, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile logger, lombok, apache_commons, json, mysql_driver, redisson, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile("com.webank:weid-contract-java:1.2.22-rc.4-SNAPSHOT") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
// exclude group: "org.fisco-bcos", module: "web3sdk"
Expand All @@ -169,7 +173,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.10'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.10'
testCompileOnly 'org.projectlombok:lombok:1.18.10'
compile logger, apache_commons, json, mysql_driver, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile logger, apache_commons, json, mysql_driver, redisson, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile("com.webank:weid-contract-java:1.2.22-rc.4-SNAPSHOT") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
// exclude group: "org.fisco-bcos", module: "web3sdk"
Expand Down
102 changes: 99 additions & 3 deletions src/main/java/com/webank/weid/constant/DataDriverConstant.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright© (2018) WeBank Co., Ltd.
* Copyright© (2018-2020) WeBank Co., Ltd.
*
* This file is part of weid-java-sdk.
*
Expand All @@ -19,13 +19,104 @@

package com.webank.weid.constant;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
* constant for DataDriver.
*
* @author tonychen 2019年3月25日
*/
public final class DataDriverConstant {

/**
*encoding form.
*/
public static final Charset STANDARDCHARSETS_ISO = StandardCharsets.ISO_8859_1;
public static final Charset STANDARDCHARSETS_UTF_8 = StandardCharsets.UTF_8;

/**
* redis execute status.
*/
public static final int REDISSON_EXECUTE_FAILED_STATUS = 0;
public static final int REDISSON_EXECUTE_SUCESS_STATUS = 1;

/**
* redis mode name.
*/
public static final String REDIS_SINGLE = "redis_single";
public static final String REDIS_CLUSTER = "redis_cluster";

/**
* redis url properties.
*/
public static final String REDIS_URL = "redis.url";

/**
* redis user password properties.
*/
public static final String PASSWORD = "redis.password";

/**
* redis single database properties.
*/
public static final String DATABASE = "database";

/**
* redis cluster idle_connection_timeout properties.
*/
public static final String IDLE_CONNECTION_TIMEOUT = "idle_connection_timeout";

/**
* redis cluster connect_timeout properties.
*/
public static final String CONNECT_TIMEOUT = "connect_timeout";

/**
* redis cluster timeout properties.
*/
public static final String TIMEOUT = "timeout";

/**
* redis cluster slave_connection_minimum_idle_size properties.
*/
public static final String SLAVE_CONNECTION_MINIMUM_IDLE_SIZE =
"slave_connection_minimum_idle_size";

/**
* redis cluster slave_connection_pool_size properties.
*/
public static final String SLAVE_CONNECTION_POOL_SIZE =
"slave_connection_pool_size";

/**
* redis cluster master_connection_minimum_idle_size properties.
*/
public static final String MASTER_CONNECTION_MINIMUM_IDLE_SIZE =
"master_connection_minimum_idle_size";

/**
* redis cluster master_connection_pool_size properties.
*/
public static final String MASTER_CONNECTION_POOL_SIZE =
"master_connection_pool_size";

/**
* the default value for redis single config.
*/
public static final String DATABASE_DEFAULT_VALUE = "0";

/**
* the default value for redis cluster config.
*/
public static final String IDLE_CONNECTION_TIMEOUT_DEFAULT_VALUE = "10000";
public static final String CONNECT_TIMEOUT_DEFAULT_VALUE = "10000";
public static final String TIMEOUT_DEFAULT_VALUE = "3000";
public static final String SLAVE_CONNECTION_MINIMUM_IDLE_SIZE_DEFAULT_VALUE = "10";
public static final String SLAVE_CONNECTION_POOL_SIZE_DEFAULT_VALUE = "64";
public static final String MASTER_CONNECTION_MINIMUM_IDLE_SIZE_DEFAULT_VALUE = "10";
public static final String MASTER_CONNECTION_POOL_SIZE_DEFAULT_VALUE = "64";

/**
* jdbc url properties.
*/
Expand Down Expand Up @@ -62,7 +153,7 @@ public final class DataDriverConstant {
public static final String JDBC_MIN_IDLE = "jdbc.minIdle";

/**
* jdbc minIdle properties.
* jdbc maxIdle properties.
*/
public static final String JDBC_MAX_IDLE = "jdbc.maxIdle";

Expand Down Expand Up @@ -124,7 +215,7 @@ public final class DataDriverConstant {
/**
* sql execute status.
*/
public static final Integer SQL_EXECUTE_FAILED_STATUS = 0;
public static final int SQL_EXECUTE_FAILED_STATUS = 0;

/**
* jdbc user password properties.
Expand Down Expand Up @@ -187,6 +278,11 @@ public final class DataDriverConstant {
public static final String DOMAIN_DEFAULT_INFO = "domain.defaultInfo";
public static final String DOMAIN_DEFAULT_INFO_TIMEOUT = "domain.defaultInfo.timeout";

/**
* redis存储的离线交易记录.
*/
public static final String DOMAIN_OFFLINE_TRANSACTION_INFO = "offline_transaction_info";

/**
* 系统domain之私钥存储domainKey.
*/
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright© (2018-2019) WeBank Co., Ltd.
* Copyright© (2018-2020) WeBank Co., Ltd.
*
* This file is part of weid-java-sdk.
*
Expand Down Expand Up @@ -813,7 +813,7 @@ public enum ErrorCode {
/**
* weidentity base exceptions or error.
*/
BASE_ERROR(160007, "baes exception error, please check the error log."),
BASE_ERROR(160007, "base exception error, please check the error log."),

/**
* weidentity data type case exceptions or error.
Expand Down Expand Up @@ -894,6 +894,24 @@ public enum ErrorCode {
*/
THIS_IS_REPEATED_CALL(160023, "this is repeated call."),

/**
* can not get the connection from Redis.
*/
REDIS_GET_CONNECTION_ERROR(
160024,
"can not get the connection from Redis, please check the error log."
),

/**
* redis execute failed.
*/
REDIS_EXECUTE_FAILED(160025, "redis execute failed."),

/**
* the data is expire.
*/
REDIS_DATA_EXPIRE(160026, "the data is expire."),

/**
* other uncatched exceptions or error.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
import com.webank.weid.service.BaseService;
import com.webank.weid.service.fisco.WeServer;
import com.webank.weid.service.impl.base.AmopCommonArgs;
import com.webank.weid.suite.api.persistence.Persistence;
import com.webank.weid.suite.persistence.sql.driver.MysqlDriver;
import com.webank.weid.suite.api.persistence.inf.Persistence;
import com.webank.weid.suite.persistence.mysql.driver.MysqlDriver;
import com.webank.weid.util.DataToolUtils;
import com.webank.weid.util.JsonUtil;
import com.webank.weid.util.WeIdUtils;
Expand Down Expand Up @@ -398,7 +398,7 @@ private void blindCredentialSignature(RequestIssueCredentialResponse response, S
// .get(CredentialConstant.CREDENTIAL_META_KEY_ID);
String dbKey = credentialPojo.getId();
ResponseData<Integer> dbResponse =
getDataDriver().saveOrUpdate(
getDataDriver().addOrUpdate(
DataDriverConstant.DOMAIN_USER_CREDENTIAL_SIGNATURE,
dbKey,
newCredentialSignature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
import com.webank.weid.rpc.CptService;
import com.webank.weid.rpc.CredentialPojoService;
import com.webank.weid.rpc.WeIdService;
import com.webank.weid.suite.api.persistence.Persistence;
import com.webank.weid.suite.api.persistence.inf.Persistence;
import com.webank.weid.suite.api.transportation.inf.PdfTransportation;
import com.webank.weid.suite.persistence.sql.driver.MysqlDriver;
import com.webank.weid.suite.persistence.mysql.driver.MysqlDriver;
import com.webank.weid.suite.transportation.pdf.impl.PdfTransportationImpl;
import com.webank.weid.suite.transportation.pdf.protocol.PdfAttributeInfo;
import com.webank.weid.util.CredentialPojoUtils;
Expand Down Expand Up @@ -784,7 +784,7 @@ private static UserResult makeCredential(

//save masterSecret and credentialSecretsBlindingFactors to persistence.
ResponseData<Integer> dbResp = getDataDriver()
.saveOrUpdate(DataDriverConstant.DOMAIN_USER_MASTER_SECRET, id, json);
.addOrUpdate(DataDriverConstant.DOMAIN_USER_MASTER_SECRET, id, json);
if (dbResp.getErrorCode().intValue() != ErrorCode.SUCCESS.getCode()) {
logger.error(
"[makeCredential] save masterSecret and blindingFactors to db failed.");
Expand Down

0 comments on commit 495caab

Please sign in to comment.