REM:
1. 增加迪普防护对象模板配置文件
2. 增加迪普防护模板配置
3. 增加迪普防护模板映射服务
4. 修改业务类型为字符串
5. 更新单测框架,自动加载防护对象模板配置文件
6. 增加迪普防护模板测试用例
This commit is contained in:
HuangXin 2021-01-13 18:25:25 +08:00
parent 346c604165
commit 6a173c0504
14 changed files with 223 additions and 76 deletions

View File

@ -0,0 +1,51 @@
template.testValue=12345
template.templateInfo.name=Game_Server_10G
template.templateInfo.bandMin=1500
template.templateInfo.bandMax=-1
template.templateInfo.type=GAME
#模板配置
template.umcTemplate[0].name=Game_Server_10G
template.umcTemplate[0].bandMin=1500
template.umcTemplate[0].bandMax=-1
template.umcTemplate[0].type=GAME
template.umcTemplate[1].name=Game_Server_1G
template.umcTemplate[1].bandMin=0
template.umcTemplate[1].bandMax=1500
template.umcTemplate[1].type=GAME
template.umcTemplate[2].name=DNS_Server_10G
template.umcTemplate[2].bandMin=1500
template.umcTemplate[2].bandMax=-1
template.umcTemplate[2].type=DNS
template.umcTemplate[3].name=DNS_Server_1G
template.umcTemplate[3].bandMin=0
template.umcTemplate[3].bandMax=1500
template.umcTemplate[3].type=DNS
template.umcTemplate[4].name=WEB_Server_10G
template.umcTemplate[4].bandMin=1500
template.umcTemplate[4].bandMax=-1
template.umcTemplate[4].type=WEB
template.umcTemplate[5].name=WEB_Server_1G
template.umcTemplate[5].bandMin=0
template.umcTemplate[5].bandMax=1500
template.umcTemplate[5].type=WEB
template.umcTemplate[6].name=General_Server_10G
template.umcTemplate[6].bandMin=1500
template.umcTemplate[6].bandMax=-1
template.umcTemplate[6].type=SERVER
template.umcTemplate[7].name=General_Server_1G
template.umcTemplate[7].bandMin=500
template.umcTemplate[7].bandMax=1500
template.umcTemplate[7].type=SERVER
template.umcTemplate[8].name=General_Server_100M
template.umcTemplate[8].bandMin=0
template.umcTemplate[8].bandMax=500
template.umcTemplate[8].type=SERVER

View File

@ -1 +1 @@
spring.profiles.active=local,dispose
spring.profiles.active=local,dispose,template

View File

@ -1,68 +0,0 @@
package com.dispose.common;
/**
* The enum Service type.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public enum ServiceType implements BaseEnum {
/**
* The Service and others.
*/
SERVICE_AND_OTHERS(0, "服务器以及其它类型"),
/**
* Web site service type.
*/
WEB_SITE(1, "网站"),
/**
* Dns service service type.
*/
DNS_SERVICE(2, "DNS 服务"),
/**
* Game service service type.
*/
GAME_SERVICE(3, "游戏 服务"),
;
/**
* The Code.
*/
private final Integer code;
/**
* The Readme.
*/
private final String readme;
/**
* Instantiates a new Service type.
*
* @param code the code
* @param readme the readme
*/
ServiceType(int code, String readme) {
this.code = code;
this.readme = readme;
}
/**
* Gets value.
*
* @return the value
*/
@Override
public Integer getValue() {
return this.code;
}
/**
* Gets description.
*
* @return the description
*/
@Override
public String getDescription() {
return this.readme;
}
}

View File

@ -0,0 +1,27 @@
package com.dispose.config;
import com.dispose.pojo.vo.TemplateInfo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* The type Template configure.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "template")
@Configuration
public class TemplateConfigure {
/**
* The Umc template.
*/
List<TemplateInfo> umcTemplate;
}

View File

@ -1,6 +1,5 @@
package com.dispose.pojo.entity;
import com.dispose.common.ServiceType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
@ -48,7 +47,7 @@ public class ServiceInfo {
/**
* The Service type.
*/
private ServiceType serviceType;
private String serviceType;
/**
* The Service bandwidth.

View File

@ -0,0 +1,34 @@
package com.dispose.pojo.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* The type Template info.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TemplateInfo {
/**
* The Name.
*/
private String name;
/**
* The Band min.
*/
private Long bandMin;
/**
* The Band max.
*/
private Long bandMax;
/**
* The Type.
*/
private String type;
}

