Commit ce5d2893 authored by Hu Jintao's avatar Hu Jintao

添加路径计算代码模块

parent d86722e1
<?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</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>business-api</artifactId>
</project>
\ No newline at end of file
package com.pitong.business.item;
import java.io.Serializable;
import java.util.List;
public class DataPackage implements Serializable {
private int number;
private List<Integer> sequence;
private Picture picture;
private String loc;
private double eta;
private Long currentime;
private Long fun1time;
private List<Double> compCapacity;
public List<Double> getCompCapacity() {
return compCapacity;
}
public void setCompCapacity(List<Double> compCapacity) {
this.compCapacity = compCapacity;
}
public void setFun1time(Long fun1time) {
this.fun1time = fun1time;
}
public Long getFun1time() {
return fun1time;
}
public void setCurrentime(Long currentime) {
this.currentime = currentime;
}
public Long getCurrentime() {
return currentime;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public List<Integer> getSequence() {
return sequence;
}
public void setSequence(List<Integer> sequence) {
this.sequence = sequence;
}
public Picture getPicture() {
return picture;
}
public void setPicture(Picture picture) {
this.picture = picture;
}
public String getLoc() {
return loc;
}
public void setLoc(String loc) {
this.loc = loc;
}
public double getEta() {
return eta;
}
public void setEta(double eta) {
this.eta = eta;
}
}
package com.pitong.business.item;
import java.io.Serializable;
public class Picture implements Serializable {
private byte[] data;
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
int length = data.length;
this.data = new byte[length];
for (int i = 0; i < length; i++) {
this.data[i] = data[i];
}
}
}
<?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</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>businessInCloud</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>top.ninwoo</groupId>
<artifactId>business-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package top.ninwoo.test;
import com.pitong.business.item.DataPackage;
import com.pitong.business.item.Picture;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.Banner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import top.ninwoo.test.doMap.DoMap;
import top.ninwoo.test.doMap.path;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
@SpringBootApplication
@path
public class BisheTestMain implements ApplicationRunner {
@Value("${eta}")
private double ETA;
@Value("${targetIp}")
private String targetIp;
public static void main(String[] args) {
new SpringApplicationBuilder(BisheTestMain.class)
.web(WebApplicationType.NONE) // .REACTIVE, .SERVLET
.bannerMode(Banner.Mode.OFF)
.run(args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
//解析注解
Class<BisheTestMain> bisheTestMainClass = BisheTestMain.class;
path annotation = bisheTestMainClass.getAnnotation(path.class);
String rmCmd = annotation.rmCmd();
String saveCmd1 = annotation.saveCmd1();
String saveCmd2 = annotation.saveCmd2();
String saveCmd3 = annotation.saveCmd3();
String saveCmd4 = annotation.saveCmd4();
String saveCmd5 = annotation.saveCmd5();
String savePath = annotation.savePath();
System.out.println("========================================");
System.out.println("exec start timestamp: " + System.currentTimeMillis());
System.out.println();
// DoMap doMap = new DoMap();
List<Integer> sequence = Arrays.asList(1, 3, 7, 8, 12, 17, 20);
System.out.println("optimal mapping scheme"+sequence);
String loc = null;
String file_path = "passport.jpg";
int number = 1;
double eta = ETA;
Long currentime = System.currentTimeMillis();
Long fun1time = Long.valueOf(0);
List<Double> compCapacity = Arrays.asList(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.2到1,首尾固定为1M/s
DataPackage dataPackage = combine(number, sequence, loc, file_path, eta, currentime, fun1time, compCapacity);
send(dataPackage, targetIp, 2020);
for(int i = 0;i<sequence.size();i++){
ServerSocket serverSocket = new ServerSocket(8900);
//获取数据流
Socket accept = serverSocket.accept();
InputStream inputStream = accept.getInputStream();
//读取数据流
ObjectInputStream objectInputStream = new ObjectInputStream(new BufferedInputStream(inputStream));
Object object = null;
try {
object = objectInputStream.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
List<String> strings = (List) object;
//输出数据流
for (String s:strings
) {
System.out.println(s);
}
serverSocket.close();
accept.close();
System.out.println();
}
//生成保存目录
File dirpath = new File(savePath);
if (!dirpath.exists()){
creatParent(dirpath);
dirpath.mkdir();
}
try { // 起作用的代码其实就下面这一行, 参数是linux中要执行的代码
Runtime.getRuntime().exec(rmCmd).waitFor();
Runtime.getRuntime().exec(saveCmd1).waitFor();//jthudocker
Runtime.getRuntime().exec(saveCmd2).waitFor();//jthudocker
Runtime.getRuntime().exec(saveCmd3).waitFor();//jthudocker
for(int i =1;i<sequence.size();i++){
Runtime.getRuntime().exec("docker cp sate"+sequence.get(i)+saveCmd4+sequence.get(i)+".jpg").waitFor();
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(saveCmd5);
System.out.println("========================================");
// System.out.print("File size :");
// System.out.println(dataPackage.getPicture().getData().length / 1000+"k");
}
private void creatParent(File dirpath) {
File file = new File(dirpath.getParent());
if (!file.exists()) {
creatParent(file);
file.mkdir();
}
}
private static DataPackage combine(int number, List<Integer> sequence, String loc, String file_path, double eta, Long Currentime, Long fun1time, List<Double> compCapacity) {
DataPackage dataPackage = new DataPackage();
dataPackage.setNumber(number);
dataPackage.setPicture(loadPicture(file_path));
dataPackage.setSequence(sequence);
dataPackage.setEta(eta);
dataPackage.setCurrentime(Currentime);
dataPackage.setFun1time(fun1time);
dataPackage.setCompCapacity(compCapacity);
return dataPackage;
}
private static Picture loadPicture(String pic_url) {
try {
File f = new File(pic_url);
InputStream is = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
is.read(b);
is.close();
Picture picture = new Picture();
picture.setData(b);
return picture;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static void send(DataPackage dataPackage, String ip, int port) {
Socket socket = null;
try {
socket = new Socket(ip, port);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
objectOutputStream.writeObject(dataPackage);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (socket != null) {
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 得到0.5到1的随机数
* @return
*/
public static Double getRangeDate(){
Double max=1.0;
Double min=0.5;
Random random = new Random();
return random.nextDouble()%(max-min) + min;
}
}
package top.ninwoo.test.doMap;
import java.util.Arrays;
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(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() {
}
}
}
package top.ninwoo.test.doMap;
import java.util.ArrayList;
import java.util.List;
public class RandomArray {
public static void main(String[] args) {
int [] arr = gennerateArray(10, 100);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
List comCapacity = gennerateArray(20,100.0);
System.out.println(comCapacity);
}
public static int[] gennerateArray (int len,int max){
int[] arr=new int[len];
for(int i=0;i<arr.length;i++){
arr[i]=(int)(Math.random()*max);
}
return arr;
}
public static ArrayList<Double> gennerateArray (int len, double max){
ArrayList<Double> objects = new ArrayList<>();
for(int i =0;i<len;i++){
objects.add(Math.random()/2.0+0.5);
}
return objects;
}
}
package top.ninwoo.test.doMap;
import java.io.File;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface path {
String savePath() default "/home/ninwoo/dynamic_sate/picResult";
String rmCmd() default "rm /home/ninwoo/dynamic_sate/picResult/*.jpg";
String saveCmd1() default "docker cp sate1_0:/pic/in.jpg /home/ninwoo/dynamic_sate/picResult/source.jpg";
String saveCmd2() default "docker cp sate1_0:/pic/out1.jpg /home/ninwoo/dynamic_sate/picResult/task_1.1.jpg";
String saveCmd3() default "docker cp sate1_0:/pic/out2.jpg /home/ninwoo/dynamic_sate/picResult/task_1.2.jpg";
String saveCmd4() default "_0:/pic/out.jpg /home/ninwoo/dynamic_sate/picResult/task_";
String saveCmd5() default "save pictrues to dynamic_sate/picResult directory finish";
}
bishe.app.app-name=joliu
bishe.app.cloud-url=192.168.47.130:9091
# bishe.app.cloud-url=192.168.31.198:9090
eta=0.7
targetIp=172.17.0.2
#targetIp=192.168.47.1
#eta=${eta}
#targetIp=${targetIp}
\ No newline at end of file
<?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</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>businessInDocker</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>top.ninwoo</groupId>
<artifactId>business-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.pitong.business;
import com.pitong.business.item.DataPackage;
import com.pitong.business.item.Picture;
import com.pitong.business.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;
@SpringBootApplication
public class Application implements ApplicationRunner {
@Autowired
private ServerService serverService;
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class)
.web(WebApplicationType.NONE) // .REACTIVE, .SERVLET
.bannerMode(Banner.Mode.OFF)
.run(args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
ServerSocket serverSocket = null;
InputStream inputStream = null;
ObjectInputStream objectInputStream = null;
Long startime = System.currentTimeMillis();
try {
serverSocket = new ServerSocket(2020);
while (true) {
Socket client = serverSocket.accept();
inputStream = client.getInputStream();
objectInputStream = new ObjectInputStream(new BufferedInputStream(inputStream));
Object object = objectInputStream.readObject();
DataPackage dataPackage = (DataPackage) object;
int number = dataPackage.getNumber();
List<Integer> sequence = dataPackage.getSequence();
Picture picture = dataPackage.getPicture();
String loc = dataPackage.getLoc();
double eta = dataPackage.getEta();
Long Currentime = dataPackage.getCurrentime();
Long fun1time = dataPackage.getFun1time();
List<Double> compCapacity = dataPackage.getCompCapacity();
System.out.println("=====================");
String methodName = "func" + number;
Method method = serverService.getClass().getMethod(methodName, Class.forName("java.util.List"), Picture.class, Class.forName("java.lang.String"), Class.forName("java.lang.Double"),
Class.forName("java.lang.Long"),Class.forName("java.lang.Long"), Class.forName("java.lang.Long"), Class.forName("java.util.List"));
method.invoke(serverService, sequence, picture, loc, eta, Currentime, startime, fun1time, compCapacity);
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
} finally {
try {
if (objectInputStream != null) {
objectInputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
if (serverSocket != null) {
serverSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.pitong.business.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.ninwoo.bishe.starter.service.NetworkService;
import java.util.List;
@Service
public class IPService {
@Autowired
private NetworkService networkService;
public String getIpByAppName(String appName) {
List<String> ipList = networkService.getIpListByAppName(11111l, appName);
if(!ipList.isEmpty()){
String ip_tmp = ipList.get(0);
String[] split_list = ip_tmp.split("/");
return split_list[0];
}
return null;
}
}
package com.pitong.business.service;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface parameters {
double coe() default 0.7;
long slot() default 1000L*20;
String cldUrl() default "192.168.47.130";
int cldPort() default 8900;
}
bishe:
app:
app-name: joliu
cloud-url: 192.168.47.130:9091
# cloud-url: 192.168.31.198:9090
slot: 20000 # 1000L*20
coe: 0.7
cldUrl: 192.168.47.130
cldPort: 8900
<?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</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sateDeploy</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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package top.ninwoo.test;
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.app.app-name=joliu
bishe.app.cloud-url=cloud.cnf.org:9091
\ No newline at end of file
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.entity.ContainerMonitor;
import top.ninwoo.bishe.starter.service.ClusterService;
import top.ninwoo.bishe.starter.service.NetworkService;
import top.ninwoo.common.entity.*;
import top.ninwoo.test.BisheTestMain;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BisheTestMain.class)
public class BisheMultiNodeTests {
@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.154:8081");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
clusterConfig.setOwner("joliu");
ContainerDescription containerDescription = new ContainerDescription();
containerDescription.setMode("normal");
containerDescription.setReplicas(1);
DockerContainer container = new DockerContainer();
container.setName("APP1");
container.setCommand("sh");
container.setImage("joliu/networktest");
containerDescription.setDockerContainer(container);
List<ContainerDescription> cds = new ArrayList<>();
cds.add(containerDescription);
ContainerDescription containerDescription1 = new ContainerDescription();
containerDescription1.setMode("normal");
containerDescription1.setReplicas(1);
DockerContainer container1 = new DockerContainer();
container1.setName("APP2");
container1.setCommand("sh");
container1.setImage("joliu/networktest");
containerDescription1.setDockerContainer(container1);
cds.add(containerDescription1);
clusterConfig.setDockers(cds);
NetworkTopology topo = new NetworkTopology();
topo.setAppNames(new String[]{"APP1", "APP2", "br:ovs1", "br:remote:ovs2:192.168.31.16"});
// 这个参数好像没啥用
topo.setTopologyId(11);
topo.setTopology(new int[][]{{0,0,0,0},{0,0,0,0},{1,1,0,0},{0,0,1,0}});
clusterConfig.setTopology(topo);
separatedClusterConfig.setClusterConfig(clusterConfig);
clusterConfigs.add(separatedClusterConfig);
// 构建第二个节点
SeparatedClusterConfig separatedClusterConfig1 = new SeparatedClusterConfig();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig1.setEdgeNodeId("192.168.31.16:8081");
ClusterConfig clusterConfig1 = new ClusterConfig();
clusterConfig1.setId(11111l);
clusterConfig1.setOwner("joliu");
ContainerDescription containerDescription11 = new ContainerDescription();
containerDescription11.setMode("normal");
containerDescription11.setReplicas(1);
DockerContainer container11 = new DockerContainer();
container11.setName("APP3");
container11.setCommand("sh");
container11.setImage("joliu/networktest");
containerDescription11.setDockerContainer(container11);
List<ContainerDescription> cds1 = new ArrayList<>();
cds1.add(containerDescription11);
ContainerDescription containerDescription12 = new ContainerDescription();
containerDescription12.setMode("normal");
containerDescription12.setReplicas(1);
DockerContainer container12 = new DockerContainer();
container12.setName("APP4");
container12.setCommand("sh");
container12.setImage("joliu/networktest");
containerDescription12.setDockerContainer(container12);
cds1.add(containerDescription12);
clusterConfig1.setDockers(cds1);
NetworkTopology topo1 = new NetworkTopology();
topo1.setAppNames(new String[]{"APP3", "APP4", "br:ovs2", "br:remote:ovs1:192.168.31.154"});
// 这个参数好像没啥用
topo1.setTopologyId(11);
topo1.setTopology(new int[][]{{0,0,0,0},{0,0,0,0},{1,1,0,0},{0,0,1,0}});
clusterConfig1.setTopology(topo1);
separatedClusterConfig1.setClusterConfig(clusterConfig1);
clusterConfigs.add(separatedClusterConfig1);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
}
@Test
public void removeClusterFromEdgeNodeTest() {
clusterService.removeClusterFromEdgeNode(11111L);
}
@Test
public void getLogicalNetworkTopologyTest() {
NetworkTopology logicalNetworkTopology = networkService.getLogicalNetworkTopology(11111L);
System.out.println(logicalNetworkTopology);
}
@Test
public void getIpListByAppNameTest() {
List<String> ipList = networkService.getIpListByAppName(11111L, "APP3");
System.out.println(ipList);
}
@Test
public void enableNetworkMonitorTest() throws InterruptedException {
String res = networkService.enableNetworkMonitor(11111L, "Run");
System.out.println(res);
}
@Test
public void cancelNetworkMonitorTest() {
String run = networkService.cancelNetworkMonitor(11111L, "Run");
System.out.println(run);
}
@Test
public void getNetworkMonitorTest() throws InterruptedException {
List<ContainerMonitor> run = networkService.getContainerMonitors(11111L, "Run");
int i = 0;
while(i < 10) {
run.forEach(c -> {
System.out.println(c.getContainerInfo());
});
Thread.sleep(500);
i++;
}
}
@Test
public void getAllEdgeNodeIdsTest() {
List<String> allEdgeNodeIds = clusterService.getAllEdgeNodeIds();
System.out.println(allEdgeNodeIds);
}
}
...@@ -102,6 +102,7 @@ public class CloudRegisterCenter implements Register { ...@@ -102,6 +102,7 @@ public class CloudRegisterCenter implements Register {
LOG.info("新的节点{}已接入", event.getData().getPath()); LOG.info("新的节点{}已接入", event.getData().getPath());
String newNode = event.getData().getPath(); String newNode = event.getData().getPath();
String newNodeIp = new String(event.getData().getData()); String newNodeIp = new String(event.getData().getData());
LOG.info("新的节点信息{}", newNodeIp);
// 通过newNodeIp获取边缘服务器的信息 // 通过newNodeIp获取边缘服务器的信息
// 注册信息到中心节点上 // 注册信息到中心节点上
// 这里通过网络进行请求,其实也是在做一次测试,查看远程服务器是否符合版本要求,网络是否顺畅 // 这里通过网络进行请求,其实也是在做一次测试,查看远程服务器是否符合版本要求,网络是否顺畅
......
...@@ -24,7 +24,7 @@ bs: ...@@ -24,7 +24,7 @@ bs:
name: my-bs-cloud-center name: my-bs-cloud-center
edgenode: edgenode:
name: random name: random
ip-prefix: 192.168.31 ip-prefix: 192.168
ipservice: ipservice:
ip: ipservice.cnf.org:23333 ip: ipservice.cnf.org:23333
sdn-controller: sdn-controller:
......
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
<module>apps/cnf-weixingsim</module> <module>apps/cnf-weixingsim</module>
<module>apps/cnf-case-dis</module> <module>apps/cnf-case-dis</module>
<module>apps/cnf-app-demo</module> <module>apps/cnf-app-demo</module>
<module>apps/cnf-path-computing/businessInDocker</module>
<module>apps/cnf-path-computing/businessInCloud</module>
<module>apps/cnf-path-computing/sateDeploy</module>
<module>apps/cnf-path-computing/business-api</module>
</modules> </modules>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment