parent
d90f961ea5
commit
a3f6128be2
|
@ -7,145 +7,150 @@ package com.dispose.common;
|
|||
*/
|
||||
public enum ErrorCode {
|
||||
/**
|
||||
* Err ok error code.
|
||||
* The Err ok.
|
||||
*/
|
||||
ERR_OK(0, "成功"),
|
||||
/**
|
||||
* Err password error code.
|
||||
* The Err password.
|
||||
*/
|
||||
ERR_PASSWORD(1, "密码错误"),
|
||||
/**
|
||||
* Err usernotfound error code.
|
||||
* The Err usernotfound.
|
||||
*/
|
||||
ERR_USERNOTFOUND(2, "用户不存在"),
|
||||
/**
|
||||
* Err passwordmore error code.
|
||||
* The Err passwordmore.
|
||||
*/
|
||||
ERR_PASSWORDMORE(3, "连续密码错误达上限,再次输入错误将锁定用户"),
|
||||
/**
|
||||
* Err userlock error code.
|
||||
* The Err userlock.
|
||||
*/
|
||||
ERR_USERLOCK(4, "密码错误达上限,用户被锁定"),
|
||||
/**
|
||||
* Err account error code.
|
||||
* The Err account.
|
||||
*/
|
||||
ERR_ACCOUNT(5, "用户账户异常"),
|
||||
/**
|
||||
* Err userexist error code.
|
||||
* The Err userexist.
|
||||
*/
|
||||
ERR_USEREXIST(6, "该用户已经存在"),
|
||||
/**
|
||||
* Err passwordsimple error code.
|
||||
* The Err passwordsimple.
|
||||
*/
|
||||
ERR_PASSWORDSIMPLE(7, "用户密码强度不符合要求"),
|
||||
/**
|
||||
* Err inputformat error code.
|
||||
* The Err inputformat.
|
||||
*/
|
||||
ERR_INPUTFORMAT(8, "输入信息格式有误"),
|
||||
/**
|
||||
* Err inputmiss error code.
|
||||
* The Err inputmiss.
|
||||
*/
|
||||
ERR_INPUTMISS(9, "缺少必要输入信息"),
|
||||
/**
|
||||
* Err permission error code.
|
||||
* The Err permission.
|
||||
*/
|
||||
ERR_PERMISSION(10, "操作员权限不足"),
|
||||
/**
|
||||
* Err reqtimeout error code.
|
||||
* The Err reqtimeout.
|
||||
*/
|
||||
ERR_REQTIMEOUT(11, "请求超时"),
|
||||
/**
|
||||
* Err params error code.
|
||||
* The Err params.
|
||||
*/
|
||||
ERR_PARAMS(12, "参数错误"),
|
||||
/**
|
||||
* Err systemexception error code.
|
||||
* The Err systemexception.
|
||||
*/
|
||||
ERR_SYSTEMEXCEPTION(13, "系统异常"),
|
||||
/**
|
||||
* Err unknowncmd error code.
|
||||
* The Err unknowncmd.
|
||||
*/
|
||||
ERR_UNKNOWNCMD(14, "未知命令"),
|
||||
/**
|
||||
* Err logout error code.
|
||||
* The Err logout.
|
||||
*/
|
||||
ERR_LOGOUT(15, "用户未登录"),
|
||||
/**
|
||||
* Err tokentimeout error code.
|
||||
* The Err tokentimeout.
|
||||
*/
|
||||
ERR_TOKENTIMEOUT(16, "Token超时"),
|
||||
/**
|
||||
* Err tokennotfound error code.
|
||||
* The Err tokennotfound.
|
||||
*/
|
||||
ERR_TOKENNOTFOUND(17, "非法Token"),
|
||||
/**
|
||||
* Err missauthhead error code.
|
||||
* The Err missauthhead.
|
||||
*/
|
||||
ERR_MISSAUTHHEAD(18, "Http 请求缺少认证头部"),
|
||||
/**
|
||||
* Err nosuchdevice error code.
|
||||
* The Err nosuchdevice.
|
||||
*/
|
||||
ERR_NOSUCHDEVICE(19, "没有这个设备"),
|
||||
/**
|
||||
* Err deviceexists error code.
|
||||
* The Err deviceexists.
|
||||
*/
|
||||
ERR_DEVICEEXISTS(20, "设备已经存在"),
|
||||
/**
|
||||
* Err paramexception error code.
|
||||
* The Err paramexception.
|
||||
*/
|
||||
ERR_PARAMEXCEPTION(21, "参数异常"),
|
||||
/**
|
||||
* Err version error code.
|
||||
* The Err version.
|
||||
*/
|
||||
ERR_VERSION(23, "协议版本不兼容,请升级系统"),
|
||||
/**
|
||||
* Err nosuchtype error code.
|
||||
* The Err nosuchtype.
|
||||
*/
|
||||
ERR_NOSUCHTYPE(24, "没有这个类型的处置设备"),
|
||||
/**
|
||||
* Err removemore error code.
|
||||
* The Err removemore.
|
||||
*/
|
||||
ERR_REMOVEMORE(25, "禁止同时删除多个设备"),
|
||||
|
||||
/**
|
||||
* Err taskrunning error code.
|
||||
* The Err taskrunning.
|
||||
*/
|
||||
ERR_TASKRUNNING(26, "同类任务正在运行"),
|
||||
|
||||
/**
|
||||
* Err unsupport error code.
|
||||
* The Err unsupport.
|
||||
*/
|
||||
ERR_UNSUPPORT(27, "不支持的操作"),
|
||||
|
||||
/**
|
||||
* Err interrupt error code.
|
||||
* The Err interrupt.
|
||||
*/
|
||||
ERR_INTERRUPT(28, "操作中断"),
|
||||
|
||||
/**
|
||||
* Err calldevice error code.
|
||||
* The Err calldevice.
|
||||
*/
|
||||
ERR_CALLDEVICE(29, "调用设备失败"),
|
||||
|
||||
/**
|
||||
* Err nosuchtask error code.
|
||||
* The Err nosuchtask.
|
||||
*/
|
||||
ERR_NOSUCHTASK(30, "没有该任务"),
|
||||
|
||||
/**
|
||||
* Err tasknotrunning error code.
|
||||
* The Err tasknotrunning.
|
||||
*/
|
||||
ERR_TASKNOTRUNNING(31, "该任务没有运行"),
|
||||
|
||||
/**
|
||||
* Err requesttimeout error code.
|
||||
* The Err requesttimeout.
|
||||
*/
|
||||
ERR_REQUESTTIMEOUT(32, "请求超时"),
|
||||
|
||||
/**
|
||||
* Err unable to dispose the ip error code.
|
||||
* The Err unabledisposeip.
|
||||
*/
|
||||
ERR_UNABLEDISPOSEIP(33, "无法处置该IP"),
|
||||
|
||||
/**
|
||||
* Err haohan error error code.
|
||||
*/
|
||||
ERR_HAOHAN_ERROR(34, "浩瀚设备返回错误"),
|
||||
;
|
||||
|
||||
private final int errno;
|
||||
|
|
|
@ -16,22 +16,24 @@ import java.util.List;
|
|||
*/
|
||||
public interface DisposeEntryManager {
|
||||
/**
|
||||
* Run dispose error code.
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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);
|
||||
MulReturnType<ErrorCode, Long> runDispose(String ip, DeviceCapacity type, Long duration);
|
||||
|
||||
/**
|
||||
* Stop dispose error code.
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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);
|
||||
MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -198,14 +198,15 @@ public class DpTechImpl implements DisposeEntryManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Run dispose error code.
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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) {
|
||||
public MulReturnType<ErrorCode, Long> runDispose(String ip, DeviceCapacity type, Long duration) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
// 当前系统接入设备仅仅支持流量清洗功能
|
||||
if (type != DeviceCapacity.CLEANUP) {
|
||||
|
@ -239,14 +240,15 @@ public class DpTechImpl implements DisposeEntryManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Stop dispose error code.
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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) {
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) {
|
||||
if (type != DeviceCapacity.CLEANUP) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,10 @@ import com.dispose.dispose.DisposeEntryManager;
|
|||
import com.dispose.dispose.po.DeviceInfo;
|
||||
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.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -21,7 +25,9 @@ import java.util.List;
|
|||
@Slf4j
|
||||
public class HaoHanImpl implements DisposeEntryManager {
|
||||
|
||||
private String deviceAddress;
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final String deviceAddress;
|
||||
|
||||
/**
|
||||
* Instantiates a new Hao han.
|
||||
|
@ -44,26 +50,58 @@ public class HaoHanImpl implements DisposeEntryManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Run dispose error code.
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
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 error code.
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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) {
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
}
|
||||
|
||||
|
@ -113,9 +151,9 @@ public class HaoHanImpl implements DisposeEntryManager {
|
|||
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||
.tolFlowCapacity(0)
|
||||
// IPv4范围
|
||||
.protectIpV4(new String[] {""})
|
||||
.protectIpV4(new String[]{""})
|
||||
// IPv6范围
|
||||
.protectIpV6(new String[] {""})
|
||||
.protectIpV6(new String[]{""})
|
||||
.build());
|
||||
|
||||
return capList;
|
||||
|
|
|
@ -38,26 +38,28 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Run dispose error code.
|
||||
* Run dispose mul return type.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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) {
|
||||
public MulReturnType<ErrorCode, Long> runDispose(String ip, DeviceCapacity type, Long duration) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dispose error code.
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
* @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) {
|
||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
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;
|
||||
}
|
|
@ -3,6 +3,7 @@ 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;
|
||||
|
@ -190,6 +191,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
long planDuration = Helper.getTimestampDiff(task.getCreateTime(), task.getPlanEndTime()) / 60;
|
||||
|
||||
List<DisposeDevice> dev = getDisposeNode(task.getDisposeIp(), task.getType());
|
||||
|
||||
// 判断是否有支持处置该IP的能力
|
||||
|
@ -207,7 +210,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(k.getType(), k.getIpAddr());
|
||||
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> dp.runDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]))
|
||||
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());
|
||||
|
@ -267,7 +270,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(k.getType(), k.getIpAddr());
|
||||
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> dp.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]))
|
||||
CompletableFuture.supplyAsync(() -> dp.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()], -1L))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
// 恢复缓存中任务状态到先前状态
|
||||
|
|
|
@ -168,6 +168,8 @@ public class TaskControllerTest extends InitTestEnvironment {
|
|||
Assert.assertNotEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
|
||||
Assert.assertNotEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
|
||||
}
|
||||
|
||||
Thread.sleep(1000 * 300);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -139,7 +139,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
|||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||
"10.88.77.15");
|
||||
|
||||
Assert.assertEquals(dp.runDispose("192.168.3.5", DeviceCapacity.CLEANUP), ErrorCode.ERR_OK);
|
||||
Assert.assertEquals(dp.runDispose("192.168.3.5", DeviceCapacity.CLEANUP, -1L).getFirstParam(), ErrorCode.ERR_OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -147,6 +147,6 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
|||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||
"10.88.77.15");
|
||||
|
||||
Assert.assertEquals(dp.stopDispose("192.168.3.5", DeviceCapacity.CLEANUP), ErrorCode.ERR_OK);
|
||||
Assert.assertEquals(dp.stopDispose("192.168.3.5", DeviceCapacity.CLEANUP, -1L).getFirstParam(), ErrorCode.ERR_OK);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue