伸缩 --流程更改:增加步骤----伸缩结束后 更新Host_info表
Showing
5 changed files
with
97 additions
and
1 deletions
@@ -121,5 +121,24 @@ public class HostInfoCtrl { | @@ -121,5 +121,24 @@ public class HostInfoCtrl { | ||
121 | return JSON.toJSONString(ips); | 121 | return JSON.toJSONString(ips); |
122 | } | 122 | } |
123 | 123 | ||
124 | + /** | ||
125 | + * 更新主机tag信息为空 | ||
126 | + * @param hostInfos | ||
127 | + * @return | ||
128 | + */ | ||
129 | + @RequestMapping("/updateHostInfoByIps") | ||
130 | + @ResponseBody | ||
131 | + public BaseResponse updateHostInfoByIps(@RequestBody List<HostInfo> hostInfos){ | ||
132 | +// List<HostInfo> hostInfoList = JSON.parseArray(hosts,HostInfo.class); | ||
133 | + return hostInfoService.updateTagByIps(hostInfos); | ||
134 | + } | ||
135 | + | ||
136 | + @RequestMapping("/saveHostListInfos") | ||
137 | + @ResponseBody | ||
138 | + public BaseResponse saveHostListInfos(@RequestBody List<HostInfo> hostInfos ){ | ||
139 | +// List<HostInfo> hostInfos = JSON.parseArray(hosts,HostInfo.class); | ||
140 | + return hostInfoService.saveHostListInfo(hostInfos); | ||
141 | + } | ||
142 | + | ||
124 | } | 143 | } |
125 | 144 |
@@ -6,7 +6,6 @@ import com.monitor.model.response.BaseResponse; | @@ -6,7 +6,6 @@ import com.monitor.model.response.BaseResponse; | ||
6 | import com.monitor.model.response.PageResponse; | 6 | import com.monitor.model.response.PageResponse; |
7 | 7 | ||
8 | import java.util.List; | 8 | import java.util.List; |
9 | -import java.util.Set; | ||
10 | 9 | ||
11 | /** | 10 | /** |
12 | * Created by yoho on 2016/6/14. | 11 | * Created by yoho on 2016/6/14. |
@@ -25,4 +24,8 @@ public interface IHostInfoService { | @@ -25,4 +24,8 @@ public interface IHostInfoService { | ||
25 | List<HostInfo> getHostInfosByTag(String tag); | 24 | List<HostInfo> getHostInfosByTag(String tag); |
26 | 25 | ||
27 | List<HostInfo> getHostInfoByIps(List<String> ids); | 26 | List<HostInfo> getHostInfoByIps(List<String> ids); |
27 | + | ||
28 | + BaseResponse updateTagByIps(List<HostInfo> hostInfoList); | ||
29 | + | ||
30 | + BaseResponse saveHostListInfo(List<HostInfo> hostInfos); | ||
28 | } | 31 | } |
@@ -123,4 +123,54 @@ public class HostInfoServiceImpl implements IHostInfoService { | @@ -123,4 +123,54 @@ public class HostInfoServiceImpl implements IHostInfoService { | ||
123 | return hostInfoMapper.selectHostInfosByIps(ips); | 123 | return hostInfoMapper.selectHostInfosByIps(ips); |
124 | } | 124 | } |
125 | 125 | ||
126 | + /** | ||
127 | + * 将tag更新为空 | ||
128 | + * @param | ||
129 | + */ | ||
130 | + @Override | ||
131 | + public BaseResponse updateTagByIps(List<HostInfo> hostInfoList){ | ||
132 | + BaseResponse resp = new BaseResponse(); | ||
133 | + String message = ""; | ||
134 | + if(hostInfoList != null && hostInfoList.size() > 0){ | ||
135 | + for(HostInfo host : hostInfoList){ | ||
136 | + try{ | ||
137 | + hostInfoMapper.updateHostInfoByIp(host); | ||
138 | + }catch(Exception e){ | ||
139 | + logger.error("updateTagByIps error: ",e); | ||
140 | + message = message + "updateTagByIps error --ip:" + host.getHostIp() + ";"; | ||
141 | + } | ||
142 | + } | ||
143 | + } | ||
144 | + if(!"".equals(message)){ | ||
145 | + resp.setCode(201); | ||
146 | + resp.setMessage(message); | ||
147 | + } | ||
148 | + return resp; | ||
149 | + | ||
150 | + } | ||
151 | + | ||
152 | + @Override | ||
153 | + public BaseResponse saveHostListInfo(List<HostInfo> hostInfos) { | ||
154 | + BaseResponse resp = new BaseResponse(); | ||
155 | + String message = ""; | ||
156 | + for(HostInfo host : hostInfos){ | ||
157 | + HostInfo h = hostInfoMapper.selectByHostIp(host.getHostIp()); | ||
158 | + try{ | ||
159 | + if(h != null){//存在则更新 | ||
160 | + hostInfoMapper.updateHostInfoByIp(host); | ||
161 | + }else{ | ||
162 | + hostInfoMapper.insert(host); | ||
163 | + } | ||
164 | + }catch(Exception e){ | ||
165 | + logger.error("saveHostListInfo error: ",e); | ||
166 | + message = message + "saveHostListInfo error --ip:" + host.getHostIp() + ";"; | ||
167 | + } | ||
168 | + } | ||
169 | + if(!"".equals(message)){ | ||
170 | + resp.setCode(201); | ||
171 | + resp.setMessage(message); | ||
172 | + } | ||
173 | + return new BaseResponse(); | ||
174 | + } | ||
175 | + | ||
126 | } | 176 | } |
@@ -30,4 +30,8 @@ public interface HostInfoMapper { | @@ -30,4 +30,8 @@ public interface HostInfoMapper { | ||
30 | HostInfo selectByHostIp(@Param("hostIp") String hostIp); | 30 | HostInfo selectByHostIp(@Param("hostIp") String hostIp); |
31 | 31 | ||
32 | List<HostInfo> selectHostInfosByIps(@Param("hostIps") List<String> ips); | 32 | List<HostInfo> selectHostInfosByIps(@Param("hostIps") List<String> ips); |
33 | + | ||
34 | + int updateTagByIps(HostInfo record); | ||
35 | + | ||
36 | + int updateHostInfoByIp(HostInfo record); | ||
33 | } | 37 | } |
@@ -199,4 +199,24 @@ | @@ -199,4 +199,24 @@ | ||
199 | #{hostIp} | 199 | #{hostIp} |
200 | </foreach> | 200 | </foreach> |
201 | </select> | 201 | </select> |
202 | + | ||
203 | + <update id="updateTagByIps" > | ||
204 | + update host_info | ||
205 | + set tags = "" | ||
206 | + where host_ip in | ||
207 | + <foreach item="hostIp" index="index" collection="hostIps" open="(" | ||
208 | + separator="," close=")"> | ||
209 | + #{hostIp} | ||
210 | + </foreach> | ||
211 | + </update> | ||
212 | + | ||
213 | + | ||
214 | + <update id="updateHostInfoByIp" parameterType="com.model.HostInfo" > | ||
215 | + update host_info | ||
216 | + set alias = #{alias,jdbcType=VARCHAR}, | ||
217 | + cloud_type = #{cloudType,jdbcType=BIT}, | ||
218 | + tags = #{tags,jdbcType=VARCHAR}, | ||
219 | + update_time = now() | ||
220 | + where host_ip = #{hostIp,jdbcType=INTEGER} | ||
221 | + </update> | ||
202 | </mapper> | 222 | </mapper> |
-
Please register or login to post a comment