From e2443d1219cc16748391475519f1ece27d9b82d0 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Tue, 23 Jul 2024 16:57:46 +0800 Subject: [PATCH 1/4] =?UTF-8?q?REPORT-114391=20=E3=80=90=E5=BE=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=80=82=E9=85=8D=E3=80=91=E8=BF=9C=E7=A8=8B&?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E8=AE=BE=E8=AE=A1=E5=99=A8=E8=83=BD=E5=A4=9F?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=90=AF=E5=8A=A8=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E4=B8=8E=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/env/HttpWorkspaceConnector.java | 4 ++++ .../com/fanruan/boot/init/DesignPreLoadComponent.java | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java index 4c4d7c9429..c92d78ad40 100644 --- a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java +++ b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java @@ -53,6 +53,10 @@ 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(), diff --git a/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java b/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java index 744ce4b65c..736aa35096 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java +++ b/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(); From 124ea3970e696b50c88f23c490aa8e72d310f0a2 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Tue, 23 Jul 2024 17:31:56 +0800 Subject: [PATCH 2/4] =?UTF-8?q?REPORT-114391=20=E3=80=90=E5=BE=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=80=82=E9=85=8D=E3=80=91=E8=BF=9C=E7=A8=8B&?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E8=AE=BE=E8=AE=A1=E5=99=A8=E8=83=BD=E5=A4=9F?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=90=AF=E5=8A=A8=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/RPCConnectHandlerCenter.java | 158 ++++++++++++++++++ .../boot/env/function/DesignComponent.java | 2 + 2 files changed, 160 insertions(+) create mode 100644 designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java diff --git a/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java b/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java new file mode 100644 index 0000000000..3a57d661df --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java @@ -0,0 +1,158 @@ +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.*; + +/** + * 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 listener = new Listener() { + @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); + } + } +} diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignComponent.java index d55b4a4fbd..31983dfe88 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignComponent.java @@ -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()); } From 8bdbb3f32943d8d035422beb6c3fdf01df7e7fd1 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Wed, 24 Jul 2024 13:58:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?REPORT-114391=20=E3=80=90=E5=BE=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=80=82=E9=85=8D=E3=80=91=E8=BF=9C=E7=A8=8B&?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E8=AE=BE=E8=AE=A1=E5=99=A8=E8=83=BD=E5=A4=9F?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=90=AF=E5=8A=A8=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E9=85=8D=E7=BD=AE+=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/env/HttpWorkspaceConnector.java | 2 +- .../java/com/fr/design/module/ChartPreStyleListPane.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java index c92d78ad40..572e2f583c 100644 --- a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java +++ b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java @@ -63,11 +63,11 @@ public class HttpWorkspaceConnector implements WorkspaceConnector { 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; diff --git a/designer-chart/src/main/java/com/fr/design/module/ChartPreStyleListPane.java b/designer-chart/src/main/java/com/fr/design/module/ChartPreStyleListPane.java index 06b3eb5028..aa7f02fbac 100644 --- a/designer-chart/src/main/java/com/fr/design/module/ChartPreStyleListPane.java +++ b/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)); } From c3c38e10c928abb834b7982072066658cf3007aa Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Wed, 24 Jul 2024 14:32:40 +0800 Subject: [PATCH 4/4] =?UTF-8?q?REPORT-114391=20=E3=80=90=E5=BE=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=80=82=E9=85=8D=E3=80=91=E8=BF=9C=E7=A8=8B&?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E8=AE=BE=E8=AE=A1=E5=99=A8=E8=83=BD=E5=A4=9F?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=90=AF=E5=8A=A8=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/RPCConnectHandlerCenter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java b/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java index 3a57d661df..eb08789d0d 100644 --- a/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java +++ b/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java @@ -22,7 +22,8 @@ import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.channel.WorkspaceChannelFactory; import com.fr.workspace.engine.exception.WorkspaceConnectionException; -import javax.swing.*; +import javax.swing.JOptionPane; +import javax.swing.UIManager; /** * RPC连接处理中心