diff --git a/src/main/java/com/cmcc/hy/phoenix/controller/taskController.java b/src/main/java/com/cmcc/hy/phoenix/controller/taskController.java index 17c6d42a..a210aba1 100644 --- a/src/main/java/com/cmcc/hy/phoenix/controller/taskController.java +++ b/src/main/java/com/cmcc/hy/phoenix/controller/taskController.java @@ -76,6 +76,9 @@ public class taskController { // Token 正确则处理业务 switch (mr.getCmdId()) { case ConstValue.ProtocolCmdId.START_DISPOSE_CMD: + EnumMap startMap = StartTaskByTaskId(mr); + err = startMap.keySet().iterator().next(); + msgCtx = startMap.get(err); break; //停止清洗任务 case ConstValue.ProtocolCmdId.STOP_DISPOSE_CMD_BY_TASKID: @@ -113,6 +116,7 @@ public class taskController { private EnumMap StopTaskByTaskId(ProtocolDTO mr) throws JsonProcessingException { String ipAddr = "10.88.77.15"; + DisposeProcess dp = new DptechUMC(ipAddr); EnumMap retMap = new EnumMap<>(ErrorCode.class); ErrorCode err = ErrorCode.ERR_OK; @@ -136,7 +140,6 @@ public class taskController { int attackType = 1; int direction = 0; - DisposeProcess dp = new DptechUMC(ipAddr); NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(disposeIp, attackType, direction); StopTaskResult sig_results = new StopTaskResult(); @@ -158,6 +161,7 @@ public class taskController { private EnumMap StopTaskByIp(ProtocolDTO mr) throws JsonProcessingException { String ipAddr = "10.88.77.15"; + DisposeProcess dp = new DptechUMC(ipAddr); EnumMap retMap = new EnumMap<>(ErrorCode.class); ErrorCode err = ErrorCode.ERR_OK; @@ -198,7 +202,6 @@ public class taskController { int attackType = 1; int direction = 0; - DisposeProcess dp = new DptechUMC(ipAddr); NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(v.getDisposeIP(), attackType, direction); StopTaskResult result = new StopTaskResult(); @@ -224,6 +227,7 @@ public class taskController { private EnumMap StopTaskByPoint(ProtocolDTO mr) throws JsonProcessingException { String ipAddr = "10.88.77.15"; + DisposeProcess dp = new DptechUMC(ipAddr); EnumMap retMap = new EnumMap<>(ErrorCode.class); ErrorCode err = ErrorCode.ERR_OK; @@ -268,7 +272,6 @@ public class taskController { int direction = 0; int taskid = 0; - DisposeProcess dp = new DptechUMC(ipAddr); for (String getDisposeIp : getDisposeIps ) { NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(getDisposeIp, attackType, direction); @@ -298,6 +301,7 @@ public class taskController { private EnumMap StopTaskAll(ProtocolDTO mr) throws JsonProcessingException { String ipAddr = "10.88.77.15"; + DisposeProcess dp = new DptechUMC(ipAddr); EnumMap retMap = new EnumMap<>(ErrorCode.class); ErrorCode err = ErrorCode.ERR_OK; @@ -331,6 +335,7 @@ public class taskController { taskIds.add("4"); String disposeIp = ""; + for (String v : taskIds ) { //每个taskId对应disposeIp,通过taskId获取disposeIp @@ -348,7 +353,6 @@ public class taskController { int attackType = 1; int direction = 0; - DisposeProcess dp = new DptechUMC(ipAddr); NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(disposeIp, attackType, direction); StopTaskResult result = new StopTaskResult(); @@ -371,4 +375,53 @@ public class taskController { retMap.put(err, objectMapper.writeValueAsString(repInfo)); return retMap; } + + + private EnumMap StartTaskByTaskId(ProtocolDTO mr) throws JsonProcessingException { + String ipAddr = "10.88.77.15"; + DisposeProcess dp = new DptechUMC(ipAddr); + EnumMap retMap = new EnumMap<>(ErrorCode.class); + ErrorCode err = ErrorCode.ERR_OK; + int status_result = 0; + + StartTaskRep repInfo = StartTaskRep.builder() + .id("") + .taskId("") + .expireTime(0L) + .status(err.getCode()).build(); + + StartTaskReq reqInfo = objectMapper.readValue(mr.getMsgContent(), StartTaskReq.class); + + List attackTypes = reqInfo.getAttackType(); + int direction = reqInfo.getFlowDirection(); + String disposeIp = reqInfo.getDisposeIp(); + + for (Integer attackType : attackTypes + ) { + NtcRequestResultInfo ntc_result = dp.startAbnormalTask(disposeIp, attackType, direction); + int ret_err = -1; + if (ntc_result.getResultRetVal().equals(ret_err)) { + System.out.println("启动清洗任务失败"); + err = ErrorCode.ERR_UNKNOWNCMD; + repInfo = null; + retMap.put(err, objectMapper.writeValueAsString(repInfo)); + return retMap; + } + + status_result = ntc_result.getResultRetVal(); + } + + repInfo.setId(reqInfo.getId()); + //MySql 根据设备Id查找对应的taskId + //test 假设设备id与taskId相同 + repInfo.setTaskId(reqInfo.getId()); + repInfo.setExpireTime(System.currentTimeMillis()+reqInfo.getDisposeTime()); + repInfo.setStatus(status_result); + + //启动清洗任务成功,task数据到MySql + + retMap.put(err, objectMapper.writeValueAsString(repInfo)); + return retMap; + } + } diff --git a/src/main/java/com/cmcc/hy/phoenix/dispose/DisposeProcess.java b/src/main/java/com/cmcc/hy/phoenix/dispose/DisposeProcess.java index 339f2436..31499266 100644 --- a/src/main/java/com/cmcc/hy/phoenix/dispose/DisposeProcess.java +++ b/src/main/java/com/cmcc/hy/phoenix/dispose/DisposeProcess.java @@ -15,4 +15,6 @@ public interface DisposeProcess { public NtcRequestResultInfo stopAbnormalTask(String abnormalIp, int attackType, int direction); + public NtcRequestResultInfo startAbnormalTask(String abnormalIp, int attackType, int direction); + } diff --git a/src/main/java/com/cmcc/hy/phoenix/dispose/DptechUMC.java b/src/main/java/com/cmcc/hy/phoenix/dispose/DptechUMC.java index 193528b0..96e1cacf 100644 --- a/src/main/java/com/cmcc/hy/phoenix/dispose/DptechUMC.java +++ b/src/main/java/com/cmcc/hy/phoenix/dispose/DptechUMC.java @@ -12,6 +12,11 @@ import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; import org.apache.wss4j.dom.WSConstants; import org.apache.wss4j.dom.handler.WSHandlerConstants; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; import java.util.HashMap; import java.util.Map; @@ -73,4 +78,10 @@ public class DptechUMC implements DisposeProcess { public NtcRequestResultInfo stopAbnormalTask(String abnormalIp, int attackType, int direction){ return cleanTypePort.stopAbnormalTaskForUMC(abnormalIp, attackType, direction); } + + @Override + public NtcRequestResultInfo startAbnormalTask(String abnormalIp, int attackType, int direction){ + return cleanTypePort.startAbnormalTaskForUMC(abnormalIp, attackType, direction); + } } + diff --git a/src/main/java/com/cmcc/hy/phoenix/pojo/vo/StartTaskRep.java b/src/main/java/com/cmcc/hy/phoenix/pojo/vo/StartTaskRep.java new file mode 100644 index 00000000..145f33d2 --- /dev/null +++ b/src/main/java/com/cmcc/hy/phoenix/pojo/vo/StartTaskRep.java @@ -0,0 +1,17 @@ +package com.cmcc.hy.phoenix.pojo.vo; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@Builder +public class StartTaskRep { + private String id; + private String taskId; + private long expireTime; + private int status; +} diff --git a/src/main/java/com/cmcc/hy/phoenix/pojo/vo/StartTaskReq.java b/src/main/java/com/cmcc/hy/phoenix/pojo/vo/StartTaskReq.java new file mode 100644 index 00000000..2895102f --- /dev/null +++ b/src/main/java/com/cmcc/hy/phoenix/pojo/vo/StartTaskReq.java @@ -0,0 +1,19 @@ +package com.cmcc.hy.phoenix.pojo.vo; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class StartTaskReq { + private String id; + private int type; + private String disposeIp; + private long disposeTime; + private int flowDirection; + private List attackType; + private int flowBandwidth; +} +