完善IP复用地址池、策略配置.
This commit is contained in:
@@ -15,34 +15,24 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.callback.InlineIp;
|
||||
import com.nis.domain.callback.IpAddrPool;
|
||||
import com.nis.domain.configuration.BaseIpCfg;
|
||||
import com.nis.domain.configuration.CfgIndexInfo;
|
||||
import com.nis.domain.configuration.IpAddrPoolCfg;
|
||||
import com.nis.domain.configuration.IpMultiplexPoolCfg;
|
||||
import com.nis.domain.configuration.IpPortCfg;
|
||||
import com.nis.domain.configuration.UserManage;
|
||||
import com.nis.domain.maat.ToMaatResult;
|
||||
import com.nis.domain.maat.MaatCfg.IpCfg;
|
||||
import com.nis.domain.maat.ToMaatResult;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.ConfigServiceUtil;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.util.httpclient.HttpClientUtil;
|
||||
import com.nis.web.dao.configuration.IpAddrPoolCfgDao;
|
||||
import com.nis.web.dao.configuration.IpCfgDao;
|
||||
import com.nis.web.security.UserUtils;
|
||||
import com.nis.web.service.BaseService;
|
||||
import com.nis.web.service.SpringContextHolder;
|
||||
import com.nis.web.service.basics.PolicyGroupInfoService;
|
||||
import com.nis.web.service.basics.SysDictInfoService;
|
||||
|
||||
import jersey.repackaged.com.google.common.collect.Maps;
|
||||
|
||||
@Service
|
||||
public class IpAddrPoolCfgService extends BaseService{
|
||||
|
||||
@@ -69,16 +59,16 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
* @param isValid
|
||||
* @return
|
||||
*/
|
||||
public IpAddrPoolCfg getIpAddrPoolCfg(Long id, Integer isValid) {
|
||||
public IpAddrPoolCfg getIpAddrPoolCfg(Long cfgId, Integer isValid) {
|
||||
// 1.获取地址池配置信息
|
||||
List<IpAddrPoolCfg> list=ipAddrPoolCfgDao.findList(id,isValid,null);
|
||||
List<IpAddrPoolCfg> list=ipAddrPoolCfgDao.findList(cfgId,isValid,null);
|
||||
IpAddrPoolCfg addrPoolCfg=null;
|
||||
if(list != null && list.size()>0){
|
||||
addrPoolCfg=list.get(0);
|
||||
}
|
||||
|
||||
// 2.获取地址池内IP信息
|
||||
List<BaseIpCfg> ipCfgs = ipAddrPoolCfgDao.getReuseIpCfgs(addrPoolCfg.getAddrPoolId());
|
||||
List<BaseIpCfg> ipCfgs = ipAddrPoolCfgDao.getReuseIpCfgs(addrPoolCfg.getCfgId());
|
||||
if(ipCfgs != null && ipCfgs.size()>0){
|
||||
addrPoolCfg.setIpCfgs(ipCfgs);
|
||||
}
|
||||
@@ -94,23 +84,13 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void saveOrUpdate(IpAddrPoolCfg entity, HttpServletRequest req, HttpServletResponse res) {
|
||||
|
||||
// 可用IP数(需调用CGI接口查询)
|
||||
/*Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", "IpNumGet");
|
||||
params.put("addr_pool_id", entity.getAddrPoolId());
|
||||
try {
|
||||
String resJson = HttpClientUtil.getMsg("", params, req);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}*/
|
||||
|
||||
// 1.更新配置信息
|
||||
// 1.更新地址池信息
|
||||
Date time = new Date();
|
||||
entity.setIsValid(0);
|
||||
entity.setIsAudit(0);
|
||||
setAreaEffectiveIds(entity);
|
||||
entity.setIpTotal(entity.getIpCfgs().size());
|
||||
if(entity.getCfgId()==null){
|
||||
if(entity.getCfgId() == null){
|
||||
entity.initDefaultValue();
|
||||
entity.setCreateTime(time);
|
||||
entity.setCreatorId(UserUtils.getUser().getId());
|
||||
@@ -134,12 +114,13 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
entity.setCreateTime(new Date());
|
||||
entity.setCreatorId(entity.getCurrentUser().getId());
|
||||
}
|
||||
ipAddrPoolCfgDao.deleteReuseIpCfgs(entity.getAddrPoolId());
|
||||
Long addrPoolId = ipAddrPoolCfgDao.getAddrPoolIdByName(entity.getAddrPoolName());
|
||||
|
||||
// 2.保存IP信息 -> ip_reuse_ip_cfg(该表user_region1字段 存放 地址池ID)
|
||||
// 2.更新地址池IP信息
|
||||
ipAddrPoolCfgDao.deleteReuseIpCfgs(addrPoolId);
|
||||
for (BaseIpCfg IpCfg : entity.getIpCfgs()) {
|
||||
BeanUtils.copyProperties(entity, IpCfg);
|
||||
IpCfg.setUserRegion1(entity.getAddrPoolId()+"");
|
||||
BeanUtils.copyProperties(entity, IpCfg, new String[]{"cfgId"});
|
||||
IpCfg.setUserRegion1(addrPoolId+"");
|
||||
ipAddrPoolCfgDao.saveReuseIpCfgs(IpCfg);
|
||||
}
|
||||
|
||||
@@ -148,7 +129,6 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void delete(Integer isAudit, Integer isValid, String ids, Integer functionId) {
|
||||
String[] idArray = ids.split(",");
|
||||
String groupIds = "";
|
||||
for(String id :idArray){
|
||||
IpAddrPoolCfg entity = new IpAddrPoolCfg();
|
||||
entity.setCfgId(Long.valueOf(id));
|
||||
@@ -157,15 +137,11 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
entity.setIsValid(isValid);
|
||||
entity.setEditorId(UserUtils.getUser().getId());
|
||||
entity.setEditTime(new Date());
|
||||
Integer addrPoolId = ipAddrPoolCfgDao.getAddrPoolId(entity.getCfgId());
|
||||
groupIds += addrPoolId+",";
|
||||
ipAddrPoolCfgDao.deleteReuseIpCfgs(addrPoolId);
|
||||
|
||||
ipAddrPoolCfgDao.updateAddrPoolCfg(entity);
|
||||
ipAddrPoolCfgDao.updateReuseIpCfgs(entity);
|
||||
|
||||
}
|
||||
PolicyGroupInfoService groupInfoService = SpringContextHolder.getBean(PolicyGroupInfoService.class);
|
||||
groupInfoService.deldete(groupIds, isValid);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,8 +161,9 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
cfg.setAuditorId(UserUtils.getUser().getId());
|
||||
cfg.setAuditTime(auditTime);
|
||||
ipAddrPoolCfgDao.updateAddrPoolCfg(cfg);// 更新配置审核状态
|
||||
ipAddrPoolCfgDao.updateReuseIpCfgs(cfg);
|
||||
|
||||
cfg=getIpAddrPoolCfg(cfg.getCfgId(), null);
|
||||
cfg = this.getIpAddrPoolCfg(cfg.getCfgId(), null);
|
||||
String json="";
|
||||
if(cfg.getIsAudit()==1){
|
||||
List<IpAddrPool> resStrategyList=new ArrayList<IpAddrPool>();
|
||||
@@ -216,9 +193,9 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
ip.setIsValid(cfg.getIsValid());
|
||||
ip.setAction(ipcfg.getAction());
|
||||
ip.setService(ipcfg.getServiceId());
|
||||
ip.setAddrPoolId(cfg.getAddrPoolId());
|
||||
ip.setAddrPoolId(cfg.getCfgId());
|
||||
ip.setOpTime(auditTime);
|
||||
ip.setAreaEffectiveIds(cfg.getAreaEffectiveIds());//添加区域管控
|
||||
//ip.setAreaEffectiveIds(cfg.getAreaEffectiveIds());//添加区域管控
|
||||
|
||||
resStrategyList.add(ip);
|
||||
}
|
||||
@@ -261,9 +238,9 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
ip.setIsValid(cfg.getIsValid());
|
||||
ip.setAction(ipcfg.getAction());
|
||||
ip.setService(ipcfg.getServiceId());
|
||||
ip.setAddrPoolId(cfg.getAddrPoolId());
|
||||
ip.setAddrPoolId(cfg.getCfgId());
|
||||
ip.setOpTime(auditTime);
|
||||
ip.setAreaEffectiveIds(cfg.getAreaEffectiveIds());
|
||||
//ip.setAreaEffectiveIds(cfg.getAreaEffectiveIds());
|
||||
resStrategyList.add(ip);
|
||||
}
|
||||
//调用服务接口取消配置
|
||||
@@ -295,107 +272,7 @@ public class IpAddrPoolCfgService extends BaseService{
|
||||
* @return
|
||||
*/
|
||||
public List<IpAddrPoolCfg> getEffectiveAddrPool() {
|
||||
List<IpAddrPoolCfg> addrPools = ipAddrPoolCfgDao.findAddrPoolCfg();
|
||||
|
||||
/*String cgiUrl = "http://localhost:8080/gwall/nis/maintenance/ipMultiplexPoolCfg/cgiCall";
|
||||
if(StringUtils.isNotBlank(Constants.IP_REUSE_CGI_URL)){
|
||||
cgiUrl = Constants.IP_REUSE_CGI_URL;
|
||||
}
|
||||
for (IpAddrPoolCfg cfg : addrPools) {
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", "IpNumGet");
|
||||
params.put("addr_pool_id", cfg.getAddrPoolId());
|
||||
try {
|
||||
String resJson = HttpClientUtil.getMsg(cgiUrl, params, req);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("获取地址池信息失败!", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
return addrPools;
|
||||
}
|
||||
|
||||
/**
|
||||
* 策略配置审核
|
||||
* @param ids
|
||||
* @param cfg
|
||||
* @param auditTime
|
||||
*/
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void auditSnatStrategy(String id, IpPortCfg cfg, Date auditTime) {
|
||||
cfg.setCfgId(Long.valueOf(id));
|
||||
cfg.setTableName(IpPortCfg.getTablename());
|
||||
cfg.setAuditorId(UserUtils.getUser().getId());
|
||||
cfg.setAuditTime(auditTime);
|
||||
// 更新配置审核状态
|
||||
IpCfgDao ipCfgDao = SpringContextHolder.getBean(IpCfgDao.class);
|
||||
IpCfgService IpCfgService = SpringContextHolder.getBean(IpCfgService.class);
|
||||
ipCfgDao.auditCfg(cfg);
|
||||
|
||||
// 获取配置信息
|
||||
BaseIpCfg ipCfg = IpCfgService.getIpCfgById(cfg);
|
||||
SysDictInfoService sysDictInfoService = SpringContextHolder.getBean(SysDictInfoService.class);
|
||||
UserManageService userManageService = SpringContextHolder.getBean(UserManageService.class);
|
||||
UserManage user = userManageService.getUserById(ipCfg.getUserRegion1());
|
||||
String json="";
|
||||
if(cfg.getIsAudit() == Constants.AUDIT_YES){
|
||||
Map<String, Object> params = new HashMap<String,Object>();
|
||||
params.put("configId", ipCfg.getCompileId());
|
||||
params.put("addrPoolId", ipCfg.getUserRegion2());
|
||||
params.put("userType", user.getUserType());
|
||||
params.put("userId", user.getId());
|
||||
params.put("isValid", 1);
|
||||
params.put("opTime", auditTime);
|
||||
if(ipCfg.getIsAreaEffective() == 1){
|
||||
params.put("effectiveRange", sysDictInfoService.setEffectiveRange(ipCfg.getAreaEffectiveIds()));
|
||||
}
|
||||
List list = Lists.newArrayList();
|
||||
list.add(params);
|
||||
//调用服务接口下发配置数据
|
||||
json=gsonToJson(list);
|
||||
logger.info("SNAT策略配置下发参数:"+json);
|
||||
//调用服务接口下发配置
|
||||
try {
|
||||
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
|
||||
if(result!=null){
|
||||
logger.info("SNAT地址池配置下发响应信息:"+result.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("SNAT策略配置下发失败",e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}else if(cfg.getIsAudit() == Constants.AUDIT_NOT_YES){
|
||||
Map<String, Object> params = new HashMap<String,Object>();
|
||||
params.put("configId", ipCfg.getCompileId());
|
||||
params.put("addrPoolId", ipCfg.getUserRegion2());
|
||||
params.put("userType", user.getUserType());
|
||||
params.put("userId", user.getId());
|
||||
params.put("isValid", 0);
|
||||
params.put("opTime", auditTime);
|
||||
if(ipCfg.getIsAreaEffective() == 1){
|
||||
params.put("effectiveRange", sysDictInfoService.setEffectiveRange(ipCfg.getAreaEffectiveIds()));
|
||||
}
|
||||
List list = Lists.newArrayList();
|
||||
list.add(params);
|
||||
//调用服务接口取消配置
|
||||
json=gsonToJson(list);
|
||||
logger.info("SNAT策略配置下发参数:"+json);
|
||||
//调用服务接口取消配置
|
||||
try {
|
||||
ToMaatResult result = ConfigServiceUtil.put(json, 2);
|
||||
logger.info("SNAT策略配置响应信息:"+result.getMsg());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("SNAT策略配置配置失败");
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
return ipAddrPoolCfgDao.findAddrPoolCfg();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.nis.web.service.configuration;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.configuration.IpReusePolicyCfg;
|
||||
import com.nis.domain.maat.ToMaatResult;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.ConfigServiceUtil;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.web.dao.configuration.IpMultiplexDao;
|
||||
import com.nis.web.security.UserUtils;
|
||||
import com.nis.web.service.BaseService;
|
||||
import com.nis.web.service.SpringContextHolder;
|
||||
import com.nis.web.service.basics.SysDictInfoService;
|
||||
|
||||
@Service
|
||||
public class IpMultiplexService extends BaseService{
|
||||
|
||||
@Autowired
|
||||
private IpMultiplexDao ipMultiplexDao;
|
||||
|
||||
public Page<IpReusePolicyCfg> findPage(Page<IpReusePolicyCfg> page, IpReusePolicyCfg entity) {
|
||||
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
||||
entity.setPage(page);
|
||||
List<IpReusePolicyCfg> list=ipMultiplexDao.findPage(entity);
|
||||
page.setList(list);
|
||||
return page;
|
||||
}
|
||||
|
||||
public IpReusePolicyCfg getPolicyCfg(Long cfgId, Integer isValid) {
|
||||
List<IpReusePolicyCfg> list=ipMultiplexDao.findList(cfgId,isValid,null);
|
||||
IpReusePolicyCfg policyCfg=null;
|
||||
if(list != null && list.size()>0){
|
||||
policyCfg=list.get(0);
|
||||
}
|
||||
return policyCfg;
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void saveOrUpdate(IpReusePolicyCfg entity, HttpServletRequest request, HttpServletResponse response) {
|
||||
Date time = new Date();
|
||||
entity.setIsValid(0);
|
||||
entity.setIsAudit(0);
|
||||
setAreaEffectiveIds(entity);
|
||||
|
||||
// 获取用户/账号类型
|
||||
if(entity.getUserId() != null){
|
||||
String userType = ipMultiplexDao.getUserType(entity.getUserId());
|
||||
entity.setUserType(userType);
|
||||
}
|
||||
|
||||
// 更新策略信息
|
||||
if(entity.getCfgId() == null){
|
||||
entity.initDefaultValue();
|
||||
entity.setCreateTime(time);
|
||||
entity.setCreatorId(UserUtils.getUser().getId());
|
||||
//调用服务接口获取compileId
|
||||
try {
|
||||
List<Integer> compileIds = ConfigServiceUtil.getId(1,1);
|
||||
if(compileIds != null && compileIds.size() > 0 ){
|
||||
entity.setCompileId(compileIds.get(0));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("获取编译ID出错");
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||||
}
|
||||
ipMultiplexDao.savePolicyCfg(entity);
|
||||
|
||||
}else{
|
||||
entity.setEditorId(UserUtils.getUser().getId());
|
||||
entity.setEditTime(time);
|
||||
ipMultiplexDao.updatePolicyCfg(entity);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void delete(Integer isValid, String ids, Integer functionId) {
|
||||
String[] idArray = ids.split(",");
|
||||
for(String id :idArray){
|
||||
IpReusePolicyCfg entity = new IpReusePolicyCfg();
|
||||
entity.setCfgId(Long.valueOf(id));
|
||||
entity.setFunctionId(functionId);
|
||||
entity.setIsValid(isValid);
|
||||
entity.setEditorId(UserUtils.getUser().getId());
|
||||
entity.setEditTime(new Date());
|
||||
ipMultiplexDao.updatePolicyCfg(entity);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 策略配置审核
|
||||
* @param ids
|
||||
* @param cfg
|
||||
* @param auditTime
|
||||
*/
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void auditSnatPolicy(Integer isAudit, Integer isValid, Integer functionId, String id, Date auditTime) {
|
||||
// 更新配置审核状态
|
||||
IpReusePolicyCfg cfg = new IpReusePolicyCfg();
|
||||
cfg.setCfgId(Long.valueOf(id));
|
||||
cfg.setIsValid(isValid);
|
||||
cfg.setIsAudit(isAudit);
|
||||
cfg.setAuditorId(UserUtils.getUser().getId());
|
||||
cfg.setAuditTime(auditTime);
|
||||
ipMultiplexDao.updatePolicyCfg(cfg);
|
||||
|
||||
SysDictInfoService sysDictInfoService = SpringContextHolder.getBean(SysDictInfoService.class);
|
||||
// 获取配置信息
|
||||
cfg = this.getPolicyCfg(cfg.getCfgId(), null);
|
||||
String json="";
|
||||
if(cfg.getIsAudit() == Constants.AUDIT_YES){
|
||||
Map<String, Object> params = new HashMap<String,Object>();
|
||||
params.put("configId", cfg.getCompileId());
|
||||
params.put("addrPoolId", cfg.getAddrPoolId());
|
||||
params.put("userType", cfg.getUserType());
|
||||
params.put("userId", cfg.getUserId());
|
||||
params.put("isValid", 1);
|
||||
params.put("opTime", auditTime);
|
||||
if(cfg.getIsAreaEffective() == 1){
|
||||
params.put("effectiveRange", sysDictInfoService.setEffectiveRange(cfg.getAreaEffectiveIds()));
|
||||
}
|
||||
List list = Lists.newArrayList();
|
||||
list.add(params);
|
||||
//调用服务接口下发配置数据
|
||||
json=gsonToJson(list);
|
||||
logger.info("SNAT策略配置下发参数:"+json);
|
||||
//调用服务接口下发配置
|
||||
try {
|
||||
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
|
||||
if(result!=null){
|
||||
logger.info("SNAT策略配置下发响应信息:"+result.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("SNAT策略配置下发失败",e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}else if(cfg.getIsAudit() == Constants.AUDIT_NOT_YES){
|
||||
Map<String, Object> params = new HashMap<String,Object>();
|
||||
params.put("configId", cfg.getCompileId());
|
||||
params.put("addrPoolId", cfg.getAddrPoolId());
|
||||
params.put("userType", cfg.getUserType());
|
||||
params.put("userId", cfg.getUserId());
|
||||
params.put("isValid", 0);
|
||||
params.put("opTime", auditTime);
|
||||
if(cfg.getIsAreaEffective() == 1){
|
||||
params.put("effectiveRange", sysDictInfoService.setEffectiveRange(cfg.getAreaEffectiveIds()));
|
||||
}
|
||||
List list = Lists.newArrayList();
|
||||
list.add(params);
|
||||
//调用服务接口取消配置
|
||||
json=gsonToJson(list);
|
||||
logger.info("SNAT策略配置下发参数:"+json);
|
||||
//调用服务接口取消配置
|
||||
try {
|
||||
ToMaatResult result = ConfigServiceUtil.put(json, 2);
|
||||
logger.info("SNAT策略配置响应信息:"+result.getMsg());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("SNAT策略配置配置失败");
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user