Commit c670b34e authored by wutu's avatar wutu

完善论文测试内容

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