Commit fa1b2f33 authored by 黎博's avatar 黎博

update

parent ed3dc9a7
......@@ -17,6 +17,7 @@ import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......@@ -32,6 +33,7 @@ import java.lang.reflect.Parameter;
@Slf4j
@Aspect
@Component
@Order(5)
public class RecordOperationAspect {
@Autowired
......@@ -40,7 +42,7 @@ public class RecordOperationAspect {
@Autowired
UserBehaviorRecordService userBehaviorRecordService;
@Before("@annotation(cn.qg.holmes.config.annotation.RecordOperation)")
@After("@annotation(cn.qg.holmes.config.annotation.RecordOperation)")
public void after(JoinPoint joinPoint) {
// 获取token,并根据token获取到用户名
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
......@@ -50,7 +52,7 @@ public class RecordOperationAspect {
throw new UnauthorizedException();
}
String username = tokenService.getUserInfoFromCache(token).getUsername();
String username = tokenService.getUserInfoFromCache(token).getChineseName();
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
RecordOperation recordOperation = methodSignature.getMethod().getAnnotation(RecordOperation.class);
......@@ -58,6 +60,7 @@ public class RecordOperationAspect {
String action = recordOperation.value();
String namespace = "";
String serviceName = "";
String image = "";
// 获取方法里的参数
Object[] args = joinPoint.getArgs();
ParameterNameDiscoverer pnd = new DefaultParameterNameDiscoverer();
......@@ -71,10 +74,11 @@ public class RecordOperationAspect {
if (parameterNames[i].equals("namespace")) {
namespace = args[i].toString();
}
if (parameterNames[i].equals("ServiceCreateVo")) {
if (parameterNames[i].equals("serviceCreateVo")) {
ServiceCreateVo serviceCreateVo = (ServiceCreateVo) args[i];
serviceName = serviceCreateVo.getServiceName();
namespace = serviceCreateVo.getNamespace();
image = serviceCreateVo.getImage().split(":")[1];
}
}
}
......@@ -85,6 +89,8 @@ public class RecordOperationAspect {
userBehaviorRecord.setAction(action);
userBehaviorRecord.setNamespace(namespace);
userBehaviorRecord.setServiceName(serviceName);
userBehaviorRecord.setImage(image);
log.info("用户{}在{}环境{}了服务{}。", username, namespace, action, serviceName);
userBehaviorRecordService.save(userBehaviorRecord);
}
}
......@@ -87,7 +87,7 @@ public class K8sController {
* @param serviceCreateVo 创建实体类
* @return
*/
@RecordOperation("create")
@RecordOperation("新增服务")
@PostMapping("/service/create")
public JsonResult createPod(@RequestBody ServiceCreateVo serviceCreateVo) {
try {
......@@ -212,12 +212,13 @@ public class K8sController {
/**
* 重置pod
* @param namespace 环境
* @param podName podName
* @param serviceName podName
* @return
*/
@RecordOperation("重置服务")
@PostMapping("/service/redeploy")
public JsonResult resetPodByName(String namespace, String podName) {
return JsonResult.buildSuccessResult(k8sService.resetPod(namespace, podName));
public JsonResult resetPodByName(String namespace, String serviceName) {
return JsonResult.buildSuccessResult(k8sService.resetPod(namespace, serviceName));
}
/**
......@@ -225,6 +226,7 @@ public class K8sController {
* @param serviceCreateVo
* @return
*/
@RecordOperation("jenkins打包")
@PostMapping("/service/modify")
public JsonResult modifyPod(@RequestBody ServiceCreateVo serviceCreateVo) {
log.info("接口/k8s/service/modify收到请求,请求参数为:{}", JSON.toJSONString(serviceCreateVo));
......@@ -291,6 +293,7 @@ public class K8sController {
* @param serviceCreateVo
* @return
*/
@RecordOperation("更新服务")
@PostMapping("/service/update")
public JsonResult updatePod(@RequestBody ServiceCreateVo serviceCreateVo) {
String namespace = serviceCreateVo.getNamespace();
......@@ -342,7 +345,7 @@ public class K8sController {
* @param serviceName 服务名称
* @return
*/
@RecordOperation("delete")
@RecordOperation("删除服务")
@PostMapping("/service/delete")
public JsonResult deletePodByName(String namespace, String serviceName) {
return JsonResult.buildSuccessResult(k8sService.deleteDeployment(namespace, serviceName));
......
......@@ -23,6 +23,8 @@ public class UserBehaviorRecord {
private String serviceName;
private String image;
private String namespace;
private String username;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment