parent
2a4c655e00
commit
cdc880b575
|
@ -1,55 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Device capacity.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum CleanTaskStatus {
|
||||
/**
|
||||
* task is cleaning.
|
||||
*/
|
||||
CLEANING(1, "清洗中"),
|
||||
/**
|
||||
* task is end of cleaning.
|
||||
*/
|
||||
ENDOFCLEANING(2, "清洗结束"),
|
||||
/**
|
||||
* task is not existed.
|
||||
*/
|
||||
NOTASK(3, "该清洗任务不存在"),
|
||||
/**
|
||||
* HaoHan device err.
|
||||
*/
|
||||
HAOHANERROR(4, "浩瀚设备返回错误"),
|
||||
/**
|
||||
* device not support get task status.
|
||||
*/
|
||||
DEVNOTSUPPORT(0, "设备不支持获取任务状态");
|
||||
|
||||
private final int code;
|
||||
private final String readme;
|
||||
|
||||
CleanTaskStatus(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets readme.
|
||||
*
|
||||
* @return the readme
|
||||
*/
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
}
|
|
@ -70,9 +70,20 @@ public class ConstValue {
|
|||
* The constant NORMAL.
|
||||
*/
|
||||
public static final int NORMAL = 0;
|
||||
|
||||
/**
|
||||
* The constant LOCKED.
|
||||
*/
|
||||
public static final int LOCKED = 1;
|
||||
|
||||
/**
|
||||
* The constant DISABLED.
|
||||
*/
|
||||
public static final int DISABLED = 2;
|
||||
|
||||
/**
|
||||
* The constant DELETED.
|
||||
*/
|
||||
public static final int DELETED = 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Device capacity.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum DeviceCapacity {
|
||||
/**
|
||||
* Cleanup device capacity.
|
||||
*/
|
||||
CLEANUP(0, "清洗能力"),
|
||||
/**
|
||||
* Hidepend device capacity.
|
||||
*/
|
||||
HIDEPEND(1, "高防能力"),
|
||||
/**
|
||||
* Blackhool device capacity.
|
||||
*/
|
||||
BLACKHOOL(2, "黑洞能力"),
|
||||
/**
|
||||
* Detecive device capacity.
|
||||
*/
|
||||
DETECIVE(3, "检测能力"),
|
||||
|
||||
/**
|
||||
* Allcapacity device capacity.
|
||||
*/
|
||||
ALLCAPACITY(-1, "所有能力");
|
||||
|
||||
private final int code;
|
||||
private final String readme;
|
||||
|
||||
DeviceCapacity(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets readme.
|
||||
*
|
||||
* @return the readme
|
||||
*/
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Dispose device type.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum DisposeDeviceType {
|
||||
/**
|
||||
* Dptech umc dispose device type.
|
||||
*/
|
||||
DPTECH_UMC(0, "迪普UMC管理平台"),
|
||||
/**
|
||||
* Haohan platform dispose device type.
|
||||
*/
|
||||
HAOHAN_PLATFORM(1, "浩瀚处置设备"),
|
||||
|
||||
/**
|
||||
* Virtual dispose dispose device type.
|
||||
*/
|
||||
VIRTUAL_DISPOSE(999, "虚拟处置设备");
|
||||
|
||||
private final int code;
|
||||
private final String readme;
|
||||
|
||||
DisposeDeviceType(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets readme.
|
||||
*
|
||||
* @return the readme
|
||||
*/
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Dispose task status.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum DisposeTaskStatus {
|
||||
/**
|
||||
* Task new dispose task status.
|
||||
*/
|
||||
TASK_NEW(0, "新建"),
|
||||
/**
|
||||
* Task running dispose task status.
|
||||
*/
|
||||
TASK_RUNNING(1, "运行中"),
|
||||
/**
|
||||
* Task stop dispose task status.
|
||||
*/
|
||||
TASK_STOP(2, "停止"),
|
||||
/**
|
||||
* Task finish dispose task status.
|
||||
*/
|
||||
TASK_FINISH(3, "结束"),
|
||||
/**
|
||||
* Task delete dispose task status.
|
||||
*/
|
||||
TASK_DELETE(4, "删除");
|
||||
|
||||
private final int code;
|
||||
private final String readme;
|
||||
|
||||
DisposeTaskStatus(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets readme.
|
||||
*
|
||||
* @return the readme
|
||||
*/
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Dp tech attack type.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum DpTechAttackType {
|
||||
/**
|
||||
* The Tcp syn flood.
|
||||
*/
|
||||
TCP_SYN_FLOOD(1, "TCP SYN Flood"),
|
||||
/**
|
||||
* The Udp flood.
|
||||
*/
|
||||
UDP_FLOOD(2, "UDP Flood"),
|
||||
/**
|
||||
* The Icmp flood.
|
||||
*/
|
||||
ICMP_FLOOD(3, "ICMP Flood"),
|
||||
/**
|
||||
* The Tcp syn ack flood.
|
||||
*/
|
||||
TCP_SYN_ACK_FLOOD(6, "TCP SYN-ACK Flood"),
|
||||
/**
|
||||
* The Tcp fin flood.
|
||||
*/
|
||||
TCP_FIN_FLOOD(7, "TCP FIN Flood"),
|
||||
/**
|
||||
* The Ip fragment flood.
|
||||
*/
|
||||
IP_FRAGMENT_FLOOD(8, "IP Fragment Flood"),
|
||||
/**
|
||||
* The Tcp ack flood.
|
||||
*/
|
||||
TCP_ACK_FLOOD(13, "TCP ACK Flood"),
|
||||
/**
|
||||
* The Cc flood.
|
||||
*/
|
||||
CC_FLOOD(15, "CC Flood"),
|
||||
/**
|
||||
* The Http flood.
|
||||
*/
|
||||
HTTP_FLOOD(14, "HTTP Flood"),
|
||||
/**
|
||||
* The Dns query flood.
|
||||
*/
|
||||
DNS_QUERY_FLOOD(16, "DNS Query Flood"),
|
||||
/**
|
||||
* The Dns reply flood.
|
||||
*/
|
||||
DNS_REPLY_FLOOD(33, "DNS Reply Flood"),
|
||||
/**
|
||||
* The Host total traffic.
|
||||
*/
|
||||
HOST_TOTAL_TRAFFIC(31, "Host Total Traffic");
|
||||
|
||||
private final int code;
|
||||
private final String readme;
|
||||
|
||||
DpTechAttackType(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets readme.
|
||||
*
|
||||
* @return the readme
|
||||
*/
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Flow direction.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum FlowDirection {
|
||||
/**
|
||||
* Direction input flow direction.
|
||||
*/
|
||||
DIRECTION_INPUT(0, "流入"),
|
||||
/**
|
||||
* Direction output flow direction.
|
||||
*/
|
||||
DIRECTION_OUTPUT(1, "流出"),
|
||||
/**
|
||||
* Direction twoway flow direction.
|
||||
*/
|
||||
DIRECTION_TWOWAY(2, "双向");
|
||||
|
||||
private final int code;
|
||||
private final String readme;
|
||||
|
||||
FlowDirection(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets readme.
|
||||
*
|
||||
* @return the readme
|
||||
*/
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The type Global var.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public class GlobalVar {
|
||||
|
||||
/**
|
||||
* The constant SOAP_CONNECT_TIMEOUT.
|
||||
*/
|
||||
public static volatile int SOAP_CONNECT_TIMEOUT = 5000;
|
||||
/**
|
||||
* The constant SOAP_RECEIVE_TIMEOUT.
|
||||
*/
|
||||
public static volatile int SOAP_RECEIVE_TIMEOUT = 5000;
|
||||
/**
|
||||
* The constant MAX_THREAT_INFO_VERSION.
|
||||
*/
|
||||
public static volatile int MAX_THREAT_INFO_VERSION = -1;
|
||||
/**
|
||||
* The constant THREAT_INFO_TYPE.
|
||||
*/
|
||||
public static volatile String THREAT_INFO_TYPE = "1";
|
||||
/**
|
||||
* The constant USED_VIRTUAL_DISPOSE_MODE.
|
||||
*/
|
||||
public static volatile boolean USED_VIRTUAL_DISPOSE_MODE = false;
|
||||
|
||||
/**
|
||||
* The constant IS_CHECK_REQUEST_TIMEOUT.
|
||||
*/
|
||||
public static volatile boolean IS_CHECK_REQUEST_TIMEOUT = false;
|
||||
|
||||
/**
|
||||
* The constant STRING_SPILT_CHAR.
|
||||
*/
|
||||
public static final String STRING_SPILT_CHAR = ",";
|
||||
|
||||
/**
|
||||
* The constant STRING_IPV4_FLAG.
|
||||
*/
|
||||
public static final String STRING_IPV4_FLAG = ".";
|
||||
|
||||
/**
|
||||
* The constant STRING_IPV6_FLAG.
|
||||
*/
|
||||
public static final String STRING_IPV6_FLAG = ":";
|
||||
|
||||
/**
|
||||
* The constant STRING_HTTP_AUTH_HEAD.
|
||||
*/
|
||||
public static final String STRING_HTTP_AUTH_HEAD = "Bearer ";
|
||||
|
||||
/**
|
||||
* The constant TASK_ERROR_MAX_RETRY.
|
||||
*/
|
||||
public static final int TASK_ERROR_MAX_RETRY = 3;
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Helper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public class Helper {
|
||||
/**
|
||||
* Attack array to string string.
|
||||
*
|
||||
* @param attack the attack
|
||||
* @return the string
|
||||
*/
|
||||
public static String attackArrayToString(Integer[] attack) {
|
||||
if (attack == null || attack.length == 0) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
StringBuilder strAttack = new StringBuilder();
|
||||
|
||||
for (int v : attack) {
|
||||
strAttack.append(v);
|
||||
strAttack.append(",");
|
||||
}
|
||||
|
||||
String ret = strAttack.toString();
|
||||
|
||||
if (ret.endsWith(GlobalVar.STRING_SPILT_CHAR)) {
|
||||
ret = ret.substring(0, ret.length() - 1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attack string to array integer [ ].
|
||||
*
|
||||
* @param str the str
|
||||
* @return the integer [ ]
|
||||
*/
|
||||
public static Integer[] attackStringToArray(String str) {
|
||||
if (str == null || str.length() == 0) {
|
||||
return new Integer[]{0};
|
||||
}
|
||||
|
||||
String[] spilt = str.split(GlobalVar.STRING_SPILT_CHAR);
|
||||
List<Integer> intArray = new ArrayList<>();
|
||||
|
||||
for (String s : spilt) {
|
||||
intArray.add(Integer.parseInt(s));
|
||||
}
|
||||
|
||||
return intArray.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets timestamp second.
|
||||
*
|
||||
* @param dateTime the date time
|
||||
* @return the timestamp second
|
||||
*/
|
||||
public static int getTimestampSecond(String dateTime) {
|
||||
return (int)(Timestamp.valueOf(dateTime).toInstant().toEpochMilli() / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets timestamp diff.
|
||||
*
|
||||
* @param begin the begin
|
||||
* @param end the end
|
||||
* @return the timestamp diff
|
||||
*/
|
||||
public static int getTimestampDiff(String begin, String end) {
|
||||
int starTime = getTimestampSecond(begin);
|
||||
int endTm = getTimestampSecond(end);
|
||||
|
||||
return endTm - starTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets timestamp diff now.
|
||||
*
|
||||
* @param begin the begin
|
||||
* @return the timestamp diff now
|
||||
*/
|
||||
public static int getTimestampDiffNow(String begin) {
|
||||
int starTime = getTimestampSecond(begin);
|
||||
int endTm = (int)(System.currentTimeMillis() / 1000);
|
||||
|
||||
return endTm - starTime;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Http.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public class Http {
|
||||
|
||||
/**
|
||||
* Post json string.
|
||||
*
|
||||
* @param url the url
|
||||
* @param header the header
|
||||
* @param body the body
|
||||
* @return the string
|
||||
*/
|
||||
public static String postJson(String url, Map<String, String> header, String body) {
|
||||
return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
|
||||
.execute().body();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post form string.
|
||||
*
|
||||
* @param url the url
|
||||
* @param header the header
|
||||
* @param body the body
|
||||
* @return the string
|
||||
*/
|
||||
public static String postForm(String url, Map<String, String> header, Map<String, Object> body) {
|
||||
//header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded")
|
||||
return HttpRequest.post(url).addHeaders(header).form(body)
|
||||
.execute().body();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string.
|
||||
*
|
||||
* @param url the url
|
||||
* @param header the header
|
||||
* @return the string
|
||||
*/
|
||||
public static String get(String url, Map<String, String> header) {
|
||||
return HttpRequest.get(url).addHeaders(header).execute().body();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import inet.ipaddr.IPAddress;
|
||||
import inet.ipaddr.IPAddressSeqRange;
|
||||
import inet.ipaddr.IPAddressString;
|
||||
|
||||
/**
|
||||
* The enum Ip addr type.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum IPAddrType {
|
||||
/**
|
||||
* Ipv 4 type ip addr type.
|
||||
*/
|
||||
IPV4_TYPE,
|
||||
/**
|
||||
* Ipv 6 type ip addr type.
|
||||
*/
|
||||
IPV6_TYPE;
|
||||
|
||||
/**
|
||||
* Gets ip addr type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the ip addr type
|
||||
*/
|
||||
public static IPAddrType getIpAddrType(String ipAddr) {
|
||||
if (ipAddr.contains(GlobalVar.STRING_IPV6_FLAG)) {
|
||||
return IPV6_TYPE;
|
||||
} else {
|
||||
return IPV4_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ip in range boolean.
|
||||
*
|
||||
* @param startIp the start ip
|
||||
* @param endIp the end ip
|
||||
* @param ipAddr the ip addr
|
||||
* @return the boolean
|
||||
* @throws AddressStringException the address string exception
|
||||
*/
|
||||
public static boolean ipInRange(String startIp, String endIp, String ipAddr) throws AddressStringException {
|
||||
IPAddress lower = new IPAddressString(startIp).toAddress();
|
||||
IPAddress upper = new IPAddressString(endIp).toAddress();
|
||||
IPAddress addr = new IPAddressString(ipAddr).toAddress();
|
||||
|
||||
IPAddressSeqRange range = lower.toSequentialRange(upper);
|
||||
|
||||
return range.contains(addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ip in range boolean.
|
||||
*
|
||||
* @param rangeIp the range ip
|
||||
* @param ipAddr the ip addr
|
||||
* @return the boolean
|
||||
* @throws AddressStringException the address string exception
|
||||
*/
|
||||
public static boolean ipInRange(String rangeIp, String ipAddr) throws AddressStringException {
|
||||
final int numIp = 2;
|
||||
|
||||
// 范围为空字符串或者与IP相同时,返回真
|
||||
if (rangeIp.length() == 0 || rangeIp.equals(ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] ipList = rangeIp.split("-");
|
||||
|
||||
if (ipList.length != numIp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IPAddress lower = new IPAddressString(ipList[0]).toAddress();
|
||||
IPAddress upper = new IPAddressString(ipList[1]).toAddress();
|
||||
IPAddress addr = new IPAddressString(ipAddr).toAddress();
|
||||
|
||||
IPAddressSeqRange range = lower.toSequentialRange(upper);
|
||||
|
||||
return range.contains(addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is ip address boolean.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the boolean
|
||||
*/
|
||||
public static boolean isIpAddress(String ipAddr) {
|
||||
|
||||
final String ipv6PortChar = "[";
|
||||
|
||||
int counts = ipAddr.length() - ipAddr.replaceAll(GlobalVar.STRING_IPV6_FLAG, "").length();
|
||||
|
||||
String ipv4Regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
|
||||
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
|
||||
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
|
||||
|
||||
String ipv6Regex = "^(([\\da-fA-F]{1,4}):){8}$";
|
||||
|
||||
switch (counts) {
|
||||
// ipv4
|
||||
case 0:
|
||||
return ipAddr.matches(ipv4Regex);
|
||||
// v4 + port
|
||||
case 1:
|
||||
String ipv4 = ipAddr.substring(0, ipAddr.lastIndexOf(GlobalVar.STRING_IPV6_FLAG));
|
||||
return ipv4.matches(ipv4Regex);
|
||||
default:
|
||||
// Ip v6 + port
|
||||
if (ipAddr.contains(ipv6PortChar)) {
|
||||
String ipv6 = ipAddr.substring(1, ipAddr.lastIndexOf(ipv6PortChar));
|
||||
return ipv6.matches(ipv6Regex);
|
||||
} else {
|
||||
return ipAddr.matches(ipv6Regex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
package com.dispose.config;
|
||||
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.TaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* The type Setup init.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SetupInit implements CommandLineRunner {
|
||||
@Resource
|
||||
private DisposeConfigure disposeConfigure;
|
||||
|
||||
@Resource
|
||||
private DpTechConfigure dpTechConfigure;
|
||||
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
private void loadConfigure() {
|
||||
try {
|
||||
GlobalVar.SOAP_CONNECT_TIMEOUT = Integer.parseInt(dpTechConfigure.getSoapConnTimeout());
|
||||
} catch(Exception ex) {
|
||||
log.error("load SOAP_CONNECT_TIMEOUT configure error: {}", ex.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
GlobalVar.SOAP_RECEIVE_TIMEOUT = Integer.parseInt(dpTechConfigure.getSoapRecvTimeout());
|
||||
} catch(Exception ex) {
|
||||
log.error("load SOAP_RECEIVE_TIMEOUT configure error: {}", ex.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
GlobalVar.IS_CHECK_REQUEST_TIMEOUT = Boolean.parseBoolean(disposeConfigure.getCheckProtocolTimeout());
|
||||
} catch(Exception ex) {
|
||||
log.error("load IS_CHECK_REQUEST_TIMEOUT configure error: {}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run.
|
||||
*
|
||||
* @param args the args
|
||||
*/
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
// 系统初始化入口
|
||||
loadConfigure();
|
||||
disposeNodeManager.loadDisposeNodeFromDatabase();
|
||||
taskService.loadTaskFromDatabase();
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.dispose.config;
|
||||
|
||||
import com.dispose.interceptor.TokenInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* The type Token config.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Configuration
|
||||
public class TokenConfig implements WebMvcConfigurer {
|
||||
/**
|
||||
* Init auth interceptor token interceptor.
|
||||
*
|
||||
* @return the token interceptor
|
||||
*/
|
||||
@Bean
|
||||
public TokenInterceptor initAuthInterceptor(){
|
||||
return new TokenInterceptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add interceptors.
|
||||
*
|
||||
* @param registry the registry
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 注册需要检查token的控制器接口
|
||||
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/information/**");
|
||||
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/manager/**");
|
||||
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/task/**");
|
||||
}
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
package com.dispose.controller;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.pojo.vo.auth.LoginReq;
|
||||
import com.dispose.pojo.vo.auth.LoginRsp;
|
||||
import com.dispose.pojo.vo.auth.LogoutRsp;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* The type Auth controller.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/auth")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||
@Component
|
||||
public class AuthController {
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
/**
|
||||
* User login protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
@ResponseBody
|
||||
@ApiOperation("登录")
|
||||
public ProtocolRespDTO userLogin(@RequestBody ProtocolReqDTO mr)
|
||||
throws JsonProcessingException, NoSuchAlgorithmException {
|
||||
ErrorCode err = mr.verifyRequest();
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
LoginReq reqInfo = mr.getRequestObject(LoginReq.class);
|
||||
|
||||
if (reqInfo.getUserName() == null || reqInfo.getUserName().length() == 0) {
|
||||
log.error("Request username params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getUserName());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getPassword() == null || reqInfo.getPassword().length() == 0) {
|
||||
log.error("Request password params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getPassword());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PASSWORD);
|
||||
}
|
||||
|
||||
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(reqInfo.getUserName(),
|
||||
reqInfo.getPassword());
|
||||
|
||||
if (ret.getFirstParam() != ErrorCode.ERR_OK) {
|
||||
log.error("User login failed, error:{}", ret.getFirstParam().getMsg());
|
||||
return ProtocolRespDTO.result(ret.getFirstParam());
|
||||
}
|
||||
|
||||
LoginRsp rspInfo = LoginRsp.builder()
|
||||
.userName(reqInfo.getUserName())
|
||||
.token(ret.getSecondParam())
|
||||
.logTime(System.currentTimeMillis())
|
||||
.expireTime(System.currentTimeMillis() + ConstValue.GlobalConfigure.TOKEN_EXPIRED_TIME_MS)
|
||||
.build();
|
||||
|
||||
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
rspInfo.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* User logout protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
@ResponseBody
|
||||
@ApiOperation("注销")
|
||||
public ProtocolRespDTO userLogout(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
LoginReq reqInfo = mr.getRequestObject(LoginReq.class);
|
||||
|
||||
if (reqInfo.getUserName() == null || reqInfo.getUserName().length() == 0) {
|
||||
log.error("Request username params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getUserName());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
err = userAccountService.logoutService(reqInfo.getUserName(), mr.getAuthToken());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("User logout failed, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
LogoutRsp rspInfo = LogoutRsp.builder()
|
||||
.userName(reqInfo.getUserName())
|
||||
.build();
|
||||
|
||||
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
rspInfo.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
}
|
|
@ -1,712 +0,0 @@
|
|||
package com.dispose.controller;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.Helper;
|
||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.vo.common.DisposeCapacity;
|
||||
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||
import com.dispose.pojo.vo.common.TaskInfoData;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.pojo.vo.information.DeviceCapacityData;
|
||||
import com.dispose.pojo.vo.information.DeviceCapacityRsp;
|
||||
import com.dispose.pojo.vo.information.DeviceInfoData;
|
||||
import com.dispose.pojo.vo.information.DeviceInfoRsp;
|
||||
import com.dispose.pojo.vo.information.DisposeNodeData;
|
||||
import com.dispose.pojo.vo.information.DisposeNodeListRsp;
|
||||
import com.dispose.pojo.vo.information.LinkStatusListRsp;
|
||||
import com.dispose.pojo.vo.information.LinkStatusRsp;
|
||||
import com.dispose.pojo.vo.information.NodeTaskData;
|
||||
import com.dispose.pojo.vo.information.NodeTaskRsp;
|
||||
import com.dispose.pojo.vo.information.VersionListRsp;
|
||||
import com.dispose.pojo.vo.information.VersionRsp;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.TaskService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Dispose node info controller.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/information")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台能力节点信息接口", tags = "抗DDoS处置平台能力节点信息接口")
|
||||
@Component
|
||||
public class DisposeNodeInfoController {
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
/**
|
||||
* Gets link status.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the link status
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/linkstatus")
|
||||
@ResponseBody
|
||||
@ApiOperation("链接状态")
|
||||
public ProtocolRespDTO getLinkStatus(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
LinkStatusListRsp rspInfo = new LinkStatusListRsp();
|
||||
rspInfo.setItems(new ArrayList<>());
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> rspInfo.getItems().add(LinkStatusRsp.builder()
|
||||
.online(v.getLinkStatus())
|
||||
.id(v.getId().toString())
|
||||
.status(ErrorCode.ERR_OK.getCode())
|
||||
.message(ErrorCode.ERR_OK.getMsg())
|
||||
.build()));
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
rspInfo.getItems().add(LinkStatusRsp.builder()
|
||||
.online(0)
|
||||
.id(v)
|
||||
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
|
||||
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
|
||||
.build());
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets version.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the version
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/version")
|
||||
@ResponseBody
|
||||
@ApiOperation("处置设备版本")
|
||||
public ProtocolRespDTO getVersion(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
VersionListRsp rspInfo = new VersionListRsp();
|
||||
rspInfo.setItems(new ArrayList<>());
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> rspInfo.getItems().add(VersionRsp.builder()
|
||||
.id(v.getId().toString())
|
||||
.version(v.getVersion())
|
||||
.status(ErrorCode.ERR_OK.getCode())
|
||||
.message(ErrorCode.ERR_OK.getMsg())
|
||||
.build()));
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
rspInfo.getItems().add(VersionRsp.builder()
|
||||
.id(v)
|
||||
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
|
||||
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
|
||||
.build());
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device info.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the device info
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/deviceinfo")
|
||||
@ResponseBody
|
||||
@ApiOperation("处置设备信息")
|
||||
public ProtocolRespDTO getDeviceInfo(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
DeviceInfoRsp rspInfo = new DeviceInfoRsp();
|
||||
rspInfo.setItems(new ArrayList<>());
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> rspInfo.getItems().add(new DeviceInfoData(
|
||||
v.getId().toString(),
|
||||
v.getDevInfo().getVendor(),
|
||||
v.getDevInfo().getModel(),
|
||||
v.getDevInfo().getFirmware(),
|
||||
v.getDevInfo().getOs(),
|
||||
v.getDevInfo().getKernel(),
|
||||
v.getDevInfo().getArch(),
|
||||
v.getDevInfo().getMemory(),
|
||||
v.getDevInfo().getFreeMemory(),
|
||||
v.getDevInfo().getCpuUsed(),
|
||||
ErrorCode.ERR_OK
|
||||
)));
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
rspInfo.getItems().add(new DeviceInfoData(v, ErrorCode.ERR_NOSUCHDEVICE));
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets capacity.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the capacity
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/capacity")
|
||||
@ResponseBody
|
||||
@ApiOperation("处置设备处置能力")
|
||||
public ProtocolRespDTO getCapacity(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
DeviceCapacityRsp rspInfo = new DeviceCapacityRsp();
|
||||
rspInfo.setItems(new ArrayList<>());
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
|
||||
cpData.setId(v.getId().toString());
|
||||
cpData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
rspInfo.getItems().add(cpData);
|
||||
});
|
||||
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
DeviceCapacityData cpData = new DeviceCapacityData();
|
||||
cpData.setId(v);
|
||||
cpData.setCapacity(null);
|
||||
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
|
||||
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
|
||||
rspInfo.getItems().add(cpData);
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo, DisposeCapacity.CapacityView.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets protected ip.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protected ip
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/protected_ip")
|
||||
@ResponseBody
|
||||
@ApiOperation("处置设备防护IP")
|
||||
public ProtocolRespDTO getProtectedIp(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
DeviceCapacityRsp rspInfo = new DeviceCapacityRsp();
|
||||
rspInfo.setItems(new ArrayList<>());
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
|
||||
cpData.setId(v.getId().toString());
|
||||
cpData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
rspInfo.getItems().add(cpData);
|
||||
});
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
DeviceCapacityData cpData = new DeviceCapacityData();
|
||||
cpData.setId(v);
|
||||
cpData.setCapacity(null);
|
||||
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
|
||||
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
|
||||
rspInfo.getItems().add(cpData);
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo, DisposeCapacity.DependIpView.class);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose node list.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the dispose node list
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/node_list")
|
||||
@ResponseBody
|
||||
@ApiOperation("处置设备列表")
|
||||
public ProtocolRespDTO getDisposeNodeList(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
if (mr.getMsgContent() == null || mr.getMsgContent().length() == 0) {
|
||||
log.error("ProtocolReqDTO msgContent error");
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
DisposeNodeListRsp rspInfo = new DisposeNodeListRsp();
|
||||
rspInfo.setItems(new ArrayList<>());
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
DisposeNodeData dpData = DisposeNodeData.builder()
|
||||
.type(v.getType())
|
||||
.name(v.getName())
|
||||
.ip(v.getIpAddr())
|
||||
.build();
|
||||
|
||||
dpData.setId(v.getId().toString());
|
||||
dpData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
rspInfo.getItems().add(dpData);
|
||||
});
|
||||
|
||||
if (reqInfo.getId().length != 0) {
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
DisposeNodeData dpData = new DisposeNodeData();
|
||||
dpData.setId(v);
|
||||
dpData.setCapacity(null);
|
||||
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
|
||||
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
|
||||
rspInfo.getItems().add(dpData);
|
||||
});
|
||||
}
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose node details.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the dispose node details
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/node_details")
|
||||
@ResponseBody
|
||||
@ApiOperation("处置节点详细信息")
|
||||
public ProtocolRespDTO getDisposeNodeDetails(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
DisposeNodeListRsp rspInfo = new DisposeNodeListRsp();
|
||||
rspInfo.setItems(new ArrayList<>());
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
DisposeNodeData dpData = new DisposeNodeData(
|
||||
v.getType(), v.getName(), v.getIpAddr(),
|
||||
v.getAreaCode(), v.getManufacturer(), v.getModel(),
|
||||
v.getVersion(), v.getReadme(), v.getDevCaps());
|
||||
|
||||
dpData.setId(v.getId().toString());
|
||||
dpData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
rspInfo.getItems().add(dpData);
|
||||
});
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
DisposeNodeData dpData = new DisposeNodeData();
|
||||
dpData.setId(v);
|
||||
dpData.setCapacity(null);
|
||||
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
|
||||
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
|
||||
rspInfo.getItems().add(dpData);
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets running dispose task list.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the running dispose task list
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/run_task")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取正在进行的处置任务")
|
||||
public ProtocolRespDTO getRunningDisposeTaskList(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
NodeTaskRsp rspInfo = new NodeTaskRsp();
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
rspInfo.getItems().add(taskData);
|
||||
taskData.setId(v.getId().toString());
|
||||
|
||||
List<TaskInfoDetail> runTasks = taskService.getNodeAllRunningTask(v.getId());
|
||||
|
||||
if (runTasks == null || runTasks.size() == 0) {
|
||||
log.error("No tasks in progress");
|
||||
taskData.setTaskArray(null);
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
} else {
|
||||
runTasks.forEach(k -> {
|
||||
int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime());
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getCreateTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
taskData.getTaskArray().add(taskInfoData);
|
||||
taskData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
rspInfo.getItems().add(taskData);
|
||||
taskData.setId(v);
|
||||
taskData.setTaskArray(null);
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all dispose task list.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the all dispose task list
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/all_task")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取所有处置任务")
|
||||
public ProtocolRespDTO getAllDisposeTaskList(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
NodeTaskRsp rspInfo = new NodeTaskRsp();
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
rspInfo.getItems().add(taskData);
|
||||
taskData.setId(v.getId().toString());
|
||||
|
||||
List<TaskInfoDetail> runTasks = taskService.getNodeAllTask(v.getId());
|
||||
|
||||
if (runTasks == null || runTasks.size() == 0) {
|
||||
log.error("No such tasks");
|
||||
taskData.setTaskArray(null);
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
} else {
|
||||
runTasks.forEach(k -> {
|
||||
int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime());
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getCreateTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.currentStatus(taskService.taskIsRunning(k) ? 0 : 1)
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
taskData.getTaskArray().add(taskInfoData);
|
||||
taskData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> !StringUtils.isNumeric(v)
|
||||
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("device not exist, deviceId:{}", v);
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
rspInfo.getItems().add(taskData);
|
||||
taskData.setId(v);
|
||||
taskData.setTaskArray(null);
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
package com.dispose.controller;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.manager.UserAccountCacheManager;
|
||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||
import com.dispose.pojo.vo.device.AddNodeReq;
|
||||
import com.dispose.pojo.vo.device.AddNodeRetData;
|
||||
import com.dispose.pojo.vo.device.AddNodeRsp;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.TaskService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Dispose node manager controller.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/manager")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台能力节点管理接口", tags = "抗DDoS处置平台能力节点管理接口")
|
||||
@Component
|
||||
public class DisposeNodeManagerController {
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
@Resource
|
||||
private UserAccountCacheManager userAccountCacheManager;
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
/**
|
||||
* Add dispose node protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PutMapping("/device")
|
||||
@ResponseBody
|
||||
@ApiOperation("添加处置能力节点")
|
||||
public ProtocolRespDTO addDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
err = userAccountCacheManager.verifyPermission(mr.getAuthToken());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("User not enough permissions, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
AddNodeReq reqInfo = mr.getRequestObject(AddNodeReq.class);
|
||||
AddNodeRsp rspInfo = new AddNodeRsp();
|
||||
|
||||
reqInfo.getItems().forEach(v -> {
|
||||
DisposeDevice dev = DisposeDevice.builder()
|
||||
.type(v.getType())
|
||||
.name(v.getName())
|
||||
.ipAddr(v.getIpAddr())
|
||||
.areaCode(v.getAreaCode())
|
||||
.manufacturer(v.getManufacturer())
|
||||
.model(v.getModel())
|
||||
.version(v.getVersion())
|
||||
.userName(v.getUserName())
|
||||
.password(v.getPassword())
|
||||
.url(v.getUrl())
|
||||
.build();
|
||||
MulReturnType<ErrorCode, String> ret;
|
||||
try {
|
||||
ret = disposeNodeManager.addNewDisposeDevice(dev);
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
ret = new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, v.getIpAddr());
|
||||
}
|
||||
|
||||
AddNodeRetData retStatus = new AddNodeRetData();
|
||||
retStatus.setIpAddr(v.getIpAddr());
|
||||
retStatus.setDevId(ret.getSecondParam());
|
||||
retStatus.setStatus(ret.getFirstParam().getCode());
|
||||
retStatus.setMessage(ret.getFirstParam().getMsg());
|
||||
rspInfo.getItems().add(retStatus);
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove dispose node protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@DeleteMapping("/device")
|
||||
@ResponseBody
|
||||
@ApiOperation("删除处置能力节点")
|
||||
public ProtocolRespDTO removeDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
err = userAccountCacheManager.verifyPermission(mr.getAuthToken());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("User not enough permissions, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getId()[0].length() == 0) {
|
||||
log.error("Prohibit deleting multiple devices at the same time");
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_REMOVEMORE);
|
||||
}
|
||||
|
||||
List<IDReturnStatus> rspInfo = new ArrayList<>();
|
||||
|
||||
IDReturnStatus retItem = new IDReturnStatus();
|
||||
retItem.setId(reqInfo.getId()[0]);
|
||||
|
||||
err = disposeNodeManager.delDisposeDeviceById(Long.valueOf(reqInfo.getId()[0]));
|
||||
|
||||
retItem.setStatus(err.getCode());
|
||||
retItem.setMessage(err.getMsg());
|
||||
|
||||
rspInfo.add(retItem);
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
}
|
|
@ -1,638 +0,0 @@
|
|||
package com.dispose.controller;
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.FlowDirection;
|
||||
import com.dispose.common.Helper;
|
||||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||
import com.dispose.pojo.vo.common.TaskInfoData;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.pojo.vo.information.NodeTaskData;
|
||||
import com.dispose.pojo.vo.information.NodeTaskRsp;
|
||||
import com.dispose.pojo.vo.task.GetTaskReq;
|
||||
import com.dispose.pojo.vo.task.StartTaskReq;
|
||||
import com.dispose.pojo.vo.task.StartTaskRsp;
|
||||
import com.dispose.pojo.vo.task.StopTaskData;
|
||||
import com.dispose.pojo.vo.task.StopTaskReq;
|
||||
import com.dispose.pojo.vo.task.TaskInfoRsp;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.TaskService;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Dispose task controller.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/task")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台处置任务接口", tags = "抗DDoS处置平台处置任务接口")
|
||||
@Component
|
||||
public class DisposeTaskController {
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
@Resource
|
||||
private TaskCacheManager taskCacheManager;
|
||||
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
private static Long convertTimeToLong(String time) {
|
||||
DateTimeFormatter ftf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime parse = LocalDateTime.parse(time, ftf);
|
||||
return LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
/**
|
||||
* Task start protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/start")
|
||||
@ResponseBody
|
||||
@ApiOperation("启动处置任务")
|
||||
public ProtocolRespDTO taskStart(@RequestBody @Valid ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class);
|
||||
|
||||
if (reqInfo.getId() == null || reqInfo.getId().length() == 0) {
|
||||
log.error("Request id params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getId());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getType() == null
|
||||
|| reqInfo.getType() < DeviceCapacity.ALLCAPACITY.getCode()
|
||||
|| reqInfo.getType() > DeviceCapacity.DETECIVE.getCode()) {
|
||||
log.error("Request type params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getType());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getDisposeIp() == null || reqInfo.getDisposeIp().length() == 0
|
||||
|| !IPAddrType.isIpAddress(reqInfo.getDisposeIp())) {
|
||||
log.error("Request dispose ip params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getDisposeIp());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getDisposeTime() == null || reqInfo.getDisposeTime() <= 0) {
|
||||
log.error("Request dispose time params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getDisposeTime());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
StartTaskRsp rspInfo = new StartTaskRsp();
|
||||
|
||||
TaskInfoDetail task = TaskInfoDetail.builder()
|
||||
.deviceId(Long.valueOf(reqInfo.getId()))
|
||||
.accountId(userAccountService.getUserByToken(mr.getAuthToken()).getId())
|
||||
.type(reqInfo.getType())
|
||||
.disposeIp(reqInfo.getDisposeIp())
|
||||
.planEndTime(String.valueOf(reqInfo.getDisposeTime()))
|
||||
.flowDirection(reqInfo.getFlowDirection() != null ? reqInfo.getFlowDirection() : FlowDirection.DIRECTION_TWOWAY.getCode())
|
||||
.flowBandWidth(reqInfo.getFlowBandwidth() != null ? reqInfo.getFlowBandwidth() : 1024)
|
||||
.attackType(Helper.attackArrayToString(reqInfo.getAttackType()))
|
||||
.build();
|
||||
|
||||
MulReturnType<ErrorCode, Long> ret = taskService.createTask(task);
|
||||
|
||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
TaskInfoDetail tf = taskCacheManager.getTaskById(ret.getSecondParam());
|
||||
rspInfo.setId(String.valueOf(tf.getDeviceId()));
|
||||
rspInfo.setTaskId(String.valueOf(ret.getSecondParam()));
|
||||
rspInfo.setExpireTime(convertTimeToLong(tf.getPlanEndTime()));
|
||||
} else {
|
||||
log.error("Failed to create task, error:{}", ret.getFirstParam().getMsg());
|
||||
rspInfo.setId(String.valueOf(reqInfo.getId()));
|
||||
}
|
||||
|
||||
rspInfo.setStatus(ret.getFirstParam().getCode());
|
||||
rspInfo.setMessage(ret.getFirstParam().getMsg());
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Task stop protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/stop")
|
||||
@ResponseBody
|
||||
@ApiOperation("停止处置任务")
|
||||
public ProtocolRespDTO taskStop(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getTaskId() == null
|
||||
|| Arrays.stream(reqInfo.getTaskId()).anyMatch(v -> v.length() == 0)) {
|
||||
log.error("Request taskId params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
Arrays.stream(reqInfo.getTaskId()).forEach(v -> {
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(DeviceCapacity.CLEANUP.getCode()).build();
|
||||
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByTaskId(Long.parseLong(v));
|
||||
|
||||
if (ret.size() == 0) {
|
||||
log.error("No such dispose task, taskId:{}", v);
|
||||
taskData.setTaskId(v);
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
ret.forEach(k -> {
|
||||
if (k.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
ErrorCode retError = k.getFirstParam();
|
||||
TaskInfoDetail taskInfo = k.getSecondParam();
|
||||
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
|
||||
taskData.setTaskId(String.valueOf(taskInfo.getId()));
|
||||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
|
||||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
log.error("Stop task: taskId:{}, error:{}", v, k.getFirstParam().getMsg());
|
||||
taskData.setTaskId(v);
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
taskData.setMessage(k.getFirstParam().getMsg());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Task stop by ip protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/stop_ip")
|
||||
@ResponseBody
|
||||
@ApiOperation("根据处置IP停止处置任务")
|
||||
public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
StopTaskReq reqInfo = mr.getRequestObject(StopTaskReq.class);
|
||||
|
||||
if (reqInfo.getItems().stream().anyMatch(v -> v.getId() == null
|
||||
|| v.getId().length() == 0)) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getItems().stream().anyMatch(v -> v.getType() == null
|
||||
|| v.getType() < DeviceCapacity.ALLCAPACITY.getCode()
|
||||
|| v.getType() > DeviceCapacity.DETECIVE.getCode())) {
|
||||
log.error("Request type params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getItems().stream().anyMatch(v -> v.getDisposeIp() == null
|
||||
|| v.getDisposeIp().length() == 0
|
||||
|| !IPAddrType.isIpAddress(v.getDisposeIp()))) {
|
||||
log.error("Request ip params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
reqInfo.getItems().forEach(v -> {
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
|
||||
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByDisposeIp(Long.parseLong(v.getId()), v.getType(), v.getDisposeIp());
|
||||
|
||||
if (ret.size() == 0) {
|
||||
log.error("No such dispose task, deviceId:{}", v.getId());
|
||||
taskData.setId(v.getId());
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
ret.forEach(k -> {
|
||||
if (k.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
ErrorCode retError = k.getFirstParam();
|
||||
TaskInfoDetail taskInfo = k.getSecondParam();
|
||||
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
|
||||
taskData.setTaskId(String.valueOf(taskInfo.getId()));
|
||||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
} else {
|
||||
log.error("Stop task: taskId:{}, type:{}, disposeIp:{}, error:{}", v.getId(), v.getType(), v.getDisposeIp(),
|
||||
k.getFirstParam().getMsg());
|
||||
if (k.getFirstParam() == ErrorCode.ERR_NOSUCHTASK) {
|
||||
taskData.setDisposeIp(v.getDisposeIp());
|
||||
} else if (k.getFirstParam() == ErrorCode.ERR_NOSUCHDEVICE) {
|
||||
taskData.setId(v.getId());
|
||||
}
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
taskData.setMessage(k.getFirstParam().getMsg());
|
||||
}
|
||||
|
||||
rspInfo.getItems().add(taskData);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Task stop all of dispose node protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/stop_node")
|
||||
@ResponseBody
|
||||
@ApiOperation("停止处置节点处置任务")
|
||||
public ProtocolRespDTO taskStopAllOfDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
StopTaskReq reqInfo = mr.getRequestObject(StopTaskReq.class);
|
||||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
if (reqInfo.getItems().stream().anyMatch(v -> v.getId() == null
|
||||
|| v.getId().length() == 0)) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getItems().stream().anyMatch(v -> v.getType() == null
|
||||
|| v.getType() < DeviceCapacity.ALLCAPACITY.getCode()
|
||||
|| v.getType() > DeviceCapacity.DETECIVE.getCode())) {
|
||||
log.error("Request type params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
reqInfo.getItems().forEach(v -> {
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByDisposeNode(Long.parseLong(v.getId()), v.getType());
|
||||
|
||||
if (ret.size() == 0) {
|
||||
log.error("No such dispose task, deviceId:{}", v.getId());
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
|
||||
taskData.setId(v.getId());
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
ret.forEach(k -> {
|
||||
if (k.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
|
||||
ErrorCode retError = k.getFirstParam();
|
||||
TaskInfoDetail taskInfo = k.getSecondParam();
|
||||
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
|
||||
taskData.setTaskId(String.valueOf(taskInfo.getId()));
|
||||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
|
||||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
log.error("Stop task: deviceId:{}, type:{}, error:{}", v.getId(),
|
||||
v.getType(), k.getFirstParam().getMsg());
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
|
||||
taskData.setId(v.getId());
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
taskData.setMessage(k.getFirstParam().getMsg());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Task stop all protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/stop_all")
|
||||
@ResponseBody
|
||||
@ApiOperation("停止所有处置任务")
|
||||
public ProtocolRespDTO taskStopAll(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
StopTaskData reqInfo = mr.getRequestObject(StopTaskData.class);
|
||||
|
||||
if (reqInfo.getType() == null
|
||||
|| reqInfo.getType() < DeviceCapacity.ALLCAPACITY.getCode()
|
||||
|| reqInfo.getType() > DeviceCapacity.DETECIVE.getCode()) {
|
||||
log.error("Request type params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByType(reqInfo.getType());
|
||||
|
||||
if (ret.size() == 0) {
|
||||
log.error("No such dispose task");
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
ret.forEach(k -> {
|
||||
if (k.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
|
||||
ErrorCode retError = k.getFirstParam();
|
||||
TaskInfoDetail taskInfo = k.getSecondParam();
|
||||
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
|
||||
taskData.setTaskId(String.valueOf(taskInfo.getId()));
|
||||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
|
||||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
log.error("No task to stop: error:{}", k.getFirstParam().getMsg());
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
|
||||
taskData.setType(reqInfo.getType());
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
taskData.setMessage(k.getFirstParam().getMsg());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets node task.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the node task
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/get_node")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取节点处置任务")
|
||||
public ProtocolRespDTO getNodeTask(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers) throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
GetTaskReq reqInfo = mr.getRequestObject(GetTaskReq.class);
|
||||
|
||||
if (reqInfo.getId() == null) {
|
||||
log.error("Request id params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
if (reqInfo.getType() == null
|
||||
|| reqInfo.getType() < DeviceCapacity.ALLCAPACITY.getCode()
|
||||
|| reqInfo.getType() > DeviceCapacity.DETECIVE.getCode()) {
|
||||
log.error("Request type params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
NodeTaskRsp rspInfo = new NodeTaskRsp();
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| reqInfo.getId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
rspInfo.getItems().add(taskData);
|
||||
taskData.setId(v.getId().toString());
|
||||
|
||||
AtomicBoolean bHasData = new AtomicBoolean(false);
|
||||
taskService.getNodeAllRunningTask(v.getId()).forEach(k -> {
|
||||
if (v.getType().equals(reqInfo.getType())
|
||||
|| reqInfo.getType() == DeviceCapacity.ALLCAPACITY.getCode()) {
|
||||
int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime());
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getCreateTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
taskData.getTaskArray().add(taskInfoData);
|
||||
bHasData.compareAndSet(false, true);
|
||||
}
|
||||
});
|
||||
|
||||
if (bHasData.get()) {
|
||||
taskData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
} else {
|
||||
log.error("No such task, deviceId:{}", v.getId());
|
||||
taskData.setId(v.getId().toString());
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
taskData.setTaskArray(null);
|
||||
}
|
||||
});
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("No such task, deviceId:{}", v);
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
rspInfo.getItems().add(taskData);
|
||||
taskData.setId(v);
|
||||
taskData.setTaskArray(null);
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all task.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the all task
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/get")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取全部处置任务")
|
||||
public ProtocolRespDTO getAllTask(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Request header error, error:{}", err.getMsg());
|
||||
return ProtocolRespDTO.result(err);
|
||||
}
|
||||
|
||||
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||
|
||||
if (reqInfo.getTaskId() == null) {
|
||||
log.error("Request taskId params error, error:{}", mr.getMsgContent());
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
|
||||
}
|
||||
|
||||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
List<TaskInfoDetail> valuableData = taskService.getAllTask()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getTaskId().length == 0
|
||||
|| reqInfo.getTaskId()[0].length() == 0
|
||||
|| Arrays.stream(reqInfo.getTaskId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
int diff = Helper.getTimestampDiff(v.getCreateTime(), v.getPlanEndTime());
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(v.getId().toString())
|
||||
.type(v.getType())
|
||||
.startTime(Helper.getTimestampSecond(v.getCreateTime()))
|
||||
.disposeTime(diff / 60)
|
||||
.disposeIp(v.getDisposeIp())
|
||||
.attackType(Helper.attackStringToArray(v.getAttackType()))
|
||||
.flowDirection(v.getFlowDirection())
|
||||
.flowBandWidth(v.getFlowBandWidth())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
rspInfo.getItems().add(taskInfoData);
|
||||
taskInfoData.setId(v.getDeviceId().toString());
|
||||
taskInfoData.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
taskInfoData.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
});
|
||||
|
||||
List<String> unExists = Arrays.stream(reqInfo.getTaskId())
|
||||
.filter(v -> v.length() > 0)
|
||||
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("No such task, taskId:{}", v);
|
||||
TaskInfoData taskData = new TaskInfoData();
|
||||
rspInfo.getItems().add(taskData);
|
||||
taskData.setTaskId(v);
|
||||
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(err, rspInfo);
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package com.dispose.dispose;
|
||||
|
||||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.dispose.impl.DpTechImpl;
|
||||
import com.dispose.dispose.impl.HaoHanImpl;
|
||||
import com.dispose.dispose.impl.VirtualDeviceImpl;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The type Device router.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public class DeviceRouter {
|
||||
|
||||
private static final ConcurrentHashMap<String, DisposeEntryManager> DEVICE_CACHE_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
private static String getMapKey(int devType, String ipAddr) {
|
||||
return devType + "_" + ipAddr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Device router factory dispose entry manager.
|
||||
*
|
||||
* @param device the device
|
||||
* @return the dispose entry manager
|
||||
*/
|
||||
public static DisposeEntryManager deviceRouterFactory(DisposeDevice device) {
|
||||
|
||||
String mapKey = getMapKey(device.getType(), device.getIpAddr());
|
||||
|
||||
// 判断缓存中是否创建过对象,如果创建过直接从缓存中获取
|
||||
if (DEVICE_CACHE_MAP.containsKey(mapKey)) {
|
||||
return DEVICE_CACHE_MAP.get(mapKey);
|
||||
} else {
|
||||
DisposeEntryManager dev = null;
|
||||
// 第一次访问创建新对象并缓存
|
||||
if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
|
||||
// 虚拟设备,供调试业务使用
|
||||
dev = new VirtualDeviceImpl(device);
|
||||
} else if (device.getType() == DisposeDeviceType.DPTECH_UMC.getCode()) {
|
||||
// 迪普设备
|
||||
dev = new DpTechImpl(device);
|
||||
} else if (device.getType() == DisposeDeviceType.HAOHAN_PLATFORM.getCode()) {
|
||||
// 浩瀚设备
|
||||
dev = new HaoHanImpl(device);
|
||||
}
|
||||
|
||||
if (dev != null) {
|
||||
DEVICE_CACHE_MAP.put(mapKey, dev);
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
||||
// 始终返回一个虚拟设备作为默认设备
|
||||
DisposeEntryManager dev = new VirtualDeviceImpl(device);
|
||||
DEVICE_CACHE_MAP.put(mapKey, dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device router factory.
|
||||
*
|
||||
* @param devType the dev type
|
||||
* @param ipAddr the ip addr
|
||||
* @return the device router factory
|
||||
*/
|
||||
public static DisposeEntryManager getDeviceRouterFactory(int devType, String ipAddr) {
|
||||
|
||||
String mapKey = getMapKey(devType, ipAddr);
|
||||
|
||||
// 判断缓存中是否创建过对象,如果创建过直接从缓存中获取
|
||||
if (DEVICE_CACHE_MAP.containsKey(mapKey)) {
|
||||
return DEVICE_CACHE_MAP.get(mapKey);
|
||||
} else {
|
||||
// 始终返回一个虚拟设备作为默认设备
|
||||
DisposeEntryManager dev = new VirtualDeviceImpl(DisposeDevice.builder().build());
|
||||
DEVICE_CACHE_MAP.put(mapKey, dev);
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
package com.dispose.dispose;
|
||||
|
||||
|
||||
import com.dispose.common.CleanTaskStatus;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Dispose entry manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeEntryManager {
|
||||
/**
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @param duration the duration
|
||||
* @return the mul return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> runDispose(String ip, DeviceCapacity type, Long duration);
|
||||
|
||||
/**
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @param devTaskId the dev task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId);
|
||||
|
||||
|
||||
/**
|
||||
* Gets all detection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all detection object
|
||||
*/
|
||||
<T> T getAllDetectionObject();
|
||||
|
||||
/**
|
||||
* Gets all protection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all protection object
|
||||
*/
|
||||
<T> T getAllProtectionObject();
|
||||
|
||||
/**
|
||||
* Gets device capacity.
|
||||
*
|
||||
* @return the device capacity
|
||||
*/
|
||||
List<DisposeDeviceCapacity> getDeviceCapacity();
|
||||
|
||||
/**
|
||||
* Gets detection devices.
|
||||
*
|
||||
* @return the detection devices
|
||||
*/
|
||||
String getDetectionDevices();
|
||||
|
||||
/**
|
||||
* Gets protect devices.
|
||||
*
|
||||
* @return the protect devices
|
||||
*/
|
||||
String getProtectDevices();
|
||||
|
||||
/**
|
||||
* Gets device link status.
|
||||
*
|
||||
* @return the device link status
|
||||
*/
|
||||
boolean getDeviceLinkStatus();
|
||||
|
||||
/**
|
||||
* Gets version.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* Gets device info.
|
||||
*
|
||||
* @return the device info
|
||||
*/
|
||||
DeviceInfo getDeviceInfo();
|
||||
|
||||
/**
|
||||
* Gets device clean task status.
|
||||
* @param devTaskId device Task Id.
|
||||
*
|
||||
* @return the task status
|
||||
*/
|
||||
CleanTaskStatus getCleanTaskStatus(Long devTaskId);
|
||||
}
|
|
@ -1,365 +0,0 @@
|
|||
package com.dispose.dispose.impl;
|
||||
|
||||
import com.dispose.common.CleanTaskStatus;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.DpTechAttackType;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.config.DisposeConfigure;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dptech.dispose.AbnormalFlowCleaningServicePortType;
|
||||
import com.dptech.dispose.ArrayOfProtectionObjectDataForService;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.cxf.endpoint.Client;
|
||||
import org.apache.cxf.frontend.ClientProxy;
|
||||
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
|
||||
import org.apache.cxf.transport.http.HTTPConduit;
|
||||
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 javax.annotation.Resource;
|
||||
import javax.xml.ws.BindingProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* The type Dp tech.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
public class DpTechImpl implements DisposeEntryManager {
|
||||
private final AbnormalFlowCleaningServicePortType cleanTypePort;
|
||||
|
||||
private String password;
|
||||
|
||||
@Resource
|
||||
private DisposeConfigure disposeConfigure;
|
||||
|
||||
/**
|
||||
* Instantiates a new Dp tech.
|
||||
*
|
||||
* @param dev the dev
|
||||
*/
|
||||
public DpTechImpl(DisposeDevice dev) {
|
||||
JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
|
||||
jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class);
|
||||
jaxWsProxyFactoryBean.setAddress(String.format(dev.getUrl(), dev.getIpAddr()));
|
||||
|
||||
this.setPassword(dev.getPassword());
|
||||
|
||||
//WS-Security Head
|
||||
Map<String, Object> outProps = new HashMap<>();
|
||||
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
|
||||
|
||||
// 配置用户名,密码类型
|
||||
outProps.put(WSHandlerConstants.USER, dev.getUserName());
|
||||
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
|
||||
|
||||
// 添加WSSecure头部验证信息
|
||||
jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
|
||||
|
||||
this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create();
|
||||
|
||||
Map<String, Object> ctx = ((BindingProvider) this.cleanTypePort).getRequestContext();
|
||||
ctx.put("password", dev.getPassword());
|
||||
ctx.put("username", dev.getUserName());
|
||||
|
||||
// 配置连接,访问超时时间
|
||||
Client proxy = ClientProxy.getClient(this.cleanTypePort);
|
||||
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
|
||||
HTTPClientPolicy policy = new HTTPClientPolicy();
|
||||
// 请求超时
|
||||
policy.setConnectionTimeout(GlobalVar.SOAP_CONNECT_TIMEOUT);
|
||||
//读取超时
|
||||
policy.setReceiveTimeout(GlobalVar.SOAP_RECEIVE_TIMEOUT);
|
||||
conduit.setClient(policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets version.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "Not Support";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device info.
|
||||
*
|
||||
* @return the device info
|
||||
*/
|
||||
@Override
|
||||
public DeviceInfo getDeviceInfo() {
|
||||
// 当前设备接口不支持,返回模拟数据
|
||||
return DeviceInfo.builder()
|
||||
.vendor("DPTech")
|
||||
.model("UMC")
|
||||
.firmware("Unknown")
|
||||
.os("Windows Server")
|
||||
.kernel("Windows")
|
||||
.arch("x86_64")
|
||||
.memory(-1)
|
||||
.freeMemory(-1)
|
||||
.cpuUsed(-1)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device capacity.
|
||||
*
|
||||
* @return the device capacity
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeDeviceCapacity> getDeviceCapacity() {
|
||||
List<DisposeDeviceCapacity> capList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// 从设备中获取所有检测设备
|
||||
String devs = cleanTypePort.getAllDetectDevices();
|
||||
|
||||
// 保存检测能力信息
|
||||
if (devs != null && devs.length() > 0) {
|
||||
capList.add(DisposeDeviceCapacity.builder()
|
||||
.capacity(DeviceCapacity.DETECIVE.getCode())
|
||||
.tolFlowCapacity(0)
|
||||
.build());
|
||||
}
|
||||
|
||||
// 从设备中获取清洗设备
|
||||
devs = cleanTypePort.getAllProtectDevices();
|
||||
|
||||
if (devs != null && devs.length() > 0) {
|
||||
List<String> strIpV4 = new ArrayList<>();
|
||||
List<String> strIpV6 = new ArrayList<>();
|
||||
|
||||
// 读取清洗设备支持的清洗IP范围
|
||||
ArrayOfProtectionObjectDataForService objs = cleanTypePort.getAllProtectionObjectFromUMC();
|
||||
// 将DPTech设备的IP格式转换成IP访问列表,支持IPv6,IPv4
|
||||
objs.getProtectionObjectDataForService().forEach(v -> {
|
||||
String ipSeg = v.getIpSegment().getValue();
|
||||
if (v.getIpType() == 0 && ipSeg.length() > 0) {
|
||||
strIpV4.addAll(Arrays.asList(ipSeg.replaceAll("\\d+_", "").split(",")));
|
||||
} else if (v.getIpType() == 1 && ipSeg.length() > 0) {
|
||||
strIpV6.addAll(Arrays.asList(ipSeg.replaceAll("\\d+_", "").split(",")));
|
||||
}
|
||||
});
|
||||
|
||||
// 保存清洗能力信息
|
||||
capList.add(DisposeDeviceCapacity.builder()
|
||||
// 清洗能力
|
||||
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||
.tolFlowCapacity(0)
|
||||
// IPv4范围
|
||||
.protectIpV4(strIpV4.toArray(new String[0]))
|
||||
// IPv6范围
|
||||
.protectIpV6(strIpV6.toArray(new String[0]))
|
||||
.build());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
|
||||
return capList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device link status.
|
||||
*
|
||||
* @return the device link status
|
||||
*/
|
||||
@Override
|
||||
public boolean getDeviceLinkStatus() {
|
||||
try {
|
||||
// 获取防护对象接口调用成功认为设备心跳正常
|
||||
getAllProtectionObject();
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @param duration the duration
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> runDispose(String ip, DeviceCapacity type, Long duration) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
// 当前系统接入设备仅仅支持流量清洗功能
|
||||
if (type != DeviceCapacity.CLEANUP) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
||||
}
|
||||
|
||||
try {
|
||||
log.info("++++Begging DPTech Start Cleanup Task: {}", ip);
|
||||
// DPTech流量清洗需要对入口,出口方向,各种攻击类型分别调用接口下发清洗任务
|
||||
// 遍历出口,入口两个方向
|
||||
for (int d : new int[]{0, 1}) {
|
||||
// 遍历所有清洗类型
|
||||
for (DpTechAttackType t : DpTechAttackType.values()) {
|
||||
CompletableFuture.supplyAsync(() -> cleanTypePort.startAbnormalTaskForUMC(ip, t.getCode(), d))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
log.error("DPTech run dispose: {}, {}, error:{}", ip, t.getCode(), ex.getMessage());
|
||||
} else {
|
||||
log.debug("Cleanup: {} --> {}:{}", d, t.getReadme(), t.getCode());
|
||||
if(v.getResultRetVal() != ErrorCode.ERR_OK.getCode()) {
|
||||
log.error("DPTech run dispose {} error: {}", ip, v.getResultInfo());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
log.info("----Finish DPTech Start Cleanup Task: {}", ip);
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
log.error("----Error DPTech Start Cleanup Task: {}", ip);
|
||||
err = ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||
}
|
||||
|
||||
return new MulReturnType<>(err, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @param devTaskId the dev task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
if (type != DeviceCapacity.CLEANUP) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
||||
}
|
||||
|
||||
try {
|
||||
log.info("++++Begging DPTech Stop Cleanup Task: {}", ipAddr);
|
||||
// 遍历入口,出口两个方向
|
||||
for (int d : new int[]{0, 1}) {
|
||||
for (DpTechAttackType t : DpTechAttackType.values()) {
|
||||
CompletableFuture.supplyAsync(() -> cleanTypePort.stopAbnormalTaskForUMC(ipAddr, t.getCode(), d))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
log.error("DPTech stop dispose: {}, {}, error:{}", ipAddr, t.getCode(), ex.getMessage());
|
||||
} else {
|
||||
log.debug("Stop Cleanup: {} --> {}:{}", d, t.getReadme(), t.getCode());
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all detection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all detection object
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAllDetectionObject() {
|
||||
try {
|
||||
return (T) cleanTypePort.getAllDetectionObjectFromUMC().getDetectionObjectDataForService();
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all protection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all protection object
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAllProtectionObject() {
|
||||
try {
|
||||
return (T) cleanTypePort.getAllProtectionObjectFromUMC().getProtectionObjectDataForService();
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets protect devices.
|
||||
*
|
||||
* @return the protect devices
|
||||
*/
|
||||
@Override
|
||||
public String getProtectDevices() {
|
||||
try {
|
||||
return cleanTypePort.getAllProtectDevices();
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detection devices.
|
||||
*
|
||||
* @return the detection devices
|
||||
*/
|
||||
@Override
|
||||
public String getDetectionDevices() {
|
||||
try {
|
||||
return cleanTypePort.getAllDetectDevices();
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device clean task status.
|
||||
*
|
||||
* @param devTaskId device Task Id.
|
||||
* @return the task status
|
||||
*/
|
||||
@Override
|
||||
public CleanTaskStatus getCleanTaskStatus(Long devTaskId) {
|
||||
return CleanTaskStatus.DEVNOTSUPPORT;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,281 +0,0 @@
|
|||
package com.dispose.dispose.impl;
|
||||
|
||||
import com.dispose.common.CleanTaskStatus;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.Http;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.pojo.vo.haohan.CleanReq;
|
||||
import com.dispose.pojo.vo.haohan.CleanRsp;
|
||||
import com.dispose.pojo.vo.haohan.CommonRsp;
|
||||
import com.dispose.pojo.vo.haohan.StopCleanReq;
|
||||
import com.dispose.pojo.vo.haohan.CleanTaskStatusRsp;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Hao han.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Slf4j
|
||||
public class HaoHanImpl implements DisposeEntryManager {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final String deviceAddress;
|
||||
|
||||
/**
|
||||
* Instantiates a new Hao han.
|
||||
*
|
||||
* @param dev the dev
|
||||
*/
|
||||
public HaoHanImpl(DisposeDevice dev) {
|
||||
deviceAddress = String.format(dev.getUrl(), dev.getIpAddr());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @param duration the duration
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> runDispose(String ip, DeviceCapacity type, Long duration) {
|
||||
CleanReq req = CleanReq.builder()
|
||||
.ip(ip)
|
||||
.duration(duration)
|
||||
.orderFrom("China Mobile")
|
||||
.build();
|
||||
|
||||
log.info("++++Begging Haohan Start Cleanup Task: {}", ip);
|
||||
|
||||
try {
|
||||
String ret = Http.postJson(deviceAddress + "/sendTow",
|
||||
null,
|
||||
objectMapper.writeValueAsString(req));
|
||||
|
||||
CleanRsp rsp = objectMapper.readValue(ret, CleanRsp.class);
|
||||
|
||||
if (rsp == null) {
|
||||
log.error("----Error Haohan start clean {} server return error", ip);
|
||||
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
|
||||
}
|
||||
|
||||
if (rsp.getState() != ErrorCode.ERR_OK.getCode()) {
|
||||
log.error("----Error Haohan start clean {} return error: {}, {}", ip, rsp.getState(), rsp.getMsg());
|
||||
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
|
||||
}
|
||||
|
||||
log.info("----Finish Haohan Start Cleanup Task: {}", ip);
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, rsp.getCleanTaskId());
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("----Error Haohan Start Cleanup Task: {}", ip);
|
||||
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @param devTaskId the dev task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) {
|
||||
StopCleanReq req = StopCleanReq.builder()
|
||||
.cleanTaskId(devTaskId)
|
||||
.orderFrom("China Mobile")
|
||||
.build();
|
||||
|
||||
log.info("++++Begging Haohan Stop Cleanup Task: {}", devTaskId);
|
||||
|
||||
try {
|
||||
String ret = Http.postJson(deviceAddress + "/delTow",
|
||||
null,
|
||||
objectMapper.writeValueAsString(req));
|
||||
|
||||
CommonRsp rsp = objectMapper.readValue(ret, CommonRsp.class);
|
||||
|
||||
if (rsp == null) {
|
||||
log.error("----Error Haohan stop task{} server return error", devTaskId);
|
||||
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
|
||||
}
|
||||
|
||||
log.info("----Finish Haohan Stop Cleanup Task: {}", devTaskId);
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("----Error Haohan Stop Cleanup Task: {}", devTaskId);
|
||||
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets version.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "Not Support";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device info.
|
||||
*
|
||||
* @return the device info
|
||||
*/
|
||||
@Override
|
||||
public DeviceInfo getDeviceInfo() {
|
||||
// 当前设备接口不支持,返回模拟数据
|
||||
return DeviceInfo.builder()
|
||||
.vendor("HaoHan")
|
||||
.model("Unknown")
|
||||
.firmware("Unknown")
|
||||
.os("Linux Server")
|
||||
.kernel("Linux")
|
||||
.arch("x86_64")
|
||||
.memory(-1)
|
||||
.freeMemory(-1)
|
||||
.cpuUsed(-1)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device capacity.
|
||||
*
|
||||
* @return the device capacity
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeDeviceCapacity> getDeviceCapacity() {
|
||||
List<DisposeDeviceCapacity> capList = new ArrayList<>();
|
||||
|
||||
// 保存清洗能力信息
|
||||
capList.add(DisposeDeviceCapacity.builder()
|
||||
// 清洗能力
|
||||
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||
.tolFlowCapacity(0)
|
||||
// IPv4范围
|
||||
.protectIpV4(new String[]{""})
|
||||
// IPv6范围
|
||||
.protectIpV6(new String[]{""})
|
||||
.build());
|
||||
|
||||
return capList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device link status.
|
||||
*
|
||||
* @return the device link status
|
||||
*/
|
||||
@Override
|
||||
public boolean getDeviceLinkStatus() {
|
||||
try {
|
||||
String jsonRequest = "{\"cleanTaskId\":\"-1\"}";
|
||||
//"http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow"
|
||||
Http.postJson(deviceAddress + "cleanTaskFlow",
|
||||
null,
|
||||
jsonRequest);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all detection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all detection object
|
||||
*/
|
||||
@Override
|
||||
public <T> T getAllDetectionObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all protection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all protection object
|
||||
*/
|
||||
@Override
|
||||
public <T> T getAllProtectionObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets protect devices.
|
||||
*
|
||||
* @return the protect devices
|
||||
*/
|
||||
@Override
|
||||
public String getProtectDevices() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detection devices.
|
||||
*
|
||||
* @return the detection devices
|
||||
*/
|
||||
@Override
|
||||
public String getDetectionDevices() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device clean task status.
|
||||
*
|
||||
* @param devTaskId device Task Id.
|
||||
* @return the task status
|
||||
*/
|
||||
@Override
|
||||
public CleanTaskStatus getCleanTaskStatus(Long devTaskId) {
|
||||
try {
|
||||
String jsonRequest = String.valueOf(devTaskId);
|
||||
//"http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState"
|
||||
String ret = Http.postJson(deviceAddress + "getCleanTaskState",
|
||||
null,
|
||||
jsonRequest);
|
||||
|
||||
CleanTaskStatusRsp rsp = objectMapper.readValue(ret, CleanTaskStatusRsp.class);
|
||||
|
||||
if (rsp == null) {
|
||||
log.error("----Error Haohan get task{} status error", devTaskId);
|
||||
return CleanTaskStatus.HAOHANERROR;
|
||||
}
|
||||
|
||||
if (rsp.getState() == 0) {
|
||||
if (rsp.getCleanTaskState() == 1) {
|
||||
log.error("----Get task {}, status {}", devTaskId, rsp.getCleanTaskState());
|
||||
return CleanTaskStatus.CLEANING;
|
||||
}
|
||||
|
||||
log.error("----Get task {}, status {}", devTaskId, rsp.getCleanTaskState());
|
||||
return CleanTaskStatus.ENDOFCLEANING;
|
||||
} else {
|
||||
log.error("----Get task {}, status {}", devTaskId, rsp.getCleanTaskState());
|
||||
return CleanTaskStatus.NOTASK;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
return CleanTaskStatus.HAOHANERROR;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
package com.dispose.dispose.impl;
|
||||
|
||||
import com.dispose.common.CleanTaskStatus;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Virtual device.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public class VirtualDeviceImpl implements DisposeEntryManager {
|
||||
|
||||
/**
|
||||
* Instantiates a new Virtual device.
|
||||
*
|
||||
* @param dev the dev
|
||||
*/
|
||||
public VirtualDeviceImpl(DisposeDevice dev) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @param duration the duration
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> runDispose(String ip, DeviceCapacity type, Long duration) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @param devTaskId the dev task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets version.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "Virtual_Device_1.0.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device info.
|
||||
*
|
||||
* @return the device info
|
||||
*/
|
||||
@Override
|
||||
public DeviceInfo getDeviceInfo() {
|
||||
return DeviceInfo.builder()
|
||||
.vendor("Virtual")
|
||||
.model("Dispose_1000")
|
||||
.firmware("Unknown")
|
||||
.os("Unknown")
|
||||
.kernel("Linux")
|
||||
.arch("x86_64")
|
||||
.memory(-1)
|
||||
.freeMemory(-1)
|
||||
.cpuUsed(-1)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device capacity.
|
||||
*
|
||||
* @return the device capacity
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeDeviceCapacity> getDeviceCapacity() {
|
||||
List<DisposeDeviceCapacity> capList = new ArrayList<>();
|
||||
|
||||
capList.add(DisposeDeviceCapacity.builder()
|
||||
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||
.protectIpV4(new String[]{"192.168.3.2-192.168.3.5", "192.168.5.2-192.168.5.10", "192.168.4.2-192.168.4.5"})
|
||||
.protectIpV6(new String[]{})
|
||||
.tolFlowCapacity(1024)
|
||||
.build());
|
||||
|
||||
capList.add(DisposeDeviceCapacity.builder()
|
||||
.capacity(DeviceCapacity.DETECIVE.getCode())
|
||||
.protectIpV4(new String[]{"192.168.2.1", "192.168.2.2"})
|
||||
.protectIpV6(new String[]{})
|
||||
.tolFlowCapacity(0)
|
||||
.build());
|
||||
|
||||
return capList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device link status.
|
||||
*
|
||||
* @return the device link status
|
||||
*/
|
||||
@Override
|
||||
public boolean getDeviceLinkStatus() {
|
||||
return GlobalVar.USED_VIRTUAL_DISPOSE_MODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all detection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all detection object
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAllDetectionObject() {
|
||||
List<String> detectionObjects = new ArrayList<>();
|
||||
|
||||
detectionObjects.add("192.168.10.12-192.168.10.124");
|
||||
return (T) detectionObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all protection object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @return the all protection object
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAllProtectionObject() {
|
||||
List<String> protectObjects = new ArrayList<>();
|
||||
|
||||
protectObjects.add("10.10.10.1-10.10.10.100");
|
||||
protectObjects.add("172.168.133.12-172.168.133.48");
|
||||
return (T) protectObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detection devices.
|
||||
*
|
||||
* @return the detection devices
|
||||
*/
|
||||
@Override
|
||||
public String getDetectionDevices() {
|
||||
return "192.168.10.11";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets protect devices.
|
||||
*
|
||||
* @return the protect devices
|
||||
*/
|
||||
@Override
|
||||
public String getProtectDevices() {
|
||||
return "192.168.10.10";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device clean task status.
|
||||
*
|
||||
* @param devTaskId device Task Id.
|
||||
* @return the task status
|
||||
*/
|
||||
@Override
|
||||
public CleanTaskStatus getCleanTaskStatus(Long devTaskId) {
|
||||
return CleanTaskStatus.DEVNOTSUPPORT;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package com.dispose.dispose.po;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Device info.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
public class DeviceInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String vendor;
|
||||
private String model;
|
||||
private String firmware;
|
||||
private String os;
|
||||
private String kernel;
|
||||
private String arch;
|
||||
private int memory;
|
||||
private int freeMemory;
|
||||
private int cpuUsed;
|
||||
|
||||
/**
|
||||
* Instantiates a new Device info.
|
||||
*
|
||||
* @param vendor the vendor
|
||||
* @param model the model
|
||||
* @param firmware the firmware
|
||||
* @param os the os
|
||||
* @param kernel the kernel
|
||||
* @param arch the arch
|
||||
* @param memory the memory
|
||||
* @param freeMemory the free memory
|
||||
* @param cpuUsed the cpu used
|
||||
*/
|
||||
public DeviceInfo(String vendor,
|
||||
String model,
|
||||
String firmware,
|
||||
String os,
|
||||
String kernel,
|
||||
String arch,
|
||||
int memory,
|
||||
int freeMemory,
|
||||
int cpuUsed) {
|
||||
this.vendor = vendor;
|
||||
this.model = model;
|
||||
this.firmware = firmware;
|
||||
this.os = os;
|
||||
this.kernel = kernel;
|
||||
this.arch = arch;
|
||||
this.memory = memory;
|
||||
this.freeMemory = freeMemory;
|
||||
this.cpuUsed = cpuUsed;
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package com.dispose.exception;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* The type Global exception handler.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* Handle exception protocol resp dto.
|
||||
*
|
||||
* @param request the request
|
||||
* @param e the e
|
||||
* @return the protocol resp dto
|
||||
*/
|
||||
@ExceptionHandler(Throwable.class)
|
||||
@ResponseBody
|
||||
public ProtocolRespDTO handleException(HttpServletRequest request, Throwable e) {
|
||||
log.error("进入全局异常处理", e);
|
||||
ProtocolRespDTO resp = new ProtocolRespDTO();
|
||||
ErrorCode err = ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||
|
||||
resp.setVer(ConstValue.Protocol.VERSION);
|
||||
resp.setCode(err.getHttpCode());
|
||||
resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
resp.setTimeStamp(System.currentTimeMillis());
|
||||
resp.setMsgContent((new ReturnStatus(err.getCode(), err.getMsg())).toString());
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Param exception protocol resp dto.
|
||||
*
|
||||
* @param request the request
|
||||
* @param e the e
|
||||
* @return the protocol resp dto
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public ProtocolRespDTO paramException(HttpServletRequest request, Exception e) {
|
||||
log.error("进入参数校验异常处理", e);
|
||||
|
||||
ProtocolRespDTO resp = new ProtocolRespDTO();
|
||||
ErrorCode err = ErrorCode.ERR_PARAMEXCEPTION;
|
||||
|
||||
resp.setVer(ConstValue.Protocol.VERSION);
|
||||
resp.setCode(err.getHttpCode());
|
||||
resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
resp.setTimeStamp(System.currentTimeMillis());
|
||||
resp.setMsgContent((new ReturnStatus(err.getCode(), err.getMsg())).toString());
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package com.dispose.interceptor;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import reactor.util.annotation.NonNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* The type Token interceptor.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Slf4j
|
||||
public class TokenInterceptor implements HandlerInterceptor {
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
/**
|
||||
* Pre handle boolean.
|
||||
*
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
* @param handler the handler
|
||||
* @return the boolean
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,
|
||||
@NonNull HttpServletResponse response,
|
||||
@NonNull Object handler) throws Exception {
|
||||
// 提取header中的Authorization字段里面的token值
|
||||
String token = request.getHeader("Authorization");
|
||||
|
||||
if (token != null && token.length() > 0) {
|
||||
token = token.replaceFirst(GlobalVar.STRING_HTTP_AUTH_HEAD, "");
|
||||
ErrorCode err = userAccountService.authTokenCheck(token);
|
||||
// 判断token是否合法
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.getWriter().write(new ObjectMapper().writeValueAsString(ProtocolRespDTO.result(err)));
|
||||
log.error("Http request token [{}] is error: {}", token, err);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// 缺少必要的认证头部
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
response.getWriter().write(new ObjectMapper().writeValueAsString(ProtocolRespDTO.result(ErrorCode.ERR_MISSAUTHHEAD)));
|
||||
log.error("Http request head miss \"Authorization\" item");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package com.dispose.manager;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Task cache manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface TaskCacheManager {
|
||||
/**
|
||||
* Add task error code.
|
||||
*
|
||||
* @param taskData the task data
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode addTask(TaskInfoDetail taskData);
|
||||
|
||||
/**
|
||||
* Gets task by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the task by id
|
||||
*/
|
||||
TaskInfoDetail getTaskById(Long id);
|
||||
|
||||
/**
|
||||
* Gets all task.
|
||||
*
|
||||
* @return the all task
|
||||
*/
|
||||
List<TaskInfoDetail> getAllRunningTask();
|
||||
|
||||
/**
|
||||
* Remove task.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
void removeTask(Long id);
|
||||
|
||||
/**
|
||||
* Upgrade task status error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode upgradeTaskStatus(Long id, int status);
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
package com.dispose.manager.impl;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The type Task cache manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TaskCacheManagerImpl implements TaskCacheManager {
|
||||
private final ConcurrentHashMap<Long, TaskInfoDetail> taskCacheMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
|
||||
|
||||
/**
|
||||
* Gets all task.
|
||||
*
|
||||
* @return the all task
|
||||
*/
|
||||
@Override
|
||||
public List<TaskInfoDetail> getAllRunningTask() {
|
||||
return new ArrayList<>(taskCacheMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets task by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the task by id
|
||||
*/
|
||||
@Override
|
||||
public TaskInfoDetail getTaskById(Long id) {
|
||||
if (taskCacheMap.containsKey(id)) {
|
||||
return taskCacheMap.get(id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add task error code.
|
||||
*
|
||||
* @param taskData the task data
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode addTask(TaskInfoDetail taskData) {
|
||||
// 输入参数验证
|
||||
if (taskData == null
|
||||
|| taskData.getDisposeIp() == null
|
||||
|| taskData.getDisposeIp().length() == 0
|
||||
|| taskData.getId() == -1) {
|
||||
if (taskData != null) {
|
||||
log.error("Add task error: taskId:{}, devId:{}, disposeIp:{}", taskData.getId(), taskData.getDeviceId(), taskData.getDisposeIp());
|
||||
} else {
|
||||
log.error("No Task info detail");
|
||||
}
|
||||
return ErrorCode.ERR_INPUTMISS;
|
||||
}
|
||||
|
||||
// 判断任务是否已经存在
|
||||
if (taskCacheMap.containsKey(taskData.getId())) {
|
||||
log.error("Task info detail already existed:taskId:{}, devId:{}, disposeIp:{}",
|
||||
taskData.getId(), taskData.getDeviceId(), taskData.getDisposeIp());
|
||||
return ErrorCode.ERR_DEVICEEXISTS;
|
||||
}
|
||||
|
||||
// 添加到Map缓存中
|
||||
// 保留字段
|
||||
taskData.setRetryTimes(0);
|
||||
taskCacheMap.put(taskData.getId(), taskData);
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove task.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
@Override
|
||||
public void removeTask(Long id) {
|
||||
taskCacheMap.remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade task status error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode upgradeTaskStatus(Long id, int status) {
|
||||
if (!taskCacheMap.containsKey(id)) {
|
||||
log.error("No such task to update the taskStatus: taskId:{}", id);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
taskCacheMap.get(id).setCurrentStatus(status);
|
||||
|
||||
disposeTaskMapper.changeTaskCurrentStatus(id, status);
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
}
|
|
@ -1,288 +0,0 @@
|
|||
package com.dispose.manager.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.config.DisposeConfigure;
|
||||
import com.dispose.manager.UserAccountCacheManager;
|
||||
import com.dispose.pojo.po.UserAccountCache;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The type User account cache manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
|
||||
private static final Random RANDOM_GEN = new Random(System.currentTimeMillis());
|
||||
private final ConcurrentHashMap<String, UserAccountCache> userAccountCache = new ConcurrentHashMap<>();
|
||||
@Resource
|
||||
private DisposeConfigure disposeConfigure;
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* Verify permission error code.
|
||||
*
|
||||
* @param token the token
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode verifyPermission(String token) {
|
||||
if (String.valueOf(false).equals(disposeConfigure.getCheckAdminPermission())) {
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
String username = getUsernameByToken(token);
|
||||
|
||||
if (username == null || username.length() == 0) {
|
||||
log.error("User {} not logged in", username);
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets username by token.
|
||||
*
|
||||
* @param token the token
|
||||
* @return the username by token
|
||||
*/
|
||||
@Override
|
||||
public String getUsernameByToken(String token) {
|
||||
if (userAccountCache.containsKey(token)) {
|
||||
return userAccountCache.get(token).getUsername();
|
||||
}
|
||||
|
||||
log.error("according to token [{}] not found username in cache", token);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify token error code.
|
||||
*
|
||||
* @param token the token
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode verifyToken(String token) {
|
||||
// 判断当前token是否存在,如果不存在则用户没有登录
|
||||
if (!userAccountCache.containsKey(token)) {
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
} else {
|
||||
UserAccountCache uc = userAccountCache.get(token);
|
||||
|
||||
// 根据token提取用户信息,判断当前token是否超时
|
||||
if ((System.currentTimeMillis() - uc.getLastAccess())
|
||||
>= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) {
|
||||
log.error("User {} token timeout before {}", uc.getUsername(), uc.getLastAccess());
|
||||
return ErrorCode.ERR_TOKENTIMEOUT;
|
||||
} else {
|
||||
// 更新用户最后一次访问时间戳
|
||||
uc.setLastAccess(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify user login error code.
|
||||
*
|
||||
* @param username the username
|
||||
* @param token the token
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode verifyUserLogin(String username, String token) {
|
||||
// 缓存中通过用户名查找当前用户
|
||||
Optional<UserAccountCache> findRet = userAccountCache.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
// 用户不存在
|
||||
if (!findRet.isPresent()) {
|
||||
log.error("User {} not exists", username);
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
UserAccountCache uc = findRet.get();
|
||||
|
||||
// 如果token为空说明用户没有登录
|
||||
if (uc.getToken().length() == 0) {
|
||||
log.error("User {} token is empty", username);
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
// 判断用户访问时间间隔是否超时
|
||||
if ((System.currentTimeMillis() - uc.getLastAccess())
|
||||
>= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) {
|
||||
log.error("User {} token is timeout: current {}, last access {}, timeout setting {}",
|
||||
username, System.currentTimeMillis(), uc.getLastAccess(), ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS);
|
||||
return ErrorCode.ERR_TOKENTIMEOUT;
|
||||
}
|
||||
|
||||
// 判断token是否正确
|
||||
if (!uc.getToken().equals(token)) {
|
||||
log.error("User {} token {} is error", username, token);
|
||||
return ErrorCode.ERR_TOKENNOTFOUND;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cache user.
|
||||
*
|
||||
* @return the cache user
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Override
|
||||
public String getCacheUser() throws JsonProcessingException {
|
||||
return objectMapper.writeValueAsString(userAccountCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean user token.
|
||||
*
|
||||
* @param username the username
|
||||
*/
|
||||
@Override
|
||||
public void cleanUserToken(String username) {
|
||||
// 根据用户名在缓存中查找用户
|
||||
Optional<UserAccountCache> findRet = userAccountCache.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if (findRet.isPresent()) {
|
||||
UserAccountCache uc = findRet.get();
|
||||
// 缓存中删除当前用户
|
||||
userAccountCache.remove(uc.getToken());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets usr pwd err times.
|
||||
*
|
||||
* @param username the username
|
||||
* @return the usr pwd err times
|
||||
*/
|
||||
@Override
|
||||
public int getUsrPwdErrTimes(String username) {
|
||||
Optional<UserAccountCache> findRet = userAccountCache.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if (findRet.isPresent()) {
|
||||
UserAccountCache uc = findRet.get();
|
||||
return uc.getPwdErrTimes();
|
||||
} else {
|
||||
// 缓存不存在,说明用户未登录过或者已经过期,创建一个新用户缓存
|
||||
UserAccountCache uc = UserAccountCache.builder()
|
||||
.username(username)
|
||||
.token("")
|
||||
.lastAccess(System.currentTimeMillis())
|
||||
.pwdErrTimes(0)
|
||||
.build();
|
||||
|
||||
userAccountCache.put(uc.getToken(), uc);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets user pwd err times.
|
||||
*
|
||||
* @param username the username
|
||||
* @param errTimes the err times
|
||||
*/
|
||||
@Override
|
||||
public void setUserPwdErrTimes(String username, Integer errTimes) {
|
||||
Optional<UserAccountCache> findRet = userAccountCache.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if (findRet.isPresent()) {
|
||||
UserAccountCache uc = findRet.get();
|
||||
uc.setPwdErrTimes(Math.abs(errTimes));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets user token.
|
||||
*
|
||||
* @param username the username
|
||||
* @return the user token
|
||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||
*/
|
||||
@Override
|
||||
public String getUserToken(String username) throws NoSuchAlgorithmException {
|
||||
UserAccountCache uc;
|
||||
|
||||
// 根据用户名在缓存中查找用户
|
||||
Optional<UserAccountCache> findRet = userAccountCache.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if (findRet.isPresent()) {
|
||||
uc = findRet.get();
|
||||
|
||||
// token过期获取以前没有token,创建一个新token
|
||||
if ((System.currentTimeMillis() - uc.getLastAccess())
|
||||
>= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS
|
||||
|| uc.getToken().length() == 0) {
|
||||
// 移除过期的项
|
||||
userAccountCache.remove(uc.getToken());
|
||||
// 更新token,访问时间
|
||||
uc.setToken(createUserToken(username));
|
||||
// 重新添加到缓存中
|
||||
userAccountCache.put(uc.getToken(), uc);
|
||||
log.info("Refresh {} Token:{}", username, uc.getToken());
|
||||
} else {
|
||||
log.info("Get {} Token:{}", username, uc.getToken());
|
||||
}
|
||||
|
||||
uc.setLastAccess(System.currentTimeMillis());
|
||||
} else {
|
||||
// 用户不存在说明没有登陆过,创建一个新的用户缓存
|
||||
uc = UserAccountCache.builder()
|
||||
.username(username)
|
||||
.token(createUserToken(username))
|
||||
.pwdErrTimes(0)
|
||||
.lastAccess(System.currentTimeMillis()).build();
|
||||
|
||||
userAccountCache.put(uc.getToken(), uc);
|
||||
|
||||
log.info("Create {} Token:{}", username, uc.getToken());
|
||||
|
||||
}
|
||||
return uc.getToken();
|
||||
}
|
||||
|
||||
private String createUserToken(String username) throws NoSuchAlgorithmException {
|
||||
// 获取指定摘要算法的messageDigest对象
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
String tokenKey = username +
|
||||
Convert.toStr(RANDOM_GEN.nextInt()) +
|
||||
Convert.toStr(System.currentTimeMillis());
|
||||
// 调用digest方法,进行加密操作
|
||||
byte[] cipherBytes = messageDigest.digest(tokenKey.getBytes());
|
||||
|
||||
return Hex.encodeHexString(cipherBytes);
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
/**
|
||||
* The interface Dispose device mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
|
||||
/**
|
||||
* Add new dispose device.
|
||||
*
|
||||
* @param dev the dev
|
||||
*/
|
||||
void addNewDisposeDevice(DisposeDevice dev);
|
||||
|
||||
/**
|
||||
* Is device exists by ip int.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the int
|
||||
*/
|
||||
int isDeviceExistsByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Is device exists by id int.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the int
|
||||
*/
|
||||
int isDeviceExistsById(Long id);
|
||||
|
||||
/**
|
||||
* Gets device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the device by ip
|
||||
*/
|
||||
DisposeDevice getDeviceByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Gets device by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the device by id
|
||||
*/
|
||||
DisposeDevice getDeviceById(Long id);
|
||||
|
||||
/**
|
||||
* Del dispose device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
*/
|
||||
void delDisposeDeviceByIp(String ipAddr);
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Dispose task mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeTaskMapper extends Mapper<TaskInfoDetail>,
|
||||
IdsMapper<TaskInfoDetail>, MySqlMapper<TaskInfoDetail> {
|
||||
|
||||
/**
|
||||
* Add new task.
|
||||
*
|
||||
* @param taskInfo the task info
|
||||
*/
|
||||
void addNewTask(TaskInfoDetail taskInfo);
|
||||
|
||||
/**
|
||||
* Remove task by id.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
void removeTaskById(Long id);
|
||||
|
||||
/**
|
||||
* Change task current status.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
*/
|
||||
void changeTaskCurrentStatus(@Param("id") Long id,
|
||||
@Param("status") int status);
|
||||
|
||||
/**
|
||||
* Gets task current status.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the task current status
|
||||
*/
|
||||
int getTaskCurrentStatus(Long id);
|
||||
|
||||
/**
|
||||
* Gets task info by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the task info by id
|
||||
*/
|
||||
TaskInfoDetail getTaskById(Long id);
|
||||
|
||||
/**
|
||||
* Gets all task by dispose ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the all task by dispose ip
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTaskByDisposeIp(@Param("ipAddr") String ipAddr);
|
||||
|
||||
/**
|
||||
* Gets all task by node dev id.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @return the all task by node dev id
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTaskByNodeDevId(Long devId);
|
||||
|
||||
/**
|
||||
* Gets node all task by user id.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @return the node all task by user id
|
||||
*/
|
||||
List<TaskInfoDetail> getNodeAllTaskByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* Gets node task by ip and status.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param ipAddr the ip addr
|
||||
* @param status the status
|
||||
* @return the node task by ip and status
|
||||
*/
|
||||
List<TaskInfoDetail> getNodeTaskByIpAndStatus(@Param("devId") Long devId,
|
||||
@Param("ipAddr") String ipAddr,
|
||||
@Param("status") int status);
|
||||
|
||||
/**
|
||||
* Gets all task by status.
|
||||
*
|
||||
* @param status the status
|
||||
* @return the all task by status
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTaskByStatus(@Param("status") int status);
|
||||
|
||||
/**
|
||||
* Gets task by task info.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param userId the user id
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the task by task info
|
||||
*/
|
||||
List<TaskInfoDetail> getTaskByTaskDetail(
|
||||
@Param("devId") Long devId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("ipAddr") String ipAddr,
|
||||
@Param("type") int type
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets all task by type.
|
||||
*
|
||||
* @param type the type
|
||||
* @return the all task by type
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTaskByType(@Param("type") int type);
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
|
||||
import com.dispose.pojo.vo.common.TaskInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Task info mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface TaskInfoMapper extends Mapper<TaskInfo>, MySqlMapper<TaskInfo> {
|
||||
/**
|
||||
* Add new task info.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param deviceId the device id
|
||||
* @param externId the extern id
|
||||
* @param status the status
|
||||
*/
|
||||
void addNewTaskInfo(@Param("taskId") Long taskId,
|
||||
@Param("deviceId") Long deviceId,
|
||||
@Param("externId") Long externId,
|
||||
@Param("status") Long status);
|
||||
|
||||
/**
|
||||
* Gets task info.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param deviceId the device id
|
||||
* @return the task info
|
||||
*/
|
||||
TaskInfo getTaskInfo(@Param("taskId") Long taskId,
|
||||
@Param("deviceId") Long deviceId);
|
||||
|
||||
/**
|
||||
* Gets task info by task id.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the task info by task id
|
||||
*/
|
||||
List<TaskInfo> getTaskInfoByTaskId(Long taskId);
|
||||
|
||||
/**
|
||||
* Change task info status.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
*/
|
||||
void changeTaskInfoStatus(@Param("id") Long id,
|
||||
@Param("status") Long status);
|
||||
|
||||
/**
|
||||
* Gets task info current status.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the task info current status
|
||||
*/
|
||||
int getTaskInfoCurrentStatus(Long id);
|
||||
|
||||
/**
|
||||
* Remove task by id.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
void removeTaskInfoById(Long id);
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package com.dispose.pojo.dto;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Base protocol dto.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ApiModel("通信协议实体")
|
||||
@JsonPropertyOrder({"ver", "cryptoType", "timeStamp", "msgContent"})
|
||||
public abstract class BaseProtocolDTO {
|
||||
@ApiModelProperty(value = "协议版本号", required = true, example = "1")
|
||||
private Integer ver;
|
||||
|
||||
@ApiModelProperty(value = "msgContent字段内容编码格式:\n" +
|
||||
"0:无编码格式,普通字符串\n" +
|
||||
"1:base64编码格式\n" +
|
||||
"2:采用AES加密后的base64编码格式\n", required = true,
|
||||
allowableValues = "0, 1, 2",
|
||||
example = "0")
|
||||
private Integer cryptoType;
|
||||
|
||||
@ApiModelProperty(value = "当前UTC时间戳", required = true, example = "1526625689000")
|
||||
private Long timeStamp;
|
||||
|
||||
@ApiModelProperty(value = "协议详细内容,Json字符串格式。\n" +
|
||||
"保存该cmdId命令相关的详细内容,\n" +
|
||||
"具体每个cmdId命令的详细内容参看对应的命令协议定义",
|
||||
example = "{}")
|
||||
private String msgContent;
|
||||
|
||||
/**
|
||||
* Is request timeout boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Boolean isRequestTimeout() {
|
||||
|
||||
if (!ConstValue.GlobalConfigure.IS_SKIP_TIMEOUT_CHECK) {
|
||||
Long current = System.currentTimeMillis();
|
||||
long timeDiff = current - this.timeStamp;
|
||||
|
||||
return timeDiff > 0 && timeDiff <= 3000;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
package com.dispose.pojo.dto;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The type Protocol req dto.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
@Slf4j
|
||||
public class ProtocolReqDTO extends BaseProtocolDTO {
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
private static String token = "";
|
||||
|
||||
/**
|
||||
* Gets request object.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param objType the obj type
|
||||
* @return the request object
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
public <T> T getRequestObject(Class<T> objType) throws JsonProcessingException {
|
||||
// 返回协议 MsgContent 字段内容
|
||||
return OBJECT_MAPPER.readValue(this.getMsgContent(), objType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets auth token.
|
||||
*
|
||||
* @return the auth token
|
||||
*/
|
||||
@JsonIgnore
|
||||
public String getAuthToken() {
|
||||
return ProtocolReqDTO.token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify request error code.
|
||||
*
|
||||
* @param headers the headers
|
||||
* @return the error code
|
||||
*/
|
||||
public ErrorCode verifyRequest(HttpHeaders headers) {
|
||||
|
||||
ErrorCode err = verifyRequest();
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("headers error, error:{}", err.getMsg());
|
||||
return err;
|
||||
}
|
||||
|
||||
// 是否有必要的HTTP Head字段
|
||||
if (headers == null) {
|
||||
log.error("Http request is missing authentication header");
|
||||
return ErrorCode.ERR_MISSAUTHHEAD;
|
||||
}
|
||||
|
||||
try {
|
||||
String authString = Objects.requireNonNull(headers.get("Authorization")).get(0);
|
||||
|
||||
if (authString.length() == 0 || !authString.startsWith(GlobalVar.STRING_HTTP_AUTH_HEAD)) {
|
||||
log.error("Input Authorization header error: [{}]", authString);
|
||||
return ErrorCode.ERR_PARAMEXCEPTION;
|
||||
}
|
||||
// 保持当前请求token内容
|
||||
ProtocolReqDTO.token = authString.replaceFirst(GlobalVar.STRING_HTTP_AUTH_HEAD, "");
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
return ErrorCode.ERR_MISSAUTHHEAD;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify request error code.
|
||||
*
|
||||
* @return the error code
|
||||
*/
|
||||
public ErrorCode verifyRequest() {
|
||||
|
||||
if (this.getVer() == null || this.getCryptoType() == null || this.getTimeStamp() == null) {
|
||||
log.error("request params error: ver:{}, cryptoType:{}, TimeStamp:{}", this.getVer(), this.getCryptoType(), this.getTimeStamp());
|
||||
return ErrorCode.ERR_PARAMEXCEPTION;
|
||||
}
|
||||
|
||||
// 校验版本
|
||||
if (this.getVer() < ConstValue.Protocol.VERSION) {
|
||||
log.error("version error: ver:{}", this.getVer());
|
||||
return ErrorCode.ERR_VERSION;
|
||||
}
|
||||
|
||||
// 校验时间错
|
||||
if (GlobalVar.IS_CHECK_REQUEST_TIMEOUT
|
||||
&& Math.abs(System.currentTimeMillis() - this.getTimeStamp()) >= ConstValue.Protocol.REQUEST_TIMEOUT_MS) {
|
||||
log.error("request timeout: diffTimeMillis:{}", Math.abs(System.currentTimeMillis() - this.getTimeStamp()));
|
||||
return ErrorCode.ERR_REQUESTTIMEOUT;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package com.dispose.pojo.dto;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Protocol resp dto.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"ver", "cryptoType", "timeStamp", "code", "msgContent"})
|
||||
public class ProtocolRespDTO extends BaseProtocolDTO {
|
||||
|
||||
@ApiModelProperty(value = "服务器返回状态码",
|
||||
example = "200")
|
||||
private Integer code;
|
||||
|
||||
private static String getObjectJson(Object obj) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
return objectMapper.writeValueAsString(obj);
|
||||
}
|
||||
|
||||
private static <T> String getObjectJson(Object obj, Class<T> objType) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
return objectMapper.writerWithView(objType).writeValueAsString(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Result protocol resp dto.
|
||||
*
|
||||
* @param err the err
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
public static ProtocolRespDTO result(ErrorCode err) throws JsonProcessingException {
|
||||
ProtocolRespDTO resp = new ProtocolRespDTO();
|
||||
|
||||
resp.setVer(ConstValue.Protocol.VERSION);
|
||||
resp.setCode(err.getHttpCode());
|
||||
resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
resp.setTimeStamp(System.currentTimeMillis());
|
||||
resp.setMsgContent(getObjectJson(new ReturnStatus(err.getCode(), err.getMsg())));
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Result protocol resp dto.
|
||||
*
|
||||
* @param err the err
|
||||
* @param respMsg the resp msg
|
||||
* @return the protocol resp dto
|
||||
*/
|
||||
public static ProtocolRespDTO result(ErrorCode err, String respMsg) {
|
||||
return result(err, respMsg, ConstValue.Protocol.CRYPTO_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Result protocol resp dto.
|
||||
*
|
||||
* @param err the err
|
||||
* @param obj the obj
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
public static ProtocolRespDTO result(ErrorCode err, Object obj) throws JsonProcessingException {
|
||||
return result(err, getObjectJson(obj), ConstValue.Protocol.CRYPTO_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Result protocol resp dto.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param err the err
|
||||
* @param obj the obj
|
||||
* @param objType the obj type
|
||||
* @return the protocol resp dto
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
public static <T> ProtocolRespDTO result(ErrorCode err, Object obj, Class<T> objType) throws JsonProcessingException {
|
||||
return result(err, getObjectJson(obj, objType), ConstValue.Protocol.CRYPTO_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Result protocol resp dto.
|
||||
*
|
||||
* @param err the err
|
||||
* @param respMsg the resp msg
|
||||
* @param crypto the crypto
|
||||
* @return the protocol resp dto
|
||||
*/
|
||||
public static ProtocolRespDTO result(ErrorCode err, String respMsg, Integer crypto) {
|
||||
ProtocolRespDTO resp = new ProtocolRespDTO();
|
||||
|
||||
resp.setVer(ConstValue.Protocol.VERSION);
|
||||
resp.setCode(err.getHttpCode());
|
||||
resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
resp.setTimeStamp(System.currentTimeMillis());
|
||||
resp.setMsgContent(respMsg);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package com.dispose.pojo.entity;
|
||||
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import tk.mybatis.mapper.annotation.KeySql;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Dispose device.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Table(name = "dispose_device")
|
||||
@NameStyle(Style.normal)
|
||||
public class DisposeDevice implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
private String ipAddr;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Integer areaCode;
|
||||
|
||||
private String name;
|
||||
|
||||
private String manufacturer;
|
||||
|
||||
private String model;
|
||||
|
||||
private String version;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String password;
|
||||
|
||||
private String url;
|
||||
|
||||
private String readme;
|
||||
|
||||
private Integer status;
|
||||
|
||||
@Transient
|
||||
private Integer linkStatus;
|
||||
|
||||
@Transient
|
||||
private List<DisposeDeviceCapacity> devCaps;
|
||||
|
||||
@Transient
|
||||
private DeviceInfo devInfo;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.dispose.pojo.po;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Dispose device capacity.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DisposeDeviceCapacity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer capacity;
|
||||
|
||||
private Integer tolFlowCapacity;
|
||||
|
||||
private String[] protectIpV4;
|
||||
|
||||
private String[] protectIpV6;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.dispose.pojo.po;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type New node info.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class NewNodeInfo {
|
||||
private String id;
|
||||
private Integer type;
|
||||
private String ipAddr;
|
||||
private Integer areaCode;
|
||||
private String name;
|
||||
private String manufacturer;
|
||||
private String model;
|
||||
private String userName;
|
||||
private String password;
|
||||
private String url;
|
||||
private String version;
|
||||
private String readme;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.dispose.pojo.po;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Return status.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ReturnStatus {
|
||||
private Integer status;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* To string string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\"status\":" + status + ", \"message\":\"" + message + "\"}";
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.dispose.pojo.po;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* The type User account cache.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class UserAccountCache {
|
||||
private String username;
|
||||
private String token;
|
||||
private Long lastAccess;
|
||||
private Integer pwdErrTimes;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.dispose.pojo.vo.auth;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Login req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class LoginReq {
|
||||
private String userName;
|
||||
private String password;
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.dispose.pojo.vo.auth;
|
||||
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Login rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"})
|
||||
public class LoginRsp extends ReturnStatus {
|
||||
private String userName;
|
||||
private String token;
|
||||
private Long logTime;
|
||||
private Long expireTime;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.dispose.pojo.vo.auth;
|
||||
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Logout rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"})
|
||||
public class LogoutRsp extends ReturnStatus {
|
||||
private String userName;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package com.dispose.pojo.vo.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* The type Dispose capacity.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DisposeCapacity {
|
||||
@JsonView(BaseView.class)
|
||||
private Integer type;
|
||||
@JsonView(DependIpView.class)
|
||||
private String disposeIp;
|
||||
@JsonView(CapacityView.class)
|
||||
private Integer tolCapacity;
|
||||
@JsonView(CapacityView.class)
|
||||
private Integer usedCapacity;
|
||||
|
||||
/**
|
||||
* The interface Base view.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface BaseView {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Capacity view.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface CapacityView extends BaseView {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Depend ip view.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DependIpView extends BaseView {
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package com.dispose.pojo.vo.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Id array req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class IDArrayReq {
|
||||
private String[] id;
|
||||
private String[] taskId;
|
||||
|
||||
public void setId(String[] id) {
|
||||
List<String> idList = Arrays.asList(id);
|
||||
|
||||
if (idList.contains(null)) {
|
||||
this.id = null;
|
||||
} else if (idList.contains("")) {
|
||||
this.id = new String[]{""};
|
||||
} else {
|
||||
Map<String, Long> ret = idList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
|
||||
System.out.println(ret);
|
||||
|
||||
List<String> keyList = new ArrayList<>(ret.keySet());
|
||||
this.id = keyList.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTaskId(String[] taskId) {
|
||||
List<String> idList = Arrays.asList(taskId);
|
||||
|
||||
if (idList.contains(null)) {
|
||||
this.taskId = null;
|
||||
} else if (idList.contains("")) {
|
||||
this.taskId = new String[]{""};
|
||||
} else {
|
||||
Map<String, Long> ret = idList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
|
||||
System.out.println(ret);
|
||||
|
||||
List<String> keyList = new ArrayList<>(ret.keySet());
|
||||
this.taskId = keyList.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.dispose.pojo.vo.common;
|
||||
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Id return status.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "devId", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class IDReturnStatus extends ReturnStatus {
|
||||
private String id;
|
||||
private String devId;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.dispose.pojo.vo.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* The type Task info.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "task_info")
|
||||
@NameStyle(Style.normal)
|
||||
public class TaskInfo {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private Long taskId;
|
||||
private Long deviceId;
|
||||
private String beginTime;
|
||||
private String endTime;
|
||||
private Long externId;
|
||||
private Long status;
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.dispose.pojo.vo.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Task info data.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "taskId", "currentStatus", "type", "disposeIp", "startTime", "disposeTime",
|
||||
"flowDirection", "attackType", "flowBandWidth", "flowAttack", "flowClean", "leftTime", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class TaskInfoData extends IDReturnStatus {
|
||||
private String taskId;
|
||||
private Integer type;
|
||||
private String disposeIp;
|
||||
private Integer leftTime;
|
||||
private Integer startTime;
|
||||
private Integer disposeTime;
|
||||
private Integer flowDirection;
|
||||
private Integer[] attackType;
|
||||
private Integer flowBandWidth;
|
||||
|
||||
private Integer flowAttack;
|
||||
|
||||
private Integer flowClean;
|
||||
|
||||
private Integer currentStatus;
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.dispose.pojo.vo.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Task info detail.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "dispose_task")
|
||||
@NameStyle(Style.normal)
|
||||
public class TaskInfoDetail implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private Long deviceId;
|
||||
private Long accountId;
|
||||
private Integer type;
|
||||
private String disposeIp;
|
||||
private String createTime;
|
||||
private String planEndTime;
|
||||
private String endTime;
|
||||
private Integer flowDirection;
|
||||
private String attackType;
|
||||
private Integer flowBandWidth;
|
||||
private Integer currentStatus;
|
||||
|
||||
private int retryTimes;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.dispose.pojo.vo.device;
|
||||
|
||||
import com.dispose.pojo.po.NewNodeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Add node req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddNodeReq {
|
||||
private List<NewNodeInfo> items;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.dispose.pojo.vo.device;
|
||||
|
||||
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Add node ret data.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@JsonPropertyOrder({"id", "ipAddr", "devId", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddNodeRetData extends IDReturnStatus {
|
||||
private String ipAddr;
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.dispose.pojo.vo.device;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Add node rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddNodeRsp {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
List<AddNodeRetData> items;
|
||||
|
||||
/**
|
||||
* Instantiates a new Add node rsp.
|
||||
*/
|
||||
public AddNodeRsp() {
|
||||
this.items = new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.dispose.pojo.vo.haohan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Clean req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class CleanReq {
|
||||
private String ip;
|
||||
private String orderFrom;
|
||||
private Long duration;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.dispose.pojo.vo.haohan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Clean rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class CleanRsp extends CommonRsp {
|
||||
private Long cleanTaskId;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.dispose.pojo.vo.haohan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Clean rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class CleanTaskStatusRsp extends CommonRsp {
|
||||
private Long cleanTaskState;
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.dispose.pojo.vo.haohan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Common rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class CommonRsp {
|
||||
private Integer state;
|
||||
private String msg;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.dispose.pojo.vo.haohan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Stop clean req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class StopCleanReq {
|
||||
private Long cleanTaskId;
|
||||
private String orderFrom;
|
||||
}
|
||||
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.vo.common.DisposeCapacity;
|
||||
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Device capacity data.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@JsonPropertyOrder({"id", "capacity", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeviceCapacityData extends IDReturnStatus {
|
||||
/**
|
||||
* The Capacity.
|
||||
*/
|
||||
List<DisposeCapacity> capacity;
|
||||
|
||||
/**
|
||||
* Instantiates a new Device capacity data.
|
||||
*
|
||||
* @param cpList the cp list
|
||||
*/
|
||||
public DeviceCapacityData(List<DisposeDeviceCapacity> cpList) {
|
||||
this.capacity = new ArrayList<>();
|
||||
|
||||
if (cpList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
cpList.forEach(v -> {
|
||||
String ipAddrs = String.join(",",
|
||||
Arrays.asList(v.getProtectIpV4() != null ? v.getProtectIpV4() : new String[]{}))
|
||||
+ "," + String.join(",",
|
||||
Arrays.asList(v.getProtectIpV6() != null ? v.getProtectIpV6() : new String[]{})
|
||||
);
|
||||
|
||||
if (ipAddrs.endsWith(GlobalVar.STRING_SPILT_CHAR)) {
|
||||
ipAddrs = ipAddrs.substring(0, ipAddrs.length() - 1);
|
||||
}
|
||||
|
||||
DisposeCapacity cp = DisposeCapacity.builder()
|
||||
.type(v.getCapacity())
|
||||
.tolCapacity(v.getTolFlowCapacity())
|
||||
.usedCapacity(0)
|
||||
.disposeIp(ipAddrs)
|
||||
.build();
|
||||
|
||||
this.capacity.add(cp);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Device capacity rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@JsonPropertyOrder({"id", "capacity", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeviceCapacityRsp {
|
||||
private List<DeviceCapacityData> items;
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Device info data.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@JsonPropertyOrder({"id"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeviceInfoData extends DeviceInfo {
|
||||
private String id;
|
||||
private int status;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* Instantiates a new Device info data.
|
||||
*
|
||||
* @param id the id
|
||||
* @param vendor the vendor
|
||||
* @param model the model
|
||||
* @param firmware the firmware
|
||||
* @param os the os
|
||||
* @param kernel the kernel
|
||||
* @param arch the arch
|
||||
* @param memory the memory
|
||||
* @param freeMemory the free memory
|
||||
* @param cpuUsed the cpu used
|
||||
* @param err the err
|
||||
*/
|
||||
public DeviceInfoData(String id,
|
||||
String vendor,
|
||||
String model,
|
||||
String firmware,
|
||||
String os,
|
||||
String kernel,
|
||||
String arch,
|
||||
int memory,
|
||||
int freeMemory,
|
||||
int cpuUsed,
|
||||
ErrorCode err) {
|
||||
super(vendor, model, firmware, os, kernel, arch, memory, freeMemory, cpuUsed);
|
||||
this.id = id;
|
||||
this.status = err.getCode();
|
||||
this.message = err.getMsg();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Device info data.
|
||||
*
|
||||
* @param id the id
|
||||
* @param err the err
|
||||
*/
|
||||
public DeviceInfoData(String id,
|
||||
ErrorCode err) {
|
||||
this.id = id;
|
||||
this.status = err.getCode();
|
||||
this.message = err.getMsg();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Device info rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
public class DeviceInfoRsp {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
List<DeviceInfoData> items;
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Dispose node data.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"id", "type", "name", "ip", "areaCode", "manufacturer", "model", "version", "readme", "status",
|
||||
"message"})
|
||||
public class DisposeNodeData extends DeviceCapacityData {
|
||||
private Integer type;
|
||||
private String name;
|
||||
private String ip;
|
||||
private Integer areaCode;
|
||||
private String manufacturer;
|
||||
private String model;
|
||||
private String version;
|
||||
private String readme;
|
||||
|
||||
/**
|
||||
* Instantiates a new Dispose node data.
|
||||
*
|
||||
* @param type the type
|
||||
* @param name the name
|
||||
* @param ip the ip
|
||||
* @param areaCode the area code
|
||||
* @param manufacturer the manufacturer
|
||||
* @param model the model
|
||||
* @param version the version
|
||||
* @param readme the readme
|
||||
* @param capacity the capacity
|
||||
*/
|
||||
public DisposeNodeData(int type, String name, String ip, Integer areaCode,
|
||||
String manufacturer, String model, String version,
|
||||
String readme,
|
||||
List<DisposeDeviceCapacity> capacity) {
|
||||
super(capacity);
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.ip = ip;
|
||||
this.areaCode = areaCode;
|
||||
this.manufacturer = manufacturer;
|
||||
this.model = model;
|
||||
this.version = version;
|
||||
this.readme = readme;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Dispose node list rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class DisposeNodeListRsp {
|
||||
private List<DisposeNodeData> items;
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Project: phoenix_ddos_handle2
|
||||
*
|
||||
* File Created at 2020/5/11 10:59
|
||||
*
|
||||
* Copyright 2019 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Link status list rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class LinkStatusListRsp {
|
||||
private List<LinkStatusRsp> items;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Link status rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "devId", "online", "status", "message"})
|
||||
public class LinkStatusRsp extends IDReturnStatus {
|
||||
private int online;
|
||||
private String id;
|
||||
private Integer status;
|
||||
private String message;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||
import com.dispose.pojo.vo.common.TaskInfoData;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Node task data.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "taskArray", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class NodeTaskData extends IDReturnStatus {
|
||||
private List<TaskInfoData> taskArray;
|
||||
|
||||
/**
|
||||
* Instantiates a new Node task data.
|
||||
*/
|
||||
public NodeTaskData() {
|
||||
this.taskArray = new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Node task rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class NodeTaskRsp {
|
||||
private List<NodeTaskData> items;
|
||||
|
||||
/**
|
||||
* Instantiates a new Node task rsp.
|
||||
*/
|
||||
public NodeTaskRsp() {
|
||||
this.items = new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Project: phoenix_ddos_handle2
|
||||
*
|
||||
* File Created at 2020/5/11 12:54
|
||||
*
|
||||
* Copyright 2019 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Version list rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class VersionListRsp {
|
||||
private List<VersionRsp> items;
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.dispose.pojo.vo.information;
|
||||
|
||||
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Version rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "devId", "version", "status", "message"})
|
||||
public class VersionRsp extends IDReturnStatus {
|
||||
private String version;
|
||||
private String id;
|
||||
private String devId;
|
||||
private Integer status;
|
||||
private String message;
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.dispose.pojo.vo.task;
|
||||
|
||||
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Get task req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class GetTaskReq extends IDArrayReq {
|
||||
private Integer type;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.dispose.pojo.vo.task;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Start task req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class StartTaskReq {
|
||||
private String id;
|
||||
private Integer type;
|
||||
private String disposeIp;
|
||||
private Integer disposeTime;
|
||||
private Integer flowDirection;
|
||||
private Integer[] attackType;
|
||||
private Integer flowBandwidth;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.dispose.pojo.vo.task;
|
||||
|
||||
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Start task rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "taskId", "expireTime", "status", "message"})
|
||||
public class StartTaskRsp extends IDReturnStatus {
|
||||
private String taskId;
|
||||
private Long expireTime;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.dispose.pojo.vo.task;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Stop task data.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"id", "type", "disposeIp"})
|
||||
public class StopTaskData {
|
||||
private String id;
|
||||
private Integer type;
|
||||
private String disposeIp;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.dispose.pojo.vo.task;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Stop task req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class StopTaskReq {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
List<StopTaskData> items;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.dispose.pojo.vo.task;
|
||||
|
||||
import com.dispose.pojo.vo.common.TaskInfoData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Task info rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class TaskInfoRsp {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
List<TaskInfoData> items;
|
||||
|
||||
/**
|
||||
* Instantiates a new Task info rsp.
|
||||
*/
|
||||
public TaskInfoRsp() {
|
||||
this.items = new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package com.dispose.service;
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Dispose node manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeNodeManager {
|
||||
/**
|
||||
* Add new dispose device m return type.
|
||||
*
|
||||
* @param dev the dev
|
||||
* @return the m return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, String> addNewDisposeDevice(DisposeDevice dev);
|
||||
|
||||
/**
|
||||
* Del dispose device by ip error code.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode delDisposeDeviceByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Del dispose device by id error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode delDisposeDeviceById(Long id);
|
||||
|
||||
/**
|
||||
* Gets all dispose device.
|
||||
*
|
||||
* @return the all dispose device
|
||||
*/
|
||||
List<DisposeDevice> getAllDisposeDevice();
|
||||
|
||||
/**
|
||||
* Gets dispose device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the dispose device by ip
|
||||
*/
|
||||
DisposeDevice getDisposeDeviceByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Gets dispose device by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the dispose device by id
|
||||
*/
|
||||
DisposeDevice getDisposeDeviceById(Long id);
|
||||
|
||||
/**
|
||||
* Load dispose node from database.
|
||||
*/
|
||||
void loadDisposeNodeFromDatabase();
|
||||
|
||||
/**
|
||||
* Cleanup dispose node cache.
|
||||
*/
|
||||
void cleanupDisposeNodeCache();
|
||||
|
||||
/**
|
||||
* Gets dispose device.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param capacity the capacity
|
||||
* @return the dispose device
|
||||
*/
|
||||
List<DisposeDevice> getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package com.dispose.service;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Task service.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface TaskService {
|
||||
/**
|
||||
* Load task from database.
|
||||
*/
|
||||
void loadTaskFromDatabase();
|
||||
|
||||
/**
|
||||
* Create task m return type.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the m return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> createTask(TaskInfoDetail task);
|
||||
|
||||
/**
|
||||
* Start task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode startTask(Long taskId);
|
||||
|
||||
/**
|
||||
* Stop task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode stopTask(Long taskId);
|
||||
|
||||
/**
|
||||
* Stop task by dispose ip list.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param type the type
|
||||
* @param ipAddr the ip addr
|
||||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByDisposeIp(Long devId, int type, String ipAddr);
|
||||
|
||||
/**
|
||||
* Stop task by task id list.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByTaskId(Long taskId);
|
||||
|
||||
/**
|
||||
* Stop task by type list.
|
||||
*
|
||||
* @param type the type
|
||||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByType(int type);
|
||||
|
||||
/**
|
||||
* Stop task by dispose node list.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param type the type
|
||||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByDisposeNode(Long devId, int type);
|
||||
|
||||
/**
|
||||
* Finish task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode finishTask(Long taskId);
|
||||
|
||||
/**
|
||||
* Task is running boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean taskIsRunning(TaskInfoDetail task);
|
||||
|
||||
/**
|
||||
* Task is expired boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean taskIsExpired(TaskInfoDetail task);
|
||||
|
||||
/**
|
||||
* Task is exists boolean.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param userId the user id
|
||||
* @param disposeIp the dispose ip
|
||||
* @param disposeType the dispose type
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean taskIsExists(Long devId, Long userId, String disposeIp, int disposeType);
|
||||
|
||||
/**
|
||||
* Gets node all running task.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @return the node all running task
|
||||
*/
|
||||
List<TaskInfoDetail> getNodeAllRunningTask(Long devId);
|
||||
|
||||
/**
|
||||
* Gets node all task.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @return the node all task
|
||||
*/
|
||||
List<TaskInfoDetail> getNodeAllTask(Long devId);
|
||||
|
||||
/**
|
||||
* Gets all task.
|
||||
*
|
||||
* @return the all task
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTask();
|
||||
|
||||
/**
|
||||
* Gets active task.
|
||||
*
|
||||
* @return the active task
|
||||
*/
|
||||
List<TaskInfoDetail> getActiveTask();
|
||||
}
|
|
@ -13,11 +13,11 @@ import java.security.NoSuchAlgorithmException;
|
|||
*/
|
||||
public interface UserAccountService {
|
||||
/**
|
||||
* Login service m return type.
|
||||
* Login service mul return type.
|
||||
*
|
||||
* @param username the username
|
||||
* @param password the password
|
||||
* @return the m return type
|
||||
* @return the mul return type
|
||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||
*/
|
||||
MulReturnType<ErrorCode, String> loginService(String username, String password) throws NoSuchAlgorithmException;
|
||||
|
|
|
@ -1,293 +0,0 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.mapper.TaskInfoMapper;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Dispose node manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
@Resource
|
||||
private TaskInfoMapper taskInfoMapper;
|
||||
|
||||
/**
|
||||
* Cleanup dispose node cache.
|
||||
*/
|
||||
@Override
|
||||
public void cleanupDisposeNodeCache() {
|
||||
disposeDevMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load dispose node from database.
|
||||
*/
|
||||
@Override
|
||||
public void loadDisposeNodeFromDatabase() {
|
||||
// 清理缓存中的所有内容
|
||||
disposeDevMap.clear();
|
||||
|
||||
// 从数据库中加载所有设备
|
||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
|
||||
if (devList == null) {
|
||||
log.error("No device in database");
|
||||
return;
|
||||
}
|
||||
|
||||
devList.forEach(v -> {
|
||||
// 对每个设备进行初始化
|
||||
//DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v.getType(),
|
||||
// v.getIpAddr(), IPAddrType.getIpAddrType(v.getIpAddr()));
|
||||
|
||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v);
|
||||
// 链接状态
|
||||
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
||||
// 版本信息
|
||||
v.setVersion(dp.getVersion());
|
||||
// 设备信息
|
||||
v.setDevInfo(dp.getDeviceInfo());
|
||||
// 设备能力信息
|
||||
v.setDevCaps(dp.getDeviceCapacity());
|
||||
|
||||
disposeDevMap.put(v.getIpAddr(), v);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Del dispose device by id error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode delDisposeDeviceById(Long id) {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceById(id);
|
||||
|
||||
if (dev == null) {
|
||||
log.error("No such device: deviceId:{}", id);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
return delDisposeDeviceByIp(dev.getIpAddr());
|
||||
}
|
||||
|
||||
/**
|
||||
* Del dispose device by ip error code.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode delDisposeDeviceByIp(String ipAddr) {
|
||||
// 判断该IP是否存在
|
||||
if (disposeDeviceMapper.isDeviceExistsByIp(ipAddr) == 0
|
||||
|| !disposeDevMap.containsKey(ipAddr)) {
|
||||
log.error("No such dispose device: ipAddr:{}", ipAddr);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
// 缓存中取出设备
|
||||
DisposeDevice dev = disposeDevMap.get(ipAddr);
|
||||
|
||||
if (dev == null) {
|
||||
log.error("No such dispose device in cache: ipAddr:{}", ipAddr);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
//删除task info表中的任务
|
||||
taskInfoMapper.removeTaskInfoById(dev.getId());
|
||||
|
||||
// 删除数据库和缓存中内容
|
||||
disposeDeviceMapper.delDisposeDeviceByIp(ipAddr);
|
||||
disposeDevMap.remove(ipAddr);
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new dispose device m return type.
|
||||
*
|
||||
* @param dev the dev
|
||||
* @return the m return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, String> addNewDisposeDevice(DisposeDevice dev) {
|
||||
DisposeEntryManager dp;
|
||||
|
||||
if (dev.getType() == null || dev.getIpAddr() == null
|
||||
|| dev.getIpAddr().length() == 0
|
||||
|| !IPAddrType.isIpAddress(dev.getIpAddr())) {
|
||||
log.error("Add device error: type {}, ip {} url {}", dev.getType(), dev.getIpAddr(), dev.getUrl());
|
||||
return new MulReturnType<>(ErrorCode.ERR_PARAMS, String.valueOf(-1));
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取处置设备硬件访问接口
|
||||
dp = DeviceRouter.deviceRouterFactory(dev);
|
||||
|
||||
// 判断设备是否在线
|
||||
if (!dp.getDeviceLinkStatus()) {
|
||||
log.error("The device heartbeat is abnormal and offline: deviceId:{}, type:{}, ip:{}",
|
||||
dev.getId(), dev.getType(), dev.getIpAddr());
|
||||
return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("No such dispose device: deviceId:{}, type:{}, ip:{}", dev.getId(), dev.getType(), dev.getIpAddr());
|
||||
return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||
}
|
||||
|
||||
// 从缓存中获取设备信息
|
||||
DisposeDevice dbDev = disposeDeviceMapper.getDeviceByIp(dev.getIpAddr());
|
||||
|
||||
// 设备已经存在
|
||||
if (dbDev != null) {
|
||||
log.error("The dispose device already exists: deviceId:{}, type:{}, ip:{}", dev.getId(), dev.getType(), dev.getIpAddr());
|
||||
return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, String.valueOf(dbDev.getId()));
|
||||
}
|
||||
|
||||
// 获取设备能力
|
||||
if (dev.getDevCaps() == null) {
|
||||
// 更新能力
|
||||
dev.setDevCaps(dp.getDeviceCapacity());
|
||||
} else {
|
||||
// 添加能力
|
||||
dev.getDevCaps().addAll(dp.getDeviceCapacity());
|
||||
}
|
||||
|
||||
dev.setDevInfo(dp.getDeviceInfo());
|
||||
|
||||
// 保存设备信息到数据库中
|
||||
disposeDeviceMapper.addNewDisposeDevice(dev);
|
||||
|
||||
// 保存设备信息到缓存中
|
||||
disposeDevMap.put(dev.getIpAddr(), dev);
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, dev.getId().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all dispose device.
|
||||
*
|
||||
* @return the all dispose device
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeDevice> getAllDisposeDevice() {
|
||||
return new ArrayList<>(disposeDevMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the dispose device by ip
|
||||
*/
|
||||
@Override
|
||||
public DisposeDevice getDisposeDeviceByIp(String ipAddr) {
|
||||
return disposeDevMap.get(ipAddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose device by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the dispose device by id
|
||||
*/
|
||||
@Override
|
||||
public DisposeDevice getDisposeDeviceById(Long id) {
|
||||
Optional<DisposeDevice> findRet = disposeDevMap.values().stream()
|
||||
.filter(disposeDevMap -> id.equals(disposeDevMap.getId()))
|
||||
.findFirst();
|
||||
|
||||
return findRet.orElse(null);
|
||||
}
|
||||
|
||||
private boolean isIpInRange(DisposeDeviceCapacity cap, String ipAddr) {
|
||||
try {
|
||||
if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV4_TYPE) {
|
||||
for (String s : cap.getProtectIpV4()) {
|
||||
if (IPAddrType.ipInRange(s, ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV6_TYPE) {
|
||||
for (String s : cap.getProtectIpV6()) {
|
||||
if (IPAddrType.ipInRange(s, ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (AddressStringException e) {
|
||||
log.error(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
log.error("The IP address is not within device capacity: ipAddr:{}, capIpv4:{}, capIpv6:{}",
|
||||
ipAddr, cap.getProtectIpV4(), cap.getProtectIpV6());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose device.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param capacity the capacity
|
||||
* @return the dispose device
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeDevice> getDisposeDevice(String ipAddr, DeviceCapacity capacity) {
|
||||
List<DisposeDevice> devList = new ArrayList<>();
|
||||
|
||||
for (DisposeDevice dev : disposeDevMap.values()) {
|
||||
// 判断设备是否在线
|
||||
if (dev.getLinkStatus() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断当前设备是否支持处置能力
|
||||
List<DisposeDeviceCapacity> capList = dev.getDevCaps()
|
||||
.stream()
|
||||
.filter(f -> f.getCapacity() == capacity.getCode())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 设备是否支持处置该IP的
|
||||
if (capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||
log.info("{} with {} used device {}:{}", ipAddr, capacity.getReadme(), dev.getId(), dev.getIpAddr());
|
||||
devList.add(dev);
|
||||
}
|
||||
}
|
||||
|
||||
if (devList.size() == 0) {
|
||||
log.error("No such device to process {} of {}", ipAddr, capacity.getReadme());
|
||||
}
|
||||
|
||||
return devList;
|
||||
}
|
||||
}
|
|
@ -1,544 +0,0 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.Helper;
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.mapper.TaskInfoMapper;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.pojo.vo.common.TaskInfo;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.TaskService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Task service.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TaskServiceImpl implements TaskService {
|
||||
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private TaskCacheManager taskCacheManager;
|
||||
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
@Resource
|
||||
private TaskInfoMapper taskInfoMapper;
|
||||
|
||||
private List<DisposeDevice> getDisposeNode(String disposeIp, int devCapType) {
|
||||
DeviceCapacity cap;
|
||||
|
||||
try {
|
||||
cap = DeviceCapacity.values()[devCapType];
|
||||
} catch (Exception ex) {
|
||||
cap = DeviceCapacity.CLEANUP;
|
||||
}
|
||||
|
||||
if (cap == null) {
|
||||
cap = DeviceCapacity.CLEANUP;
|
||||
}
|
||||
|
||||
return disposeNodeManager.getDisposeDevice(disposeIp, cap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load task from database.
|
||||
*/
|
||||
@Override
|
||||
public void loadTaskFromDatabase() {
|
||||
// 从数据库中取出所有任务
|
||||
List<TaskInfoDetail> taskList = disposeTaskMapper.selectAll().stream()
|
||||
.filter(this::taskIsRunning)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
taskList.forEach(v -> {
|
||||
v.setRetryTimes(0);
|
||||
if (taskCacheManager.addTask(v) != ErrorCode.ERR_OK) {
|
||||
try {
|
||||
log.error("load error:\n" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create task m return type.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the m return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> createTask(TaskInfoDetail task) {
|
||||
List<DisposeDevice> disposeDevice = new ArrayList<>();
|
||||
Long taskId = task.getDeviceId();
|
||||
|
||||
// 首先查找有没有能处置这个ip的能力节点
|
||||
// 没有指定处置能力节点的情况
|
||||
if (taskId == null || taskId < 0) {
|
||||
disposeDevice = getDisposeNode(task.getDisposeIp(), task.getType());
|
||||
task.setDeviceId(-1L);
|
||||
} else { // 指定了处置能力节点的情况
|
||||
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(taskId);
|
||||
if (dev != null) {
|
||||
disposeDevice.add(dev);
|
||||
task.setDeviceId(dev.getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (disposeDevice.size() == 0) {
|
||||
log.error("No such device to dispose this task: devId:{}, disposeIp:{}, type:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
return MulReturnType.<ErrorCode, Long>builder()
|
||||
.firstParam(ErrorCode.ERR_NOSUCHDEVICE)
|
||||
.secondParam(-1L)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 查询当前是否有相同能力节点,相同用户,相同处置IP的且正在执行的处置任务,如果存在则忽略该次任务(依照产品需求)
|
||||
List<TaskInfoDetail> taskList = taskCacheManager.getAllRunningTask()
|
||||
.stream()
|
||||
.filter(v -> ((taskId == null || taskId == -1L) || Objects.equals(v.getDeviceId(), task.getDeviceId()) ||(v.getDeviceId() == -1L) )
|
||||
&& Objects.equals(v.getAccountId(), task.getAccountId())
|
||||
&& taskIsRunning(v)
|
||||
&& Objects.equals(v.getType(), task.getType())
|
||||
&& Objects.equals(v.getDisposeIp(), task.getDisposeIp()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
log.error("Same dispose task is running: devId:{}, disposeIp:{}, type:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
return MulReturnType.<ErrorCode, Long>builder()
|
||||
.firstParam(ErrorCode.ERR_TASKRUNNING)
|
||||
.secondParam(taskList.get(0).getId())
|
||||
.build();
|
||||
}
|
||||
|
||||
// 将该任务写入数据库和缓存,等到定时任务真正启动该任务
|
||||
disposeTaskMapper.addNewTask(task);
|
||||
|
||||
task.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
TaskInfoDetail cacheTask = disposeTaskMapper.getTaskById(task.getId());
|
||||
|
||||
ErrorCode err = taskCacheManager.addTask(cacheTask);
|
||||
|
||||
log.info("Create new dispose task: devId:{}, disposeIp:{}, type:{}, result:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType(), err.getMsg());
|
||||
|
||||
return MulReturnType.<ErrorCode, Long>builder().firstParam(err).secondParam(task.getId()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode startTask(Long taskId) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
// 从缓存中根据任务id取回需要启动的任务的详细信息
|
||||
TaskInfoDetail task = taskCacheManager.getTaskById(taskId);
|
||||
|
||||
if (task == null) {
|
||||
log.error("No such task: taskId:{}", taskId);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
long planDuration = Helper.getTimestampDiff(task.getCreateTime(), task.getPlanEndTime()) / 60;
|
||||
|
||||
List<DisposeDevice> dev = getDisposeNode(task.getDisposeIp(), task.getType());
|
||||
|
||||
// 判断是否有支持处置该IP的能力
|
||||
if (dev.size() == 0) {
|
||||
log.info("No dispose device handle: disposeIp:{}, devCapType:{}", task.getDisposeIp(), task.getType());
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
// 对新建的任务执行启动操作
|
||||
if (task.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode()) {
|
||||
// 更新任务状态为进行中
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
|
||||
dev.forEach(k -> {
|
||||
DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(k.getType(), k.getIpAddr());
|
||||
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> dp.runDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()], planDuration))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
log.error("Start task: taskId:{}, error:{}", taskId, ex.getMessage());
|
||||
// 增加设备执行清洗任务信息
|
||||
taskInfoMapper.addNewTaskInfo(taskId, k.getId(), null,
|
||||
(long) ErrorCode.ERR_SYSTEMEXCEPTION.getCode());
|
||||
} else {
|
||||
if (v.getFirstParam() != ErrorCode.ERR_OK) {
|
||||
// 执行任务失败恢复缓存中的任务状态
|
||||
taskInfoMapper.addNewTaskInfo(taskId, k.getId(), null, (long) v.getFirstParam().getCode());
|
||||
log.error("Start task: taskId:{}, disposeIp:{}, error:{}",
|
||||
taskId, task.getDisposeIp(), v.getFirstParam().getMsg());
|
||||
} else {
|
||||
// 执行任务成功
|
||||
taskInfoMapper.addNewTaskInfo(taskId, k.getId(), v.getSecondParam(), (long) v.getFirstParam().getCode());
|
||||
log.info("Start task finished: taskId:{}, disposeId:{}, type:{}",
|
||||
taskId, task.getDisposeIp(), task.getType());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode stopTask(Long taskId) {
|
||||
TaskInfoDetail task = taskCacheManager.getTaskById(taskId);
|
||||
|
||||
if (task != null) {
|
||||
List<DisposeDevice> dev = getDisposeNode(task.getDisposeIp(), task.getType());
|
||||
|
||||
// 判断是否有支持处置该IP的能力
|
||||
if (dev.size() == 0) {
|
||||
log.info("No dispose device handle: disposeIp:{}, devCapType:{}", task.getDisposeIp(), task.getType());
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
int prdStatus = task.getCurrentStatus();
|
||||
|
||||
ErrorCode err = taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_STOP.getCode());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Failed to update task status, currentStatus:{}", task.getCurrentStatus());
|
||||
return err;
|
||||
}
|
||||
|
||||
dev.forEach(k -> {
|
||||
DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(k.getType(), k.getIpAddr());
|
||||
|
||||
TaskInfo taskInfo = taskInfoMapper.getTaskInfo(taskId, k.getId());
|
||||
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> dp.stopDispose(task.getDisposeIp(),
|
||||
DeviceCapacity.values()[task.getType()],
|
||||
(taskInfo == null || taskInfo.getExternId() == null) ? -1 : taskInfo.getExternId()))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
// 恢复缓存中任务状态到先前状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, prdStatus);
|
||||
log.error("Stop task: taskId:{}, error:{}", taskId, ex.getMessage());
|
||||
} else {
|
||||
if (v.getFirstParam() != ErrorCode.ERR_OK) {
|
||||
// 恢复缓存中任务状态到先前状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, prdStatus);
|
||||
log.error("Stop task: taskId:{}, error:{}", taskId, v.getFirstParam().getMsg());
|
||||
} else {
|
||||
// 任务执行完成后更新数据库处置任务状态
|
||||
finishTask(taskId);
|
||||
log.info("Stop task finished: taskId:{}, disposeId:{}, type:{}",
|
||||
taskId, task.getDisposeIp(), task.getType());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
log.error("No such task: taskId:{}", taskId);
|
||||
return ErrorCode.ERR_NOSUCHTASK;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode finishTask(Long taskId) {
|
||||
// 设置缓存任务状态为完成状态
|
||||
ErrorCode err = taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
// 设置数据库任务状态为完成状态
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
Integer currentStatus = disposeTaskMapper.getTaskById(taskId).getCurrentStatus();
|
||||
log.info("taskId:{}, currentStatus:{}", taskId, currentStatus);
|
||||
// 移除缓存中的任务信息
|
||||
taskCacheManager.removeTask(taskId);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task is running boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean taskIsRunning(TaskInfoDetail task) {
|
||||
return task.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()
|
||||
|| task.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Task is expired boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean taskIsExpired(TaskInfoDetail task) {
|
||||
return LocalDateTime.parse(task.getPlanEndTime(),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
.isBefore(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets node all running task.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @return the node all running task
|
||||
*/
|
||||
@Override
|
||||
public List<TaskInfoDetail> getNodeAllRunningTask(Long devId) {
|
||||
List<TaskInfoDetail> taskList = taskCacheManager
|
||||
.getAllRunningTask()
|
||||
.stream()
|
||||
.filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()
|
||||
&& (v.getDeviceId().equals(devId)) || v.getDeviceId() == -1L)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
log.info("The device has tasks running: devId:{}, tasksRunningNumber:{}", devId, taskList.size());
|
||||
return taskList;
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets node all task.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @return the node all task
|
||||
*/
|
||||
@Override
|
||||
public List<TaskInfoDetail> getNodeAllTask(Long devId) {
|
||||
List<TaskInfoDetail> taskList = new ArrayList<>();
|
||||
|
||||
//-1广播,所有设备都下发清洗任务
|
||||
List<TaskInfoDetail> curId = disposeTaskMapper.getAllTaskByNodeDevId(devId);
|
||||
List<TaskInfoDetail> allId = disposeTaskMapper.getAllTaskByNodeDevId(-1L);
|
||||
|
||||
if(allId != null && allId.size() > 0) {
|
||||
taskList.addAll(allId);
|
||||
}
|
||||
|
||||
if(curId != null && curId.size() > 0) {
|
||||
taskList.addAll(curId);
|
||||
}
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
log.info("The device has tasks: devId:{}, tasksNumber:{}", devId, taskList.size());
|
||||
} else {
|
||||
log.info("The device has nothing tasks: devId:{}", devId);
|
||||
}
|
||||
|
||||
return taskList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all task.
|
||||
*
|
||||
* @return the all task
|
||||
*/
|
||||
@Override
|
||||
public List<TaskInfoDetail> getAllTask() {
|
||||
List<TaskInfoDetail> taskList = disposeTaskMapper.selectAll();
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
return taskList;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets active task.
|
||||
*
|
||||
* @return the active task
|
||||
*/
|
||||
@Override
|
||||
public List<TaskInfoDetail> getActiveTask() {
|
||||
List<TaskInfoDetail> taskList = taskCacheManager.getAllRunningTask();
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
return taskList;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop task by task id list.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the list
|
||||
*/
|
||||
@Override
|
||||
public List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByTaskId(Long taskId) {
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> retList = new ArrayList<>();
|
||||
|
||||
// 根据处置IP,拿出所有正在处置的任务
|
||||
List<TaskInfoDetail> taskList = taskCacheManager.getAllRunningTask().stream()
|
||||
.filter(v -> (Objects.equals(v.getId(), taskId))
|
||||
&& taskIsRunning(v))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 对符合条件的任务调用停止命令
|
||||
taskList.forEach(v -> {
|
||||
ErrorCode err = stopTask(v.getId());
|
||||
retList.add(new MulReturnType<>(err, v));
|
||||
});
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task is exists boolean.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param userId the user id
|
||||
* @param disposeIp the dispose ip
|
||||
* @param disposeType the dispose type
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean taskIsExists(Long devId, Long userId, String disposeIp, int disposeType) {
|
||||
return taskCacheManager.getAllRunningTask().stream()
|
||||
.anyMatch(v -> Objects.equals(v.getAccountId(), userId)
|
||||
&& Objects.equals(v.getDeviceId(), devId)
|
||||
&& Objects.equals(v.getDisposeIp(), disposeIp)
|
||||
&& Objects.equals(v.getType(), disposeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop task by dispose ip list.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param type the type
|
||||
* @param ipAddr the ip addr
|
||||
* @return the list
|
||||
*/
|
||||
@Override
|
||||
public List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByDisposeIp(Long devId, int type, String ipAddr) {
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> retList = new ArrayList<>();
|
||||
|
||||
// 根据处置IP,拿出所有正在处置的任务
|
||||
List<TaskInfoDetail> taskList = taskCacheManager.getAllRunningTask().stream()
|
||||
.filter(v -> (Objects.equals(v.getDeviceId(), devId))
|
||||
&& (Objects.equals(v.getType(), type) || type == DeviceCapacity.ALLCAPACITY.getCode())
|
||||
&& Objects.equals(v.getDisposeIp(), ipAddr)
|
||||
&& taskIsRunning(v))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 对符合条件的任务调用停止命令
|
||||
taskList.forEach(v -> {
|
||||
ErrorCode err = stopTask(v.getId());
|
||||
retList.add(new MulReturnType<>(err, v));
|
||||
});
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop task by dispose node list.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param type the type
|
||||
* @return the list
|
||||
*/
|
||||
@Override
|
||||
public List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByDisposeNode(Long devId, int type) {
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> retList = new ArrayList<>();
|
||||
|
||||
// 根据处置IP,拿出所有正在处置的任务
|
||||
List<TaskInfoDetail> taskList = taskCacheManager.getAllRunningTask().stream()
|
||||
.filter(v -> ((devId == -1L) || Objects.equals(v.getDeviceId(), devId))
|
||||
&& (Objects.equals(v.getType(), type) || type == DeviceCapacity.ALLCAPACITY.getCode())
|
||||
&& taskIsRunning(v))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 对符合条件的任务调用停止命令
|
||||
taskList.forEach(v -> {
|
||||
ErrorCode err = stopTask(v.getId());
|
||||
retList.add(new MulReturnType<>(err, v));
|
||||
});
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop task by type list.
|
||||
*
|
||||
* @param type the type
|
||||
* @return the list
|
||||
*/
|
||||
@Override
|
||||
public List<MulReturnType<ErrorCode, TaskInfoDetail>> stopTaskByType(int type) {
|
||||
List<MulReturnType<ErrorCode, TaskInfoDetail>> retList = new ArrayList<>();
|
||||
|
||||
// 根据处置IP,拿出所有正在处置的任务
|
||||
List<TaskInfoDetail> taskList = taskCacheManager.getAllRunningTask().stream()
|
||||
.filter(v -> (Objects.equals(v.getType(), type) || type == DeviceCapacity.ALLCAPACITY.getCode())
|
||||
&& taskIsRunning(v))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 对符合条件的任务调用停止命令
|
||||
taskList.forEach(v -> {
|
||||
ErrorCode err = stopTask(v.getId());
|
||||
retList.add(new MulReturnType<>(err, v));
|
||||
});
|
||||
|
||||
return retList;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package com.dispose.swagger;
|
||||
|
||||
import com.dispose.config.MyConfig;
|
||||
import com.google.common.base.Predicates;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* The type Swagger 2 config.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
|
||||
@Resource
|
||||
private MyConfig myConfig;
|
||||
|
||||
/**
|
||||
* Api docket.
|
||||
*
|
||||
* @return the docket
|
||||
*/
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).enable(Boolean.parseBoolean(myConfig.getSwaggerSwitch()))
|
||||
.select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any())
|
||||
// 错误路径不监控
|
||||
.paths(Predicates.not(PathSelectors.regex("/error.*")))
|
||||
// 对根下所有路径进行监控
|
||||
.paths(PathSelectors.regex("/.*"))
|
||||
.build().apiInfo(apiInfo());
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfo(
|
||||
"phoenix脚手架工程API示例", "展示所有API信息,方便测试", "API V1.0", "xxx", new Contact("phoenix",
|
||||
"http://git.komect.net/WLFHCZ/phoenix_share_framework.git", "phoenix@cmhi.chinamobile.com"),
|
||||
"CMCC.HY", "", Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.dispose.task;
|
||||
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Device manager task.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
public class DeviceManagerTask {
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
/**
|
||||
* Thread pool task.
|
||||
*/
|
||||
@Async("bizExecutor")
|
||||
@Scheduled(cron = "0/30 * * * * ?")
|
||||
public void threadPoolTask() {
|
||||
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
|
||||
|
||||
devList.forEach(v -> {
|
||||
DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(v.getType(), v.getIpAddr());
|
||||
// 自动更新设备心跳状态
|
||||
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
||||
// 自动读取设备系统版本信息
|
||||
v.setVersion(dp.getVersion());
|
||||
// 自动更新系统信息
|
||||
v.setDevInfo(dp.getDeviceInfo());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package com.dispose.task;
|
||||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.service.TaskService;
|
||||
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.Resource;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* The type Task manager task.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TaskManagerTask {
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
/**
|
||||
* Task runtime manager.
|
||||
*/
|
||||
@Async("bizExecutor")
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
public void taskRuntimeManager() {
|
||||
Iterator<TaskInfoDetail> it = taskService.getActiveTask().iterator();
|
||||
|
||||
// 由于可能删除列表中的项目,所以使用迭代器
|
||||
while (it.hasNext()) {
|
||||
TaskInfoDetail taskData = it.next();
|
||||
|
||||
// 判断是否存在正在运行的过期的任务,如果存在则结束该任务
|
||||
if(taskService.taskIsExpired(taskData) && taskService.taskIsRunning(taskData)) {
|
||||
log.info("Finish expired task {}:{} begin at {}",
|
||||
taskData.getId(), taskData.getDisposeIp(), taskData.getCreateTime());
|
||||
taskService.stopTask(taskData.getId());
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果重试次数过多,停止处理该任务
|
||||
if(taskData.getRetryTimes() > GlobalVar.TASK_ERROR_MAX_RETRY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断是否有新建任务,如果有的话启动新建的处置任务
|
||||
if (taskData.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode()) {
|
||||
log.info("Start task {}:{} of {}",
|
||||
taskData.getId(), taskData.getDisposeIp(), taskData.getCreateTime());
|
||||
if (taskService.startTask(taskData.getId()) != ErrorCode.ERR_OK) {
|
||||
taskData.setRetryTimes(taskData.getRetryTimes() + 1);
|
||||
log.error("startTask Task {}:{} error\n", taskData.getId(), taskData.getDisposeIp());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
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 {
|
||||
|
||||
/**
|
||||
* Log executor executor.
|
||||
*
|
||||
* @return the executor
|
||||
*/
|
||||
@Bean
|
||||
public Executor logExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setThreadNamePrefix("myLog-");
|
||||
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() << 1 + 1);
|
||||
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
-- ----------------------------
|
||||
-- Records of dispose_device
|
||||
-- ----------------------------
|
||||
INSERT INTO `dispose_device` VALUES (1, '10.88.77.88:18080', 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0);
|
||||
INSERT INTO `dispose_device` VALUES (2, '10.88.77.15', 0, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', 'B5.2.27.7', 'admin', 'UMCAdministrator', 'http://%s/UMC/service/AbnormalFlowCleaningService', '实验室测试设备', 0);
|
||||
INSERT INTO `dispose_device` VALUES (1, '10.88.77.88:18080', 1, 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0);
|
||||
INSERT INTO `dispose_device` VALUES (2, '10.88.77.15', 0, 1, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', 'B5.2.27.7', 'admin', 'UMCAdministrator', 'http://%s/UMC/service/AbnormalFlowCleaningService', '实验室测试设备', 0);
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
|
|
|
@ -15,26 +15,23 @@ SET NAMES utf8mb4;
|
|||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for dispose_device
|
||||
-- Table structure for task_info
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `dispose_device`;
|
||||
CREATE TABLE `dispose_device`
|
||||
DROP TABLE IF EXISTS `task_info`;
|
||||
CREATE TABLE `task_info`
|
||||
(
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符',
|
||||
`ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备IP地址, IPv4/IPv6',
|
||||
`type` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备',
|
||||
`areaCode` int(11) NULL DEFAULT NULL COMMENT '设备物理位置区域码',
|
||||
`name` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称',
|
||||
`manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商',
|
||||
`model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号',
|
||||
`version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本',
|
||||
`userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名',
|
||||
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码',
|
||||
`url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL类型',
|
||||
`readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常, 1:删除',
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符',
|
||||
`taskId` int(10) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符',
|
||||
`deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符',
|
||||
`beginTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '任务开始时间',
|
||||
`endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间',
|
||||
`externId` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '扩展ID(供浩瀚处置任务使用)',
|
||||
`status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `ipAddr` (`ipAddr`) USING BTREE
|
||||
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
|
||||
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,
|
||||
CONSTRAINT `task_info_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT,
|
||||
CONSTRAINT `task_info_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
CHARACTER SET = utf8
|
||||
|
@ -70,23 +67,26 @@ CREATE TABLE `dispose_task`
|
|||
ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for task_info
|
||||
-- Table structure for dispose_device
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `task_info`;
|
||||
CREATE TABLE `task_info`
|
||||
DROP TABLE IF EXISTS `dispose_device`;
|
||||
CREATE TABLE `dispose_device`
|
||||
(
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符',
|
||||
`taskId` int(10) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符',
|
||||
`deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符',
|
||||
`beginTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '任务开始时间',
|
||||
`endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间',
|
||||
`externId` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '扩展ID(供浩瀚处置任务使用)',
|
||||
`status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态',
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符',
|
||||
`ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备IP地址, IPv4/IPv6',
|
||||
`type` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备',
|
||||
`areaCode` int(11) NULL DEFAULT NULL COMMENT '设备物理位置区域码',
|
||||
`name` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称',
|
||||
`manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商',
|
||||
`model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号',
|
||||
`version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本',
|
||||
`userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名',
|
||||
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码',
|
||||
`url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL类型',
|
||||
`readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常, 1:删除',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
|
||||
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,
|
||||
CONSTRAINT `task_info_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT,
|
||||
CONSTRAINT `task_info_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT
|
||||
UNIQUE INDEX `ipAddr` (`ipAddr`) USING BTREE
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
CHARACTER SET = utf8
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.DisposeDeviceMapper">
|
||||
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id" parameterType="com.dispose.pojo.entity.DisposeDevice">
|
||||
INSERT IGNORE INTO
|
||||
dispose_device(ipAddr, type,
|
||||
areaCode, name, manufacturer,
|
||||
model, version, userName, password, url, readme, status)
|
||||
VALUES
|
||||
(#{ipAddr}, #{type},
|
||||
#{areaCode}, #{name}, #{manufacturer},
|
||||
#{model}, #{version}, #{userName}, #{password}, #{url}, #{readme}, 0)
|
||||
</insert>
|
||||
|
||||
<select id="getDeviceByIp" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.String">
|
||||
SELECT * FROM dispose_device
|
||||
WHERE
|
||||
ipAddr = #{ipAddr}
|
||||
</select>
|
||||
|
||||
<select id="getDeviceById" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.Long">
|
||||
SELECT * FROM dispose_device
|
||||
WHERE
|
||||
id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="isDeviceExistsByIp" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM dispose_device
|
||||
WHERE
|
||||
ipAddr = #{ipAddr}
|
||||
</select>
|
||||
<select id="isDeviceExistsById" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM dispose_device
|
||||
WHERE
|
||||
id = #{id}
|
||||
</select>
|
||||
<delete id="delDisposeDeviceByIp" parameterType="java.lang.String">
|
||||
DELETE
|
||||
dispose_device
|
||||
FROM
|
||||
dispose_device
|
||||
WHERE
|
||||
dispose_device.ipAddr = #{ipAddr}
|
||||
</delete>
|
||||
</mapper>
|
|
@ -1,99 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.DisposeTaskMapper">
|
||||
<insert id="addNewTask" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
INSERT IGNORE INTO dispose_task(deviceId, accountId, type, disposeIp,
|
||||
planEndTime, flowDirection, attackType, flowBandWidth,
|
||||
currentStatus)
|
||||
VALUES (#{deviceId}, #{accountId}, #{type}, #{disposeIp},
|
||||
date_add(now(), interval #{planEndTime} MINUTE), #{flowDirection}, #{attackType},
|
||||
#{flowBandWidth}, #{currentStatus})
|
||||
</insert>
|
||||
|
||||
<delete id="removeTaskById" parameterType="java.lang.Long">
|
||||
DELETE
|
||||
dispose_task
|
||||
FROM dispose_task
|
||||
WHERE dispose_task.id = #{id}
|
||||
</delete>
|
||||
|
||||
<update id="changeTaskCurrentStatus">
|
||||
UPDATE
|
||||
dispose_task
|
||||
SET
|
||||
currentStatus = #{status, jdbcType=INTEGER}
|
||||
<if test="status != @com.dispose.common.DisposeTaskStatus@TASK_NEW.getCode()
|
||||
and status != @com.dispose.common.DisposeTaskStatus@TASK_RUNNING.getCode()">
|
||||
, endTime = CURRENT_TIMESTAMP
|
||||
</if>
|
||||
WHERE
|
||||
id = #{id, jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<select id="getTaskCurrentStatus" resultType="java.lang.Integer">
|
||||
SELECT currentStatus
|
||||
FROM dispose_task
|
||||
WHERE id = #{id, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getTaskById" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE id = #{id, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getAllTaskByDisposeIp" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE disposeIp = #{ipAddr, jdbcType=VARCHAR}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||
</select>
|
||||
|
||||
<select id="getAllTaskByNodeDevId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE deviceId = #{devId, jdbcType=INTEGER}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||
</select>
|
||||
|
||||
<select id="getNodeAllTaskByUserId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE accountId = #{userId, jdbcType=INTEGER}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||
</select>
|
||||
|
||||
<select id="getNodeTaskByIpAndStatus" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE deviceId = #{devId, jdbcType=INTEGER}
|
||||
AND disposeIp = #{ipAddr, jdbcType=VARCHAR}
|
||||
AND currentStatus = #{status, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getAllTaskByStatus" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE currentStatus = #{status, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getTaskByTaskDetail" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE deviceId = #{devId, jdbcType=INTEGER}
|
||||
AND accountId = #{userId, jdbcType=INTEGER}
|
||||
AND disposeIp = #{ipAddr, jdbcType=VARCHAR}
|
||||
AND type = #{type, jdbcType=INTEGER}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_FINISH.getCode()}
|
||||
</select>
|
||||
|
||||
<select id="getAllTaskByType" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE type = #{type, jdbcType=INTEGER}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -1,44 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.TaskInfoMapper">
|
||||
<insert id="addNewTaskInfo">
|
||||
INSERT IGNORE INTO task_info(taskId, deviceId, externId, status)
|
||||
VALUES (#{taskId}, #{deviceId}, #{externId}, #{status})
|
||||
</insert>
|
||||
|
||||
<select id="getTaskInfo" resultType="com.dispose.pojo.vo.common.TaskInfo">
|
||||
SELECT *
|
||||
FROM task_info
|
||||
WHERE taskId = #{taskId, jdbcType=INTEGER}
|
||||
AND deviceId = #{deviceId, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getTaskInfoByTaskId" resultType="com.dispose.pojo.vo.common.TaskInfo">
|
||||
SELECT *
|
||||
FROM task_info
|
||||
WHERE taskId = #{taskId, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<update id="changeTaskInfoStatus">
|
||||
UPDATE
|
||||
task_info
|
||||
SET
|
||||
status = #{status, jdbcType=INTEGER}
|
||||
WHERE
|
||||
id = #{id, jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<select id="getTaskInfoCurrentStatus" resultType="java.lang.Integer">
|
||||
SELECT status
|
||||
FROM task_info
|
||||
WHERE id = #{id, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<delete id="removeTaskInfoById" parameterType="java.lang.Long">
|
||||
DELETE
|
||||
task_info
|
||||
FROM task_info
|
||||
WHERE task_info.deviceId = #{deviceId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
|
@ -1,160 +0,0 @@
|
|||
package com.dispose.test.Global;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* The type Init test environment.
|
||||
*/
|
||||
@Slf4j
|
||||
@Getter
|
||||
@ActiveProfiles("test")
|
||||
public class InitTestEnvironment {
|
||||
/**
|
||||
* The connect timeout.
|
||||
*/
|
||||
public static final int HTTP_CONNECT_TIMEOUT = 10000;
|
||||
/**
|
||||
* The constant logToken.
|
||||
*/
|
||||
private static String logToken = "45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122";
|
||||
/**
|
||||
* The User name.
|
||||
*/
|
||||
private final String USER_NAME = "admin";
|
||||
/**
|
||||
* The Password.
|
||||
*/
|
||||
private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58";
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
/**
|
||||
* Init virtual device.
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void initVirtualDevice() {
|
||||
GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true;
|
||||
GlobalVar.IS_CHECK_REQUEST_TIMEOUT = true;
|
||||
|
||||
log.warn("Current Used Virtual Dispose Device");
|
||||
}
|
||||
|
||||
/**
|
||||
* User login.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Before
|
||||
public void userLogin() throws Exception {
|
||||
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD());
|
||||
|
||||
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK);
|
||||
logToken = ret.getSecondParam();
|
||||
|
||||
Assert.assertNotNull(logToken);
|
||||
Assert.assertNotEquals(logToken.length(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets log token.
|
||||
*
|
||||
* @return the log token
|
||||
*/
|
||||
public String getLogToken() {
|
||||
return logToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify resp string.
|
||||
*
|
||||
* @param resp the resp
|
||||
* @return the string
|
||||
*/
|
||||
public String verifyResp(String resp) {
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ProtocolRespDTO rspInfo = objectMapper.readValue(resp, ProtocolRespDTO.class);
|
||||
|
||||
// 校验版本
|
||||
if (rspInfo.getVer() < ConstValue.Protocol.VERSION) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
// 校验时间错
|
||||
if (GlobalVar.IS_CHECK_REQUEST_TIMEOUT
|
||||
&& Math.abs(System.currentTimeMillis() - rspInfo.getTimeStamp()) >= ConstValue.Protocol.REQUEST_TIMEOUT_MS) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
return rspInfo.getMsgContent();
|
||||
} catch (Exception ex) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
Assert.fail();
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check response body.
|
||||
*
|
||||
* @param data the data
|
||||
* @param reqTime the req time
|
||||
* @return the string
|
||||
* @throws JSONException the json exception
|
||||
*/
|
||||
public String verifyRep(String data, Long reqTime) throws JSONException {
|
||||
Long verValue = 2L;
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
JSONObject jsonObject = new JSONObject(data);
|
||||
Iterator<String> it = jsonObject.keys();
|
||||
System.out.println();
|
||||
while (it.hasNext()) {
|
||||
// 获得key
|
||||
String key = it.next();
|
||||
String value = jsonObject.getString(key);
|
||||
System.out.println("key: " + key + ",value:" + value);
|
||||
}
|
||||
|
||||
Long repTime = Long.valueOf(jsonObject.getString("timeStamp"));
|
||||
if ((jsonObject.getString("timeStamp").length() == 0) || (repTime - reqTime) > HTTP_CONNECT_TIMEOUT) {
|
||||
err = ErrorCode.ERR_REQTIMEOUT;
|
||||
}
|
||||
Assert.assertEquals(err, ErrorCode.ERR_OK);
|
||||
|
||||
Long ver = Long.valueOf(jsonObject.getString("ver"));
|
||||
if ((jsonObject.getString("ver").length() == 0) || (!ver.equals(verValue))) {
|
||||
err = ErrorCode.ERR_VERSION;
|
||||
}
|
||||
Assert.assertEquals(err, ErrorCode.ERR_OK);
|
||||
|
||||
long cryptoType = Long.parseLong(jsonObject.getString("cryptoType"));
|
||||
if ((String.valueOf(cryptoType).length() == 0) || (cryptoType < 0)) {
|
||||
err = ErrorCode.ERR_INPUTMISS;
|
||||
}
|
||||
Assert.assertEquals(err, ErrorCode.ERR_OK);
|
||||
|
||||
return jsonObject.getString("msgContent");
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.dispose.test.TestSuit;
|
||||
|
||||
|
||||
import com.dispose.test.config.DisposeConfigureTest;
|
||||
import com.dispose.test.config.MyConfigTest;
|
||||
import com.dispose.test.controller.AuthControllerTest;
|
||||
import com.dispose.test.controller.DeviceNodeInfoControllerTest;
|
||||
import com.dispose.test.controller.DeviceNodeManagerControllerTest;
|
||||
import com.dispose.test.controller.TaskControllerTest;
|
||||
import com.dispose.test.dptech.DPTechInterfaceTestCase;
|
||||
import com.dispose.test.manager.UserAccountManagerTest;
|
||||
import com.dispose.test.mapper.DisposeDeviceMapperTest;
|
||||
import com.dispose.test.mapper.DisposeTaskMapperTest;
|
||||
import com.dispose.test.mapper.UserAccountMapperTest;
|
||||
import com.dispose.test.service.DisposeNodeManagerTest;
|
||||
import com.dispose.test.service.TaskServiceTest;
|
||||
import com.dispose.test.service.UserAccountServiceTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
/**
|
||||
* The type All dispose platform test.
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
// MyConfigTest.class,
|
||||
// TaskServiceTest.class,
|
||||
// DisposeConfigureTest.class,
|
||||
// DisposeTaskMapperTest.class,
|
||||
// DisposeNodeManagerTest.class,
|
||||
// DPTechInterfaceTestCase.class,
|
||||
// UserAccountMapperTest.class,
|
||||
// UserAccountManagerTest.class,
|
||||
// DisposeDeviceMapperTest.class,
|
||||
// AuthControllerTest.class,
|
||||
// DeviceNodeManagerControllerTest.class,
|
||||
// DeviceNodeInfoControllerTest.class,
|
||||
// UserAccountServiceTest.class,
|
||||
// TaskControllerTest.class
|
||||
})
|
||||
|
||||
public class AllDisposePlatformTest {
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.dispose.test.TestSuit;
|
||||
|
||||
import com.dispose.test.controller.AuthControllerQATest;
|
||||
import com.dispose.test.controller.AuthControllerSmokeTest;
|
||||
import com.dispose.test.controller.DeviceNodeInfoControllerQATest;
|
||||
import com.dispose.test.controller.DeviceNodeInfoControllerSmokeTest;
|
||||
import com.dispose.test.controller.DeviceNodeManagerControllerQATest;
|
||||
import com.dispose.test.controller.DeviceNodeManagerControllerSmokeTest;
|
||||
import com.dispose.test.controller.TaskControllerQATest;
|
||||
import com.dispose.test.controller.TaskControllerSmokeTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
// AuthControllerQATest.class,
|
||||
// AuthControllerSmokeTest.class,
|
||||
// DeviceNodeManagerControllerQATest.class,
|
||||
// DeviceNodeManagerControllerSmokeTest.class,
|
||||
// DeviceNodeInfoControllerQATest.class,
|
||||
// DeviceNodeInfoControllerSmokeTest.class,
|
||||
// TaskControllerQATest.class,
|
||||
// TaskControllerSmokeTest.class
|
||||
})
|
||||
public class QATest {
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.dispose.test.TestSuit;
|
||||
|
||||
import com.dispose.test.controller.AuthControllerSmokeTest;
|
||||
import com.dispose.test.controller.DeviceNodeInfoControllerSmokeTest;
|
||||
import com.dispose.test.controller.DeviceNodeManagerControllerSmokeTest;
|
||||
import com.dispose.test.controller.TaskControllerSmokeTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
/**
|
||||
* The type Smoke test.
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
// AuthControllerSmokeTest.class,
|
||||
// DeviceNodeManagerControllerSmokeTest.class,
|
||||
// DeviceNodeInfoControllerSmokeTest.class,
|
||||
// TaskControllerSmokeTest.class
|
||||
})
|
||||
|
||||
public class SmokeTest {
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package com.dispose.test.config;
|
||||
|
||||
import com.dispose.config.DisposeConfigure;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* The type Dispose configure test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class DisposeConfigureTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Dispose configure.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeConfigure disposeConfigure;
|
||||
|
||||
/**
|
||||
* User login.
|
||||
*/
|
||||
@Override
|
||||
public void userLogin() {
|
||||
}
|
||||
|
||||
/**
|
||||
* T 1 dispose cfg test.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t1_disposeCfgTest() throws JsonProcessingException {
|
||||
Assert.assertNotNull(disposeConfigure);
|
||||
|
||||
log.info(new ObjectMapper().writeValueAsString(disposeConfigure));
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package com.dispose.test.config;
|
||||
|
||||
import com.dispose.config.MyConfig;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* The type My config test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class MyConfigTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The My config.
|
||||
*/
|
||||
@Resource
|
||||
private MyConfig myConfig;
|
||||
|
||||
/**
|
||||
* User login.
|
||||
*/
|
||||
@Override
|
||||
public void userLogin() {
|
||||
}
|
||||
|
||||
/**
|
||||
* T 1 my config test.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t1_myConfigTest() throws JsonProcessingException {
|
||||
Assert.assertNotNull(myConfig);
|
||||
|
||||
log.info(new ObjectMapper().writeValueAsString(myConfig));
|
||||
}
|
||||
}
|
|
@ -1,716 +0,0 @@
|
|||
package com.dispose.test.controller;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.dispose.pojo.vo.auth.LogoutRsp;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* The type Auth controller exception smoke test.
|
||||
*/
|
||||
@AutoConfigureMockMvc
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Slf4j
|
||||
public class AuthControllerQATest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* A 2 ver json exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a1_loginVerJsonExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":" +
|
||||
"\"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3 ver null exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a2_loginVerNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
|
||||
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4 crypto json exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a3_loginCryptoJsonExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":\"timeStamp\":1587604296988,\"msgContent\":\"" +
|
||||
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A 5 crypto null exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a4_loginCryptoNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":null,\"timeStamp\":1587604296988,\"msgContent\":\"" +
|
||||
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A 7 username empty exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a5_loginUsernameEmptyExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
|
||||
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":\\\"\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A 8 username null exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a6_loginUsernameNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
|
||||
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":null}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* B 1 password null exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b1_loginPasswordNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
|
||||
"\"msgContent\":\"{\\\"password\\\":null,\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* B 2 password error exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b2_loginPasswordErrorExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
|
||||
"\"msgContent\":\"{\\\"password\\\":\\\"123456\\\",\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* B 3 password empty exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b3_loginPasswordEmptyExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
|
||||
"\"msgContent\":\"{\\\"password\\\":\\\"\\\",\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* B 4 msg empty exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b4_loginMsgEmptyExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
|
||||
"\"msgContent\":\"\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* B 5 msg null exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b5_loginMsgNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
|
||||
"\"msgContent\":\"null\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* B 6 username type exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b6_loginUsernameIntExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
|
||||
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":1}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* C 1 normal logout test .
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c1_logoutNormalLogoutTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
LogoutRsp rspInfo = objectMapper.readValue(verifyResp(ret), LogoutRsp.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo);
|
||||
Assert.assertNotNull(rspInfo.getUserName());
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* C 2 username type exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c2_logoutUsernameTypeExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":1,\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* C 2 username empty exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c3_logoutUsernameEmptyExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":\\\"\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* C 3 username null exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c4_logoutUsernameNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":null}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* C 5 msg empty exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c5_logoutMsgEmptyExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
/**
|
||||
* C 6 msg null exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c6_logoutMsgNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"null\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
}
|
||||
/**
|
||||
* C 7 ver json exception test .
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c7_logoutVerJsonExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* C 8 ver null exception test .
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c8_logoutVerNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
/**
|
||||
* C 9 crypto json exception test .
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c9_logoutCryptoJsonExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* C 10 crypto null exception test .
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c10_logoutCryptoNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":null,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
/**
|
||||
* C 11 username not exit exception test .
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c11_logoutUsernameNotExitExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
|
||||
"\"msgContent\":\"{\\\"userName\\\":\\\"a\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_USERNOTFOUND.getMsg());
|
||||
}
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
package com.dispose.test.controller;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.dispose.pojo.vo.auth.LoginRsp;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* The type Auth controller smoke test.
|
||||
*/
|
||||
@AutoConfigureMockMvc
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Slf4j
|
||||
public class AuthControllerSmokeTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* A 1 login normal login test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a1_loginNormalLoginTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
|
||||
"\"msgContent\":\"{\\\"password\\\"" +
|
||||
":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
LoginRsp rspInfo = objectMapper.readValue(verifyResp(ret), LoginRsp.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo);
|
||||
Assert.assertNotNull(rspInfo.getUserName());
|
||||
Assert.assertNotNull(rspInfo.getLogTime());
|
||||
Assert.assertNotNull(rspInfo.getToken());
|
||||
Assert.assertNotNull(rspInfo.getExpireTime());
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2 login username as integer exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a2_loginUsernameAsIntegerExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
|
||||
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||
"\\\"userName\\\":\\\"123456\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3 login password empty exception test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a3_loginPasswordEmptyExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
|
||||
"\"msgContent\":\"{\\\"password\\\":\\\"\\\",\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
|
||||
}
|
||||
}
|
|
@ -1,240 +0,0 @@
|
|||
package com.dispose.test.controller;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||
import com.dispose.pojo.vo.auth.LoginReq;
|
||||
import com.dispose.pojo.vo.auth.LoginRsp;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* The type Auth controller test.
|
||||
*/
|
||||
@AutoConfigureMockMvc
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Slf4j
|
||||
public class AuthControllerTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* Login 1.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a1_login() throws Exception {
|
||||
LoginReq logReq = LoginReq.builder()
|
||||
.userName(getUSER_NAME())
|
||||
.password(getPASSWORD())
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ProtocolRespDTO rspInfo = objectMapper.readValue(ret, ProtocolRespDTO.class);
|
||||
LoginRsp logRsp = objectMapper.readValue(rspInfo.getMsgContent(), LoginRsp.class);
|
||||
|
||||
Assert.assertEquals(getLogToken(), logRsp.getToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void a1_loginBadHead() throws Exception {
|
||||
LoginReq logReq = LoginReq.builder()
|
||||
.userName(getUSER_NAME())
|
||||
.password(getPASSWORD())
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(1);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void a1_loginBadUsername() throws Exception {
|
||||
LoginReq logReq = LoginReq.builder()
|
||||
.userName(getUSER_NAME() + "123")
|
||||
.password(getPASSWORD())
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout 2.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b1_logout() throws Exception {
|
||||
LoginReq logReq = LoginReq.builder()
|
||||
.userName("admin")
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout 2.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void b2_logout() throws Exception {
|
||||
LoginReq logReq = LoginReq.builder()
|
||||
.userName("admin2")
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(502))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void b3_logoutBadVersionTest() throws Exception {
|
||||
LoginReq logReq = LoginReq.builder()
|
||||
.userName("admin2")
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(1);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void b4_logoutBadAuthHeadTest() throws Exception {
|
||||
LoginReq logReq = LoginReq.builder()
|
||||
.userName("admin2")
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "" + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,273 +0,0 @@
|
|||
package com.dispose.test.controller;
|
||||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.dispose.pojo.vo.common.TaskInfoData;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.pojo.vo.information.DisposeNodeData;
|
||||
import com.dispose.pojo.vo.information.DisposeNodeListRsp;
|
||||
import com.dispose.pojo.vo.information.NodeTaskData;
|
||||
import com.dispose.pojo.vo.information.NodeTaskRsp;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* The type Device node info controller smoke test.
|
||||
*/
|
||||
@AutoConfigureMockMvc
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
@Slf4j
|
||||
public class DeviceNodeInfoControllerSmokeTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Dispose task mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
|
||||
/**
|
||||
* A 1 get all task normal test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a1_getAllTaskNormalTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/all_task")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo);
|
||||
Assert.assertNotEquals(rspInfo.getItems().size(), 0);
|
||||
|
||||
List<TaskInfoDetail> taskList = disposeTaskMapper.getAllTaskByNodeDevId(1L);
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getItems().get(0).getTaskArray().size()), Long.valueOf(taskList.size()));
|
||||
|
||||
if(taskList.size() > 0) {
|
||||
NodeTaskData taskData = rspInfo.getItems().get(0);
|
||||
|
||||
Assert.assertNotNull(taskData);
|
||||
Assert.assertNotNull(taskData.getId());
|
||||
Assert.assertNotNull(taskData.getStatus());
|
||||
Assert.assertNotNull(taskData.getMessage());
|
||||
|
||||
Assert.assertNotNull(taskData.getStatus());
|
||||
Assert.assertNotNull(taskData.getMessage());
|
||||
Assert.assertEquals(Long.valueOf(taskData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
|
||||
|
||||
TaskInfoData taskInfoData = taskData.getTaskArray().get(0);
|
||||
Assert.assertNotNull(taskInfoData);
|
||||
Assert.assertNotNull(taskInfoData.getTaskId());
|
||||
Assert.assertNotNull(taskInfoData.getCurrentStatus());
|
||||
Assert.assertNotNull(taskInfoData.getType());
|
||||
Assert.assertNotNull(taskInfoData.getStartTime());
|
||||
Assert.assertNotNull(taskInfoData.getDisposeTime());
|
||||
Assert.assertNotNull(taskInfoData.getDisposeIp());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2 get all task id null test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a2_getAllTaskIdNullTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/all_task")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class);
|
||||
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3 get run task normal test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a3_getRunTaskNormalTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/run_task")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class) ;
|
||||
|
||||
Assert.assertNotNull(rspInfo);
|
||||
Assert.assertNotEquals(rspInfo.getItems().size(), 0);
|
||||
|
||||
List<TaskInfoDetail> taskList = disposeTaskMapper.getAllTaskByNodeDevId(1L).stream()
|
||||
.filter(v -> Objects.equals(v.getCurrentStatus(), DisposeTaskStatus.TASK_RUNNING.getCode()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getItems().get(0).getTaskArray().size()), Long.valueOf(taskList.size()));
|
||||
|
||||
if(taskList.size() > 0) {
|
||||
NodeTaskData taskData = rspInfo.getItems().get(0);
|
||||
|
||||
Assert.assertNotNull(taskData);
|
||||
Assert.assertNotNull(taskData.getId());
|
||||
Assert.assertNotNull(taskData.getStatus());
|
||||
Assert.assertNotNull(taskData.getMessage());
|
||||
Assert.assertNotNull(taskData.getStatus());
|
||||
Assert.assertNotNull(taskData.getMessage());
|
||||
Assert.assertEquals(Long.valueOf(taskData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
|
||||
|
||||
TaskInfoData taskInfoData = taskData.getTaskArray().get(0);
|
||||
Assert.assertNotNull(taskInfoData);
|
||||
Assert.assertNotNull(taskInfoData.getTaskId());
|
||||
Assert.assertNotNull(taskInfoData.getType());
|
||||
Assert.assertNotNull(taskInfoData.getStartTime());
|
||||
Assert.assertNotNull(taskInfoData.getDisposeTime());
|
||||
Assert.assertNotNull(taskInfoData.getDisposeIp());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* C 1 get Node Details Normal Test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c1_getNodeDetailsNormalTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/node_details")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class);
|
||||
|
||||
Assert.assertNotNull(rspInfo);
|
||||
Assert.assertNotEquals(rspInfo.getItems().size(), 0);
|
||||
|
||||
//DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(1L);
|
||||
DisposeNodeData dpData = rspInfo.getItems().get(0);
|
||||
|
||||
Assert.assertNotNull(dpData);
|
||||
Assert.assertNotNull(dpData.getId());
|
||||
Assert.assertNotNull(dpData.getStatus());
|
||||
Assert.assertNotNull(dpData.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* C 2 get node details msg content empty test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void c2_getNodeDetailsMsgContentEmptyTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}";
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/node_details")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
// DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class) ;
|
||||
// List<DisposeNodeData> List = rspInfo.getItems();
|
||||
//
|
||||
// for (DisposeNodeData r:List){
|
||||
// Assert.assertNotNull(r.getMessage());
|
||||
// Assert.assertNotNull(r.getStatus());
|
||||
// Assert.assertEquals(Long.valueOf(r.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
// }
|
||||
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class);
|
||||
|
||||
Assert.assertNotNull(rspInfo.getStatus());
|
||||
Assert.assertNotNull(rspInfo.getMessage());
|
||||
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue