From 92bfd2c7f29dd6444cc5adbdc70e40a2e9a67f8e Mon Sep 17 00:00:00 2001 From: OTTO <731554297@example.com> Date: Tue, 22 Jul 2025 16:54:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=BF=90=E7=BB=B4=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=A8=A1=E5=9D=97):=20=E5=AE=8C=E5=96=84=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 修复当应用没有标签时无法获取启停功能的bug --- .../service/impl/K8SDashboardServiceImpl.java | 152 +++++++++--------- 1 file changed, 77 insertions(+), 75 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 f08d5248b..1ade2fa52 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 @@ -190,7 +190,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo return applicationFunctionsList; } RancherApplicationVo rancherApplicationVo = applicationJson.toJavaObject(RancherApplicationVo.class); - if (rancherApplicationVo != null && rancherApplicationVo.getMetadata() != null && rancherApplicationVo.getMetadata().getLabels() != null) { + if (rancherApplicationVo != null) { K8sApplication k8sApplication = rancherApplicationVo.toK8sApplication(); // 所有应用添加启停管理功能 ApplicationFunction applicationFunction = new ApplicationFunction(); @@ -233,92 +233,94 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo } - JSONObject LabelsJson = rancherApplicationVo.getMetadata().getLabels(); - for (String key : LabelsJson.keySet()) { - String k8sLabelValue = LabelsJson.getString(key); - ApplicationFunctionType applicationFunctionType = ApplicationFunctionType.getByLabelsKey(key); - if (applicationFunctionType != null) { - switch (applicationFunctionType) { - case LINK_TRACKING: - // 处理应用链路追踪功能相关逻辑 - GraphqlQueryVo gqlQueryVo = SkywalkingGQLConstant.getAllServicesByGroup(skywalkingGroup); - JSONObject skywalkingServices = remoteGatewayService.executeSkywalkingGql(gqlQueryVo); - if (skywalkingServices != null - && skywalkingServices.getJSONObject("data") != null - && skywalkingServices.getJSONObject("data").getJSONArray(gqlQueryVo.getOperationName()) != null) { - JSONArray skywalkingServicesArray = skywalkingServices.getJSONObject("data").getJSONArray(gqlQueryVo.getOperationName()); - for (int i = 0; i < skywalkingServicesArray.size(); i++) { - JSONObject skywalkingService = skywalkingServicesArray.getJSONObject(i); - if (k8sLabelValue.equals(skywalkingService.getString("shortName"))) { - applicationFunction = new ApplicationFunction(); - applicationFunction.setKeyAndName(applicationFunctionType); - functionVariables = new JSONObject(); - functionVariables.put("serviceId", skywalkingService.getString("id")); - applicationFunction.setVariables(functionVariables); - applicationFunctionsList.add(applicationFunction); - } - } - } - break; - case FLOW_CONTROL: - // 处理应用流量控制功能相关逻辑 - JSONObject sentinelAppList = remoteGatewayService.getSentinelAppList(SecurityContextHolder.getUserKey()); - if (sentinelAppList != null && sentinelAppList.containsKey("success") && sentinelAppList.getBoolean("success")) { - JSONArray sentinelAppListArray = sentinelAppList.getJSONArray("data"); - if (sentinelAppListArray != null && !sentinelAppList.getJSONArray("data").isEmpty()) { - for (int i = 0; i < sentinelAppListArray.size(); i++) { - JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i); - if (k8sLabelValue.equals(sentinelApp.getString("app"))) { + if (rancherApplicationVo.getMetadata() != null && rancherApplicationVo.getMetadata().getLabels() != null) { + JSONObject LabelsJson = rancherApplicationVo.getMetadata().getLabels(); + for (String key : LabelsJson.keySet()) { + String k8sLabelValue = LabelsJson.getString(key); + ApplicationFunctionType applicationFunctionType = ApplicationFunctionType.getByLabelsKey(key); + if (applicationFunctionType != null) { + switch (applicationFunctionType) { + case LINK_TRACKING: + // 处理应用链路追踪功能相关逻辑 + GraphqlQueryVo gqlQueryVo = SkywalkingGQLConstant.getAllServicesByGroup(skywalkingGroup); + JSONObject skywalkingServices = remoteGatewayService.executeSkywalkingGql(gqlQueryVo); + if (skywalkingServices != null + && skywalkingServices.getJSONObject("data") != null + && skywalkingServices.getJSONObject("data").getJSONArray(gqlQueryVo.getOperationName()) != null) { + JSONArray skywalkingServicesArray = skywalkingServices.getJSONObject("data").getJSONArray(gqlQueryVo.getOperationName()); + for (int i = 0; i < skywalkingServicesArray.size(); i++) { + JSONObject skywalkingService = skywalkingServicesArray.getJSONObject(i); + if (k8sLabelValue.equals(skywalkingService.getString("shortName"))) { applicationFunction = new ApplicationFunction(); applicationFunction.setKeyAndName(applicationFunctionType); functionVariables = new JSONObject(); - functionVariables.put("app", k8sLabelValue); - functionVariables.put("appType", sentinelApp.getLongValue("appType")); + functionVariables.put("serviceId", skywalkingService.getString("id")); applicationFunction.setVariables(functionVariables); applicationFunctionsList.add(applicationFunction); } } } - } - break; - case REGISTRATION_CENTER: - // 处理应用注册中心功能相关逻辑 - JSONObject nacosServiceList = remoteGatewayService.getNacosServiceList(k8sLabelValue, SecurityContextHolder.getUserKey()); - if (nacosServiceList != null && nacosServiceList.getJSONArray("serviceList") != null && !nacosServiceList.getJSONArray("serviceList").isEmpty()) { - JSONArray nacosServiceListArray = nacosServiceList.getJSONArray("serviceList"); - for (int i = 0; i < nacosServiceListArray.size(); i++) { - JSONObject nacosService = nacosServiceListArray.getJSONObject(i); - if (k8sLabelValue.equals(nacosService.getString("name"))) { - applicationFunction = new ApplicationFunction(); - applicationFunction.setKeyAndName(applicationFunctionType); - functionVariables = new JSONObject(); - functionVariables.put("name", k8sLabelValue); - applicationFunction.setVariables(functionVariables); - applicationFunctionsList.add(applicationFunction); + break; + case FLOW_CONTROL: + // 处理应用流量控制功能相关逻辑 + JSONObject sentinelAppList = remoteGatewayService.getSentinelAppList(SecurityContextHolder.getUserKey()); + if (sentinelAppList != null && sentinelAppList.containsKey("success") && sentinelAppList.getBoolean("success")) { + JSONArray sentinelAppListArray = sentinelAppList.getJSONArray("data"); + if (sentinelAppListArray != null && !sentinelAppList.getJSONArray("data").isEmpty()) { + for (int i = 0; i < sentinelAppListArray.size(); i++) { + JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i); + if (k8sLabelValue.equals(sentinelApp.getString("app"))) { + applicationFunction = new ApplicationFunction(); + applicationFunction.setKeyAndName(applicationFunctionType); + functionVariables = new JSONObject(); + functionVariables.put("app", k8sLabelValue); + functionVariables.put("appType", sentinelApp.getLongValue("appType")); + applicationFunction.setVariables(functionVariables); + applicationFunctionsList.add(applicationFunction); + } + } } } - } - break; - case GATEWAY_MANAGEMENT: - // 处理应用网关管理功能相关逻辑 - JSONObject nacosGatewayConfigList = remoteGatewayService.getGatewayNacosConfigList(String.format("*%s*", k8sLabelValue), SecurityContextHolder.getUserKey()); - if (nacosGatewayConfigList != null && nacosGatewayConfigList.getJSONArray("pageItems") != null && !nacosGatewayConfigList.getJSONArray("pageItems").isEmpty()) { - JSONArray nacosConfigListJSONArray = nacosGatewayConfigList.getJSONArray("pageItems"); - for (int i = 0; i < nacosConfigListJSONArray.size(); i++) { - JSONObject nacosService = nacosConfigListJSONArray.getJSONObject(i); - String dataId = nacosService.getString("dataId"); - if (StringUtils.isNotEmpty(dataId) && dataId.contains(k8sLabelValue)) { - applicationFunction = new ApplicationFunction(); - applicationFunction.setKeyAndName(applicationFunctionType); - functionVariables = new JSONObject(); - functionVariables.put("dataId", dataId); - functionVariables.put("group", nacosService.getString("group")); - applicationFunction.setVariables(functionVariables); - applicationFunctionsList.add(applicationFunction); + break; + case REGISTRATION_CENTER: + // 处理应用注册中心功能相关逻辑 + JSONObject nacosServiceList = remoteGatewayService.getNacosServiceList(k8sLabelValue, SecurityContextHolder.getUserKey()); + if (nacosServiceList != null && nacosServiceList.getJSONArray("serviceList") != null && !nacosServiceList.getJSONArray("serviceList").isEmpty()) { + JSONArray nacosServiceListArray = nacosServiceList.getJSONArray("serviceList"); + for (int i = 0; i < nacosServiceListArray.size(); i++) { + JSONObject nacosService = nacosServiceListArray.getJSONObject(i); + if (k8sLabelValue.equals(nacosService.getString("name"))) { + applicationFunction = new ApplicationFunction(); + applicationFunction.setKeyAndName(applicationFunctionType); + functionVariables = new JSONObject(); + functionVariables.put("name", k8sLabelValue); + applicationFunction.setVariables(functionVariables); + applicationFunctionsList.add(applicationFunction); + } } } - } - break; + break; + case GATEWAY_MANAGEMENT: + // 处理应用网关管理功能相关逻辑 + JSONObject nacosGatewayConfigList = remoteGatewayService.getGatewayNacosConfigList(String.format("*%s*", k8sLabelValue), SecurityContextHolder.getUserKey()); + if (nacosGatewayConfigList != null && nacosGatewayConfigList.getJSONArray("pageItems") != null && !nacosGatewayConfigList.getJSONArray("pageItems").isEmpty()) { + JSONArray nacosConfigListJSONArray = nacosGatewayConfigList.getJSONArray("pageItems"); + for (int i = 0; i < nacosConfigListJSONArray.size(); i++) { + JSONObject nacosService = nacosConfigListJSONArray.getJSONObject(i); + String dataId = nacosService.getString("dataId"); + if (StringUtils.isNotEmpty(dataId) && dataId.contains(k8sLabelValue)) { + applicationFunction = new ApplicationFunction(); + applicationFunction.setKeyAndName(applicationFunctionType); + functionVariables = new JSONObject(); + functionVariables.put("dataId", dataId); + functionVariables.put("group", nacosService.getString("group")); + applicationFunction.setVariables(functionVariables); + applicationFunctionsList.add(applicationFunction); + } + } + } + break; + } } } }