ConfigCenterCtrl.java
4.75 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
package com.ui.ctrl;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.ZkDetailReq;
import com.ui.model.req.ZkTreeReq;
import org.apache.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
/**
* Created by liyl on 2017/12/4.
*/
@Controller
@RequestMapping("configCenter")
public class ConfigCenterCtrl {
Logger log = LoggerFactory.getLogger(TypeCtrl.class);
@Autowired
private HttpRestClient httpClient;
@RequestMapping("/tozkConfigCenterList")
public ModelAndView tozkConfigCenter() {
return new ModelAndView("zkConfigCenter/zkConfigCenterList");
}
@RequestMapping("/zkTreeLeaf")
@ResponseBody
public String zkTreeLeaf() {
String strType = "";
log.debug("get zkTreeLeaf");
strType = httpClient.defaultGet(HttpUriContants.TYPE_GET_ZKTREE_LEAF, String.class);
log.info("zkTreeLeaf: {}", strType);
return strType;
}
@RequestMapping("/getRootConfigCenter")
@ResponseBody
public BaseResponse getRootConfigCenter(ZkTreeReq req){
log.info("getRootConfigCenter with req is {}",req);
BaseResponse response=httpClient.defaultPost(HttpUriContants.GET_ZK_TREE_CONFIGCENTER, req, BaseResponse.class);
return response;
}
@RequestMapping("/getZkConfigList")
@ResponseBody
public BaseResponse getZkConfigList(ZkDetailReq req){
log.info("getZkConfigList with req is {}",req);
BaseResponse response=httpClient.defaultPost(HttpUriContants.GET_ZK_LIST, req, BaseResponse.class);
return response;
}
@RequestMapping("/export")
@ResponseBody
public void export(ZkDetailReq req, HttpServletResponse response){
log.info("export with req is {}", req);
Properties res = httpClient.defaultPost(HttpUriContants.GET_ZK_LIST_EXPORT, req, Properties.class);
if (null == res) {
res = new Properties();
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-download");
response.addHeader("Content-Disposition", "attachment;filename=config.properties");
OutputStream out = null;
try {
out = response.getOutputStream();
res.store(out, "export config info from zk!");
out.flush();
} catch (IOException e) {
log.error("export with req is {}", req, e);
} finally {
if (out != null) {
try {
out.close();
} catch (Exception e) {
}
}
}
}
@RequestMapping("/editDetail")
@ResponseBody
public BaseResponse editDetail(ZkDetailReq req){
log.info("editDetail with req is {}",req);
BaseResponse response=httpClient.defaultPost(HttpUriContants.EDIT_ZK_CONFIG_DETAIL, req, BaseResponse.class);
return response;
}
@RequestMapping("/addRoot")
@ResponseBody
public BaseResponse addRoot(ZkTreeReq req){
log.info("addRoot with req is {}",req);
BaseResponse response=httpClient.defaultPost(HttpUriContants.ADD_ZK_ROOT, req, BaseResponse.class);
return response;
}
@RequestMapping("/batchImport")
@ResponseBody
public BaseResponse batchImport(ZkTreeReq req, @RequestParam("file") MultipartFile file){
log.info("batchImport with req is {}", req);
Properties properties = new Properties();
try {
properties.load(file.getInputStream());
req.setProperties(properties);
} catch (Exception e) {
log.error("get zk batchImport file info failed", e);
}
BaseResponse response=httpClient.defaultPost(HttpUriContants.BATCHIMPORT_ZK_ROOT_CONFIGCENTER, req, BaseResponse.class);
return response;
}
/**
* 新增一个配置项到多个环境
* @param req
* @return
*/
@RequestMapping("/addZkCongfigMulti")
@ResponseBody
public BaseResponse addZkCongfigMulti(ZkDetailReq req){
log.info("addZkCongfigMulti with req is {}",req);
BaseResponse response=httpClient.defaultPost(HttpUriContants.ADD_ZKCONFIG_MULTI, req, BaseResponse.class);
return response;
}
}