parent
6ac14e9371
commit
16acbbbcae
2
pom.xml
2
pom.xml
|
@ -17,7 +17,7 @@
|
|||
</parent>
|
||||
<groupId>com.dispose</groupId>
|
||||
<artifactId>dispose_platform</artifactId>
|
||||
<version>2.0.8.6</version>
|
||||
<version>2.0.8.7</version>
|
||||
<name>dispose_platform</name>
|
||||
<description>Dispose Platform</description>
|
||||
<dependencies>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.dispose.ability.impl;
|
||||
|
||||
import com.dispose.ability.DisposeAbility;
|
||||
import com.dispose.common.CommonEnumHandler;
|
||||
import com.dispose.common.DisposeCapacityType;
|
||||
import com.dispose.common.DisposeConfigValue;
|
||||
import com.dispose.common.DisposeObjectType;
|
||||
|
@ -28,19 +29,17 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* The type Peng xin ability.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Slf4j
|
||||
public class PengXinAbilityImpl implements DisposeAbility {
|
||||
/**
|
||||
* The Protect ip v 4.
|
||||
*/
|
||||
private final List<String> protectIpV4 = new ArrayList<>();
|
||||
//private final List<String> protectIpV4 = new ArrayList<>();
|
||||
/**
|
||||
* The Protect ip v 6.
|
||||
*/
|
||||
private final List<String> protectIpV6 = new ArrayList<>();
|
||||
//private final List<String> protectIpV6 = new ArrayList<>();
|
||||
/**
|
||||
* The Restful interface.
|
||||
*/
|
||||
|
@ -180,14 +179,18 @@ public class PengXinAbilityImpl implements DisposeAbility {
|
|||
|
||||
ProtocolRespDTO<PengXinStartTaskRsp> rspInfo = restfulInterface.startDisposeTask(url, token, reqItems);
|
||||
|
||||
// 判断是否token过期
|
||||
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getItems().get(0).getStatus())) {
|
||||
rspInfo = restfulInterface.startDisposeTask(url, token, reqItems);
|
||||
ErrorCode err = verifyInterfaceResp(rspInfo);
|
||||
|
||||
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()) {
|
||||
log.error("----Error PengXin start clean {} server return error", disposeObject);
|
||||
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
|
||||
err = verifyRespStatus(rspInfo.getMsgContent().getItems().get(0).getStatus());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("----Error PengXin start clean {} server return {}", disposeObject, err.getMsg());
|
||||
return new MulReturnType<>(err, disposeObject);
|
||||
}
|
||||
|
||||
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
||||
|
@ -247,14 +250,18 @@ public class PengXinAbilityImpl implements DisposeAbility {
|
|||
ProtocolRespDTO<PengXinStopTaskRsp> rspInfo = restfulInterface.stopDisposeTask(url, token,
|
||||
new String[]{taskId});
|
||||
|
||||
// 判断是否token过期
|
||||
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getItems().get(0).getStatus())) {
|
||||
rspInfo = restfulInterface.stopDisposeTask(url, token, new String[]{taskId});
|
||||
ErrorCode err = verifyInterfaceResp(rspInfo);
|
||||
|
||||
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()) {
|
||||
log.error("----Error PengXin stop task{} server return error", taskId);
|
||||
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null);
|
||||
err = verifyRespStatus(rspInfo.getMsgContent().getItems().get(0).getStatus());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("----Error PengXin start clean {} server return {}", taskId, err.getMsg());
|
||||
return new MulReturnType<>(err, null);
|
||||
}
|
||||
|
||||
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
||||
|
@ -359,53 +366,57 @@ public class PengXinAbilityImpl implements DisposeAbility {
|
|||
@Override
|
||||
public void getDisposeDeviceProtectObject() {
|
||||
// 集团一键处置线上环境,移除从设备获取能力信息相关接口调用
|
||||
|
||||
// if (token == null || token.length() == 0) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// try {
|
||||
// String url = urlRootPath + "dispose_device/information/capacity";
|
||||
//
|
||||
// String url = urlRootPath + "dispose_device/information/capacity";
|
||||
//
|
||||
// try {
|
||||
// ProtocolRespDTO<PengXinDisposeAbilityRsp> rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
|
||||
//
|
||||
// // 判断是否token过期
|
||||
// if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getStatus())) {
|
||||
// rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
|
||||
// ErrorCode err = verifyInterfaceResp(rspInfo);
|
||||
//
|
||||
// if (err != ErrorCode.ERR_OK) {
|
||||
// log.error("----Error PengXin get dispose device protect object server {} return {}", url, token);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()
|
||||
// && rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
|
||||
// err = verifyRespStatus(rspInfo.getMsgContent().getStatus());
|
||||
//
|
||||
// rspInfo.getMsgContent().getCapacity().forEach(v -> {
|
||||
// if (v.getObjectType().equals(DisposeObjectType.DOMAIN.getValue())) {
|
||||
// log.error("Unsupported: {}", v.getObjectType());
|
||||
// } else if (v.getObjectType().equals(DisposeObjectType.URL.getValue())) {
|
||||
// log.error("Unsupported: {}", v.getObjectType());
|
||||
// } else {
|
||||
// synchronized (this) {
|
||||
// if (err != ErrorCode.ERR_OK) {
|
||||
// log.error("---Error PengXin get dispose device protect object server {} return {}", url, err.getMsg());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// protectIpV4.clear();
|
||||
// protectIpV6.clear();
|
||||
// rspInfo.getMsgContent().getCapacity().forEach(v -> {
|
||||
// if (v.getObjectType().equals(DisposeObjectType.DOMAIN.getValue())) {
|
||||
// log.error("Unsupported: {}", v.getObjectType());
|
||||
// } else if (v.getObjectType().equals(DisposeObjectType.URL.getValue())) {
|
||||
// log.error("Unsupported: {}", v.getObjectType());
|
||||
// } else {
|
||||
// synchronized (this) {
|
||||
//
|
||||
// if (v.getIpType() == null || v.getIpType().equals(IpAddrType.IPV4_IPV6.getValue())) {
|
||||
// String [] allIpAddr = {null, "0.0.0.0", "0.0.0.0,::"};
|
||||
// protectIpV4.clear();
|
||||
// protectIpV6.clear();
|
||||
//
|
||||
// if(Arrays.asList(allIpAddr).contains(v.getDisposeIp())) {
|
||||
// protectIpV4.add("");
|
||||
// protectIpV6.add("");
|
||||
// }
|
||||
// } else if (v.getIpType().equals(IpAddrType.IPV4.getValue())) {
|
||||
// if (v.getIpType() == null || v.getIpType().equals(IpAddrType.IPV4_IPV6.getValue())) {
|
||||
// String [] allIpAddr = {null, "0.0.0.0", "0.0.0.0,::"};
|
||||
//
|
||||
// if(Arrays.asList(allIpAddr).contains(v.getDisposeIp())) {
|
||||
// protectIpV4.add("");
|
||||
// } else if (v.getIpType().equals(IpAddrType.IPV6.getValue())) {
|
||||
// protectIpV6.add("");
|
||||
// }
|
||||
// } else if (v.getIpType().equals(IpAddrType.IPV4.getValue())) {
|
||||
// protectIpV4.add("");
|
||||
// } else if (v.getIpType().equals(IpAddrType.IPV6.getValue())) {
|
||||
// protectIpV6.add("");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// } catch (Exception ignored) {
|
||||
// }
|
||||
// });
|
||||
// } catch (Exception ex) {
|
||||
// log.error("server {}({}) exception: {}", url, token, ex);
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -468,22 +479,25 @@ public class PengXinAbilityImpl implements DisposeAbility {
|
|||
ProtocolRespDTO<PengXinTaskStatusRsp> rspInfo = restfulInterface.getDeviceTaskStatus(url, token,
|
||||
new String[]{taskId});
|
||||
|
||||
// 判断是否token过期
|
||||
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getItems().get(0).getStatus())) {
|
||||
rspInfo = restfulInterface.getDeviceTaskStatus(url, token, new String[]{taskId});
|
||||
ErrorCode err = verifyInterfaceResp(rspInfo);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("----Error PengXin start clean {} server return {}", taskId, err.getMsg());
|
||||
return new MulReturnType<>(err, -1L);
|
||||
}
|
||||
|
||||
if (rspInfo != null) {
|
||||
if (rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()) {
|
||||
int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus();
|
||||
if (rspInfo.getMsgContent().getItems().size() == 0 || errCode != ErrorCode.ERR_OK.getCode()) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_NOSUCHTASK, -1L);
|
||||
}
|
||||
}
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskStatus());
|
||||
} else {
|
||||
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, -1L);
|
||||
err = verifyRespStatus(rspInfo.getMsgContent().getItems().get(0).getStatus());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("----Error PengXin start clean {} server return {}", taskId, err.getMsg());
|
||||
return new MulReturnType<>(err, -1L);
|
||||
}
|
||||
|
||||
if (rspInfo.getMsgContent().getItems().size() == 0) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_NOSUCHTASK, -1L);
|
||||
}
|
||||
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskStatus());
|
||||
} catch (Exception ignored) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, -1L);
|
||||
}
|
||||
|
@ -505,27 +519,53 @@ public class PengXinAbilityImpl implements DisposeAbility {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reLogin.
|
||||
*/
|
||||
private <T> boolean reLogin(ProtocolRespDTO<T> rspInfo, int status) {
|
||||
try {
|
||||
// 判断是否token过期
|
||||
if (rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) {
|
||||
// 重新登录获取 token
|
||||
upgradeToken();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (rspInfo.getCode() == HttpServletResponse.SC_OK &&
|
||||
(status == ErrorCode.ERR_LOGOUT.getCode() || status == ErrorCode.ERR_TOKENTIMEOUT.getCode() ||
|
||||
status == ErrorCode.ERR_TOKENNOTFOUND.getCode())) {
|
||||
upgradeToken();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
/**
|
||||
* Verify interface resp error code.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param rspInfo the rsp info
|
||||
* @return the error code
|
||||
*/
|
||||
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 {
|
||||
return CommonEnumHandler.codeOf(ErrorCode.class, status);
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
if (status == ErrorCode.ERR_OK.getCode()) {
|
||||
return ErrorCode.ERR_OK;
|
||||
} else {
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -538,7 +578,7 @@ public class PengXinAbilityImpl implements DisposeAbility {
|
|||
|
||||
// 集团一键处置线上环境,不再定时获取设备能力信息
|
||||
// 更新防护对象
|
||||
//getDisposeDeviceProtectObject();
|
||||
getDisposeDeviceProtectObject();
|
||||
|
||||
// 更新心跳状态
|
||||
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum ErrorCode {
|
||||
public enum ErrorCode implements BaseEnum {
|
||||
/**
|
||||
* The Err ok.
|
||||
*/
|
||||
|
@ -365,4 +365,25 @@ public enum ErrorCode {
|
|||
public String getMsg() {
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.errno;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.errMsg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.pengxin.dispose.protocol;
|
||||
|
||||
import com.dispose.common.CommonEnumHandler;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.dto.protocol.base.BaseProtocolDTO;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||
|
@ -86,19 +87,27 @@ public class PengXinInterface {
|
|||
null,
|
||||
PengXinBaseResp.class,
|
||||
RequestMethod.GET);
|
||||
if (rspInfo != null && rspInfo.getMsgContent() != null) {
|
||||
if (rspInfo != null) {
|
||||
if (rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) {
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
} else if (rspInfo.getCode() == HttpServletResponse.SC_OK) {
|
||||
if(rspInfo.getMsgContent().getStatus() != ErrorCode.ERR_OK.getCode()){
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (rspInfo.getMsgContent() == null) {
|
||||
return ErrorCode.ERR_PARAMS;
|
||||
}
|
||||
|
||||
try {
|
||||
return CommonEnumHandler.codeOf(ErrorCode.class, rspInfo.getCode());
|
||||
} catch (Exception ignored) {
|
||||
if (rspInfo.getCode() == ErrorCode.ERR_OK.getCode()) {
|
||||
return ErrorCode.ERR_OK;
|
||||
} else {
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_UNKNOWNCMD;
|
||||
return ErrorCode.ERR_PARAMS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue