From 3ab7ad484a2be9ad9d632ea8147d2ba30814d077 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AE=89=E6=B5=A9=E6=B5=A9?= <1036606149@qq.com>
Date: Fri, 14 Feb 2025 09:34:25 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?=
=?UTF-8?q?=E3=80=91IoT:=20=E5=A2=9E=E5=BC=BA=E6=8F=92=E4=BB=B6=E5=90=AF?=
=?UTF-8?q?=E5=8A=A8=E5=92=8C=E5=81=9C=E6=AD=A2=E9=80=BB=E8=BE=91=EF=BC=8C?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=EF=BC=8C?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=94=99=E8=AF=AF=E7=A0=81=EF=BC=8C=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../module/iot/enums/ErrorCodeConstants.java | 2 ++
yudao-module-iot/yudao-module-iot-biz/pom.xml | 16 ++++-----
.../plugin/IotPluginInstanceServiceImpl.java | 14 ++++++--
.../yudao-module-iot-plugin-http/pom.xml | 34 +++++++++++++++----
.../http/config/IotHttpVertxPlugin.java | 21 ++++--------
5 files changed, 56 insertions(+), 31 deletions(-)
diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
index e85d4b368f..cd065aaf52 100644
--- a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
+++ b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
@@ -46,6 +46,8 @@ public interface ErrorCodeConstants {
ErrorCode PLUGIN_CONFIG_DELETE_FAILED_RUNNING = new ErrorCode(1_050_006_003, "请先停止插件");
ErrorCode PLUGIN_STATUS_INVALID = new ErrorCode(1_050_006_004, "插件状态无效");
ErrorCode PLUGIN_CONFIG_KEY_DUPLICATE = new ErrorCode(1_050_006_005, "插件标识已存在");
+ ErrorCode PLUGIN_START_FAILED = new ErrorCode(1_050_006_006, "插件启动失败");
+ ErrorCode PLUGIN_STOP_FAILED = new ErrorCode(1_050_006_007, "插件停止失败");
// ========== 插件实例 1-050-007-000 ==========
diff --git a/yudao-module-iot/yudao-module-iot-biz/pom.xml b/yudao-module-iot/yudao-module-iot-biz/pom.xml
index 6f01e33191..780817848b 100644
--- a/yudao-module-iot/yudao-module-iot-biz/pom.xml
+++ b/yudao-module-iot/yudao-module-iot-biz/pom.xml
@@ -65,16 +65,16 @@
-
- io.vertx
- vertx-web
-
+
+
+
+
-
- org.eclipse.paho
- org.eclipse.paho.client.mqttv3
-
+
+
+
+
org.pf4j
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java
index 8c9973a703..3c15ff774b 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java
@@ -191,13 +191,23 @@ public class IotPluginInstanceServiceImpl implements IotPluginInstanceService {
// 启动插件
if (status.equals(IotPluginStatusEnum.RUNNING.getStatus())
&& plugin.getPluginState() != PluginState.STARTED) {
- pluginManager.startPlugin(pluginKey);
+ try {
+ pluginManager.startPlugin(pluginKey);
+ } catch (Exception e) {
+ log.error("[updatePluginStatus][启动插件({}) 失败]", pluginKey, e);
+ throw exception(ErrorCodeConstants.PLUGIN_START_FAILED, e);
+ }
log.info("已启动插件: {}", pluginKey);
}
// 停止插件
else if (status.equals(IotPluginStatusEnum.STOPPED.getStatus())
&& plugin.getPluginState() == PluginState.STARTED) {
- pluginManager.stopPlugin(pluginKey);
+ try {
+ pluginManager.stopPlugin(pluginKey);
+ } catch (Exception e) {
+ log.error("[updatePluginStatus][停止插件({}) 失败]", pluginKey, e);
+ throw exception(ErrorCodeConstants.PLUGIN_STOP_FAILED, e);
+ }
log.info("已停止插件: {}", pluginKey);
}
}
diff --git a/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml b/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml
index 0f7e092f0d..88a413ca67 100644
--- a/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml
+++ b/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml
@@ -94,6 +94,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -112,12 +140,6 @@
-
- maven-deploy-plugin
-
- true
-
-
diff --git a/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java b/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java
index fe789af52d..ac9a933401 100644
--- a/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java
+++ b/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java
@@ -59,22 +59,13 @@ public class IotHttpVertxPlugin extends SpringPlugin {
@Override
protected ApplicationContext createApplicationContext() {
- // TODO @haohao:这个加 deviceDataApi 的目的是啥呀?
- AnnotationConfigApplicationContext pluginContext = new AnnotationConfigApplicationContext() {
-
- @Override
- protected void prepareRefresh() {
- // 在刷新容器前注册主程序中的 Bean
- ConfigurableListableBeanFactory beanFactory = this.getBeanFactory();
- IotDeviceUpstreamApi deviceDataApi = SpringUtil.getBean(IotDeviceUpstreamApi.class);
- beanFactory.registerSingleton("deviceDataApi", deviceDataApi);
- super.prepareRefresh();
- }
-
- };
-
+ // 创建插件自己的 ApplicationContext
+ AnnotationConfigApplicationContext pluginContext = new AnnotationConfigApplicationContext();
+ // 设置父容器为主应用的 ApplicationContext (确保主应用中提供的类可用)
+ pluginContext.setParent(SpringUtil.getApplicationContext());
+ // 继续使用插件自己的 ClassLoader 以加载插件内部的类
pluginContext.setClassLoader(getWrapper().getPluginClassLoader());
- // TODO @芋艿:枚举
+ // 扫描当前插件的自动配置包
pluginContext.scan("cn.iocoder.yudao.module.iot.plugin.http.config");
pluginContext.refresh();
return pluginContext;