SaveJobInfoController.java
2.67 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
/**
*
*/
package com.yoho.jobs.server.controller;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.yoho.jobs.common.domain.ConstantEnum;
import com.yoho.jobs.common.domain.ProcessResult;
import com.yoho.jobs.dal.IJobResultMapper;
import com.yoho.jobs.dal.domain.ProcessResultVO;
import com.yoho.jobs.server.alarm.SendAlarmTool;
/**
* @author yanzhang.fu
*
*/
@Controller
@RequestMapping("/jobmanager")
public class SaveJobInfoController {
@Resource
private IJobResultMapper jobResultMapper;
@Resource(name = "sendAlarmTool")
private SendAlarmTool sendAlarmTool;
@RequestMapping("/saveJobResult.do")
public void saveJobResult(@RequestBody ProcessResult jobInfo) {
ProcessResultVO result = new ProcessResultVO();
convert(result, jobInfo);
// TODO 若执行失败,则上报告警并入库
if (ConstantEnum.JobProcessResultCode.ERROR_CODE.equals(jobInfo.getCode())) {
// 上报告警
Map<String, String> tags = new HashMap<String, String>();
buildTags(result, tags);
Map<String, Object> fields = new HashMap<String, Object>();
buildFields(result, fields);
sendAlarmTool.sendAlarm(tags, fields);
}
jobResultMapper.insertJob(result);
}
private void convert(ProcessResultVO result, ProcessResult jobInfo) {
result.setActiveMode(jobInfo.getJobInfo().getActiveMode());
result.setBeginTime(jobInfo.getBeginTime());
result.setCode(jobInfo.getCode());
result.setContext(jobInfo.getJobInfo().getContext());
result.setCronExpression(jobInfo.getJobInfo().getCronExpression());
result.setDesc(jobInfo.getJobInfo().getDesc());
result.setEndTime(jobInfo.getEndTime());
result.setJobGroup(jobInfo.getJobInfo().getJobGroup());
result.setJobName(jobInfo.getJobInfo().getJobName());
result.setJobType(jobInfo.getJobInfo().getJobType());
result.setMessage(jobInfo.getMessage());
result.setModule(jobInfo.getJobInfo().getModule());
result.setOperator(jobInfo.getJobInfo().getOperator());
result.setProcessIp(jobInfo.getJobInfo().getProcessIp());
result.setProcessor(jobInfo.getJobInfo().getProcessor());
result.setStatus(jobInfo.getJobInfo().getStatus());
result.setRecordDate(new Date());
}
private void buildTags(ProcessResultVO result, Map<String, String> tags) {
tags.put("jobname", result.getJobName());
tags.put("module", result.getModule());
}
private void buildFields(ProcessResultVO result, Map<String, Object> fields) {
fields.put("message", result.getMessage());
fields.put("desc", "exec job faild");
}
}