Commit 86a5047d authored by wutu's avatar wutu

删除容器id出现bug,已修复

parent 544e2ce3
...@@ -6,6 +6,7 @@ import top.ninwoo.edgecenter.entity.ClusterConfig; ...@@ -6,6 +6,7 @@ import top.ninwoo.edgecenter.entity.ClusterConfig;
import top.ninwoo.edgecenter.entity.ContainerInfo; import top.ninwoo.edgecenter.entity.ContainerInfo;
import top.ninwoo.edgecenter.entity.NetworkTopology; import top.ninwoo.edgecenter.entity.NetworkTopology;
import top.ninwoo.edgecenter.service.ClusterService; import top.ninwoo.edgecenter.service.ClusterService;
import top.ninwoo.edgecenter.service.TopologyService;
import top.ninwoo.utils.entity.DockerContainer; import top.ninwoo.utils.entity.DockerContainer;
import top.ninwoo.utils.entity.NetworkInfo; import top.ninwoo.utils.entity.NetworkInfo;
import top.ninwoo.utils.entity.OvsBridge; import top.ninwoo.utils.entity.OvsBridge;
...@@ -22,6 +23,9 @@ public class IndexController { ...@@ -22,6 +23,9 @@ public class IndexController {
@Autowired @Autowired
ClusterService clusterService; ClusterService clusterService;
@Autowired
TopologyService topologyService;
@RequestMapping("/index") @RequestMapping("/index")
public List<DockerContainer> index(int flag) { public List<DockerContainer> index(int flag) {
...@@ -155,15 +159,23 @@ public class IndexController { ...@@ -155,15 +159,23 @@ public class IndexController {
} }
@RequestMapping(value = "/createTopo", method = RequestMethod.POST) @RequestMapping(value = "/createTopo", method = RequestMethod.POST)
public NetworkTopology createTopo(long topologyId, String[] appNames, String topology) { public NetworkTopology createTopo(long clusterId, long topologyId, String[] appNames, String topology) {
// 二维数组作为一个字符串传递进来,需要进行一个解析 // 二维数组作为一个字符串传递进来,需要进行一个解析
NetworkTopology topo = new NetworkTopology(); NetworkTopology topo = new NetworkTopology();
topo.setAppNames(appNames); topo.setAppNames(appNames);
topo.setTopologyId(111); topo.setTopologyId(111);
topo.setTopology(parseString(topology)); topo.setTopology(parseString(topology));
// 使用topo创建工具
topologyService.createTopo(clusterId, topo);
return topo; return topo;
} }
@RequestMapping(value = "/delCluster", method = RequestMethod.GET)
public String delCluster(long clusterId) {
clusterService.removeContainersByClusterId(clusterId);
return "success";
}
private int[][] parseString(String topology) { private int[][] parseString(String topology) {
String[] lines = topology.split(";"); String[] lines = topology.split(";");
int x = lines.length; int x = lines.length;
......
package top.ninwoo.edgecenter.service; package top.ninwoo.edgecenter.service;
import top.ninwoo.edgecenter.entity.ClusterConfig; import top.ninwoo.edgecenter.entity.ClusterConfig;
import top.ninwoo.edgecenter.entity.NetworkTopology;
/** /**
* @Author joliu * @Author joliu
...@@ -15,4 +16,6 @@ public interface TopologyService { ...@@ -15,4 +16,6 @@ public interface TopologyService {
* @param clusterConfig * @param clusterConfig
*/ */
void initTopo(ClusterConfig clusterConfig); void initTopo(ClusterConfig clusterConfig);
void createTopo(long clusterId, NetworkTopology topology);
} }
...@@ -165,7 +165,14 @@ public class ClusterServiceImpl implements ClusterService { ...@@ -165,7 +165,14 @@ public class ClusterServiceImpl implements ClusterService {
return; return;
} }
clustersInfo.get(clusterId).keySet().forEach( clustersInfo.get(clusterId).keySet().forEach(
c -> removeContainersByClusterIdAndContainerName(clusterId, c) //c -> removeContainersByClusterIdAndContainerName(clusterId, c)
// bug: 遍历过程中,不能进行删除,会导致并发错误,不能直接调用removeContainersByCo...接口
cName -> {
LOG.debug("删除应用[" + cName + "]");
// 获取全部的容器id
clustersInfo.get(clusterId).get(cName).forEach(
c -> dockerService.deleteDockerById(c));
}
); );
clustersInfo.remove(clusterId); clustersInfo.remove(clusterId);
} }
......
...@@ -3,6 +3,7 @@ package top.ninwoo.edgecenter.service.impl; ...@@ -3,6 +3,7 @@ package top.ninwoo.edgecenter.service.impl;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.ninwoo.edgecenter.entity.ClusterConfig; import top.ninwoo.edgecenter.entity.ClusterConfig;
import top.ninwoo.edgecenter.entity.NetworkTopology; import top.ninwoo.edgecenter.entity.NetworkTopology;
import top.ninwoo.edgecenter.service.ClusterService; import top.ninwoo.edgecenter.service.ClusterService;
...@@ -18,6 +19,7 @@ import java.util.Set; ...@@ -18,6 +19,7 @@ import java.util.Set;
* @Description 这里描述的物理连接的拓扑关系 * @Description 这里描述的物理连接的拓扑关系
* @Date Create in 上午11:16 2019/11/7 * @Date Create in 上午11:16 2019/11/7
*/ */
@Service
public class TopologyServiceImpl implements TopologyService { public class TopologyServiceImpl implements TopologyService {
private final static Logger LOG = LoggerFactory.getLogger(TopologyServiceImpl.class); private final static Logger LOG = LoggerFactory.getLogger(TopologyServiceImpl.class);
...@@ -37,9 +39,13 @@ public class TopologyServiceImpl implements TopologyService { ...@@ -37,9 +39,13 @@ public class TopologyServiceImpl implements TopologyService {
@Override @Override
public void initTopo(ClusterConfig clusterConfig) { public void initTopo(ClusterConfig clusterConfig) {
// 获取topology // 获取topology
NetworkTopology topology = clusterConfig.getTopology(); createTopo(clusterConfig.getId(), clusterConfig.getTopology());
}
@Override
public void createTopo(long clusterId, NetworkTopology topology) {
if(topology == null) { if(topology == null) {
LOG.warn("集群[" + clusterConfig.getId() + "]未设置网络"); LOG.warn("集群[" + clusterId + "]未设置网络");
return; return;
} }
...@@ -56,7 +62,7 @@ public class TopologyServiceImpl implements TopologyService { ...@@ -56,7 +62,7 @@ public class TopologyServiceImpl implements TopologyService {
// 判断每一个节点的连接状态 // 判断每一个节点的连接状态
if(topo[i][j] == 1) { if(topo[i][j] == 1) {
// 如果存在连接,则创建连接 // 如果存在连接,则创建连接
addLink(clusterConfig.getId(), cNames[i], cNames[j]); addLink(clusterId, cNames[i], cNames[j]);
} }
} }
} }
......
...@@ -249,6 +249,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -249,6 +249,7 @@ public class OvsUtilsImpl implements OvsUtils {
*/ */
@Override @Override
public boolean setVxlan(String bridgeName, String remoteIp) { public boolean setVxlan(String bridgeName, String remoteIp) {
// TODO: bug
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl add-port " + bridgeName String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl add-port " + bridgeName
+ " vxlan0 -- set interface vxlan0 type=vxlan options:remote_ip=" + remoteIp; + " vxlan0 -- set interface vxlan0 type=vxlan options:remote_ip=" + remoteIp;
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
......
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