View File

@ -0,0 +1,17 @@
package com.dispose.service;
/**
* The interface Template service.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public interface TemplateService {
/**
* Gets template.
*
* @param type the type
* @param bandWidth the band width
* @return the template
*/
String getTemplate(String type, Long bandWidth);
}

View File

@ -0,0 +1,50 @@
package com.dispose.service.impl;
import com.dispose.config.TemplateConfigure;
import com.dispose.pojo.vo.TemplateInfo;
import com.dispose.service.TemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* The type Template service.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Service
@Slf4j
public class TemplateServiceImpl implements TemplateService {
@Resource
TemplateConfigure templateConfigure;
/**
* Gets template.
*
* @param type the type
* @param bandWidth the band width
* @return the template
*/
@Override
public String getTemplate(String type, Long bandWidth) {
// 遍历所有模板
for (TemplateInfo v : templateConfigure.getUmcTemplate()) {
// 判断类型是否一致
if (v.getType().equals(type)) {
// 当前带宽大于当前模板最小值
if (bandWidth > v.getBandMin()) {
// 模板最大值为-1或者带宽小于等于模板最小值返回模板名称
if (v.getBandMax() == -1 || bandWidth <= v.getBandMax()) {
log.debug("Template analyze: {}, {} match {}", type, bandWidth, v);
return v.getName();
}
}
}
}
// 纪录异常日志
log.error("Template analyze: {}, {} match nothing!!!", type, bandWidth);
return null;
}
}

View File

@ -136,7 +136,7 @@ CREATE TABLE `service_group`
(
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符',
`serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID',
`serviceType` int(11) NOT NULL COMMENT '业务类型:\r\n0SEVER\r\n1WEB\r\n2DNS\r\n3GAME',
`serviceType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务类型:SERVER,WEB,DNS,GAME',
`serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽单位M',
`serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址逗号分割',
PRIMARY KEY (`id`) USING BTREE

View File

@ -4,7 +4,7 @@
<resultMap id="service_grp" type="com.dispose.pojo.entity.ServiceInfo">
<id column="id" property="id"/>
<id column = "serviceId" property="serviceId"/>
<result column="serviceType" property="serviceType" javaType="com.dispose.common.ServiceType"/>
<result column="serviceType" property="serviceType"/>
<result column="serviceBandwidth" property="serviceBandwidth"/>
<result column="serviceIp" property="serviceIp"/>
</resultMap>

View File

@ -212,7 +212,7 @@ CREATE TABLE `service_group`
(
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符',
`serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID',
`serviceType` int(11) NOT NULL COMMENT '业务类型:\r\n0SEVER\r\n1WEB\r\n2DNS\r\n3GAME',
`serviceType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务类型:SERVER,WEB,DNS,GAME',
`serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽单位M',
`serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址逗号分割',
PRIMARY KEY (`id`) USING BTREE

View File

@ -26,7 +26,7 @@ import java.util.Optional;
@Data
@Slf4j
@EnableEncryptableProperties
@ActiveProfiles({"test", "dispose"})
@ActiveProfiles({"test", "dispose", "template"})
public class CommonEnvironment {
/**

View File

@ -26,7 +26,7 @@ import javax.annotation.Resource;
@Slf4j
@Getter
@EnableEncryptableProperties
@ActiveProfiles({"test", "dispose"})
@ActiveProfiles({"test", "dispose", "template"})
public class InitTestEnvironment {
/**
* The constant HTTP_CONNECT_TIMEOUT.

View File

@ -0,0 +1,37 @@
package com.dispose.test.dev.config;
import com.dispose.config.TemplateConfigure;
import com.dispose.test.dev.Global.InitTestEnvironment;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* The type Template configure test.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class TemplateConfigureTest extends InitTestEnvironment {
/**
* The Template configure.
*/
@Resource
TemplateConfigure templateConfigure;
/**
* Template loads test.
*/
@Test
public void templateLoadsTest() {
log.info("Load template: {}", templateConfigure.getUmcTemplate());
Assert.assertEquals(9, templateConfigure.getUmcTemplate().size());
}
}