Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Distributed Computing and Network Fusion System
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
WirelessInformationCollaborate
Distributed Computing and Network Fusion System
Commits
63dd43bf
Commit
63dd43bf
authored
Nov 28, 2019
by
wutu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
构建基础的java-api客户端
parent
245e984e
Changes
37
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
809 additions
and
53 deletions
+809
-53
bishe-client-starter/pom.xml
bishe-client-starter/pom.xml
+49
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/config/BisheAppAutoConfiguration.java
...inwoo/bishe/starter/config/BisheAppAutoConfiguration.java
+33
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/config/ClientProperties.java
...ava/top/ninwoo/bishe/starter/config/ClientProperties.java
+13
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/entity/ContainerMonitor.java
...ava/top/ninwoo/bishe/starter/entity/ContainerMonitor.java
+47
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/ClusterService.java
...java/top/ninwoo/bishe/starter/service/ClusterService.java
+15
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/ClusterServiceImpl.java
.../top/ninwoo/bishe/starter/service/ClusterServiceImpl.java
+45
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkService.java
...java/top/ninwoo/bishe/starter/service/NetworkService.java
+24
-0
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkServiceImpl.java
.../top/ninwoo/bishe/starter/service/NetworkServiceImpl.java
+121
-0
bishe-client-starter/src/main/resources/META-INF/spring.factories
...ient-starter/src/main/resources/META-INF/spring.factories
+2
-0
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/controller/ClusterController.java
.../top/ninwoo/cloudcenter/controller/ClusterController.java
+31
-0
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/controller/NetworkController.java
.../top/ninwoo/cloudcenter/controller/NetworkController.java
+42
-0
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/entity/SeparatedClusterConfig.java
...top/ninwoo/cloudcenter/entity/SeparatedClusterConfig.java
+0
-24
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/CloudService.java
...ain/java/top/ninwoo/cloudcenter/service/CloudService.java
+11
-1
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
...top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
+87
-10
bishe-cloud-center/src/main/resources/application.yml
bishe-cloud-center/src/main/resources/application.yml
+4
-2
bishe-cloud-center/src/test/java/top/ninwoo/cloud/CloudServiceImplTest.java
.../src/test/java/top/ninwoo/cloud/CloudServiceImplTest.java
+1
-7
bishe-cloud-ipservice/pom.xml
bishe-cloud-ipservice/pom.xml
+19
-0
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/controller/IpController.java
...a/top/ninwoo/cloud/ipservice/controller/IpController.java
+8
-0
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/service/IpService.java
...in/java/top/ninwoo/cloud/ipservice/service/IpService.java
+2
-0
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/service/impl/IpServiceImpl.java
...op/ninwoo/cloud/ipservice/service/impl/IpServiceImpl.java
+17
-0
bishe-common-api/pom.xml
bishe-common-api/pom.xml
+1
-0
bishe-common-api/src/main/java/top/ninwoo/common/entity/ClusterConfig.java
...src/main/java/top/ninwoo/common/entity/ClusterConfig.java
+1
-1
bishe-common-api/src/main/java/top/ninwoo/common/entity/ContainerMonitorInfo.java
...n/java/top/ninwoo/common/entity/ContainerMonitorInfo.java
+14
-0
bishe-common-api/src/main/java/top/ninwoo/common/entity/NetworkTopology.java
...c/main/java/top/ninwoo/common/entity/NetworkTopology.java
+11
-0
bishe-common-api/src/main/java/top/ninwoo/common/entity/SeparatedClusterConfig.java
...java/top/ninwoo/common/entity/SeparatedClusterConfig.java
+9
-0
bishe-edge-center/pom.xml
bishe-edge-center/pom.xml
+21
-2
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
...ava/top/ninwoo/edgecenter/controller/IndexController.java
+9
-0
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/IpService.java
...rc/main/java/top/ninwoo/edgecenter/service/IpService.java
+2
-0
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/ClusterServiceImpl.java
...op/ninwoo/edgecenter/service/impl/ClusterServiceImpl.java
+19
-3
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/IpServiceImpl.java
...ava/top/ninwoo/edgecenter/service/impl/IpServiceImpl.java
+10
-0
bishe-edge-center/src/main/resources/application.yaml
bishe-edge-center/src/main/resources/application.yaml
+2
-3
bishe-test/pom.xml
bishe-test/pom.xml
+34
-0
bishe-test/src/main/java/top/ninwoo/test/BisheTestMain.java
bishe-test/src/main/java/top/ninwoo/test/BisheTestMain.java
+11
-0
bishe-test/src/main/resources/application.properties
bishe-test/src/main/resources/application.properties
+2
-0
bishe-test/src/test/java/top/ninwoo/BisheTests.java
bishe-test/src/test/java/top/ninwoo/BisheTests.java
+88
-0
bishe-utils/pom.xml
bishe-utils/pom.xml
+2
-0
pom.xml
pom.xml
+2
-0
No files found.
bishe-client-starter/pom.xml
0 → 100644
View file @
63dd43bf
<?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-client-starter
</artifactId>
<properties>
<dubbo.version>
2.7.4.1
</dubbo.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
<version>
2.1.2.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
1.16.18
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<version>
2.1.2.RELEASE
</version>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
bishe-common-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
<version>
5.2.0.RELEASE
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/config/BisheAppAutoConfiguration.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.bishe.starter.config
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
@Slf4j
@Configuration
@ComponentScan
(
value
=
"top.ninwoo.bishe.starter"
)
@EnableConfigurationProperties
(
ClientProperties
.
class
)
public
class
BisheAppAutoConfiguration
{
@Resource
private
ClientProperties
clientProperties
;
@PostConstruct
public
void
init
()
{
log
.
info
(
"开启这个client-starter"
);
log
.
info
(
"cloud配置为{}"
,
clientProperties
);
}
@Bean
public
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
}
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/config/ClientProperties.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.bishe.starter.config
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
@Data
@ConfigurationProperties
(
prefix
=
"bishe.app"
)
public
class
ClientProperties
{
private
String
zookeeperUrl
=
"zookeeper://127.0.0.1:2181"
;
private
String
cloudUrl
=
"127.0.0.1:9300"
;
private
String
appName
=
"default"
;
}
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/entity/ContainerMonitor.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.bishe.starter.entity
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.client.RestTemplate
;
import
top.ninwoo.common.entity.ContainerInfo
;
import
top.ninwoo.common.entity.ContainerMonitorInfo
;
import
java.util.HashMap
;
import
java.util.Map
;
@Slf4j
public
class
ContainerMonitor
{
private
static
final
String
GET_CONTAINER_INFO_BY_CONTAINER_ID
=
"/getContainerMonitorByContainerId?containerId={containerId}"
;
// 远程edgeNode的ID
private
String
edgeNodeId
;
// 对应cluster的id
private
long
clusterId
;
// 对应的app name
private
String
appName
;
private
String
monitorUrl
;
private
String
containerId
;
private
RestTemplate
restTemplate
;
public
ContainerMonitor
(
ContainerMonitorInfo
containerMonitorInfo
,
RestTemplate
restTemplate
)
{
this
.
edgeNodeId
=
containerMonitorInfo
.
getEdgeNodeId
();
this
.
clusterId
=
containerMonitorInfo
.
getClusterId
();
this
.
appName
=
containerMonitorInfo
.
getAppName
();
this
.
containerId
=
containerMonitorInfo
.
getContainerId
();
monitorUrl
=
"http://"
+
edgeNodeId
+
GET_CONTAINER_INFO_BY_CONTAINER_ID
;
this
.
restTemplate
=
restTemplate
;
}
public
ContainerInfo
getContainerInfo
()
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"containerId"
,
this
.
containerId
);
ContainerInfo
containerInfo
=
restTemplate
.
getForObject
(
monitorUrl
,
ContainerInfo
.
class
,
param
);
// 这里可能返回一个null的类,此时需要上级的调用函数做处理
return
containerInfo
;
}
}
\ No newline at end of file
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/ClusterService.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.bishe.starter.service
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
top.ninwoo.common.entity.SeparatedClusterConfig
;
import
java.util.List
;
/**
* 操作集群的api接口
*/
public
interface
ClusterService
{
List
<
SeparatedClusterConfig
>
sendClusterConfigToEdgeNode
(
List
<
SeparatedClusterConfig
>
configs
);
String
removeClusterFromEdgeNode
(
Long
clusterId
);
}
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/ClusterServiceImpl.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.bishe.starter.service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
top.ninwoo.bishe.starter.config.ClientProperties
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
top.ninwoo.common.entity.SeparatedClusterConfig
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
ClusterServiceImpl
implements
ClusterService
{
private
final
static
String
SEND_CLUSTER_CONFIG_TO_EDGE_NODE
=
"/cluster/sendClusterConfigToEdgeNode"
;
private
final
static
String
REMOVE_CLUSTER_FROM_EDGE_NODE
=
"/cluster/removeClusterFromEdgeNode?clusterId="
;
@Resource
private
RestTemplate
restTemplate
;
@Resource
private
ClientProperties
clientProperties
;
@Override
public
List
<
SeparatedClusterConfig
>
sendClusterConfigToEdgeNode
(
List
<
SeparatedClusterConfig
>
configs
)
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"configs"
,
configs
.
toArray
());
List
<
SeparatedClusterConfig
>
results
=
restTemplate
.
postForObject
(
"http://"
+
clientProperties
.
getCloudUrl
()
+
SEND_CLUSTER_CONFIG_TO_EDGE_NODE
,
configs
,
List
.
class
);
return
results
;
}
@Override
public
String
removeClusterFromEdgeNode
(
Long
clusterId
)
{
return
restTemplate
.
getForObject
(
"http://"
+
clientProperties
.
getCloudUrl
()
+
REMOVE_CLUSTER_FROM_EDGE_NODE
+
clusterId
,
String
.
class
);
}
}
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkService.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.bishe.starter.service
;
import
top.ninwoo.bishe.starter.entity.ContainerMonitor
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
java.util.List
;
/**
* 网络服务接口
*/
public
interface
NetworkService
{
/**
* 获取逻辑网络拓扑
* @param clusterId
* @return
*/
NetworkTopology
getLogicalNetworkTopology
(
Long
clusterId
);
List
<
String
>
getIpListByAppName
(
Long
clusterId
,
String
appName
);
String
enableNetworkMonitor
(
Long
clusterId
,
String
appName
);
List
<
ContainerMonitor
>
getContainerMonitors
(
Long
clusterId
,
String
appName
);
}
bishe-client-starter/src/main/java/top/ninwoo/bishe/starter/service/NetworkServiceImpl.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.bishe.starter.service
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
top.ninwoo.bishe.starter.config.ClientProperties
;
import
top.ninwoo.bishe.starter.entity.ContainerMonitor
;
import
top.ninwoo.common.entity.ContainerMonitorInfo
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Service
public
class
NetworkServiceImpl
implements
NetworkService
{
// 获取 网络的逻辑拓扑
private
final
static
String
GET_LOGICAL_NETWORK_TOPOLOGY
=
"/network/getLogicalNetworkTopology?clusterId={clusterId}"
;
private
final
static
String
GET_IP_LIST_BY_APP_NAME
=
"/network/getIpListByAppName?clusterId={clusterId}&appName={appName}"
;
private
final
static
String
ENABLE_NETWORK_MONITOR
=
"/enableNetworkMonitor?clusterId={clusterId}&appName={appName}"
;
private
final
static
String
GET_NETWORK_MONITOR_INFO
=
"/getNetworkMonitorInfo?clusterId={clusterId}&appName={appName}"
;
@Resource
ClientProperties
clientProperties
;
@Resource
RestTemplate
restTemplate
;
@Override
public
NetworkTopology
getLogicalNetworkTopology
(
Long
clusterId
)
{
String
cloudUrl
=
clientProperties
.
getCloudUrl
();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
ResponseEntity
<
NetworkTopology
>
response
=
restTemplate
.
getForEntity
(
"http://"
+
cloudUrl
+
GET_LOGICAL_NETWORK_TOPOLOGY
,
NetworkTopology
.
class
,
param
);
if
(!
response
.
getStatusCode
().
is2xxSuccessful
())
{
log
.
error
(
"网络请求失败"
);
throw
new
RuntimeException
(
"网络请求出现异常"
);
}
return
response
.
getBody
();
}
/**
* 通过AppName找到对应的全部ip地址列表
* @param clusterId
* @param appName
* @return
*/
@Override
public
List
<
String
>
getIpListByAppName
(
Long
clusterId
,
String
appName
)
{
String
cloudUrl
=
clientProperties
.
getCloudUrl
();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"appName"
,
appName
);
ResponseEntity
<
List
>
response
=
restTemplate
.
getForEntity
(
"http://"
+
cloudUrl
+
GET_IP_LIST_BY_APP_NAME
,
List
.
class
,
param
);
if
(!
response
.
getStatusCode
().
is2xxSuccessful
())
{
log
.
error
(
"网络请求错误"
);
throw
new
RuntimeException
(
"网络请求错误"
);
}
return
response
.
getBody
();
}
/**
* 对容器应用开启网速监控
* @param clusterId
* @param appName
* @return
*/
@Override
public
String
enableNetworkMonitor
(
Long
clusterId
,
String
appName
)
{
String
cloudUrl
=
clientProperties
.
getCloudUrl
();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"appName"
,
appName
);
// 这里需要构建这个ContainerMonitor
return
restTemplate
.
getForObject
(
"http://"
+
cloudUrl
+
ENABLE_NETWORK_MONITOR
,
String
.
class
,
param
);
}
/**
* 获取容器监控的钩子程序
* @param clusterId
* @param appName
* @return
*/
@Override
public
List
<
ContainerMonitor
>
getContainerMonitors
(
Long
clusterId
,
String
appName
)
{
String
cloudUrl
=
clientProperties
.
getCloudUrl
();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"appName"
,
appName
);
// 这里需要构建这个ContainerMonitor
List
<
ContainerMonitorInfo
>
containerMonitorInfos
=
restTemplate
.
getForObject
(
"http://"
+
cloudUrl
+
GET_NETWORK_MONITOR_INFO
,
List
.
class
,
param
);
List
<
ContainerMonitor
>
containerMonitors
=
new
ArrayList
<>();
containerMonitorInfos
.
forEach
(
c
->
{
containerMonitors
.
add
(
new
ContainerMonitor
(
c
,
restTemplate
));
});
return
containerMonitors
;
}
}
\ No newline at end of file
bishe-client-starter/src/main/resources/META-INF/spring.factories
0 → 100644
View file @
63dd43bf
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
top.ninwoo.bishe.starter.config.BisheAppAutoConfiguration
\ No newline at end of file
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/controller/ClusterController.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.cloudcenter.controller
;
import
org.springframework.web.bind.annotation.*
;
import
top.ninwoo.cloudcenter.service.CloudService
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
top.ninwoo.common.entity.SeparatedClusterConfig
;
import
javax.annotation.Resource
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/cluster"
)
public
class
ClusterController
{
@Resource
CloudService
cloudService
;
@RequestMapping
(
value
=
"/sendClusterConfigToEdgeNode"
,
method
=
RequestMethod
.
POST
)
public
List
<
SeparatedClusterConfig
>
sendClusterConfigToEdgeNode
(
@RequestBody
List
<
SeparatedClusterConfig
>
clusterConfigs
)
{
return
cloudService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
@RequestMapping
(
value
=
"/removeClusterFromEdgeNode"
)
public
String
removeClusterFromEdgeNode
(
Long
clusterId
)
{
boolean
res
=
cloudService
.
deleteClusterFromEdgeNode
(
clusterId
);
if
(
res
)
{
return
"success"
;
}
return
"fail"
;
}
}
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/controller/NetworkController.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.cloudcenter.controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
top.ninwoo.cloudcenter.service.CloudService
;
import
top.ninwoo.common.entity.ContainerMonitorInfo
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
@RestController
@RequestMapping
(
"/network"
)
public
class
NetworkController
{
@Resource
CloudService
cloudService
;
@RequestMapping
(
value
=
"/getLogicalNetworkTopology"
)
public
NetworkTopology
getLogicalNetworkTopology
(
Long
clusterId
)
{
return
cloudService
.
getLogicalNetworkByClusterId
(
clusterId
);
}
@RequestMapping
(
value
=
"/getIpListByAppName"
)
public
List
<
String
>
getIpListByAppName
(
Long
clusterId
,
String
appName
)
{
Set
<
String
>
ipSet
=
cloudService
.
getIpListFromRemoteIpServiceByAppName
(
clusterId
,
appName
);
// 这里的ipSet是无序的
return
new
ArrayList
<>(
ipSet
);
}
@RequestMapping
(
value
=
"/enableNetworkMonitor"
)
public
String
enableNetworkMonitor
(
Long
clusterId
,
String
appName
)
{
return
cloudService
.
enableNetworkMonitor
(
clusterId
,
appName
);
}
@RequestMapping
(
value
=
"/getNetworkMonitorInfo"
)
public
List
<
ContainerMonitorInfo
>
getNetworkMonitor
(
Long
clusterId
,
String
appName
)
{
// 这里可以理解为是返回一个网络监控的钩子程序,具体的查询还需要通过钩子进行执行
return
cloudService
.
getContainerMonitorInfoByAppName
(
clusterId
,
appName
);
}
}
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/entity/SeparatedClusterConfig.java
deleted
100644 → 0
View file @
245e984e
package
top.ninwoo.cloudcenter.entity
;
import
top.ninwoo.common.entity.ClusterConfig
;
public
class
SeparatedClusterConfig
{
private
ClusterConfig
clusterConfig
;
private
String
edgeNodeId
;
public
ClusterConfig
getClusterConfig
()
{
return
clusterConfig
;
}
public
void
setClusterConfig
(
ClusterConfig
clusterConfig
)
{
this
.
clusterConfig
=
clusterConfig
;
}
public
String
getEdgeNodeId
()
{
return
edgeNodeId
;
}
public
void
setEdgeNodeId
(
String
edgeNodeId
)
{
this
.
edgeNodeId
=
edgeNodeId
;
}
}
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/CloudService.java
View file @
63dd43bf
package
top.ninwoo.cloudcenter.service
;
import
top.ninwoo.cloudcenter.entity.SeparatedClusterConfig
;
import
top.ninwoo.common.entity.ClusterConfig
;
import
top.ninwoo.common.entity.ContainerMonitorInfo
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
top.ninwoo.common.entity.SeparatedClusterConfig
;
import
java.util.List
;
import
java.util.Set
;
/**
* 云端的服务接口
...
...
@@ -12,9 +14,17 @@ import java.util.List;
public
interface
CloudService
{
String
initCluster
(
ClusterConfig
clusterConfig
);
Set
<
String
>
getIpListFromRemoteIpServiceByAppName
(
long
clusterId
,
String
appName
);
List
<
SeparatedClusterConfig
>
sendClusterConfigToEdgeNode
(
List
<
SeparatedClusterConfig
>
clusterConfigs
);
boolean
deleteClusterFromEdgeNode
(
long
clusterId
);
void
updateLogicalTopology
(
long
clusterId
,
NetworkTopology
topology
);
NetworkTopology
getLogicalNetworkByClusterId
(
Long
clusterId
);
String
enableNetworkMonitor
(
Long
clusterId
,
String
appName
);
List
<
ContainerMonitorInfo
>
getContainerMonitorInfoByAppName
(
Long
clusterId
,
String
appName
);
}
bishe-cloud-center/src/main/java/top/ninwoo/cloudcenter/service/impl/CloudServiceImpl.java
View file @
63dd43bf
...
...
@@ -2,15 +2,13 @@ package top.ninwoo.cloudcenter.service.impl;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
top.ninwoo.cloudcenter.entity.SeparatedClusterConfig
;
import
top.ninwoo.cloudcenter.register.CloudRegisterCenter
;
import
top.ninwoo.cloudcenter.service.CloudService
;
import
top.ninwoo.common.entity.ClusterConfig
;
import
top.ninwoo.common.entity.ContainerDescription
;
import
top.ninwoo.common.entity.NetworkTopology
;
import
top.ninwoo.common.entity.*
;
import
javax.annotation.Resource
;
import
java.util.*
;
...
...
@@ -24,8 +22,11 @@ public class CloudServiceImpl implements CloudService {
private
static
final
String
DELETE_CLUSTER
=
"/delCluster"
;
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
=
"http://127.0.0.1:23333/getIpListByAppName?clusterId={clusterId}&appName={appName}"
;
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}"
;
@Value
(
"${bs.ipservice.url}"
)
private
String
ipServiceUrl
;
// 全部的逻辑拓扑
// 全部的逻辑拓扑
private
ConcurrentHashMap
<
Long
,
NetworkTopology
>
allLogicalTopo
=
new
ConcurrentHashMap
<>();
...
...
@@ -63,20 +64,21 @@ public class CloudServiceImpl implements CloudService {
return
""
;
}
private
Set
<
String
>
getIpListFromRemoteIpServiceByAppName
(
long
clusterId
,
String
appName
)
{
@Override
public
Set
<
String
>
getIpListFromRemoteIpServiceByAppName
(
long
clusterId
,
String
appName
)
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"appName"
,
appName
);
ResponseEntity
<
Set
>
restEntity
=
restTemplate
.
getForEntity
(
REMOTE_IP_LIST_BY_APPNAME
,
Set
.
class
,
param
);
ResponseEntity
<
Set
>
restEntity
=
restTemplate
.
getForEntity
(
"http://"
+
ipServiceUrl
+
REMOTE_IP_LIST_BY_APPNAME
,
Set
.
class
,
param
);
if
(!
restEntity
.
getStatusCode
().
is2xxSuccessful
())
{
LOG
.
error
(
"远程IP服务无法连接"
);
throw
new
RuntimeException
(
"远程服务无法连接:"
+
REMOTE_IP_LIST_BY_APPNAME
);
throw
new
RuntimeException
(
"远程服务无法连接:"
+
ipServiceUrl
+
REMOTE_IP_LIST_BY_APPNAME
);
}
return
restEntity
.
getBody
();
}
private
ClusterConfig
registerClusterInDataBase
(
ClusterConfig
clusterConfig
)
{
clusterConfig
.
setId
(
11111
);
clusterConfig
.
setId
(
11111
L
);
return
clusterConfig
;
}
...
...
@@ -279,11 +281,19 @@ public class CloudServiceImpl implements CloudService {
public
boolean
deleteClusterFromEdgeNode
(
long
clusterId
)
{
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"clusterId"
,
clusterId
);
if
(!
allClusterConfig
.
containsKey
(
clusterId
))
{
LOG
.
warn
(
"集群{}不存在"
);
return
false
;
}
List
<
SeparatedClusterConfig
>
separatedClusterConfigs
=
allClusterConfig
.
get
(
clusterId
);
separatedClusterConfigs
.
forEach
(
c
->
{
// 调用远程借口删除服务
restTemplate
.
getForEntity
(
"http://"
+
c
.
getEdgeNodeId
()
+
DELETE_CLUSTER
+
"?clusterId="
+
clusterId
,
String
.
class
);
String
res
=
restTemplate
.
getForObject
(
"http://"
+
c
.
getEdgeNodeId
()
+
DELETE_CLUSTER
+
"?clusterId="
+
clusterId
,
String
.
class
);
LOG
.
info
(
"删除集群{}"
,
res
);
});
// 删除对应的逻辑topo
allLogicalTopo
.
remove
(
clusterId
);
return
true
;
}
...
...
@@ -409,4 +419,71 @@ public class CloudServiceImpl implements CloudService {
allLogicalTopo
.
put
(
clusterId
,
networkTopology
);
}
@Override
public
NetworkTopology
getLogicalNetworkByClusterId
(
Long
clusterId
)
{
if
(!
allLogicalTopo
.
containsKey
(
clusterId
))
{
LOG
.
error
(
"无法找到对应的集群topo"
);
return
null
;
}
return
allLogicalTopo
.
get
(
clusterId
);
}
@Override
public
String
enableNetworkMonitor
(
Long
clusterId
,
String
appName
)
{
if
(!
allClusterConfig
.
containsKey
(
clusterId
))
{
LOG
.
warn
(
"正在启用一个不存在集群的网络监控"
);
return
"failed"
;
}
if
(!
allClusterConfig
.
containsKey
(
appName
))
{
LOG
.
warn
(
"正在启用一个不存在的AppName的监控"
);
return
"failed"
;
}
List
<
SeparatedClusterConfig
>
separatedClusterConfigs
=
allClusterConfig
.
get
(
appName
);
// 遍历clusterAppName下发,容器监控模块
separatedClusterConfigs
.
forEach
(
c
->
{
if
(
c
.
getClusterConfig
().
getTopology
().
containsAppName
(
appName
))
{
// 下发启用monitor监控的指令
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"appName"
,
appName
);
ResponseEntity
<
Boolean
>
response
=
restTemplate
.
getForEntity
(
"http://"
+
c
.
getEdgeNodeId
()
+
ENABLE_NETWORK_MONITOR
,
Boolean
.
class
,
param
);
if
(!
response
.
getStatusCode
().
is2xxSuccessful
())
{
LOG
.
warn
(
"集群{}通信失败"
,
c
.
getEdgeNodeId
());
}
if
(!
response
.
getBody
())
{
LOG
.
warn
(
"集群{},appName{}指令下发失败"
,
c
.
getEdgeNodeId
(),
appName
);
}
}
});
return
"success"
;
}
@Override
public
List
<
ContainerMonitorInfo
>
getContainerMonitorInfoByAppName
(
Long
clusterId
,
String
appName
)
{
List
<
ContainerMonitorInfo
>
containerMonitorInfos
=
new
ArrayList
<>();
if
(!
allClusterConfig
.
containsKey
(
clusterId
))
{
return
containerMonitorInfos
;
}
List
<
SeparatedClusterConfig
>
separatedClusterConfigs
=
allClusterConfig
.
get
(
clusterId
);
if
(!
separatedClusterConfigs
.
contains
(
appName
))
{
return
containerMonitorInfos
;
}
separatedClusterConfigs
.
forEach
(
c
->
{
if
(
c
.
getClusterConfig
().
getTopology
().
containsAppName
(
appName
))
{
for
(
ContainerDescription
docker
:
c
.
getClusterConfig
().
getDockers
())
{
ContainerMonitorInfo
monitorInfo
=
new
ContainerMonitorInfo
();
monitorInfo
.
setAppName
(
appName
);
monitorInfo
.
setEdgeNodeId
(
c
.
getEdgeNodeId
());
monitorInfo
.
setClusterId
(
clusterId
);
monitorInfo
.
setContainerId
(
docker
.
getDockerContainer
().
getId
());
containerMonitorInfos
.
add
(
monitorInfo
);
}
}
});
return
containerMonitorInfos
;
}
}
bishe-cloud-center/src/main/resources/application.yml
View file @
63dd43bf
...
...
@@ -2,8 +2,10 @@ server:
port
:
9090
zookeeper
:
url
:
1
27.0.0.1
:2181
url
:
1
92.168.31.154
:2181
bs
:
cloudcenter
:
name
:
my-bs-cloud-center
\ No newline at end of file
name
:
my-bs-cloud-center
ipservice
:
url
:
127.0.0.1:23333
\ No newline at end of file
bishe-cloud-center/src/test/java/top/ninwoo/cloud/CloudServiceImplTest.java
View file @
63dd43bf
package
top.ninwoo.cloud
;
import
com.spotify.docker.client.messages.BlockIoStats
;
import
com.spotify.docker.client.messages.Network
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
...
...
@@ -13,12 +11,8 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.web.client.RestTemplate
;
import
top.ninwoo.cloudcenter.CloudCenterMain
;
import
top.ninwoo.cloudcenter.entity.SeparatedClusterConfig
;
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
top.ninwoo.common.entity.*
;
import
java.util.*
;
...
...
bishe-cloud-ipservice/pom.xml
View file @
63dd43bf
...
...
@@ -19,4 +19,23 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<!--这里写上main方法所在类的路径-->
<configuration>
<mainClass>
top.ninwoo.cloud.ipservice.IpServiceMainApp
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/controller/IpController.java
View file @
63dd43bf
...
...
@@ -32,4 +32,12 @@ public class IpController {
public
String
clearIpByClusterId
(
long
clusterId
)
{
return
ipService
.
clearIpByClusterId
(
clusterId
);
}
@RequestMapping
(
"/deleteIp"
)
public
String
deleteIp
(
long
clusterId
,
String
appName
,
String
containerId
,
String
ip
)
{
ipService
.
deleteIp
(
clusterId
,
appName
,
containerId
,
ip
);
return
"success"
;
}
}
\ No newline at end of file
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/service/IpService.java
View file @
63dd43bf
...
...
@@ -6,6 +6,8 @@ public interface IpService {
String
assignIp
(
long
clusterId
,
String
appName
,
String
containerId
,
String
ipRange
);
void
deleteIp
(
long
clusterId
,
String
appName
,
String
containerId
,
String
ip
);
String
getContainerIp
(
String
containerId
);
Set
<
String
>
getIpListByAppName
(
long
clusterId
,
String
appName
);
...
...
bishe-cloud-ipservice/src/main/java/top/ninwoo/cloud/ipservice/service/impl/IpServiceImpl.java
View file @
63dd43bf
...
...
@@ -59,6 +59,23 @@ public class IpServiceImpl implements IpService {
return
ip
;
}
@Override
public
void
deleteIp
(
long
clusterId
,
String
appName
,
String
containerId
,
String
ip
)
{
// TODO: 这里应该在加入一个还回ip的功能
if
(!
ipMap
.
containsKey
(
containerId
))
{
return
;
}
ipMap
.
remove
(
containerId
);
if
(!
appIp
.
containsKey
(
clusterId
))
{
return
;
}
Map
<
String
,
Set
<
String
>>
clusterAppId
=
appIp
.
get
(
clusterId
);
if
(!
clusterAppId
.
containsKey
(
appName
))
{
return
;
}
clusterAppId
.
get
(
appName
).
remove
(
ip
);
}
/**
* 通过容器id获取ip地址
* @param containerId
...
...
bishe-common-api/pom.xml
View file @
63dd43bf
...
...
@@ -11,6 +11,7 @@
<artifactId>
bishe-common-api
</artifactId>
<packaging>
jar
</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
...
...
bishe-common-api/src/main/java/top/ninwoo/common/entity/ClusterConfig.java
View file @
63dd43bf
...
...
@@ -12,7 +12,7 @@ import java.util.List;
*/
@Data
public
class
ClusterConfig
{
private
l
ong
id
;
private
L
ong
id
;
private
Date
createTime
;
private
String
owner
;
private
List
<
ContainerDescription
>
dockers
;
...
...
bishe-common-api/src/main/java/top/ninwoo/common/entity/ContainerMonitorInfo.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.common.entity
;
import
lombok.Data
;
@Data
public
class
ContainerMonitorInfo
{
private
String
edgeNodeId
;
// 对应cluster的id
private
long
clusterId
;
// 对应的app name
private
String
appName
;
private
String
containerId
;
}
bishe-common-api/src/main/java/top/ninwoo/common/entity/NetworkTopology.java
View file @
63dd43bf
...
...
@@ -13,6 +13,17 @@ public class NetworkTopology {
private
String
[]
appNames
;
private
int
[][]
topology
;
public
boolean
containsAppName
(
String
appName
)
{
if
(
topology
!=
null
)
{
for
(
int
i
=
0
;
i
<
appNames
.
length
;
i
++)
{
if
(
appNames
[
i
].
equals
(
appName
))
{
return
true
;
}
}
}
return
false
;
}
/* public NetworkTopology(long topologyId, String[] appNames) {
this.topologyId = topologyId;
this.appNames = appNames;
...
...
bishe-common-api/src/main/java/top/ninwoo/common/entity/SeparatedClusterConfig.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.common.entity
;
import
lombok.Data
;
@Data
public
class
SeparatedClusterConfig
{
private
ClusterConfig
clusterConfig
;
private
String
edgeNodeId
;
}
bishe-edge-center/pom.xml
View file @
63dd43bf
...
...
@@ -62,8 +62,8 @@
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
bishe-common-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
...
...
@@ -88,4 +88,23 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<!--这里写上main方法所在类的路径-->
<configuration>
<mainClass>
top.ninwoo.edgecenter.EdgeCenterApp
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
View file @
63dd43bf
...
...
@@ -50,6 +50,7 @@ public class IndexController {
* @return
*/
// 这里一次查询需要两秒,需要采用异步进行查询
// TODO: 这里的containerId指的是容器名称
@RequestMapping
(
"/containerMonitor"
)
public
List
<
ContainerInfo
>
getContainerMonitor
(
@RequestParam
(
"clusterId"
)
Long
clusterId
,
@RequestParam
(
"containerId"
)
String
containerId
)
{
// 获取全部的容器id
...
...
@@ -68,6 +69,14 @@ public class IndexController {
return
containerInfos
;
}
@RequestMapping
(
"/getContainerMonitorByContainerId"
)
public
ContainerInfo
getContainerMonitorByContainerId
(
String
containerId
)
{
if
(
containerInfoMap
.
containsKey
(
containerId
))
{
return
containerInfoMap
.
get
(
containerId
);
}
return
null
;
}
@RequestMapping
(
"/enableContainerMonitor"
)
public
boolean
enableNetworkMonitor
(
long
clusterId
,
String
containerName
)
{
// 先获取全部的容器id
...
...
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/IpService.java
View file @
63dd43bf
...
...
@@ -16,5 +16,7 @@ public interface IpService {
// TODO: 这个应该结合数据库,由云端提供服务,暂时提供一个测试版本
String
assignIpString
(
long
clusterId
,
String
appName
,
String
containerId
,
String
networkSegment
);
String
deleteIP
(
long
clusterId
,
String
appName
,
String
containerId
,
String
ip
);
String
getContainerIp
(
String
containerId
);
}
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/ClusterServiceImpl.java
View file @
63dd43bf
...
...
@@ -8,6 +8,7 @@ import top.ninwoo.common.entity.ClusterConfig;
import
top.ninwoo.common.entity.ContainerDescription
;
import
top.ninwoo.common.entity.DockerContainer
;
import
top.ninwoo.edgecenter.service.ClusterService
;
import
top.ninwoo.edgecenter.service.IpService
;
import
top.ninwoo.edgecenter.service.TopologyService
;
import
top.ninwoo.utils.entity.NetworkInfo
;
import
top.ninwoo.utils.entity.OvsBridge
;
...
...
@@ -49,6 +50,9 @@ public class ClusterServiceImpl implements ClusterService {
@Autowired
TopologyService
topologyService
;
@Autowired
IpService
ipService
;
/**
* 定时更新容器列表
*/
...
...
@@ -177,6 +181,10 @@ public class ClusterServiceImpl implements ClusterService {
cids
.
remove
(
cid
);
// step 2 删除ovs上多余的网络
ovsDockerService
.
deleteContainerPorts
(
cid
);
// step 3 删除对应的ip地址
String
ip
=
ipService
.
getContainerIp
(
cid
);
ipService
.
deleteIP
(
clusterId
,
name
,
cid
,
ip
);
}
}
// 把docker容器配置恢复初始状态
...
...
@@ -234,7 +242,12 @@ public class ClusterServiceImpl implements ClusterService {
LOG
.
debug
(
"删除应用["
+
cName
+
"]"
);
// 获取全部的容器id
clustersInfo
.
get
(
clusterId
).
get
(
cName
).
forEach
(
c
->
dockerService
.
deleteDockerById
(
c
));
c
->
{
// 删除对应容器的网络
dockerService
.
deleteDockerById
(
c
);
String
containerIp
=
ipService
.
getContainerIp
(
c
);
ipService
.
deleteIP
(
clusterId
,
cName
,
c
,
containerIp
);
});
}
);
clustersInfo
.
remove
(
clusterId
);
...
...
@@ -252,8 +265,11 @@ public class ClusterServiceImpl implements ClusterService {
return
;
}
clustersInfo
.
get
(
clusterId
).
get
(
containerName
).
forEach
(
c
->
dockerService
.
deleteDockerById
(
c
)
);
c
->
{
dockerService
.
deleteDockerById
(
c
);
String
containerIp
=
ipService
.
getContainerIp
(
c
);
ipService
.
deleteIP
(
clusterId
,
containerName
,
c
,
containerIp
);
});
clustersInfo
.
get
(
clusterId
).
remove
(
containerName
);
}
...
...
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/IpServiceImpl.java
View file @
63dd43bf
...
...
@@ -26,6 +26,7 @@ public class IpServiceImpl implements IpService {
// clusterId, String appName, String cid, String ipRange
private
static
final
String
ASSIGN_IP
=
"/assignIp?clusterId={clusterId}&appName={appName}&cid={cid}&ipRange={ipRange}"
;
private
static
final
String
GET_IP_BY_CONTAINERID
=
"/getIpByContainerId?cid="
;
private
static
final
String
DELETE_IP
=
"/deleteIp?clusterId={clusterId}&appName={appName}&containerId={containerId}&ip={ip}"
;
@Value
(
"${bs.ipservice.ip}"
)
private
String
ipServiceHost
;
...
...
@@ -53,6 +54,15 @@ public class IpServiceImpl implements IpService {
return
forEntity
.
getBody
();
}
@Override
public
String
deleteIP
(
long
clusterId
,
String
appName
,
String
containerId
,
String
ip
)
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"clusterId"
,
clusterId
);
param
.
put
(
"appName"
,
appName
);
param
.
put
(
"containerId"
,
containerId
);
param
.
put
(
"ip"
,
ip
);
return
restTemplate
.
getForObject
(
"http://"
+
ipServiceHost
+
DELETE_IP
,
String
.
class
,
param
);
}
@Override
public
String
getContainerIp
(
String
containerId
)
{
// 更换为远程接口
...
...
bishe-edge-center/src/main/resources/application.yaml
View file @
63dd43bf
...
...
@@ -21,7 +21,6 @@ bs:
name
:
random
ip-prefix
:
192
ipservice
:
ip
:
1
27.0.0.1
:23333
ip
:
1
92.168.31.154
:23333
zookeeper
:
url
:
127.0.0.1:2181
url
:
192.168.31.154:2181
\ No newline at end of file
bishe-test/pom.xml
0 → 100644
View file @
63dd43bf
<?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-test
</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>
</project>
\ No newline at end of file
bishe-test/src/main/java/top/ninwoo/test/BisheTestMain.java
0 → 100644
View file @
63dd43bf
package
top.ninwoo.test
;
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
);
}
}
bishe-test/src/main/resources/application.properties
0 → 100644
View file @
63dd43bf
bishe.app.app-name
=
joliu
bishe.app.cloud-url
=
192.168.31.154:9090
\ No newline at end of file
bishe-test/src/test/java/top/ninwoo/BisheTests.java
0 → 100644
View file @
63dd43bf
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.common.entity.*
;
import
top.ninwoo.test.BisheTestMain
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
BisheTestMain
.
class
)
public
class
BisheTests
{
@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
(
"127.0.0.1:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
2
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"Run"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
ContainerDescription
containerDescription1
=
new
ContainerDescription
();
containerDescription1
.
setMode
(
"normal"
);
containerDescription1
.
setReplicas
(
3
);
DockerContainer
container1
=
new
DockerContainer
();
container1
.
setName
(
"APP"
);
container1
.
setCommand
(
"sh"
);
container1
.
setImage
(
"joliu/networktest"
);
containerDescription1
.
setDockerContainer
(
container1
);
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
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
@Test
public
void
removeClusterFromEdgeNodeTest
()
{
clusterService
.
removeClusterFromEdgeNode
(
11111L
);
}
@Test
public
void
getLogicalNetworkTopologyTest
()
{
NetworkTopology
logicalNetworkTopology
=
networkService
.
getLogicalNetworkTopology
(
11111L
);
System
.
out
.
println
(
logicalNetworkTopology
);
}
@Test
public
void
getIpListByAppNameTest
()
{
List
<
String
>
ipList
=
networkService
.
getIpListByAppName
(
11111L
,
"Run"
);
System
.
out
.
println
(
ipList
);
}
}
bishe-utils/pom.xml
View file @
63dd43bf
...
...
@@ -11,6 +11,8 @@
<artifactId>
bishe-utils
</artifactId>
<packaging>
jar
</packaging>
<properties>
<jersey.version>
2.27
</jersey.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
...
...
pom.xml
View file @
63dd43bf
...
...
@@ -14,6 +14,8 @@
<module>
bishe-cloud-center
</module>
<module>
bishe-common-api
</module>
<module>
bishe-cloud-ipservice
</module>
<module>
bishe-client-starter
</module>
<module>
bishe-test
</module>
</modules>
...
...
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