Browse Source

Pull request #14253: REPORT-114391 【微服务适配】远程&本地设计器能够正常启动 修复部分bug

Merge in DESIGN/design from ~DESTINY.LIN/design:mss/2.0 to mss/2.0

* commit 'c3c38e10c928abb834b7982072066658cf3007aa':
  REPORT-114391 【微服务适配】远程&本地设计器能够正常启动 代码规范
  REPORT-114391 【微服务适配】远程&本地设计器能够正常启动 修复图表配置+优化环境切换
  REPORT-114391 【微服务适配】远程&本地设计器能够正常启动 优化断开提醒
  REPORT-114391 【微服务适配】远程&本地设计器能够正常启动 优化启动与切换
mss/2.0
Destiny.Lin-林锦龙 5 months ago
parent
commit
ad2491d232
  1. 159
      designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java
  2. 6
      designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java
  3. 5
      designer-chart/src/main/java/com/fr/design/module/ChartPreStyleListPane.java
  4. 2
      designer-realize/src/main/java/com/fanruan/boot/env/function/DesignComponent.java
  5. 8
      designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java

159
designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java

@ -0,0 +1,159 @@
package com.fr.design;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.ui.util.UIUtil;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StableUtils;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceEvent;
import com.fr.workspace.base.WorkspaceConstants;
import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.channel.WorkspaceChannelFactory;
import com.fr.workspace.engine.exception.WorkspaceConnectionException;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/**
* RPC连接处理中心
*
* @author Roger
* @since 11.0
* Created on 2023/12/13
*/
public class RPCConnectHandlerCenter {
private static volatile boolean alerting = false;
private static final int TIMEOUT = 5000;
private static Listener<Workspace> listener = new Listener<Workspace>() {
@Override
public void on(Event event, Workspace workspace) {
//暂时先不做重连处理,3次RPC连接失败后提示切换工作目录
showRPCDisconnectDialog();
}
};
/**
* 开启事件监听
*/
public static void startListener() {
if (!WorkContext.getCurrent().isLocal()) {
EventDispatcher.listen(WorkspaceEvent.LostConnect, listener);
}
}
/**
* 弹窗提示连接断开
*/
public static void showRPCDisconnectDialog() {
UIUtil.invokeLaterIfNeeded(RPCConnectHandlerCenter::showDialog);
}
/**
* RPC连接测试
*
* @param info 连接信息
* @return 是否连接成功
*/
public static boolean checkRPCConnect(WorkspaceConnectionInfo info) {
try {
return WorkspaceChannelFactory.testConnection(info);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, e.getMessage());
return false;
}
}
/**
* http连接检测从DesignerSocketIO中移过来的先保留着
*
* @param info 连接信息
* @return 是否连接成功
*/
public static boolean checkHttpConnect(WorkspaceConnectionInfo info) {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(StableUtils.pathJoin(info.getUrl(), WorkspaceConstants.CONTROLLER_PREFIX, WorkspaceConstants.VT));
RequestConfig requestConfig = RequestConfig
.custom()
.setConnectTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.build();
httpGet.setConfig(requestConfig);
try {
CloseableHttpResponse response = httpclient.execute(httpGet);
if (isErrorStatus(response.getStatusLine().getStatusCode())) {
//这边nginx做负载,服务器被kill掉,返回的是502,不会抛错,导致checkRPCConnect通过
//针对500-600的错误码加个判断,其他类型的状态码暂不考虑,如果有遇到再处理,不然怕影响范围大
throw new WorkspaceConnectionException("Response " + response.getStatusLine().toString());
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, e.getMessage());
return false;
}
return true;
}
/**
* 提示连接已经断开如果已经在提示中了就直接返回
*/
private static void showDialog() {
if (alerting) {
return;
}
synchronized (RPCConnectHandlerCenter.class) {
if (alerting) {
return;
}
alerting = true;
try {
FineJOptionPane.showMessageDialog(
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Remote_Disconnected"),
UIManager.getString("OptionPane.messageDialogTitle"),
JOptionPane.ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon"));
EnvChangeEntrance.getInstance().chooseEnv();
} finally {
alerting = false;
}
}
}
/**
* 错误状态码
* 5xx(服务器错误)这些状态代码表示服务器在尝试处理请求时发生内部错误 这些错误可能是服务器本身的错误而不是请求出错代码 说明
* 500 (服务器内部错误) 服务器遇到错误无法完成请求
* 501 (尚未实施) 服务器不具备完成请求的功能 例如服务器无法识别请求方法时可能会返回此代码
* 502 (错误网关) 服务器作为网关或代理从上游服务器收到无效响应
* 503 (服务不可用) 服务器目前无法使用(由于超载或停机维护) 通常这只是暂时状态
* 504 (网关超时) 服务器作为网关或代理但是没有及时从上游服务器收到请求
* 505 (HTTP 版本不受支持) 服务器不支持请求中所用的 HTTP 协议版本
*
* @param status 错误状态码
* @return 是否是错误状态码
*/
private static boolean isErrorStatus(int status) {
return status >= 500 && status <= 600;
}
/**
* 停止事件监听
*/
public static void stopListener() {
if (!WorkContext.getCurrent().isLocal()) {
EventDispatcher.stopListen(listener);
}
}
}

