Commit 44daf7ef authored by wutu's avatar wutu

Merge branch 'pretty-log' of gitee.com:prowo_admin/bishe into pretty-log

parents 4b07dc37 4848a97f
......@@ -14,4 +14,6 @@ public interface ClusterService {
String removeClusterFromEdgeNode(Long clusterId);
List<String> getAllEdgeNodeIds();
boolean adjustClusterToEdgeNode(List<SeparatedClusterConfig> configs);
}
package top.ninwoo.bishe.starter.service;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import top.ninwoo.bishe.starter.config.ClientProperties;
......@@ -21,6 +22,8 @@ public class ClusterServiceImpl implements ClusterService {
= "/cluster/removeClusterFromEdgeNode?clusterId=";
private final static String GET_ALL_EDGE_NODE_IDS
= "/cluster/getEdgeNodeIds";
private final static String ADJUST_CLUSTER_TO_EDGE_NODE
= "/cluster/adjustCluster";
@Resource
private RestTemplate restTemplate;
......@@ -50,4 +53,15 @@ public class ClusterServiceImpl implements ClusterService {
return restTemplate.getForObject("http://" + clientProperties.getCloudUrl() +
GET_ALL_EDGE_NODE_IDS, List.class);
}
@Override
public boolean adjustClusterToEdgeNode(List<SeparatedClusterConfig> configs) {
Map<String, Object> param = new HashMap<>();
param.put("configs", configs.toArray());
ResponseEntity<Boolean> result = restTemplate.postForEntity("http://" + clientProperties.getCloudUrl() + ADJUST_CLUSTER_TO_EDGE_NODE, configs, Boolean.class);
return result.getStatusCode().is2xxSuccessful();
}
}
......@@ -34,4 +34,9 @@ public class ClusterController {
public List<String> getEdgeNodeIds() {
return cloudService.getEdgeNodeIds();
}
@RequestMapping(value = "/adjustCluster", method = RequestMethod.POST)
public Boolean adjustClusterToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
return cloudService.adjustCluster(clusterConfigs);
}
}
......@@ -34,4 +34,5 @@ public interface CloudService {
List<String> getEdgeNodeIds();
boolean adjustCluster(List<SeparatedClusterConfig> clusterConfigs);
}
......@@ -20,6 +20,7 @@ public class CloudServiceImpl implements CloudService {
private static final Random randomInt = new Random(14);
private static final String CREATE_CLUSTER = "/createCluster";
private static final String DELETE_CLUSTER = "/delCluster";
private static final String ADJUST_CLUSTER = "/adjustCluster";
private static final String DROP_DOCKER_NETWORK = "/dropDockerNetwork?clusterId={clusterId}&appName={appName}&ipList={ipList}";
private static final String CANCEL_DROP_DOCKER_NETWORK = "/cancelDropDockerNetwork?clusterId={clusterId}&appName={appName}&ipList={ipList}";
private static final String REMOTE_IP_LIST_BY_APPNAME = "/getIpListByAppName?clusterId={clusterId}&appName={appName}";
......@@ -49,6 +50,26 @@ public class CloudServiceImpl implements CloudService {
private RestTemplate restTemplate;
@Override
public boolean adjustCluster(List<SeparatedClusterConfig> clusterConfigs) {
if(clusterConfigs == null) {
throw new RuntimeException("clusterConfig cannot be null.");
}
try {
clusterConfigs.forEach(c -> {
ResponseEntity<String> response = restTemplate.postForEntity("http://" + c.getEdgeNodeId() + ADJUST_CLUSTER, c.getClusterConfig(), String.class);
if (!response.getStatusCode().is2xxSuccessful()) {
throw new RuntimeException("send Error!");
}
LOG.info("{} update success!", c.getEdgeNodeId());
});
} catch (Exception e) {
return false;
}
return true;
}
/**
* 这里的拓扑必须限定为逻辑拓扑
* @param clusterConfig
......
......@@ -78,7 +78,7 @@ public class BisheMultiNodeTests {
List<ContainerDescription> cds1 = new ArrayList<>();
cds1.add(containerDescription11);
ContainerDescription containerDescription12 = new ContainerDescription();
/*ContainerDescription containerDescription12 = new ContainerDescription();
containerDescription12.setMode("normal");
containerDescription12.setReplicas(1);
DockerContainer container12 = new DockerContainer();
......@@ -87,11 +87,11 @@ public class BisheMultiNodeTests {
container12.setImage("joliu/networktest");
containerDescription12.setDockerContainer(container12);
cds1.add(containerDescription12);
cds1.add(containerDescription12);*/
clusterConfig1.setDockers(cds1);
NetworkTopology topo1 = new NetworkTopology();
topo1.setAppNames(new String[]{"APP2", "br:ovs3", "br:ovs4","br:ovs5","br:ovs6","br:ovs7","br:ovs8","br:remote:ovs2:192.168.61.130"});
topo1.setAppNames(new String[]{"APP3", "br:ovs3", "br:ovs4","br:ovs5","br:ovs6","br:ovs7","br:ovs8","br:remote:ovs2:192.168.61.130"});
// 这个参数好像没啥用
topo1.setTopologyId(11);
......@@ -99,7 +99,7 @@ public class BisheMultiNodeTests {
,{0,0,0,0,0,0,0,0}
,{0,1,0,0,0,0,0,0}
,{0,0,1,0,0,0,0,0}
,{0,0,1,1,0,0,0,0}
,{0,0,1,0,0,0,0,0}
,{0,0,0,0,1,0,0,0}
,{1,0,0,0,0,1,0,0}
,{0,1,0,0,0,0,0,0}});
......@@ -108,6 +108,14 @@ public class BisheMultiNodeTests {
clusterConfigs.add(separatedClusterConfig1);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
topo1.getTopology()[5][3] = 1;
adjustCluster(clusterConfigs);
}
private boolean adjustCluster(List<SeparatedClusterConfig> configs) {
boolean b = clusterService.adjustClusterToEdgeNode(configs);
return b;
}
......
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