1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-06-16 18:30:03 +08:00
Signed-off-by: Hai Liang Wang <hai@chatopera.com>
This commit is contained in:
Hai Liang Wang 2023-09-21 11:49:32 +08:00
parent 629abe88d2
commit 63c5750181
7 changed files with 75 additions and 4 deletions

View File

@ -223,7 +223,7 @@ public class Constants {
public static final String LICENSE_SERVER_INST_ID = "SERVERINSTID";
public static final String LICENSE_SERVICE_NAME = "SERVICENAME";
public static final String LICENSE_SERVICE_NAME_PREFIX = "春松客服";
public static final String LICENSES = "LICENSES";
public static final String LICENSEIDS = "LICENSEIDS";
public static final String METAKV_DATATYPE_STRING = "string";
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
* <https://www.chatopera.com>, Licensed under the Chunsong Public
* License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html
* 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.
* Copyright (C) 2019-2022 Chatopera Inc, <https://www.chatopera.com>,
* Licensed under the Apache License, Version 2.0,
* http://www.apache.org/licenses/LICENSE-2.0
*/
package com.cskefu.cc.config;
import com.chatopera.store.sdk.QuotaWdClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class QuotaWdClientConfig {
@Value("${cskefu.license.store}")
private String cskefuLicenseStore;
/**
* 证书商店服务客户端
*
* @return
*/
@Bean
public QuotaWdClient quotaWdClient() {
QuotaWdClient quotaWdClient = new QuotaWdClient();
quotaWdClient.setBaseUrl(cskefuLicenseStore);
return quotaWdClient;
}
}

View File

@ -10,7 +10,11 @@
*/
package com.cskefu.cc.proxy;
import com.chatopera.store.sdk.QuotaWdClient;
import com.chatopera.store.sdk.Response;
import com.chatopera.store.sdk.exceptions.InvalidResponseException;
import com.cskefu.cc.basic.Constants;
import com.cskefu.cc.basic.MainContext;
import com.cskefu.cc.basic.MainUtils;
import com.cskefu.cc.model.Metakv;
import com.cskefu.cc.persistence.repository.MetakvRepository;
@ -19,6 +23,7 @@ import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Service;
import java.util.Date;
@ -31,11 +36,35 @@ public class LicenseProxy {
@Autowired
private MetakvRepository metkvRes;
@Autowired
private QuotaWdClient quotaWdClient;
/**
* 初始化 serverinstId
* serverinstId 作为服务唯一的实例ID
*/
public void checkOnStartup() {
/**
* Check service connection
*/
System.out.println("[license] license service URL " + quotaWdClient.getBaseUrl());
try {
Response resp = quotaWdClient.ping();
System.out.println("[license] license service ping successfully.");
if (resp.getRc() != 0) {
throw new InvalidResponseException("Unexpected response from license service " + resp.toString());
}
} catch (InvalidResponseException e) {
logger.error("[license] make sure this host machine could connect to " + quotaWdClient.getBaseUrl() + " during running.");
logger.error("[license] checkOnStartup could not connect to license service, CSKeFu instance is terminated.", e);
// Very serious event happens, just shutdown the instance
SpringApplication.exit(MainContext.getContext(), () -> 1);
}
/**
* Init local data for License
*/
Optional<Metakv> metaServerinstIdOpt = metkvRes.findFirstByMetakey(Constants.LICENSE_SERVER_INST_ID);
if (metaServerinstIdOpt.isEmpty()) {
// 没有 serverinstId 信息初始化
@ -50,10 +79,10 @@ public class LicenseProxy {
createMetakv(Constants.LICENSE_SERVICE_NAME, serviceName, Constants.METAKV_DATATYPE_STRING);
}
Optional<Metakv> metaLicensesOpt = metkvRes.findFirstByMetakey(Constants.LICENSES);
Optional<Metakv> metaLicensesOpt = metkvRes.findFirstByMetakey(Constants.LICENSEIDS);
if (metaLicensesOpt.isEmpty()) {
// 没有 license 信息初始化
createMetakv(Constants.LICENSES, (new JSONArray()).toString(), Constants.METAKV_DATATYPE_STRING);
createMetakv(Constants.LICENSEIDS, (new JSONArray()).toString(), Constants.METAKV_DATATYPE_STRING);
}
}

View File

@ -154,6 +154,8 @@ cskefu.modules.report=true
# https://gitlab.chatopera.com/chatopera/cosinee/issues/838
cskefu.settings.webim.visitor-separate=false
# License Service Provider URL
cskefu.license.store=https://store.chatopera.com
##############################################
# Skype Channel

View File

@ -410,7 +410,7 @@
<dependency>
<groupId>com.chatopera.store</groupId>
<artifactId>store-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</dependency>
<!-- Required for Java 11 https://github.com/cskefu/cskefu/issues/714 -->

View File

@ -42,6 +42,7 @@ services:
- BOT_THRESHOLD_FAQ_BEST_REPLY=${BOT_THRESHOLD_FAQ_BEST_REPLY:-0.9}
- BOT_THRESHOLD_FAQ_SUGG_REPLY=${BOT_THRESHOLD_FAQ_SUGG_REPLY:-0.1}
- CSKEFU_SETTINGS_WEBIM_VISITOR_SEPARATE=true
- CSKEFU_LICENSE_STORE=${CSKEFU_LICENSE_STORE:-https://store.chatopera.com}
- TONGJI_BAIDU_SITEKEY=${TONGJI_BAIDU_SITEKEY:-placeholder}
- EXTRAS_LOGIN_BANNER=${NOTICE_LOGIN_BANNER:-off}
- EXTRAS_LOGIN_CHATBOX=${EXTRAS_LOGIN_CHATBOX:-off}

View File

@ -30,6 +30,7 @@ CACHE_SETUP_STRATEGY=create_by_force
BOT_THRESHOLD_FAQ_BEST_REPLY=0.8
BOT_THRESHOLD_FAQ_SUGG_REPLY=0.6
CSKEFU_LICENSE_STORE=https://store.chatopera.com
TONGJI_BAIDU_SITEKEY=placeholder
EXTRAS_LOGIN_BANNER=""
EXTRAS_LOGIN_CHATBOX=