REM:
1. 修正添加设备时异常问题
This commit is contained in:
HuangXin 2021-02-02 10:11:12 +08:00
parent 42cbb0760c
commit a1f1d82158
3 changed files with 74 additions and 55 deletions

View File

@ -80,22 +80,29 @@ public class DisposeDeviceManagerController {
// 获取请求中的需要添加的设备列表 // 获取请求中的需要添加的设备列表
req.getItems().forEach(v -> { req.getItems().forEach(v -> {
HttpType hType = CommonEnumHandler.codeOf(HttpType.class, v.getUrlType());
String port = v.getIpPort();
if (v.getIpPort() == null || v.getIpPort().length() == 0) {
port = HttpType.getDefaultPort(hType);
}
DisposeDevice dev = DisposeDevice.builder() DisposeDevice dev = DisposeDevice.builder()
.ipAddr(v.getIpAddr()) .ipAddr(v.getIpAddr())
.ipPort(v.getIpPort()) .ipPort(port)
.deviceType(CommonEnumHandler.codeOf(DisposeDeviceType.class, .deviceType(CommonEnumHandler.codeOf(DisposeDeviceType.class,
v.getDeviceType())) v.getDeviceType()))
.areaCode(v.getAreaCode()) .areaCode(v.getAreaCode())
.deviceName(v.getDeviceName()) .deviceName(v.getDeviceName())
.manufacturer(v.getManufacturer()) .manufacturer(v.getManufacturer())
.model(v.getModel()) .model(v.getModel())
.version(v.getVersion()) .version(v.getVersion())
.userName(v.getUserName()) .userName(v.getUserName())
.password(v.getPassword()) .password(v.getPassword())
.urlPath(v.getUrlPath()) .urlPath(v.getUrlPath())
.urlType(CommonEnumHandler.codeOf(HttpType.class, v.getUrlType())) .urlType(hType)
.readme(v.getReadme()) .readme(v.getReadme())
.build(); .build();
// 初始化设备能力信息 // 初始化设备能力信息
dev.setDevCapacity(new ArrayList<>()); dev.setDevCapacity(new ArrayList<>());
@ -103,13 +110,13 @@ public class DisposeDeviceManagerController {
v.getCapacity().forEach(k -> { v.getCapacity().forEach(k -> {
// 添加设备能力 // 添加设备能力
DisposeCapacity cap = DisposeCapacity.builder() DisposeCapacity cap = DisposeCapacity.builder()
.capacityType(CommonEnumHandler.codeOf(DisposeCapacityType.class, k.getCapacityType())) .capacityType(CommonEnumHandler.codeOf(DisposeCapacityType.class, k.getCapacityType()))
.ipType(k.getIpType() == null ? IpAddrType.IPV4 : .ipType(k.getIpType() == null ? IpAddrType.IPV4 :
CommonEnumHandler.codeOf(IpAddrType.class, k.getIpType())) CommonEnumHandler.codeOf(IpAddrType.class, k.getIpType()))
.objectType(CommonEnumHandler.codeOf(DisposeObjectType.class, k.getObjectType())) .objectType(CommonEnumHandler.codeOf(DisposeObjectType.class, k.getObjectType()))
.protectIp(k.getProtectIp() == null ? "" : k.getProtectIp()) .protectIp(k.getProtectIp() == null ? "" : k.getProtectIp())
.reserveNetflow(k.getReserveNetflow()) .reserveNetflow(k.getReserveNetflow())
.build(); .build();
dev.getDevCapacity().add(cap); dev.getDevCapacity().add(cap);
}); });
@ -129,8 +136,8 @@ public class DisposeDeviceManagerController {
@ResponseBody @ResponseBody
@ApiOperation("添加处置能力节点") @ApiOperation("添加处置能力节点")
public ProtocolRespDTO<AddDeviceRsp> addDisposeDevice( public ProtocolRespDTO<AddDeviceRsp> addDisposeDevice(
@Validated(ValidGroups.AddDeviceValid.class) @Validated(ValidGroups.AddDeviceValid.class)
@RequestBody ProtocolReqDTO<AddDeviceReq> mr) { @RequestBody ProtocolReqDTO<AddDeviceReq> mr) {
// 请求参数转换 // 请求参数转换
List<DisposeDevice> devs = requestToDeviceList(mr.getMsgContent()); List<DisposeDevice> devs = requestToDeviceList(mr.getMsgContent());
@ -144,9 +151,9 @@ public class DisposeDeviceManagerController {
ret.forEach(v -> { ret.forEach(v -> {
DisposeDevice dev = v.getSecondParam(); DisposeDevice dev = v.getSecondParam();
AddDeviceRet rsp = AddDeviceRet.builder() AddDeviceRet rsp = AddDeviceRet.builder()
.ipAddr(dev.getIpAddr()) .ipAddr(dev.getIpAddr())
.ipPort(Helper.ipPortNormalize(dev.getIpPort(), dev.getUrlType())) .ipPort(Helper.ipPortNormalize(dev.getIpPort(), dev.getUrlType()))
.build(); .build();
rsp.setStatus(v.getFirstParam().getCode()); rsp.setStatus(v.getFirstParam().getCode());
rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); rsp.setMessage(new String[]{v.getFirstParam().getMsg()});
@ -172,8 +179,8 @@ public class DisposeDeviceManagerController {
@ResponseBody @ResponseBody
@ApiOperation("删除处置能力节点") @ApiOperation("删除处置能力节点")
public ProtocolRespDTO<CommDeviceListRsp> removeDisposeDevice( public ProtocolRespDTO<CommDeviceListRsp> removeDisposeDevice(
@Validated(ValidGroups.ExplicitIdArrayValid.class) @Validated(ValidGroups.ExplicitIdArrayValid.class)
@RequestBody ProtocolReqDTO<IdArraysReq> mr) { @RequestBody ProtocolReqDTO<IdArraysReq> mr) {
List<Long> idList = new ArrayList<>(); List<Long> idList = new ArrayList<>();
@ -183,7 +190,7 @@ public class DisposeDeviceManagerController {
} }
List<MulReturnType<ErrorCode, DisposeDevice>> ret = List<MulReturnType<ErrorCode, DisposeDevice>> ret =
disposeDeviceManagerService.removeDisposeDevice(idList); disposeDeviceManagerService.removeDisposeDevice(idList);
CommDeviceListRsp rspInfo = new CommDeviceListRsp(); CommDeviceListRsp rspInfo = new CommDeviceListRsp();
rspInfo.setItems(new ArrayList<>()); rspInfo.setItems(new ArrayList<>());
@ -213,8 +220,8 @@ public class DisposeDeviceManagerController {
@ResponseBody @ResponseBody
@ApiOperation("更新处置能力节点") @ApiOperation("更新处置能力节点")
public ProtocolRespDTO<CommDeviceListRsp> upgradeDisposeDevice( public ProtocolRespDTO<CommDeviceListRsp> upgradeDisposeDevice(
@Validated(ValidGroups.UpgradeDeviceValid.class) @Validated(ValidGroups.UpgradeDeviceValid.class)
@RequestBody ProtocolReqDTO<AddDeviceReq> mr) { @RequestBody ProtocolReqDTO<AddDeviceReq> mr) {
// 请求参数转换 // 请求参数转换
List<DisposeDevice> devs = requestToDeviceList(mr.getMsgContent()); List<DisposeDevice> devs = requestToDeviceList(mr.getMsgContent());
@ -230,8 +237,8 @@ public class DisposeDeviceManagerController {
DisposeDevice dev = v.getSecondParam(); DisposeDevice dev = v.getSecondParam();
disposeDeviceManagerService.getAllDisposeDevice().parallelStream() disposeDeviceManagerService.getAllDisposeDevice().parallelStream()
.filter(k -> k.getId().equals(dev.getId())) .filter(k -> k.getId().equals(dev.getId()))
.findAny().ifPresent(device -> rsp.setDevStatus(device.getStatus().getValue())); .findAny().ifPresent(device -> rsp.setDevStatus(device.getStatus().getValue()));
rsp.setId(String.valueOf(dev.getId())); rsp.setId(String.valueOf(dev.getId()));
rsp.setStatus(v.getFirstParam().getCode()); rsp.setStatus(v.getFirstParam().getCode());
@ -253,12 +260,12 @@ public class DisposeDeviceManagerController {
@ResponseBody @ResponseBody
@ApiOperation("获取处置能力节点") @ApiOperation("获取处置能力节点")
public ProtocolRespDTO<? extends BaseRespStatus> getAllDisposeDevice( public ProtocolRespDTO<? extends BaseRespStatus> getAllDisposeDevice(
@Validated(ValidGroups.ProtocolCommonValid.class) @Validated(ValidGroups.ProtocolCommonValid.class)
@RequestBody ProtocolReqDTO<BasePagesGetReq> mr) { @RequestBody ProtocolReqDTO<BasePagesGetReq> mr) {
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> ret = MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> ret =
disposeDeviceManagerService.getPageDisposeDevice(mr.getMsgContent().getStartPage(), disposeDeviceManagerService.getPageDisposeDevice(mr.getMsgContent().getStartPage(),
mr.getMsgContent().getPageSize()); mr.getMsgContent().getPageSize());
GetDeviceRsp rspInfo = new GetDeviceRsp(); GetDeviceRsp rspInfo = new GetDeviceRsp();
@ -277,7 +284,7 @@ public class DisposeDeviceManagerController {
GetDeviceDetail devInfo = new GetDeviceDetail(); GetDeviceDetail devInfo = new GetDeviceDetail();
devInfo.setId(v.getId().toString()); devInfo.setId(v.getId().toString());
devInfo.setIpAddr(DisposeConfigValue.USED_PRIVACY_PROTECT ? devInfo.setIpAddr(DisposeConfigValue.USED_PRIVACY_PROTECT ?
PrivacyHelper.ipAddressPrivacy(v.getIpAddr()) : v.getIpAddr()); PrivacyHelper.ipAddressPrivacy(v.getIpAddr()) : v.getIpAddr());
devInfo.setIpPort(Helper.ipPortNormalize(v.getIpPort(), v.getUrlType())); devInfo.setIpPort(Helper.ipPortNormalize(v.getIpPort(), v.getUrlType()));
devInfo.setDeviceType(v.getDeviceType().getValue()); devInfo.setDeviceType(v.getDeviceType().getValue());
devInfo.setAreaCode(v.getAreaCode()); devInfo.setAreaCode(v.getAreaCode());
@ -286,7 +293,7 @@ public class DisposeDeviceManagerController {
devInfo.setModel(v.getModel()); devInfo.setModel(v.getModel());
devInfo.setVersion(v.getVersion()); devInfo.setVersion(v.getVersion());
devInfo.setUserName(DisposeConfigValue.USED_PRIVACY_PROTECT ? devInfo.setUserName(DisposeConfigValue.USED_PRIVACY_PROTECT ?
PrivacyHelper.usernamePrivacy(v.getUserName()) : v.getUserName()); PrivacyHelper.usernamePrivacy(v.getUserName()) : v.getUserName());
devInfo.setUrlType(v.getUrlType().getValue()); devInfo.setUrlType(v.getUrlType().getValue());
devInfo.setReadme(v.getReadme()); devInfo.setReadme(v.getReadme());
devInfo.setDevStatus(v.getStatus().getValue()); devInfo.setDevStatus(v.getStatus().getValue());
@ -296,12 +303,12 @@ public class DisposeDeviceManagerController {
v.getDevCapacity().forEach(k -> { v.getDevCapacity().forEach(k -> {
AddCapacityInfo capInfo = AddCapacityInfo.builder() AddCapacityInfo capInfo = AddCapacityInfo.builder()
.capacityType(k.getCapacityType().getValue()) .capacityType(k.getCapacityType().getValue())
.objectType(k.getObjectType().getValue()) .objectType(k.getObjectType().getValue())
.ipType(k.getIpType().getValue()) .ipType(k.getIpType().getValue())
.protectIp(k.getProtectIp()) .protectIp(k.getProtectIp())
.reserveNetflow(k.getReserveNetflow()) .reserveNetflow(k.getReserveNetflow())
.build(); .build();
capList.add(capInfo); capList.add(capInfo);
}); });

View File

@ -2,7 +2,6 @@ package com.dispose.manager.impl;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.Helper; import com.dispose.common.Helper;
import com.dispose.common.HttpType;
import com.dispose.common.IpAddrType; import com.dispose.common.IpAddrType;
import com.dispose.common.ObjectStatus; import com.dispose.common.ObjectStatus;
import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeDeviceManager;
@ -58,7 +57,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
public MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) { public MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) {
// 看看系统中有没有存在相同IP+端口地址的设备有的话返回失败 // 看看系统中有没有存在相同IP+端口地址的设备有的话返回失败
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddrAndType(dev.getIpAddr(), dev.getIpPort(), DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddrAndType(dev.getIpAddr(), dev.getIpPort(),
dev.getDeviceType().getValue()); dev.getDeviceType().getValue());
if (tDev != null) { if (tDev != null) {
// 如果设备是删除状态则更新设备信息 // 如果设备是删除状态则更新设备信息
@ -117,7 +116,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
fdDest.setAccessible(true); fdDest.setAccessible(true);
if (!obj.equals(fdDest.get(destDev))) { if (!obj.equals(fdDest.get(destDev))) {
log.debug("Upgrade field [{}] value form [{}] to [{}]", fdSrc.getName(), fdDest.get(destDev), log.debug("Upgrade field [{}] value form [{}] to [{}]", fdSrc.getName(), fdDest.get(destDev),
obj); obj);
fdDest.set(destDev, obj); fdDest.set(destDev, obj);
} }
fdDest.setAccessible(false); fdDest.setAccessible(false);
@ -137,8 +136,21 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
*/ */
@Override @Override
public MulReturnType<ErrorCode, Long> upgradeDisposeDevice(DisposeDevice dev) { public MulReturnType<ErrorCode, Long> upgradeDisposeDevice(DisposeDevice dev) {
DisposeDevice tDev = null;
// 根据Ip和设备类型获取设备 // 根据Ip和设备类型获取设备
DisposeDevice tDev = disposeDeviceMapper.getDeviceByIpAndType(dev.getIpAddr(), dev.getDeviceType().getValue()); List<DisposeDevice> devList = disposeDeviceMapper.getDeviceByIpAndType(dev.getIpAddr(),
dev.getDeviceType().getValue());
if (devList == null || devList.size() == 0) {
return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, -1L);
}
for (DisposeDevice v : devList) {
if (Helper.isIpPortMatch(v.getIpPort(), dev.getIpPort(), dev.getUrlType())) {
tDev = v;
break;
}
}
// 找不到设备 // 找不到设备
if (tDev == null || !Helper.isIpPortMatch(tDev.getIpPort(), dev.getIpPort(), dev.getUrlType())) { if (tDev == null || !Helper.isIpPortMatch(tDev.getIpPort(), dev.getIpPort(), dev.getUrlType())) {

View File

@ -76,12 +76,12 @@ public interface DisposeDeviceMapper {
int availableDisposeDevice(@Param("id") Long id); int availableDisposeDevice(@Param("id") Long id);
/** /**
* Gets device by address. * Gets device by addr and type.
* *
* @param ipAddr the ip addr * @param ipAddr the ip addr
* @param ipPort the ip port * @param ipPort the ip port
* @param devType the device type * @param devType the dev type
* @return the device by address * @return the device by addr and type
*/ */
DisposeDevice getDeviceByAddrAndType(@Param("ipAddr") String ipAddr, DisposeDevice getDeviceByAddrAndType(@Param("ipAddr") String ipAddr,
@Param("ipPort") String ipPort, @Param("ipPort") String ipPort,
@ -94,8 +94,8 @@ public interface DisposeDeviceMapper {
* @param devType the dev type * @param devType the dev type
* @return the device by ip and type * @return the device by ip and type
*/ */
DisposeDevice getDeviceByIpAndType(@Param("ipAddr") String ipAddr, List<DisposeDevice> getDeviceByIpAndType(@Param("ipAddr") String ipAddr,
@Param("devType") Integer devType); @Param("devType") Integer devType);
/** /**