forked from Gitlink/microservices
Merge pull request '新增Pod删除接口' (#934) from otto/microservices:dev_monitoring into dev_monitoring
This commit is contained in:
commit
4fd5c1cc4d
|
|
@ -63,4 +63,10 @@ public interface RemoteRancherService {
|
|||
JSONObject getK8sServiceByApplicationId(@PathVariable("cluster_id") String cluster_id,
|
||||
@PathVariable("nginxApplicationId") String nginxApplicationId,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@DeleteMapping("/rancher/v1/pods/{namespace}/{podName}")
|
||||
Response deletePod(@PathVariable("namespace") String namespace,
|
||||
@PathVariable("podName") String podName,
|
||||
@RequestBody JSONObject deletePodBody,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,11 @@ public class RemoteRancherFallbackFactory implements FallbackFactory<RemoteRanch
|
|||
public JSONObject getK8sServiceByApplicationId(String cluster_id, String nginxApplicationId, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response deletePod(String namespace, String podName, JSONObject deletePodBody, String token) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.microservices.mon.k8s.controller;
|
||||
|
||||
import com.microservices.common.core.web.controller.BaseController;
|
||||
import com.microservices.common.core.web.domain.AjaxResult;
|
||||
import com.microservices.common.core.web.domain.GenericsAjaxResult;
|
||||
import com.microservices.common.core.web.page.GenericsTableDataInfo;
|
||||
import com.microservices.mon.k8s.domain.K8sApplication;
|
||||
|
|
@ -16,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
@RestController
|
||||
@RequestMapping("micro")
|
||||
@Api(tags = "微服务管理")
|
||||
public class MicroManagementController {
|
||||
public class MicroManagementController extends BaseController {
|
||||
@Autowired
|
||||
private IMicroManagementService microManagementService;
|
||||
|
||||
|
|
@ -30,7 +32,7 @@ public class MicroManagementController {
|
|||
@GetMapping("/pod/status/{containerID}")
|
||||
public GenericsAjaxResult<K8sPodContainerMetric> podStatus(@PathVariable("containerID") String containerID,
|
||||
@RequestParam(value = "step", required = false) @ApiParam(value = "统计频率") Long step) {
|
||||
return GenericsAjaxResult.success(microManagementService.getPodStatus(containerID,step));
|
||||
return GenericsAjaxResult.success(microManagementService.getPodStatus(containerID, step));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取微服务应用详情")
|
||||
|
|
@ -40,4 +42,12 @@ public class MicroManagementController {
|
|||
@PathVariable("applicationName") String applicationName) {
|
||||
return GenericsAjaxResult.success(microManagementService.getApplicationDetail(kind, namespace, applicationName));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除POD容器")
|
||||
@DeleteMapping("/pod/{namespace}/{podName}")
|
||||
public AjaxResult applicationDetail(@PathVariable("namespace") String namespace,
|
||||
@PathVariable("podName") String podName,
|
||||
@RequestParam(value = "isForce", required = false) @ApiParam(value = "是否强制删除") Boolean isForce) {
|
||||
return toAjax(microManagementService.deletePod(namespace, podName, isForce));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,4 +12,6 @@ public interface IMicroManagementService {
|
|||
K8sPodContainerMetric getPodStatus(String containerID, Long step);
|
||||
|
||||
K8sApplication getApplicationDetail(String kind, String namespace, String applicationName);
|
||||
|
||||
Boolean deletePod(String namespace, String podName, Boolean isForce);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|||
import com.microservices.common.core.context.SecurityContextHolder;
|
||||
import com.microservices.common.core.utils.DateUtils;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.mon.k8s.domain.*;
|
||||
import com.microservices.mon.k8s.domain.vo.*;
|
||||
import com.microservices.mon.k8s.service.IK8sDashboardService;
|
||||
|
|
@ -15,6 +16,7 @@ import com.microservices.mon.k8s.utils.SkywalkingGQLConstant;
|
|||
import com.microservices.system.api.RemoteGatewayService;
|
||||
import com.microservices.system.api.RemoteRancherService;
|
||||
import com.microservices.system.api.model.GraphqlQueryVo;
|
||||
import feign.Response;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -71,4 +73,16 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
|
|||
}
|
||||
return k8sApplication;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deletePod(String namespace, String podName, Boolean isForce) {
|
||||
JSONObject deletePodBody = new JSONObject();
|
||||
if (isForce != null && isForce) {
|
||||
deletePodBody.put("force", true);
|
||||
deletePodBody.put("gracePeriod", 0);
|
||||
}
|
||||
try (Response response = remoteRancherService.deletePod(namespace, podName, deletePodBody, SecurityContextHolder.getUserKey())) {
|
||||
return response != null && response.status() >= 200 && response.status() < 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue