Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Distributed Computing and Network Fusion System
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WirelessInformationCollaborate
Distributed Computing and Network Fusion System
Commits
c670b34e
Commit
c670b34e
authored
Mar 23, 2020
by
wutu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善论文测试内容
parent
712d0b5a
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
636 additions
and
23 deletions
+636
-23
bishe-case-dis/pom.xml
bishe-case-dis/pom.xml
+70
-0
bishe-case-dis/src/main/java/top/ninwoo/BisheTestMain.java
bishe-case-dis/src/main/java/top/ninwoo/BisheTestMain.java
+1
-1
bishe-case-dis/src/main/java/top/ninwoo/controller/TestController.java
...s/src/main/java/top/ninwoo/controller/TestController.java
+63
-0
bishe-case-dis/src/main/resources/application.properties
bishe-case-dis/src/main/resources/application.properties
+2
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkService.java
...java/top/ninwoo/bishe/starter/service/NetworkService.java
+2
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkServiceImpl.java
.../top/ninwoo/bishe/starter/service/NetworkServiceImpl.java
+14
-1
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/controller/NetworkController.java
.../top/ninwoo/cloudcenter/controller/NetworkController.java
+5
-0
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/CloudService.java
...ain/java/top/ninwoo/cloudcenter/service/CloudService.java
+2
-0
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
...top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
+21
-1
bishe-cloud-center/src/main/resources/application.yml
bishe-cloud-center/src/main/resources/application.yml
+2
-2
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/service/impl/IpServiceImpl.java
...op/ninwoo/cloud/ipservice/service/impl/IpServiceImpl.java
+1
-1
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
...ava/top/ninwoo/edgecenter/controller/IndexController.java
+32
-6
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/TopologyServiceImpl.java
...p/ninwoo/edgecenter/service/impl/TopologyServiceImpl.java
+4
-0
bishe-edge-center/src/main/resources/application.yaml
bishe-edge-center/src/main/resources/application.yaml
+4
-4
bishe-test/pom.xml
bishe-test/pom.xml
+9
-0
bishe-test/src/main/java/top/ninwoo/client/BisheTestMain.java
...e-test/src/main/java/top/ninwoo/client/BisheTestMain.java
+11
-0
bishe-test/src/main/java/top/ninwoo/client/controller/TestController.java
...ain/java/top/ninwoo/client/controller/TestController.java
+63
-0
bishe-test/src/main/resources/application.properties
bishe-test/src/main/resources/application.properties
+1
-1
bishe-test/src/test/java/top/ninwoo/BisheMultiNodeTests.java
bishe-test/src/test/java/top/ninwoo/BisheMultiNodeTests.java
+74
-3
bishe-test/src/test/java/top/ninwoo/BisheTests.java
bishe-test/src/test/java/top/ninwoo/BisheTests.java
+1
-1
bishe-test/src/test/java/top/ninwoo/LunWenTests.java
bishe-test/src/test/java/top/ninwoo/LunWenTests.java
+251
-0
bishe-utils/src/main/java/top/ninwoo/utils/service/impl/TcServiceImpl.java
...ain/java/top/ninwoo/utils/service/impl/TcServiceImpl.java
+2
-2
pom.xml
pom.xml
+1
-0
No files found.
bishe-case-dis/pom.xml
0 → 100644
View file @
c670b34e
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
bishe
</artifactId>
<groupId>
top.ninwoo
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
bishe-case-dis
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<version>
2.1.2.RELEASE
</version>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
bishe-client-starter
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<version>
2.1.2.RELEASE
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-shade-plugin
</artifactId>
<version>
1.2.1
</version>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
shade
</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"
>
<mainClass>
top.ninwoo.BisheTestMain
</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
bishe-
test/src/main/java/top/ninwoo/test
/BisheTestMain.java
→
bishe-
case-dis/src/main/java/top/ninwoo
/BisheTestMain.java
View file @
c670b34e
package
top.ninwoo
.test
;
package
top.ninwoo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
bishe-case-dis/src/main/java/top/ninwoo/controller/TestController.java
0 → 100644
View file @
c670b34e
package
top.ninwoo.controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
javax.annotation.Resource
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
@RestController
public
class
TestController
{
@Resource
private
NetworkService
networkService
;
@GetMapping
(
"/start"
)
public
String
start
(
String
ip
,
String
t
,
String
selfName
,
String
targetName
,
float
div
)
{
int
i
=
(
int
)
(
40
*
div
);
networkService
.
addQos
(
11111L
,
targetName
,
i
+
"mbit"
,
"100ms"
);
networkService
.
addQos
(
11111L
,
selfName
,
(
40
-
i
)
+
"mbit"
,
"100ms"
);
runCmd
(
"iperf -c "
+
ip
+
" -t "
+
t
);
networkService
.
addQos
(
11111L
,
targetName
,
"40mbit"
,
"100ms"
);
return
"success"
;
}
private
String
runCmd
(
String
cmd
)
{
String
result
=
""
;
try
{
Process
exec
=
Runtime
.
getRuntime
().
exec
(
new
String
[]{
"/bin/sh"
,
"-c"
,
cmd
});
exec
.
waitFor
();
InputStream
in
=
exec
.
getInputStream
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
String
msg
;
while
((
msg
=
br
.
readLine
())!=
null
&&
msg
.
length
()
>
0
)
{
result
+=
msg
+
"\n"
;
}
if
(
""
.
equals
(
result
))
{
// 构建Error
InputStream
errorStream
=
exec
.
getErrorStream
();
BufferedReader
ebr
=
new
BufferedReader
(
new
InputStreamReader
(
errorStream
));
String
eMsg
;
while
((
eMsg
=
ebr
.
readLine
())!=
null
&&
eMsg
.
length
()
>
0
)
{
result
+=
eMsg
+
"\n"
;
}
if
(
result
.
equals
(
""
))
{
return
result
;
}
result
=
"Error: "
+
result
;
}
if
(
result
.
length
()
>
0
)
{
result
=
result
.
substring
(
0
,
result
.
length
()-
1
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
}
bishe-case-dis/src/main/resources/application.properties
0 → 100644
View file @
c670b34e
bishe.app.app-name
=
dis
bishe.app.cloud-url
=
192.168.0.108:9091
\ No newline at end of file
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkService.java
View file @
c670b34e
...
...
@@ -9,6 +9,8 @@ import java.util.List;
* 网络服务接口
*/
public
interface
NetworkService
{
boolean
addQos
(
Long
clusterId
,
String
appName
,
String
maxRate
,
String
latency
);
/**
* 获取逻辑网络拓扑
* @param clusterId
...
...
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkServiceImpl.java
View file @
c670b34e
...
...
@@ -31,13 +31,26 @@ public class NetworkServiceImpl implements NetworkService {
private
final
static
String
CANCEL_NETWORK_MONITOR
=
"/network/cancelNetworkMonitor?clusterId={clusterId}&appName={appName}"
;
private
final
static
String
GET_NETWORK_MONITOR_INFO
=
"/network/getNetworkMonitorInfo?clusterId={clusterId}&appName={appName}"
;
private
final
static
String
ADD_QOS
=
"/network/addQos?clusterId={clusterId}&appName={appName}&maxRate={maxRate}&latency={latency}"
;
@Resource
ClientProperties
clientProperties
;
@Resource
RestTemplate
restTemplate
;
@Override
public
boolean
addQos
(
Long
clusterId
,
String
appName
,
String
maxRate
,
String
latency
)
{
String
cloudUrl
=
clientProperties
.
getCloudUrl
();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"appName"
,
appName
);
param
.
put
(
"maxRate"
,
maxRate
);
param
.
put
(
"latency"
,
latency
);
return
restTemplate
.
getForObject
(
"http://"
+
cloudUrl
+
ADD_QOS
,
Boolean
.
class
,
param
);
}
@Override
public
NetworkTopology
getLogicalNetworkTopology
(
Long
clusterId
)
{
String
cloudUrl
=
clientProperties
.
getCloudUrl
();
...
...
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/controller/NetworkController.java
View file @
c670b34e
...
...
@@ -44,4 +44,9 @@ public class NetworkController {
// 这里可以理解为是返回一个网络监控的钩子程序,具体的查询还需要通过钩子进行执行
return
cloudService
.
getContainerMonitorInfoByAppName
(
clusterId
,
appName
);
}
@RequestMapping
(
value
=
"/addQos"
)
public
Boolean
addQos
(
Long
clusterId
,
String
appName
,
String
maxRate
,
String
latency
)
{
return
cloudService
.
addQos
(
clusterId
,
appName
,
maxRate
,
latency
);
}
}
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/CloudService.java
View file @
c670b34e
...
...
@@ -34,5 +34,7 @@ public interface CloudService {
List
<
String
>
getEdgeNodeIds
();
Boolean
addQos
(
Long
clusterId
,
String
appName
,
String
maxRate
,
String
latency
);
boolean
adjustCluster
(
List
<
SeparatedClusterConfig
>
clusterConfigs
);
}
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
View file @
c670b34e
...
...
@@ -26,7 +26,7 @@ public class CloudServiceImpl implements CloudService {
private
static
final
String
REMOTE_IP_LIST_BY_APPNAME
=
"/getIpListByAppName?clusterId={clusterId}&appName={appName}"
;
private
static
final
String
ENABLE_NETWORK_MONITOR
=
"/enableContainerMonitor?clusterId={clusterId}&containerName={appName}"
;
private
static
final
String
CANCEL_NETWORK_MONITOR
=
"/cancelNetworkMonitor?clusterId={clusterId}&containerName={appName}"
;
private
static
final
String
ADD_QOS
=
"/addQos?clusterId={clusterId}&cName={cName}&maxRate={maxRate}&latency={latency}"
;
private
static
final
ExecutorService
initEdgeExecutorPool
=
Executors
.
newFixedThreadPool
(
6
*
2
);
private
static
final
CompletionService
<
ThreadResult
>
initEdgeExcutorCompletionPool
=
new
ExecutorCompletionService
<>(
initEdgeExecutorPool
);
...
...
@@ -49,6 +49,26 @@ public class CloudServiceImpl implements CloudService {
@Resource
private
RestTemplate
restTemplate
;
@Override
public
Boolean
addQos
(
Long
clusterId
,
String
appName
,
String
maxRate
,
String
latency
)
{
Map
<
String
,
Map
<
String
,
Set
<
String
>>>
stringMapMap
=
allContainerIds
.
get
(
clusterId
);
String
nodeId
=
null
;
for
(
String
s
:
stringMapMap
.
keySet
())
{
if
(
stringMapMap
.
get
(
s
).
keySet
().
contains
(
appName
))
{
nodeId
=
s
;
}
}
if
(
nodeId
==
null
)
{
throw
new
RuntimeException
(
"无法找到可以使用的节点"
);
}
HashMap
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"cName"
,
appName
);
param
.
put
(
"maxRate"
,
maxRate
);
param
.
put
(
"latency"
,
latency
);
Boolean
res
=
restTemplate
.
getForObject
(
"http://"
+
nodeId
+
ADD_QOS
,
Boolean
.
class
,
param
);
return
res
;
}
@Override
public
boolean
adjustCluster
(
List
<
SeparatedClusterConfig
>
clusterConfigs
)
{
...
...
bishe-cloud-center/src/main/resources/application.yml
View file @
c670b34e
...
...
@@ -2,10 +2,10 @@ server:
port
:
9091
zookeeper
:
url
:
1
92.168.0.108
:2181
url
:
1
27.0.0.1
:2181
bs
:
cloudcenter
:
name
:
my-bs-cloud-center
ipservice
:
url
:
192.168.0.108:23333
\ No newline at end of file
url
:
127.0.0.1:23333
\ No newline at end of file
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/service/impl/IpServiceImpl.java
View file @
c670b34e
...
...
@@ -56,7 +56,7 @@ public class IpServiceImpl implements IpService {
}
Set
<
String
>
ipSet
=
clusterAppId
.
get
(
appName
);
ipSet
.
add
(
ip
);
return
ip
;
return
"10.10.1.255"
;
}
@Override
...
...
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
View file @
c670b34e
...
...
@@ -2,6 +2,8 @@ package top.ninwoo.edgecenter.controller;
import
org.influxdb.InfluxDB
;
import
org.influxdb.dto.Point
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
top.ninwoo.common.entity.ClusterConfig
;
...
...
@@ -13,6 +15,7 @@ import top.ninwoo.edgecenter.service.IpService;
import
top.ninwoo.edgecenter.service.TopologyService
;
import
top.ninwoo.utils.entity.NetworkInfo
;
import
top.ninwoo.utils.entity.OvsBridge
;
import
top.ninwoo.utils.service.TcService
;
import
java.util.*
;
import
java.util.concurrent.*
;
...
...
@@ -35,6 +38,9 @@ public class IndexController {
@Autowired
private
InfluxDB
influxDB
;
@Autowired
private
TcService
tcService
;
@RequestMapping
(
value
=
"/index"
)
public
List
<
DockerContainer
>
index
(
int
flag
)
{
...
...
@@ -42,6 +48,13 @@ public class IndexController {
return
containerIds
;
}
@RequestMapping
(
value
=
"/addQos"
)
public
Boolean
addQos
(
Long
clusterId
,
String
cName
,
String
maxRate
,
String
latency
)
{
Set
<
String
>
cids
=
clusterService
.
getContainerIdsByClusterId
(
clusterId
,
cName
);
boolean
res
=
tcService
.
addQos
(
cids
.
toArray
(
new
String
[]{})[
0
],
maxRate
,
latency
);
return
res
;
}
@RequestMapping
(
"/ovs"
)
public
List
<
OvsBridge
>
getOvsBridgeList
()
{
List
<
OvsBridge
>
bridges
=
clusterService
.
getOvsBridges
();
...
...
@@ -95,7 +108,7 @@ public class IndexController {
containerInfoMap
.
put
(
cid
,
new
ContainerInfo
());
NetworkMonitorThread
networkMonitorThread
=
new
NetworkMonitorThread
(
cid
,
containerInfoMap
,
clusterService
,
influxDB
,
containerName
);
// 放入线程池执行任务
ScheduledFuture
<?>
future
=
scheduledExecutorService
.
scheduleAtFixedRate
(
networkMonitorThread
,
0
,
1
,
TimeUnit
.
SECONDS
);
ScheduledFuture
<?>
future
=
scheduledExecutorService
.
scheduleAtFixedRate
(
networkMonitorThread
,
0
,
1
0
,
TimeUnit
.
MICRO
SECONDS
);
// 保存任务,以方便进行定时任务的关闭
scheduledFutureMap
.
put
(
cid
,
future
);
}
...
...
@@ -149,6 +162,7 @@ public class IndexController {
private
ClusterService
clusterService
;
private
InfluxDB
influxDB
;
private
String
cName
;
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
NetworkMonitorThread
.
class
);
public
NetworkMonitorThread
(
String
containerId
,
ConcurrentHashMap
<
String
,
ContainerInfo
>
map
,
ClusterService
clusterService
,
InfluxDB
influxDB
,
String
cName
)
{
this
.
containerId
=
containerId
;
...
...
@@ -171,16 +185,28 @@ public class IndexController {
if
(
map
.
containsKey
(
containerId
))
{
map
.
put
(
containerId
,
containerInfo
);
// TODO: 这里有又重新把容器id注册回去了
}
savePoint
(
networkInfo
);
try
{
savePoint
(
cName
,
networkInfo
);
LOG
.
info
(
"数据监控中"
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
"监控错误 {}"
,
e
.
getMessage
());
}
}
private
void
savePoint
(
NetworkInfo
networkInfo
)
{
Point
.
Builder
builder
=
Point
.
measurement
(
"monitor"
);
private
void
savePoint
(
String
cName
,
NetworkInfo
networkInfo
)
{
if
(
networkInfo
==
null
)
{
return
;
}
if
(
networkInfo
.
getCurRate
()
>
800
f
)
{
return
;
}
Point
.
Builder
builder
=
Point
.
measurement
(
cName
);
Point
point
=
builder
.
addField
(
"rate"
,
networkInfo
.
getCurRate
())
.
addField
(
"error"
,
networkInfo
.
getErrorRate
())
.
addField
(
"drop"
,
networkInfo
.
getDropRate
())
//
.addField("error", networkInfo.getErrorRate())
//
.addField("drop", networkInfo.getDropRate())
.
tag
(
"cid"
,
containerId
)
.
tag
(
"cName"
,
cName
).
build
();
influxDB
.
setDatabase
(
"test"
).
write
(
point
);
...
...
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/TopologyServiceImpl.java
View file @
c670b34e
...
...
@@ -157,6 +157,10 @@ public class TopologyServiceImpl implements TopologyService {
// 使用ovsDocker接口创建连接
// 获取全部的APP容器id
Set
<
String
>
cids
=
clusterService
.
getContainerIdsByClusterId
(
clusterId
,
containerName
);
if
(
cids
==
null
)
{
LOG
.
error
(
"cannot find cids {}:{}"
,
clusterId
,
containerName
);
throw
new
RuntimeException
(
"cannot find cids"
);
}
cids
.
forEach
(
cid
->
{
// ip分配服务
// TODO: 网段应该是和网络拓扑绑定到一起,需要重新进行设计
...
...
bishe-edge-center/src/main/resources/application.yaml
View file @
c670b34e
...
...
@@ -6,7 +6,7 @@ spring:
username
:
root
password
:
Vudo3423ljo
influx
:
url
:
http://1
92.168.61.13
1:8086
url
:
http://1
27.0.0.
1:8086
user
:
admin
password
:
admin
mybatis
:
...
...
@@ -24,9 +24,9 @@ bs:
name
:
random
ip-prefix
:
192
ipservice
:
ip
:
1
92.168.0.108
:23333
ip
:
1
27.0.0.1
:23333
sdn-controller
:
host
:
1
92.168.0.108
host
:
1
27.0.0.1
port
:
6653
zookeeper
:
url
:
1
92.168.0.108
:2181
url
:
1
27.0.0.1
:2181
bishe-test/pom.xml
View file @
c670b34e
...
...
@@ -36,4 +36,13 @@
<version>
2.9
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
bishe-test/src/main/java/top/ninwoo/client/BisheTestMain.java
0 → 100644
View file @
c670b34e
package
top.ninwoo.client
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
BisheTestMain
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
BisheTestMain
.
class
,
args
);
}
}
bishe-test/src/main/java/top/ninwoo/client/controller/TestController.java
0 → 100644
View file @
c670b34e
package
top.ninwoo.client.controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
javax.annotation.Resource
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
@RestController
public
class
TestController
{
@Resource
private
NetworkService
networkService
;
@GetMapping
(
"/start"
)
public
String
start
(
String
ip
,
String
t
,
String
selfName
,
String
targetName
,
float
div
)
{
int
i
=
(
int
)
(
40
*
div
);
networkService
.
addQos
(
11111L
,
targetName
,
i
+
"mbit"
,
"100ms"
);
networkService
.
addQos
(
11111L
,
selfName
,
(
40
-
i
)
+
"mbit"
,
"100ms"
);
runCmd
(
"iperf -c "
+
ip
+
" -t "
+
t
);
networkService
.
addQos
(
11111L
,
targetName
,
"40mbit"
,
"100ms"
);
return
"success"
;
}
private
String
runCmd
(
String
cmd
)
{
String
result
=
""
;
try
{
Process
exec
=
Runtime
.
getRuntime
().
exec
(
new
String
[]{
"/bin/sh"
,
"-c"
,
cmd
});
exec
.
waitFor
();
InputStream
in
=
exec
.
getInputStream
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
String
msg
;
while
((
msg
=
br
.
readLine
())!=
null
&&
msg
.
length
()
>
0
)
{
result
+=
msg
+
"\n"
;
}
if
(
""
.
equals
(
result
))
{
// 构建Error
InputStream
errorStream
=
exec
.
getErrorStream
();
BufferedReader
ebr
=
new
BufferedReader
(
new
InputStreamReader
(
errorStream
));
String
eMsg
;
while
((
eMsg
=
ebr
.
readLine
())!=
null
&&
eMsg
.
length
()
>
0
)
{
result
+=
eMsg
+
"\n"
;
}
if
(
result
.
equals
(
""
))
{
return
result
;
}
result
=
"Error: "
+
result
;
}
if
(
result
.
length
()
>
0
)
{
result
=
result
.
substring
(
0
,
result
.
length
()-
1
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
}
bishe-test/src/main/resources/application.properties
View file @
c670b34e
bishe.app.app-name
=
joliu
bishe.app.cloud-url
=
127.0.0.1:9091
spring.influx.url
=
http://192.168.
61.131
:8086
spring.influx.url
=
http://192.168.
0.108
:8086
spring.influx.user
=
admin
spring.influx.password
=
admin
\ No newline at end of file
bishe-test/src/test/java/top/ninwoo/BisheMultiNodeTests.java
View file @
c670b34e
...
...
@@ -11,12 +11,11 @@ import top.ninwoo.bishe.starter.entity.ContainerMonitor;
import
top.ninwoo.bishe.starter.service.ClusterService
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
top.ninwoo.common.entity.*
;
import
top.ninwoo.
tes
t.BisheTestMain
;
import
top.ninwoo.
clien
t.BisheTestMain
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
BisheTestMain
.
class
)
...
...
@@ -43,6 +42,9 @@ public class BisheMultiNodeTests {
influxDB
.
setDatabase
(
"test"
).
write
(
point
);
}
/**
* step1 创建容器
*/
@Test
public
void
testNetworkChange
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
...
...
@@ -86,7 +88,7 @@ public class BisheMultiNodeTests {
clusterConfig1
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription11
=
new
ContainerDescription
();
containerDescription11
.
setMode
(
"normal"
);
containerDescription11
.
setReplicas
(
1
);
containerDescription11
.
setReplicas
(
2
);
DockerContainer
container11
=
new
DockerContainer
();
container11
.
setName
(
"APP3"
);
container11
.
setCommand
(
"sh"
);
...
...
@@ -130,12 +132,73 @@ public class BisheMultiNodeTests {
adjustCluster
(
clusterConfigs
);
}
@Test
public
void
case1
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
separatedClusterConfig
.
setEdgeNodeId
(
"127.0.0.1:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
10
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"NODE"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
ContainerDescription
dis
=
new
ContainerDescription
();
dis
.
setMode
(
"normal"
);
dis
.
setReplicas
(
1
);
DockerContainer
disContainer
=
new
DockerContainer
();
disContainer
.
setName
(
"DIS"
);
disContainer
.
setCommand
(
"sh"
);
disContainer
.
setImage
(
"joliu/networktest"
);
dis
.
setDockerContainer
(
disContainer
);
cds
.
add
(
dis
);
ContainerDescription
ftp
=
new
ContainerDescription
();
ftp
.
setMode
(
"normal"
);
ftp
.
setReplicas
(
1
);
DockerContainer
ftpContainer
=
new
DockerContainer
();
ftpContainer
.
setName
(
"FTP"
);
ftpContainer
.
setCommand
(
"sh"
);
ftpContainer
.
setImage
(
"joliu/networktest"
);
ftp
.
setDockerContainer
(
ftpContainer
);
cds
.
add
(
ftp
);
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
new
String
[]{
"DIS"
,
"FTP"
,
"NODE"
,
"br:ovs1"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{
{
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
},
{
1
,
1
,
1
,
0
}});
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
//topo1.getTopology()[6][3] = 1;
adjustCluster
(
clusterConfigs
);
}
private
boolean
adjustCluster
(
List
<
SeparatedClusterConfig
>
configs
)
{
boolean
b
=
clusterService
.
adjustClusterToEdgeNode
(
configs
);
return
b
;
}
/**
* 创建新的链路
*/
@Test
public
void
testNewService
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
...
...
@@ -270,10 +333,18 @@ public class BisheMultiNodeTests {
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
/**
* step3 删除容器
*/
@Test
public
void
removeClusterFromEdgeNodeTest
()
{
clusterService
.
removeClusterFromEdgeNode
(
11111L
);
}
@Test
public
void
testAddQos
()
{
boolean
dis
=
networkService
.
addQos
(
11111L
,
"DIS"
,
"4mbit"
,
"100ms"
);
System
.
out
.
println
(
dis
);
}
@Test
public
void
getLogicalNetworkTopologyTest
()
{
...
...
bishe-test/src/test/java/top/ninwoo/BisheTests.java
View file @
c670b34e
...
...
@@ -9,7 +9,7 @@ import top.ninwoo.bishe.starter.entity.ContainerMonitor;
import
top.ninwoo.bishe.starter.service.ClusterService
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
top.ninwoo.common.entity.*
;
import
top.ninwoo.
tes
t.BisheTestMain
;
import
top.ninwoo.
clien
t.BisheTestMain
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
...
...
bishe-test/src/test/java/top/ninwoo/LunWenTests.java
0 → 100644
View file @
c670b34e
package
top.ninwoo
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
top.ninwoo.bishe.starter.service.ClusterService
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
top.ninwoo.client.BisheTestMain
;
import
top.ninwoo.common.entity.*
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
BisheTestMain
.
class
)
public
class
LunWenTests
{
@Autowired
private
ClusterService
clusterService
;
@Resource
private
NetworkService
networkService
;
@Test
public
void
test1
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
separatedClusterConfig
.
setEdgeNodeId
(
"127.0.0.1:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
10
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"D1"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
ContainerDescription
dis
=
new
ContainerDescription
();
dis
.
setMode
(
"normal"
);
dis
.
setReplicas
(
1
);
DockerContainer
disContainer
=
new
DockerContainer
();
disContainer
.
setName
(
"D2"
);
disContainer
.
setCommand
(
"sh"
);
disContainer
.
setImage
(
"joliu/networktest"
);
dis
.
setDockerContainer
(
disContainer
);
cds
.
add
(
dis
);
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
new
String
[]{
"D1"
,
"br:ovs1"
,
"br:ovs2"
,
"br:ovs3"
,
"D2"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{
{
0
,
0
,
0
,
0
,
0
},
{
1
,
0
,
0
,
0
,
0
},
{
0
,
1
,
0
,
0
,
0
},
{
0
,
0
,
1
,
0
,
0
},
{
0
,
0
,
0
,
1
,
0
}});
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
@Test
public
void
test2
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
separatedClusterConfig
.
setEdgeNodeId
(
"127.0.0.1:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
5
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"D1"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
ContainerDescription
dis
=
new
ContainerDescription
();
dis
.
setMode
(
"normal"
);
dis
.
setReplicas
(
1
);
DockerContainer
disContainer
=
new
DockerContainer
();
disContainer
.
setName
(
"D2"
);
disContainer
.
setCommand
(
"sh"
);
disContainer
.
setImage
(
"joliu/networktest"
);
dis
.
setDockerContainer
(
disContainer
);
cds
.
add
(
dis
);
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
new
String
[]{
"D1"
,
"br:ovs1"
,
"br:ovs2"
,
"br:ovs3"
,
"D2"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{
{
0
,
0
,
0
,
0
,
0
},
{
1
,
0
,
0
,
0
,
0
},
{
0
,
1
,
0
,
0
,
0
},
{
0
,
1
,
1
,
0
,
0
},
{
0
,
0
,
0
,
1
,
0
}});
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
adjustClusterToEdgeNode
(
clusterConfigs
);
}
@Test
public
void
test3
()
throws
InterruptedException
{
int
i
=
1
;
while
(
i
<
40
)
{
System
.
out
.
println
(
networkService
.
addQos
(
11111L
,
"D1"
,
i
+
"mbit"
,
"100ms"
));
i
++;
Thread
.
sleep
(
10000
);
}
}
@Test
public
void
test4
()
throws
InterruptedException
{
int
i
=
39
;
while
(
i
>
0
)
{
System
.
out
.
println
(
networkService
.
addQos
(
11111L
,
"D1"
,
i
+
"mbit"
,
"100ms"
));
i
--;
Thread
.
sleep
(
10000
);
}
}
@Test
public
void
test5
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
separatedClusterConfig
.
setEdgeNodeId
(
"127.0.0.1:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
10
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"NODE"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
ContainerDescription
dis
=
new
ContainerDescription
();
dis
.
setMode
(
"normal"
);
dis
.
setReplicas
(
1
);
DockerContainer
disContainer
=
new
DockerContainer
();
disContainer
.
setName
(
"DIS"
);
disContainer
.
setCommand
(
"sh"
);
disContainer
.
setImage
(
"joliu/networktest"
);
dis
.
setDockerContainer
(
disContainer
);
cds
.
add
(
dis
);
ContainerDescription
ftp
=
new
ContainerDescription
();
ftp
.
setMode
(
"normal"
);
ftp
.
setReplicas
(
1
);
DockerContainer
ftpContainer
=
new
DockerContainer
();
ftpContainer
.
setName
(
"FTP"
);
ftpContainer
.
setCommand
(
"sh"
);
ftpContainer
.
setImage
(
"joliu/networktest"
);
ftp
.
setDockerContainer
(
ftpContainer
);
cds
.
add
(
ftp
);
ContainerDescription
dis2
=
new
ContainerDescription
();
dis2
.
setMode
(
"normal"
);
dis2
.
setReplicas
(
1
);
DockerContainer
dis2Container
=
new
DockerContainer
();
dis2Container
.
setName
(
"DISREC"
);
dis2Container
.
setCommand
(
"sh"
);
dis2Container
.
setImage
(
"joliu/networktest"
);
dis2
.
setDockerContainer
(
dis2Container
);
cds
.
add
(
dis2
);
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
new
String
[]{
"FTP"
,
"NODE"
,
"DIS"
,
"DISREC"
,
"br:ovs1"
,
"br:ovs2"
,
"br:ovs3"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{
{
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
1
,
0
,
1
,
0
,
0
,
0
,
0
},
{
0
,
1
,
0
,
0
,
1
,
0
,
0
},
{
0
,
0
,
0
,
1
,
0
,
1
,
0
}});
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
@Test
public
void
test6
()
{
for
(
int
i
=
1
;
i
<=
50
;
i
++)
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
separatedClusterConfig
.
setEdgeNodeId
(
"127.0.0.1:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
i
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"D1"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
new
String
[]{
"D1"
,
"br:ovs1"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{
{
0
,
0
},
{
1
,
0
}});
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
long
start
=
System
.
currentTimeMillis
();
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
System
.
out
.
printf
(
"%s,"
,
System
.
currentTimeMillis
()
-
start
);
clusterService
.
removeClusterFromEdgeNode
(
11111L
);
}
}
}
bishe-utils/src/main/java/top/ninwoo/utils/service/impl/TcServiceImpl.java
View file @
c670b34e
...
...
@@ -80,7 +80,7 @@ public class TcServiceImpl implements TcService {
break
;
}
}
Thread
.
sleep
(
10
00
);
Thread
.
sleep
(
5
00
);
long
endTime
=
System
.
currentTimeMillis
();
lines
=
dockerUtils
.
execInDocker
(
containerId
,
command
.
split
(
" "
)).
split
(
"\n"
);
i
=
0
;
...
...
@@ -116,7 +116,7 @@ public class TcServiceImpl implements TcService {
if
(
qosMap
.
containsKey
(
containerId
))
{
maxRate
=
qosMap
.
get
(
containerId
);
}
netUsage
=
curRate
/
(
1024
*
8
f
)
;
netUsage
=
curRate
/
maxRate
;
if
(
netUsage
>
1.0
)
{
netUsage
=
1.0f
;
}
...
...
pom.xml
View file @
c670b34e
...
...
@@ -16,6 +16,7 @@
<module>
bishe-cloud-ipservice
</module>
<module>
bishe-client-starter
</module>
<module>
bishe-test
</module>
<module>
bishe-case-dis
</module>
</modules>
...
...
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