1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.example.fuzzControll.aop;
import com.example.fuzzControll.annotion.NeedCutAround;
import com.example.fuzzControll.annotion.NeedCutBefore;
import com.example.fuzzControll.constents.MissionStateEnum;
import com.example.fuzzControll.constents.TableClassEnum;
import com.example.fuzzControll.domain.po.MissionInfo;
import com.example.fuzzControll.exception.mysqlException.MysqlException;
import com.example.fuzzControll.exception.testException.AflnetException;
import com.example.fuzzControll.exception.testException.KittyException;
import com.example.fuzzControll.mapper.MissionInfoMapper;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.system.SystemRunningParams;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Aspect
@Component
@Slf4j
public class aroundAop implements Ordered {
@Autowired
MissionInfoMapper missionInfoMapper;
@Pointcut(value = "@annotation(com.example.fuzzControll.annotion.NeedCutAround)")
private void aroundCut() {
}
@Around("aroundCut()")
public Map<String, List<String>> around(ProceedingJoinPoint point) throws Throwable {
Signature signature = point.getSignature();
MethodSignature methodSignature = null;
if (!(signature instanceof MethodSignature)) {
throw new IllegalArgumentException("该注解只能用于方法");
}
methodSignature = (MethodSignature) signature;
Object target = point.getTarget();
Method currentMethod = target.getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes());
NeedCutAround logotype = currentMethod.getAnnotation(NeedCutAround.class);
/*aflnet相关处理逻辑,负责数据存入*/
switch (logotype.name()) {
case "aflnet":
return null;
// aflnetAround(logotype.function());
case "kitty":
return kittyAround(logotype.function(), point);
default:
return null;
}
}
private Map<String, List<String>> kittyAround(String function, ProceedingJoinPoint point) {
Object result = null;
if (function == null || "".equals(function)) {
throw new AflnetException("There is no value in function!");
}
if ("generation".equals(function)) {
/*运行前处理*/
SystemRunningParams.testTimeMessage.get("kitty").put("start", System.currentTimeMillis());
/*放行方法*/
try {
result = point.proceed();
} catch (Throwable e) {
e.printStackTrace();
throw new KittyException("Kitty run error!");
}
/*运行后方法*/
if (function == null || "".equals(function)) {
throw new AflnetException("There is no value in function!");
}
/*存入kitty结束时的任务信息*/
try {
SystemRunningParams.testTimeMessage.get("kitty").put("end", System.currentTimeMillis());
System.out.println(SystemRunningParams.testTimeMessage.get("kitty").put("end", System.currentTimeMillis()));
int missionId = SystemRunningParams.kittyMissionId;
Long runTime = SystemRunningParams.testTimeMessage.get("kitty").get("end") - SystemRunningParams.testTimeMessage.get("kitty").get("start");
System.out.println("MissionId :" + missionId);
MissionInfo missionInfo = missionInfoMapper.selectByMissionId(missionId);
missionInfo.setState(MissionStateEnum.DONE.getStateCode());
missionInfo.setRunTime(runTime);
GlobalClass.missionInfoMapper.updateMission(missionInfo);//更新该次任务的执行时间;
} catch (Exception e) {
e.printStackTrace();
throw new MysqlException("Kitty start backup failed!");
}
}
if (result == null) {
throw new KittyException("Result is null!");
}
return (Map<String, List<String>>) result;
}
@Override
public int getOrder() {
return 2;
}
}