Authored by mlge

伸缩 --流程更改:增加步骤----伸缩结束后 更新Host_info表

... ... @@ -121,5 +121,24 @@ public class HostInfoCtrl {
return JSON.toJSONString(ips);
}
/**
* 更新主机tag信息为空
* @param hostInfos
* @return
*/
@RequestMapping("/updateHostInfoByIps")
@ResponseBody
public BaseResponse updateHostInfoByIps(@RequestBody List<HostInfo> hostInfos){
// List<HostInfo> hostInfoList = JSON.parseArray(hosts,HostInfo.class);
return hostInfoService.updateTagByIps(hostInfos);
}
@RequestMapping("/saveHostListInfos")
@ResponseBody
public BaseResponse saveHostListInfos(@RequestBody List<HostInfo> hostInfos ){
// List<HostInfo> hostInfos = JSON.parseArray(hosts,HostInfo.class);
return hostInfoService.saveHostListInfo(hostInfos);
}
}
... ...
... ... @@ -6,7 +6,6 @@ import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import java.util.List;
import java.util.Set;
/**
* Created by yoho on 2016/6/14.
... ... @@ -25,4 +24,8 @@ public interface IHostInfoService {
List<HostInfo> getHostInfosByTag(String tag);
List<HostInfo> getHostInfoByIps(List<String> ids);
BaseResponse updateTagByIps(List<HostInfo> hostInfoList);
BaseResponse saveHostListInfo(List<HostInfo> hostInfos);
}
... ...
... ... @@ -123,4 +123,54 @@ public class HostInfoServiceImpl implements IHostInfoService {
return hostInfoMapper.selectHostInfosByIps(ips);
}
/**
* 将tag更新为空
* @param
*/
@Override
public BaseResponse updateTagByIps(List<HostInfo> hostInfoList){
BaseResponse resp = new BaseResponse();
String message = "";
if(hostInfoList != null && hostInfoList.size() > 0){
for(HostInfo host : hostInfoList){
try{
hostInfoMapper.updateHostInfoByIp(host);
}catch(Exception e){
logger.error("updateTagByIps error: ",e);
message = message + "updateTagByIps error --ip:" + host.getHostIp() + ";";
}
}
}
if(!"".equals(message)){
resp.setCode(201);
resp.setMessage(message);
}
return resp;
}
@Override
public BaseResponse saveHostListInfo(List<HostInfo> hostInfos) {
BaseResponse resp = new BaseResponse();
String message = "";
for(HostInfo host : hostInfos){
HostInfo h = hostInfoMapper.selectByHostIp(host.getHostIp());
try{
if(h != null){//存在则更新
hostInfoMapper.updateHostInfoByIp(host);
}else{
hostInfoMapper.insert(host);
}
}catch(Exception e){
logger.error("saveHostListInfo error: ",e);
message = message + "saveHostListInfo error --ip:" + host.getHostIp() + ";";
}
}
if(!"".equals(message)){
resp.setCode(201);
resp.setMessage(message);
}
return new BaseResponse();
}
}
... ...
... ... @@ -30,4 +30,8 @@ public interface HostInfoMapper {
HostInfo selectByHostIp(@Param("hostIp") String hostIp);
List<HostInfo> selectHostInfosByIps(@Param("hostIps") List<String> ips);
int updateTagByIps(HostInfo record);
int updateHostInfoByIp(HostInfo record);
}
\ No newline at end of file
... ...
... ... @@ -199,4 +199,24 @@
#{hostIp}
</foreach>
</select>
<update id="updateTagByIps" >
update host_info
set tags = ""
where host_ip in
<foreach item="hostIp" index="index" collection="hostIps" open="("
separator="," close=")">
#{hostIp}
</foreach>
</update>
<update id="updateHostInfoByIp" parameterType="com.model.HostInfo" >
update host_info
set alias = #{alias,jdbcType=VARCHAR},
cloud_type = #{cloudType,jdbcType=BIT},
tags = #{tags,jdbcType=VARCHAR},
update_time = now()
where host_ip = #{hostIp,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...