REM:
1.更新华为设备能力接口
2.增加华为设备查询所有zone接口
3.增加华为设备启动、停止处置任务接口
4.增加错误码
This commit is contained in:
chenlinghy 2020-11-17 18:22:31 +08:00
parent 6781d98a6d
commit 2e47fc9ff8
5 changed files with 275 additions and 66 deletions

View File

@ -92,7 +92,46 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable Long duration) {
return null;
String url = urlRootPath + "/divert";
String disposeObj = disposeObject + "/32";
if (token == null || token.length() == 0) {
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, "");
}
try {
log.info("++++Begging HuaWei Start Cleanup Task: {}", disposeObject);
if (capType != DisposeCapacityType.CLEANUP) {
log.error("----Error HuaWei don't support dispose capacity type: {}", capType);
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
}
ErrorCode resp = restfulInterface.createDivert(url, token, new String[]{disposeObj});
// 判断是否token过期
if (resp == ErrorCode.ERR_TOKENNOTFOUND) {
// 重新登录获取 token
upgradeToken();
resp = restfulInterface.createDivert(url, token, new String[]{disposeObject});
}
if (resp == null) {
log.error("----Error HuaWei start clean {} server return error", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HUAWEI_ERROR, null);
}
if (resp != ErrorCode.ERR_OK) {
log.error("----Error HuaWei start clean {} return error: {}, {}", disposeObject, resp.getCode(), resp.getMsg());
return new MulReturnType<>(ErrorCode.ERR_HUAWEI_ERROR, null);
}
log.debug("----Finish HuaWei Start Cleanup Task: {}", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
} catch (Exception ex) {
log.error("----Exception HuaWei Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, duration);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}
@ -111,7 +150,51 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable String taskId) {
return null;
String disposeObj = disposeObject + "-32";
String url = urlRootPath + "/divert/" + disposeObj;
if (token == null || token.length() == 0) {
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, null);
}
try {
log.debug("++++Begging HuaWei Stop Cleanup Task: {}", taskId);
if (capType != DisposeCapacityType.CLEANUP) {
log.error("----Error HuaWei don't support dispose capacity type: {}", capType);
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
}
if (taskId == null) {
return new MulReturnType<>(ErrorCode.ERR_PARAMS, null);
}
ErrorCode rspInfo = restfulInterface.deleteZones(url, token);
// 判断是否token过期
if (rspInfo == ErrorCode.ERR_TOKENNOTFOUND) {
// 重新登录获取 token
upgradeToken();
rspInfo = restfulInterface.deleteZones(url, token);
}
if (rspInfo == null) {
log.error("----Error HuaWei stop task{} server return error", taskId);
return new MulReturnType<>(ErrorCode.ERR_HUAWEI_ERROR, null);
}
if (rspInfo != ErrorCode.ERR_OK) {
log.error("----Error HuaWei stop task{} server return error", taskId);
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null);
}
log.debug("----Finish HuaWei Stop Cleanup Task: {}", taskId);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
} catch (Exception ex) {
log.error("----Exception HuaWei Stop Cleanup Task: {}, {}, {}", disposeObject, nfDirection, taskId);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}
/**
@ -167,9 +250,23 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
public boolean getDeviceLinkStatus() {
try {
//查询所有的zone接口调用成功认为设备心跳正常
//return (restfulInterface.queryAllZones(this.urlRootPath, token) != null);
return true;
} catch (Exception ex) {
String url = urlRootPath + "/allzone";
if (token == null || token.length() == 0) {
return false;
}
HttpResponse response = restfulInterface.queryAllZones(url, token);
if (response.getStatus() == ErrorCode.ERR_TOKENNOTFOUND.getCode()) {
// 重新登录获取 token
upgradeToken();
response = restfulInterface.queryAllZones(url, token);
}
return response.getStatus() == ErrorCode.ERR_OK.getCode();
} catch (
Exception ex) {
log.error(ex.getMessage());
}
@ -212,3 +309,4 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
}
}
}

View File

@ -232,6 +232,10 @@ public enum ErrorCode {
* The Err server processing request.
*/
ERR_SERVER_PROCESSREQ(115, "服务器处理请求错误"),
/**
* The Err huawei error.
*/
ERR_HUAWEI_ERROR(34, "华为设备返回错误"),
;
/**

View File

@ -508,6 +508,88 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
}
}
/**
* Huawei ATIC device task run.
*
* @param ai the ai
* @param deviceTask the device task
* @param disposeTask the dispose task
*/
private void huaWeiDeviceTaskRun(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) {
MulReturnType<ErrorCode, String> ret;
// 重试错误次数过多
if (deviceTask.getErrRetry() >= DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
return;
}
// 设置任务状态为启动中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING);
// 设置启动任务攻击类型状态
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType());
ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), null,
null, (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), deviceTask.getTaskAttackType());
// 更改处置任务状态为处置中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTED);
log.info("HUAWEI_PLATFORM setup task succeed: {}, device taskId {}", deviceTask, ret.getSecondParam());
// 重置错误尝试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 设置该任务为新任务待下次重试启动
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_NEW);
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("HUAWEI_PLATFORM setup task times {} error {}: {}", deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
// 任务出错不在重试当做失败任务处理
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), 0L);
log.error("HUAWEI_PLATFORM setup task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
/**
* Huawei ATIC device task stop.
*
* @param ai the ai
* @param deviceTask the device task
* @param disposeTask the dispose task
*/
private void huaWeiDeviceTaskStop(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) {
MulReturnType<ErrorCode, Long> ret;
// 停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
deviceTask.getExternId());
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
log.info("HUAWEI_PLATFORM stop task succeed: {}, device taskId {}", deviceTask, ret.getSecondParam());
// 设置任务状态为结束
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_FINISHED);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("HUAWEI_PLATFORM stop task times {} error {}: {}", deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
log.error("HUAWEI_PLATFORM stop task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
/**
* Dispose task manager schedule.
*/
@ -601,6 +683,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
pengXinDeviceTaskRun(ai, v, task);
break;
case HUAWEI_PLATFORM:
huaWeiDeviceTaskRun(ai, v, task);
break;
default:
log.error("Unknown dispose device type: {}", ai.getDev());
break;
@ -672,6 +758,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
pengXinDeviceTaskStop(ai, v, task);
break;
case HUAWEI_PLATFORM:
huaWeiDeviceTaskStop(ai, v, task);
break;
default:
log.error("Unknown dispose device type: {}", ai.getDev());
break;

View File

@ -5,6 +5,7 @@ import com.dispose.ability.impl.DpTechAbilityImpl;
import com.dispose.ability.impl.HaoHanAbilityImpl;
import com.dispose.ability.impl.PengXinAbilityImpl;
import com.dispose.ability.impl.VirtualAbilityImpl;
import com.dispose.ability.impl.HuaWeiAbilityImpl;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType;
@ -115,6 +116,9 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
case PENGXIN_PLATFORM:
db = new PengXinAbilityImpl();
break;
case HUAWEI_PLATFORM:
db = new HuaWeiAbilityImpl();
break;
case VIRTUAL_DISPOSE:
db = new VirtualAbilityImpl();
break;

View File

@ -39,9 +39,9 @@ public class HuaWeiInterface {
* @param zone_ip zone ip
* @return the delete zone status
*/
public ErrorCode createDivert(String baseUrlPath, String token, String[] zone_ip){
public ErrorCode createDivert(String baseUrlPath, String token, String[] zone_ip) {
//获取HTTP部分
HttpResponse response = RestfulInterface.huaWeiProRun(baseUrlPath + "/divert",
HttpResponse response = RestfulInterface.huaWeiProRun(baseUrlPath,
token,
new HuaWeiCreatDivertReq(zone_ip),
RequestMethod.POST);
@ -49,13 +49,13 @@ public class HuaWeiInterface {
if (response != null) {
if (response.getStatus() == HttpServletResponse.SC_CREATED) {
return ErrorCode.ERR_OK;
}else if(response.getStatus() == HttpServletResponse.SC_BAD_REQUEST) {
} else if (response.getStatus() == HttpServletResponse.SC_BAD_REQUEST) {
return ErrorCode.ERR_PARAMS;
}else if(response.getStatus() == HttpServletResponse.SC_CONFLICT){
} else if (response.getStatus() == HttpServletResponse.SC_CONFLICT) {
return ErrorCode.ERR_SPECIFIEDIP_EXISTS;
} else if (response.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
return ErrorCode.ERR_TOKENNOTFOUND;
}else if(response.getStatus() == HttpServletResponse.SC_INTERNAL_SERVER_ERROR){
} else if (response.getStatus() == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
return ErrorCode.ERR_SERVER_PROCESSREQ;
}
}
@ -69,12 +69,11 @@ public class HuaWeiInterface {
*
* @param baseUrlPath the base url path
* @param token the token
* @param zone_ip zone ip
* @return the delete zone status
*/
public ErrorCode deleteZones(String baseUrlPath, String token, String zone_ip) {
public ErrorCode deleteZones(String baseUrlPath, String token) {
//获取HTTP部分
HttpResponse response = RestfulInterface.huaWeiProRun(baseUrlPath + "/divert/" + zone_ip,
HttpResponse response = RestfulInterface.huaWeiProRun(baseUrlPath,
token,
null,
RequestMethod.DELETE);
@ -82,17 +81,31 @@ public class HuaWeiInterface {
if (response != null) {
if (response.getStatus() == HttpServletResponse.SC_OK) {
return ErrorCode.ERR_OK;
}else if(response.getStatus() == HttpServletResponse.SC_BAD_REQUEST){
} else if (response.getStatus() == HttpServletResponse.SC_BAD_REQUEST) {
return ErrorCode.ERR_PARAMS;
}else if(response.getStatus() == HttpServletResponse.SC_NOT_FOUND){
} else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
return ErrorCode.ERR_SPECIFIEDIP_NOTEXISTS;
} else if (response.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
return ErrorCode.ERR_TOKENNOTFOUND;
}else if(response.getStatus() == HttpServletResponse.SC_INTERNAL_SERVER_ERROR){
} else if (response.getStatus() == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
return ErrorCode.ERR_SERVER_PROCESSREQ;
}
}
return ErrorCode.ERR_UNKNOWNCMD;
}
/**
* query all zones protocol resp dto.
*
* @param baseUrlPath the base url path
* @param token the token
* @return the http resp
*/
public HttpResponse queryAllZones(String baseUrlPath, String token) {
return RestfulInterface.huaWeiProRun(baseUrlPath,
token,
null,
RequestMethod.GET);
}
}