parent
cfbec4da90
commit
08d68b66ab
|
@ -56,6 +56,14 @@ public interface DisposeAbility {
|
|||
@Nullable Integer attackType,
|
||||
@Nullable String taskId);
|
||||
|
||||
/**
|
||||
* Task status mul return type.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> taskStatus(Long taskId);
|
||||
|
||||
/**
|
||||
* Gets ability device fireware.
|
||||
*
|
||||
|
|
|
@ -316,4 +316,15 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task status mul return type.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> taskStatus(Long taskId) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,4 +214,15 @@ public class HaoHanAbilityImpl implements DisposeAbility {
|
|||
IPAddress addr = new IPAddressString(ipAddr).getAddress();
|
||||
return addr.isIPv4();
|
||||
}
|
||||
|
||||
/**
|
||||
* Task status mul return type.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> taskStatus(Long taskId) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.pengxin.dispose.common.PengXinLoginRsp;
|
|||
import com.pengxin.dispose.common.PengXinStartTaskItem;
|
||||
import com.pengxin.dispose.common.PengXinStartTaskRsp;
|
||||
import com.pengxin.dispose.common.PengXinStopTaskRsp;
|
||||
import com.pengxin.dispose.common.PengXinTaskStatusRsp;
|
||||
import com.pengxin.dispose.protocol.PengXinInterface;
|
||||
import inet.ipaddr.IPAddress;
|
||||
import inet.ipaddr.IPAddressString;
|
||||
|
@ -407,6 +408,48 @@ public class PengXinAbilityImpl implements DisposeAbility {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task status mul return type.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> taskStatus(Long taskId) {
|
||||
if (token == null || token.length() == 0) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, -1L);
|
||||
}
|
||||
|
||||
try {
|
||||
String url = urlRootPath + "dispose_device/task/get";
|
||||
|
||||
ProtocolRespDTO<PengXinTaskStatusRsp> rspInfo = restfulInterface.getDeviceTaskStatus(url, token,
|
||||
new String[] {String.valueOf(taskId)});
|
||||
|
||||
// 判断是否token过期
|
||||
if (rspInfo != null && rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) {
|
||||
// 重新登录获取 token
|
||||
upgradeToken();
|
||||
rspInfo = restfulInterface.getDeviceTaskStatus(urlRootPath, token,
|
||||
new String[] {String.valueOf(taskId)});
|
||||
}
|
||||
|
||||
if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()) {
|
||||
|
||||
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());
|
||||
} else {
|
||||
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, -1L);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, -1L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade token.
|
||||
*/
|
||||
|
|
|
@ -132,4 +132,15 @@ public class VirtualAbilityImpl implements DisposeAbility {
|
|||
public boolean isCarryProtectIp(String ipAddr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task status mul return type.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> taskStatus(Long taskId) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public class DisposeTaskController {
|
|||
Long devId = Long.parseLong(Optional.ofNullable(req.getDeviceId()).orElse("-1"));
|
||||
Long aId = userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization")).get(0));
|
||||
DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType());
|
||||
String endTime = String.valueOf(req.getDisposeTime());
|
||||
String endTime = String.valueOf(req.getDisposeTime() == -1 ? 52560000 : req.getDisposeTime());
|
||||
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
|
||||
Optional.ofNullable(req.getFlowDirection()).orElse(2));
|
||||
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
|
||||
|
@ -399,6 +399,7 @@ public class DisposeTaskController {
|
|||
.devId(String.valueOf(k.getDeviceId()))
|
||||
.externId(String.valueOf(k.getExternId()))
|
||||
.status(k.getStatus())
|
||||
.devStatus(k.getDevStatus())
|
||||
.build();
|
||||
taskDetail.getDeviceTask().add(deviceTaskDetail);
|
||||
});
|
||||
|
|
|
@ -45,6 +45,14 @@ public interface DeviceTaskManager {
|
|||
*/
|
||||
boolean changeDisposeDeviceTaskInfoStatus(Long id, DisposeTaskStatus status);
|
||||
|
||||
/**
|
||||
* Gets dispose device task status.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the dispose device task status
|
||||
*/
|
||||
int changeDisposeDeviceTaskInfoDevStatus(Long id, Long devStatus);
|
||||
|
||||
/**
|
||||
* Sets exec attack type.
|
||||
*
|
||||
|
|
|
@ -79,6 +79,18 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||
return deviceTaskMapper.changeTaskStatus(id, status) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change dispose device task info dev status long.
|
||||
*
|
||||
* @param id the id
|
||||
* @param devStatus the dev status
|
||||
* @return the long
|
||||
*/
|
||||
@Override
|
||||
public int changeDisposeDeviceTaskInfoDevStatus(Long id, Long devStatus) {
|
||||
return deviceTaskMapper.changeTaskDevStatus(id, devStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets exec attack type.
|
||||
*
|
||||
|
|
|
@ -85,6 +85,16 @@ public interface DeviceTaskMapper {
|
|||
int changeTaskStatus(@Param("id") Long id,
|
||||
@Param("status") DisposeTaskStatus status);
|
||||
|
||||
/**
|
||||
* Change task dev status int.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the int
|
||||
*/
|
||||
int changeTaskDevStatus(@Param("id") Long id,
|
||||
@Param("status") Long status);
|
||||
|
||||
/**
|
||||
* Change exec attack type in value int.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,10 @@ public class GetDeviceTaskDetail {
|
|||
* The Extern id.
|
||||
*/
|
||||
private String externId;
|
||||
/**
|
||||
* The Dev status.
|
||||
*/
|
||||
private Long devStatus;
|
||||
/**
|
||||
* The Status.
|
||||
*/
|
||||
|
|
|
@ -87,4 +87,8 @@ public class DeviceTask implements Serializable {
|
|||
* The Status.
|
||||
*/
|
||||
private Long status;
|
||||
/**
|
||||
* The Dev status.
|
||||
*/
|
||||
private Long devStatus;
|
||||
}
|
||||
|
|
|
@ -682,6 +682,53 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Device task status schedule.
|
||||
*/
|
||||
public void deviceTaskStatusSchedule() {
|
||||
// 遍历所有新的设备处置任务
|
||||
for (DeviceTask v : deviceTaskManager.getStartedDisposeDeviceTaskInfo()) {
|
||||
DisposeTask task = disposeTaskManager.getDisposeTaskById(v.getTaskId());
|
||||
|
||||
// 保护代码,理论上不存在该情况
|
||||
assert task != null;
|
||||
|
||||
// 获取设备
|
||||
AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId());
|
||||
|
||||
// 如果设备已经删除或者禁用,跳过处理
|
||||
if (ai == null) {
|
||||
// 设置任务状态为已完成
|
||||
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(v.getId(), DisposeTaskStatus.TASK_FINISHED);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 对处置IP生成一个唯一的操作标识符
|
||||
String taskStatusKey = v.getId() + "Status" + ai.getDev().getDeviceType().getDescription();
|
||||
|
||||
if (taskCache.containsKey(taskStatusKey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 设置标志,避免对同一个IP重复调用停止处置命令
|
||||
taskCache.put(taskStatusKey, true);
|
||||
|
||||
// 任务预计结束5分钟内,
|
||||
if (Helper.getTimestampDiffNow(task.getPlanEndTime()) < 5 * 60) {
|
||||
if (v.getEndTime() == null && Helper.getTimestampDiffNow(v.getEndTime()) < 5 * 60) {
|
||||
MulReturnType<ErrorCode, Long> ret = ai.getDb().taskStatus(v.getId());
|
||||
|
||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(v.getId(), ret.getSecondParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处置命令调用结束,允许下一次停止命令调用
|
||||
taskCache.remove(taskStatusKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule runner thread.
|
||||
*/
|
||||
|
@ -697,5 +744,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
|
||||
// 处置设备停止任务
|
||||
deviceTaskStopSchedule();
|
||||
|
||||
// 定时刷新设备任务状态
|
||||
deviceTaskStatusSchedule();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.pengxin.dispose.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Peng xin tast status item.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class PengXinTaskStatusItem extends PengXinBaseResp {
|
||||
/**
|
||||
* The Task id.
|
||||
*/
|
||||
private String taskId;
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* The Object type.
|
||||
*/
|
||||
private Integer objectType;
|
||||
/**
|
||||
* The Dispose object.
|
||||
*/
|
||||
private String disposeObject;
|
||||
/**
|
||||
* The Start time.
|
||||
*/
|
||||
private Long startTime;
|
||||
/**
|
||||
* The Dispose time.
|
||||
*/
|
||||
private Long disposeTime;
|
||||
/**
|
||||
* The Task status.
|
||||
*/
|
||||
private Long taskStatus;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.pengxin.dispose.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Peng xin task status rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class PengXinTaskStatusRsp {
|
||||
|
||||
/**
|
||||
* The Device name.
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
private List<PengXinTaskStatusItem> items;
|
||||
}
|
|
@ -13,6 +13,7 @@ import com.pengxin.dispose.common.PengXinStartTaskReq;
|
|||
import com.pengxin.dispose.common.PengXinStartTaskRsp;
|
||||
import com.pengxin.dispose.common.PengXinStopTaskReq;
|
||||
import com.pengxin.dispose.common.PengXinStopTaskRsp;
|
||||
import com.pengxin.dispose.common.PengXinTaskStatusRsp;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -160,4 +161,29 @@ public class PengXinInterface {
|
|||
PengXinDisposeAbilityRsp.class,
|
||||
RequestMethod.GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device task status.
|
||||
*
|
||||
* @param baseUrlPath the base url path
|
||||
* @param token the token
|
||||
* @param taskId the task id
|
||||
* @return the device task status
|
||||
*/
|
||||
public ProtocolRespDTO<PengXinTaskStatusRsp> getDeviceTaskStatus(String baseUrlPath, String token, String[] taskId) {
|
||||
BaseProtocolDTO<PengXinStopTaskReq> reqInfo = new BaseProtocolDTO<>();
|
||||
|
||||
reqInfo.setMsgContent(new PengXinStopTaskReq());
|
||||
|
||||
reqInfo.getMsgContent().setTaskId(taskId);
|
||||
reqInfo.setCryptoType(this.cryptoType);
|
||||
reqInfo.setVer(this.ver);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
|
||||
return RestfulInterface.baseProRun(baseUrlPath,
|
||||
token,
|
||||
reqInfo,
|
||||
PengXinTaskStatusRsp.class,
|
||||
RequestMethod.POST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ CREATE TABLE `device_task`
|
|||
`externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID',
|
||||
`errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数',
|
||||
`status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态',
|
||||
`devStatus` int(10) NOT NULL DEFAULT 0 COMMENT '设备任务状态',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
|
||||
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<result column="attackTypeStatusOut" property="attackTypeStatusOut"/>
|
||||
<result column="externId" property="externId"/>
|
||||
<result column="errRetry" property="errRetry"/>
|
||||
<result column="devStatus" property="devStatus"/>
|
||||
<result column="status" property="status"/>
|
||||
</resultMap>
|
||||
|
||||
|
@ -24,11 +25,11 @@
|
|||
|
||||
<insert id="addNewTaskInfoList" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.DeviceTask">
|
||||
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status)
|
||||
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status, devStatus)
|
||||
VALUES
|
||||
<foreach collection="taskLists" item="task" separator=",">
|
||||
(#{task.taskId}, #{task.deviceId}, #{task.taskAttackType},
|
||||
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
|
||||
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, 0)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
@ -87,6 +88,12 @@
|
|||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="changeTaskDevStatus">
|
||||
UPDATE device_task
|
||||
SET status = #{status}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="changeExecAttackTypeInValue">
|
||||
UPDATE device_task
|
||||
SET execAttackTypeIn = #{attackTypeValue}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
<result column="externId" property="externId"/>
|
||||
<result column="errRetry" property="errRetry"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="devStatus" property="devStatus"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
|
@ -61,6 +62,7 @@
|
|||
ti.attackTypeStatusOut attackTypeStatusOut,
|
||||
ti.externId externId,
|
||||
ti.errRetry errRetry,
|
||||
ti.devStatus devStatus,
|
||||
ti.status status
|
||||
FROM dispose_task dt
|
||||
LEFT JOIN device_task ti on dt.id = ti.taskId
|
||||
|
@ -84,6 +86,7 @@
|
|||
ti.attackTypeStatusOut attackTypeStatusOut,
|
||||
ti.externId externId,
|
||||
ti.errRetry errRetry,
|
||||
ti.devStatus devStatus,
|
||||
ti.status status
|
||||
FROM dispose_task dt
|
||||
LEFT JOIN device_task ti on dt.id = ti.taskId
|
||||
|
@ -103,6 +106,7 @@
|
|||
ti.attackTypeStatusOut attackTypeStatusOut,
|
||||
ti.externId externId,
|
||||
ti.errRetry errRetry,
|
||||
ti.devStatus devStatus,
|
||||
ti.status status
|
||||
FROM dispose_task dt
|
||||
LEFT JOIN device_task ti on dt.id = ti.taskId
|
||||
|
|
|
@ -36,6 +36,7 @@ CREATE TABLE `device_task`
|
|||
`externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID',
|
||||
`errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数',
|
||||
`status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态',
|
||||
`devStatus` int(10) NOT NULL DEFAULT 0 COMMENT '设备任务状态',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
|
||||
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,
|
||||
|
@ -174,7 +175,8 @@ VALUES (1, -1, 1, -1, 0, '192.168.10.1', 1, CURRENT_TIMESTAMP, date_add(now(), i
|
|||
8796093022207,
|
||||
1024, 0);
|
||||
INSERT INTO `dispose_task`
|
||||
VALUES (2, -1, 1, -1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207,
|
||||
VALUES (2, -1, 1, -1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2,
|
||||
8796093022207,
|
||||
1024, 0);
|
||||
|
||||
-- ----------------------------
|
||||
|
|
Loading…
Reference in New Issue