Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-service
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
qinchao
7 years ago
Commit
07e6bc8ddfebaef837b70b2ab1018059b27c4a27
1 parent
0c6c5ffc
优化代码
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
55 deletions
monitor-service-awstools/pom.xml
monitor-service-awstools/src/main/java/com/monitor/cloudtools/service/impl/CloudToolServiceImpl.java
monitor-service-cmdb/src/main/java/com/monitor/cmdb/ctrl/TypeInfoCtrl.java
monitor-service-cmdb/src/main/java/com/monitor/cmdb/service/ITypeInfoService.java
monitor-service-cmdb/src/main/java/com/monitor/cmdb/service/impl/TypeInfoServiceImpl.java
monitor-service-awstools/pom.xml
View file @
07e6bc8
...
...
@@ -18,6 +18,10 @@
<artifactId>
monitor-service-common
</artifactId>
</dependency>
<dependency>
<groupId>
monitor-service
</groupId>
<artifactId>
monitor-service-cmdb
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
</dependency>
...
...
monitor-service-awstools/src/main/java/com/monitor/cloudtools/service/impl/CloudToolServiceImpl.java
View file @
07e6bc8
...
...
@@ -6,6 +6,7 @@ import com.monitor.cloudtools.model.CommTestResponse;
import
com.monitor.cloudtools.service.CloudToolService
;
import
com.monitor.cloudtools.util.CommodUtil
;
import
com.monitor.cloudtools.util.HttpConnectUtil
;
import
com.monitor.cmdb.service.impl.TypeInfoServiceImpl
;
import
com.monitor.model.response.BaseResponse
;
import
com.monitor.mysql.mapper.*
;
import
org.apache.commons.collections.CollectionUtils
;
...
...
@@ -51,6 +52,9 @@ public class CloudToolServiceImpl implements CloudToolService {
@Autowired
private
InternalDomainHistoryMapper
internalDomainHistoryMapper
;
@Autowired
private
TypeInfoServiceImpl
typeInfoService
;
/**
...
...
@@ -345,7 +349,7 @@ public class CloudToolServiceImpl implements CloudToolService {
for
(
String
typeName:
typeNames
.
split
(
"-"
)){
mobjectPaths_array
[
mobjectPaths_array
.
length
-
1
]=
typeName
;
TypeInfo
typeInfo
=
getTypeByMobjectPathArray
(
mobjectPaths_array
);
TypeInfo
typeInfo
=
typeInfoService
.
getTypeByMobjectPathArray
(
mobjectPaths_array
);
if
(
typeInfo
!=
null
){
List
<
MObjectInfo
>
objectInfoList
=
mObjectInfoMapper
.
getTypeMosInfo
(
typeInfo
.
getTypeId
());
List
<
String
>
existsHostIps
=
new
ArrayList
<
String
>();
...
...
@@ -451,7 +455,7 @@ public class CloudToolServiceImpl implements CloudToolService {
String
typeName
=
mobjectPaths_array
[
mobjectPaths_array
.
length
-
1
];
//1:获取的type ,用来做type_id
TypeInfo
typeInfo
=
getTypeByMobjectPathArray
(
mobjectPaths_array
);
TypeInfo
typeInfo
=
typeInfoService
.
getTypeByMobjectPathArray
(
mobjectPaths_array
);
if
(
typeInfo
==
null
){
res
.
setData
(
"无法获取typeinfo信息:"
+
mobjectPaths
);
return
res
;
...
...
@@ -516,7 +520,7 @@ public class CloudToolServiceImpl implements CloudToolService {
String
typeName
=
mobjectPaths_array
[
mobjectPaths_array
.
length
-
1
];
//1:获取的type ,用来做type_id
TypeInfo
typeInfo
=
getTypeByMobjectPathArray
(
mobjectPaths_array
);
TypeInfo
typeInfo
=
typeInfoService
.
getTypeByMobjectPathArray
(
mobjectPaths_array
);
if
(
typeInfo
==
null
){
res
.
setData
(
"无法获取typeinfo信息:"
+
mobjectPaths
);
return
res
;
...
...
@@ -566,48 +570,6 @@ public class CloudToolServiceImpl implements CloudToolService {
return
res
;
}
private
TypeInfo
getTypeByMobjectPathArray
(
String
[]
mobjectPaths_array
){
String
typeName
=
mobjectPaths_array
[
mobjectPaths_array
.
length
-
1
];
List
<
TypeInfo
>
typeInfoList
=
mTypeInfoMapper
.
selectAllTypeInfoByName
(
typeName
);
if
(
typeInfoList
==
null
||
typeInfoList
.
size
()<=
0
){
return
null
;
}
if
(
typeInfoList
.
size
()==
1
){
return
typeInfoList
.
get
(
0
);
}
else
{
//// 名字多于一个的时候,就要根据路径查询
String
topName
=
mobjectPaths_array
[
0
];
List
<
TypeInfo
>
typeInfoList_top
=
mTypeInfoMapper
.
selectAllTypeInfoByName
(
topName
);
if
(
typeInfoList_top
==
null
||
typeInfoList_top
.
size
()!=
1
){
logger
.
error
(
"typeinfo配置错误:存在零或者多条"
+
topName
);
return
null
;
}
int
parentTypeID
=
typeInfoList_top
.
get
(
0
).
getTypeId
();
TypeInfo
targetTypeInfo
=
null
;
//循环从1开始
for
(
int
i
=
1
;
i
<
mobjectPaths_array
.
length
;
i
++){
List
<
TypeInfo
>
typeInfoList_tmp
=
mTypeInfoMapper
.
selectAllTypeInfoByName
(
mobjectPaths_array
[
i
]);
if
(
typeInfoList_tmp
==
null
||
typeInfoList_tmp
.
size
()<=
0
){
logger
.
error
(
"typeinfo配置错误:没有配置"
+
typeName
);
return
null
;
}
for
(
TypeInfo
typeInfo:
typeInfoList_tmp
){
if
(
parentTypeID
==
typeInfo
.
getTypeParentId
()){
parentTypeID
=
typeInfo
.
getTypeId
();
if
(
i
==
mobjectPaths_array
.
length
-
1
){
//最后一次循环
targetTypeInfo
=
typeInfo
;
}
break
;
}
}
}
return
targetTypeInfo
;
}
}
public
BaseResponse
updateNginxConfig
(
AutoScalingInfoReq
infoReq
){
BaseResponse
response
=
new
BaseResponse
();
String
commond
=
"ssh master@172.31.16.167 sh /home/master/nginx-sync/update-java-nginx.sh"
;
...
...
monitor-service-cmdb/src/main/java/com/monitor/cmdb/ctrl/TypeInfoCtrl.java
View file @
07e6bc8
...
...
@@ -321,7 +321,7 @@ public class TypeInfoCtrl {
BaseResponse
response
=
new
BaseResponse
();
try
{
allTypeInfo
=
typeInfoService
.
get
ChildById
();
allTypeInfo
=
typeInfoService
.
get
ZkTree
();
if
(
null
!=
allTypeInfo
)
{
...
...
monitor-service-cmdb/src/main/java/com/monitor/cmdb/service/ITypeInfoService.java
View file @
07e6bc8
...
...
@@ -24,6 +24,10 @@ public interface ITypeInfoService {
TypeInfo
queryTypeInfoByName
(
String
typeName
);
List
<
TypeInfo
>
getChildById
();
List
<
TypeInfo
>
getZkTree
();
//根据路径数据查询配置
TypeInfo
getTypeByMobjectPathArray
(
String
[]
mobjectPaths_array
);
}
...
...
monitor-service-cmdb/src/main/java/com/monitor/cmdb/service/impl/TypeInfoServiceImpl.java
View file @
07e6bc8
package
com
.
monitor
.
cmdb
.
service
.
impl
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.model.TypeInfo
;
import
com.monitor.cmdb.service.ITypeInfoService
;
import
com.monitor.mysql.mapper.MObjectInfoMapper
;
import
com.monitor.mysql.mapper.MTypeInfoMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by yoho on 2016/6/15.
...
...
@@ -17,6 +18,8 @@ import com.monitor.mysql.mapper.MTypeInfoMapper;
@Service
public
class
TypeInfoServiceImpl
implements
ITypeInfoService
{
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
TypeInfoServiceImpl
.
class
);
@Autowired
MTypeInfoMapper
mTypeInfoMapper
;
...
...
@@ -88,9 +91,10 @@ public class TypeInfoServiceImpl implements ITypeInfoService {
}
@Override
public
List
<
TypeInfo
>
get
ChildById
()
{
public
List
<
TypeInfo
>
get
ZkTree
()
{
List
<
TypeInfo
>
list
=
new
ArrayList
<
TypeInfo
>();
TypeInfo
typeInfo
=
mTypeInfoMapper
.
selectTypeInfoByName
(
"zookeeper"
);
//YOHO,middleware,zookeeper
TypeInfo
typeInfo
=
this
.
getTypeByMobjectPathArray
(
"YOHO,middleware,zookeeper"
.
split
(
","
));
typeInfo
.
setTypeParentId
(
0
);
list
.
add
(
typeInfo
);
List
<
TypeInfo
>
listInfo
=
mTypeInfoMapper
.
getChildTypesInfo
(
typeInfo
.
getTypeId
());
...
...
@@ -104,6 +108,49 @@ public class TypeInfoServiceImpl implements ITypeInfoService {
return
list
;
}
@Override
public
TypeInfo
getTypeByMobjectPathArray
(
String
[]
mobjectPaths_array
){
String
typeName
=
mobjectPaths_array
[
mobjectPaths_array
.
length
-
1
];
List
<
TypeInfo
>
typeInfoList
=
mTypeInfoMapper
.
selectAllTypeInfoByName
(
typeName
);
if
(
typeInfoList
==
null
||
typeInfoList
.
size
()<=
0
){
return
null
;
}
if
(
typeInfoList
.
size
()==
1
){
return
typeInfoList
.
get
(
0
);
}
else
{
//// 名字多于一个的时候,就要根据路径查询
String
topName
=
mobjectPaths_array
[
0
];
List
<
TypeInfo
>
typeInfoList_top
=
mTypeInfoMapper
.
selectAllTypeInfoByName
(
topName
);
if
(
typeInfoList_top
==
null
||
typeInfoList_top
.
size
()!=
1
){
logger
.
error
(
"typeinfo配置错误:存在零或者多条"
+
topName
);
return
null
;
}
int
parentTypeID
=
typeInfoList_top
.
get
(
0
).
getTypeId
();
TypeInfo
targetTypeInfo
=
null
;
//循环从1开始
for
(
int
i
=
1
;
i
<
mobjectPaths_array
.
length
;
i
++){
List
<
TypeInfo
>
typeInfoList_tmp
=
mTypeInfoMapper
.
selectAllTypeInfoByName
(
mobjectPaths_array
[
i
]);
if
(
typeInfoList_tmp
==
null
||
typeInfoList_tmp
.
size
()<=
0
){
logger
.
error
(
"typeinfo配置错误:没有配置"
+
typeName
);
return
null
;
}
for
(
TypeInfo
typeInfo:
typeInfoList_tmp
){
if
(
parentTypeID
==
typeInfo
.
getTypeParentId
()){
parentTypeID
=
typeInfo
.
getTypeId
();
if
(
i
==
mobjectPaths_array
.
length
-
1
){
//最后一次循环
targetTypeInfo
=
typeInfo
;
}
break
;
}
}
}
return
targetTypeInfo
;
}
}
}
...
...
Please
register
or
login
to post a comment