6
designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java vendored

@ -53,17 +53,21 @@ public class HttpWorkspaceConnector implements WorkspaceConnector {
FineWorkspaceHttpClient client = FineWorkspaceHttpClient.create("Http-Client", connectionInfo);
try {
LoginResponseInfoBean bean = RemoteAuthorityRepository.getInstance().login(createLoginBean(connectionInfo));
// 服务器如果没返回token,肯定是出问题了,直接抛出异常
if (StringUtils.isEmpty(bean.getAccessToken())) {
throw new RuntimeException("Empty token, try connect again and check server");
}
WorkspaceConnection connection = new WorkspaceConnection(
UUID.randomUUID().toString(),
connectionInfo.getUserName(),
HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(),
InetAddress.getLocalHost().getHostAddress());
client.updateConnection(connection);
client.startHeartBeat();
} catch (Exception e) {
client.closePool();
throw e;
}
client.startHeartBeat();
CompatibleRegister.registerCompatibleEnv();
RepositoryManager.getInstance().clearLastPool();
return client;

5
designer-chart/src/main/java/com/fr/design/module/ChartPreStyleListPane.java

@ -118,7 +118,10 @@ public class ChartPreStyleListPane extends JListControlPane {
while (keys.hasNext()) {
Object key = keys.next();
ChartColorMatching value = (ChartColorMatching) config.getPreStyle(key);
// 新配置框架不再使用mirror后 原先mirror的地方需要手动清理下namespace
if(!StringUtils.isEmpty(value.getNameSpace())) {
value.reset();
}
list.add(new NameObject(Utils.objectToString(key), value));
}

2
designer-realize/src/main/java/com/fanruan/boot/env/function/DesignComponent.java vendored

@ -23,6 +23,7 @@ import com.fr.decision.webservice.v10.plugin.helper.category.impl.PluginResource
import com.fr.decision.webservice.v10.plugin.helper.category.impl.UpmResourceLoader;
import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.RPCConnectHandlerCenter;
import com.fr.design.actions.NewFormAction;
import com.fr.design.actions.core.ActionFactory;
import com.fr.design.actions.insert.cell.BiasCellAction;
@ -218,6 +219,7 @@ public class DesignComponent {
DesignerWorkspaceLoader.init();
storePassport();
AlphaFineHelper.switchConfig4Locale();
RPCConnectHandlerCenter.startListener();
RecoverManager.register(new RecoverForDesigner());
}

8
designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java

@ -12,6 +12,7 @@ import com.fanruan.plugin.autonomy.AutonomyClassManagerGroup;
import com.fanruan.product.BuildContext;
import com.fanruan.product.ProductConstants;
import com.fr.base.OptimizeUtil;
import com.fr.concurrent.FineExecutors;
import com.fr.config.dao.DaoSelectorFactory;
import com.fr.config.dao.PropertiesConstants;
import com.fr.decision.service.context.ServiceContext;
@ -74,6 +75,7 @@ import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Set;
import java.util.Timer;
import java.util.concurrent.TimeUnit;
/**
@ -226,6 +228,12 @@ public class DesignPreLoadComponent {
try {
beforeAllStart();
//清空临时文件
FineExecutors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
TmpFileUtils.cleanUpInnerTmpFiles();
}
}, 10, 10, TimeUnit.MINUTES);
Runtime.getRuntime().addShutdownHook(new Thread(TmpFileUtils::cleanUpInnerTmpFiles));
RestartHelper.deleteRecordFilesWhenStart();
CloudCenter.getInstance();

Loading…
Cancel
Save