parent
7456a9947e
commit
325caf2f9e
|
@ -10,6 +10,7 @@ import com.cmhi.dispose.common.CmhiDisposeStartTaskRsp;
|
||||||
import com.cmhi.dispose.common.CmhiDisposeStopTaskReq;
|
import com.cmhi.dispose.common.CmhiDisposeStopTaskReq;
|
||||||
import com.cmhi.dispose.common.CmhiDisposeStopTaskRsp;
|
import com.cmhi.dispose.common.CmhiDisposeStopTaskRsp;
|
||||||
import com.cmhi.dispose.common.CmhiDisposeTaskStatusRsp;
|
import com.cmhi.dispose.common.CmhiDisposeTaskStatusRsp;
|
||||||
|
import com.dispose.common.CommonEnumHandler;
|
||||||
import com.dispose.common.ErrorCode;
|
import com.dispose.common.ErrorCode;
|
||||||
import com.dispose.pojo.dto.protocol.base.BaseProtocolDTO;
|
import com.dispose.pojo.dto.protocol.base.BaseProtocolDTO;
|
||||||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.cmhi.dispose.common.CmhiDisposeStopTaskRsp;
|
||||||
import com.cmhi.dispose.common.CmhiDisposeTaskStatusRsp;
|
import com.cmhi.dispose.common.CmhiDisposeTaskStatusRsp;
|
||||||
import com.cmhi.dispose.protocol.CmhiDisposeInterface;
|
import com.cmhi.dispose.protocol.CmhiDisposeInterface;
|
||||||
import com.dispose.ability.DisposeAbility;
|
import com.dispose.ability.DisposeAbility;
|
||||||
|
import com.dispose.common.CommonEnumHandler;
|
||||||
import com.dispose.common.DisposeCapacityType;
|
import com.dispose.common.DisposeCapacityType;
|
||||||
import com.dispose.common.DisposeConfigValue;
|
import com.dispose.common.DisposeConfigValue;
|
||||||
import com.dispose.common.DisposeObjectType;
|
import com.dispose.common.DisposeObjectType;
|
||||||
|
@ -156,16 +157,17 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
String url = urlRootPath + "dispose_device/task/start";
|
String url = urlRootPath + "dispose_device/task/start";
|
||||||
|
|
||||||
if (token == null || token.length() == 0) {
|
if (token == null || token.length() == 0) {
|
||||||
|
upgradeToken();
|
||||||
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, "");
|
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("++++Begging PengXin Start Cleanup Task: {}", disposeObject);
|
log.info("++++Begging PengXin Start Cleanup Task: {}", disposeObject);
|
||||||
|
|
||||||
if (capType != DisposeCapacityType.BLACKHOOL) {
|
// if (capType != DisposeCapacityType.BLACKHOOL) {
|
||||||
log.error("----Error PengXin don't support dispose capacity type: {}", capType);
|
// log.error("----Error PengXin don't support dispose capacity type: {}", capType);
|
||||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
// return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 适配处置时间参数, -1为不限制处置时间
|
// 适配处置时间参数, -1为不限制处置时间
|
||||||
if (duration == null || duration < 0) {
|
if (duration == null || duration < 0) {
|
||||||
|
@ -182,14 +184,20 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
|
|
||||||
ProtocolRespDTO<CmhiDisposeStartTaskRsp> rspInfo = restfulInterface.startDisposeTask(url, token, reqItems);
|
ProtocolRespDTO<CmhiDisposeStartTaskRsp> rspInfo = restfulInterface.startDisposeTask(url, token, reqItems);
|
||||||
|
|
||||||
// 判断是否token过期
|
ErrorCode err = verifyInterfaceResp(rspInfo);
|
||||||
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getItems().get(0).getStatus())) {
|
|
||||||
rspInfo = restfulInterface.startDisposeTask(url, token, reqItems);
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
log.error("----Error PengXin start clean {} server return {}", disposeObject, err.getMsg());
|
||||||
|
return new MulReturnType<>(err, disposeObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rspInfo == null || rspInfo.getCode() != ErrorCode.ERR_OK.getHttpCode()) {
|
err = verifyRespStatus(rspInfo.getMsgContent().getItems().get(0).getStatus());
|
||||||
log.error("----Error PengXin start clean {} server return error", disposeObject);
|
|
||||||
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
log.error("----Error PengXin start clean {} server return {}({})", disposeObject,
|
||||||
|
rspInfo.getMsgContent().getItems().get(0).getStatus(),
|
||||||
|
rspInfo.getMsgContent().getItems().get(0).getMessage());
|
||||||
|
return new MulReturnType<>(err, disposeObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
||||||
|
@ -203,7 +211,7 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
|
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("----Finish PengXin Start Cleanup Task: {}", disposeObject);
|
log.info("----Finish PengXin Start Cleanup Task: {}", disposeObject);
|
||||||
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskId());
|
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskId());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -230,6 +238,7 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
String url = urlRootPath + "dispose_device/task/stop";
|
String url = urlRootPath + "dispose_device/task/stop";
|
||||||
|
|
||||||
if (token == null || token.length() == 0) {
|
if (token == null || token.length() == 0) {
|
||||||
|
upgradeToken();
|
||||||
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, null);
|
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,14 +257,17 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
ProtocolRespDTO<CmhiDisposeStopTaskRsp> rspInfo = restfulInterface.stopDisposeTask(url, token,
|
ProtocolRespDTO<CmhiDisposeStopTaskRsp> rspInfo = restfulInterface.stopDisposeTask(url, token,
|
||||||
new String[]{taskId});
|
new String[]{taskId});
|
||||||
|
|
||||||
// 判断是否token过期
|
ErrorCode err = verifyInterfaceResp(rspInfo);
|
||||||
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getItems().get(0).getStatus())) {
|
|
||||||
rspInfo = restfulInterface.stopDisposeTask(url, token, new String[]{taskId});
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
log.error("----Error PengXin start clean {} server return {}", taskId, err.getMsg());
|
||||||
|
return new MulReturnType<>(err, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rspInfo == null || rspInfo.getCode() != ErrorCode.ERR_OK.getHttpCode()) {
|
err = verifyRespStatus(rspInfo.getMsgContent().getItems().get(0).getStatus());
|
||||||
log.error("----Error PengXin stop task{} server return error", taskId);
|
if (err != ErrorCode.ERR_OK) {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null);
|
log.error("----Error PengXin start clean {} server return {}", taskId, err.getMsg());
|
||||||
|
return new MulReturnType<>(err, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
||||||
|
@ -269,7 +281,7 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
|
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("----Finish PengXin Stop Cleanup Task: {}", taskId);
|
log.info("----Finish PengXin Stop Cleanup Task: {}", taskId);
|
||||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -325,8 +337,8 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
* Dev get link status.
|
* Dev get link status.
|
||||||
*/
|
*/
|
||||||
private void devGetLinkStatus() {
|
private void devGetLinkStatus() {
|
||||||
|
String url = urlRootPath + "dispose_device/information/linkstatus";
|
||||||
try {
|
try {
|
||||||
String url = urlRootPath + "dispose_device/information/linkstatus";
|
|
||||||
|
|
||||||
if (token == null || token.length() == 0) {
|
if (token == null || token.length() == 0) {
|
||||||
deviceLinkStatus = false;
|
deviceLinkStatus = false;
|
||||||
|
@ -347,7 +359,7 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error(ex.getMessage());
|
log.error("Exception: {}, {}", url, ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceLinkStatus = false;
|
deviceLinkStatus = false;
|
||||||
|
@ -359,53 +371,53 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
@Override
|
@Override
|
||||||
public void getDisposeDeviceProtectObject() {
|
public void getDisposeDeviceProtectObject() {
|
||||||
|
|
||||||
if (token == null || token.length() == 0) {
|
// if (token == null || token.length() == 0) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
String url = urlRootPath + "dispose_device/information/capacity";
|
// String url = urlRootPath + "dispose_device/information/capacity";
|
||||||
|
//
|
||||||
ProtocolRespDTO<CmhiDisposeAbilityRsp> rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
|
// ProtocolRespDTO<CmhiDisposeAbilityRsp> rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
|
||||||
|
//
|
||||||
// 判断是否token过期
|
// // 判断是否token过期
|
||||||
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getStatus())) {
|
// if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getStatus())) {
|
||||||
rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
|
// rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()
|
// if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()
|
||||||
&& rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
|
// && rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
|
||||||
|
//
|
||||||
rspInfo.getMsgContent().getCapacity().forEach(v -> {
|
// rspInfo.getMsgContent().getCapacity().forEach(v -> {
|
||||||
if (v.getObjectType().equals(DisposeObjectType.DOMAIN.getValue())) {
|
// if (v.getObjectType().equals(DisposeObjectType.DOMAIN.getValue())) {
|
||||||
log.error("Unsupported: {}", v.getObjectType());
|
// log.error("Unsupported: {}", v.getObjectType());
|
||||||
} else if (v.getObjectType().equals(DisposeObjectType.URL.getValue())) {
|
// } else if (v.getObjectType().equals(DisposeObjectType.URL.getValue())) {
|
||||||
log.error("Unsupported: {}", v.getObjectType());
|
// log.error("Unsupported: {}", v.getObjectType());
|
||||||
} else {
|
// } else {
|
||||||
synchronized (this) {
|
// synchronized (this) {
|
||||||
|
//
|
||||||
protectIpV4.clear();
|
// protectIpV4.clear();
|
||||||
protectIpV6.clear();
|
// protectIpV6.clear();
|
||||||
|
//
|
||||||
if (v.getIpType() == null || v.getIpType().equals(IpAddrType.IPV4_IPV6.getValue())) {
|
// if (v.getIpType() == null || v.getIpType().equals(IpAddrType.IPV4_IPV6.getValue())) {
|
||||||
String [] allIpAddr = {null, "0.0.0.0", "0.0.0.0,::"};
|
// String [] allIpAddr = {null, "0.0.0.0", "0.0.0.0,::"};
|
||||||
|
//
|
||||||
if(Arrays.asList(allIpAddr).contains(v.getDisposeIp())) {
|
// if(Arrays.asList(allIpAddr).contains(v.getDisposeIp())) {
|
||||||
protectIpV4.add("");
|
// protectIpV4.add("");
|
||||||
protectIpV6.add("");
|
// protectIpV6.add("");
|
||||||
}
|
// }
|
||||||
} else if (v.getIpType().equals(IpAddrType.IPV4.getValue())) {
|
// } else if (v.getIpType().equals(IpAddrType.IPV4.getValue())) {
|
||||||
protectIpV4.add("");
|
// protectIpV4.add("");
|
||||||
} else if (v.getIpType().equals(IpAddrType.IPV6.getValue())) {
|
// } else if (v.getIpType().equals(IpAddrType.IPV6.getValue())) {
|
||||||
protectIpV6.add("");
|
// protectIpV6.add("");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
} catch (Exception ignored) {
|
// } catch (Exception ignored) {
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -416,34 +428,35 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isCarryProtectIp(String ipAddr) {
|
public boolean isCarryProtectIp(String ipAddr) {
|
||||||
boolean ret = false;
|
return true;
|
||||||
IPAddress addr = new IPAddressString(ipAddr).getAddress();
|
// boolean ret = false;
|
||||||
synchronized (this) {
|
// IPAddress addr = new IPAddressString(ipAddr).getAddress();
|
||||||
if (addr.isIPv4()) {
|
// synchronized (this) {
|
||||||
ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
// if (addr.isIPv4()) {
|
||||||
}
|
// ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
||||||
|
// }
|
||||||
if (addr.isIPv6()) {
|
//
|
||||||
ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
// if (addr.isIPv6()) {
|
||||||
}
|
// ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
if (!ret) {
|
//
|
||||||
// 更新设备防护IP
|
// if (!ret) {
|
||||||
getDisposeDeviceProtectObject();
|
// // 更新设备防护IP
|
||||||
|
// getDisposeDeviceProtectObject();
|
||||||
synchronized (this) {
|
//
|
||||||
if (addr.isIPv4()) {
|
// synchronized (this) {
|
||||||
ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
// if (addr.isIPv4()) {
|
||||||
}
|
// ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
||||||
|
// }
|
||||||
if (addr.isIPv6()) {
|
//
|
||||||
ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
// if (addr.isIPv6()) {
|
||||||
}
|
// ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
return ret;
|
//
|
||||||
|
// return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -455,6 +468,7 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
@Override
|
@Override
|
||||||
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
|
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
|
||||||
if (token == null || token.length() == 0) {
|
if (token == null || token.length() == 0) {
|
||||||
|
upgradeToken();
|
||||||
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, -1L);
|
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,23 +478,25 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
ProtocolRespDTO<CmhiDisposeTaskStatusRsp> rspInfo = restfulInterface.getDeviceTaskStatus(url, token,
|
ProtocolRespDTO<CmhiDisposeTaskStatusRsp> rspInfo = restfulInterface.getDeviceTaskStatus(url, token,
|
||||||
new String[]{taskId});
|
new String[]{taskId});
|
||||||
|
|
||||||
// 判断是否token过期
|
ErrorCode err = verifyInterfaceResp(rspInfo);
|
||||||
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getItems().get(0).getStatus())) {
|
|
||||||
rspInfo = restfulInterface.getDeviceTaskStatus(url, token, new String[]{taskId});
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
log.error("----Error PengXin start clean {} server return {}", taskId, err.getMsg());
|
||||||
|
return new MulReturnType<>(err, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()) {
|
|
||||||
|
|
||||||
int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus();
|
err = verifyRespStatus(rspInfo.getMsgContent().getItems().get(0).getStatus());
|
||||||
if (rspInfo.getMsgContent().getItems().size() == 0 || errCode != ErrorCode.ERR_OK.getCode()) {
|
|
||||||
return new MulReturnType<>(ErrorCode.ERR_NOSUCHTASK, -1L);
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
log.error("----Error PengXin start clean {} server return {}", taskId, err.getMsg());
|
||||||
|
return new MulReturnType<>(err, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MulReturnType<>(ErrorCode.ERR_OK,
|
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
||||||
rspInfo.getMsgContent().getItems().get(0).getTaskStatus());
|
return new MulReturnType<>(ErrorCode.ERR_NOSUCHTASK, -1L);
|
||||||
} else {
|
|
||||||
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, -1L);
|
|
||||||
}
|
}
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskStatus());
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, -1L);
|
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, -1L);
|
||||||
}
|
}
|
||||||
|
@ -490,41 +506,70 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
* Upgrade token.
|
* Upgrade token.
|
||||||
*/
|
*/
|
||||||
private void upgradeToken() {
|
private void upgradeToken() {
|
||||||
|
String url = urlRootPath + "dispose_device/auth/login";
|
||||||
try {
|
try {
|
||||||
String url = urlRootPath + "dispose_device/auth/login";
|
|
||||||
ProtocolRespDTO<CmhiDisposeLoginRsp> logInfo = restfulInterface.login(url, username, password);
|
ProtocolRespDTO<CmhiDisposeLoginRsp> logInfo = restfulInterface.login(url, username, password);
|
||||||
|
|
||||||
if (logInfo != null && logInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
|
if (logInfo != null && logInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
|
||||||
this.token = logInfo.getMsgContent().getToken();
|
this.token = logInfo.getMsgContent().getToken();
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ex) {
|
||||||
|
log.error("Exception: {}, {}", url, ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reLogin.
|
* Verify interface resp error code.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param rspInfo the rsp info
|
||||||
|
* @return the error code
|
||||||
*/
|
*/
|
||||||
private <T> boolean reLogin(ProtocolRespDTO<T> rspInfo, int status) {
|
private <T> ErrorCode verifyInterfaceResp(ProtocolRespDTO<T> rspInfo) {
|
||||||
|
if (rspInfo == null) {
|
||||||
|
return ErrorCode.ERR_PENGXIN_ERROR;
|
||||||
|
} else if (rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) {
|
||||||
|
upgradeToken();
|
||||||
|
return ErrorCode.ERR_TOKENTIMEOUT;
|
||||||
|
} else if (rspInfo.getCode() != HttpServletResponse.SC_OK) {
|
||||||
|
return ErrorCode.ERR_PENGXIN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rspInfo.getMsgContent() == null) {
|
||||||
|
return ErrorCode.ERR_PARAMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ErrorCode.ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify resp status error code.
|
||||||
|
*
|
||||||
|
* @param status the status
|
||||||
|
* @return the error code
|
||||||
|
*/
|
||||||
|
private ErrorCode verifyRespStatus(int status) {
|
||||||
|
if (status == ErrorCode.ERR_LOGOUT.getCode()
|
||||||
|
|| status == ErrorCode.ERR_TOKENTIMEOUT.getCode()
|
||||||
|
|| status == ErrorCode.ERR_TOKENNOTFOUND.getCode()) {
|
||||||
|
upgradeToken();
|
||||||
|
return ErrorCode.ERR_TOKENTIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 判断是否token过期
|
ErrorCode err = CommonEnumHandler.codeOf(ErrorCode.class, status);
|
||||||
if (rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) {
|
|
||||||
// 重新登录获取 token
|
|
||||||
upgradeToken();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rspInfo.getCode() == HttpServletResponse.SC_OK) {
|
if (err == null) {
|
||||||
if (status == ErrorCode.ERR_LOGOUT.getCode() ||
|
return ErrorCode.ERR_CALLDEVICE;
|
||||||
status == ErrorCode.ERR_TOKENTIMEOUT.getCode() ||
|
} else {
|
||||||
status == ErrorCode.ERR_TOKENNOTFOUND.getCode()) {
|
return err;
|
||||||
upgradeToken();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
return false;
|
if (status == ErrorCode.ERR_OK.getCode()) {
|
||||||
|
return ErrorCode.ERR_OK;
|
||||||
|
} else {
|
||||||
|
return ErrorCode.ERR_CALLDEVICE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,17 +578,16 @@ public class CmhiAbilityImpl implements DisposeAbility {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void periodTaskRuntime() {
|
public void periodTaskRuntime() {
|
||||||
log.debug("++++PengXin Period Task Running");
|
// 集团一键处置线上环境,不再定时获取设备能力信息
|
||||||
|
|
||||||
// 更新防护对象
|
// 更新防护对象
|
||||||
getDisposeDeviceProtectObject();
|
//getDisposeDeviceProtectObject();
|
||||||
|
|
||||||
// 更新心跳状态
|
// 更新心跳状态
|
||||||
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
|
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
|
||||||
devGetLinkStatus();
|
devGetLinkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("----PengXin Period Task Running");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
SET
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
FOREIGN_KEY_CHECKS = 0;
|
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for device_task
|
-- Table structure for device_task
|
||||||
|
@ -172,8 +171,7 @@ CREATE TABLE `user_account`
|
||||||
COLLATE = utf8_general_ci
|
COLLATE = utf8_general_ci
|
||||||
ROW_FORMAT = DYNAMIC;
|
ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
SET
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
FOREIGN_KEY_CHECKS = 1;
|
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for msg_serial
|
-- Table structure for msg_serial
|
||||||
|
@ -186,6 +184,7 @@ CREATE TABLE `msg_serial`
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for alarm_information
|
-- Table structure for alarm_information
|
||||||
|
@ -199,3 +198,5 @@ CREATE TABLE `alarm_information`
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package com.dispose.test.dev.debug;
|
package com.dispose.test.dev.debug;
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
=======
|
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
>>>>>>> origin/v2.0.9_dev
|
import com.cmhi.dispose.common.CmhiDisposeStartTaskRsp;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.common.DDoSAttackType;
|
import com.dispose.common.DDoSAttackType;
|
||||||
import com.dispose.common.DisposeConfigValue;
|
import com.dispose.common.DisposeConfigValue;
|
||||||
|
@ -17,9 +14,9 @@ import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import com.dispose.security.arithmetic.CryptoHelper;
|
import com.dispose.security.arithmetic.CryptoHelper;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.pengxin.dispose.common.PengXinStartTaskRsp;
|
|
||||||
import inet.ipaddr.IPAddress;
|
import inet.ipaddr.IPAddress;
|
||||||
import inet.ipaddr.IPAddressString;
|
import inet.ipaddr.IPAddressString;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -80,6 +77,13 @@ public class demo {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
|
||||||
|
private static <T> Type createRespType(Class<T> c) {
|
||||||
|
Type[] types = new Type[1];
|
||||||
|
types[0] = c;
|
||||||
|
return ParameterizedTypeImpl.make(ProtocolRespDTO.class, types,
|
||||||
|
ProtocolRespDTO.class.getDeclaringClass());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 2 ip range test.
|
* A 2 ip range test.
|
||||||
*/
|
*/
|
||||||
|
@ -94,13 +98,6 @@ public class demo {
|
||||||
Assert.assertTrue(Helper.ipInRange("::", "::abcd"));
|
Assert.assertTrue(Helper.ipInRange("::", "::abcd"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Type createRespType(Class<T> c) {
|
|
||||||
Type[] types = new Type[1];
|
|
||||||
types[0] = c;
|
|
||||||
return ParameterizedTypeImpl.make(ProtocolRespDTO.class, types,
|
|
||||||
ProtocolRespDTO.class.getDeclaringClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void json_test() {
|
public void json_test() {
|
||||||
ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
@ -108,13 +105,13 @@ public class demo {
|
||||||
String json = "{\"ver\":1,\"cryptoType\":0,\"timeStamp\":1634780505248,\"code\":200,\"msgContent\":{\"deviceName\":\"okp\",\"items\":[{\"taskReqId\":\"1634780428667\"," +
|
String json = "{\"ver\":1,\"cryptoType\":0,\"timeStamp\":1634780505248,\"code\":200,\"msgContent\":{\"deviceName\":\"okp\",\"items\":[{\"taskReqId\":\"1634780428667\"," +
|
||||||
"\"taskId\":\"c285c206-0e4e-45f5-beab-9ac21eaf4769\",\"status\":0,\"message\":\"SUCCESS\",\"taskInfo\":\"192.168.123.126\"}]}}";
|
"\"taskId\":\"c285c206-0e4e-45f5-beab-9ac21eaf4769\",\"status\":0,\"message\":\"SUCCESS\",\"taskInfo\":\"192.168.123.126\"}]}}";
|
||||||
try {
|
try {
|
||||||
ProtocolRespDTO<PengXinStartTaskRsp> rspInfo = OBJECT_MAPPER.readValue(json,
|
ProtocolRespDTO<CmhiDisposeStartTaskRsp> rspInfo = OBJECT_MAPPER.readValue(json,
|
||||||
new TypeReference<ProtocolRespDTO<PengXinStartTaskRsp>>() {
|
new TypeReference<ProtocolRespDTO<CmhiDisposeStartTaskRsp>>() {
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return createRespType(PengXinStartTaskRsp.class);
|
return createRespType(CmhiDisposeStartTaskRsp.class);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("Ret: {}", rspInfo);
|
log.info("Ret: {}", rspInfo);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -203,8 +200,8 @@ public class demo {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
log.debug(new ObjectMapper()
|
log.debug(new ObjectMapper()
|
||||||
.writerWithDefaultPrettyPrinter()
|
.writerWithDefaultPrettyPrinter()
|
||||||
.writeValueAsString(upgradeDisposeDeviceProperties(dev, dev2)));
|
.writeValueAsString(upgradeDisposeDeviceProperties(dev, dev2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -487,8 +484,8 @@ public class demo {
|
||||||
|
|
||||||
for (String n : src) {
|
for (String n : src) {
|
||||||
log.info("{} network {}contains {}", n,
|
log.info("{} network {}contains {}", n,
|
||||||
Helper.ipInRange(n, ip) ? "is " : "not ",
|
Helper.ipInRange(n, ip) ? "is " : "not ",
|
||||||
ip);
|
ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,8 +497,8 @@ public class demo {
|
||||||
String n = "0.0.0.0";
|
String n = "0.0.0.0";
|
||||||
|
|
||||||
log.info("{} network {}contains {}", n,
|
log.info("{} network {}contains {}", n,
|
||||||
Helper.ipInRange(n, ip) ? "is " : "not ",
|
Helper.ipInRange(n, ip) ? "is " : "not ",
|
||||||
ip);
|
ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -618,7 +615,7 @@ public class demo {
|
||||||
String aesKey = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
|
String aesKey = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
|
||||||
|
|
||||||
byte[] encode = CryptoHelper.aes128Encryption(plainText.getBytes(StandardCharsets.UTF_8),
|
byte[] encode = CryptoHelper.aes128Encryption(plainText.getBytes(StandardCharsets.UTF_8),
|
||||||
aesKey);
|
aesKey);
|
||||||
log.info("AES Key: {}", aesKey);
|
log.info("AES Key: {}", aesKey);
|
||||||
log.info("Src: {}", plainText);
|
log.info("Src: {}", plainText);
|
||||||
log.info("AES256: {}", CryptoHelper.base64Encryption(encode));
|
log.info("AES256: {}", CryptoHelper.base64Encryption(encode));
|
||||||
|
|
Loading…
Reference in New Issue