Commit 16b2a979 authored by joliu's avatar joliu

Merge branch 'feature-cnf' into 'master'

Feature cnf

See merge request xidiancos/cnf!7
parents b1cf359b 3c8e74e7
......@@ -18,3 +18,9 @@
* 王一鸣
* 刘建瓯
* 张夏童
## 更新说明
1. 使用域名替换配置中的IP,防止多人多次修改配置类并进行提交,避免合并分支时出现冲突的问题。
如果有需要在自己的电脑上进行部署,需要通过修改本机host的方式来修改对应节点的IP。
2. 测试代码
\ No newline at end of file
# 范例项目说明
## 注意
这是一个范例项目,请勿在此项目中添加新的业务代码
## 平台应用创建流程
1. 当需要创建一个平台应用时,需要在apps目录中创建对应的module,以便进行应用的管理。
2. 新建module中必须包含以下依赖:
```xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-client-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
```
其中的`spring-boot-starter-web`可以变更为`spring-boot-starter`,具体根据是否有web应用需求而定。
3. 新建module必须包含以下plugin,以防止打Jar包时出现找不到主类的问题:
```xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
4. 应用中必须有主类,主类应该符合SpringBoot项目的主类编写方式。
## 警告
* 所有的应用禁止引用除starter之外的平台Jar包,包括:
* cnf-cloud-center
* cnf-edge-center
* cnf-test
* cnf-cloud-ipservice
* 其他基础工具包
<?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>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cnf-app-demo</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-client-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package top.ninwoo.cnf.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoMain {
public static void main(String[] args) {
SpringApplication.run(DemoMain.class, args);
}
}
......@@ -3,59 +3,38 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bishe-case-dis</artifactId>
<artifactId>cnf-case-dis</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>
<artifactId>cnf-client-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>top.ninwoo.BisheTestMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
......
<?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>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cnf-weixingsim</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-client-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package top.ninwoo.weixingsim;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WxMain {
public static void main(String[] args) {
SpringApplication.run(WxMain.class, args);
}
}
......@@ -9,7 +9,7 @@ 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.client.BisheTestMain;
import top.ninwoo.weixingsim.WxMain;
import top.ninwoo.weixingsim.entity.SimData;
import top.ninwoo.weixingsim.entity.WeiXingData;
import top.ninwoo.weixingsim.service.impl.ToponetImpl;
......@@ -21,8 +21,8 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BisheTestMain.class)
public class BisheTests {
@SpringBootTest(classes = WxMain.class)
public class WxTests {
@Autowired
private ClusterService clusterService;
......
package top.ninwoo.utils;
/**
* @Author joliu
* @Description
* @Date Create in 下午10:50 2019/10/27
*/
public class EntityTests {
}
package top.ninwoo.utils;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig;
import top.ninwoo.utils.service.IptablesService;
/**
* @Author joliu
* @Description
* @Date Create in 下午3:15 2019/10/30
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class)
public class IptablesServiceTests {
@Autowired
IptablesService iptablesService;
}
package top.ninwoo.utils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import top.ninwoo.utils.config.DockerConfig;
public class SpringMain {
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(DockerConfig.class);
}
}
package top.ninwoo.utils;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig;
import top.ninwoo.utils.util.DockerUtils;
/**
* @Author joliu
* @Description 这个测试迁移到集群服务中
* @Date Create in 下午4:06 2019/10/30
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class)
public class TcUtilsTests {
@Autowired
DockerUtils dockerUtils;
@Before
public void init() {
// 创建两个容器
// 创建一个ovs网桥
}
}
<?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-weixingsim</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -3,13 +3,14 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>bishe-client-starter</artifactId>
<artifactId>cnf-client-starter</artifactId>
<properties>
<dubbo.version>2.7.4.1</dubbo.version>
</properties>
......@@ -17,31 +18,26 @@
<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>
<artifactId>cnf-common-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.0.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
......
......@@ -3,13 +3,14 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bishe-cloud-center</artifactId>
<artifactId>cnf-cloud-center</artifactId>
<packaging>jar</packaging>
<description>用作集群工的汇总</description>
......@@ -17,7 +18,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
......@@ -30,38 +30,64 @@
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>
<!-- 封装了一些高级特性,如:Cache事件监听、选举、分布式锁、分布式Barrier -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.12.0</version>
</dependency>
<!--日志模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>bishe-utils</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>cnf-utils</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>bishe-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>cnf-common-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<!--自动生成文档-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package top.ninwoo.cloudcenter.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("top.ninwoo.cloudcenter.controller"))
.paths(PathSelectors.any())
.build().apiInfo(new ApiInfoBuilder().title("CNF云平台Swagger文档")
.description("由Swagger自动生成,仅限测试环境使用")
.version("1.0")
.contact(new Contact("joliu", "opengn.org", "ljo0412@live.com"))
.license("The Apache License")
.licenseUrl("http://git.opensource5g.org/xidiancos/cnf/-/blob/master/LICENSE")
.build());
}
}
package top.ninwoo.cloudcenter.controller;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import top.ninwoo.cloudcenter.service.CloudService;
import top.ninwoo.common.entity.NetworkTopology;
......@@ -9,19 +10,24 @@ import javax.annotation.Resource;
import java.util.List;
@RestController
@Api(tags = "容器集群管理相关接口")
@RequestMapping("/cluster")
public class ClusterController {
@Resource
CloudService cloudService;
@RequestMapping(value = "/sendClusterConfigToEdgeNode", method = RequestMethod.POST)
@ApiOperation("下发集群配置")
@ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", dataType = "List" ,required = true)
@PostMapping(value = "/sendClusterConfigToEdgeNode")
public List<SeparatedClusterConfig> sendClusterConfigToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
// return cloudService.sendClusterConfigToEdgeNode(clusterConfigs);
return cloudService.sendClusterConfigToEdgeNodeByThreads(clusterConfigs);
}
@RequestMapping(value = "/removeClusterFromEdgeNode")
@ApiOperation("删除集群")
@ApiImplicitParam(name = "clusterId", value = "容器集群ID", defaultValue = "11111", required = true)
@GetMapping(value = "/removeClusterFromEdgeNode")
public String removeClusterFromEdgeNode(Long clusterId) {
boolean res = cloudService.deleteClusterFromEdgeNode(clusterId);
if(res) {
......@@ -30,22 +36,29 @@ public class ClusterController {
return "fail";
}
@RequestMapping(value = "/getEdgeNodeIds")
@ApiOperation("获取边缘节点")
@GetMapping(value = "/getEdgeNodeIds")
public List<String> getEdgeNodeIds() {
return cloudService.getEdgeNodeIds();
}
@RequestMapping(value = "/adjustCluster", method = RequestMethod.POST)
@ApiOperation("调整容器集群")
@ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", required = true)
@PostMapping(value = "/adjustCluster")
public Boolean adjustClusterToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
return cloudService.adjustCluster(clusterConfigs);
}
@RequestMapping(value = "/sendLogicTopo", method = RequestMethod.POST)
@ApiOperation("下发容器逻辑拓扑")
@ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", required = true)
@PostMapping(value = "/sendLogicTopo")
public Boolean sendLogicTopoToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
return cloudService.sendLogicTopo(clusterConfigs);
}
@RequestMapping(value = "/adjustLogicTopo", method = RequestMethod.POST)
@ApiOperation("调整容器逻辑拓扑")
@ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", required = true)
@PostMapping(value = "/adjustLogicTopo")
public Boolean adjustLogicTopoToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
return cloudService.adjustLogicTopo(clusterConfigs);
}
......
......@@ -2,10 +2,10 @@ server:
port: 9091
zookeeper:
url: 192.168.31.156:2181
url: zk.cnf.org:2181
bs:
cloudcenter:
name: my-bs-cloud-center
ipservice:
url: 192.168.31.156:23333
\ No newline at end of file
url: ipservice.cnf.org:23333
\ No newline at end of file
......@@ -3,19 +3,18 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bishe-cloud-ipservice</artifactId>
<artifactId>cnf-cloud-ipservice</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
</dependencies>
......@@ -24,10 +23,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--这里写上main方法所在类的路径-->
<configuration>
<mainClass>top.ninwoo.cloud.ipservice.IpServiceMainApp</mainClass>
</configuration>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
......
......@@ -3,13 +3,13 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bishe-common-api</artifactId>
<artifactId>cnf-common-api</artifactId>
<packaging>jar</packaging>
<dependencies>
......@@ -17,8 +17,11 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package top.ninwoo.common.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SeparatedClusterConfig {
@ApiModelProperty
private ClusterConfig clusterConfig;
@ApiModelProperty
private String edgeNodeId;
}
# 边缘承载节点
该Module为
\ No newline at end of file
......@@ -3,19 +3,18 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bishe-edge-center</artifactId>
<artifactId>cnf-edge-center</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
......@@ -26,75 +25,62 @@
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.9</version>
</dependency>
<!--日志模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>bishe-utils</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>cnf-utils</artifactId>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>bishe-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>cnf-common-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<!-- 对zookeeper的底层api的一些封装 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>
<!-- 封装了一些高级特性,如:Cache事件监听、选举、分布式锁、分布式Barrier -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
</dependencies>
......@@ -104,10 +90,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--这里写上main方法所在类的路径-->
<configuration>
<mainClass>top.ninwoo.edgecenter.EdgeCenterApp</mainClass>
</configuration>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
......
......@@ -90,11 +90,16 @@ public class ClusterServiceCheck {
log.info("创建自检容器集群【Test1_0,Test1_1,Test2】");
try {
clusterService.initContainers(clusterConfig);
topologyService.createTopo(clusterConfig.getId(), clusterConfig.getTopology());
} catch (Exception e) {
log.error("容器启动失败");
throw new RuntimeException("容器启动失败");
}
try {
topologyService.createTopo(clusterConfig.getId(), clusterConfig.getTopology());
} catch (Exception e) {
log.error("容器网络初始化失败", e);
throw new RuntimeException("容器网络初始化失败");
}
if(!clusterService.getClusterIds().contains(CLUSTERID)) {
log.error("集群创建失败%", CLUSTERID);
}
......
package top.ninwoo.edgecenter.config;
import javafx.scene.control.cell.TextFieldListCell;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
......@@ -14,11 +13,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.WebApplicationContextUtils;
import top.ninwoo.edgecenter.check.ClusterServiceCheck;
import top.ninwoo.edgecenter.register.EdgeNodeRegister;
import javax.annotation.Resource;
@Slf4j
@Configuration
public class ZookeeperConfiguration implements ApplicationContextAware {
......
......@@ -6,7 +6,7 @@ spring:
username: root
password: Vudo3423ljo
influx:
url: http://127.0.0.1:8086
url: http://influxdb.cnf.org:8086
user: admin
password: admin
mybatis:
......@@ -17,7 +17,7 @@ debug: false
#边缘节点的端口
server:
port: 8081
port: 18088
bs:
cloudcenter:
......@@ -26,9 +26,12 @@ bs:
name: random
ip-prefix: 192.168.31
ipservice:
ip: 192.168.31.238:23333
ip: ipservice.cnf.org:23333
sdn-controller:
host: 127.0.0.1
host: sdn.cnf.org
port: 6653
zookeeper:
url: 192.168.31.238:2181
url: zk.cnf.org:2181
cnf:
passwd: Vudo3423
......@@ -3,50 +3,49 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bishe-test</artifactId>
<artifactId>cnf-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>
<artifactId>cnf-client-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>bishe-weixingsim</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
......
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.entity.ContainerMonitor;
import top.ninwoo.bishe.starter.service.ClusterService;
import top.ninwoo.bishe.starter.service.NetworkService;
import top.ninwoo.common.entity.*;
import top.ninwoo.client.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("192.168.190.135:8081");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
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);
}
@Test
public void enableNetworkMonitorTest() throws InterruptedException {
String res = networkService.enableNetworkMonitor(11111L, "Run");
System.out.println(res);
}
@Test
public void cancelNetworkMonitorTest() {
String run = networkService.cancelNetworkMonitor(11111L, "Run");
System.out.println(run);
}
@Test
public void getNetworkMonitorTest() throws InterruptedException {
List<ContainerMonitor> run = networkService.getContainerMonitors(11111L, "Run");
int i = 0;
while(i < 10) {
run.forEach(c -> {
System.out.println(c.getContainerInfo());
});
Thread.sleep(500);
i++;
}
}
//改变集群拓扑配置
private boolean adjustCluster(List<SeparatedClusterConfig> configs) {
boolean b = clusterService.adjustClusterToEdgeNode(configs);
return b;
}
//测试逻辑网路
@Test
public void test1() {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
//需修改为下发的IP地址
separatedClusterConfig.setEdgeNodeId("192.168.190.135:8081");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
clusterConfig.setOwner("joliu");
ContainerDescription containerDescription = new ContainerDescription();
containerDescription.setMode("normal");
containerDescription.setReplicas(1);
DockerContainer container = new DockerContainer();
container.setName("D1");
container.setCommand("sh");
container.setImage("test2");
containerDescription.setDockerContainer(container);
List<ContainerDescription> cds = new ArrayList<>();
cds.add(containerDescription);
ContainerDescription dis = new ContainerDescription();
dis.setMode("normal");
dis.setReplicas(1);
DockerContainer disContainer = new DockerContainer();
disContainer.setName("D2");
disContainer.setCommand("sh");
disContainer.setImage("test2");
dis.setDockerContainer(disContainer);
cds.add(dis);
ContainerDescription dis2 = new ContainerDescription();
dis2.setMode("normal");
dis2.setReplicas(1);
DockerContainer disContainer2 = new DockerContainer();
disContainer2.setName("D3");
disContainer2.setCommand("sh");
disContainer2.setImage("test2");
dis2.setDockerContainer(disContainer2);
cds.add(dis2);
String[] appnames = new String[]{"D1", "D2", "D3", "br:ovs"};
int[][] topology = new int[][]{
{0, 0, 0 ,0},
{1, 0, 0 ,0},
{0, 1, 0 ,0},
{1, 1, 1 ,0}};
clusterConfig.setDockers(cds);
NetworkTopology topo = new NetworkTopology();
topo.setAppNames(appnames);
// 这个参数好像没啥用
topo.setTopologyId(11);
topo.setTopology(topology);
clusterConfig.setTopology(topo);
separatedClusterConfig.setClusterConfig(clusterConfig);
clusterConfigs.add(separatedClusterConfig);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
//下发逻辑拓扑
clusterService.sendLogicTopoToEdgeNode(clusterConfigs);
/*
//改变逻辑拓扑
int[][] newtopology = new int[][]{
{0, 0, 0, 0 },
{1, 0, 0, 0 },
{1, 1, 0, 0 },
{1, 1, 1, 0 }};
topo.setTopology(newtopology);
//下发修改后的逻辑拓扑
clusterService.adjustLogicTopoToEdgeNode(clusterConfigs);
*/
}
//测试容器运行程序
@Test
public void test5() {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
//需修改为下发的IP地址
separatedClusterConfig.setEdgeNodeId("192.168.190.135:8081");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
clusterConfig.setOwner("joliu");
ContainerDescription containerDescription = new ContainerDescription();
containerDescription.setMode("normal");
containerDescription.setReplicas(1);
DockerContainer container = new DockerContainer();
container.setName("D1");
container.setCommand("-e PARAMS=\"--name=" +container.getName()+"\"");
container.setImage("joliu/networktest");
containerDescription.setDockerContainer(container);
List<ContainerDescription> cds = new ArrayList<>();
cds.add(containerDescription);
ContainerDescription dis = new ContainerDescription();
dis.setMode("normal");
dis.setReplicas(1);
DockerContainer disContainer = new DockerContainer();
disContainer.setName("D2");
disContainer.setCommand("-e PARAMS=\"--name=" +disContainer.getName()+"\"");
disContainer.setImage("joliu/networktest");
dis.setDockerContainer(disContainer);
cds.add(dis);
ContainerDescription dis2 = new ContainerDescription();
dis2.setMode("normal");
dis2.setReplicas(1);
DockerContainer disContainer2 = new DockerContainer();
disContainer2.setName("D3");
disContainer2.setCommand("-e PARAMS=\"--name=" +disContainer2.getName()+"\"");
disContainer2.setImage("joliu/networktest");
dis2.setDockerContainer(disContainer2);
cds.add(dis2);
String[] appnames = new String[]{"D1", "D2", "D3", "br:ovs"};
int[][] topology = new int[][]{
{0, 0, 0 ,0},
{1, 0, 0 ,0},
{0, 1, 0 ,0},
{1, 1, 1 ,0}};
clusterConfig.setDockers(cds);
NetworkTopology topo = new NetworkTopology();
topo.setAppNames(appnames);
// 这个参数好像没啥用
topo.setTopologyId(11);
topo.setTopology(topology);
clusterConfig.setTopology(topo);
separatedClusterConfig.setClusterConfig(clusterConfig);
clusterConfigs.add(separatedClusterConfig);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
//下发逻辑拓扑
clusterService.sendLogicTopoToEdgeNode(clusterConfigs);
/*
//改变逻辑拓扑
int[][] newtopology = new int[][]{
{0, 0, 0, 0 },
{1, 0, 0, 0 },
{1, 1, 0, 0 },
{1, 1, 1, 0 }};
topo.setTopology(newtopology);
//下发修改后的逻辑拓扑
clusterService.adjustLogicTopoToEdgeNode(clusterConfigs);
*/
}
}
......@@ -3,13 +3,13 @@
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>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bishe-utils</artifactId>
<artifactId>cnf-utils</artifactId>
<packaging>jar</packaging>
......@@ -20,36 +20,42 @@
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.3.RELEASE</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>docker-client</artifactId>
<version>8.16.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>bishe-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>cnf-common-api</artifactId>
</dependency>
</dependencies>
......
......@@ -2,6 +2,7 @@ package top.ninwoo.utils.config;
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerClient;
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;
......@@ -10,7 +11,8 @@ import java.net.URI;
@Configuration
@ComponentScan("top.ninwoo.utils")
public class DockerConfig {
@EnableConfigurationProperties(UtilsProperties.class)
public class CNFUtilsAutoConfiguration {
@Bean(destroyMethod = "close")
public DockerClient dockerClient() {
return DefaultDockerClient.builder()
......
package top.ninwoo.utils.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "cnf.utils")
public class UtilsProperties {
private String passwd = "Vudo3423";
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
}
package top.ninwoo.utils.util.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import top.ninwoo.utils.util.LinuxCtlUtils;
import top.ninwoo.utils.util.OvsDockerUtils;
import top.ninwoo.utils.util.Utils;
......@@ -12,17 +15,23 @@ import top.ninwoo.utils.util.Utils;
*/
@Utils
public class OvsDockerUtilsImpl implements OvsDockerUtils {
private static Logger LOG = LoggerFactory.getLogger(OvsDockerUtilsImpl.class);
@Value("${cnf.passwd}")
private String passwd;
@Autowired
LinuxCtlUtils linuxCtlUtils;
@Override
public String addPort(String bridgeName, String devName,
String containerId, String ip) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-docker add-port " + bridgeName
String cmd = "echo '" + passwd + "' | sudo -S ovs-docker add-port " + bridgeName
+ " " + devName + " " + containerId + " --ipaddress=" + ip;
String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) {
throw new RuntimeException(res);
LOG.error("创建网络失败", cmd, res);
throw new RuntimeException(cmd + ":" + res);
}
// 这里需要给容器设置mtu
String mtuCmd = "docker exec " + containerId + " ifconfig eth1 mtu 1450";
......@@ -33,7 +42,7 @@ public class OvsDockerUtilsImpl implements OvsDockerUtils {
@Override
public String delPort(String bridgeName, String devName, String containerId) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-docker del-port " + bridgeName + " "
String cmd = "echo '" + passwd + "' | sudo -S ovs-docker del-port " + bridgeName + " "
+ devName + " " + containerId;
return linuxCtlUtils.runCmd(cmd);
......
......@@ -3,6 +3,7 @@ package top.ninwoo.utils.util.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import top.ninwoo.utils.entity.BridgePort;
import top.ninwoo.utils.entity.Ovs;
import top.ninwoo.utils.entity.OvsBridge;
......@@ -26,11 +27,13 @@ public class OvsUtilsImpl implements OvsUtils {
private final AtomicInteger atomicInteger = new AtomicInteger(0);
@Autowired
LinuxCtlUtils linuxCtlUtils;
@Value("${cnf.passwd}")
private String passwd;
@Override
public boolean isInstall() {
// 可能会遇到权限问题
String s = linuxCtlUtils.runCmd("ovs-vsctl --version");
String s = linuxCtlUtils.runCmd("echo '" + passwd + "' | sudo -S ovs-vsctl --version");
if(s.contains("Error")) {
return false;
} else {
......@@ -40,7 +43,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override
public Ovs showDetails() {
String res = linuxCtlUtils.runCmd("echo 'Vudo3423' | sudo -S ovs-vsctl show");
String res = linuxCtlUtils.runCmd("echo '" + passwd + "' | sudo -S ovs-vsctl show");
Ovs ovs = parseOvsString(res);
return ovs;
......@@ -128,7 +131,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override
public void addBridge(String name) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl add-br " + name;
String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl add-br " + name;
String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) {
throw new RuntimeException("linux bridge has existed!");
......@@ -137,7 +140,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override
public void setBridgeProtocol(String bridgeName, String protocol) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl set bridge " + bridgeName + " protocols=" + protocol;
String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl set bridge " + bridgeName + " protocols=" + protocol;
String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) {
throw new RuntimeException(res);
......@@ -146,7 +149,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override
public void setController(String bridgeName, String host, int port) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl set-controller " + bridgeName + " tcp:" + host + ":" + port;
String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl set-controller " + bridgeName + " tcp:" + host + ":" + port;
String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) {
throw new RuntimeException(res);
......@@ -155,7 +158,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override
public void delBridge(String name) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl del-br " + name;
String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl del-br " + name;
LOG.info("删除网桥[{}]", name);
String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) {
......@@ -171,7 +174,7 @@ public class OvsUtilsImpl implements OvsUtils {
*/
@Override
public boolean addBridgePort(String bridgeName, String port) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl add-port " + bridgeName + " " + port;
String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl add-port " + bridgeName + " " + port;
String res = linuxCtlUtils.runCmd(cmd);
LOG.info("为Bridge:{} 添加Port:{}", bridgeName, port);
if(!"".equals(res)) {
......@@ -183,7 +186,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override
public boolean delBridgePort(String bridgeName, String port) {
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl del-port " + bridgeName + " " + port;
String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl del-port " + bridgeName + " " + port;
LOG.info("删除Bridge:{} Port:{}", bridgeName, port);
String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) {
......@@ -203,7 +206,7 @@ public class OvsUtilsImpl implements OvsUtils {
public String[] createVethPair(String br1, String br2) {
String veth1 = br1 + "_" + br2;
String veth2 = br2 + "_" + br1;
String cmd = "echo 'Vudo3423' | sudo -S ip link add " + veth1 + " type veth peer name " + veth2;
String cmd = "echo '" + passwd + "' | sudo -S ip link add " + veth1 + " type veth peer name " + veth2;
LOG.info("创建虚拟网卡对[{},{}]", veth1, veth2);
String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) {
......@@ -221,7 +224,7 @@ public class OvsUtilsImpl implements OvsUtils {
public boolean delVethPort(String[] veths) {
String veth1 = veths[0];
String veth2 = veths[1];
String cmd = "echo 'Vudo3423' | sudo -S ip link del " + veth1 + " type veth peer name " + veth2;
String cmd = "echo '" + passwd + "' | sudo -S ip link del " + veth1 + " type veth peer name " + veth2;
LOG.info("删除虚拟网卡对[{},{}]", veth1, veth2);
String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) {
......@@ -239,7 +242,7 @@ public class OvsUtilsImpl implements OvsUtils {
*/
@Override
public boolean enableLinuxPort(String port) {
String cmd = "echo 'Vudo3423' | sudo -S ifconfig " + port + " up";
String cmd = "echo '" + passwd + "' | sudo -S ifconfig " + port + " up";
LOG.info("启动Linux端口:{}",port);
String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) {
......@@ -275,7 +278,7 @@ public class OvsUtilsImpl implements OvsUtils {
public boolean setVxlan(String bridgeName, String remoteIp) {
// TODO: bug
int id = atomicInteger.getAndIncrement();
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl add-port " + bridgeName
String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl add-port " + bridgeName
+ " vxlan" + id + " -- set interface vxlan" + id + " type=vxlan options:remote_ip=" + remoteIp;
System.out.println(cmd);
LOG.info("设置VXLAN[bridgeName:{},remoteIP:{},{}]", bridgeName, remoteIp,cmd);
......
......@@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.common.entity.DockerContainer;
import top.ninwoo.utils.config.DockerConfig;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.service.DockerService;
import top.ninwoo.utils.util.LinuxCtlUtils;
......@@ -15,7 +15,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class DockerServiceTests {
@Autowired
private LinuxCtlUtils linuxCtlService;
......@@ -37,7 +37,7 @@ public class DockerServiceTests {
@Test
public void testSudo() {
String result = linuxCtlService.runCmd("echo Vudo3423 | sudo -S ovs-vsctl show");
String result = linuxCtlService.runCmd("ovs-vsctl show");
System.out.println(result);
}
......
package top.ninwoo.utils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -7,24 +9,37 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;
import top.ninwoo.common.entity.DockerContainer;
import top.ninwoo.utils.config.DockerConfig;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.util.DockerUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @Author joliu
* @Description
* @Date Create in 下午5:54 2019/10/25
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class DockerUtilsTest {
private static String cid = null;
@Autowired
DockerUtils dockerUtils;
@Before
public void prepare() {
DockerContainer container = new DockerContainer();
container.setName("Router_4");
container.setImage("joliu/networktest");
container.setCommand("sh");
cid = dockerUtils.runDocker(container).getId();
}
@Test
public void testGetDockerById() {
DockerContainer dockerById = dockerUtils.getDockerById("123123");
Assert.isNull(dockerById);
DockerContainer dockerById = dockerUtils.getDockerById(cid);
Assert.isTrue(dockerById != null);
}
......@@ -32,6 +47,12 @@ public class DockerUtilsTest {
public void testExecInDocker() {
final String s =
dockerUtils.execInDocker("Router_4", new String[]{"ifconfig"});
System.out.println(s);
Assert.isTrue(!("".equals(s)));
}
@After
public void close() {
boolean result = dockerUtils.deleteDockerById(cid);
Assert.isTrue(result);
}
}
......@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.common.entity.DockerContainer;
import top.ninwoo.utils.config.DockerConfig;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.entity.ChainEntity;
import top.ninwoo.utils.entity.ChainType;
import top.ninwoo.utils.entity.TableType;
......@@ -26,7 +26,7 @@ import java.util.Map;
* @Date Create in 上午11:54 2019/10/29
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class IptablesUtilsTests {
private static final Logger LOG = LoggerFactory.getLogger(IptablesUtilsTests.class);
......
......@@ -6,11 +6,10 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.entity.BridgePort;
import top.ninwoo.utils.entity.Ovs;
import top.ninwoo.utils.entity.OvsBridge;
import top.ninwoo.utils.service.OVSService;
import top.ninwoo.utils.util.OvsUtils;
......@@ -18,7 +17,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class OVSServiceTests {
@Autowired
private OvsUtils ovsService;
......
......@@ -5,7 +5,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.util.OSUtils;
/**
......@@ -14,7 +14,7 @@ import top.ninwoo.utils.util.OSUtils;
* @Date Create in 上午10:45 2019/11/4
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class OsUtilsTests {
@Autowired
......@@ -26,7 +26,7 @@ public class OsUtilsTests {
System.out.println("CPU:" + osUtils.cpuUsage() + "%");
System.out.println("MEM:" + osUtils.memoryUsage() + "%");
int i = 0;
while(i < 10) {
while(i++ < 10) {
System.out.println("NET:" + osUtils.networkUsage() + "%");
}
}
......
......@@ -5,29 +5,161 @@
<modelVersion>4.0.0</modelVersion>
<groupId>top.ninwoo</groupId>
<artifactId>bishe</artifactId>
<artifactId>cnf</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>bishe-edge-center</module>
<module>bishe-utils</module>
<module>bishe-cloud-center</module>
<module>bishe-common-api</module>
<module>bishe-cloud-ipservice</module>
<module>bishe-client-starter</module>
<module>bishe-test</module>
<module>bishe-case-dis</module>
<module>bishe-weixingsim</module>
<module>cnf-utils</module>
<module>cnf-common-api</module>
<module>cnf-cloud-ipservice</module>
<module>cnf-cloud-center</module>
<module>cnf-test</module>
<module>cnf-edge-center</module>
<module>cnf-client-starter</module>
<module>apps/cnf-weixingsim</module>
<module>apps/cnf-case-dis</module>
<module>apps/cnf-app-demo</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springboot.version>2.1.2.RELEASE</springboot.version>
<spring.version>5.1.4.RELEASE</spring.version>
<docker.version>8.16.0</docker.version>
<curator.version>2.12.0</curator.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-client-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>docker-client</artifactId>
<version>${docker.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.1.RELEASE</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
......@@ -40,7 +172,5 @@
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
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