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

View File

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

View File

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