forked from Gitlink/microservices
parent
ddb1a06acc
commit
d0fcf1fbce
|
|
@ -10,7 +10,7 @@ import com.microservices.mon.k8s.domain.vo.*;
|
|||
import com.microservices.mon.k8s.service.IK8sDashboardService;
|
||||
import com.microservices.mon.k8s.service.IMonCommonAsyncService;
|
||||
import com.microservices.mon.k8s.utils.PromQLConstant;
|
||||
import com.microservices.mon.k8s.utils.RancherFeignUtils;
|
||||
import com.microservices.mon.k8s.utils.RancherResponseHandler;
|
||||
import com.microservices.mon.k8s.utils.SkywalkingGQLConstant;
|
||||
import com.microservices.system.api.RemoteGatewayService;
|
||||
import com.microservices.system.api.RemoteRancherService;
|
||||
|
|
@ -39,7 +39,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
|
|||
public List<K8sClusterNode> getClusterNodeList() {
|
||||
List<RancherClusterNodeVo> rancherClusterNodeVoList;
|
||||
//调用rancher远程接口获取集群节点列表
|
||||
JSONObject clusterNodeJsonObject = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sClusterNodeList(cluster_id, SecurityContextHolder.getUserKey()), "获取K8S集群节点");
|
||||
JSONObject clusterNodeJsonObject = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sClusterNodeList(cluster_id, SecurityContextHolder.getUserKey()), "获取K8S集群节点");
|
||||
if (clusterNodeJsonObject != null && clusterNodeJsonObject.containsKey("data")) {
|
||||
rancherClusterNodeVoList = clusterNodeJsonObject.getJSONArray("data").toList(RancherClusterNodeVo.class);
|
||||
return rancherClusterNodeVoList.stream().map(RancherClusterNodeVo::toK8sClusterNode).collect(Collectors.toList());
|
||||
|
|
@ -50,7 +50,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
|
|||
@Override
|
||||
public List<String> getApplicationPodIdList(String kind, String namespace, String applicationName) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
JSONObject applicationJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
JSONObject applicationJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
RancherApplicationVo rancherApplicationVo = applicationJson.toJavaObject(RancherApplicationVo.class);
|
||||
if (rancherApplicationVo != null && rancherApplicationVo.getMetadata() != null && rancherApplicationVo.getMetadata().getRelationships() != null) {
|
||||
JSONArray relationships = rancherApplicationVo.getMetadata().getRelationships();
|
||||
|
|
@ -60,7 +60,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
|
|||
String selector = relationship.getString("selector");
|
||||
if (StringUtils.isNotEmpty(selector) && selector.contains("app=")) {
|
||||
String appName = selector.substring(selector.indexOf("=") + 1);
|
||||
JSONObject podListJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sPodListByNamespace(cluster_id, namespace, SecurityContextHolder.getUserKey()), "获取容器列表");
|
||||
JSONObject podListJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sPodListByNamespace(cluster_id, namespace, SecurityContextHolder.getUserKey()), "获取容器列表");
|
||||
if (podListJson != null && podListJson.containsKey("data")) {
|
||||
List<RancherPodVo> rancherPodVoList = podListJson.getJSONArray("data").toList(RancherPodVo.class);
|
||||
List<RancherPodVo> applicationToPodList = rancherPodVoList.stream()
|
||||
|
|
@ -105,7 +105,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
|
|||
public List<ApplicationRequestCountData> getApplicationRequestCount() {
|
||||
List<ApplicationRequestCountData> applicationRequestCountDataList = new ArrayList<>();
|
||||
HashMap<String, String> portMap = new HashMap<>();
|
||||
JSONObject nginxSvcJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sServiceByApplicationId(cluster_id, nginxApplicationId, SecurityContextHolder.getUserKey()), "获取统一请求入口服务");
|
||||
JSONObject nginxSvcJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sServiceByApplicationId(cluster_id, nginxApplicationId, SecurityContextHolder.getUserKey()), "获取统一请求入口服务");
|
||||
if (nginxSvcJson != null) {
|
||||
RancherServiceVo rancherServiceVo = nginxSvcJson.toJavaObject(RancherServiceVo.class);
|
||||
for (RancherServicePortsVo rancherServicePortsVo : rancherServiceVo.getSpec().getPorts()) {
|
||||
|
|
@ -186,7 +186,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
|
|||
public List<ApplicationFunction> getApplicationFunction(String kind, String namespace, String applicationName, String podIpList) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
List<ApplicationFunction> applicationFunctionsList = new ArrayList<>();
|
||||
JSONObject applicationJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
JSONObject applicationJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
if (applicationJson == null) {
|
||||
return applicationFunctionsList;
|
||||
}
|
||||
|
|
@ -334,7 +334,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
|
|||
List<K8sNamespace> k8sNamespaceList = new ArrayList<>();
|
||||
List<RancherNamespaceVo> rancherNamespaceVoList;
|
||||
//调用rancher远程接口获取所有命名空间列表
|
||||
JSONObject namespaceJsonObject = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sNamespaceList(cluster_id, SecurityContextHolder.getUserKey()), "获取K8S命名空间列表");
|
||||
JSONObject namespaceJsonObject = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sNamespaceList(cluster_id, SecurityContextHolder.getUserKey()), "获取K8S命名空间列表");
|
||||
if (namespaceJsonObject != null && namespaceJsonObject.containsKey("data")) {
|
||||
rancherNamespaceVoList = namespaceJsonObject.getJSONArray("data").toList(RancherNamespaceVo.class);
|
||||
for (RancherNamespaceVo rancherNamespaceVo : rancherNamespaceVoList) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package com.microservices.mon.k8s.service.impl;
|
||||
|
||||
import com.alibaba.cloud.commons.io.IOUtils;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.context.SecurityContextHolder;
|
||||
|
|
@ -11,8 +9,7 @@ import com.microservices.mon.k8s.domain.*;
|
|||
import com.microservices.mon.k8s.domain.vo.*;
|
||||
import com.microservices.mon.k8s.service.IMicroManagementService;
|
||||
import com.microservices.mon.k8s.service.IMonCommonAsyncService;
|
||||
import com.microservices.mon.k8s.utils.MonUtils;
|
||||
import com.microservices.mon.k8s.utils.RancherFeignUtils;
|
||||
import com.microservices.mon.k8s.utils.RancherResponseHandler;
|
||||
import com.microservices.system.api.RemoteRancherService;
|
||||
import com.microservices.system.api.utils.FeignUtils;
|
||||
import feign.Response;
|
||||
|
|
@ -20,8 +17,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -48,7 +43,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
public K8sApplication getApplicationDetail(String kind, String namespace, String applicationName) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
K8sApplication k8sApplication = new K8sApplication();
|
||||
JSONObject applicationJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
JSONObject applicationJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
if (applicationJson == null) {
|
||||
return k8sApplication;
|
||||
}
|
||||
|
|
@ -70,14 +65,14 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
deletePodBody.put("gracePeriod", 0);
|
||||
}
|
||||
try (Response response = remoteRancherService.deletePod(namespace, podName, deletePodBody, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "删除容器");
|
||||
return RancherResponseHandler.handleBoolean(response, "删除容器");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<K8sApplicationPod> getK8sApplicationPodList(K8sApplication k8sApplication) {
|
||||
// 获取命名空间下pod列表
|
||||
JSONObject podListJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sPodListByNamespace(cluster_id, k8sApplication.getNamespace(), SecurityContextHolder.getUserKey()), "获取应用下容器列表");
|
||||
JSONObject podListJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sPodListByNamespace(cluster_id, k8sApplication.getNamespace(), SecurityContextHolder.getUserKey()), "获取应用下容器列表");
|
||||
List<RancherPodVo> rancherPodVoList;
|
||||
if (podListJson != null && podListJson.containsKey("data")) {
|
||||
rancherPodVoList = podListJson.getJSONArray("data").toList(RancherPodVo.class);
|
||||
|
|
@ -107,7 +102,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
if ("DaemonSet".equals(kind) && !applicationStartAndStopType.getIsDaemonSetOperation()) {
|
||||
throw new ServiceException("该应用操作类型不支持(操作类型[%s])", operationKey);
|
||||
}
|
||||
JSONObject applicationDetailJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
JSONObject applicationDetailJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
if (applicationDetailJson == null || !applicationDetailJson.containsKey("metadata") || !applicationDetailJson.containsKey("spec")) {
|
||||
throw new ServiceException("该应用不存在或应用数据异常(应用类型[%s],命名空间[%s],应用名称[%s],)", kind, namespace, applicationName);
|
||||
}
|
||||
|
|
@ -134,13 +129,13 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
}
|
||||
applicationSpecJson.put("replicas", 1);
|
||||
try (Response response = remoteRancherService.updateK8sApplication(applicationType.getFullName(), namespace, applicationName, applicationDetailJson, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
case STOP: {
|
||||
applicationSpecJson.put("replicas", 0);
|
||||
try (Response response = remoteRancherService.updateK8sApplication(applicationType.getFullName(), namespace, applicationName, applicationDetailJson, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
case FORCE_STOP: {
|
||||
|
|
@ -161,7 +156,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
}
|
||||
return delPodSuccess;
|
||||
}
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
case RESTART: {
|
||||
|
|
@ -193,7 +188,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
applicationDetailJson.put("spec", applicationSpecJson);
|
||||
applicationDetailJson.put("metadata", metadataJson);
|
||||
try (Response response = remoteRancherService.updateK8sApplication(applicationType.getFullName(), namespace, applicationName, applicationDetailJson, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,14 +198,14 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
applicationSpecJson.put("paused", true);
|
||||
applicationDetailJson.put("spec", applicationSpecJson);
|
||||
try (Response response = remoteRancherService.updateK8sApplication(applicationType.getFullName(), namespace, applicationName, applicationDetailJson, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
case RESUME: {
|
||||
applicationSpecJson.put("paused", false);
|
||||
applicationDetailJson.put("spec", applicationSpecJson);
|
||||
try (Response response = remoteRancherService.updateK8sApplication(applicationType.getFullName(), namespace, applicationName, applicationDetailJson, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -234,21 +229,21 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
public Boolean createApplication(String kind, String yamlContent) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
try (Response response = remoteRancherService.createK8sApplication(applicationType.getFullName(), yamlContent, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getApplicationYamlFile(String kind, String namespace, String applicationName) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
return RancherFeignUtils.getResponseBody(remoteRancherService.getApplicationYamlFile(applicationType.getName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用yaml文件");
|
||||
return RancherResponseHandler.handleJsonObject(remoteRancherService.getApplicationYamlFile(applicationType.getName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用yaml文件");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean editApplication(String kind, String namespace, String applicationName, String yamlContent) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
try (Response response = remoteRancherService.editK8sApplication(applicationType.getFullName(), namespace, applicationName, yamlContent, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -256,7 +251,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
public Boolean deleteApplication(String kind, String namespace, String applicationName) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
try (Response response = remoteRancherService.deleteApplication(applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +259,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
public List<K8sApplicationEnv> getApplicationEnv(String kind, String namespace, String applicationName) {
|
||||
List<K8sApplicationEnv> envList = new ArrayList<>();
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
JSONObject applicationJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
JSONObject applicationJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
if (applicationJson == null) {
|
||||
return envList;
|
||||
}
|
||||
|
|
@ -305,7 +300,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
@Override
|
||||
public List<K8sApplicationEnvOptionalParameter> getEnvOptionalParameters(String namespace) {
|
||||
List<K8sApplicationEnvOptionalParameter> envOptionalParametersList = new ArrayList<>();
|
||||
JSONObject configmapJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sConfigmapByNamespace(namespace, SecurityContextHolder.getUserKey()), "获取命名空间下所有ConfigMap");
|
||||
JSONObject configmapJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sConfigmapByNamespace(namespace, SecurityContextHolder.getUserKey()), "获取命名空间下所有ConfigMap");
|
||||
if (configmapJson != null && configmapJson.containsKey("data")) {
|
||||
JSONArray dataJsonArray = configmapJson.getJSONArray("data");
|
||||
for (int i = 0; i < dataJsonArray.size(); i++) {
|
||||
|
|
@ -327,7 +322,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
}
|
||||
}
|
||||
}
|
||||
JSONObject secretJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sSecretByNamespace(namespace, SecurityContextHolder.getUserKey()), "获取命名空间下所有Secret");
|
||||
JSONObject secretJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sSecretByNamespace(namespace, SecurityContextHolder.getUserKey()), "获取命名空间下所有Secret");
|
||||
if (secretJson != null && secretJson.containsKey("data")) {
|
||||
JSONArray dataJsonArray = secretJson.getJSONArray("data");
|
||||
for (int i = 0; i < dataJsonArray.size(); i++) {
|
||||
|
|
@ -369,7 +364,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
@Override
|
||||
public Boolean updateApplicationEnv(String kind, String namespace, String applicationName, List<K8sApplicationEnv> k8sApplicationEnvList) {
|
||||
ApplicationType applicationType = ApplicationType.getApplicationTypeByKey(kind);
|
||||
JSONObject applicationDetailJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
JSONObject applicationDetailJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sApplicationDetail(cluster_id, applicationType.getFullName(), namespace, applicationName, SecurityContextHolder.getUserKey()), "获取应用详情");
|
||||
if (applicationDetailJson == null || !applicationDetailJson.containsKey("spec")) {
|
||||
throw new ServiceException("该应用不存在或应用数据异常(应用类型[%s],命名空间[%s],应用名称[%s],)", kind, namespace, applicationName);
|
||||
}
|
||||
|
|
@ -398,7 +393,7 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
|
||||
|
||||
try (Response response = remoteRancherService.updateK8sApplication(applicationType.getFullName(), namespace, applicationName, applicationDetailJson, SecurityContextHolder.getUserKey())) {
|
||||
return RancherFeignUtils.disposeRancherErrorMsg(response, "启动应用");
|
||||
return RancherResponseHandler.handleBoolean(response, "启动应用");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.microservices.mon.k8s.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.context.SecurityContextHolder;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
|
|
@ -12,7 +11,7 @@ import com.microservices.mon.k8s.service.IK8sDashboardService;
|
|||
import com.microservices.mon.k8s.service.IMonCommonAsyncService;
|
||||
import com.microservices.mon.k8s.utils.CustomExecutorFactory;
|
||||
import com.microservices.mon.k8s.utils.PromQLConstant;
|
||||
import com.microservices.mon.k8s.utils.RancherFeignUtils;
|
||||
import com.microservices.mon.k8s.utils.RancherResponseHandler;
|
||||
import com.microservices.system.api.RemoteGatewayService;
|
||||
import com.microservices.system.api.RemoteRancherService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -135,7 +134,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
|
|||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
try {
|
||||
//调用rancher远程接口获取所有daemonsets列表
|
||||
JSONObject daemonsetsJsonObject = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sDaemonsetsList(cluster_id, SecurityContextHolder.getUserKey()), "获取DaemonSet类型应用");
|
||||
JSONObject daemonsetsJsonObject = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sDaemonsetsList(cluster_id, SecurityContextHolder.getUserKey()), "获取DaemonSet类型应用");
|
||||
if (daemonsetsJsonObject != null && daemonsetsJsonObject.containsKey("data")) {
|
||||
rancherApplicationVoList.addAll(daemonsetsJsonObject.getJSONArray("data").toList(RancherApplicationVo.class));
|
||||
}
|
||||
|
|
@ -146,7 +145,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
|
|||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
try {
|
||||
//调用rancher远程接口获取所有deploy列表
|
||||
JSONObject deployJsonObject = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sDeployList(cluster_id, SecurityContextHolder.getUserKey()), "获取Deploy类型应用");
|
||||
JSONObject deployJsonObject = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sDeployList(cluster_id, SecurityContextHolder.getUserKey()), "获取Deploy类型应用");
|
||||
if (deployJsonObject != null && deployJsonObject.containsKey("data")) {
|
||||
rancherApplicationVoList.addAll(deployJsonObject.getJSONArray("data").toList(RancherApplicationVo.class));
|
||||
}
|
||||
|
|
@ -157,7 +156,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
|
|||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
try {
|
||||
//调用rancher远程接口获取所有Stateful列表
|
||||
JSONObject statefulJsonObject = RancherFeignUtils.getResponseBody(remoteRancherService
|
||||
JSONObject statefulJsonObject = RancherResponseHandler.handleJsonObject(remoteRancherService
|
||||
.getK8sStatefulList(cluster_id, SecurityContextHolder.getUserKey()), "获取StatefulSet类型应用");
|
||||
if (statefulJsonObject != null && statefulJsonObject.containsKey("data")) {
|
||||
rancherApplicationVoList.addAll(statefulJsonObject.getJSONArray("data").toList(RancherApplicationVo.class));
|
||||
|
|
@ -196,7 +195,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
|
|||
.collect(Collectors.toList());
|
||||
if (needPod) {
|
||||
// 获取命名空间下pod列表
|
||||
JSONObject podListJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sPodListByNamespace(cluster_id, k8sNamespace.getName(), SecurityContextHolder.getUserKey()), "获取容器列表");
|
||||
JSONObject podListJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sPodListByNamespace(cluster_id, k8sNamespace.getName(), SecurityContextHolder.getUserKey()), "获取容器列表");
|
||||
List<RancherPodVo> rancherPodVoList;
|
||||
if (podListJson != null && podListJson.containsKey("data")) {
|
||||
rancherPodVoList = podListJson.getJSONArray("data").toList(RancherPodVo.class);
|
||||
|
|
@ -248,7 +247,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
|
|||
try {
|
||||
K8sNamespace k8sNamespace = k8sNamespaceList.get(finalI);
|
||||
// 获取命名空间下pod列表
|
||||
JSONObject podListJson = RancherFeignUtils.getResponseBody(remoteRancherService.getK8sPodListByNamespace(cluster_id, k8sNamespace.getName(), SecurityContextHolder.getUserKey()), "获取容器列表");
|
||||
JSONObject podListJson = RancherResponseHandler.handleJsonObject(remoteRancherService.getK8sPodListByNamespace(cluster_id, k8sNamespace.getName(), SecurityContextHolder.getUserKey()), "获取容器列表");
|
||||
|
||||
if (podListJson != null && podListJson.containsKey("data")) {
|
||||
List<RancherPodVo> rancherPodVoList = podListJson.getJSONArray("data").toList(RancherPodVo.class);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.microservices.mon.k8s.utils;
|
|||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.DateUtils;
|
||||
import com.microservices.system.api.utils.FeignUtils;
|
||||
import feign.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -10,12 +9,11 @@ import org.apache.commons.io.IOUtils;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
public class RancherFeignUtils {
|
||||
public class RancherResponseHandler {
|
||||
|
||||
public static JSONObject getResponseBody(Response response, String functionName) {
|
||||
public static JSONObject handleJsonObject(Response response, String functionName) {
|
||||
Response.Body body = response.body();
|
||||
if (body != null) {
|
||||
try {
|
||||
|
|
@ -36,8 +34,8 @@ public class RancherFeignUtils {
|
|||
}
|
||||
|
||||
|
||||
public static Boolean disposeRancherErrorMsg(Response response, String functionName) {
|
||||
JSONObject bodyJson = getResponseBody(response, functionName);
|
||||
public static Boolean handleBoolean(Response response, String functionName) {
|
||||
JSONObject bodyJson = handleJsonObject(response, functionName);
|
||||
return bodyJson != null;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue