HttpRequestServiceImpl.java
4.05 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.ecar.apm.service.impl;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ecar.apm.dao.HttpRequestLogMapper;
import com.ecar.apm.dao.HttpRequestMapper;
import com.ecar.apm.http.client.HttpSequenceHandle;
import com.ecar.apm.model.HttpRequest;
import com.ecar.apm.model.HttpRequestLog;
import com.ecar.apm.model.HttpSequence;
import com.ecar.apm.quartz.DynamicJobManager;
import com.ecar.apm.service.HttpRequestService;
import com.ecar.apm.service.HttpSequenceService;
import com.ecar.apm.util.GuidGenerator;
import com.github.pagehelper.StringUtil;
@Service
public class HttpRequestServiceImpl implements HttpRequestService {
@Autowired
private HttpRequestMapper httpRequestMapper;
@Autowired
private HttpSequenceService httpSequenceService;
@Autowired
private HttpRequestLogMapper httpRequestLogMapper;
@Transactional
@Override
public boolean enableMonitor(String guid) {
HttpSequence instance = httpSequenceService.getByGuid(guid);
DynamicJobManager dynamicJobManager = new DynamicJobManager(instance);
return dynamicJobManager.enable();
}
@Transactional
@Override
public boolean disableMonitor(String guid) {
HttpSequence instance = httpSequenceService.getByGuid(guid);
DynamicJobManager dynamicJobManager = new DynamicJobManager(instance);
return dynamicJobManager.kill();
}
@Transactional
@Override
public boolean deleteMonitor(String guid) {
HttpSequence instance = httpSequenceService.getByGuid(guid);
DynamicJobManager dynamicJobManager = new DynamicJobManager(instance);
return dynamicJobManager.delete();
}
@Transactional
@Override
public void executeRequest(String guid) {
HttpSequence instance = httpSequenceService.getByGuid(guid);
if(instance==null){
//删除任务
return;
}
List<HttpRequest> list = this.getHttpRequestListByPguid(guid);
instance.setHttpRequest(list);
//执行接口探测
HttpSequenceHandle httpSequenceHandle = new HttpSequenceHandle(instance);
httpSequenceHandle.execute();
httpSequenceService.insertLog(httpSequenceHandle.httpSequenceLog);
//保存日志
for(HttpRequestLog httpRequestLog : httpSequenceHandle.httpRequestLogList){
httpRequestLog.setPid(httpSequenceHandle.httpSequenceLog.getId());
httpRequestLogMapper.insert(httpRequestLog);
}
}
@Transactional
@Override
public void archivedHttpData(String guid){
httpSequenceService.archived(guid);
httpRequestMapper.archived(guid);
}
@Transactional
@Override
public void deleteHttpLog(String guid){
httpSequenceService.deleteLog(guid);
httpRequestLogMapper.delete(guid);
}
@Transactional
@Override
public void cleanMonitorLogs(int day) {
httpRequestLogMapper.cleanLogByDay(day);
httpSequenceService.cleanLog(day);
}
@Override
public void updateEnabled(HttpSequence httpSequence){
httpSequenceService.updateEnabled(httpSequence);
}
@Override
public List<HttpRequest> getAllHttpRequest(){
return httpRequestMapper.selectAll();
}
@Override
public HttpRequest getHttpRequestByGuid(String guid){
return httpRequestMapper.getByGuid(guid);
}
@Override
public List<HttpRequest> getHttpRequestListByPguid(String pguid){
return httpRequestMapper.getListByPguid(pguid);
}
@Override
public void insertHttpRequest(HttpRequest httpRequest){
if(StringUtil.isEmpty(httpRequest.getGuid())){
httpRequest.setGuid(GuidGenerator.generate());
}
httpRequestMapper.insert(httpRequest);
}
@Override
public void updateHttpRequest(HttpRequest httpRequest){
httpRequestMapper.update(httpRequest);
}
@Override
public List<Map<String, Object>> getHttpRequestLogByPid(String id){
List<Map<String, Object>> list = httpRequestLogMapper.getByPid(Integer.parseInt(id));
return list;
}
}