JavaRestartCtrl.java
3.5 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
package com.ui.ctrl;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.RestartModel;
import com.ui.model.req.PageRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
/**
* Created by zhengyouwei on 2016/10/18.
*/
@RestController
@RequestMapping(value = "/javaRestart")
public class JavaRestartCtrl {
Logger log = LoggerFactory.getLogger(JavaRestartCtrl.class);
@Autowired
private HttpRestClient httpClient;
@RequestMapping("/toJavaRestart")
public ModelAndView toJavaRestart() {
return new ModelAndView("/switch/java_restart");
}
@RequestMapping("/toStopOrRestart")
public ModelAndView toStopOrRestart(String project,String cloud, String exe,String ip,Model model) {
model.addAttribute("project",project);
model.addAttribute("cloud",cloud);
model.addAttribute("exe",exe);
model.addAttribute("ip",ip);
return new ModelAndView("/switch/java_restart_process");
}
@RequestMapping("/query")
@ResponseBody
public BaseResponse query(PageRequest req) {
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_RESTART_GET, req, BaseResponse.class);
return rep;
}
@RequestMapping("/getProjectStatus")
@ResponseBody
public BaseResponse getProjectStatus(String project) {
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_RESTART_STATAUS + "?project=" + project, null, BaseResponse.class);
return rep;
}
@RequestMapping("/stopOrRestart")
@ResponseBody
public BaseResponse stopOrRestart( RestartModel restartModel) {
if(StringUtils.isBlank(restartModel.getExe()) || StringUtils.isBlank(restartModel.getCloud()) || StringUtils.isBlank(restartModel.getProject())){
return null;
}
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_STOP_RESTART, restartModel, BaseResponse.class);
return rep;
}
@RequestMapping("/getMessage")
@ResponseBody
public BaseResponse getMessage(Integer id) {
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_GET_MESSAGE+ "?id=" + id, null, BaseResponse.class);
return rep;
}
@RequestMapping("/getMessageStatus")
@ResponseBody
public BaseResponse getMessageStatus(String ids) {
boolean allOk=true;
StringBuilder sb=new StringBuilder();
for(String id:ids.split(",")){
if(StringUtils.isNotBlank(id)){
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_GET_MESSAGE_STATUS+ "?id=" + id, null, BaseResponse.class);
sb.append(id).append(":").append(rep!=null?rep.getData():"").append("<br>");
if(rep!=null&&rep.getData()!=null&&(rep.getData().equals("0")||rep.getData().equals("2"))){
}else{
allOk=false;
}
}
}
if(allOk){
return new BaseResponse("ok");
}else{
return new BaseResponse(sb.toString());
}
}
}