diff --git a/pom.xml b/pom.xml index dac750f..0d01611 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.alipay.sofa sofaboot-dependencies - 3.0.0 + 3.3.0 sofa-dashboard diff --git a/sofa-dashboard-backend/pom.xml b/sofa-dashboard-backend/pom.xml index 2cf385f..56da1d6 100644 --- a/sofa-dashboard-backend/pom.xml +++ b/sofa-dashboard-backend/pom.xml @@ -87,6 +87,12 @@ ${mysql.connector.version} + + net.minidev + accessors-smart + 1.2 + + com.alibaba diff --git a/sofa-dashboard-backend/sofa-dashboard-application/src/test/java/com/alipay/sofa/dashboard/app/MonitorServiceTest.java b/sofa-dashboard-backend/sofa-dashboard-application/src/test/java/com/alipay/sofa/dashboard/app/MonitorServiceTest.java index 77775ce..bbee4a7 100644 --- a/sofa-dashboard-backend/sofa-dashboard-application/src/test/java/com/alipay/sofa/dashboard/app/MonitorServiceTest.java +++ b/sofa-dashboard-backend/sofa-dashboard-application/src/test/java/com/alipay/sofa/dashboard/app/MonitorServiceTest.java @@ -134,6 +134,6 @@ public void fetchMappingsTest() { private HostAndPort randomInstance() { String host = UUID.randomUUID().toString().replace("-", "").substring(8); int port = random.nextInt(65536); - return new HostAndPort(host, port); + return new HostAndPort(host, host, port); } } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml index ef21e52..99433fa 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml +++ b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml @@ -35,9 +35,24 @@ sofa-dashboard-application + + net.minidev + accessors-smart + + com.alipay.sofa rpc-sofa-boot-starter + + + activation + javax.activation + + + commons-io + commons-io + + com.alipay.sofa diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/model/InstanceRecord.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/model/InstanceRecord.java index 1db3d5c..c052bb1 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/model/InstanceRecord.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/model/InstanceRecord.java @@ -25,30 +25,30 @@ */ public class InstanceRecord extends Application { - public InstanceRecord() { - } + public InstanceRecord() { + } - public InstanceRecord(Application other) { - setAppName(other.getAppName()); - setHostName(other.getHostName()); - setInternalHost(other.getInternalHost()); - setPort(other.getPort()); - setAppState(other.getAppState()); - setStartTime(other.getStartTime()); - setLastRecover(other.getLastRecover()); - } + public InstanceRecord(Application other) { + setAppName(other.getAppName()); + setHostName(other.getHostName()); + setInternalHost(other.getInternalHost()); + setPort(other.getPort()); + setAppState(other.getAppState()); + setStartTime(other.getStartTime()); + setLastRecover(other.getLastRecover()); + } - /** - * Id 是接口层概念,用来和前端交换一个短的 host&port 描述 - * - * @return 唯一id - */ - public String getId() { - return HostPortUtils.uniqueId(new HostAndPort(getHostName(), getInternalHost(), getPort())); - } + /** + * Id 是接口层概念,用来和前端交换一个短的 host&port 描述 + * + * @return 唯一id + */ + public String getId() { + return HostPortUtils.uniqueId(new HostAndPort(getHostName(), getInternalHost(), getPort())); + } - public void setId(String instanceId) { - // Do nothing for json serializer - } + public void setId(String instanceId) { + // Do nothing for json serializer + } } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/utils/HostPortUtils.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/utils/HostPortUtils.java index f36d6ef..7dcdc33 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/utils/HostPortUtils.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/utils/HostPortUtils.java @@ -30,142 +30,142 @@ */ public final class HostPortUtils { - /** - * 0~255 - */ - private static final String SEGMENT_REG = "((2[0-4]\\d)|(25[0-5])|(1\\d{2})|([1-9]\\d)|(\\d))"; + /** + * 0~255 + */ + private static final String SEGMENT_REG = "((2[0-4]\\d)|(25[0-5])|(1\\d{2})|([1-9]\\d)|(\\d))"; - private static final Pattern IP_PATTERN = getIpv4Reg(); + private static final Pattern IP_PATTERN = getIpv4Reg(); - /** - * 工具类隐藏构造方法 - */ - private HostPortUtils() { - } + /** + * 工具类隐藏构造方法 + */ + private HostPortUtils() { + } - /** - * 根据 Host and port 获取唯一id - * - * @param hostAndPort - * 地址 - * @return 唯一id:(真实IP+内部IP)编码 & 端口编码 - */ - public static String uniqueId(HostAndPort hostAndPort) { - long ipSeg = toDigital(hostAndPort.getHost(), 0); - long portSeg = ((long) hostAndPort.getPort() & 0xFFFF); - String internalHost = hostAndPort.getInternalHost(); - if (StringUtils.isEmpty(internalHost) == false) { - long internalIpSeg = toDigital(internalHost, 1); - return Long.toHexString(ipSeg + internalIpSeg) + "&" + Long.toHexString(portSeg); - } else { - return Long.toHexString(ipSeg) + "&" + Long.toHexString(portSeg); - } - } + /** + * 根据 Host and port 获取唯一id + * + * @param hostAndPort + * 地址 + * @return 唯一id:(真实IP+内部IP)编码 & 端口编码 + */ + public static String uniqueId(HostAndPort hostAndPort) { + long ipSeg = toDigital(hostAndPort.getHost(), 0); + long portSeg = ((long) hostAndPort.getPort() & 0xFFFF); + String internalHost = hostAndPort.getInternalHost(); + if (StringUtils.isEmpty(internalHost) == false) { + long internalIpSeg = toDigital(internalHost, 1); + return Long.toHexString(ipSeg + internalIpSeg) + "&" + Long.toHexString(portSeg); + } else { + return Long.toHexString(ipSeg) + "&" + Long.toHexString(portSeg); + } + } - /** - * 从id中获取ipv4地址 - * - * @param uniqueId - * 唯一id - * @return ipv4地址 - */ - public static HostAndPort getById(String uniqueId) { - String[] segment = uniqueId.split("&"); - int port = ((Number) (Long.parseLong(segment[1], 16) & 0xFFFF)).intValue(); - long ipPartSeg = Long.parseLong(segment[0], 16); - String ipv4 = fromDigital(ipPartSeg & 0xFFFFFFFFL); - long virtualPart = ipPartSeg >> 32; - if (virtualPart <= 0) { - return new HostAndPort(ipv4, null, port); - } else { - String virtualIp = fromDigital(virtualPart & 0xFFFFFFFFL); - return new HostAndPort(ipv4, virtualIp, port); - } - } + /** + * 从id中获取ipv4地址 + * + * @param uniqueId + * 唯一id + * @return ipv4地址 + */ + public static HostAndPort getById(String uniqueId) { + String[] segment = uniqueId.split("&"); + int port = ((Number) (Long.parseLong(segment[1], 16) & 0xFFFF)).intValue(); + long ipPartSeg = Long.parseLong(segment[0], 16); + String ipv4 = fromDigital(ipPartSeg & 0xFFFFFFFFL); + long virtualPart = ipPartSeg >> 32; + if (virtualPart <= 0) { + return new HostAndPort(ipv4, null, port); + } else { + String virtualIp = fromDigital(virtualPart & 0xFFFFFFFFL); + return new HostAndPort(ipv4, virtualIp, port); + } + } - /** - * ipv4正则 - * - * @return 正则对象 - */ - private static Pattern getIpv4Reg() { - StringJoiner sj = new StringJoiner("\\."); - sj.add(SEGMENT_REG); - sj.add(SEGMENT_REG); - sj.add(SEGMENT_REG); - sj.add(SEGMENT_REG); - return Pattern.compile(sj.toString()); - } + /** + * ipv4正则 + * + * @return 正则对象 + */ + private static Pattern getIpv4Reg() { + StringJoiner sj = new StringJoiner("\\."); + sj.add(SEGMENT_REG); + sj.add(SEGMENT_REG); + sj.add(SEGMENT_REG); + sj.add(SEGMENT_REG); + return Pattern.compile(sj.toString()); + } - /** - * 非法ipv4抛异常 - * - * @param ipv4 - * ipv4 - */ - private static void checkIPv4(String ipv4) { - if (!isLegalV4(ipv4)) { - throw new IllegalArgumentException("Illegal ipv4 value " + ipv4); - } - } + /** + * 非法ipv4抛异常 + * + * @param ipv4 + * ipv4 + */ + private static void checkIPv4(String ipv4) { + if (!isLegalV4(ipv4)) { + throw new IllegalArgumentException("Illegal ipv4 value " + ipv4); + } + } - /** - * ip转换为对应32bit数字 - * - * @param ipv4 - * 点分十进制ipv4 - * @param segmentPart - * TODO - * @return ipv4 对应数字 - */ - private static long toDigital(String ipv4, int segmentPart) { - checkIPv4(ipv4); - String[] segments = ipv4.split("\\."); - long result = 0; - for (int i = 0; i < 4; i++) { - result += Long.parseLong(segments[3 - i]) << ((8 * i) + segmentPart * Integer.SIZE); - } - return result; - } + /** + * ip转换为对应32bit数字 + * + * @param ipv4 + * 点分十进制ipv4 + * @param segmentPart + * TODO + * @return ipv4 对应数字 + */ + private static long toDigital(String ipv4, int segmentPart) { + checkIPv4(ipv4); + String[] segments = ipv4.split("\\."); + long result = 0; + for (int i = 0; i < 4; i++) { + result += Long.parseLong(segments[3 - i]) << ((8 * i) + segmentPart * Integer.SIZE); + } + return result; + } - /** - * 检查是否合法ipv4 - * - * @param ipv4 - * ipv4地址 - * @return 是否匹配 - */ - private static boolean isLegalV4(String ipv4) { - return !StringUtils.isEmpty(ipv4) && IP_PATTERN.matcher(ipv4).matches(); - } + /** + * 检查是否合法ipv4 + * + * @param ipv4 + * ipv4地址 + * @return 是否匹配 + */ + private static boolean isLegalV4(String ipv4) { + return !StringUtils.isEmpty(ipv4) && IP_PATTERN.matcher(ipv4).matches(); + } - /** - * 数字转换为string ip格式 - * - * @param ipv4 - * 32位数字ip - * @return 点分十进制ip - */ - public static String fromDigital(Long ipv4) { - if (ipv4 > 0xFFFFFFFFL || ipv4 < 0) { - throw new IllegalArgumentException("Illegal ipv4 digital " + ipv4); - } - int[] segments = new int[4]; - for (int i = 0; i < 4; i++) { - segments[3 - i] = ipv4.intValue() & 0xFF; - ipv4 >>= 8; - } - StringJoiner sj = new StringJoiner("."); - for (int segment : segments) { - sj.add(String.valueOf(segment)); - } - return sj.toString(); - } + /** + * 数字转换为string ip格式 + * + * @param ipv4 + * 32位数字ip + * @return 点分十进制ip + */ + public static String fromDigital(Long ipv4) { + if (ipv4 > 0xFFFFFFFFL || ipv4 < 0) { + throw new IllegalArgumentException("Illegal ipv4 digital " + ipv4); + } + int[] segments = new int[4]; + for (int i = 0; i < 4; i++) { + segments[3 - i] = ipv4.intValue() & 0xFF; + ipv4 >>= 8; + } + StringJoiner sj = new StringJoiner("."); + for (int segment : segments) { + sj.add(String.valueOf(segment)); + } + return sj.toString(); + } - public static void main(String[] args) { - String id = uniqueId(new HostAndPort("192.168.0.104", "8.16.32.64", 38081)); - System.out.println(id); - HostAndPort hostAndPort = getById(id); - System.out.println(hostAndPort); - } + public static void main(String[] args) { + String id = uniqueId(new HostAndPort("192.168.0.104", "8.16.32.64", 38081)); + System.out.println(id); + HostAndPort hostAndPort = getById(id); + System.out.println(hostAndPort); + } }