REM:
1. 备份DP处置设备相关代码
This commit is contained in:
HuangXin 2020-08-19 09:12:35 +08:00
parent 5680d51a9a
commit 34d7e9af73
5 changed files with 17 additions and 225 deletions

View File

@ -1,39 +0,0 @@
package com.dispose.ability;
import com.dispose.common.DpTechAttackType;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
/**
* The interface Attack type task.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public interface AttackTypeTask {
/**
* Inti attack type task dispose attack type task.
*
* @param ipAddr the ip addr
* @return the dispose attack type task
*/
DisposeAttackTypeTask intiAttackTypeTask(String ipAddr);
/**
* Add attack type task error code.
*
* @param ipAddr the ip addr
* @param directions the directions
* @param attackTypes the attack types
* @param disposeTime the dispose time
* @return the error code
*/
ErrorCode addAttackTypeTask(String ipAddr,
NetflowDirection directions,
DpTechAttackType[] attackTypes,
Long disposeTime);
/**
* Attack type task cleanup.
*/
void attackTypeTaskCleanup();
}

View File

@ -1,27 +0,0 @@
package com.dispose.ability;
import com.dispose.common.DisposeTaskStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* The type Attack type task info.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AttackTypeTaskInfo {
/**
* The Task end time.
*/
private Long taskEndTime;
/**
* The Task status.
*/
private DisposeTaskStatus taskStatus;
}

View File

@ -1,33 +0,0 @@
package com.dispose.ability;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
/**
* The type Dispose attack type task.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DisposeAttackTypeTask {
/**
* The Dir in task.
*/
private HashMap<Integer, AttackTypeTaskInfo> dirInTask;
/**
* The Dir out task.
*/
private HashMap<Integer, AttackTypeTaskInfo> dirOutTask;
/**
* The Ip address.
*/
private String ipAddress;
}

View File

@ -1,12 +1,8 @@
package com.dispose.ability.impl;
import com.dispose.ability.AttackTypeTask;
import com.dispose.ability.AttackTypeTaskInfo;
import com.dispose.ability.DisposeAbility;
import com.dispose.ability.DisposeAttackTypeTask;
import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.DpTechAttackType;
import com.dispose.common.DpTechConfigValue;
import com.dispose.common.ErrorCode;
@ -23,13 +19,10 @@ import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.wss4j.dom.WSConstants;
import org.apache.wss4j.dom.handler.WSHandlerConstants;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
import javax.xml.ws.BindingProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -44,12 +37,7 @@ import java.util.stream.Collectors;
*/
@Component
@Slf4j
public class DpTechAbilityImpl implements DisposeAbility, AttackTypeTask {
/**
* The Device task.
*/
private final HashMap<String, DisposeAttackTypeTask> deviceTask = new HashMap<>();
public class DpTechAbilityImpl implements DisposeAbility {
/**
* The Clean type port.
*/
@ -244,117 +232,4 @@ public class DpTechAbilityImpl implements DisposeAbility, AttackTypeTask {
.cpuUsed(-1)
.build());
}
/**
* Inti attack type task dispose attack type task.
*
* @param ipAddr the ip addr
* @return the dispose attack type task
*/
@Override
public DisposeAttackTypeTask intiAttackTypeTask(String ipAddr) {
if (deviceTask.containsKey(ipAddr)) {
return deviceTask.get(ipAddr);
}
DisposeAttackTypeTask aTask = DisposeAttackTypeTask.builder()
.dirInTask(new HashMap<>(DpTechAttackType.values().length))
.dirOutTask(new HashMap<>(DpTechAttackType.values().length))
.ipAddress(ipAddr)
.build();
for (DpTechAttackType t : DpTechAttackType.values()) {
aTask.getDirInTask().put(t.getValue(), AttackTypeTaskInfo.builder()
.taskEndTime(0L)
.taskStatus(DisposeTaskStatus.TASK_FINISHED)
.build());
aTask.getDirOutTask().put(t.getValue(), AttackTypeTaskInfo.builder()
.taskEndTime(0L)
.taskStatus(DisposeTaskStatus.TASK_FINISHED)
.build());
}
synchronized (this) {
deviceTask.put(ipAddr, aTask);
}
return aTask;
}
/**
* Add attack type task error code.
*
* @param ipAddr the ip addr
* @param directions the directions
* @param attackTypes the attack types
* @param disposeTime the dispose time
* @return the error code
*/
@Override
public ErrorCode addAttackTypeTask(String ipAddr,
NetflowDirection directions,
DpTechAttackType[] attackTypes,
Long disposeTime) {
DisposeAttackTypeTask taskInfo = intiAttackTypeTask(ipAddr);
Long endTime = System.currentTimeMillis() + (disposeTime * 60 * 1000);
if (directions == NetflowDirection.DIRECTION_IN || directions == NetflowDirection.DIRECTION_BI) {
for (DpTechAttackType t : attackTypes) {
AttackTypeTaskInfo ti = taskInfo.getDirInTask().get(t.getValue());
if (ti.getTaskEndTime() < endTime) {
ti.setTaskEndTime(endTime);
if (ti.getTaskStatus() == DisposeTaskStatus.TASK_CANCELED ||
ti.getTaskStatus() == DisposeTaskStatus.TASK_FINISHED) {
ti.setTaskStatus(DisposeTaskStatus.TASK_NEW);
}
taskInfo.getDirInTask().put(t.getValue(), ti);
}
}
}
if (directions == NetflowDirection.DIRECTION_OUT || directions == NetflowDirection.DIRECTION_BI) {
for (DpTechAttackType t : attackTypes) {
AttackTypeTaskInfo ti = taskInfo.getDirOutTask().get(t.getValue());
if (ti.getTaskEndTime() < endTime) {
ti.setTaskEndTime(endTime);
if (ti.getTaskStatus() == DisposeTaskStatus.TASK_CANCELED ||
ti.getTaskStatus() == DisposeTaskStatus.TASK_FINISHED) {
ti.setTaskStatus(DisposeTaskStatus.TASK_NEW);
}
taskInfo.getDirOutTask().put(t.getValue(), ti);
}
}
}
return ErrorCode.ERR_OK;
}
/**
* Attack type task cleanup.
*/
@Override
@Async("bizExecutor")
@Scheduled(fixedDelay = 1000 * 60)
public void attackTypeTaskCleanup() {
for (DisposeAttackTypeTask t : deviceTask.values()) {
boolean clean = true;
List<AttackTypeTaskInfo> taskInfo = new ArrayList<>();
taskInfo.addAll(t.getDirInTask().values());
taskInfo.addAll(t.getDirOutTask().values());
for (AttackTypeTaskInfo v : taskInfo) {
if (v.getTaskEndTime() > System.currentTimeMillis()) {
clean = false;
break;
}
}
if (clean) {
synchronized (this) {
deviceTask.remove(t.getIpAddress());
}
}
}
}
}

View File

@ -80,6 +80,22 @@ public enum DpTechAttackType implements BaseEnum {
this.readme = readme;
}
/**
* Gets type mask from attack type.
*
* @param types the types
* @return the type mask from attack type
*/
public static Long getTypeMaskFromAttackType(DpTechAttackType[] types) {
long mask = 0L;
for (DpTechAttackType type : types) {
mask |= (long)1 << type.getValue();
}
return mask;
}
/**
* From ddos attack type value stream.
*