Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-WIC-Cnf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CommunityXG
OpenXG-WIC-Cnf
Commits
b72113de
Commit
b72113de
authored
Nov 18, 2019
by
wutu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成并测试集群创建和删除的功能模块
parent
72eff040
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
3 deletions
+69
-3
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/CloudService.java
...ain/java/top/ninwoo/cloudcenter/service/CloudService.java
+2
-0
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
...top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
+22
-0
bishe-cloud-center/src/test/java/top/ninwoo/cloud/CloudServiceImplTest.java
.../src/test/java/top/ninwoo/cloud/CloudServiceImplTest.java
+10
-2
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
...ava/top/ninwoo/edgecenter/controller/IndexController.java
+6
-1
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/TopologyService.java
...n/java/top/ninwoo/edgecenter/service/TopologyService.java
+2
-0
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/ClusterServiceImpl.java
...op/ninwoo/edgecenter/service/impl/ClusterServiceImpl.java
+1
-0
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/TopologyServiceImpl.java
...p/ninwoo/edgecenter/service/impl/TopologyServiceImpl.java
+26
-0
No files found.
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/CloudService.java
View file @
b72113de
...
...
@@ -13,4 +13,6 @@ public interface CloudService {
String
initCluster
(
ClusterConfig
clusterConfig
);
List
<
SeparatedClusterConfig
>
sendClusterConfigToEdgeNode
(
List
<
SeparatedClusterConfig
>
clusterConfigs
);
boolean
deleteClusterFromEdgeNode
(
long
clusterId
);
}
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
View file @
b72113de
...
...
@@ -21,6 +21,7 @@ public class CloudServiceImpl implements CloudService {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
CloudServiceImpl
.
class
);
private
static
final
Random
randomInt
=
new
Random
(
14
);
private
static
final
String
CREATE_CLUSTER
=
"/createCluster"
;
private
static
final
String
DELETE_CLUSTER
=
"/delCluster"
;
// 用于存储配置文件
private
ConcurrentHashMap
<
Long
,
List
<
SeparatedClusterConfig
>>
allClusterConfig
=
new
ConcurrentHashMap
<>();
...
...
@@ -199,8 +200,29 @@ public class CloudServiceImpl implements CloudService {
if
(!
response
.
getStatusCode
().
is2xxSuccessful
())
{
LOG
.
error
(
"集群配置下发失败:{}:{}"
,
c
.
getEdgeNodeId
(),
response
.
getBody
());
}
if
(!
allClusterConfig
.
containsKey
(
c
.
getClusterConfig
().
getId
()))
{
allClusterConfig
.
put
(
c
.
getClusterConfig
().
getId
(),
new
ArrayList
<>());
}
allClusterConfig
.
get
(
c
.
getClusterConfig
().
getId
()).
add
(
c
);
});
return
clusterConfigs
;
}
/**
* 删除全部的容器集群
* @param clusterId
* @return
*/
@Override
public
boolean
deleteClusterFromEdgeNode
(
long
clusterId
)
{
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"clusterId"
,
clusterId
);
List
<
SeparatedClusterConfig
>
separatedClusterConfigs
=
allClusterConfig
.
get
(
clusterId
);
separatedClusterConfigs
.
forEach
(
c
->
{
// 调用远程借口删除服务
restTemplate
.
getForEntity
(
"http://"
+
c
.
getEdgeNodeId
()
+
DELETE_CLUSTER
+
"?clusterId="
+
clusterId
,
String
.
class
);
});
return
true
;
}
}
bishe-cloud-center/src/test/java/top/ninwoo/cloud/CloudServiceImplTest.java
View file @
b72113de
...
...
@@ -11,6 +11,7 @@ import top.ninwoo.cloudcenter.service.CloudService;
import
top.ninwoo.common.entity.ClusterConfig
;
import
top.ninwoo.common.entity.ContainerDescription
;
import
top.ninwoo.common.entity.DockerContainer
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -53,14 +54,21 @@ public class CloudServiceImplTest {
cds
.
add
(
containerDescription1
);
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
new
String
[]{
"Run"
,
"APP"
,
"br:ovs1"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{{
0
,
0
,
0
},{
0
,
0
,
0
},{
1
,
1
,
0
}});
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
cloudService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
cloudService
.
deleteClusterFromEdgeNode
(
11111
l
);
}
@Test
public
void
deleteClusterFromEdgeNodeTest
()
{
}
}
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
View file @
b72113de
...
...
@@ -105,7 +105,9 @@ public class IndexController {
public
long
createCluster
(
@RequestBody
ClusterConfig
clusterConfig
)
{
// 创建一个解析器
long
l
=
clusterService
.
initContainers
(
clusterConfig
);
// 使用json进行解析
// 创建网络
// 使用topo创建工具
topologyService
.
createTopo
(
l
,
clusterConfig
.
getTopology
());
return
l
;
}
...
...
@@ -165,7 +167,10 @@ public class IndexController {
@RequestMapping
(
value
=
"/delCluster"
,
method
=
RequestMethod
.
GET
)
public
String
delCluster
(
long
clusterId
)
{
// 删除集群
topologyService
.
removeTopoByCluterId
(
clusterId
);
clusterService
.
removeContainersByClusterId
(
clusterId
);
return
"success"
;
}
...
...
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/TopologyService.java
View file @
b72113de
...
...
@@ -27,4 +27,6 @@ public interface TopologyService {
// 调整网络拓扑,这里限定条件为,网络节点不改变
String
modifyTopology
(
long
clusterId
,
NetworkTopology
topology
);
void
removeTopoByCluterId
(
long
clusterId
);
}
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/ClusterServiceImpl.java
View file @
b72113de
...
...
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
import
top.ninwoo.common.entity.DockerContainer
;
import
top.ninwoo.edgecenter.entity.ClusterConfig
;
import
top.ninwoo.edgecenter.entity.ContainerDescription
;
import
top.ninwoo.edgecenter.entity.NetworkTopology
;
import
top.ninwoo.edgecenter.service.ClusterService
;
import
top.ninwoo.edgecenter.service.TopologyService
;
import
top.ninwoo.utils.entity.NetworkInfo
;
...
...
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/TopologyServiceImpl.java
View file @
b72113de
...
...
@@ -358,4 +358,30 @@ public class TopologyServiceImpl implements TopologyService {
throw
new
RuntimeException
(
"Physical topology does not support c2c link."
);
}
}
@Override
public
void
removeTopoByCluterId
(
long
clusterId
)
{
if
(!
clustersTopo
.
containsKey
(
clusterId
))
{
return
;
}
NetworkTopology
topo
=
clustersTopo
.
get
(
clusterId
);
setZeroTopo
(
topo
);
// 先将全部网络调整为0
modifyTopology
(
clusterId
,
topo
);
String
[]
appNames
=
clustersTopo
.
get
(
clusterId
).
getAppNames
();
for
(
String
appName
:
appNames
)
{
if
(
appName
.
contains
(
"br"
)
&&
!
appName
.
contains
(
"remote"
))
{
ovsService
.
delBridge
(
appName
.
substring
(
3
));
}
}
}
private
void
setZeroTopo
(
NetworkTopology
topo
)
{
int
[][]
topology
=
topo
.
getTopology
();
for
(
int
i
=
0
;
i
<
topology
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
topology
.
length
;
j
++)
{
topology
[
i
][
j
]
=
0
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment