Commit 82c0d7f0 authored by ymwang's avatar ymwang

添加云计算模块

parent 862dea04
bishe.app.app-name=joliu
#bishe.app.cloud-url=192.168.31.156:9090
bishe.app.cloud-url=192.168.81.1:9091
spring.influx.url=http://192.168.0.108:8086
spring.influx.user=admin
spring.influx.password=admin
\ No newline at end of file
package top.ninwoo.distri.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.distri.test.DistriTestMain;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DistriTestMain.class)
public class WymDisCloudTests {
/*分散计算业务的测试*/
@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.81.133:18088");
ClusterConfig clusterConfigCom = new ClusterConfig();
clusterConfigCom.setId(11114l);
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("dbc_cloud_client");//创建一个client容器
container.setCommand("sh");
container.setImage("dbc_cloud_client");
container.setPorts("8000");//指定容器端口
containerDescriptionClient.setDockerContainer(container);
cds.add(containerDescriptionClient);//将client容器添加到list集合中
/*通过镜像"ymwang/dfs_transfer_server"启动一个名为server1的容器,用于存储图片切片*/
ContainerDescription containerDescriptionServer1 = new ContainerDescription();
containerDescriptionServer1.setMode("normal");
containerDescriptionServer1.setReplicas(1);
DockerContainer containerServer1 = new DockerContainer();
containerServer1.setName("dbc_cloud_server");//创建一个server1容器
containerServer1.setCommand("sh");
containerServer1.setImage("dbc_cloud_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_cloud_client", "dbc_cloud_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(11114L, "dbc_cloud_server");
System.out.println(ipList);
}
@Test
public void getIpList() {
List<String> ipListS = networkService.getIpListByAppName(11114L, "dbc_cloud_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]+":8888";
}
}
for (int j = 0; j < ipList.length; j++) {
System.out.println(ipList[j]);
}
}
@Test
public void removeClusterFromEdgeNodeTest() {
clusterService.removeClusterFromEdgeNode(11114L);
}
@Test
public void getLogicalNetworkTopologyTest() {
NetworkTopology logicalNetworkTopology = networkService.getLogicalNetworkTopology(11114L);
System.out.println(logicalNetworkTopology);
}
@Test
public void enableNetworkMonitorTest() throws InterruptedException {
String res = networkService.enableNetworkMonitor(11114L, "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++;
}
}
}
package top.ninwoo.dbc.cloud.client.service;
import top.ninwoo.bishe.starter.service.NetworkService;
import top.ninwoo.dbc.api.po.*;
import top.ninwoo.dbc.api.service.DistributedComService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,6 +11,7 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
......@@ -27,11 +29,32 @@ public class FileCloService {
@Autowired
private RestTemplate restTemplate;
@Autowired
private NetworkService networkService;
@Autowired
private DistributedComService distributedComService;
String cloudIp = "127.0.0.1:8888";
//String cloudIp = "127.0.0.1:8888";
//String cloudIp = "172.17.0.4:8888";
private String cloudIp = null;
@PostConstruct
public void init() {
cloudIp = getIpList(11114l,"dbc_cloud_server");
System.out.println(cloudIp);
}
public String getIpList(Long clusterId, String appName) {
List<String> ipList = networkService.getIpListByAppName(clusterId, appName);
if(!ipList.isEmpty()){
String ip_tmp = ipList.get(0);
String[] split_list = ip_tmp.split("/");
String containerIp = split_list[0]+":8888";
return containerIp;
}
return null;
}
/**
......@@ -44,8 +67,9 @@ public class FileCloService {
public String sendFile(Long fileId, byte[] fileBytes) {
// 通过集群服务器接口获取当前集群的节点数量
// todo 这里需要制定文件的fileId
cloudIp = getIpList(11114l,"dbc_cloud_server");
// todo 这里需要制定文件的fileId
FileCloudSlice fileCloudSlice = new FileCloudSlice();
fileCloudSlice.setFileCloudId(fileId);
fileCloudSlice.setFileByte(fileBytes);
......@@ -76,6 +100,8 @@ public class FileCloService {
}
public String getFile(String fileName, Long fileId) {
cloudIp = getIpList(11114l,"dbc_cloud_server");
Set<FileCloudSlice> result = new HashSet<>();
Set<FileCloudSlice> fileCloudComSet = getFileSlice(cloudIp, fileId);
......
......@@ -2,8 +2,8 @@
server.port=8000
#接入云端的端口设置
#bishe.app.app-name=joliu
#bishe.app.cloud-url=192.168.31.156:9090
bishe.app.app-name=joliu
bishe.app.cloud-url=192.168.81.1:9091
#容器里的挂载目录
dbc.directory.output=/tmp/static/
......
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