Merge remote-tracking branch 'origin/v2.0.5_dev' into v2.0.5_dev
This commit is contained in:
commit
9f147ed229
|
@ -6,6 +6,7 @@ import inet.ipaddr.AddressStringException;
|
||||||
import inet.ipaddr.IPAddress;
|
import inet.ipaddr.IPAddress;
|
||||||
import inet.ipaddr.IPAddressSeqRange;
|
import inet.ipaddr.IPAddressSeqRange;
|
||||||
import inet.ipaddr.IPAddressString;
|
import inet.ipaddr.IPAddressString;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -227,4 +228,38 @@ public class Helper {
|
||||||
|
|
||||||
return ret.orElse("");
|
return ret.orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is ip port match boolean.
|
||||||
|
*
|
||||||
|
* @param originPort the origin port
|
||||||
|
* @param targetPort the target port
|
||||||
|
* @param portType the port type
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
|
public static boolean isIpPortMatch(String originPort, String targetPort, HttpType portType) {
|
||||||
|
String oPort, tPort;
|
||||||
|
|
||||||
|
if (portType == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originPort != null && originPort.length() > 0) {
|
||||||
|
oPort = originPort;
|
||||||
|
} else {
|
||||||
|
oPort = portType.equals(HttpType.HTTP) ?
|
||||||
|
HttpType.getDefaultPort(HttpType.HTTP) :
|
||||||
|
HttpType.getDefaultPort(HttpType.HTTPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetPort != null && targetPort.length() > 0) {
|
||||||
|
tPort = targetPort;
|
||||||
|
} else {
|
||||||
|
tPort = portType.equals(HttpType.HTTP) ?
|
||||||
|
HttpType.getDefaultPort(HttpType.HTTP) :
|
||||||
|
HttpType.getDefaultPort(HttpType.HTTPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return oPort.equals(tPort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.dispose.manager.impl;
|
package com.dispose.manager.impl;
|
||||||
|
|
||||||
import com.dispose.common.ErrorCode;
|
import com.dispose.common.ErrorCode;
|
||||||
|
import com.dispose.common.Helper;
|
||||||
import com.dispose.common.HttpType;
|
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;
|
||||||
|
@ -56,7 +57,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
@Override
|
@Override
|
||||||
public MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) {
|
public MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) {
|
||||||
// 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败
|
// 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败
|
||||||
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort(),
|
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddrAndType(dev.getIpAddr(), dev.getIpPort(),
|
||||||
dev.getDeviceType().getValue());
|
dev.getDeviceType().getValue());
|
||||||
|
|
||||||
if (tDev != null) {
|
if (tDev != null) {
|
||||||
|
@ -136,22 +137,11 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MulReturnType<ErrorCode, Long> upgradeDisposeDevice(DisposeDevice dev) {
|
public MulReturnType<ErrorCode, Long> upgradeDisposeDevice(DisposeDevice dev) {
|
||||||
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort(),
|
// 根据Ip和设备类型获取设备
|
||||||
dev.getDeviceType().getValue());
|
DisposeDevice tDev = disposeDeviceMapper.getDeviceByIpAndType(dev.getIpAddr(), dev.getDeviceType().getValue());
|
||||||
|
|
||||||
// 处理默认端口情况
|
// 找不到设备
|
||||||
if (tDev == null) {
|
if (tDev == null || !Helper.isIpPortMatch(tDev.getIpPort(), dev.getIpPort(), dev.getUrlType())) {
|
||||||
if (dev.getIpPort() == null || dev.getIpPort().length() == 0) {
|
|
||||||
tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(),
|
|
||||||
dev.getUrlType() == HttpType.HTTP ?
|
|
||||||
HttpType.getDefaultPort(HttpType.HTTP) :
|
|
||||||
HttpType.getDefaultPort(HttpType.HTTPS),
|
|
||||||
dev.getDeviceType().getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 实在找不到设备返回错误
|
|
||||||
if (tDev == null) {
|
|
||||||
return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, -1L);
|
return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +150,9 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
dev.setUserName(null);
|
dev.setUserName(null);
|
||||||
dev.setUrlType(null);
|
dev.setUrlType(null);
|
||||||
dev.setPassword(null);
|
dev.setPassword(null);
|
||||||
|
dev.setIpPort(null);
|
||||||
|
dev.setIpAddr(null);
|
||||||
|
dev.setDeviceType(null);
|
||||||
|
|
||||||
// 更新值
|
// 更新值
|
||||||
upgradeDisposeDeviceProperties(tDev, dev);
|
upgradeDisposeDeviceProperties(tDev, dev);
|
||||||
|
|
|
@ -83,10 +83,20 @@ public interface DisposeDeviceMapper {
|
||||||
* @param devType the device type
|
* @param devType the device type
|
||||||
* @return the device by address
|
* @return the device by address
|
||||||
*/
|
*/
|
||||||
DisposeDevice getDeviceByAddress(@Param("ipAddr") String ipAddr,
|
DisposeDevice getDeviceByAddrAndType(@Param("ipAddr") String ipAddr,
|
||||||
@Param("ipPort") String ipPort,
|
@Param("ipPort") String ipPort,
|
||||||
@Param("devType") Integer devType);
|
@Param("devType") Integer devType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device by ip and type.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @param devType the dev type
|
||||||
|
* @return the device by ip and type
|
||||||
|
*/
|
||||||
|
DisposeDevice getDeviceByIpAndType(@Param("ipAddr") String ipAddr,
|
||||||
|
@Param("devType") Integer devType);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets device by id.
|
* Gets device by id.
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getDeviceByAddress" resultMap="dispose_device">
|
<select id="getDeviceByAddrAndType" resultMap="dispose_device">
|
||||||
SELECT d.*,
|
SELECT d.*,
|
||||||
c.*
|
c.*
|
||||||
FROM dispose_device d
|
FROM dispose_device d
|
||||||
|
@ -73,6 +73,15 @@
|
||||||
AND d.deviceType = #{devType}
|
AND d.deviceType = #{devType}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getDeviceByIpAndType" resultMap="dispose_device">
|
||||||
|
SELECT d.*,
|
||||||
|
c.*
|
||||||
|
FROM dispose_device d
|
||||||
|
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
||||||
|
WHERE d.ipAddr = #{ipAddr}
|
||||||
|
AND d.deviceType = #{devType}
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="getDeviceById" resultMap="dispose_device">
|
<select id="getDeviceById" resultMap="dispose_device">
|
||||||
SELECT d.*,
|
SELECT d.*,
|
||||||
c.*
|
c.*
|
||||||
|
|
|
@ -666,4 +666,20 @@ public class demo {
|
||||||
log.info("demoList2 difference demoList1: {}", demoList.equals(demoList2));
|
log.info("demoList2 difference demoList1: {}", demoList.equals(demoList2));
|
||||||
log.info("tmpTable difference tmpTable: {}", tmpTable.equals(tmpTable2));
|
log.info("tmpTable difference tmpTable: {}", tmpTable.equals(tmpTable2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ip port match test.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void ipPortMatchTest() {
|
||||||
|
String[] srcPort = new String[] {"", "80", "443", "81", null};
|
||||||
|
String[] dstPort = new String[] {"", "80", "443", "81", null};
|
||||||
|
|
||||||
|
for(String s : srcPort) {
|
||||||
|
for(String d : dstPort) {
|
||||||
|
log.info("HTTP: [{}] match [{}] is {}", s, d, Helper.isIpPortMatch(s, d, HttpType.HTTP));
|
||||||
|
log.info("HTTPS: [{}] match [{}] is {}", s, d, Helper.isIpPortMatch(s, d, HttpType.HTTPS));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ public class DisposeDeviceManagerTest extends InitTestEnvironment {
|
||||||
) {
|
) {
|
||||||
MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v.getId(), obj);
|
MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v.getId(), obj);
|
||||||
|
|
||||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort(),
|
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddrAndType(v.getIpAddr(), v.getIpPort(),
|
||||||
v.getDeviceType().getValue());
|
v.getDeviceType().getValue());
|
||||||
|
|
||||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
||||||
|
|
||||||
devList.forEach(v -> {
|
devList.forEach(v -> {
|
||||||
if(v.getIpPort().length() != 0){
|
if(v.getIpPort().length() != 0){
|
||||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort(),
|
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddrAndType(v.getIpAddr(), v.getIpPort(),
|
||||||
v.getDeviceType().getValue());
|
v.getDeviceType().getValue());
|
||||||
|
|
||||||
String beforeVer = dev.getVersion();
|
String beforeVer = dev.getVersion();
|
||||||
|
@ -165,12 +165,12 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
||||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||||
|
|
||||||
devList.forEach(v -> {
|
devList.forEach(v -> {
|
||||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort(),
|
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddrAndType(v.getIpAddr(), v.getIpPort(),
|
||||||
v.getDeviceType().getValue());
|
v.getDeviceType().getValue());
|
||||||
Assert.assertNotNull(dev);
|
Assert.assertNotNull(dev);
|
||||||
|
|
||||||
if(v.getIpPort().length() != 0){
|
if(v.getIpPort().length() != 0){
|
||||||
dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(),
|
dev = disposeDeviceMapper.getDeviceByAddrAndType(v.getIpAddr(),
|
||||||
String.valueOf(Long.parseLong(Optional.ofNullable(v.getIpPort()).orElse("123")) + 1233),
|
String.valueOf(Long.parseLong(Optional.ofNullable(v.getIpPort()).orElse("123")) + 1233),
|
||||||
v.getDeviceType().getValue());
|
v.getDeviceType().getValue());
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ public class P1All {
|
||||||
Assert.assertNotNull(k.getDevStatus());
|
Assert.assertNotNull(k.getDevStatus());
|
||||||
});
|
});
|
||||||
|
|
||||||
DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddress("127.0.0.1", "",
|
DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddrAndType("127.0.0.1", "",
|
||||||
DisposeDeviceType.VIRTUAL_DISPOSE.getValue());
|
DisposeDeviceType.VIRTUAL_DISPOSE.getValue());
|
||||||
|
|
||||||
Assert.assertNotNull(dev);
|
Assert.assertNotNull(dev);
|
||||||
|
|
|
@ -797,7 +797,7 @@ public class P2DeviceAdd {
|
||||||
Assert.assertNotNull(k.getDevId());
|
Assert.assertNotNull(k.getDevId());
|
||||||
});
|
});
|
||||||
|
|
||||||
DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddress("10.88.77.15", "", DisposeDeviceType.DPTECH_UMC
|
DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddrAndType("10.88.77.15", "", DisposeDeviceType.DPTECH_UMC
|
||||||
.getValue());
|
.getValue());
|
||||||
Assert.assertNotNull(dev);
|
Assert.assertNotNull(dev);
|
||||||
|
|
||||||
|
|
|
@ -985,7 +985,7 @@ public class P2DeviceUpgrade {
|
||||||
Assert.assertNotNull(k.getDevStatus());
|
Assert.assertNotNull(k.getDevStatus());
|
||||||
});
|
});
|
||||||
|
|
||||||
DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddress("127.0.0.1", "", DisposeDeviceType.VIRTUAL_DISPOSE
|
DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddrAndType("127.0.0.1", "", DisposeDeviceType.VIRTUAL_DISPOSE
|
||||||
.getValue());
|
.getValue());
|
||||||
Assert.assertNotNull(dev);
|
Assert.assertNotNull(dev);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue