Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
PRMS
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengfunan
PRMS
Commits
a1710a9d
Commit
a1710a9d
authored
Jan 13, 2021
by
gaozhentao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
拓扑图查询和修改
parent
d919d2b5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
63 deletions
+99
-63
ReliabilityApi.java
src/main/java/com/yingxin/prms/api/ReliabilityApi.java
+18
-16
WebConfiguration.java
...java/com/yingxin/prms/config/filter/WebConfiguration.java
+3
-1
FlowLine.java
src/main/java/com/yingxin/prms/domain/FlowLine.java
+8
-16
FlowNode.java
src/main/java/com/yingxin/prms/domain/FlowNode.java
+8
-6
Manager.java
src/main/java/com/yingxin/prms/service/business/Manager.java
+47
-19
FlowDaoImpl.java
src/main/java/com/yingxin/prms/service/dao/FlowDaoImpl.java
+15
-5
No files found.
src/main/java/com/yingxin/prms/api/ReliabilityApi.java
View file @
a1710a9d
package
com
.
yingxin
.
prms
.
api
;
package
com
.
yingxin
.
prms
.
api
;
import
com.yingxin.prms.domain.FlowLine
;
import
com.yingxin.prms.domain.FlowNode
;
import
com.yingxin.prms.domain.FlowNode
;
import
com.yingxin.prms.dto.SingleHostStatus
;
import
com.yingxin.prms.service.asyncTask.QueryHostStatusTask
;
import
com.yingxin.prms.service.business.Manager
;
import
com.yingxin.prms.service.business.Manager
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.task.AsyncTaskExecutor
;
import
org.springframework.core.task.AsyncTaskExecutor
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.Future
;
@RestController
@RestController
...
@@ -87,22 +80,31 @@ public class ReliabilityApi {
...
@@ -87,22 +80,31 @@ public class ReliabilityApi {
return
manager
.
selectChart
(
json
);
return
manager
.
selectChart
(
json
);
}
}
/**
/**
* 获取拓扑图数据
* 获取拓扑图
点
数据
*
*
* @return
集群信息json字符串
* @return
*/
*/
@
Pos
tMapping
(
"selectTopology"
)
@
Ge
tMapping
(
"selectTopology"
)
public
List
<
FlowNode
>
selectTopology
(){
public
Map
selectTopology
(){
return
manager
.
selectTopology
();
return
manager
.
selectTopology
();
}
}
/**
/**
* 获取拓扑图数据
* 获取拓扑图
线
数据
*
*
* @return 集群信息json字符串
* @return
*/
// @PostMapping("selectTopologyLine")
// public List<FlowLine> selectTopologyLine(){
// return manager.selectTopologyLine();
// }
/**
* 保存数据
* @return
*/
*/
@PostMapping
(
"saveTopology"
)
@PostMapping
(
"saveTopology"
)
public
Map
saveTopology
(
@RequestBody
String
json
)
throws
Exception
{
public
Map
saveTopology
(
@RequestBody
String
json
)
{
return
manager
.
saveTopology
();
return
manager
.
saveTopology
(
json
);
}
}
}
}
src/main/java/com/yingxin/prms/config/filter/WebConfiguration.java
View file @
a1710a9d
...
@@ -51,7 +51,9 @@ public class WebConfiguration implements WebMvcConfigurer {
...
@@ -51,7 +51,9 @@ public class WebConfiguration implements WebMvcConfigurer {
.
excludePathPatterns
(
"/img/**"
)
.
excludePathPatterns
(
"/img/**"
)
.
excludePathPatterns
(
"/js/**"
)
.
excludePathPatterns
(
"/js/**"
)
.
excludePathPatterns
(
"/index.html"
)
.
excludePathPatterns
(
"/index.html"
)
.
excludePathPatterns
(
"/rest/rel/login"
);
.
excludePathPatterns
(
"/rest/rel/login"
)
.
excludePathPatterns
(
"/rest/rel/selectTopology"
)
.
excludePathPatterns
(
"/rest/rel/saveTopology"
);
WebMvcConfigurer
.
super
.
addInterceptors
(
registry
);
WebMvcConfigurer
.
super
.
addInterceptors
(
registry
);
}
}
...
...
src/main/java/com/yingxin/prms/domain/FlowLine.java
View file @
a1710a9d
package
com
.
yingxin
.
prms
.
domain
;
package
com
.
yingxin
.
prms
.
domain
;
import
org.springframework.data.cassandra.core.cql.PrimaryKeyType
;
import
org.springframework.data.cassandra.core.mapping.Column
;
import
org.springframework.data.cassandra.core.mapping.Column
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKey
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKey
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn
;
import
org.springframework.data.cassandra.core.mapping.Table
;
import
org.springframework.data.cassandra.core.mapping.Table
;
/**
/**
...
@@ -9,13 +11,11 @@ import org.springframework.data.cassandra.core.mapping.Table;
...
@@ -9,13 +11,11 @@ import org.springframework.data.cassandra.core.mapping.Table;
* Datetime: 2021/1/12 9:40
* Datetime: 2021/1/12 9:40
* Author: gaozhentao
* Author: gaozhentao
*/
*/
@Table
(
value
=
"flow
Nod
e"
)
@Table
(
value
=
"flow
lin
e"
)
public
class
FlowLine
{
public
class
FlowLine
{
@PrimaryKey
@PrimaryKey
String
id
;
//主键id
String
cluster_name_left
;
//左集群名称
@Column
(
"cluster_name_left"
)
String
clusterNameLeft
;
//左集群名称
@Column
(
"cluster_name_right"
)
@Column
(
"cluster_name_right"
)
String
clusterNameRight
;
//右集群名称
String
clusterNameRight
;
//右集群名称
@Column
(
"coordinate_left"
)
@Column
(
"coordinate_left"
)
...
@@ -24,20 +24,12 @@ public class FlowLine {
...
@@ -24,20 +24,12 @@ public class FlowLine {
String
coordinateRight
;
//右坐标
String
coordinateRight
;
//右坐标
public
String
get
Id
()
{
public
String
get
Cluster_name_left
()
{
return
id
;
return
cluster_name_left
;
}
}
public
void
setId
(
String
id
)
{
public
void
setCluster_name_left
(
String
cluster_name_left
)
{
this
.
id
=
id
;
this
.
cluster_name_left
=
cluster_name_left
;
}
public
String
getClusterNameLeft
()
{
return
clusterNameLeft
;
}
public
void
setClusterNameLeft
(
String
clusterNameLeft
)
{
this
.
clusterNameLeft
=
clusterNameLeft
;
}
}
public
String
getClusterNameRight
()
{
public
String
getClusterNameRight
()
{
...
...
src/main/java/com/yingxin/prms/domain/FlowNode.java
View file @
a1710a9d
package
com
.
yingxin
.
prms
.
domain
;
package
com
.
yingxin
.
prms
.
domain
;
import
org.springframework.data.cassandra.core.cql.PrimaryKeyType
;
import
org.springframework.data.cassandra.core.mapping.Column
;
import
org.springframework.data.cassandra.core.mapping.Column
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKey
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKey
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn
;
import
org.springframework.data.cassandra.core.mapping.Table
;
import
org.springframework.data.cassandra.core.mapping.Table
;
/**
/**
...
@@ -13,20 +15,20 @@ import org.springframework.data.cassandra.core.mapping.Table;
...
@@ -13,20 +15,20 @@ import org.springframework.data.cassandra.core.mapping.Table;
public
class
FlowNode
{
public
class
FlowNode
{
@PrimaryKey
@PrimaryKey
@Column
(
"cluster_name"
)
//
@Column("cluster_name")
String
cluster
N
ame
;
//集群名称
String
cluster
_n
ame
;
//集群名称
String
coordinate
;
//坐标
String
coordinate
;
//坐标
String
mark
;
//标识
String
mark
;
//标识
@Column
(
"server_path"
)
@Column
(
"server_path"
)
String
serverPath
;
//服务路径
String
serverPath
;
//服务路径
String
faultCount
;
//错误数
String
faultCount
;
//错误数
public
String
getCluster
N
ame
()
{
public
String
getCluster
_n
ame
()
{
return
cluster
N
ame
;
return
cluster
_n
ame
;
}
}
public
void
setCluster
Name
(
String
clusterN
ame
)
{
public
void
setCluster
_name
(
String
cluster_n
ame
)
{
this
.
cluster
Name
=
clusterN
ame
;
this
.
cluster
_name
=
cluster_n
ame
;
}
}
public
String
getCoordinate
()
{
public
String
getCoordinate
()
{
...
...
src/main/java/com/yingxin/prms/service/business/Manager.java
View file @
a1710a9d
package
com
.
yingxin
.
prms
.
service
.
business
;
package
com
.
yingxin
.
prms
.
service
.
business
;
import
com.fasterxml.jackson.databind.util.JSONPObject
;
import
com.yingxin.prms.config.filter.TokenInterceptor
;
import
com.yingxin.prms.config.filter.TokenInterceptor
;
import
com.yingxin.prms.domain.*
;
import
com.yingxin.prms.domain.*
;
import
com.yingxin.prms.dto.*
;
import
com.yingxin.prms.dto.*
;
...
@@ -16,20 +15,15 @@ import org.kairosdb.client.builder.*;
...
@@ -16,20 +15,15 @@ import org.kairosdb.client.builder.*;
import
org.kairosdb.client.response.QueryResponse
;
import
org.kairosdb.client.response.QueryResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
static
sun
.
misc
.
MessageUtils
.
where
;
@Service
@Service
public
class
Manager
{
public
class
Manager
{
...
@@ -39,8 +33,10 @@ public class Manager {
...
@@ -39,8 +33,10 @@ public class Manager {
@Value
(
"${tokeTime}"
)
@Value
(
"${tokeTime}"
)
private
long
tokeTime
;
private
long
tokeTime
;
@Value
(
"${pointNumber}"
)
@Value
(
"${pointNumber}"
)
private
int
pointNumber
;
private
int
pointNumber
;
private
final
AuthModeAndHostList
authModeAndHostList
;
private
final
AuthModeAndHostList
authModeAndHostList
;
private
final
CassandraDaoImpl
cassandraDao
;
private
final
CassandraDaoImpl
cassandraDao
;
...
@@ -398,23 +394,34 @@ public class Manager {
...
@@ -398,23 +394,34 @@ public class Manager {
return
dataPoints
;
return
dataPoints
;
}
}
public
List
<
FlowNode
>
selectTopology
(){
public
Map
selectTopology
(){
List
<
Server_Host_Info
>
serverHostInfoAll
=
authModeAndHostList
.
getClusterBeMonitoredList
();
List
<
Server_Host_Info
>
serverHostInfoAll
=
authModeAndHostList
.
getClusterBeMonitoredList
();
Map
result
=
new
HashMap
();
List
<
FlowNode
>
flowNodeAll
=
flowDao
.
findNodeAll
();
List
<
FlowNode
>
flowNodes
=
flowDao
.
findNodeAll
();
List
<
FlowLine
>
flowLines
=
flowDao
.
findLineAll
();
List
<
FlowNode
>
list
=
new
ArrayList
<>();
List
<
FlowNode
>
list
=
new
ArrayList
<>();
if
(
flowNodeAll
.
size
()>
0
){
if
(
flowNodes
.
size
()>
0
){
list
=
flowNodeAll
;
result
.
put
(
"linkData"
,
flowLines
);
for
(
FlowNode
node
:
flowNodes
){
long
faultCount
=
0
;
try
{
faultCount
=
getFaultCount
(
node
.
getServerPath
());
}
catch
(
Exception
e
)
{
faultCount
=
0
;
}
node
.
setFaultCount
(
String
.
valueOf
(
faultCount
));
}
result
.
put
(
"nodeData"
,
flowNodes
);
}
else
{
}
else
{
Map
<
String
,
String
>
map
=
new
HashMap
();
Map
<
String
,
String
>
map
=
new
HashMap
();
for
(
Server_Host_Info
hostInfo
:
serverHostInfoAll
){
for
(
Server_Host_Info
hostInfo
:
serverHostInfoAll
){
if
(!
map
.
containsKey
(
hostInfo
.
getCluster_name
())){
if
(!
map
.
containsKey
(
hostInfo
.
getCluster_name
())){
map
.
put
(
hostInfo
.
getCluster_name
(),
hostInfo
.
getService_path
());
map
.
put
(
hostInfo
.
getCluster_name
(),
hostInfo
.
getService_path
());
FlowNode
flowNode
=
new
FlowNode
();
FlowNode
flowNode
=
new
FlowNode
();
flowNode
.
setCluster
N
ame
(
hostInfo
.
getCluster_name
());
flowNode
.
setCluster
_n
ame
(
hostInfo
.
getCluster_name
());
flowNode
.
setServerPath
(
hostInfo
.
getService_path
());
flowNode
.
setServerPath
(
hostInfo
.
getService_path
());
flowNode
.
setCoordinate
(
"初始坐标"
);
flowNode
.
setCoordinate
(
"初始坐标"
);
long
faultCount
;
long
faultCount
=
0
;
try
{
try
{
faultCount
=
getFaultCount
(
hostInfo
.
getService_path
());
faultCount
=
getFaultCount
(
hostInfo
.
getService_path
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -431,7 +438,7 @@ public class Manager {
...
@@ -431,7 +438,7 @@ public class Manager {
}
}
}
}
}
}
return
lis
t
;
return
resul
t
;
}
}
private
long
getFaultCount
(
String
servicePath
)
throws
IOException
,
DataFormatException
{
private
long
getFaultCount
(
String
servicePath
)
throws
IOException
,
DataFormatException
{
...
@@ -446,14 +453,35 @@ public class Manager {
...
@@ -446,14 +453,35 @@ public class Manager {
return
dataPointsDay
.
size
()
==
0
?
0
:
dataPointsDay
.
get
(
dataPointsDay
.
size
()
-
1
).
longValue
();
return
dataPointsDay
.
size
()
==
0
?
0
:
dataPointsDay
.
get
(
dataPointsDay
.
size
()
-
1
).
longValue
();
}
}
public
Map
saveTopology
()
{
public
Map
saveTopology
(
String
json
)
{
List
<
Server_Host_Info
>
serverHostInfoAll
=
authModeAndHostList
.
getClusterBeMonitoredList
();
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
json
);
Map
map
=
new
HashMap
();
List
<
Map
<
String
,
String
>>
list
=
jsonObject
.
getJSONArray
(
"list"
);
for
(
Map
<
String
,
String
>
map
:
list
){
if
(
map
!=
null
&&
!
map
.
isEmpty
()){
flowDao
.
updateNode
(
map
.
get
(
"clusterName"
),
map
.
get
(
"coordinate"
),
map
.
get
(
"mark"
));
// String id = UUID.randomUUID().toString();
// FlowLine flowLine = new FlowLine();
// flowLine.setClusterNameLeft(map.get("clusterNameLeft"));
// flowLine.setClusterNameRight(map.get("clusterNameRight"));
// flowLine.setCoordinateLeft(map.get("coordinateLeft"));
// flowLine.setCoordinateRight(map.get("coordinateRight"));
// flowDao.insertLine(flowLine);
}
}
Map
result
=
new
HashMap
();
result
.
put
(
"state"
,
true
);
/*线程池*/
/*线程池*/
for
(
Server_Host_Info
hostInfo
:
serverHostInfoAll
){
return
result
;
}
public
List
<
FlowLine
>
selectTopologyLine
()
{
List
<
FlowLine
>
flowLines
=
flowDao
.
findLineAll
();
if
(
flowLines
.
size
()>
0
){
return
null
;
}
else
{
return
flowLines
;
}
}
return
null
;
}
}
/*
/*
...
...
src/main/java/com/yingxin/prms/service/dao/FlowDaoImpl.java
View file @
a1710a9d
package
com
.
yingxin
.
prms
.
service
.
dao
;
package
com
.
yingxin
.
prms
.
service
.
dao
;
import
com.yingxin.prms.domain.FlowLine
;
import
com.yingxin.prms.domain.FlowNode
;
import
com.yingxin.prms.domain.FlowNode
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.cassandra.core.CassandraTemplate
;
import
org.springframework.data.cassandra.core.CassandraTemplate
;
...
@@ -25,19 +26,28 @@ public class FlowDaoImpl {
...
@@ -25,19 +26,28 @@ public class FlowDaoImpl {
public
void
insertNode
(
FlowNode
flowNode
)
{
public
void
insertNode
(
FlowNode
flowNode
)
{
String
cql
=
"INSERT INTO ctid_prof.flownode(cluster_name, server_path)"
+
String
cql
=
"INSERT INTO ctid_prof.flownode(cluster_name, server_path)"
+
"VALUES('"
+
flowNode
.
getCluster
N
ame
()+
"', '"
+
flowNode
.
getServerPath
()+
"');"
;
"VALUES('"
+
flowNode
.
getCluster
_n
ame
()+
"', '"
+
flowNode
.
getServerPath
()+
"');"
;
template
.
getCqlOperations
().
execute
(
cql
);
template
.
getCqlOperations
().
execute
(
cql
);
}
}
public
boolean
updateNode
(
FlowNode
flowNode
)
{
public
boolean
updateNode
(
String
clusterName
,
String
coordinate
,
String
mark
)
{
String
cql
=
"UPDATE ctid_prof.flownode set coordinate='"
+
flowNode
.
getCoordinate
()+
"', mark='"
+
flowNode
.
getMark
()
+
String
cql
=
"UPDATE ctid_prof.flownode set coordinate='"
+
coordinate
+
"', mark='"
+
mark
+
"' WHERE cluster_name='"
+
flowNode
.
getClusterName
()
+
"'"
;
"' WHERE cluster_name='"
+
clusterName
+
"'"
;
return
template
.
getCqlOperations
().
execute
(
cql
);
return
template
.
getCqlOperations
().
execute
(
cql
);
}
}
public
List
<
FlowNode
>
findNodeAll
()
{
public
List
<
FlowNode
>
findNodeAll
()
{
String
cql
=
"SELECT * FROM ctid_prof.flownode"
;
String
cql
=
"SELECT * FROM ctid_prof.flownode"
;
return
template
.
select
(
cql
,
FlowNode
.
class
);
return
template
.
select
(
cql
,
FlowNode
.
class
);
}
}
public
List
<
FlowLine
>
findLineAll
()
{
String
cql
=
"SELECT * FROM ctid_prof.flowline"
;
return
template
.
select
(
cql
,
FlowLine
.
class
);
}
public
void
insertLine
(
FlowLine
flowLine
)
{
String
cql
=
"update INTO ctid_prof.flowline ( cluster_name_left, cluster_name_right, coordinate_left, coordinate_right)"
+
"VALUES( '"
+
flowLine
.
getCluster_name_left
()+
"', '"
+
flowLine
.
getClusterNameRight
()+
"', '"
+
flowLine
.
getCoordinateLeft
()+
"', '"
+
flowLine
.
getCoordinateRight
()+
"');"
;
template
.
getCqlOperations
().
execute
(
cql
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment