欺骗ip配置添加、删除(与转换层通信)
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
package com.nis.web.service.configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.nis.domain.configuration.DnsIpCfg;
|
||||
import com.nis.domain.maat.DnsIpRecvData;
|
||||
import com.nis.domain.maat.FromMaatBean;
|
||||
import com.nis.domain.maat.MaatDnsIpCfg;
|
||||
import com.nis.domain.maat.ToMaatDnsIpBean;
|
||||
import com.nis.main.ConvertTool;
|
||||
import com.nis.util.Collections3;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.dao.configuration.DnsIpCfgDao;
|
||||
import com.nis.web.service.CrudService;
|
||||
|
||||
@@ -11,12 +23,50 @@ public class DnsIpCfgService extends CrudService<DnsIpCfgDao, DnsIpCfg>{
|
||||
|
||||
@Override
|
||||
public void save(DnsIpCfg dnsIpCfg) {
|
||||
if (dnsIpCfg.getCfgId() == null) {
|
||||
dao.insert(dnsIpCfg);
|
||||
} else {
|
||||
dao.update(dnsIpCfg);
|
||||
dao.insert(dnsIpCfg);
|
||||
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
|
||||
//组织要发送的json
|
||||
ToMaatDnsIpBean toMaatBean = new ToMaatDnsIpBean();
|
||||
List<MaatDnsIpCfg> ipCfgList = new ArrayList<MaatDnsIpCfg>();
|
||||
MaatDnsIpCfg ipCfg = new MaatDnsIpCfg();
|
||||
List<DnsIpCfg> d1 = new ArrayList<DnsIpCfg>();
|
||||
d1.add(dnsIpCfg);
|
||||
ipCfg.setIpCfg(d1);
|
||||
ipCfgList.add(ipCfg);
|
||||
toMaatBean.setServiceCfg(ipCfgList);
|
||||
String sendJson = gson.toJson(toMaatBean);
|
||||
|
||||
//下发配置、接收结果
|
||||
String recvJson = "";
|
||||
try {
|
||||
recvJson = new ConvertTool().saveDNSIPConfig(sendJson);
|
||||
logger.info("收到结果:" + recvJson);
|
||||
} catch (Throwable e) {
|
||||
logger.error("欺骗ip配置新增下发失败,cfgId=" + dnsIpCfg.getCfgId(), e);
|
||||
throw new RuntimeException("欺骗ip配置新增下发失败:通讯异常");
|
||||
}
|
||||
|
||||
if (!StringUtil.isEmpty(recvJson)) {
|
||||
logger.error("新增欺骗ip配置失败:收到空的返回结果,cfgId:" + dnsIpCfg.getCfgId());
|
||||
throw new RuntimeException("新增欺骗ip配置失败:收到空的返回结果");
|
||||
}
|
||||
logger.info("结果接收成功");
|
||||
|
||||
FromMaatBean fromMaatBean = gson.fromJson(recvJson, FromMaatBean.class);
|
||||
List<DnsIpRecvData> data = fromMaatBean.getData();
|
||||
if (!Collections3.isEmpty(data)) {
|
||||
DnsIpRecvData dnsIpRecvData = data.get(0);
|
||||
if (dnsIpRecvData.getFakeId() != null && dnsIpRecvData.getCfgId() != null
|
||||
&& dnsIpRecvData.getCfgId().longValue() == dnsIpCfg.getCfgId().longValue()) {
|
||||
dnsIpCfg.setFakeId(dnsIpRecvData.getFakeId());
|
||||
dao.update(dnsIpCfg);
|
||||
}
|
||||
} else {
|
||||
logger.error("新增欺骗ip配置失败:收到空的返回结果,cfgId:" + dnsIpCfg.getCfgId());
|
||||
throw new RuntimeException("新增欺骗ip配置失败:收到空的返回结果");
|
||||
}
|
||||
//TODO 下发流程
|
||||
}
|
||||
|
||||
public void delete(String cfgIds) {
|
||||
@@ -26,6 +76,19 @@ public class DnsIpCfgService extends CrudService<DnsIpCfgDao, DnsIpCfg>{
|
||||
d.setCfgId(Long.valueOf(cfgId));
|
||||
dao.delete(d);
|
||||
}
|
||||
//TODO 下发流程
|
||||
|
||||
//给配置转换层发送、接收结果
|
||||
String sendJson = "{\"fakeId\":[" + cfgIds + "]}";
|
||||
Boolean recv = true;
|
||||
try {
|
||||
recv = new ConvertTool().invalidDNSIPConfig(sendJson);
|
||||
} catch (Throwable e) {
|
||||
logger.error("欺骗ip配置删除失败:通讯异常,cfgIds:" + cfgIds, e);
|
||||
throw new RuntimeException("欺骗ip配置删除失败:通讯失败");
|
||||
}
|
||||
if (!recv) {
|
||||
logger.error("欺骗ip配置删除失败,收到结果 " + recv + " ,cfgIds:" + cfgIds);
|
||||
throw new RuntimeException("欺骗ip配置删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user