Authored by qinchao

Merge branch 'dev_gml'

Showing 26 changed files with 445 additions and 61 deletions
... ... @@ -16,7 +16,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
... ... @@ -34,9 +37,9 @@ public class HostGroupCtrl {
@RequestMapping("/getAllGroups")
@ResponseBody
public BaseResponse getAllGroups() {
public BaseResponse getAllGroups(@RequestBody TagReq request) {
try{
List<HostGroup> list=hostGroupService.getListGroups();
List<HostGroup> list=hostGroupService.getAllGroups(request.getTagTypeContent(),request.getSearchContent());
if (list == null || CollectionUtils.isEmpty(list)) {
return new BaseResponse<List<HostGroup>>();
... ... @@ -50,6 +53,33 @@ public class HostGroupCtrl {
}
@RequestMapping("/getAllTagsGroupByType")
@ResponseBody
public BaseResponse getAllTagsGroupByType() {
try{
List<HostGroup> list=hostGroupService.getAllGroups("","");
Map<String,List<HostGroup>> map= new HashMap<String,List<HostGroup>>();
if(list!=null&&list.size()>0){
for(HostGroup tag:list){
if(map.keySet().contains(tag.getTagType())){
map.get(tag.getTagType()).add(tag);
}else{
List<HostGroup> ls=new ArrayList<HostGroup>();
ls.add(tag);
map.put(tag.getTagType(),ls);
}
}
}
return new BaseResponse<Map<String,List<HostGroup>>>(map);
}catch (Exception e){
log.error("getAllTagsGroupByType error",e);
return null;
}
}
@RequestMapping("/getHostGroups")
@ResponseBody
public BaseResponse<PageResponse<HostGroup>> getHostGroups(@RequestBody TagReq request) {
... ...
package com.monitor.cmdb.ctrl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.model.HostInfo;
import com.monitor.cmdb.service.IHostInfoService;
import com.monitor.model.request.HostInfoReq;
import com.monitor.model.request.SetHostTagsReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.yoho.ops.cmdb.aws.ec2.AwsEc2Fetcher;
import com.yoho.ops.cmdb.models.CmdbApiReq;
import com.yoho.ops.cmdb.models.Host;
import com.yoho.ops.cmdb.qcloud.autoscaling.QcloudAutoScalingFetcher;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -19,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
... ... @@ -36,6 +42,10 @@ public class HostInfoCtrl {
@Autowired
IHostInfoService hostInfoService;
@Autowired
private AwsEc2Fetcher awsFetcher;
@Autowired
private QcloudAutoScalingFetcher qcloudFetcher;
... ... @@ -158,5 +168,33 @@ public class HostInfoCtrl {
return hostInfoService.saveHostListInfo(hostInfos);
}
/**
* 同步主机信息(线上 &&database)
* @return
*/
@RequestMapping("/synHostInfo")
@ResponseBody
public BaseResponse synHostInfo() {
String message;
List<Host> awsHosts = awsFetcher.getAllEc2Details();
message = hostInfoService.compareHostInfo(awsHosts, 1);
List<Host> qcloudHosts = qcloudFetcher.getAllInstancesSet();
message += hostInfoService.compareHostInfo(qcloudHosts,2);
if(StringUtils.isNotBlank(message)){
return new BaseResponse(message);
}
return new BaseResponse<>();
}
@RequestMapping("/saveHostTags")
@ResponseBody
public BaseResponse<Integer> saveHostTags(@RequestBody SetHostTagsReq req) {
String hostIds = req.getHostIds();
String tags = req.getTags();
log.info("saveHostTags with param is {}, {}", hostIds, tags);
List<Integer> hostIdList = JSON.parseArray(hostIds,Integer.class);
return hostInfoService.saveHostTags(hostIdList,tags);
}
}
... ...
... ... @@ -17,6 +17,7 @@ import com.monitor.model.request.HostInfoReq;
import com.monitor.model.request.MObjectHostInfoReq;
import com.monitor.model.request.MObjectInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.HostInfoMapper;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -50,6 +51,9 @@ public class MObjectInfoCtrl {
@Autowired
ITypeInfoService typeInfoService;
@Autowired
HostInfoMapper hostInfoMapper;
@RequestMapping(value = "/queryHost", method = RequestMethod.POST)
public BaseResponse queryMObjectHost(@RequestBody MObjectHostInfoReq request) {
... ... @@ -76,7 +80,7 @@ public class MObjectInfoCtrl {
String selectTag = "";
List<HostGroup> sourceGroupList = groupService.getListGroups();
List<HostGroup> sourceGroupList = groupService.getAllGroups("","");
//add blank tag
... ... @@ -277,25 +281,115 @@ public class MObjectInfoCtrl {
return modelList;
}
@RequestMapping(value = "/asyMobjectHost")
public BaseResponse asyMobjectHost(int moTypeId) {
StringBuilder sb=new StringBuilder();
TypeInfo typeInfo=typeInfoService.queryTypeInfo(moTypeId);
sb.append("开始同步监控对象"+moTypeId);
if(typeInfo!=null&&StringUtils.isNotBlank(typeInfo.getTags())){
MObjectInfoReq mObjectInfoReq = new MObjectInfoReq();
mObjectInfoReq.setMoTypeId(typeInfo.getTypeId());
mObjectInfoReq.setMoTypeName(typeInfo.getTypeName());
mObjectInfoReq.setMoTags(typeInfo.getDescr());
sb.append("---").append(typeInfo.getTypeName()).append(":");
//根据typeinfo的主机标签查询出主机
List<String> hostTagsList=new ArrayList<String>();
List<Integer> cloudTagsList=new ArrayList<Integer>();
if(StringUtils.isNotBlank(typeInfo.getCloudTags())){
for(String cloudTag:typeInfo.getCloudTags().split(",")){
if("1".equalsIgnoreCase(cloudTag)){
cloudTagsList.add(1);
}else if("2".equalsIgnoreCase(cloudTag)){
cloudTagsList.add(2);
}else if("3".equalsIgnoreCase(cloudTag)){
cloudTagsList.add(3);
}else if("0".equalsIgnoreCase(cloudTag)){
cloudTagsList=new ArrayList<Integer>(); //全部云
break;
}
}
}
for(String hostTag:typeInfo.getTags().split(",")){
if(StringUtils.isNotBlank(hostTag)){
hostTagsList.add(hostTag);
}
}
if(hostTagsList.size()>0){
List<HostInfo> newhostInfos =hostInfoMapper.selectHostInfosByTagListAndCloudTypeList(hostTagsList,cloudTagsList);
List<MObjectInfo> oldMobjects = mobjectService.queryMObjectsInfoByType(moTypeId);
//
List<String> newIps=new ArrayList<String>();
if(newhostInfos!=null&&newhostInfos.size()>0){
for(HostInfo hostInfo:newhostInfos){
newIps.add(hostInfo.getHostIp());
}
}
Map<String,List<Integer>> oldMobjectsMap=new HashMap<String,List<Integer>>();
if(oldMobjects!=null&&oldMobjects.size()>0){
for(MObjectInfo mObjectInfo:oldMobjects){
if(oldMobjectsMap.keySet().contains(mObjectInfo.getMoHostIp())){
oldMobjectsMap.get(mObjectInfo.getMoHostIp()).add(mObjectInfo.getMoId());
}else{
List<Integer> tmpLs=new ArrayList<Integer>();
tmpLs.add(mObjectInfo.getMoId());
oldMobjectsMap.put(mObjectInfo.getMoHostIp(),tmpLs);
}
}
}
List<String> needAddIpList=new ArrayList<String>();
List<Integer> needDelMobjectIdList=new ArrayList<Integer>();
for(String ip :newIps){
if(!oldMobjectsMap.keySet().contains(ip)){
needAddIpList.add(ip);
}
}
String tmpDelips="";
for(String ip:oldMobjectsMap.keySet()){
if(!newIps.contains(ip)){
if(tmpDelips.length()>0){
tmpDelips+=",";
}
tmpDelips += ip;
needDelMobjectIdList.addAll(oldMobjectsMap.get(ip));
}
}
sb.append("删除hostip:").append(tmpDelips);
//删除
mobjectService.deleteMObjectInfo(needDelMobjectIdList);
//新增
sb.append("新增hostip:").append(StringUtils.join(needAddIpList,","));
mObjectInfoReq.setMoHostIp(StringUtils.join(needAddIpList,","));
addMobjectWithCheckFlag(mObjectInfoReq,false);
}
}
BaseResponse rtn= new BaseResponse();
rtn.setData(sb.toString());
return rtn;
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public BaseResponse addMObject(@RequestBody MObjectInfoReq request) {
return addMobjectWithCheckFlag(request,true);
}
DEBUG.debug("Add mObject: {}", request);
private BaseResponse addMobjectWithCheckFlag(MObjectInfoReq request,boolean checkFlag){
BaseResponse response = new BaseResponse();
try {
if (null != request&&StringUtils.isNotBlank(request.getMoHostIp())) {
if (!checkHost(request.getMoHostIp())) {
if(checkFlag){
if (!checkHost(request.getMoHostIp())) {
response.setCode(400);
response.setCode(400);
response.setMessage("Host " + request.getMoHostIp() + " does not exist...");
response.setMessage("Host " + request.getMoHostIp() + " does not exist...");
return response;
return response;
}
}
String allIps=request.getMoHostIp();
for(String ip:allIps.split(",")){
MObjectInfo info = new MObjectInfo();
... ... @@ -306,19 +400,13 @@ public class MObjectInfoCtrl {
mobjectService.addMObjectInfo(info);
}
}
} catch (Exception e) {
DEBUG.error("Failed to Add mobjects: {} , eror: {} ", request, e);
response.setCode(400);
response.setMessage(e.getMessage());
}
return response;
}
... ...
... ... @@ -32,9 +32,6 @@ public class TypeInfoCtrl {
@RequestMapping(value = "/query", method = RequestMethod.GET)
public BaseResponse queryTypeInfo() {
DEBUG.debug("Query all typeInfo...");
List<TypeInfo> allTypeInfo = null;
BaseResponse response = new BaseResponse();
... ... @@ -43,15 +40,11 @@ public class TypeInfoCtrl {
allTypeInfo = typeInfoService.queryAllTypesInfo();
if (null != allTypeInfo) {
response.setData(allTypeInfo);
}
} catch (Exception e) {
DEBUG.error("Failed to query all typeInfo, error: {}", e);
response.setCode(400);
response.setMessage(e.getMessage());
}
... ... @@ -160,9 +153,6 @@ public class TypeInfoCtrl {
@RequestMapping(value = "/add", method = RequestMethod.POST)
public BaseResponse addTypeInfo(@RequestBody TypeInfo request) {
DEBUG.debug("Add typeInfo: {}", request);
BaseResponse response = new BaseResponse();
try {
... ... @@ -226,8 +216,6 @@ public class TypeInfoCtrl {
@RequestMapping(value = "/update", method = RequestMethod.POST)
public BaseResponse updateMObject(@RequestBody TypeInfo request) {
DEBUG.debug("Update typeInfo: {}", request);
BaseResponse response = new BaseResponse();
try {
... ... @@ -248,6 +236,23 @@ public class TypeInfoCtrl {
}
@RequestMapping(value = "/updateTag", method = RequestMethod.POST)
public BaseResponse updateTag(@RequestBody TypeInfo request) {
BaseResponse response = new BaseResponse();
try {
if (null != request) {
typeInfoService.updateTypeInfoTag(request);
}
} catch (Exception e) {
DEBUG.error("Failed to update typeInfo: {}, error: {}", request, e);
response.setCode(400);
response.setMessage(e.getMessage());
}
return response;
}
@RequestMapping(value = "/queryJavaApi", method = RequestMethod.GET)
public BaseResponse queryJavaApi() {
... ... @@ -313,15 +318,9 @@ public class TypeInfoCtrl {
@RequestMapping(value = "/queryZk", method = RequestMethod.GET)
public BaseResponse queryZkTree() {
DEBUG.debug("Query all queryZkTree...");
List<TypeInfo> allTypeInfo = null;
BaseResponse response = new BaseResponse();
int parentId=7;
try {
allTypeInfo = typeInfoService.getChildById();
... ...
... ... @@ -7,6 +7,7 @@ import com.monitor.model.request.TagReq;
import com.monitor.model.response.BaseResponse;
import java.util.List;
import java.util.Map;
/**
* Created by yoho on 2016/6/14.
... ... @@ -20,6 +21,6 @@ public interface IHostGroupService {
BaseResponse<HostGroup> getHostGroupById(int id);
List<HostGroup> getListGroups();
List<HostGroup> getAllGroups(String tagType,String searchContent);
}
... ...
... ... @@ -4,6 +4,7 @@ import com.model.HostInfo;
import com.monitor.model.request.HostInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.yoho.ops.cmdb.models.Host;
import java.util.List;
... ... @@ -35,4 +36,8 @@ public interface IHostInfoService {
BaseResponse saveHostListInfo(List<HostInfo> hostInfos);
BaseResponse removeByIps(List<String> removeIps);
String compareHostInfo(List<Host> cloudHosts, int cloudType);
BaseResponse<Integer> saveHostTags(List<Integer> hostIdList, String tags);
}
... ...
... ... @@ -21,6 +21,8 @@ public interface IMObjectInfoService {
void deleteMObjectInfo(int id);
void deleteMObjectInfo(List<Integer> idList);
void updateMObjectInfo(MObjectInfo info);
boolean checkMoNameExist(String name);
... ...
... ... @@ -20,6 +20,7 @@ public interface ITypeInfoService {
void deleteTypeInfo(int id);
void updateTypeInfo(TypeInfo typeInfo);
void updateTypeInfoTag(TypeInfo typeInfo);
TypeInfo queryTypeInfoByName(String typeName);
... ...
... ... @@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
/**
* Created by yoho on 2016/6/15.
... ... @@ -92,7 +93,7 @@ public class HostGroupServiceImpl implements IHostGroupService {
}
@Override
public List<HostGroup> getListGroups() {
return hostGroupMapper.selectAllGroups();
public List<HostGroup> getAllGroups(String tagType,String searchContent) {
return hostGroupMapper.selectAllGroups(tagType,searchContent);
}
}
... ...
... ... @@ -14,6 +14,7 @@ import com.monitor.model.request.HostInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.HostInfoMapper;
import com.yoho.ops.cmdb.models.Host;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -153,12 +154,13 @@ public class HostInfoServiceImpl implements IHostInfoService {
@Override
public PageResponse<HostInfo> getHostInfos(HostInfoReq req) {
logger.info("getHostInfos with param is {}", req);
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = hostInfoMapper.selectCountByCodition(page);
logger.info("selectUserTotal num is {}, with param is {}", total,
logger.info("selectUserTotal num is {}, with param is {}", total,
req);
// 数量为0 直接返回
if (total == 0) {
... ... @@ -319,4 +321,115 @@ public class HostInfoServiceImpl implements IHostInfoService {
}
/**
*hostInfo ip 对比
* @param hosts---线上 主机信息
* @return
*/
@Override
public String compareHostInfo(List<Host> hosts, int cloudType) {
String resultMessage = "";
if(hosts == null || hosts.size() == 0){
logger.error("hostIps get from cloud is null! cloudType is {}",cloudType);
return "hostIps get from cloud is null! cloudType is " + cloudType ;
}
List<String> cloudHosts = new ArrayList<>();
for(Host h : hosts){
if(StringUtils.isNotBlank(h.getIp())){
cloudHosts.add(h.getIp());
}
}
List<String> dbHosts;
try{
dbHosts = hostInfoMapper.selectHostIpByCloud(cloudType);
}catch (Exception e){
logger.error("selectHostIpByCloud from database error! cloudType is {} : ",cloudType, e);
return "selectHostIpByCloud from database error! cloudType is " + cloudType;
}
if(dbHosts==null){
dbHosts=new ArrayList<>();
}
List<String> newIpList = new ArrayList<>();//需要插入到数据库中的ip
List<String> oldIpList = new ArrayList<>();//需要从数据库中删除的ip
for(String ip : cloudHosts){
if( !dbHosts.contains(ip) ){
newIpList.add(ip);
}
}
for(String ip : dbHosts){
if( !cloudHosts.contains(ip)){
oldIpList.add(ip);
}
}
if(newIpList.size() > 0 ){
logger.info("add new ips to database , ipList is {} ,cloudType is {} ,", newIpList, cloudType);
for (String ip : newIpList){
HostInfo hostInfo = new HostInfo();
hostInfo.setHostIp(ip);
hostInfo.setCloudType(cloudType);
if(cloudType == 1){
hostInfo.setAlias("AWS-" + ip);
}else if(cloudType == 2){
hostInfo.setAlias("QCLOUD-" + ip);
}
try{
hostInfoMapper.insert(hostInfo);
}catch (Exception e ){
logger.error("insert hostInfo error ! ip is {} : ", ip , e);
resultMessage += "insert hostInfo error ! ip is " + ip;
}
}
}
if(oldIpList.size() > 0 ){
logger.info("delete ip from database , ipList is {} ,cloudType is {} ,", oldIpList, cloudType);
for(String ip : oldIpList){
try{
//删除数据--暂时屏蔽
hostInfoMapper.deleteByIp(ip);
}catch (Exception e){
logger.error("delete ip error ! ip is {} : {}", ip , cloudType);
resultMessage += "delete ip error ! ip is " + ip ;
}
}
}
return resultMessage;
}
@Override
public BaseResponse<Integer> saveHostTags(List<Integer> hostIdList, String tags) {
int result = 0;
String message = "setTagsError: hostId is ";
if( hostIdList != null && hostIdList.size() > 0){
for(Integer hostId : hostIdList){
HostInfo host = new HostInfo();
host.setTags(tags);
host.setId(hostId);
try{
hostInfoMapper.updateByPrimaryKeySelective(host);
}catch (Exception e){
logger.error("saveHostTags error! hostId is {} : ", hostId , e);
result = 1;
message += hostId + " , ";
}
}
}
if(result == 0){
return new BaseResponse<>();
}
return new BaseResponse<>(message);
}
}
... ...
... ... @@ -100,6 +100,13 @@ public class MObjectInfoServiceImpl implements IMObjectInfoService {
}
@Override
public void deleteMObjectInfo(List<Integer> idList){
if(idList!=null&&idList.size()>0){
mObjectInfoMapper.deleteMoInfoList(idList);
}
}
@Override
public void updateMObjectInfo(MObjectInfo info) {
mObjectInfoMapper.updateMoInfo(info);
}
... ...
... ... @@ -78,6 +78,11 @@ public class TypeInfoServiceImpl implements ITypeInfoService {
}
@Override
public void updateTypeInfoTag(TypeInfo typeInfo){
mTypeInfoMapper.updateTypeInfoTag(typeInfo);
}
@Override
public TypeInfo queryTypeInfoByName(String typeName) {
return mTypeInfoMapper.selectTypeInfoByName(typeName);
}
... ...
... ... @@ -15,6 +15,8 @@ public class HostInfoReq extends PageRequest {
private String hostIp;
private String onlyShowTagsIsNull;
private int cloudType;
private int groupId;
... ...
package com.monitor.model.request;
import lombok.Data;
/**
* Created by meiling.ge on 2017/11/8.
*/
@Data
public class SetHostTagsReq {
private String hostIds;
private String tags;
}
... ...
... ... @@ -9,4 +9,5 @@ import lombok.Data;
@Data
public class TagReq extends PageRequest {
private String searchContent;
private String tagTypeContent;
}
... ...
... ... @@ -14,10 +14,14 @@ public class HostGroup implements Serializable {
private String groupName;
private String tagType;
private String createTime;
private String updateTime;
private String descr;
private int pid;///父id
}
... ...
... ... @@ -18,4 +18,10 @@ public class TypeInfo implements Serializable{
private int typeParentId;
private String cloudTags;//云标签
private String tags;//主机标签
private String descr;//节点的特殊信息
}
... ...
... ... @@ -4,6 +4,7 @@ package com.monitor.mysql.mapper;
import com.model.HostGroup;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageRequest;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
... ... @@ -22,6 +23,6 @@ public interface HostGroupMapper {
List<HostGroup> selectHostGroups(PageBean page);
List<HostGroup> selectAllGroups();
List<HostGroup> selectAllGroups(@Param("tagTypeContent") String tagTypeContent,@Param("searchContent") String searchContent);
}
\ No newline at end of file
... ...
... ... @@ -40,4 +40,6 @@ public interface HostInfoMapper {
int updateHostInfoByIp(HostInfo record);
int deleteByIp(String ip);
List<String> selectHostIpByCloud(@Param("cloudType") int cloudType);
}
\ No newline at end of file
... ...
... ... @@ -12,6 +12,8 @@ public interface MObjectInfoMapper {
void deleteMoInfo(int moId);
void deleteMoInfoList(List<Integer> moIds);
void updateMoInfo(MObjectInfo moInfo);
List<MObjectInfo> getAllMosInfo();
... ...
... ... @@ -13,6 +13,7 @@ public interface MTypeInfoMapper {
void deleteTypeInfo(int typeId);
void updateTypeInfo(TypeInfo typeInfo);
void updateTypeInfoTag(TypeInfo typeInfo);
List<TypeInfo> getAllTypesInfo();
... ...
... ... @@ -3,13 +3,15 @@
<mapper namespace="com.monitor.mysql.mapper.HostGroupMapper" >
<resultMap id="BaseResultMap" type="com.model.HostGroup" >
<id column="id" property="id" jdbcType="INTEGER" />
<id column="pid" property="pid" jdbcType="INTEGER" />
<result column="group_name" property="groupName" jdbcType="VARCHAR" />
<result column="tag_type" property="tagType" jdbcType="VARCHAR" />
<result column="descr" property="descr" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, group_name,descr, create_time, update_time
id, group_name,tag_type,descr, create_time, update_time,pid
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
... ... @@ -26,15 +28,17 @@
<insert id="insert" parameterType="com.model.HostGroup" >
insert into host_group
(group_name, descr,create_time, update_time)
(pid,group_name,tag_type, descr,create_time, update_time)
values
(#{groupName,jdbcType=VARCHAR},#{descr,jdbcType=VARCHAR}, now(),now())
(#{pid,jdbcType=INTEGER},#{groupName,jdbcType=VARCHAR},#{tagType,jdbcType=VARCHAR},#{descr,jdbcType=VARCHAR}, now(),now())
</insert>
<update id="updateByPrimaryKey" parameterType="com.model.HostGroup" >
update host_group
set group_name = #{groupName,jdbcType=VARCHAR},
descr = #{descr,jdbcType=VARCHAR},
pid = #{pid,jdbcType=INTEGER},
tag_type = #{tagType,jdbcType=VARCHAR},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
... ... @@ -43,10 +47,16 @@
select
<include refid="Base_Column_List" />
from host_group
where 1=1
<if test="params.searchContent!=null &amp;&amp; params.searchContent != ''">
where group_name like CONCAT('%',#{params.searchContent,jdbcType=VARCHAR},'%')
and (group_name like CONCAT('%',#{params.searchContent,jdbcType=VARCHAR},'%')
or
descr like CONCAT('%',#{params.searchContent,jdbcType=VARCHAR},'%'))
</if>
order by id desc
<if test="params.tagTypeContent!=null &amp;&amp; params.tagTypeContent != ''">
and tag_type = #{params.tagTypeContent,jdbcType=VARCHAR}
</if>
order by tag_type,id desc
limit #{startIndex},#{pageSize}
</select>
... ... @@ -54,14 +64,29 @@
select
<include refid="Base_Column_List" />
from host_group
where 1=1
<if test="searchContent!=null &amp;&amp; searchContent != ''">
and (group_name like CONCAT('%',#{searchContent,jdbcType=VARCHAR},'%')
or
descr like CONCAT('%',#{searchContent,jdbcType=VARCHAR},'%'))
</if>
<if test="tagTypeContent!=null &amp;&amp; tagTypeContent != ''">
and tag_type = #{tagTypeContent,jdbcType=VARCHAR}
</if>
</select>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from host_group
<if test="params.searchContent!=null &amp;&amp; params.searchContent != ''">
where group_name like CONCAT('%',#{params.searchContent,jdbcType=VARCHAR},'%')
where 1=1
<if test="params.searchContent!=null &amp;&amp; params.searchContent != ''">
and (group_name like CONCAT('%',#{params.searchContent,jdbcType=VARCHAR},'%')
or
descr like CONCAT('%',#{params.searchContent,jdbcType=VARCHAR},'%'))
</if>
<if test="params.tagTypeContent!=null &amp;&amp; params.tagTypeContent != ''">
and tag_type = #{params.tagTypeContent,jdbcType=VARCHAR}
</if>
</select>
... ...
... ... @@ -94,13 +94,13 @@
<if test="alias != null" >
alias = #{alias,jdbcType=VARCHAR},
</if>
<if test="hostIp != null" >
<if test="hostIp != null " >
host_ip = #{hostIp,jdbcType=VARCHAR},
</if>
<if test="groupId != null" >
<if test="groupId != null &amp;&amp; groupId != 0 " >
group_id = #{groupId,jdbcType=INTEGER},
</if>
<if test="cloudType != null" >
<if test="cloudType != null &amp;&amp; cloudType != 0" >
cloud_type = #{cloudType,jdbcType=BIT},
</if>
<if test="tags != null" >
... ... @@ -141,12 +141,19 @@
<if test="params.hostIp != null &amp;&amp; params.hostIp != ''" >
and a.host_ip = #{params.hostIp}
</if>
<if test="params.tagsList != null &amp;&amp; params.tagsList != ''" >
and
<foreach collection="params.tagsList" index="index" item="item" separator="and">
instr(a.tags, #{item}) &gt; 0
</foreach>
</if>
<choose>
<when test="params.onlyShowTagsIsNull != null &amp;&amp; params.onlyShowTagsIsNull != '' ">
and ( ISNULL(a.tags) or trim(a.tags) = "")
</when>
<otherwise>
<if test="params.tagsList != null &amp;&amp; params.tagsList.size()>0" >
and
<foreach collection="params.tagsList" index="index" item="item" separator="and">
instr(a.tags, #{item}) &gt; 0
</foreach>
</if>
</otherwise>
</choose>
</select>
<select id="selectHostInfosByCodition" resultMap="BaseResultMap">
... ... @@ -164,12 +171,20 @@
<if test="params.hostIp != null &amp;&amp; params.hostIp != ''" >
and a.host_ip = #{params.hostIp}
</if>
<if test="params.tagsList != null &amp;&amp; params.tagsList.size > 0" >
and
<foreach collection="params.tagsList" index="index" item="item" separator="and">
<choose>
<when test="params.onlyShowTagsIsNull != null &amp;&amp; params.onlyShowTagsIsNull != '' ">
and ( ISNULL(a.tags) or trim(a.tags) = "")
</when>
<otherwise>
<if test="params.tagsList != null &amp;&amp; params.tagsList.size()>0" >
and
<foreach collection="params.tagsList" index="index" item="item" separator="and">
instr(a.tags, #{item}) &gt; 0
</foreach>
</if>
</if>
</otherwise>
</choose>
order by a.create_time desc
limit #{startIndex},#{pageSize}
... ... @@ -266,4 +281,10 @@
delete from host_info
where host_ip = #{ip,jdbcType=VARCHAR}
</delete>
<select id="selectHostIpByCloud" parameterType="java.lang.Integer" resultType="java.lang.String">
select distinct(host_ip)
from host_info
where cloud_type = #{cloudType,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -33,6 +33,14 @@
DELETE FROM mobject_info WHERE id = #{moId}
</delete>
<delete id="deleteMoInfoList">
DELETE FROM mobject_info WHERE id in
<foreach collection="list" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</delete>
<update id="updateMoInfo" parameterType="com.model.MObjectInfo">
UPDATE mobject_info SET alias=#{moName},host_ip=#{moHostIp},type_id=#{moTypeId},tags=#{moTags},url=#{moUrl} WHERE id = #{moId}
</update>
... ...
... ... @@ -10,9 +10,12 @@
<id property="typeName" column="alias"></id>
<id property="typeIsLeaf" column="isLeaf"></id>
<id property="typeParentId" column="parent_id"></id>
<result property="tags" column="tags" jdbcType="VARCHAR" />
<result property="cloudTags" column="cloud_tags" jdbcType="VARCHAR" />
<result property="descr" column="descr" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List"> id, alias, isLeaf, parent_id </sql>
<sql id="Base_Column_List"> id, alias, isLeaf, parent_id ,tags,descr,cloud_tags </sql>
<select id="getAllTypesInfo" resultType="com.model.TypeInfo" resultMap="typeInfoMap">
SELECT
... ... @@ -32,7 +35,7 @@
</select>
<insert id="insertTypeInfo" useGeneratedKeys="true" keyProperty="typeId" parameterType="com.model.TypeInfo">
INSERT INTO type_info(alias,isLeaf,parent_id) VALUES (#{typeName},#{typeIsLeaf},#{typeParentId})
INSERT INTO type_info(alias,isLeaf,parent_id,tags,descr,cloud_tags) VALUES (#{typeName},#{typeIsLeaf},#{typeParentId},#{tags},#{descr},#{cloudTags})
</insert>
<delete id="deleteTypeInfo" parameterType="int">
... ... @@ -44,6 +47,11 @@
WHERE id=#{typeId}
</update>
<update id="updateTypeInfoTag" parameterType="com.model.TypeInfo">
UPDATE type_info SET tags=#{tags},descr=#{descr},cloud_tags=#{cloudTags}
WHERE id=#{typeId}
</update>
<select id="selectTypeInfoByName" resultMap="typeInfoMap" resultType="com.model.TypeInfo">
SELECT
... ...
... ... @@ -5,5 +5,6 @@
<configuration>
<settings>
<setting name="defaultStatementTimeout" value="2"/> <!-- seconds -->
<!--<setting name="logImpl" value="STDOUT_LOGGING" />-->
</settings>
</configuration>
\ No newline at end of file
... ...