parent
b9bfbfd468
commit
3648437328
|
@ -21,9 +21,8 @@ public interface DisposeAbility {
|
|||
* @param urlPath the url path
|
||||
* @param username the username
|
||||
* @param password the password
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode initDeviceEnv(String urlPath, String username, String password);
|
||||
void initDeviceEnv(String urlPath, String username, String password);
|
||||
|
||||
/**
|
||||
* Run dispose mul return type.
|
||||
|
@ -45,9 +44,19 @@ public interface DisposeAbility {
|
|||
*
|
||||
* @param ip the ip
|
||||
* @param capType the cap type
|
||||
* @param nfDirection the nf direction
|
||||
* @param attackType the attack type
|
||||
* @return the mul return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType);
|
||||
MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
|
||||
@Nullable NetflowDirection[] nfDirection,
|
||||
@Nullable DDoSAttackType[] attackType);
|
||||
|
||||
|
||||
/**
|
||||
* Gets device link status.
|
||||
*
|
||||
* @return the device link status
|
||||
*/
|
||||
boolean getDeviceLinkStatus();
|
||||
}
|
||||
|
|
|
@ -39,16 +39,26 @@ import java.util.stream.Collectors;
|
|||
@Slf4j
|
||||
public class DpTechAbilityImpl implements DisposeAbility {
|
||||
|
||||
/**
|
||||
* The Clean type port.
|
||||
*/
|
||||
private AbnormalFlowCleaningServicePortType cleanTypePort;
|
||||
|
||||
/**
|
||||
* Init device env error code.
|
||||
*
|
||||
* @param urlPath the url path
|
||||
* @param username the username
|
||||
* @param password the password
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode initDeviceEnv(String urlPath, String username, String password) {
|
||||
public void initDeviceEnv(String urlPath, String username, String password) {
|
||||
JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
|
||||
jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class);
|
||||
jaxWsProxyFactoryBean.setAddress(urlPath);
|
||||
|
||||
//WS-Security Head
|
||||
Map<String, Object> outProps = new HashMap<>();
|
||||
Map<String, Object> outProps = new HashMap<>(16);
|
||||
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
|
||||
|
||||
// 配置用户名,密码类型
|
||||
|
@ -61,8 +71,8 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create();
|
||||
|
||||
Map<String, Object> ctx = ((BindingProvider) this.cleanTypePort).getRequestContext();
|
||||
ctx.put("password", username);
|
||||
ctx.put("username", password);
|
||||
ctx.put("password", password);
|
||||
ctx.put("username", username);
|
||||
|
||||
// 配置连接,访问超时时间
|
||||
Client proxy = ClientProxy.getClient(this.cleanTypePort);
|
||||
|
@ -73,8 +83,6 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
//读取超时
|
||||
policy.setReceiveTimeout(DpTechConfigValue.SOAP_RECEIVE_TIMEOUT_SECOND);
|
||||
conduit.setClient(policy);
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,6 +90,9 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
*
|
||||
* @param ip the ip
|
||||
* @param capType the cap type
|
||||
* @param nfDirection the nf direction
|
||||
* @param attackType the attack type
|
||||
* @param duration the duration
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
|
@ -119,7 +130,6 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
}
|
||||
}
|
||||
})));
|
||||
|
||||
log.info("----Finish DPTech Start Cleanup Task: {}", ip);
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
|
@ -133,12 +143,65 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
/**
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param ipAddr the ip addr
|
||||
* @param capType the cap type
|
||||
* @param nfDirection the nf direction
|
||||
* @param attackType the attack type
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType) {
|
||||
return null;
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DisposeCapacityType capType,
|
||||
@Nullable NetflowDirection[] nfDirection,
|
||||
@Nullable DDoSAttackType[] attackType) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
try {
|
||||
log.info("++++Begging DPTech Stop Cleanup Task: {}", ipAddr);
|
||||
|
||||
// 查找需要处置的流量方向集合
|
||||
List<NetflowDirection> dirList = Arrays.stream(NetflowDirection.values())
|
||||
.filter(d -> nfDirection == null || nfDirection.length == 0 || Arrays.asList(nfDirection).contains(d))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查找需要处理的攻击类型集合
|
||||
List<DpTechAttackType> typeList = Arrays.stream(DDoSAttackType.values())
|
||||
.filter(t -> attackType == null || attackType.length == 0 || Arrays.asList(attackType).contains(t))
|
||||
.map(t -> CommonEnumHandler.codeOf(DpTechAttackType.class,
|
||||
DpTechAttackType.fromDdosAttackTypeValue(t)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
dirList.forEach(d -> typeList.forEach(t -> CompletableFuture.supplyAsync(() ->
|
||||
cleanTypePort.stopAbnormalTaskForUMC(ipAddr, t.getValue(), d.getCode()))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
log.error("DPTech stop dispose: {}, {}, error:{}", ipAddr, t.getValue(), ex.getMessage());
|
||||
} else {
|
||||
log.debug("Stop Cleanup: {} --> {}:{}", d, t.getDescription(), t.getValue());
|
||||
if(v.getResultRetVal() != ErrorCode.ERR_OK.getCode()) {
|
||||
log.error("DPTech stop dispose {} error: {}", ipAddr, v.getResultInfo());
|
||||
}
|
||||
}
|
||||
})));
|
||||
log.info("----Finish DPTech Stop Cleanup Task: {}", ipAddr);
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
log.error("----Error DPTech Stop Cleanup Task: {}", ipAddr);
|
||||
err = ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||
}
|
||||
|
||||
return new MulReturnType<>(err, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDeviceLinkStatus() {
|
||||
try {
|
||||
// 获取防护对象接口调用成功认为设备心跳正常
|
||||
cleanTypePort.getAllProtectionObjectFromUMC().getProtectionObjectDataForService();
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ public enum DDoSAttackType implements BaseEnum {
|
|||
*/
|
||||
HOST_TOTAL_TRAFFIC(11, "Host Total Traffic");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
|
|
|
@ -40,12 +40,19 @@ public interface DisposeDeviceManager {
|
|||
MulReturnType<ErrorCode, ObjectStatus> changeDisposeDeviceStatus(Long id, ObjectStatus status);
|
||||
|
||||
/**
|
||||
* Gets all devices.
|
||||
* Gets pages of devices.
|
||||
*
|
||||
* @param startPage the start page
|
||||
* @param pageSize the page size
|
||||
* @return the all devices
|
||||
* @return the pages of devices
|
||||
*/
|
||||
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getAllDevices(Integer startPage,
|
||||
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getPagesOfDevices(Integer startPage,
|
||||
Integer pageSize);
|
||||
|
||||
/**
|
||||
* Gets all dispose devices.
|
||||
*
|
||||
* @return the all dispose devices
|
||||
*/
|
||||
List<DisposeDevice> getAllDisposeDevices();
|
||||
}
|
||||
|
|
|
@ -205,14 +205,14 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets all devices.
|
||||
* Gets pages of devices.
|
||||
*
|
||||
* @param startPage the start page
|
||||
* @param pageSize the page size
|
||||
* @return the all devices
|
||||
* @return the pages of devices
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getAllDevices(Integer startPage,
|
||||
public MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getPagesOfDevices(Integer startPage,
|
||||
Integer pageSize) {
|
||||
// 设置分页信息
|
||||
PageHelper.startPage(startPage, pageSize);
|
||||
|
@ -229,4 +229,20 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
|||
|
||||
return new MulReturnType<>(pageInfo, devList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all dispose devices.
|
||||
*
|
||||
* @return the all dispose devices
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeDevice> getAllDisposeDevices() {
|
||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
|
||||
if(devList == null) {
|
||||
devList = new ArrayList<>();
|
||||
}
|
||||
|
||||
return devList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.dispose.service;
|
||||
|
||||
/**
|
||||
* The interface Dispose ability router service.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeAbilityRouterService {
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.ability.DisposeAbility;
|
||||
import com.dispose.ability.impl.DpTechAbilityImpl;
|
||||
import com.dispose.common.HttpType;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.service.DisposeAbilityRouterService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The type Dispose ability router service.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterService {
|
||||
/**
|
||||
* The Dispose ability map.
|
||||
*/
|
||||
private ConcurrentHashMap<String, DisposeAbility> disposeAbilityMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* The Dispose device manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
|
||||
/**
|
||||
* Init dispose ability.
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initDisposeAbility() {
|
||||
List<DisposeDevice> devList = disposeDeviceManager.getAllDisposeDevices();
|
||||
|
||||
devList.forEach(v -> {
|
||||
DisposeAbility db;
|
||||
|
||||
String httpType = v.getUrlType() == HttpType.HTTP ? "http://" : "https://";
|
||||
String addr = v.getIpPort() == null || v.getIpPort().length() == 0 ? v.getIpAddr() :
|
||||
v.getIpAddr() + ":" + v.getIpPort();
|
||||
|
||||
String url = httpType + addr + "/" + v.getUrlPath();
|
||||
|
||||
switch (v.getDeviceType()) {
|
||||
case DPTECH_UMC:
|
||||
db = new DpTechAbilityImpl();
|
||||
db.initDeviceEnv(url, v.getUserName(), v.getPassword());
|
||||
disposeAbilityMap.put(addr, db);
|
||||
break;
|
||||
case HAOHAN_PLATFORM:
|
||||
break;
|
||||
case VIRTUAL_DISPOSE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -110,6 +110,6 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
|
|||
@Override
|
||||
public MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getAllDisposeDevice(Integer startPage,
|
||||
Integer pageSize) {
|
||||
return disposeDeviceManager.getAllDevices(startPage, pageSize);
|
||||
return disposeDeviceManager.getPagesOfDevices(startPage, pageSize);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.dispose.task;
|
||||
|
||||
import com.dispose.ability.DisposeAbility;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* The type Device manager task.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeviceManagerTask {
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
|
||||
@Resource
|
||||
private DisposeAbility disposeAbility;
|
||||
|
||||
/**
|
||||
* Thread pool task.
|
||||
*/
|
||||
@Async("bizExecutor")
|
||||
@Scheduled(cron = "0/5 * * * * ?")
|
||||
public void threadPoolTask() {
|
||||
log.info("task run......... {}", disposeAbility.getDeviceLinkStatus());
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
disposeAbility.initDeviceEnv("http://10.88.77.15/UMC/service/AbnormalFlowCleaningService",
|
||||
"admin", "UMCAdministrator");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.dispose.thread;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* The type Thread pool config.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Configuration
|
||||
public class ThreadPoolConfig {
|
||||
/**
|
||||
* Biz executor executor.
|
||||
*
|
||||
* @return the executor
|
||||
*/
|
||||
@Bean
|
||||
public Executor bizExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setThreadNamePrefix("myBiz-");
|
||||
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() << 1 + 1);
|
||||
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
|
||||
return executor;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue