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
47651670
Commit
47651670
authored
Dec 29, 2020
by
ymwangya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new
parent
526c38e8
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
1992 additions
and
102 deletions
+1992
-102
apps/cnf-distributed-business-computing/dbc-businessComputing-topology/src/main/resources/application.properties
...puting-topology/src/main/resources/application.properties
+1
-1
apps/cnf-distributed-business-computing/dbc-businessComputing-topology/src/test/java/top/ninwoo/tests/TopoTests.java
...ng-topology/src/test/java/top/ninwoo/tests/TopoTests.java
+5
-5
apps/cnf-hadoop-computing/cnf-hadoop-client/src/main/java/top/ninwoo/hadoop/client/service/FileService.java
...in/java/top/ninwoo/hadoop/client/service/FileService.java
+34
-77
apps/cnf-hadoop-computing/cnf-hadoop-client/src/main/resources/application.properties
...f-hadoop-client/src/main/resources/application.properties
+25
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/pom.xml
apps/cnf-hadoop-computing/cnf-hadoop-test/pom.xml
+37
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/WxMain.java
...doop-test/src/main/java/top/ninwoo/weixingsim/WxMain.java
+11
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopo.java
...main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopo.java
+89
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopoUnit.java
.../java/top/ninwoo/weixingsim/dynamicNet/CycleTopoUnit.java
+79
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/DoMap.java
...src/main/java/top/ninwoo/weixingsim/dynamicNet/DoMap.java
+278
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/InterSlotDijstraV2.java
.../top/ninwoo/weixingsim/dynamicNet/InterSlotDijstraV2.java
+158
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/TimeExpanGraph.java
...java/top/ninwoo/weixingsim/dynamicNet/TimeExpanGraph.java
+164
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/WxMain.java
.../main/java/top/ninwoo/weixingsim/sateTopology/WxMain.java
+17
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/entity/SimData.java
...va/top/ninwoo/weixingsim/sateTopology/entity/SimData.java
+40
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/entity/WeiXingData.java
...op/ninwoo/weixingsim/sateTopology/entity/WeiXingData.java
+31
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/init/Initapp.java
...java/top/ninwoo/weixingsim/sateTopology/init/Initapp.java
+107
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/Toponet.java
...a/top/ninwoo/weixingsim/sateTopology/service/Toponet.java
+60
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/Weixing.java
...a/top/ninwoo/weixingsim/sateTopology/service/Weixing.java
+138
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/impl/ToponetImpl.java
...woo/weixingsim/sateTopology/service/impl/ToponetImpl.java
+131
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/impl/WeixingImpl.java
...woo/weixingsim/sateTopology/service/impl/WeixingImpl.java
+244
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/resources/application.properties
...cnf-hadoop-test/src/main/resources/application.properties
+8
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/test/java/top/ninwoo/hadoop/tests/HadoopTest.java
...est/src/test/java/top/ninwoo/hadoop/tests/HadoopTest.java
+175
-0
apps/cnf-hadoop-computing/cnf-hadoop-test/src/test/java/top/ninwoo/hadoop/tests/HadoopTest2.java
...st/src/test/java/top/ninwoo/hadoop/tests/HadoopTest2.java
+141
-0
apps/cnf-hadoop-computing/cnf-hadoop-utils/src/main/java/top/ninwoo/hadoop/utils/ImageToArrayUtils.java
.../main/java/top/ninwoo/hadoop/utils/ImageToArrayUtils.java
+3
-3
apps/cnf-hadoop-computing/pom.xml
apps/cnf-hadoop-computing/pom.xml
+1
-0
apps/cnf-weixingsim/src/main/java/top/ninwoo/weixingsim/service/Toponet.java
.../src/main/java/top/ninwoo/weixingsim/service/Toponet.java
+2
-2
apps/cnf-weixingsim/src/main/java/top/ninwoo/weixingsim/service/Weixing.java
.../src/main/java/top/ninwoo/weixingsim/service/Weixing.java
+2
-2
apps/cnf-weixingsim/src/main/java/top/ninwoo/weixingsim/service/impl/WeixingImpl.java
.../java/top/ninwoo/weixingsim/service/impl/WeixingImpl.java
+1
-1
cnf-cloud-center/src/main/resources/application.yml
cnf-cloud-center/src/main/resources/application.yml
+4
-4
cnf-edge-center/src/main/resources/application.yaml
cnf-edge-center/src/main/resources/application.yaml
+5
-5
cnf-test/src/main/resources/application.properties
cnf-test/src/main/resources/application.properties
+1
-1
pom.xml
pom.xml
+0
-1
No files found.
apps/cnf-distributed-business-computing/dbc-businessComputing-topology/src/main/resources/application.properties
View file @
47651670
bishe.app.app-name
=
joliu
#bishe.app.cloud-url=192.168.31.156:9090
bishe.app.cloud-url
=
192.168.31.
198
:9091
bishe.app.cloud-url
=
192.168.31.
9
:9091
spring.influx.url
=
http://192.168.0.108:8086
spring.influx.user
=
admin
...
...
apps/cnf-distributed-business-computing/dbc-businessComputing-topology/src/test/java/top/ninwoo/tests/TopoTests.java
View file @
47651670
...
...
@@ -37,7 +37,7 @@ public class TopoTests {
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.31.
198
:18088"
);
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.31.
213
:18088"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11113
l
);
clusterConfig
.
setOwner
(
"joliu"
);
...
...
@@ -47,7 +47,7 @@ public class TopoTests {
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"F:\\
ymwang
\\topusim_1.txt"
);
File
file
=
new
File
(
"F:\\
2.GraduatePro
\\topusim_1.txt"
);
// D:\LabratoryJavaPro\codingDownload\latestCoding\
List
<
WeiXingData
>
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
int
[][]
toponet
=
tp
.
getTopology
(
wxData
,
sd
);
...
...
@@ -74,7 +74,7 @@ public class TopoTests {
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
wxData
.
get
(
k
).
getName
());
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"
dbc
_server"
);
container
.
setImage
(
"
hadoop
_server"
);
containerDescription
.
setDockerContainer
(
container
);
cds
.
add
(
containerDescription
);
...
...
@@ -86,7 +86,7 @@ public class TopoTests {
DockerContainer
container0
=
new
DockerContainer
();
container0
.
setName
(
wxData
.
get
(
wxData
.
size
()-
1
).
getName
());
container0
.
setCommand
(
"sh"
);
container0
.
setImage
(
"
dbc
_client"
);
container0
.
setImage
(
"
hadoop
_client"
);
container0
.
setPorts
(
"8999"
);
//指定容器端口
containerDescription0
.
setDockerContainer
(
container0
);
...
...
@@ -141,7 +141,7 @@ public class TopoTests {
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"F:\\
ymwang
\\topusim_1.txt"
);
File
file
=
new
File
(
"F:\\
2.GraduatePro
\\topusim_1.txt"
);
List
<
WeiXingData
>
wxData
=
null
;
try
{
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
...
...
apps/cnf-hadoop-computing/cnf-hadoop-client/src/main/java/top/ninwoo/hadoop/client/service/FileService.java
View file @
47651670
...
...
@@ -14,22 +14,19 @@ import top.ninwoo.hadoop.api.po.MergeResult;
import
top.ninwoo.hadoop.api.po.SplitResult
;
import
top.ninwoo.hadoop.api.service.HadoopComService
;
import
javax.annotation.PostConstruct
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
/**
* 文件服务
*/
@Service
public
class
FileService
{
public
class
FileService
{
@Value
(
"${dbc.directory.output}"
)
...
...
@@ -45,26 +42,32 @@ public class FileService {
@Autowired
private
HadoopComService
hadoopComService
;
//不需要了,我懒得改
Long
clusterId
=
11113L
;
//docker集群ID
//String[] wxName_list = new String[]{"sate1","sate2","sate3","sate4","sate5","sate6","sate7"};//获取卫星名字
String
[]
wxName_list
=
new
String
[]{
"sate2"
,
"sate3"
,
"sate4"
,
"sate5"
,
"sate6"
,
"sate7"
,
"sate8"
,
"sate9"
,
"sate10"
,
"sate11"
,
String
[]
wxName_list
=
new
String
[]{
"sate1"
,
"sate2"
,
"sate3"
,
"sate4"
,
"sate5"
,
"sate6"
,
"sate7"
,
"sate8"
,
"sate9"
,
"sate10"
,
"sate11"
,
"sate12"
,
"sate13"
,
"sate14"
,
"sate15"
,
"sate16"
,
"sate17"
,
"sate18"
,
"sate19"
,
"sate20"
,
"sate21"
,
"sate22"
,
"sate23"
,
"sate24"
,
"sate25"
,
"sate26"
,
"sate27"
,
"sate28"
,
"sate29"
,
"sate30"
};
//获取卫星名字
"sate22"
,
"sate23"
,
"sate24"
,
"sate25"
,
"sate26"
,
"sate27"
,
"sate28"
,
"sate29"
};
//获取卫星名字
private
String
[]
ipList
=
new
String
[
29
];
private
List
<
Integer
>
index
=
new
ArrayList
<
Integer
>()
{}
;
@PostConstruct
public
void
init
()
{
System
.
out
.
println
(
Arrays
.
toString
(
ipList
));
for
(
int
k
=
0
;
k
<
wxName_list
.
length
;
k
++){
ipList
[
k
]
=
getIpByAppName
(
clusterId
,
wxName_list
[
k
]);
//通过卫星名字获取卫星ip
long
startTime
=
System
.
currentTimeMillis
();
// 获取开始时间
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//设置日期格式
/*获取容器ip*/
public
String
[]
getIpList
(
Long
clusterId
,
String
appName
)
{
List
<
String
>
ipListS
=
networkService
.
getIpListByAppName
(
clusterId
,
appName
);
//用于存储容器ip的list集合
String
[]
containerIp
=
new
String
[
ipListS
.
size
()];
//将集合中的元素存在数组里,因为下边用的是数组
for
(
int
i
=
0
;
i
<
ipListS
.
size
();
i
++)
{
if
(!
ipListS
.
isEmpty
()){
String
ip_tmp
=
ipListS
.
get
(
i
);
String
rep
=
ip_tmp
.
replaceAll
(
"[\\[\\]]"
,
""
);
String
[]
split_list
=
rep
.
split
(
"/"
);
containerIp
[
i
]
=
split_list
[
0
]+
":8082"
;
}
}
return
containerIp
;
}
/*获取容器ip*/
public
String
getIpByAppName
(
Long
clusterId
,
String
appName
)
{
List
<
String
>
ipList
=
networkService
.
getIpListByAppName
(
clusterId
,
appName
);
if
(!
ipList
.
isEmpty
()){
...
...
@@ -75,24 +78,6 @@ public class FileService {
return
null
;
}
/* //todo 可能会有找不到文件的情况
public String getIpByAppName(Long clusterId,String appName) {
String str;
File file = new File(directoryOutput+"sateIP.txt");
try{
BufferedReader br = new BufferedReader(new FileReader(file));
while((str = br.readLine()) != null){
if (str.startsWith(appName)){
String sateIp = str.split(":")[1];
return sateIp + ":8082";
}
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}*/
/**
* 发送文件到分布式节点
* @param fileId
...
...
@@ -101,9 +86,10 @@ public class FileService {
*/
@Async
(
"taskExecutor"
)
public
String
sendFile
(
Long
fileId
,
BufferedImage
bufferedImage
)
{
// 通过集群服务器接口获取当前集群的节点数量
//int sliceNum = ipList.length;
//ipList = getIpList(11113l,"dbc_server");
//long startTime = System.currentTimeMillis(); // 获取开始时间
System
.
out
.
println
(
"The current system time at the beginning of the program:"
+
df
.
format
(
new
Date
()));
// new Date()为获取当前系统时间
System
.
out
.
println
(
"The execution time at the beginning of the program:"
+
startTime
);
for
(
int
i
=
0
;
i
<
wxName_list
.
length
;
i
++){
ipList
[
i
]
=
getIpByAppName
(
clusterId
,
wxName_list
[
i
]);
//通过卫星名字获取卫星ip
...
...
@@ -113,13 +99,10 @@ public class FileService {
System
.
out
.
println
(
Arrays
.
toString
(
ipList
));
index
=
this
.
getIndex
(
ipList
.
length
);
//设置切片的数量
int
sliceNum
=
5
;
// todo 这里需要制定文件的fileId
SplitResult
splitResult
=
hadoopComService
.
fileSplit
(
bufferedImage
,
sliceNum
);
//int ipIndex = 0;
int
i
=
0
;
for
(
FileSlice
slice
:
splitResult
.
getFileSliceList
())
{
slice
.
setFileId
(
fileId
);
...
...
@@ -127,29 +110,15 @@ public class FileService {
while
(
true
){
try
{
sendFileSlice
(
ipList
[
index
.
get
(
i
)],
slice
);
//
System
.
out
.
println
(
"send "
+
wxName_list
[
index
.
get
(
i
)]+
" success"
);
i
=
i
+
1
;
//ipIndex = (ipIndex + 1) % ipList.length;
break
;
}
catch
(
Exception
e
){
//ipIndex = (ipIndex + 1) % ipList.length;
//
System
.
out
.
println
(
"send "
+
wxName_list
[
index
.
get
(
i
)]+
" failed"
);
}
}
}
return
"success"
;
/*for (FileSlice slice : splitResult.getFileSliceList()) {
slice.setFileId(fileId);
String result = sendFileSlice(ipList[ipIndex], slice);
ipIndex = (ipIndex + 1) % ipList.length;
if(result.equals("failed")) {
return "fail";
}
}
return "success";*/
}
// 发送文件切片到目标地址
...
...
@@ -170,26 +139,21 @@ public class FileService {
}
public
String
getFile
(
String
fileName
,
Long
fileId
)
{
//ipList = getIpList(11113l,"dbc_server");
for
(
int
i
=
0
;
i
<
wxName_list
.
length
;
i
++){
ipList
[
i
]
=
getIpByAppName
(
clusterId
,
wxName_list
[
i
]);
//通过卫星名字获取卫星ip
}
int
sliceNum
=
5
;
//int sliceNum = ipList.length;
Set
<
FileSlice
>
result
=
new
HashSet
<>();
/* for (String ip : ipList) {
Set<FileSlice> fileSliceSet = getFileSlice(ip, fileId); //将fileId=1的碎片收回,HashSet无序收回
result.addAll(fileSliceSet);
}*/
//异常处理
for
(
int
k
=
0
;
k
<
5
;
k
++)
{
try
{
Set
<
FileSlice
>
fileSliceSet
=
getFileSlice
(
ipList
[
index
.
get
(
k
)],
fileId
);
System
.
out
.
println
(
"recive "
+
wxName_list
[
index
.
get
(
k
)]+
" success"
);
//Set<FileSlice> fileSliceSet = getFileSlice(ipList[index.get(k)], fileId);
//System.out.println("recive "+wxName_list[index.get(k)]+" success");
Set
<
FileSlice
>
fileSliceSet
=
getFileSlice
(
ipList
[
k
],
fileId
);
System
.
out
.
println
(
"recive "
+
wxName_list
[
k
]+
" success"
);
result
.
addAll
(
fileSliceSet
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
"recive fileslice fail"
);
}
}
List
<
FileSlice
>
list
=
new
ArrayList
<>(
result
);
...
...
@@ -208,9 +172,8 @@ public class FileService {
}
}
//给List集合里的元素进行排序
,便于图片正常恢复
//给List集合里的元素进行排序
public
List
<
FileSlice
>
sortList
(
List
<
FileSlice
>
list
){
//List<FileSlice> list = new ArrayList<FileSlice>();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
for
(
int
j
=
list
.
size
()-
1
;
j
>
i
;
j
--)
{
int
no
=
list
.
get
(
j
).
getSliceId
();
...
...
@@ -226,12 +189,6 @@ public class FileService {
return
list
;
}
//对分割后得到的碎片List按照碎片的大小进行排序---使用冒泡排序
/* public SplitResult sortSpiltList(){
return null;
}*/
public
void
saveFile
(
String
fileName
,
MergeResult
mergeResult
)
{
BufferedImage
images
=
mergeResult
.
getImages
();
//输出拼接后的图像
...
...
@@ -240,9 +197,12 @@ public class FileService {
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
long
endTime
=
System
.
currentTimeMillis
();
//获取程序结束时间
System
.
out
.
println
(
"The current system time at the end of the program:"
+
df
.
format
(
new
Date
()));
// new Date()为获取当前系统时间
System
.
out
.
println
(
"The execution time at the end of the program:"
+
endTime
);
System
.
out
.
println
(
"The total running time of the program:"
+
(
endTime
-
startTime
)
+
"ms"
);
}
public
List
<
Integer
>
getIndex
(
int
num
){
Random
r
=
new
Random
();
List
<
Integer
>
v
=
new
ArrayList
<
Integer
>()
{}
;
...
...
@@ -259,7 +219,4 @@ public class FileService {
return
v
;
}
}
apps/cnf-hadoop-computing/cnf-hadoop-client/src/main/resources/application.properties
0 → 100644
View file @
47651670
#项目端口
server.port
=
8999
#接入云端的端口设置
bishe.app.app-name
=
joliu
bishe.app.cloud-url
=
192.168.31.213:9091
#容器里的挂载目录
dbc.directory.output
=
/tmp/static/
#dbc.directory.output=/F:/resources/static/
#thymeleaf
spring.thymeleaf.prefix
=
classpath:/templates/
spring.thymeleaf.suffix
=
.html
spring.thymeleaf.mode
=
LEGACYHTML5
spring.thymeleaf.encoding
=
UTF-8
spring.thymeleaf.servlet.content-type
=
text/html
spring.thymeleaf.cache
=
false
# 设置文件上传的大小
spring.servlet.multipart.max-file-size
=
1024000000000MB
spring.servlet.multipart.max-request-size
=
1024000000000MB
\ No newline at end of file
apps/cnf-hadoop-computing/cnf-hadoop-test/pom.xml
0 → 100644
View file @
47651670
<?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>
cnf-hadoop-computing
</artifactId>
<groupId>
top.ninwoo
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
cnf-hadoop-test
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
cnf-client-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.influxdb
</groupId>
<artifactId>
influxdb-java
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/WxMain.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
WxMain
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
WxMain
.
class
,
args
);
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopo.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.dynamicNet
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.ToponetImpl
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.WeixingImpl
;
import
java.io.File
;
import
java.util.*
;
public
class
CycleTopo
{
public
static
void
main
(
String
[]
args
)
{
cycleTp
();
}
public
static
HashMap
<
Integer
,
double
[][]>
cycleTp
(){
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"D:\\project\\topusim_1.txt"
);
//D:\LabratoryJavaPro\codingDownload\latestCoding\
List
<
WeiXingData
>
wxData
=
null
;
{
try
{
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
//初始topo
double
[][]
toponet
=
tp
.
getWeightedTopology
(
wxData
,
sd
);
//去掉ovs
double
[][]
topoNet
=
new
double
[
10
][
10
];
for
(
int
i
=
0
;
i
<
topoNet
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
i
][
j
]
=
toponet
[
i
][
j
];
}
}
HashMap
<
Integer
,
double
[][]>
TopoStore
=
new
HashMap
<>();
TopoStore
.
put
(
0
,
topoNet
);
for
(
int
i
=
1
;
i
<
sd
.
getZhouqi
()/
sd
.
getJiange
();
i
++)
{
int
time
=
i
*
sd
.
getJiange
();
List
<
WeiXingData
>
changetp
=
wx
.
changeTopo
(
wxData
,
time
);
double
[][]
changeTopo
=
tp
.
getWeightedTopology
(
changetp
,
sd
);
//去掉ovs
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
changeTopo
[
k
][
j
];
}
}
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
k
+
1
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
topoNet
[
j
][
k
];
}
}
TopoStore
.
put
(
i
,
topoNet
);
}
int
count
=
0
;
int
count2
=
-
1
;
Iterator
<
Map
.
Entry
<
Integer
,
double
[][]>>
iterator
=
TopoStore
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
()){
double
[][]
value
=
iterator
.
next
().
getValue
();
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++){
if
(
i
>
0
){
boolean
equals
=
Arrays
.
equals
(
value
[
i
],
topoNet
[
i
]);
count
+=
(
equals
?
1
:
0
);
}
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
i
][
j
]
=
value
[
i
][
j
];
}
}
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
k
+
1
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
topoNet
[
j
][
k
];
}
}
if
(
count
!=
30
){
count2
++;
}
System
.
out
.
println
(
Arrays
.
deepToString
(
topoNet
));
System
.
out
.
println
(
"========================================="
);
System
.
out
.
println
(
count2
);
}
return
TopoStore
;
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopoUnit.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.dynamicNet
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.ToponetImpl
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.WeixingImpl
;
import
java.io.File
;
import
java.util.*
;
public
class
CycleTopoUnit
{
public
static
void
main
(
String
[]
args
)
throws
IllegalAccessException
{
cycleTp
();
}
public
static
HashMap
<
Integer
,
int
[][]>
cycleTp
()
{
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"F:\\ymwang\\topusim_1.txt"
);
List
<
WeiXingData
>
wxData
=
null
;
try
{
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
sd
.
setJiange
(
60
);
sd
.
setC0
(
3
e10
);
//存储全周期拓扑
HashMap
<
Integer
,
int
[][]>
TopoStore
=
new
HashMap
<>();
out:
for
(
int
i
=
0
;
i
<
sd
.
getZhouqi
()/
sd
.
getJiange
();
i
++)
{
//Thread.sleep(2000);
int
time
=
i
*
sd
.
getJiange
();
List
<
WeiXingData
>
changetp
=
wx
.
changeTopo
(
wxData
,
time
);
int
[][]
topoChange
=
tp
.
getTopology
(
changetp
,
sd
);
TopoStore
.
put
(
i
,
topoChange
);
}
/*
* 对比全周期拓扑
* count记录重复拓扑行数
* count2记录不同拓扑数目
* */
int
count
=
0
;
int
count2
=
0
;
Iterator
<
Map
.
Entry
<
Integer
,
int
[][]>>
iterator
=
TopoStore
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
()){
int
[][]
value
=
iterator
.
next
().
getValue
();
/* System.out.println(Arrays.deepToString(value));
System.out.println("=========================================");
System.out.println(count2);*/
while
(
iterator
.
hasNext
()){
int
[][]
valueNext
=
iterator
.
next
().
getValue
();
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++){
boolean
equals
=
Arrays
.
equals
(
value
[
i
],
valueNext
[
i
]);
count
+=
(
equals
?
1
:
0
);
}
if
(
count
!=
30
){
/* System.out.println(Arrays.deepToString(valueNext));
System.out.println("=========================================");
System.out.println(count2);*/
count2
++;
}
count
=
0
;
value
=
valueNext
;
}
}
return
TopoStore
;
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/DoMap.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.dynamicNet
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.Stack
;
import
static
top
.
ninwoo
.
weixingsim
.
dynamicNet
.
CycleTopo
.
cycleTp
;
/**
* 求某一数据量下的最佳映射结果和业务处理时延
* 输出最佳粒子的位置和适应度值
* 目前只允许计算过程跨单时隙
* @jthu
*/
public
class
DoMap
{
//最大权值
static
final
int
MAXWEIGHT
=
10000
*
1000
;
/*
* 业务参数
*/
//数据量MB?
static
double
D
=
4
;
//子任务数
static
int
c
=
7
;
//8
//子任务依赖关系 边
static
int
[][]
link
=
{{
0
,
0
,
1
,
2
,
3
,
4
,
5
},
{
1
,
2
,
3
,
4
,
5
,
5
,
6
}};
//
//固定映射任务数==起始任务+终止任务
static
final
int
C_STABLE
=
2
;
//实际需映射任务数
static
int
n1
=
c
-
C_STABLE
;
/*
* 网络参数
*/
//设备数
static
int
num
=
6
;
//设备计算能力参数s GB/s
static
double
[]
nt
=
{
1.112341341313
,
0.5196272109574349
,
0.675827555541419
,
0.7637869915859579
,
0.7998320296858645
,
0.638652700648973
,
0.6396760676518485
,
0.5615337810185533
,
0.6356797503522186
,
0.8266103444996542
};
//30节点
/*static double[] nt = {1.112341341313, 0.5196272109574349, 0.675827555541419, 0.7637869915859579, 0.7998320296858645,
0.638652700648973, 0.6396760676518485, 0.5615337810185533, 0.6356797503522186, 0.8266103444996542, 0.6924037701405794,
0.9371892689614395, 0.6949256728585527, 0.6212614126622614, 0.6318393608430264, 0.7494680794385384, 0.9983949989039682,
0.5610722256465777, 0.6415780028672076, 0.9371892689, 0.5269659075274151, 0.8219152161388867, 0.5815463889106197,
0.8431429542046349, 0.31386253514456774, 0.6045132365410817, 0.8102279249524735, 0.47057296148341216, 0.8529743685059654, 0.8177711194660409}; //30节点*/
//时隙大小
static
double
slot
=
20
*
1000
;
//时隙数目
static
int
slotnum
;
//网络节点数
static
int
dev
;
//初始化时延偏移量
//这里需要一个时钟输入
static
double
testLatency
=
0
;
//固定映射设备数==起始设备+终止设备
static
final
int
N_STABLE
=
2
;
//实际可映射设备数
static
int
n2
;
//单时隙可映射设备数
static
int
mapdev
=
num
-
N_STABLE
;
/*
* BPSO参数
*/
//粒子群规模
static
int
n
=
1000
;
//种群迭代次数
static
int
k
=
500
;
//惯性权重,加速因子1,2
static
double
s
=
1.5
;
static
int
c1
=
1
;
static
int
c2
=
1
;
public
static
void
main
(
String
[]
args
)
{
doMapApp
();
}
//节点最终分配结果
public
static
int
[]
result
=
new
int
[
c
];
//节点间最短路由
public
static
Stack
[]
route
=
new
Stack
[
link
[
0
].
length
+
1
];
//业务发起时刻
public
static
long
startT
;
//传输时延约束
public
static
LinkedList
<
Double
>
list
=
new
LinkedList
<>();
public
static
void
doMapApp
()
{
for
(
slotnum
=
1
;
slotnum
<=
3
;
slotnum
++){
//slotnum = 3;
dev
=
num
*
slotnum
;
//10个卫星节点,3个时隙,则共有10*3个卫星节点
n2
=
dev
-
N_STABLE
*
slotnum
;
//n2实际可映射的节点
//组装最短路矩阵
double
[][]
edgeWeight
=
WTEG
();
System
.
out
.
println
(
"大矩阵是:"
);
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
edgeWeight
[
0
].
length
;
j
++)
{
System
.
out
.
print
(
edgeWeight
[
i
][
j
]+
" "
);
}
System
.
out
.
println
();
}
//最短路由矩阵
InterSlotDijstraV2
dijs
=
new
InterSlotDijstraV2
(
num
,
slot
);
InterSlotDijstraV2
.
pathRecord
pathRecord
=
dijs
.
dijstra
(
edgeWeight
,
testLatency
);
double
[][]
lt
=
pathRecord
.
pathWeight
;
for
(
int
i
=
0
;
i
<
lt
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
lt
.
length
;
j
++){
lt
[
i
][
j
]
*=
D
;
}
}
/*System.out.println("最短路由");
System.out.println(Arrays.deepToString(lt));*/
for
(
int
i
=
0
;
i
<
nt
.
length
;
i
++)
{
nt
[
i
]
=
(
D
*
1000
)
/
nt
[
i
];
}
}
}
private
static
double
[][]
WTEG
()
{
//获取当前3时隙拓扑
/**
* 先用SimpleDateFormat.parse() 方法将日期字符串转化为Date格式
* 通过Date.getTime()方法,将其转化为毫秒数
*/
String
date
=
"2019-01-01 00-00-00"
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH-mm-ss"
);
//24小时制
long
time
=
0
;
try
{
time
=
simpleDateFormat
.
parse
(
date
).
getTime
();
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
int
slotKey
=
(
int
)
((((
System
.
currentTimeMillis
()-
time
)/
20
/
1000
)-
1
)%
300
+
1
);
startT
=
((
System
.
currentTimeMillis
()-
time
)/
20000
+
1
)*
20000
;
HashMap
<
Integer
,
double
[][]>
cycleTp
=
cycleTp
();
//HashMap<Integer, double[][]> cycleTp = cycleTpE();
//获得单时隙连接矩阵 0或MAXWEIGHT
//等待下一时隙开始执行业务
/* double[][] currentTp = cycleTp.get((slotKey)%300+1);
double[][] slot1 = new double[num][num];*/
double
[][]
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
1
);
double
[][]
slot1
=
new
double
[
num
][
num
];
//10*10的矩阵图
System
.
out
.
println
(
"1:"
+(
slotKey
)%
300
+
1
);
for
(
int
i
=
0
;
i
<
currentTp
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
currentTp
[
0
].
length
;
j
++)
{
System
.
out
.
print
(
currentTp
[
i
][
j
]+
" "
);
}
System
.
out
.
println
();
}
//int[][] slot1 = new int[num][num]; //10*10的矩阵图
/* for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1.length;j++){
if (currentTp[i][j]==0.0){
if (i==j){
slot1[i][j]=0.0;
}else
slot1[i][j] = MAXWEIGHT;
}else{
slot1[i][j] = 10e5/currentTp[i][j];
}
}
}*/
for
(
int
i
=
0
;
i
<
slot1
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot1
[
0
].
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot1
[
i
][
j
]=
0
;
}
else
slot1
[
i
][
j
]
=
MAXWEIGHT
;
}
else
{
//slot1[i][j] = 10e5/currentTp[i][j];
}
}
}
/*System.out.println("第一个时隙的网络拓扑:"+Arrays.deepToString(slot1));
System.out.println(slot1.length);
System.out.println(slot1[0].length);
System.out.println("第一个时隙的网络拓扑:");
for (int i = 0; i < slot1.length; i++) {
for (int j = 0; j < slot1[0].length; j++) {
System.out.print(slot1[i][j]+" ");
}
System.out.println();
}*/
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
1
);
System
.
out
.
println
(
"2:"
+(
slotKey
)%
300
+
2
);
double
[][]
slot2
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot2
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot2
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot2
[
i
][
j
]=
0.0
;
}
else
slot2
[
i
][
j
]
=
MAXWEIGHT
;
}
else
{
slot2
[
i
][
j
]
=
10
e5
/
currentTp
[
i
][
j
];
}
}
}
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
1
);
double
[][]
slot3
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot3
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot3
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot3
[
i
][
j
]=
0.0
;
}
else
slot3
[
i
][
j
]
=
MAXWEIGHT
;
}
else
{
slot3
[
i
][
j
]
=
10
e5
/
currentTp
[
i
][
j
];
}
}
}
//生成相邻时隙矩阵
double
[][]
neighbor
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
neighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
neighbor
.
length
;
j
++){
if
(
i
==
j
){
neighbor
[
i
][
j
]
=
slot
;
}
else
{
neighbor
[
i
][
j
]
=
MAXWEIGHT
;
}
}
}
//生成其余时隙矩阵
double
[][]
nonNeighbor
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
nonNeighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
nonNeighbor
.
length
;
j
++){
nonNeighbor
[
i
][
j
]
=
MAXWEIGHT
;
}
}
//组装连接矩阵
double
[][]
edgeWeight
=
new
double
[
dev
][
dev
];
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++){
if
(
i
>=
0
&
i
<
num
&
j
>=
0
&
j
<
num
)
{
edgeWeight
[
i
][
j
]
=
slot1
[
i
][
j
];
}
else
if
(
i
>=
num
&
i
<
2
*
num
&
j
>=
num
&
j
<
2
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot2
[
i
%
num
][
j
%
num
];
}
else
if
(
i
>=
2
*
num
&
i
<
3
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot3
[
i
%
num
][
j
%
num
];
}
else
if
((
i
>=
0
&
i
<
num
&
j
>=
num
&
j
<
2
*
num
)
||
(
i
>=
num
&
i
<
2
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)){
edgeWeight
[
i
][
j
]
=
neighbor
[
i
%
num
][
j
%
num
];
}
else
{
edgeWeight
[
i
][
j
]
=
nonNeighbor
[
i
%
num
][
j
%
num
];
}
}
}
return
edgeWeight
;
}
}
\ No newline at end of file
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/InterSlotDijstraV2.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.dynamicNet
;
public
class
InterSlotDijstraV2
{
public
static
void
main
(
String
[]
args
)
{
double
[][]
edgeWeight
=
new
double
[][]
{
{
0
,
96
,
157
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
371
,
0
,
163
,
MAXWEIGHT
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
84
,
395
,
0
,
MAXWEIGHT
,
MAXWEIGHT
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
0
,
8
,
1
,
100
,
MAXWEIGHT
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
5
,
0
,
1
,
MAXWEIGHT
,
100
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
5
,
5
,
0
,
MAXWEIGHT
,
MAXWEIGHT
,
100
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
0
,
46
,
83
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
25
,
0
,
55
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
35
,
18
,
0
}};
int
num
=
3
;
double
slot
=
100
;
double
testLatency
=
0
;
InterSlotDijstraV2
di
=
new
InterSlotDijstraV2
(
num
,
slot
);
di
.
dijstra
(
edgeWeight
,
testLatency
);
}
/* //最短路矩阵
double [][] pathWeight;
//*/
//设备数目
int
num
;
//时隙值
double
slot
;
//最大权值
static
final
int
MAXWEIGHT
=
10000
*
1000
;
public
InterSlotDijstraV2
(
int
num
,
double
slot
)
{
// TODO Auto-generated constructor stub
this
.
num
=
num
;
this
.
slot
=
slot
;
}
//最短路径算法
public
pathRecord
dijstra
(
double
[][]
edgeWeight
,
double
testLatency
)
{
pathRecord
pathRecord
=
new
pathRecord
();
//存放上一条路径
pathRecord
.
lastHop
=
new
int
[
edgeWeight
.
length
][
edgeWeight
.
length
];
//存放最短路径
pathRecord
.
pathWeight
=
new
double
[
edgeWeight
.
length
][
edgeWeight
.
length
];
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++)
{
singlePointDijstra
(
edgeWeight
,
i
,
testLatency
,
pathRecord
.
lastHop
[
i
],
pathRecord
.
pathWeight
[
i
]);
/* for(int j = 0; j < edgeWeight.length; j++) {
pathWeight[i][j] = singleRowWeight[j];
// System.out.print(pathWeight[i][j]+""+'\t');
}*/
// System.out.println('\n');
}
// System.out.println(Arrays.deepToString(pathRecord.pathWeight));
//上一跳路由矩阵
/*System.out.println("上一跳路由矩阵");
System.out.println(Arrays.deepToString(pathRecord.lastHop));*/
// System.out.println(Arrays.deepToString(pathWeight));
return
pathRecord
;
}
//单点最短路算法
private
double
[]
singlePointDijstra
(
double
[][]
edgeWeight
,
int
point
,
double
testLatency
,
int
[]
lastHopi
,
double
[]
pathWeighti
)
{
/* //存放最短路径
double [] singleRowWeight = new double [edgeWeight.length];*/
//存放已求得最短路径节点
boolean
[]
isVisited
=
new
boolean
[
edgeWeight
.
length
];
//初始化
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++)
{
if
(
edgeWeight
[
point
][
j
]!=
MAXWEIGHT
&&
edgeWeight
[
point
][
j
]!=
slot
)
{
if
((
edgeWeight
[
point
][
j
]+
testLatency
)
<=
slot
)
{
pathWeighti
[
j
]
=
edgeWeight
[
point
][
j
]
+
testLatency
;
}
else
{
pathWeighti
[
j
]
=
MAXWEIGHT
;
}
}
else
{
pathWeighti
[
j
]
=
edgeWeight
[
point
][
j
];
}
}
isVisited
[
point
]
=
true
;
//遍历所有节点
for
(
int
j
=
0
;
j
<
edgeWeight
[
point
].
length
;
j
++)
{
//遍历下一节点
int
index
=
MAXWEIGHT
;
index
=
nextPoint
(
pathWeighti
,
index
,
isVisited
,
edgeWeight
);
if
(
index
==
MAXWEIGHT
)
{
break
;}
isVisited
[
index
]
=
true
;
//更新以下一节点中转的全局最短路
pathWeighti
=
updateSRW
(
edgeWeight
,
pathWeighti
,
point
,
index
,
isVisited
,
lastHopi
);
}
return
pathWeighti
;
}
//遍历下一节点
private
int
nextPoint
(
double
[]
singleRowWeight
,
int
index
,
boolean
[]
isVisited
,
double
[][]
edgeWeight
)
{
double
min
=
0
;
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++)
{
if
(
isVisited
[
j
]
==
false
)
{
if
(
singleRowWeight
[
j
]
!=
0
&&
min
==
0
&&
singleRowWeight
[
j
]
!=
MAXWEIGHT
)
{
min
=
singleRowWeight
[
j
];
index
=
j
;
}
if
(
singleRowWeight
[
j
]
<
min
)
{
min
=
singleRowWeight
[
j
];
index
=
j
;
}
}
}
return
index
;
}
//更新以下一节点中转的全局最短路
private
double
[]
updateSRW
(
double
[][]
edgeWeight
,
double
[]
singleRowWeight
,
int
point
,
int
index
,
boolean
[]
isVisited
,
int
[]
lastHopi
)
{
double
temp
=
singleRowWeight
[
index
];
for
(
int
k
=
0
;
k
<
edgeWeight
.
length
;
k
++)
{
if
(
isVisited
[
k
]
==
false
)
{
if
((
index
+
num
)
==
k
)
{
if
(
(
k
/
num
-
point
/
num
)*
slot
<
singleRowWeight
[
k
])
{
singleRowWeight
[
k
]
=
(
k
/
num
-
point
/
num
)*
slot
;
lastHopi
[
k
]
=
index
;
}
}
else
{
if
((
temp
+
edgeWeight
[
index
][
k
])<=
(
k
/
num
-
point
/
num
+
1
)*
slot
&&
(
temp
+
edgeWeight
[
index
][
k
])
<
singleRowWeight
[
k
])
{
singleRowWeight
[
k
]
=
temp
+
edgeWeight
[
index
][
k
];
lastHopi
[
k
]
=
index
;
}
}
}
}
return
singleRowWeight
;
}
class
pathRecord
{
//最短路矩阵
double
[][]
pathWeight
;
//上一跳矩阵
int
[][]
lastHop
;
public
pathRecord
()
{
}
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/dynamicNet/TimeExpanGraph.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.dynamicNet
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.HashMap
;
import
static
top
.
ninwoo
.
weixingsim
.
dynamicNet
.
CycleTopoUnit
.
cycleTp
;
public
class
TimeExpanGraph
{
/*
* 网络参数
*/
//设备数
static
int
num
=
30
;
//时隙大小
static
double
slot
=
20
*
1000
;
//时隙数目
static
int
slotnum
;
//网络节点数
static
int
dev
;
public
static
void
main
(
String
[]
args
)
{
doMapApp
();
}
//业务发起时刻
public
static
long
startT
;
public
static
void
doMapApp
()
{
for
(
slotnum
=
1
;
slotnum
<=
3
;
slotnum
++)
{
dev
=
num
*
slotnum
;
//10个卫星节点,3个时隙,则共有10*3个卫星节点
//组装最短路矩阵
int
[][]
matrixGraph
=
MatrixGraph
();
System
.
out
.
println
(
"大矩阵是:"
);
for
(
int
i
=
0
;
i
<
matrixGraph
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
matrixGraph
[
0
].
length
;
j
++)
{
System
.
out
.
print
(
matrixGraph
[
i
][
j
]+
" "
);
}
System
.
out
.
println
();
}
//最短路由矩阵
}
}
private
static
int
[][]
MatrixGraph
()
{
//获取当前3时隙拓扑
/**
* 先用SimpleDateFormat.parse() 方法将日期字符串转化为Date格式
* 通过Date.getTime()方法,将其转化为毫秒数
*/
String
date
=
"2019-01-01 00-00-00"
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH-mm-ss"
);
//24小时制
long
time
=
0
;
try
{
time
=
simpleDateFormat
.
parse
(
date
).
getTime
();
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
int
slotKey
=
(
int
)
((((
System
.
currentTimeMillis
()-
time
)/
20
/
1000
)-
1
)%
300
+
1
);
startT
=
((
System
.
currentTimeMillis
()-
time
)/
20000
+
1
)*
20000
;
HashMap
<
Integer
,
int
[][]>
cycleTp
=
cycleTp
();
//获得第1个时隙的连接矩阵 0或1
int
[][]
currentTp
=
cycleTp
.
get
((
slotKey
)%
30
+
1
);
int
[][]
slot1
=
new
int
[
num
][
num
];
//10*10的矩阵图
for
(
int
i
=
0
;
i
<
slot1
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot1
[
0
].
length
;
j
++){
slot1
[
i
][
j
]
=
currentTp
[
i
][
j
];
}
}
/*for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1[0].length;j++){
if (currentTp[i][j]==0){
if (i==j){
slot1[i][j]=0;
}else
slot1[i][j] = 0;
}else{
slot1[i][j] = currentTp[i][j];
}
}
}*/
//获得第2个时隙的连接矩阵
currentTp
=
cycleTp
.
get
((
slotKey
)%
30
+
2
);
int
[][]
slot2
=
new
int
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot2
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot2
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot2
[
i
][
j
]=
0
;
}
else
slot2
[
i
][
j
]
=
0
;
}
else
{
slot2
[
i
][
j
]
=
currentTp
[
i
][
j
];
}
}
}
//获得第3个时隙的连接矩阵
currentTp
=
cycleTp
.
get
((
slotKey
)%
30
+
3
);
int
[][]
slot3
=
new
int
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot3
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot3
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot3
[
i
][
j
]=
0
;
}
else
slot3
[
i
][
j
]
=
0
;
}
else
{
slot3
[
i
][
j
]
=
currentTp
[
i
][
j
];
}
}
}
//生成相邻时隙矩阵
int
[][]
neighbor
=
new
int
[
num
][
num
];
for
(
int
i
=
0
;
i
<
neighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
neighbor
.
length
;
j
++){
if
(
i
==
j
){
neighbor
[
i
][
j
]
=
1
;
}
else
{
neighbor
[
i
][
j
]
=
0
;
}
}
}
//生成其余时隙矩阵
int
[][]
nonNeighbor
=
new
int
[
num
][
num
];
for
(
int
i
=
0
;
i
<
nonNeighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
nonNeighbor
.
length
;
j
++){
nonNeighbor
[
i
][
j
]
=
0
;
}
}
//组装连接矩阵
int
[][]
edgeWeight
=
new
int
[
dev
][
dev
];
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
edgeWeight
[
0
].
length
;
j
++){
if
(
i
>=
0
&
i
<
num
&
j
>=
0
&
j
<
num
)
{
edgeWeight
[
i
][
j
]
=
slot1
[
i
][
j
];
}
else
if
(
i
>=
num
&
i
<
2
*
num
&
j
>=
num
&
j
<
2
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot2
[
i
%
num
][
j
%
num
];
}
else
if
(
i
>=
2
*
num
&
i
<
3
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot3
[
i
%
num
][
j
%
num
];
}
else
if
((
i
>=
0
&
i
<
num
&
j
>=
num
&
j
<
2
*
num
)
||
(
i
>=
num
&
i
<
2
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)){
edgeWeight
[
i
][
j
]
=
neighbor
[
i
%
num
][
j
%
num
];
}
else
{
edgeWeight
[
i
][
j
]
=
nonNeighbor
[
i
%
num
][
j
%
num
];
}
}
}
return
edgeWeight
;
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/WxMain.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
WxMain
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
WxMain
.
class
,
args
);
/*try {
new Initapp().run();
} catch (Exception e) {
e.printStackTrace();
}*/
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/entity/SimData.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology.entity
;
import
lombok.Data
;
/**
* @description 储存有关星间链路的数据
*/
@Data
public
class
SimData
{
//设置时间,默认为 2020-01-01 00-00-00
//24小时制
private
String
defaultDate
=
"2020-01-01 00-00-00"
;
//时间间隔,默认值为10
private
int
jiange
=
10
;
//周期值,默认值为100分钟,即为6000秒
private
int
zhouqi
=
6000
;
//todo:这里因该预设默认值
//星间链路带宽
private
double
bandwidth
=
10
e9
;
//加性高斯白噪声(AWGN)
private
double
n0
=
5
*
10
e
-
15
;
//信号发射功率
private
double
pt
=
5
*
10
e3
;
//信号发射增益系数
private
double
gt
=
52.5
;
//信号接收增益系数
private
double
gr
=
37.5
;
//载波波长
private
double
lamda
=
0.05
;
//星间信道容量最低容限
private
double
c0
=
10
e9
;
public
double
ptGtGr
(){
return
pt
*
gt
*
gr
;
}
public
double
n0B
(){
return
n0
*
bandwidth
;
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/entity/WeiXingData.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology.entity
;
import
lombok.Data
;
@Data
public
class
WeiXingData
{
//卫星的名字,之后可能作为增删改查的唯一标识
private
String
name
;
//地心距离
private
Float
high
=
(
float
)
780
;
//根据高度计算得出,规定(默认)逆时针为正方向
private
Double
speed
;
private
Boolean
tag
=
true
;
//测试用一个角度作为初始相位,后期需要三个角度来算出xyz坐标轴
private
Float
alpha
;
private
Float
beta
;
private
Float
gamma
;
//xyz坐标轴数据
private
Double
xaxis
;
private
Double
yaxis
;
private
Double
zaxis
;
//卫星的序列号
private
Integer
index
;
//运行时间
private
int
lastime
=
0
;
@Override
public
String
toString
(){
return
"卫星名是:"
+
name
+
";高度是:"
+
high
+
"\n"
+
"x轴坐标:"
+
xaxis
+
"\n"
+
"y轴坐标:"
+
yaxis
+
"\n"
+
"z轴坐标:"
+
zaxis
;
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/init/Initapp.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology.init
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
top.ninwoo.bishe.starter.service.ClusterService
;
import
top.ninwoo.common.entity.*
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.ToponetImpl
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.WeixingImpl
;
import
java.io.File
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
Initapp
implements
CommandLineRunner
{
@Autowired
private
ClusterService
clusterService
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.31.198:18088"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111L
);
clusterConfig
.
setOwner
(
"joliu"
);
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"D:\\LabratoryJavaPro\\codingDownload\\latestCoding\\topusim_1.txt"
);
List
<
WeiXingData
>
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
int
[][]
toponet
=
tp
.
getTopology
(
wxData
,
sd
);
//创建容器
for
(
int
k
=
0
;
k
<
wxData
.
size
();
k
++)
{
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
1
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
wxData
.
get
(
k
).
getName
());
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
cds
.
add
(
containerDescription
);
}
//设置创建时间
//自己设计的时间
//sd.setDefaultDate("2020-07-16 20-38-56");
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH-mm-ss"
);
//24小时制
clusterConfig
.
setCreateTime
(
sdf
.
parse
(
sd
.
getDefaultDate
()));
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
tp
.
getAppNames
(
wxData
));
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
toponet
);
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
//下发逻辑拓扑
clusterService
.
sendLogicTopoToEdgeNode
(
clusterConfigs
);
out:
for
(
int
i
=
1
;
i
<
600
;
i
++)
{
Thread
.
sleep
(
2000
);
int
time
=
i
*
sd
.
getJiange
();
List
<
WeiXingData
>
changetp
=
wx
.
changeTopo
(
wxData
,
time
);
topo
.
setTopology
(
tp
.
getTopology
(
changetp
,
sd
));
//下发修改后逻辑拓扑
clusterService
.
adjustLogicTopoToEdgeNode
(
clusterConfigs
);
Boolean
tag
=
false
;
for
(
int
k
=
1
;
k
<
toponet
[
0
].
length
;
k
++){
for
(
int
j
=
0
;
j
<
k
;
j
++){
if
(
toponet
[
k
][
j
]
==
tp
.
getTopology
(
changetp
,
sd
)[
k
][
j
]){
tag
=
true
;
}
}
}
if
(
tag
){
break
out
;
}
}
System
.
out
.
println
(
"所有topo完成"
);
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/Toponet.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology.service
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
java.util.List
;
/**
* 拓扑网络的服务
* 根据Weixing的服务所得到的List转化为二维数组
*/
public
interface
Toponet
{
/**
* @param weiXingDataList WeiXingData对象
* @return 拓扑图的元素
* @description 得到生成拓扑网络中的所有元素名字,需要自动生成所需的ovs,和docker容器一一对应
*/
String
[]
getAppNames
(
List
<
WeiXingData
>
weiXingDataList
);
/**
* @param weiXingDataList WeiXingData对象
* @return 二维数组,也就是拓扑图
* @description 得到网络拓扑形式类似为 app1 app2 app3 ovs1 ovs2 ovs3
*/
int
[][]
getTopology
(
List
<
WeiXingData
>
weiXingDataList
,
SimData
simData
);
/**
* @param weiXingDataList WeiXingData对象
* @return 二维数组,也就是拓扑图
* @description 得到网络拓扑形式类似为 app1 app2 app3 ovs1 ovs2 ovs3
*/
double
[][]
getWeightedTopology
(
List
<
WeiXingData
>
weiXingDataList
,
SimData
simData
);
/**
* @param a 具体的卫星a
* @param b 具体的卫星b
* @return a,b之间的距离
* @description 计算距离,在getTopology中调用
*/
Double
distance
(
WeiXingData
a
,
WeiXingData
b
);
Double
channelCapacity
(
WeiXingData
a
,
WeiXingData
b
,
SimData
simData
);
/**
@description 记录卫星拓扑的变化历史
*/
/**
* @description 写入一个文本文件中,作为拓扑的历史记录
* @param appNames 传入的卫星名字,取前1/2
* @param topo 卫星拓扑图
*/
void
history
(
String
[]
appNames
,
int
[][]
topo
);
/**
* @description 删除历史记lu
*/
void
delHistory
();
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/Weixing.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology.service
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
java.io.File
;
import
java.util.List
;
import
java.util.Map
;
/**
* 有关卫星的服务
* 1.解析初始文本,得到初始的卫星状态
* 2.将卫星的状态写入一个List中
* 3.增删改查四种基本功能
*/
public
interface
Weixing
{
/**
* @description 从文本中获取卫星的初始状态,但是其中的数据均为string型
* @param file 传入的文本路径
* @return 返回一个List
*/
List
<
Map
>
parseTxt
(
File
file
);
/**
* @description 将parseTxt中得到的Map转化为初始的卫星数据
* @param wx WeiXingData类
* @param map parseTxt得到的Map
* @return 单个卫星数据
* @throws IllegalAccessException
*/
WeiXingData
initWX
(
Class
wx
,
Map
map
)
throws
IllegalAccessException
;
List
<
WeiXingData
>
initNet
(
List
<
Map
>
maps
)
throws
IllegalAccessException
;
/**
* @description 根据卫星高度计算出卫星的速度,取逆时针为正方向。
* @description 和addAxis不同,只需计算一次即可
* @param wx WeiXingData对象
* @return
*/
List
<
WeiXingData
>
addWSpeed
(
List
<
WeiXingData
>
wx
,
int
zhouqi
);
/**
* @description 根据角度,高度,速度和间隔时间t获取卫星的坐标数据
* @param wx WeiXingData对象
* @return
*/
List
<
WeiXingData
>
addAxis
(
List
<
WeiXingData
>
wx
);
/**
* @description 为每个卫星添加序号值
* @param wx 卫星List
* @return bool类型
*/
boolean
addIndex
(
List
<
WeiXingData
>
wx
);
/**
* @description 确认index和卫星List的对应关系
* @param wx 卫星List
* @return boolean
*/
boolean
checkIndex
(
List
<
WeiXingData
>
wx
);
/**
* @description 确保卫星列表中中没有名字重复的卫星
* @param wx 卫星List
*/
void
checkWX
(
List
<
WeiXingData
>
wx
);
/**
增删改查的功能
*/
/**
* @description 根据提供的appName查找对应的序列号
* @param weiXingDataList 卫星List
* @param appName 卫星名字
* @return index 序列号
*/
Integer
findindex
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
);
/**
* @description 查找功能
* @param weiXingDataList 传入的卫星列表
* @param appName 查找的卫星名字
* @return 卫星数据
*/
WeiXingData
findWX
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
);
/**
* @description 增加一个卫星,这里无需考虑顺序问题,卫星主要靠名字搜索
* @param weiXingDataList 旧的卫星List数据
* @param newWX 新的卫星数据
* @return 新的卫星List数据
*/
List
<
WeiXingData
>
addWX
(
List
<
WeiXingData
>
weiXingDataList
,
WeiXingData
newWX
);
/**
* @description 删除指定的卫星
* @param weiXingDataList 旧的卫星List数据
* @param appName 指定卫星的名字
* @return 新的卫星List
*/
List
<
WeiXingData
>
delWX
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
);
/**
* @description 修改给定卫星的给定值,只能修改高度
* @param weiXingDataList 旧的卫星List
* @param appName 要修改的卫星名字
* @param field 要修改的属性
* @param val 要改成的值,传入为String类型,可在代码中转化为Double类型的值
* @return 新的卫星List
*/
List
<
WeiXingData
>
changeWX
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
,
String
field
,
String
val
);
/**
* @description 初始化拓扑
* @param file 传入文件路径
* @return 返回为卫星List
*/
List
<
WeiXingData
>
iniTopo
(
File
file
,
int
zhouqi
)
throws
IllegalAccessException
;
/**
* @description 改变拓扑
* @param wxData 旧的网络
* @param time 抽样时间
* @return 改变后的网络
*/
List
<
WeiXingData
>
changeTopo
(
List
<
WeiXingData
>
wxData
,
int
time
);
/**
* @description 增减卫星时需要调用
* @param wxData
* @return
*/
List
<
WeiXingData
>
initChangeTopo
(
List
<
WeiXingData
>
wxData
,
int
zhouqi
);
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/impl/ToponetImpl.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology.service.impl
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.Toponet
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
public
class
ToponetImpl
implements
Toponet
{
@Override
public
String
[]
getAppNames
(
List
<
WeiXingData
>
weiXingDataList
)
{
//先判断有多少个docker容器,并生成相对应的ovs
int
n
=
weiXingDataList
.
size
();
//创建docker容器和一个ovs的数组
String
[]
appNames
=
new
String
[
n
+
1
];
for
(
int
j
=
0
;
j
<
n
;
j
++){
appNames
[
j
]
=
weiXingDataList
.
get
(
j
).
getName
();
}
appNames
[
n
]
=
"br:"
+
"ovs"
;
return
appNames
;
}
@Override
public
int
[][]
getTopology
(
List
<
WeiXingData
>
weiXingDataList
,
SimData
simData
)
{
int
n
=
weiXingDataList
.
size
();
int
[][]
topu
=
new
int
[
n
+
1
][
n
+
1
];
//先将docker容器和ovs相连如:app1连br:ovs,app2连br:ovs
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
topu
[
n
][
i
]
=
1
;
}
//判断docker之间是否相通
for
(
int
a
=
0
;
a
<
n
;
a
++){
for
(
int
b
=
a
+
1
;
b
<
n
;
b
++){
//通过距离来判断
double
channelCapacity
=
this
.
channelCapacity
(
weiXingDataList
.
get
(
a
),
weiXingDataList
.
get
(
b
),
simData
);
if
(
channelCapacity
>=
simData
.
getC0
()){
topu
[
b
][
a
]
=
1
;
}
}
}
return
topu
;
}
@Override
public
double
[][]
getWeightedTopology
(
List
<
WeiXingData
>
weiXingDataList
,
SimData
simData
)
{
int
n
=
weiXingDataList
.
size
();
double
[][]
topu
=
new
double
[
n
+
1
][
n
+
1
];
//先将docker容器和ovs相连如:app1连br:ovs,app2连br:ovs
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
topu
[
n
][
i
]
=
1
;
}
//判断docker之间是否相通
for
(
int
a
=
0
;
a
<
n
;
a
++){
for
(
int
b
=
a
+
1
;
b
<
n
;
b
++){
//通过距离来判断
double
channelCapacity
=
this
.
channelCapacity
(
weiXingDataList
.
get
(
a
),
weiXingDataList
.
get
(
b
),
simData
);
if
(
channelCapacity
>=
simData
.
getC0
()){
topu
[
b
][
a
]
=
channelCapacity
/
1024
/
1024
;
}
}
}
return
topu
;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public
Double
distance
(
WeiXingData
a
,
WeiXingData
b
)
{
Double
r
;
r
=
Math
.
sqrt
(
Math
.
pow
(
a
.
getXaxis
()-
b
.
getXaxis
(),
2
)+
Math
.
pow
(
a
.
getYaxis
()-
b
.
getYaxis
(),
2
)+
Math
.
pow
(
a
.
getZaxis
()-
b
.
getZaxis
(),
2
));
return
r
;
}
@Override
public
Double
channelCapacity
(
WeiXingData
a
,
WeiXingData
b
,
SimData
sd
)
{
double
r
=
this
.
distance
(
a
,
b
);
double
channelCapacity
;
channelCapacity
=
sd
.
getBandwidth
()*
Math
.
log
(
1
+(
sd
.
ptGtGr
()/(
Math
.
pow
(
4
*
Math
.
PI
*
r
/
sd
.
getLamda
(),
2
)*
sd
.
n0B
())))/
Math
.
log
(
2
);
return
channelCapacity
;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public
void
history
(
String
[]
appNames
,
int
[][]
topo
)
{
File
file1
=
new
File
(
"F:\\2.GraduatePro\\topusim_1.txt"
);
try
{
FileWriter
fw
=
new
FileWriter
(
file1
,
true
);
BufferedWriter
bw
=
new
BufferedWriter
(
fw
);
//先写上日期标记
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss SSS"
);
Date
d
=
new
Date
();
String
str
=
sdf
.
format
(
d
);
bw
.
write
(
str
+
"开始的拓扑结构"
+
"\n"
);
//todo 需要设计排版
int
num
=
appNames
.
length
;
int
[][]
logic
=
new
int
[
num
][
num
];
for
(
int
i
=
0
;
i
<
num
;
i
++){
for
(
int
m
=
0
;
m
<
num
;
m
++){
logic
[
i
][
m
]
=
topo
[
i
+
num
][
m
+
num
];
bw
.
write
(
logic
[
i
][
m
]
+
" "
);
bw
.
flush
();
}
bw
.
write
(
"\n"
);
bw
.
flush
();
}
bw
.
close
();
fw
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
void
delHistory
()
{
File
file
=
new
File
(
"C:\\WorkSpace\\test\\history.txt"
);
if
(
file
.
exists
())
{
file
.
delete
();
}
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/java/top/ninwoo/weixingsim/sateTopology/service/impl/WeixingImpl.java
0 → 100644
View file @
47651670
package
top.ninwoo.weixingsim.sateTopology.service.impl
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.Weixing
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
WeixingImpl
implements
Weixing
{
@Override
public
List
<
Map
>
parseTxt
(
File
file
)
{
String
str
;
List
<
Map
>
maps
=
new
ArrayList
<
Map
>();
try
{
BufferedReader
br
=
new
BufferedReader
(
new
FileReader
(
file
));
while
((
str
=
br
.
readLine
())
!=
null
){
if
(
str
.
equals
(
"-------------"
)){
//WeiXing initwx = new WeiXing();
Map
<
String
,
String
>
map
=
new
HashMap
();
str
=
br
.
readLine
();
while
(
str
.
equals
(
"-------------"
)==
false
){
String
[]
split
=
str
.
split
(
"="
);
//if(split(0)==initwx.)
map
.
put
(
split
[
0
],
split
[
1
]);
str
=
br
.
readLine
();
}
maps
.
add
(
map
);
}
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
maps
;
}
@Override
public
WeiXingData
initWX
(
Class
wx
,
Map
map
)
throws
IllegalAccessException
{
WeiXingData
initwx
=
new
WeiXingData
();
Field
[]
fields
=
wx
.
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
field
.
setAccessible
(
true
);
if
(
field
.
getType
()
==
Float
.
class
)
{
field
.
set
(
initwx
,
Float
.
parseFloat
((
String
)
map
.
get
(
field
.
getName
())));
}
else
if
(
field
.
getType
()
==
String
.
class
)
{
field
.
set
(
initwx
,
map
.
get
(
field
.
getName
()));
}
else
if
(
field
.
getType
()
==
Boolean
.
class
)
{
if
(
map
.
get
(
field
.
getName
()).
equals
(
"true"
)){
field
.
set
(
initwx
,
true
);
}
else
{
field
.
set
(
initwx
,
false
);}
}
}
return
initwx
;
}
@Override
public
List
<
WeiXingData
>
initNet
(
List
<
Map
>
maps
)
throws
IllegalAccessException
{
List
<
WeiXingData
>
initnet
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
maps
.
size
();
i
++){
WeiXingData
wx
=
new
WeiXingData
();
wx
=
this
.
initWX
(
WeiXingData
.
class
,
maps
.
get
(
i
));
initnet
.
add
(
wx
);
}
return
initnet
;
}
@Override
public
List
<
WeiXingData
>
addWSpeed
(
List
<
WeiXingData
>
wx
,
int
zhouqi
)
{
for
(
int
i
=
0
;
i
<
wx
.
size
();
i
++){
if
(
wx
.
get
(
i
).
getTag
().
equals
(
true
)){
Double
speed
=
2
*
Math
.
PI
/
zhouqi
;
wx
.
get
(
i
).
setSpeed
(
speed
);}
else
{
wx
.
get
(
i
).
setSpeed
((-
1
)*
2
*
Math
.
PI
*(
1
/
zhouqi
));}
}
return
wx
;
}
@Override
public
List
<
WeiXingData
>
addAxis
(
List
<
WeiXingData
>
wx
)
{
for
(
int
i
=
0
;
i
<
wx
.
size
();
i
++)
{
Float
High
=
wx
.
get
(
i
).
getHigh
();
Double
hudu
=
wx
.
get
(
i
).
getSpeed
()
*
wx
.
get
(
i
).
getLastime
();
Double
Alpha
=
Math
.
toRadians
(
wx
.
get
(
i
).
getAlpha
());
Double
Beta
=
Math
.
toRadians
(
wx
.
get
(
i
).
getBeta
());
Double
Gamma
=
Math
.
toRadians
(
wx
.
get
(
i
).
getGamma
());
wx
.
get
(
i
).
setXaxis
(
High
*
Math
.
cos
(
hudu
+
Gamma
)
*
Math
.
sin
(
Beta
)
+
High
*
Math
.
sin
(
hudu
+
Gamma
)
*
Math
.
cos
(
Alpha
)
*
Math
.
cos
(
Beta
));
wx
.
get
(
i
).
setYaxis
(
High
*
Math
.
cos
(
hudu
+
Gamma
)
*
Math
.
cos
(
Beta
)
-
High
*
Math
.
sin
(
hudu
+
Gamma
)
*
Math
.
cos
(
Alpha
)
*
Math
.
sin
(
Beta
));
wx
.
get
(
i
).
setZaxis
(
High
*
Math
.
sin
(
hudu
+
Gamma
)
*
Math
.
sin
(
Alpha
));
}
return
wx
;
}
@Override
public
boolean
addIndex
(
List
<
WeiXingData
>
wx
)
{
for
(
int
i
=
0
;
i
<
wx
.
size
();
i
++){
wx
.
get
(
i
).
setIndex
(
i
+
1
);
}
return
true
;
}
@Override
public
boolean
checkIndex
(
List
<
WeiXingData
>
wx
)
{
boolean
k
=
false
;
int
tag
=
0
;
for
(
int
m
=
0
;
m
<
wx
.
size
();
m
++){
if
(
wx
.
get
(
m
).
getIndex
()
==
m
+
1
){
tag
++;
}
else
{
wx
.
get
(
m
).
setIndex
(
m
+
1
);
m
=
m
-
1
;
}
}
if
(
tag
==
wx
.
size
()){
k
=
true
;
}
return
k
;
}
@Override
public
void
checkWX
(
List
<
WeiXingData
>
wx
)
{
for
(
int
i
=
0
;
i
<
wx
.
size
();
i
++){
for
(
int
j
=
i
+
1
;
j
<
wx
.
size
();
j
++){
if
(
wx
.
get
(
i
).
getName
().
equals
(
wx
.
get
(
j
).
getName
())){
String
str
=
wx
.
get
(
i
).
getName
()
+
i
+
j
;
wx
.
get
(
j
).
setName
(
str
);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public
Integer
findindex
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
)
{
Integer
index
=
0
;
for
(
int
i
=
0
;
i
<
weiXingDataList
.
size
();
i
++){
if
(
weiXingDataList
.
get
(
i
).
getName
().
equals
(
appName
)){
index
=
weiXingDataList
.
get
(
i
).
getIndex
();
break
;
}
}
return
index
;
}
@Override
public
WeiXingData
findWX
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
)
{
WeiXingData
wxData
=
null
;
int
k
=
findindex
(
weiXingDataList
,
appName
);
if
(
k
!=
0
){
wxData
=
weiXingDataList
.
get
(
k
-
1
);
}
return
wxData
;
}
//增加和删除卫星需要反求(球坐标)
@Override
public
List
<
WeiXingData
>
addWX
(
List
<
WeiXingData
>
weiXingDataList
,
WeiXingData
newWX
)
{
//先判断是否已存在相同名字的卫星
WeiXingData
wxdata
=
findWX
(
weiXingDataList
,
newWX
.
getName
());
if
(
wxdata
!=
null
){
//加上时间这一唯一标识
newWX
.
setName
(
newWX
.
getName
()+
System
.
currentTimeMillis
());
}
weiXingDataList
.
add
(
newWX
);
//修改坐标系
for
(
int
i
=
0
;
i
<
weiXingDataList
.
size
()-
1
;
i
++){
float
gamma
=
(
float
)
(
weiXingDataList
.
get
(
i
).
getGamma
()+
weiXingDataList
.
get
(
i
).
getLastime
()*
weiXingDataList
.
get
(
i
).
getSpeed
());
weiXingDataList
.
get
(
i
).
setGamma
(
gamma
);
weiXingDataList
.
get
(
i
).
setLastime
(
0
);
}
this
.
addIndex
(
weiXingDataList
);
this
.
checkIndex
(
weiXingDataList
);
return
weiXingDataList
;
}
@Override
public
List
<
WeiXingData
>
delWX
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
)
{
//找到该卫星
WeiXingData
wxdata
=
findWX
(
weiXingDataList
,
appName
);
if
(
wxdata
!=
null
){
weiXingDataList
.
remove
(
wxdata
.
getIndex
()-
1
);
}
//修改坐标系
for
(
int
i
=
0
;
i
<
weiXingDataList
.
size
();
i
++){
float
gamma
=
(
float
)
(
weiXingDataList
.
get
(
i
).
getGamma
()+
weiXingDataList
.
get
(
i
).
getLastime
()*
weiXingDataList
.
get
(
i
).
getSpeed
());
weiXingDataList
.
get
(
i
).
setGamma
(
gamma
);
weiXingDataList
.
get
(
i
).
setLastime
(
0
);
}
this
.
addIndex
(
weiXingDataList
);
this
.
checkIndex
(
weiXingDataList
);
return
weiXingDataList
;
}
//todo 只考虑增加高度一个选项
@Override
public
List
<
WeiXingData
>
changeWX
(
List
<
WeiXingData
>
weiXingDataList
,
String
appName
,
String
field
,
String
val
)
{
return
null
;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public
List
<
WeiXingData
>
iniTopo
(
File
file
,
int
zhouqi
)
throws
IllegalAccessException
{
List
<
Map
>
maps
=
this
.
parseTxt
(
file
);
List
<
WeiXingData
>
wxData
=
this
.
initNet
(
maps
);
wxData
=
this
.
initChangeTopo
(
wxData
,
zhouqi
);
return
wxData
;
}
@Override
public
List
<
WeiXingData
>
changeTopo
(
List
<
WeiXingData
>
wxData
,
int
time
)
{
for
(
int
i
=
0
;
i
<
wxData
.
size
();
i
++){
wxData
.
get
(
i
).
setLastime
(
time
);
}
wxData
=
this
.
addAxis
(
wxData
);
this
.
addIndex
(
wxData
);
this
.
checkIndex
(
wxData
);
return
wxData
;
}
@Override
public
List
<
WeiXingData
>
initChangeTopo
(
List
<
WeiXingData
>
wxData
,
int
zhouqi
)
{
wxData
=
this
.
addWSpeed
(
wxData
,
zhouqi
);
wxData
=
this
.
addAxis
(
wxData
);
this
.
checkWX
(
wxData
);
this
.
addIndex
(
wxData
);
this
.
checkIndex
(
wxData
);
return
wxData
;
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/main/resources/application.properties
0 → 100644
View file @
47651670
bishe.app.app-name
=
joliu
#bishe.app.cloud-url=192.168.31.156:9090
bishe.app.cloud-url
=
192.168.31.213:9091
#ʱûõ
spring.influx.url
=
http://192.168.0.108:8086
spring.influx.user
=
admin
spring.influx.password
=
admin
\ No newline at end of file
apps/cnf-hadoop-computing/cnf-hadoop-test/src/test/java/top/ninwoo/hadoop/tests/HadoopTest.java
0 → 100644
View file @
47651670
package
top.ninwoo.hadoop.tests
;
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.common.entity.*
;
import
top.ninwoo.weixingsim.WxMain
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.ToponetImpl
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.WeixingImpl
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
WxMain
.
class
)
public
class
HadoopTest
{
/*hadoop计算*/
@Autowired
private
ClusterService
clusterService
;
@Resource
private
NetworkService
networkService
;
@Test
public
void
test
()
throws
IllegalAccessException
,
InterruptedException
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.31.213:18088"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11113
l
);
clusterConfig
.
setOwner
(
"joliu"
);
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"F:\\2.GraduatePro\\topusim_1.txt"
);
// D:\LabratoryJavaPro\codingDownload\latestCoding\
List
<
WeiXingData
>
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
int
[][]
toponet
=
tp
.
getTopology
(
wxData
,
sd
);
//创建容器
/* ContainerDescription containerDescription0 = new ContainerDescription();
containerDescription0.setMode("normal");
containerDescription0.setReplicas(1);
DockerContainer container0 = new DockerContainer();
container0.setName(wxData.get(0).getName());
container0.setCommand("sh");
container0.setImage("dbc_client");
container0.setPorts("8999");//指定容器端口
containerDescription0.setDockerContainer(container0);
cds.add(containerDescription0);*/
for
(
int
k
=
0
;
k
<
wxData
.
size
()-
1
;
k
++)
{
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
1
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
wxData
.
get
(
k
).
getName
());
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"hadoop_server"
);
containerDescription
.
setDockerContainer
(
container
);
cds
.
add
(
containerDescription
);
}
ContainerDescription
containerDescription0
=
new
ContainerDescription
();
containerDescription0
.
setMode
(
"normal"
);
containerDescription0
.
setReplicas
(
1
);
DockerContainer
container0
=
new
DockerContainer
();
container0
.
setName
(
wxData
.
get
(
wxData
.
size
()-
1
).
getName
());
container0
.
setCommand
(
"sh"
);
container0
.
setImage
(
"hadoop_client"
);
container0
.
setPorts
(
"8999"
);
//指定容器端口
containerDescription0
.
setDockerContainer
(
container0
);
cds
.
add
(
containerDescription0
);
/////////////////////////////////////////////
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
tp
.
getAppNames
(
wxData
));
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
toponet
);
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
//测试容器ip
@Test
public
void
getIpListByAppNameTest
()
{
//List<String> ipList = networkService.getIpListByAppName(11112L, "sate2");
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"F:\\2.GraduatePro\\topusim_1.txt"
);
List
<
WeiXingData
>
wxData
=
null
;
try
{
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
List
<
String
>
ipList
=
new
ArrayList
<>();
for
(
int
k
=
1
;
k
<
wxData
.
size
();
k
++){
String
appName
=
wxData
.
get
(
k
).
getName
();
ipList
.
add
(
networkService
.
getIpListByAppName
(
11113L
,
appName
).
toString
())
;
}
//System.out.println("长度:"+ipList.size());
}
@Test
public
void
getIpList
()
{
//List<String> ipListS = networkService.getIpListByAppName(11112L, "dfs_server");
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"F:\\2.GraduatePro\\topusim_1.txt"
);
List
<
WeiXingData
>
wxData
=
null
;
try
{
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
List
<
String
>
ipListS
=
new
ArrayList
<>();
for
(
int
k
=
1
;
k
<
wxData
.
size
();
k
++){
String
appName
=
wxData
.
get
(
k
).
getName
();
ipListS
.
add
(
networkService
.
getIpListByAppName
(
11113L
,
appName
).
toString
())
;
}
String
[]
ipList
=
new
String
[
ipListS
.
size
()];
for
(
int
i
=
0
;
i
<
ipListS
.
size
();
i
++)
{
if
(!
ipListS
.
isEmpty
()){
String
ip_tmp
=
ipListS
.
get
(
i
);
String
rep
=
ip_tmp
.
replaceAll
(
"[\\[\\]]"
,
""
);
String
[]
split_list
=
rep
.
split
(
"/"
);
ipList
[
i
]
=
split_list
[
0
];
}
}
for
(
int
j
=
0
;
j
<
ipList
.
length
;
j
++)
{
System
.
out
.
println
(
ipList
[
j
]);
}
}
@Test
public
void
removeClusterFromEdgeNodeTest
()
{
clusterService
.
removeClusterFromEdgeNode
(
11113L
);
}
}
apps/cnf-hadoop-computing/cnf-hadoop-test/src/test/java/top/ninwoo/hadoop/tests/HadoopTest2.java
0 → 100644
View file @
47651670
package
top.ninwoo.hadoop.tests
;
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.entity.ContainerMonitor
;
import
top.ninwoo.bishe.starter.service.ClusterService
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
top.ninwoo.common.entity.*
;
import
top.ninwoo.weixingsim.WxMain
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
WxMain
.
class
)
public
class
HadoopTest2
{
@Autowired
private
ClusterService
clusterService
;
@Resource
private
NetworkService
networkService
;
@Test
public
void
testSendSeparateConfig
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
// TODO: 这个ID应该是从借口获取的
//separatedClusterConfig.setEdgeNodeId("192.168.31.198:8881"); //边缘节点IP+端口号
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.31.213:18088"
);
ClusterConfig
clusterConfigCom
=
new
ClusterConfig
();
clusterConfigCom
.
setId
(
11113
l
);
clusterConfigCom
.
setOwner
(
"joliu"
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
/*通过镜像"ymwang/dfs_transfer_client"启动一个名为client的容器,来作为文件的收发端(图片的切割、合并)*/
ContainerDescription
containerDescriptionClient
=
new
ContainerDescription
();
containerDescriptionClient
.
setMode
(
"normal"
);
containerDescriptionClient
.
setReplicas
(
1
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"hadoop_client"
);
//创建一个client容器
container
.
setCommand
(
"bash"
);
container
.
setImage
(
"hadoop_client"
);
container
.
setPorts
(
"8999"
);
//指定容器端口
containerDescriptionClient
.
setDockerContainer
(
container
);
cds
.
add
(
containerDescriptionClient
);
//将client容器添加到list集合中
/*通过镜像"ymwang/dfs_transfer_server"启动一个名为server1的容器,用于存储图片切片*/
ContainerDescription
containerDescriptionServer1
=
new
ContainerDescription
();
containerDescriptionServer1
.
setMode
(
"normal"
);
containerDescriptionServer1
.
setReplicas
(
10
);
DockerContainer
containerServer1
=
new
DockerContainer
();
containerServer1
.
setName
(
"hadoop_server"
);
//创建一个server1容器
containerServer1
.
setCommand
(
"sh"
);
containerServer1
.
setImage
(
"hadoop_server"
);
containerDescriptionServer1
.
setDockerContainer
(
containerServer1
);
cds
.
add
(
containerDescriptionServer1
);
//将server1容器添加到list集合中
clusterConfigCom
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
//topo.setAppNames(new String[]{"Run", "APP", "br:ovs1"});
topo
.
setAppNames
(
new
String
[]{
"dbc_client"
,
"dbc_server"
,
"br:ovs1"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{{
0
,
0
,
0
},{
0
,
0
,
0
},{
1
,
1
,
0
}});
clusterConfigCom
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfigCom
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
//测试容器ip
@Test
public
void
getIpListByAppNameTest
()
{
List
<
String
>
ipList
=
networkService
.
getIpListByAppName
(
11113L
,
"dbc_server"
);
System
.
out
.
println
(
ipList
);
}
@Test
public
void
getIpList
()
{
List
<
String
>
ipListS
=
networkService
.
getIpListByAppName
(
11113L
,
"dbc_server"
);
String
[]
ipList
=
new
String
[
ipListS
.
size
()];
for
(
int
i
=
0
;
i
<
ipListS
.
size
();
i
++)
{
if
(!
ipListS
.
isEmpty
()){
String
ip_tmp
=
ipListS
.
get
(
i
);
String
[]
split_list
=
ip_tmp
.
split
(
"/"
);
ipList
[
i
]
=
split_list
[
0
]+
":8082"
;
}
}
for
(
int
j
=
0
;
j
<
ipList
.
length
;
j
++)
{
System
.
out
.
println
(
ipList
[
j
]);
}
}
@Test
public
void
removeClusterFromEdgeNodeTest
()
{
clusterService
.
removeClusterFromEdgeNode
(
11113L
);
}
@Test
public
void
getLogicalNetworkTopologyTest
()
{
NetworkTopology
logicalNetworkTopology
=
networkService
.
getLogicalNetworkTopology
(
11113L
);
System
.
out
.
println
(
logicalNetworkTopology
);
}
@Test
public
void
enableNetworkMonitorTest
()
throws
InterruptedException
{
String
res
=
networkService
.
enableNetworkMonitor
(
11112L
,
"server"
);
System
.
out
.
println
(
res
);
}
@Test
public
void
cancelNetworkMonitorTest
()
{
String
run
=
networkService
.
cancelNetworkMonitor
(
11112L
,
"server"
);
System
.
out
.
println
(
run
);
}
@Test
public
void
getNetworkMonitorTest
()
throws
InterruptedException
{
List
<
ContainerMonitor
>
run
=
networkService
.
getContainerMonitors
(
11112L
,
"Run"
);
int
i
=
0
;
while
(
i
<
10
)
{
run
.
forEach
(
c
->
{
System
.
out
.
println
(
c
.
getContainerInfo
());
});
Thread
.
sleep
(
500
);
i
++;
}
}
}
apps/cnf-hadoop-computing/cnf-hadoop-utils/src/main/java/top/ninwoo/hadoop/utils/ImageToArrayUtils.java
View file @
47651670
...
...
@@ -115,7 +115,7 @@ public class ImageToArrayUtils {
grayImage
[
i
].
setRGB
(
j
,
k
,
rgb
);
}
}
ImageIO
.
write
(
grayImage
[
i
],
"jpg"
,
new
File
(
"\\tmp\\static
s
\\image"
+
i
+
".jpg"
));
ImageIO
.
write
(
grayImage
[
i
],
"jpg"
,
new
File
(
"\\tmp\\static\\image"
+
i
+
".jpg"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -152,7 +152,7 @@ public class ImageToArrayUtils {
try
{
images
[
i
]
=
ImageIO
.
read
(
bis
);
//ImageIO.write(images[i], "jpg", new File("F:\\images\\grayImage\\image" + i + ".jpg"));
ImageIO
.
write
(
images
[
i
],
"jpg"
,
new
File
(
"\\tmp\\static
s
\\image"
+
i
+
".jpg"
));
ImageIO
.
write
(
images
[
i
],
"jpg"
,
new
File
(
"\\tmp\\static\\image"
+
i
+
".jpg"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -172,7 +172,7 @@ public class ImageToArrayUtils {
File
[]
imgFiles
=
new
File
[
chunks
];
for
(
int
i
=
0
;
i
<
chunks
;
i
++)
{
//imgFiles[i] = new File("F:\\images\\grayImage\\image" + i + ".jpg");
imgFiles
[
i
]
=
new
File
(
"\\tmp\\static
s
\\image"
+
i
+
".jpg"
);
imgFiles
[
i
]
=
new
File
(
"\\tmp\\static\\image"
+
i
+
".jpg"
);
}
//创建BufferedImage
...
...
apps/cnf-hadoop-computing/pom.xml
View file @
47651670
...
...
@@ -17,6 +17,7 @@
<module>
cnf-hadoop-server
</module>
<module>
cnf-hadoop-utils
</module>
<module>
cnf-hadoop-api
</module>
<module>
cnf-hadoop-test
</module>
</modules>
<dependencyManagement>
...
...
apps/cnf-weixingsim/src/main/java/top/ninwoo/weixingsim/service/Toponet.java
View file @
47651670
...
...
@@ -34,7 +34,7 @@ public interface Toponet {
*/
Double
distance
(
WeiXingData
a
,
WeiXingData
b
);
Double
channelCapacity
(
WeiXingData
a
,
WeiXingData
b
,
SimData
simData
);
Double
channelCapacity
(
WeiXingData
a
,
WeiXingData
b
,
SimData
simData
);
/**
@description 记录卫星拓扑的变化历史
...
...
@@ -44,7 +44,7 @@ public interface Toponet {
* @param appNames 传入的卫星名字,取前1/2
* @param topo 卫星拓扑图
*/
void
history
(
String
[]
appNames
,
int
[][]
topo
);
void
history
(
String
[]
appNames
,
int
[][]
topo
);
/**
* @description 删除历史记lu
...
...
apps/cnf-weixingsim/src/main/java/top/ninwoo/weixingsim/service/Weixing.java
View file @
47651670
...
...
@@ -29,7 +29,7 @@ public interface Weixing {
* @return 单个卫星数据
* @throws IllegalAccessException
*/
WeiXingData
initWX
(
Class
wx
,
Map
map
)
throws
IllegalAccessException
;
WeiXingData
initWX
(
Class
wx
,
Map
map
)
throws
IllegalAccessException
;
List
<
WeiXingData
>
initNet
(
List
<
Map
>
maps
)
throws
IllegalAccessException
;
...
...
@@ -125,7 +125,7 @@ public interface Weixing {
* @param time 抽样时间
* @return 改变后的网络
*/
List
<
WeiXingData
>
changeTopo
(
List
<
WeiXingData
>
wxData
,
int
time
);
List
<
WeiXingData
>
changeTopo
(
List
<
WeiXingData
>
wxData
,
int
time
);
/**
* @description 增减卫星时需要调用
...
...
apps/cnf-weixingsim/src/main/java/top/ninwoo/weixingsim/service/impl/WeixingImpl.java
View file @
47651670
...
...
@@ -45,7 +45,7 @@ public class WeixingImpl implements Weixing {
}
@Override
public
WeiXingData
initWX
(
Class
wx
,
Map
map
)
throws
IllegalAccessException
{
public
WeiXingData
initWX
(
Class
wx
,
Map
map
)
throws
IllegalAccessException
{
WeiXingData
initwx
=
new
WeiXingData
();
Field
[]
fields
=
wx
.
getDeclaredFields
();
//Java反射中的getDeclaredFields()方法的用处
...
...
cnf-cloud-center/src/main/resources/application.yml
View file @
47651670
...
...
@@ -2,13 +2,13 @@ server:
port
:
9091
zookeeper
:
url
:
zk.cnf.org:2181
#url: 192.168.31.190
:2181
#
url: zk.cnf.org:2181
url
:
192.168.31.213
:2181
bs
:
cloudcenter
:
name
:
my-bs-cloud-center
ipservice
:
url
:
ipservice.cnf.org:23333
#url
:
192.168.31.190:23333
\ No newline at end of file
#url: ipservice.cnf.org:23333
url
:
192.168.31.213:23333
\ No newline at end of file
cnf-edge-center/src/main/resources/application.yaml
View file @
47651670
...
...
@@ -24,17 +24,17 @@ bs:
name
:
my-bs-cloud-center
edgenode
:
name
:
random
ip-prefix
:
192.168.31
ip-prefix
:
192.168.31
.213
#ip-prefix: 192.168.31
ipservice
:
ip
:
ipservice.cnf.org:23333
#ip
:
192.168.31.190
:23333
#
ip: ipservice.cnf.org:23333
ip
:
192.168.31.213
:23333
sdn-controller
:
host
:
sdn.cnf.org
port
:
6653
zookeeper
:
url
:
zk.cnf.org:2181
#url: 192.168.31.190
:2181
#
url: zk.cnf.org:2181
url
:
192.168.31.213
:2181
cnf
:
passwd
:
Vudo3423
cnf-test/src/main/resources/application.properties
View file @
47651670
bishe.app.app-name
=
joliu
#bishe.app.cloud-url=192.168.31.156:9090
bishe.app.cloud-url
=
192.168.31.
190
:9091
bishe.app.cloud-url
=
192.168.31.
9
:9091
spring.influx.url
=
http://192.168.0.108:8086
spring.influx.user
=
admin
...
...
pom.xml
View file @
47651670
...
...
@@ -23,7 +23,6 @@
<module>
apps/cnf-distributed-file-transfer
</module>
<module>
apps/cnf-distributed-business-computing
</module>
<module>
apps/cnf-hadoop-computing
</module>
<module>
apps/cnf-hadoop-computing
</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