From bac9eeda5f3113c17c94230c5ba4b973d4d155c6 Mon Sep 17 00:00:00 2001 From: OTTO <731554297@example.com> Date: Thu, 19 Jun 2025 19:49:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=BF=90=E7=BB=B4=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=A8=A1=E5=9D=97):=20=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9A=E8=8E=B7=E5=8F=96=E5=BE=AE=E6=9C=8D=E5=8A=A1=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=8A=9F=E8=83=BD=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这段代码为每个应用添加“启停管理”功能,设置对应的功能键和名称,并将命名空间和应用名称作为参数存入variables,最后将该功能对象加入功能列表中。 --- .../service/impl/K8SDashboardServiceImpl.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/microservices-modules/microservices-modules-mon/src/main/java/com/microservices/mon/k8s/service/impl/K8SDashboardServiceImpl.java b/microservices-modules/microservices-modules-mon/src/main/java/com/microservices/mon/k8s/service/impl/K8SDashboardServiceImpl.java index 5e5bce71d..c2f78d9ee 100644 --- a/microservices-modules/microservices-modules-mon/src/main/java/com/microservices/mon/k8s/service/impl/K8SDashboardServiceImpl.java +++ b/microservices-modules/microservices-modules-mon/src/main/java/com/microservices/mon/k8s/service/impl/K8SDashboardServiceImpl.java @@ -247,6 +247,15 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo JSONObject applicationJson = remoteRancherService.getK8sApplicationDetail(cluster_id, K8sApplication.getApplicationFullKind(kind), namespace, applicationName, SecurityContextHolder.getUserKey()); RancherApplicationVo rancherApplicationVo = applicationJson.toJavaObject(RancherApplicationVo.class); if (rancherApplicationVo != null && rancherApplicationVo.getMetadata() != null && rancherApplicationVo.getMetadata().getLabels() != null) { + // 所有应用添加启停管理功能 + ApplicationFunction applicationFunction = new ApplicationFunction(); + applicationFunction.setKeyAndName(ApplicationFunctionType.START_AND_STOP_MANAGEMENT); + // 使用命名空间和应用名称作为搜索条件 + JSONObject functionVariables = new JSONObject(); + functionVariables.put("namespace", namespace); + functionVariables.put("applicationName", applicationName); + applicationFunction.setVariables(functionVariables); + applicationFunctionsList.add(applicationFunction); JSONObject LabelsJson = rancherApplicationVo.getMetadata().getLabels(); for (String key : LabelsJson.keySet()) { String k8sLabelValue = LabelsJson.getString(key); @@ -264,9 +273,9 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo for (int i = 0; i < skywalkingServicesArray.size(); i++) { JSONObject skywalkingService = skywalkingServicesArray.getJSONObject(i); if (k8sLabelValue.equals(skywalkingService.getString("shortName"))) { - ApplicationFunction applicationFunction = new ApplicationFunction(); + applicationFunction = new ApplicationFunction(); applicationFunction.setKeyAndName(applicationFunctionType); - JSONObject functionVariables = new JSONObject(); + functionVariables = new JSONObject(); functionVariables.put("serviceId", skywalkingService.getString("id")); applicationFunction.setVariables(functionVariables); applicationFunctionsList.add(applicationFunction); @@ -282,9 +291,9 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo for (int i = 0; i < sentinelAppListArray.size(); i++) { JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i); if (k8sLabelValue.equals(sentinelApp.getString("app"))) { - ApplicationFunction applicationFunction = new ApplicationFunction(); + applicationFunction = new ApplicationFunction(); applicationFunction.setKeyAndName(applicationFunctionType); - JSONObject functionVariables = new JSONObject(); + functionVariables = new JSONObject(); functionVariables.put("app", k8sLabelValue); functionVariables.put("appType", sentinelApp.getLongValue("appType")); applicationFunction.setVariables(functionVariables); @@ -301,9 +310,9 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo for (int i = 0; i < nacosServiceListArray.size(); i++) { JSONObject nacosService = nacosServiceListArray.getJSONObject(i); if (k8sLabelValue.equals(nacosService.getString("name"))) { - ApplicationFunction applicationFunction = new ApplicationFunction(); + applicationFunction = new ApplicationFunction(); applicationFunction.setKeyAndName(applicationFunctionType); - JSONObject functionVariables = new JSONObject(); + functionVariables = new JSONObject(); functionVariables.put("name", k8sLabelValue); applicationFunction.setVariables(functionVariables); applicationFunctionsList.add(applicationFunction); @@ -320,9 +329,9 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo JSONObject nacosService = nacosConfigListJSONArray.getJSONObject(i); String dataId = nacosService.getString("dataId"); if (StringUtils.isNotEmpty(dataId) && dataId.contains(k8sLabelValue)) { - ApplicationFunction applicationFunction = new ApplicationFunction(); + applicationFunction = new ApplicationFunction(); applicationFunction.setKeyAndName(applicationFunctionType); - JSONObject functionVariables = new JSONObject(); + functionVariables = new JSONObject(); functionVariables.put("dataId", dataId); applicationFunction.setVariables(functionVariables); applicationFunctionsList.add(applicationFunction);