Showing
5 changed files
with
72 additions
and
55 deletions
@@ -18,6 +18,10 @@ | @@ -18,6 +18,10 @@ | ||
18 | <artifactId>monitor-service-common</artifactId> | 18 | <artifactId>monitor-service-common</artifactId> |
19 | </dependency> | 19 | </dependency> |
20 | <dependency> | 20 | <dependency> |
21 | + <groupId>monitor-service</groupId> | ||
22 | + <artifactId>monitor-service-cmdb</artifactId> | ||
23 | + </dependency> | ||
24 | + <dependency> | ||
21 | <groupId>org.springframework</groupId> | 25 | <groupId>org.springframework</groupId> |
22 | <artifactId>spring-context</artifactId> | 26 | <artifactId>spring-context</artifactId> |
23 | </dependency> | 27 | </dependency> |
monitor-service-awstools/src/main/java/com/monitor/cloudtools/service/impl/CloudToolServiceImpl.java
@@ -6,6 +6,7 @@ import com.monitor.cloudtools.model.CommTestResponse; | @@ -6,6 +6,7 @@ import com.monitor.cloudtools.model.CommTestResponse; | ||
6 | import com.monitor.cloudtools.service.CloudToolService; | 6 | import com.monitor.cloudtools.service.CloudToolService; |
7 | import com.monitor.cloudtools.util.CommodUtil; | 7 | import com.monitor.cloudtools.util.CommodUtil; |
8 | import com.monitor.cloudtools.util.HttpConnectUtil; | 8 | import com.monitor.cloudtools.util.HttpConnectUtil; |
9 | +import com.monitor.cmdb.service.impl.TypeInfoServiceImpl; | ||
9 | import com.monitor.model.response.BaseResponse; | 10 | import com.monitor.model.response.BaseResponse; |
10 | import com.monitor.mysql.mapper.*; | 11 | import com.monitor.mysql.mapper.*; |
11 | import org.apache.commons.collections.CollectionUtils; | 12 | import org.apache.commons.collections.CollectionUtils; |
@@ -51,6 +52,9 @@ public class CloudToolServiceImpl implements CloudToolService { | @@ -51,6 +52,9 @@ public class CloudToolServiceImpl implements CloudToolService { | ||
51 | @Autowired | 52 | @Autowired |
52 | private InternalDomainHistoryMapper internalDomainHistoryMapper; | 53 | private InternalDomainHistoryMapper internalDomainHistoryMapper; |
53 | 54 | ||
55 | + @Autowired | ||
56 | + private TypeInfoServiceImpl typeInfoService; | ||
57 | + | ||
54 | 58 | ||
55 | 59 | ||
56 | /** | 60 | /** |
@@ -345,7 +349,7 @@ public class CloudToolServiceImpl implements CloudToolService { | @@ -345,7 +349,7 @@ public class CloudToolServiceImpl implements CloudToolService { | ||
345 | 349 | ||
346 | for(String typeName:typeNames.split("-")){ | 350 | for(String typeName:typeNames.split("-")){ |
347 | mobjectPaths_array[mobjectPaths_array.length-1]=typeName; | 351 | mobjectPaths_array[mobjectPaths_array.length-1]=typeName; |
348 | - TypeInfo typeInfo = getTypeByMobjectPathArray(mobjectPaths_array); | 352 | + TypeInfo typeInfo = typeInfoService.getTypeByMobjectPathArray(mobjectPaths_array); |
349 | if(typeInfo!=null){ | 353 | if(typeInfo!=null){ |
350 | List<MObjectInfo> objectInfoList = mObjectInfoMapper.getTypeMosInfo(typeInfo.getTypeId()); | 354 | List<MObjectInfo> objectInfoList = mObjectInfoMapper.getTypeMosInfo(typeInfo.getTypeId()); |
351 | List<String> existsHostIps=new ArrayList<String>(); | 355 | List<String> existsHostIps=new ArrayList<String>(); |
@@ -451,7 +455,7 @@ public class CloudToolServiceImpl implements CloudToolService { | @@ -451,7 +455,7 @@ public class CloudToolServiceImpl implements CloudToolService { | ||
451 | String typeName=mobjectPaths_array[mobjectPaths_array.length-1]; | 455 | String typeName=mobjectPaths_array[mobjectPaths_array.length-1]; |
452 | 456 | ||
453 | //1:获取的type ,用来做type_id | 457 | //1:获取的type ,用来做type_id |
454 | - TypeInfo typeInfo = getTypeByMobjectPathArray(mobjectPaths_array); | 458 | + TypeInfo typeInfo = typeInfoService.getTypeByMobjectPathArray(mobjectPaths_array); |
455 | if(typeInfo==null){ | 459 | if(typeInfo==null){ |
456 | res.setData("无法获取typeinfo信息:"+mobjectPaths); | 460 | res.setData("无法获取typeinfo信息:"+mobjectPaths); |
457 | return res; | 461 | return res; |
@@ -516,7 +520,7 @@ public class CloudToolServiceImpl implements CloudToolService { | @@ -516,7 +520,7 @@ public class CloudToolServiceImpl implements CloudToolService { | ||
516 | String typeName=mobjectPaths_array[mobjectPaths_array.length-1]; | 520 | String typeName=mobjectPaths_array[mobjectPaths_array.length-1]; |
517 | 521 | ||
518 | //1:获取的type ,用来做type_id | 522 | //1:获取的type ,用来做type_id |
519 | - TypeInfo typeInfo =getTypeByMobjectPathArray(mobjectPaths_array); | 523 | + TypeInfo typeInfo =typeInfoService.getTypeByMobjectPathArray(mobjectPaths_array); |
520 | if(typeInfo==null){ | 524 | if(typeInfo==null){ |
521 | res.setData("无法获取typeinfo信息:"+mobjectPaths); | 525 | res.setData("无法获取typeinfo信息:"+mobjectPaths); |
522 | return res; | 526 | return res; |
@@ -566,48 +570,6 @@ public class CloudToolServiceImpl implements CloudToolService { | @@ -566,48 +570,6 @@ public class CloudToolServiceImpl implements CloudToolService { | ||
566 | return res; | 570 | return res; |
567 | } | 571 | } |
568 | 572 | ||
569 | - private TypeInfo getTypeByMobjectPathArray(String[] mobjectPaths_array){ | ||
570 | - String typeName=mobjectPaths_array[mobjectPaths_array.length-1]; | ||
571 | - List<TypeInfo> typeInfoList=mTypeInfoMapper.selectAllTypeInfoByName(typeName); | ||
572 | - if(typeInfoList==null||typeInfoList.size()<=0){ | ||
573 | - return null; | ||
574 | - } | ||
575 | - | ||
576 | - if(typeInfoList.size()==1){ | ||
577 | - return typeInfoList.get(0); | ||
578 | - }else{ | ||
579 | - //// 名字多于一个的时候,就要根据路径查询 | ||
580 | - String topName=mobjectPaths_array[0]; | ||
581 | - List<TypeInfo> typeInfoList_top=mTypeInfoMapper.selectAllTypeInfoByName(topName); | ||
582 | - if(typeInfoList_top==null||typeInfoList_top.size()!=1){ | ||
583 | - logger.error("typeinfo配置错误:存在零或者多条"+topName); | ||
584 | - return null; | ||
585 | - } | ||
586 | - | ||
587 | - int parentTypeID=typeInfoList_top.get(0).getTypeId(); | ||
588 | - TypeInfo targetTypeInfo=null; | ||
589 | - //循环从1开始 | ||
590 | - for(int i=1;i<mobjectPaths_array.length;i++){ | ||
591 | - List<TypeInfo> typeInfoList_tmp=mTypeInfoMapper.selectAllTypeInfoByName(mobjectPaths_array[i]); | ||
592 | - if(typeInfoList_tmp==null||typeInfoList_tmp.size()<=0){ | ||
593 | - logger.error("typeinfo配置错误:没有配置"+typeName); | ||
594 | - return null; | ||
595 | - } | ||
596 | - for(TypeInfo typeInfo:typeInfoList_tmp){ | ||
597 | - if(parentTypeID==typeInfo.getTypeParentId()){ | ||
598 | - parentTypeID=typeInfo.getTypeId(); | ||
599 | - if(i==mobjectPaths_array.length-1){ | ||
600 | - //最后一次循环 | ||
601 | - targetTypeInfo=typeInfo; | ||
602 | - } | ||
603 | - break; | ||
604 | - } | ||
605 | - } | ||
606 | - } | ||
607 | - return targetTypeInfo; | ||
608 | - } | ||
609 | - } | ||
610 | - | ||
611 | public BaseResponse updateNginxConfig(AutoScalingInfoReq infoReq){ | 573 | public BaseResponse updateNginxConfig(AutoScalingInfoReq infoReq){ |
612 | BaseResponse response=new BaseResponse(); | 574 | BaseResponse response=new BaseResponse(); |
613 | String commond = "ssh master@172.31.16.167 sh /home/master/nginx-sync/update-java-nginx.sh"; | 575 | String commond = "ssh master@172.31.16.167 sh /home/master/nginx-sync/update-java-nginx.sh"; |
@@ -321,7 +321,7 @@ public class TypeInfoCtrl { | @@ -321,7 +321,7 @@ public class TypeInfoCtrl { | ||
321 | 321 | ||
322 | BaseResponse response = new BaseResponse(); | 322 | BaseResponse response = new BaseResponse(); |
323 | try { | 323 | try { |
324 | - allTypeInfo = typeInfoService.getChildById(); | 324 | + allTypeInfo = typeInfoService.getZkTree(); |
325 | 325 | ||
326 | if (null != allTypeInfo) { | 326 | if (null != allTypeInfo) { |
327 | 327 |
@@ -24,6 +24,10 @@ public interface ITypeInfoService { | @@ -24,6 +24,10 @@ public interface ITypeInfoService { | ||
24 | 24 | ||
25 | TypeInfo queryTypeInfoByName(String typeName); | 25 | TypeInfo queryTypeInfoByName(String typeName); |
26 | 26 | ||
27 | - List<TypeInfo> getChildById(); | 27 | + List<TypeInfo> getZkTree(); |
28 | + | ||
29 | + | ||
30 | + //根据路径数据查询配置 | ||
31 | + TypeInfo getTypeByMobjectPathArray(String[] mobjectPaths_array); | ||
28 | 32 | ||
29 | } | 33 | } |
1 | package com.monitor.cmdb.service.impl; | 1 | package com.monitor.cmdb.service.impl; |
2 | 2 | ||
3 | -import java.util.ArrayList; | ||
4 | -import java.util.List; | ||
5 | - | ||
6 | -import org.springframework.beans.factory.annotation.Autowired; | ||
7 | -import org.springframework.stereotype.Service; | ||
8 | - | ||
9 | import com.model.TypeInfo; | 3 | import com.model.TypeInfo; |
10 | import com.monitor.cmdb.service.ITypeInfoService; | 4 | import com.monitor.cmdb.service.ITypeInfoService; |
11 | import com.monitor.mysql.mapper.MObjectInfoMapper; | 5 | import com.monitor.mysql.mapper.MObjectInfoMapper; |
12 | import com.monitor.mysql.mapper.MTypeInfoMapper; | 6 | import com.monitor.mysql.mapper.MTypeInfoMapper; |
7 | +import org.slf4j.Logger; | ||
8 | +import org.slf4j.LoggerFactory; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import java.util.ArrayList; | ||
13 | +import java.util.List; | ||
13 | 14 | ||
14 | /** | 15 | /** |
15 | * Created by yoho on 2016/6/15. | 16 | * Created by yoho on 2016/6/15. |
@@ -17,6 +18,8 @@ import com.monitor.mysql.mapper.MTypeInfoMapper; | @@ -17,6 +18,8 @@ import com.monitor.mysql.mapper.MTypeInfoMapper; | ||
17 | @Service | 18 | @Service |
18 | public class TypeInfoServiceImpl implements ITypeInfoService { | 19 | public class TypeInfoServiceImpl implements ITypeInfoService { |
19 | 20 | ||
21 | + public static final Logger logger = LoggerFactory.getLogger(TypeInfoServiceImpl.class); | ||
22 | + | ||
20 | @Autowired | 23 | @Autowired |
21 | MTypeInfoMapper mTypeInfoMapper; | 24 | MTypeInfoMapper mTypeInfoMapper; |
22 | 25 | ||
@@ -88,9 +91,10 @@ public class TypeInfoServiceImpl implements ITypeInfoService { | @@ -88,9 +91,10 @@ public class TypeInfoServiceImpl implements ITypeInfoService { | ||
88 | } | 91 | } |
89 | 92 | ||
90 | @Override | 93 | @Override |
91 | - public List<TypeInfo> getChildById() { | 94 | + public List<TypeInfo> getZkTree() { |
92 | List<TypeInfo> list= new ArrayList<TypeInfo>(); | 95 | List<TypeInfo> list= new ArrayList<TypeInfo>(); |
93 | - TypeInfo typeInfo=mTypeInfoMapper.selectTypeInfoByName("zookeeper"); | 96 | + //YOHO,middleware,zookeeper |
97 | + TypeInfo typeInfo=this.getTypeByMobjectPathArray("YOHO,middleware,zookeeper".split(",")); | ||
94 | typeInfo.setTypeParentId(0); | 98 | typeInfo.setTypeParentId(0); |
95 | list.add(typeInfo); | 99 | list.add(typeInfo); |
96 | List<TypeInfo> listInfo=mTypeInfoMapper.getChildTypesInfo(typeInfo.getTypeId()); | 100 | List<TypeInfo> listInfo=mTypeInfoMapper.getChildTypesInfo(typeInfo.getTypeId()); |
@@ -104,6 +108,49 @@ public class TypeInfoServiceImpl implements ITypeInfoService { | @@ -104,6 +108,49 @@ public class TypeInfoServiceImpl implements ITypeInfoService { | ||
104 | 108 | ||
105 | return list; | 109 | return list; |
106 | } | 110 | } |
111 | + | ||
112 | + @Override | ||
113 | + public TypeInfo getTypeByMobjectPathArray(String[] mobjectPaths_array){ | ||
114 | + String typeName=mobjectPaths_array[mobjectPaths_array.length-1]; | ||
115 | + List<TypeInfo> typeInfoList=mTypeInfoMapper.selectAllTypeInfoByName(typeName); | ||
116 | + if(typeInfoList==null||typeInfoList.size()<=0){ | ||
117 | + return null; | ||
118 | + } | ||
119 | + | ||
120 | + if(typeInfoList.size()==1){ | ||
121 | + return typeInfoList.get(0); | ||
122 | + }else{ | ||
123 | + //// 名字多于一个的时候,就要根据路径查询 | ||
124 | + String topName=mobjectPaths_array[0]; | ||
125 | + List<TypeInfo> typeInfoList_top=mTypeInfoMapper.selectAllTypeInfoByName(topName); | ||
126 | + if(typeInfoList_top==null||typeInfoList_top.size()!=1){ | ||
127 | + logger.error("typeinfo配置错误:存在零或者多条"+topName); | ||
128 | + return null; | ||
129 | + } | ||
130 | + | ||
131 | + int parentTypeID=typeInfoList_top.get(0).getTypeId(); | ||
132 | + TypeInfo targetTypeInfo=null; | ||
133 | + //循环从1开始 | ||
134 | + for(int i=1;i<mobjectPaths_array.length;i++){ | ||
135 | + List<TypeInfo> typeInfoList_tmp=mTypeInfoMapper.selectAllTypeInfoByName(mobjectPaths_array[i]); | ||
136 | + if(typeInfoList_tmp==null||typeInfoList_tmp.size()<=0){ | ||
137 | + logger.error("typeinfo配置错误:没有配置"+typeName); | ||
138 | + return null; | ||
139 | + } | ||
140 | + for(TypeInfo typeInfo:typeInfoList_tmp){ | ||
141 | + if(parentTypeID==typeInfo.getTypeParentId()){ | ||
142 | + parentTypeID=typeInfo.getTypeId(); | ||
143 | + if(i==mobjectPaths_array.length-1){ | ||
144 | + //最后一次循环 | ||
145 | + targetTypeInfo=typeInfo; | ||
146 | + } | ||
147 | + break; | ||
148 | + } | ||
149 | + } | ||
150 | + } | ||
151 | + return targetTypeInfo; | ||
152 | + } | ||
153 | + } | ||
107 | 154 | ||
108 | 155 | ||
109 | } | 156 | } |
-
Please register or login to post a comment