Commit 462fc42f authored by Elf's avatar Elf

增加起始时间

打jar包
parent 8ba09f7e
......@@ -7,9 +7,11 @@ import lombok.Data;
*/
@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:这里因该预设默认值
......
package top.ninwoo.weixingsim.init;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import top.ninwoo.bishe.starter.service.ClusterService;
import top.ninwoo.common.entity.*;
import top.ninwoo.weixingsim.entity.SimData;
import top.ninwoo.weixingsim.entity.WeiXingData;
import top.ninwoo.weixingsim.service.impl.ToponetImpl;
import top.ninwoo.weixingsim.service.impl.WeixingImpl;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@Component
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.190.135: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("C:\\WorkSpace\\test\\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完成");
}
}
......@@ -17,6 +17,8 @@ import top.ninwoo.weixingsim.service.impl.WeixingImpl;
import javax.annotation.Resource;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
......@@ -310,7 +312,7 @@ public class WxTests {
//下发逻辑拓扑
clusterService.sendLogicTopoToEdgeNode(clusterConfigs);
out:for (int i = 1; ; i++) {
out:for (int i = 1; i<600; i++) {
Thread.sleep(2000);
int time = i * sd.getJiange();
List<WeiXingData> changetp = wx.changeTopo(wxData,time);
......@@ -562,4 +564,88 @@ public class WxTests {
*/
}
//测试设置时间
@Test
public void test7() throws IllegalAccessException, InterruptedException, ParseException {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
List<ContainerDescription> cds = new ArrayList<>();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig.setEdgeNodeId("192.168.190.135: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("C:\\WorkSpace\\test\\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完成");
}
}
......@@ -18,6 +18,7 @@ import top.ninwoo.utils.entity.NetworkInfo;
import top.ninwoo.utils.entity.OvsBridge;
import top.ninwoo.utils.service.TcService;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.*;
......@@ -316,12 +317,12 @@ public class IndexController {
}
//下发逻辑拓扑
@RequestMapping(value = "/sendLogicTopo", method = RequestMethod.POST)
public String sendLogicTopo(@RequestBody ClusterConfig clusterConfig) {
public String sendLogicTopo(@RequestBody ClusterConfig clusterConfig) throws ParseException {
if(clusterConfig == null){
return "请传入正确的集群设置";
}
// 使用topo创建工具
String res = logicTopoService.creatLogicTopo(clusterConfig.getId(), clusterConfig.getTopology());
String res = logicTopoService.creatLogicTopo(clusterConfig.getId(), clusterConfig.getTopology(),clusterConfig.getCreateTime());
//System.out.println("ok");
return res;
}
......
package top.ninwoo.edgecenter.service;
import com.sun.xml.internal.ws.spi.db.DatabindingException;
import top.ninwoo.common.entity.NetworkTopology;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
//逻辑网络
public interface LogicTopoService {
//通过逻辑拓扑创造逻辑网络
String creatLogicTopo(long clusterId, NetworkTopology logictopo);
String creatLogicTopo (long clusterId, NetworkTopology logictopo, Date date) throws ParseException;
//调整逻辑网络
String modifyLogicTopology(long clusterId, NetworkTopology logictopo);
//得到逻辑拓扑
......
......@@ -10,6 +10,8 @@ import top.ninwoo.edgecenter.service.IpService;
import top.ninwoo.edgecenter.service.LogicTopoService;
import top.ninwoo.utils.service.IptablesService;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -38,7 +40,7 @@ public class LogicTopoServiceImpl implements LogicTopoService {
private IptablesService iptablesService;
@Override
public String creatLogicTopo(long clusterId, NetworkTopology oldtopo) {
public String creatLogicTopo(long clusterId, NetworkTopology oldtopo,Date date) throws ParseException {
List<String> IPlist = new ArrayList<String>();
NetworkTopology logictopo = this.getLogictopo(oldtopo);
......@@ -71,7 +73,6 @@ public class LogicTopoServiceImpl implements LogicTopoService {
clustersTopo.put(clusterId, logictopo);
clustersIPlist.put(clusterId,IPlist);
Date date = new Date();
time = date.getTime();
topoAll.put(time,logictopo.getTopology());
return "success";
......
......@@ -12,6 +12,7 @@ import top.ninwoo.common.entity.*;
import top.ninwoo.client.BisheTestMain;
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
......@@ -30,7 +31,7 @@ public class BisheTests {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig.setEdgeNodeId("192.168.190.135:8081");
separatedClusterConfig.setEdgeNodeId("192.168.190.135:18088");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
clusterConfig.setOwner("joliu");
......@@ -124,7 +125,7 @@ public class BisheTests {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
//需修改为下发的IP地址
separatedClusterConfig.setEdgeNodeId("192.168.190.135:8081");
separatedClusterConfig.setEdgeNodeId("192.168.190.135:18088");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
......@@ -205,7 +206,7 @@ public class BisheTests {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
//需修改为下发的IP地址
separatedClusterConfig.setEdgeNodeId("192.168.190.135:8081");
separatedClusterConfig.setEdgeNodeId("192.168.190.135:18088");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
......
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