From be94f817a604448e13e020c3544db905d5f3b729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Fri, 9 Jul 2021 17:03:57 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=8F=AF=E8=A7=86=E5=8C=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sofa-dashboard-web/pom.xml | 11 + .../configuration/Swagger2Config.java | 40 +++ .../sofa/dashboard/model/InstanceRecord.java | 44 +-- .../sofa/dashboard/utils/HostPortUtils.java | 256 +++++++++--------- 4 files changed, 201 insertions(+), 150 deletions(-) create mode 100644 sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java diff --git a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml index ef21e52..fbebcf3 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml +++ b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml @@ -18,6 +18,17 @@ + + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.2 + + + com.google.guava + guava + 20.0 + com.alipay.sofa sofa-dashboard-governance diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java new file mode 100644 index 0000000..b9d3d46 --- /dev/null +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java @@ -0,0 +1,40 @@ +package com.alipay.sofa.dashboard.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2Config { + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .useDefaultResponseMessages(false) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller")) + .paths(PathSelectors.any()) + .build(); + + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("SOFADashboard APIs") + .description("SOFADashboard 接口对接文档") + .termsOfServiceUrl("http://localhost:8099/") + .version("1.0") + .build(); + } + + + +} 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); + } } From 05f6b80de9b9626f2d35b71aafff1b0a8f9b33fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Fri, 9 Jul 2021 17:42:53 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E6=8A=8Aknife=E7=89=88=E6=9C=AC=E6=8D=A2?= =?UTF-8?q?=E6=88=903.0.2=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sofa-dashboard-backend/sofa-dashboard-web/pom.xml | 6 +++++- .../src/main/resources/application-knife4j.yml | 0 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-knife4j.yml diff --git a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml index fbebcf3..7bb0354 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml +++ b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml @@ -22,13 +22,17 @@ com.github.xiaoymin knife4j-spring-boot-starter - 2.0.2 + 3.0.2 + com.google.guava guava 20.0 + + + com.alipay.sofa sofa-dashboard-governance diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-knife4j.yml b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-knife4j.yml new file mode 100644 index 0000000..e69de29 From b5862572d11368d2c36525f856092d8209d06288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Fri, 9 Jul 2021 19:53:35 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E6=8A=8Aknife=E7=89=88=E6=9C=AC=E6=8D=A2?= =?UTF-8?q?=E6=88=902.0.7=E7=89=88=E6=9C=AC=E6=94=AF=E6=8C=81=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sofa-dashboard-backend/sofa-dashboard-web/pom.xml | 8 ++++++-- .../sofa/dashboard/configuration/Swagger2Config.java | 6 ++++-- .../sofa/dashboard/controller/ArkAppMngController.java | 2 ++ .../src/main/resources/application-knife4j.yml | 9 +++++++++ .../src/main/resources/application.properties | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml index 7bb0354..c0c46d7 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml +++ b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml @@ -22,7 +22,7 @@ com.github.xiaoymin knife4j-spring-boot-starter - 3.0.2 + 2.0.7 @@ -31,7 +31,11 @@ 20.0 - + + org.springframework.plugin + spring-plugin-core + 2.0.0.RELEASE + com.alipay.sofa diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java index b9d3d46..1aa7f90 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java @@ -9,16 +9,18 @@ import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + @Configuration -@EnableSwagger2 +@EnableSwagger2WebMvc public class Swagger2Config { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .useDefaultResponseMessages(false) .apiInfo(apiInfo()) + .groupName("1.0版本") .select() .apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller")) .paths(PathSelectors.any()) diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java index 01bcb2b..858b6a8 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java @@ -27,6 +27,7 @@ import com.alipay.sofa.dashboard.response.ResponseEntity; import com.alipay.sofa.dashboard.service.ArkMngService; import com.alipay.sofa.dashboard.spi.CommandPushManager; +import io.swagger.annotations.Api; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +45,7 @@ * @author: guolei.sgl (guolei.sgl@antfin.com) 18/12/21 下午2:26 * @since: **/ + @RestController @RequestMapping("/api/arkapp") public class ArkAppMngController { diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-knife4j.yml b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-knife4j.yml index e69de29..a9f3796 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-knife4j.yml +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-knife4j.yml @@ -0,0 +1,9 @@ +knife4j: + enable: true + + +# 开启验证 +# basic: +# password: 123456 +# username: root +# enable: true \ No newline at end of file diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application.properties b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application.properties index e54f3f7..1b9ae77 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application.properties +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application.properties @@ -15,4 +15,4 @@ mybatis.config-location=classpath:spring/mybatis-configuration.xml # server port server.port=8099 -spring.profiles.active=localhost +spring.profiles.active=localhost,knife4j From a96d55ae1cced96a5371767265afbd4225412281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Sat, 10 Jul 2021 16:58:28 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/dashboard/dao/ArkDao.java | 8 +++++ .../dashboard/impl/ArkMngServiceImpl.java | 32 +++++++++++-------- .../sofa/dashboard/service/ArkMngService.java | 7 ++++ .../resources/spring/mybatis/ArkMapper.xml | 3 ++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java index 70a7b2e..3492412 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java @@ -167,4 +167,12 @@ ArkModuleVersionDO queryByModuleIdAndModuleVersion(@Param("moduleId") int module * @return */ int deletePluginVersion(@Param("id") int id, @Param("version") String version); + + /*** + * 根据模块id和应用名字 获取模块-应用关联信息 + * @param mId + * @param appName + * @return + */ + List queryRelationByModuleIdAndAppName(int mId,String appName); } diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java index c4288d8..c608eea 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java @@ -16,12 +16,10 @@ */ package com.alipay.sofa.dashboard.impl; +import com.alipay.sofa.ark.spi.service.ArkService; +import com.alipay.sofa.dashboard.app.AppServiceImpl; import com.alipay.sofa.dashboard.dao.ArkDao; -import com.alipay.sofa.dashboard.model.AppArkDO; -import com.alipay.sofa.dashboard.model.ArkModuleUserDO; -import com.alipay.sofa.dashboard.model.ArkModuleVersionDO; -import com.alipay.sofa.dashboard.model.ArkPluginDO; -import com.alipay.sofa.dashboard.model.ArkPluginModel; +import com.alipay.sofa.dashboard.model.*; import com.alipay.sofa.dashboard.service.ArkMngService; import com.alipay.sofa.dashboard.utils.SofaDashboardUtil; import org.slf4j.Logger; @@ -29,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; @@ -45,8 +44,11 @@ public class ArkMngServiceImpl implements ArkMngService { private static final Logger LOGGER = LoggerFactory.getLogger(ArkMngServiceImpl.class); @Autowired - private ArkDao arkDao; - + private ArkDao arkDao; + @Override + public boolean isRelatedByModuleAndApp(int mId, String appName) { + return arkDao.queryRelationByModuleIdAndAppName(mId, appName).size() > 0; + } @Override public List fetchRegisteredPlugins() { return doFetchPluginsByName(null); @@ -121,12 +123,16 @@ public int relatedAppToPlugin(int moduleId, String appName) { if (moduleId < 0) { return -1; } - AppArkDO appArkDO = new AppArkDO(); - appArkDO.setAppName(appName); - appArkDO.setCreateTime(SofaDashboardUtil.now()); - appArkDO.setModuleId(moduleId); - arkDao.insertAppArk(appArkDO); - return appArkDO.getId(); + if (isRelatedByModuleAndApp(moduleId, appName) == false) + { + AppArkDO appArkDO = new AppArkDO(); + appArkDO.setAppName(appName); + appArkDO.setCreateTime(SofaDashboardUtil.now()); + appArkDO.setModuleId(moduleId); + arkDao.insertAppArk(appArkDO); + return appArkDO.getId(); + } + return -1; } @Override diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java index d1379bf..496fad5 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java @@ -28,6 +28,13 @@ **/ public interface ArkMngService { + /*** + * 根据模块Id和应用名字 获取模块是否已关联该应用 + * @param mId + * @param appName + * @return + */ + boolean isRelatedByModuleAndApp(int mId,String appName); /** * 获取当前所有注册的 plugin 信息 * diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/spring/mybatis/ArkMapper.xml b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/spring/mybatis/ArkMapper.xml index 7c28b2c..2b03cf3 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/spring/mybatis/ArkMapper.xml +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/spring/mybatis/ArkMapper.xml @@ -95,6 +95,9 @@ select * from ark_module_version where module_id=#{moduleId} and module_version=#{moduleVersion} + update ark_module_info set plugin_name = #{pluginName}, description = #{description} where id=#{id} From 81c500b11d98926d31d1f0b0322c9cec9aa049a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Sat, 10 Jul 2021 16:59:48 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/impl/ArkMngServiceImpl.java | 22 ++++++---- .../alipay/sofa/dashboard/impl/ZkHelper.java | 44 ++++++++++++++----- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java index c608eea..ff3523b 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java @@ -45,6 +45,8 @@ public class ArkMngServiceImpl implements ArkMngService { @Autowired private ArkDao arkDao; + @Autowired + private ZkHelper zkHelper; @Override public boolean isRelatedByModuleAndApp(int mId, String appName) { return arkDao.queryRelationByModuleIdAndAppName(mId, appName).size() > 0; @@ -123,14 +125,18 @@ public int relatedAppToPlugin(int moduleId, String appName) { if (moduleId < 0) { return -1; } - if (isRelatedByModuleAndApp(moduleId, appName) == false) - { - AppArkDO appArkDO = new AppArkDO(); - appArkDO.setAppName(appName); - appArkDO.setCreateTime(SofaDashboardUtil.now()); - appArkDO.setModuleId(moduleId); - arkDao.insertAppArk(appArkDO); - return appArkDO.getId(); + List arkAppList = zkHelper.getArkAppList(); + boolean relatedByModuleAndApp = isRelatedByModuleAndApp(moduleId, appName); + for (String appApp : arkAppList) { + //zk中已存在应用 并且 未关联 + if (appApp.equals(appName) && isRelatedByModuleAndApp(moduleId,appName)==false) { + AppArkDO appArkDO = new AppArkDO(); + appArkDO.setAppName(appName); + appArkDO.setCreateTime(SofaDashboardUtil.now()); + appArkDO.setModuleId(moduleId); + arkDao.insertAppArk(appArkDO); + return appArkDO.getId(); + } } return -1; } diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java index dfbc8e6..7d867bb 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java @@ -53,7 +53,6 @@ public class ZkHelper { @Autowired ZkCommandClient zkCommandClient; - /** * 根据应用名获取当前应用的所有实例 * @@ -87,7 +86,7 @@ private List getInstanceIpList(String appName) { List result = null; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT - + SofaDashboardConstants.SEPARATOR + appName; + + SofaDashboardConstants.SEPARATOR + appName; try { if (checkExist(arkAppBasePath, curatorClient)) { // 根据应用名获取所有实例信息 @@ -103,6 +102,29 @@ private List getInstanceIpList(String appName) { return result; } + /** + * 获取 /sofa-ark 下面所有的应用 + * @return + */ + public List getArkAppList( ) { + List result = null; + CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); + String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT; + try { + if (checkExist(arkAppBasePath, curatorClient)) { + // 获取所有应用信息 + result = curatorClient.getChildren().forPath(arkAppBasePath); + } + } catch (Exception e) { + LOGGER.error("Failed to get ark app list.", e); + } finally { + if (result == null) { + result = new ArrayList<>(); + } + } + return result; + } + /** * 获取当前应用实例的个数 * @@ -136,13 +158,13 @@ private boolean checkExist(String path, CuratorFramework curatorClient) { * @return */ public String getAppState(String appName, String ip, String pluginName, String version) - throws Exception { + throws Exception { String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT - + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; + + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); if (curatorClient.checkExists().forPath(bizPath) != null) { String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName - + SofaDashboardConstants.SEPARATOR + ip; + + SofaDashboardConstants.SEPARATOR + ip; if (curatorClient.checkExists().forPath(bizAppPath) != null) { byte[] bytes = curatorClient.getData().forPath(bizAppPath); String data = new String(bytes); @@ -154,7 +176,7 @@ public String getAppState(String appName, String ip, String pluginName, String v String bizName = FastJsonUtils.getString(item, "bizName"); String bizVersion = FastJsonUtils.getString(item, "bizVersion"); if (bizName.equalsIgnoreCase(pluginName) - && bizVersion.equalsIgnoreCase(version)) { + && bizVersion.equalsIgnoreCase(version)) { return FastJsonUtils.getString(item, "bizState"); } } @@ -172,11 +194,11 @@ public String getAppState(String appName, String ip, String pluginName, String v public ClientResponseModel getBizState(String appName, String ip) throws Exception { ClientResponseModel result = new ClientResponseModel(); String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT - + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; + + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); if (curatorClient.checkExists().forPath(bizPath) != null) { String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName - + SofaDashboardConstants.SEPARATOR + ip; + + SofaDashboardConstants.SEPARATOR + ip; if (curatorClient.checkExists().forPath(bizAppPath) != null) { byte[] bytes = curatorClient.getData().forPath(bizAppPath); String data = new String(bytes); @@ -199,12 +221,12 @@ public ClientResponseModel getBizState(String appName, String ip) throws Excepti bizModel.setClassPath(getUrls("classPath", item)); bizModel.setDenyImportClasses(parseBizStateByKey("denyImportClasses", item)); bizModel.setDenyImportPackageNodes(parseBizStateByKey("denyImportPackageNodes", - item)); + item)); bizModel.setDenyImportPackageStems(parseBizStateByKey("denyImportPackageStems", - item)); + item)); bizModel.setDenyImportPackages(parseBizStateByKey("denyImportPackages", item)); bizModel - .setDenyImportResources(parseBizStateByKey("denyImportResources", item)); + .setDenyImportResources(parseBizStateByKey("denyImportResources", item)); bizModel.setWebContextPath(FastJsonUtils.getString(item, "webContextPath")); bizModel.setPriority(FastJsonUtils.getInteger(item, "priority")); bizModel.setBizClassLoader(getClassLoader(item)); From fce71efbc511ead5515cc5204dec2815439d3491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Sat, 10 Jul 2021 22:53:38 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E5=AF=B9ark=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B7=BB=E5=8A=A0=E4=B8=AD=E6=96=87=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/SofaDashboardConstants.java | 6 ++++ .../controller/ApplicationController.java | 7 +++++ .../controller/ArkMngController.java | 28 +++++++++++++++---- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java index 9cd7d61..b732886 100644 --- a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java +++ b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java @@ -70,4 +70,10 @@ public class SofaDashboardConstants { public static final String ZOOKEEPER_PREFIX = "zookeeper://"; public static final String SOFA_PREFIX = "sofa://"; +// API接口类 + public static final String API_ARK_TAGS = "Ark相关接口"; + public static final String API_APPLICATION_TAGS = "Application相关接口"; + public static final String API_GOVERNANCE_TAGS = "Governance相关接口"; + public static final String API_WEB_TAGS = "Web相关接口"; + } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java index 5ec1a45..8142793 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java @@ -16,9 +16,13 @@ */ package com.alipay.sofa.dashboard.controller; +import com.alipay.sofa.dashboard.constants.SofaDashboardConstants; import com.alipay.sofa.dashboard.model.ApplicationInfo; import com.alipay.sofa.dashboard.spi.AppService; import com.alipay.sofa.rpc.common.utils.StringUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,12 +35,15 @@ * @author guolei.sgl (guolei.sgl@antfin.com) 18/12/7 下午5:15 */ @RestController +@Api(value = SofaDashboardConstants.API_APPLICATION_TAGS,tags = SofaDashboardConstants.API_APPLICATION_TAGS) @RequestMapping("/api/application") public class ApplicationController { @Autowired private AppService appService; + + @ApiOperation(value = "获取应用信息") @GetMapping public List getApplication(@RequestParam(value = "keyword", required = false) String keyword) { return StringUtils.isEmpty(keyword) ? appService.getAllStatistics() : appService diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java index 45bcc10..b39d540 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java @@ -25,6 +25,9 @@ import com.alipay.sofa.dashboard.response.ResponseEntity; import com.alipay.sofa.dashboard.service.ArkMngService; import com.alipay.sofa.dashboard.utils.SofaDashboardUtil; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +45,7 @@ * @author: guolei.sgl (guolei.sgl@antfin.com) 18/12/19 上午11:06 * @since: **/ +@Api(value = SofaDashboardConstants.API_ARK_TAGS,tags = SofaDashboardConstants.API_ARK_TAGS) @RestController @RequestMapping("/api/ark") public class ArkMngController { @@ -59,6 +63,8 @@ public class ArkMngController { * * @return */ + @ApiOperation(value = "查询全部插件",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 1) @RequestMapping("/plugin-list") public List queryArkPluginList() { List list = arkMngService.fetchRegisteredPlugins(); @@ -87,6 +93,9 @@ public List queryArkPluginList() { * @param map * @return */ + @ApiOperation(value = "注册插件",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperationSupport(order = 2) @RequestMapping("/register") public boolean registerPlugin(@RequestBody Map map) { if (map == null) { @@ -98,6 +107,8 @@ public boolean registerPlugin(@RequestBody Map map) { return arkMngService.registerPlugin(arkPluginDO); } + @ApiOperation(value = "更新插件",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 3) @RequestMapping("/update-plugin") public boolean updatePlugin(@RequestBody ArkPluginDO arkPluginDO) { if (arkPluginDO == null) { @@ -106,6 +117,8 @@ public boolean updatePlugin(@RequestBody ArkPluginDO arkPluginDO) { return arkMngService.updatePlugin(arkPluginDO); } + @ApiOperation(value = "更新插件版本",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 4) @RequestMapping("/register-new-version") public boolean registerNewVersion(@RequestBody Map map) { if (map == null) { @@ -120,7 +133,8 @@ public boolean registerNewVersion(@RequestBody Map map) { } return arkMngService.addNewVersion(Integer.valueOf(id), version, address); } - + @ApiOperation(value = "删除插件版本",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 8) @RequestMapping("/delete-version") public ResponseEntity deleteVersion(@RequestParam("id") int id, @RequestParam("version") String version) { @@ -136,7 +150,8 @@ public ResponseEntity deleteVersion(@RequestParam("id") int id, } return result; } - + @ApiOperation(value = "删除插件",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 9) @RequestMapping("/delete-plugin") public boolean deletePluginModel(@RequestParam("id") int id) { if (id < 0) { @@ -144,7 +159,8 @@ public boolean deletePluginModel(@RequestParam("id") int id) { } return arkMngService.removePlugins(id); } - + @ApiOperation(value = "查询插件",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 7) @RequestMapping("/search-plugin") public List searchPlugins(@RequestParam("pluginName") String pluginName) { if (StringUtils.isEmpty(pluginName)) { @@ -153,12 +169,14 @@ public List searchPlugins(@RequestParam("pluginName") String plu } return arkMngService.fetchPluginsByName(pluginName); } - + @ApiOperation(value = "关联应用",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 5) @RequestMapping("/related-app") public boolean relatedApp(@RequestParam("id") int id, @RequestParam("appName") String appName) { return arkMngService.relatedAppToPlugin(id, appName) > 0; } - + @ApiOperation(value = "取消关联应用",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperationSupport(order = 6) @RequestMapping("/cancel-related-app") public boolean cancelRelatedApp(@RequestParam("pluginName") String pluginName, @RequestParam("appName") String appName) { From 749375f924416c308ac6c41de1fbcb691328a3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Mon, 12 Jul 2021 16:27:25 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0docker-compose=E4=B8=80?= =?UTF-8?q?=E9=94=AE=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/dashboard/dao/ArkDao.java | 2 +- .../dashboard/impl/ArkMngServiceImpl.java | 8 ++-- .../alipay/sofa/dashboard/impl/ZkHelper.java | 23 +++++------ .../sofa/dashboard/service/ArkMngService.java | 3 +- .../constants/SofaDashboardConstants.java | 10 ++--- .../configuration/Swagger2Config.java | 39 +++++++++++-------- .../controller/ApplicationController.java | 2 +- .../controller/ArkMngController.java | 24 +++++++----- .../application-localhost.properties | 6 +-- 9 files changed, 65 insertions(+), 52 deletions(-) diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java index 3492412..3bb8f5e 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java @@ -174,5 +174,5 @@ ArkModuleVersionDO queryByModuleIdAndModuleVersion(@Param("moduleId") int module * @param appName * @return */ - List queryRelationByModuleIdAndAppName(int mId,String appName); + List queryRelationByModuleIdAndAppName(int mId, String appName); } diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java index ff3523b..232a592 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java @@ -44,13 +44,15 @@ public class ArkMngServiceImpl implements ArkMngService { private static final Logger LOGGER = LoggerFactory.getLogger(ArkMngServiceImpl.class); @Autowired - private ArkDao arkDao; + private ArkDao arkDao; @Autowired - private ZkHelper zkHelper; + private ZkHelper zkHelper; + @Override public boolean isRelatedByModuleAndApp(int mId, String appName) { return arkDao.queryRelationByModuleIdAndAppName(mId, appName).size() > 0; } + @Override public List fetchRegisteredPlugins() { return doFetchPluginsByName(null); @@ -129,7 +131,7 @@ public int relatedAppToPlugin(int moduleId, String appName) { boolean relatedByModuleAndApp = isRelatedByModuleAndApp(moduleId, appName); for (String appApp : arkAppList) { //zk中已存在应用 并且 未关联 - if (appApp.equals(appName) && isRelatedByModuleAndApp(moduleId,appName)==false) { + if (appApp.equals(appName) && isRelatedByModuleAndApp(moduleId, appName) == false) { AppArkDO appArkDO = new AppArkDO(); appArkDO.setAppName(appName); appArkDO.setCreateTime(SofaDashboardUtil.now()); diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java index 7d867bb..511d8b8 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java @@ -53,6 +53,7 @@ public class ZkHelper { @Autowired ZkCommandClient zkCommandClient; + /** * 根据应用名获取当前应用的所有实例 * @@ -86,7 +87,7 @@ private List getInstanceIpList(String appName) { List result = null; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT - + SofaDashboardConstants.SEPARATOR + appName; + + SofaDashboardConstants.SEPARATOR + appName; try { if (checkExist(arkAppBasePath, curatorClient)) { // 根据应用名获取所有实例信息 @@ -106,7 +107,7 @@ private List getInstanceIpList(String appName) { * 获取 /sofa-ark 下面所有的应用 * @return */ - public List getArkAppList( ) { + public List getArkAppList() { List result = null; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT; @@ -158,13 +159,13 @@ private boolean checkExist(String path, CuratorFramework curatorClient) { * @return */ public String getAppState(String appName, String ip, String pluginName, String version) - throws Exception { + throws Exception { String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT - + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; + + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); if (curatorClient.checkExists().forPath(bizPath) != null) { String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName - + SofaDashboardConstants.SEPARATOR + ip; + + SofaDashboardConstants.SEPARATOR + ip; if (curatorClient.checkExists().forPath(bizAppPath) != null) { byte[] bytes = curatorClient.getData().forPath(bizAppPath); String data = new String(bytes); @@ -176,7 +177,7 @@ public String getAppState(String appName, String ip, String pluginName, String v String bizName = FastJsonUtils.getString(item, "bizName"); String bizVersion = FastJsonUtils.getString(item, "bizVersion"); if (bizName.equalsIgnoreCase(pluginName) - && bizVersion.equalsIgnoreCase(version)) { + && bizVersion.equalsIgnoreCase(version)) { return FastJsonUtils.getString(item, "bizState"); } } @@ -194,11 +195,11 @@ public String getAppState(String appName, String ip, String pluginName, String v public ClientResponseModel getBizState(String appName, String ip) throws Exception { ClientResponseModel result = new ClientResponseModel(); String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT - + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; + + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); if (curatorClient.checkExists().forPath(bizPath) != null) { String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName - + SofaDashboardConstants.SEPARATOR + ip; + + SofaDashboardConstants.SEPARATOR + ip; if (curatorClient.checkExists().forPath(bizAppPath) != null) { byte[] bytes = curatorClient.getData().forPath(bizAppPath); String data = new String(bytes); @@ -221,12 +222,12 @@ public ClientResponseModel getBizState(String appName, String ip) throws Excepti bizModel.setClassPath(getUrls("classPath", item)); bizModel.setDenyImportClasses(parseBizStateByKey("denyImportClasses", item)); bizModel.setDenyImportPackageNodes(parseBizStateByKey("denyImportPackageNodes", - item)); + item)); bizModel.setDenyImportPackageStems(parseBizStateByKey("denyImportPackageStems", - item)); + item)); bizModel.setDenyImportPackages(parseBizStateByKey("denyImportPackages", item)); bizModel - .setDenyImportResources(parseBizStateByKey("denyImportResources", item)); + .setDenyImportResources(parseBizStateByKey("denyImportResources", item)); bizModel.setWebContextPath(FastJsonUtils.getString(item, "webContextPath")); bizModel.setPriority(FastJsonUtils.getInteger(item, "priority")); bizModel.setBizClassLoader(getClassLoader(item)); diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java index 496fad5..9ebd916 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java @@ -34,7 +34,8 @@ public interface ArkMngService { * @param appName * @return */ - boolean isRelatedByModuleAndApp(int mId,String appName); + boolean isRelatedByModuleAndApp(int mId, String appName); + /** * 获取当前所有注册的 plugin 信息 * diff --git a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java index b732886..09dc07d 100644 --- a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java +++ b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java @@ -70,10 +70,10 @@ public class SofaDashboardConstants { public static final String ZOOKEEPER_PREFIX = "zookeeper://"; public static final String SOFA_PREFIX = "sofa://"; -// API接口类 - public static final String API_ARK_TAGS = "Ark相关接口"; - public static final String API_APPLICATION_TAGS = "Application相关接口"; - public static final String API_GOVERNANCE_TAGS = "Governance相关接口"; - public static final String API_WEB_TAGS = "Web相关接口"; + // API接口类 + public static final String API_ARK_TAGS = "Ark相关接口"; + public static final String API_APPLICATION_TAGS = "Application相关接口"; + public static final String API_GOVERNANCE_TAGS = "Governance相关接口"; + public static final String API_WEB_TAGS = "Web相关接口"; } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java index 1aa7f90..3bc0a56 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alipay.sofa.dashboard.configuration; import org.springframework.context.annotation.Bean; @@ -11,32 +27,21 @@ import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; - @Configuration @EnableSwagger2WebMvc public class Swagger2Config { @Bean public Docket createRestApi() { - return new Docket(DocumentationType.SWAGGER_2) - .useDefaultResponseMessages(false) - .apiInfo(apiInfo()) - .groupName("1.0版本") - .select() - .apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller")) - .paths(PathSelectors.any()) - .build(); + return new Docket(DocumentationType.SWAGGER_2).useDefaultResponseMessages(false) + .apiInfo(apiInfo()).groupName("1.0版本").select() + .apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller")) + .paths(PathSelectors.any()).build(); } private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("SOFADashboard APIs") - .description("SOFADashboard 接口对接文档") - .termsOfServiceUrl("http://localhost:8099/") - .version("1.0") - .build(); + return new ApiInfoBuilder().title("SOFADashboard APIs").description("SOFADashboard 接口对接文档") + .termsOfServiceUrl("http://localhost:8099/").version("1.0").build(); } - - } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java index 8142793..9f714b5 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java @@ -35,7 +35,7 @@ * @author guolei.sgl (guolei.sgl@antfin.com) 18/12/7 下午5:15 */ @RestController -@Api(value = SofaDashboardConstants.API_APPLICATION_TAGS,tags = SofaDashboardConstants.API_APPLICATION_TAGS) +@Api(value = SofaDashboardConstants.API_APPLICATION_TAGS, tags = SofaDashboardConstants.API_APPLICATION_TAGS) @RequestMapping("/api/application") public class ApplicationController { diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java index b39d540..33a9957 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java @@ -45,7 +45,7 @@ * @author: guolei.sgl (guolei.sgl@antfin.com) 18/12/19 上午11:06 * @since: **/ -@Api(value = SofaDashboardConstants.API_ARK_TAGS,tags = SofaDashboardConstants.API_ARK_TAGS) +@Api(value = SofaDashboardConstants.API_ARK_TAGS, tags = SofaDashboardConstants.API_ARK_TAGS) @RestController @RequestMapping("/api/ark") public class ArkMngController { @@ -93,8 +93,7 @@ public List queryArkPluginList() { * @param map * @return */ - @ApiOperation(value = "注册插件",tags = SofaDashboardConstants.API_ARK_TAGS) - + @ApiOperation(value = "注册插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 2) @RequestMapping("/register") public boolean registerPlugin(@RequestBody Map map) { @@ -107,7 +106,7 @@ public boolean registerPlugin(@RequestBody Map map) { return arkMngService.registerPlugin(arkPluginDO); } - @ApiOperation(value = "更新插件",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperation(value = "更新插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 3) @RequestMapping("/update-plugin") public boolean updatePlugin(@RequestBody ArkPluginDO arkPluginDO) { @@ -117,7 +116,7 @@ public boolean updatePlugin(@RequestBody ArkPluginDO arkPluginDO) { return arkMngService.updatePlugin(arkPluginDO); } - @ApiOperation(value = "更新插件版本",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperation(value = "更新插件版本", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 4) @RequestMapping("/register-new-version") public boolean registerNewVersion(@RequestBody Map map) { @@ -133,7 +132,8 @@ public boolean registerNewVersion(@RequestBody Map map) { } return arkMngService.addNewVersion(Integer.valueOf(id), version, address); } - @ApiOperation(value = "删除插件版本",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "删除插件版本", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 8) @RequestMapping("/delete-version") public ResponseEntity deleteVersion(@RequestParam("id") int id, @@ -150,7 +150,8 @@ public ResponseEntity deleteVersion(@RequestParam("id") int id, } return result; } - @ApiOperation(value = "删除插件",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "删除插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 9) @RequestMapping("/delete-plugin") public boolean deletePluginModel(@RequestParam("id") int id) { @@ -159,7 +160,8 @@ public boolean deletePluginModel(@RequestParam("id") int id) { } return arkMngService.removePlugins(id); } - @ApiOperation(value = "查询插件",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "查询插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 7) @RequestMapping("/search-plugin") public List searchPlugins(@RequestParam("pluginName") String pluginName) { @@ -169,13 +171,15 @@ public List searchPlugins(@RequestParam("pluginName") String plu } return arkMngService.fetchPluginsByName(pluginName); } - @ApiOperation(value = "关联应用",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "关联应用", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 5) @RequestMapping("/related-app") public boolean relatedApp(@RequestParam("id") int id, @RequestParam("appName") String appName) { return arkMngService.relatedAppToPlugin(id, appName) > 0; } - @ApiOperation(value = "取消关联应用",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "取消关联应用", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 6) @RequestMapping("/cancel-related-app") public boolean cancelRelatedApp(@RequestParam("pluginName") String pluginName, diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties index 998c8a0..0b8a017 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties @@ -1,10 +1,10 @@ ## ark 管控端配置中心地址 ## mysql 数据库连接属性配置 -spring.datasource.url=jdbc:mysql://127.0.0.1:3306/SofaDashboardDB +spring.datasource.url=jdbc:mysql://mysql:3306/SofaDashboardDB spring.datasource.username=root spring.datasource.password=123456 ## zookeeper 注册中心地址 -com.alipay.sofa.dashboard.registry=zookeeper://127.0.0.1:2181 +com.alipay.sofa.dashboard.registry=zookeeper://zk01:2181 com.alipay.sofa.dashboard.redis.host=127.0.0.1 com.alipay.sofa.dashboard.redis.port=6379 -com.alipay.sofa.dashboard.zookeeper.address=127.0.0.1:2181 \ No newline at end of file +com.alipay.sofa.dashboard.zookeeper.address=zk01:2181 \ No newline at end of file From e8d55178fc7641ef1b9c0da8eaccfab2e8c1db0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Mon, 12 Jul 2021 16:27:25 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0docker-compose=E4=B8=80?= =?UTF-8?q?=E9=94=AE=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/dashboard/dao/ArkDao.java | 2 +- .../dashboard/impl/ArkMngServiceImpl.java | 8 ++-- .../alipay/sofa/dashboard/impl/ZkHelper.java | 23 +++++------ .../sofa/dashboard/service/ArkMngService.java | 3 +- .../constants/SofaDashboardConstants.java | 10 ++--- .../configuration/Swagger2Config.java | 39 +++++++++++-------- .../controller/ApplicationController.java | 2 +- .../controller/ArkMngController.java | 24 +++++++----- .../application-localhost.properties | 6 +-- 9 files changed, 65 insertions(+), 52 deletions(-) diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java index 3492412..3bb8f5e 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/dao/ArkDao.java @@ -174,5 +174,5 @@ ArkModuleVersionDO queryByModuleIdAndModuleVersion(@Param("moduleId") int module * @param appName * @return */ - List queryRelationByModuleIdAndAppName(int mId,String appName); + List queryRelationByModuleIdAndAppName(int mId, String appName); } diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java index ff3523b..232a592 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ArkMngServiceImpl.java @@ -44,13 +44,15 @@ public class ArkMngServiceImpl implements ArkMngService { private static final Logger LOGGER = LoggerFactory.getLogger(ArkMngServiceImpl.class); @Autowired - private ArkDao arkDao; + private ArkDao arkDao; @Autowired - private ZkHelper zkHelper; + private ZkHelper zkHelper; + @Override public boolean isRelatedByModuleAndApp(int mId, String appName) { return arkDao.queryRelationByModuleIdAndAppName(mId, appName).size() > 0; } + @Override public List fetchRegisteredPlugins() { return doFetchPluginsByName(null); @@ -129,7 +131,7 @@ public int relatedAppToPlugin(int moduleId, String appName) { boolean relatedByModuleAndApp = isRelatedByModuleAndApp(moduleId, appName); for (String appApp : arkAppList) { //zk中已存在应用 并且 未关联 - if (appApp.equals(appName) && isRelatedByModuleAndApp(moduleId,appName)==false) { + if (appApp.equals(appName) && isRelatedByModuleAndApp(moduleId, appName) == false) { AppArkDO appArkDO = new AppArkDO(); appArkDO.setAppName(appName); appArkDO.setCreateTime(SofaDashboardUtil.now()); diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java index 7d867bb..511d8b8 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/impl/ZkHelper.java @@ -53,6 +53,7 @@ public class ZkHelper { @Autowired ZkCommandClient zkCommandClient; + /** * 根据应用名获取当前应用的所有实例 * @@ -86,7 +87,7 @@ private List getInstanceIpList(String appName) { List result = null; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT - + SofaDashboardConstants.SEPARATOR + appName; + + SofaDashboardConstants.SEPARATOR + appName; try { if (checkExist(arkAppBasePath, curatorClient)) { // 根据应用名获取所有实例信息 @@ -106,7 +107,7 @@ private List getInstanceIpList(String appName) { * 获取 /sofa-ark 下面所有的应用 * @return */ - public List getArkAppList( ) { + public List getArkAppList() { List result = null; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT; @@ -158,13 +159,13 @@ private boolean checkExist(String path, CuratorFramework curatorClient) { * @return */ public String getAppState(String appName, String ip, String pluginName, String version) - throws Exception { + throws Exception { String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT - + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; + + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); if (curatorClient.checkExists().forPath(bizPath) != null) { String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName - + SofaDashboardConstants.SEPARATOR + ip; + + SofaDashboardConstants.SEPARATOR + ip; if (curatorClient.checkExists().forPath(bizAppPath) != null) { byte[] bytes = curatorClient.getData().forPath(bizAppPath); String data = new String(bytes); @@ -176,7 +177,7 @@ public String getAppState(String appName, String ip, String pluginName, String v String bizName = FastJsonUtils.getString(item, "bizName"); String bizVersion = FastJsonUtils.getString(item, "bizVersion"); if (bizName.equalsIgnoreCase(pluginName) - && bizVersion.equalsIgnoreCase(version)) { + && bizVersion.equalsIgnoreCase(version)) { return FastJsonUtils.getString(item, "bizState"); } } @@ -194,11 +195,11 @@ public String getAppState(String appName, String ip, String pluginName, String v public ClientResponseModel getBizState(String appName, String ip) throws Exception { ClientResponseModel result = new ClientResponseModel(); String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT - + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; + + SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ; CuratorFramework curatorClient = zkCommandClient.getCuratorClient(); if (curatorClient.checkExists().forPath(bizPath) != null) { String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName - + SofaDashboardConstants.SEPARATOR + ip; + + SofaDashboardConstants.SEPARATOR + ip; if (curatorClient.checkExists().forPath(bizAppPath) != null) { byte[] bytes = curatorClient.getData().forPath(bizAppPath); String data = new String(bytes); @@ -221,12 +222,12 @@ public ClientResponseModel getBizState(String appName, String ip) throws Excepti bizModel.setClassPath(getUrls("classPath", item)); bizModel.setDenyImportClasses(parseBizStateByKey("denyImportClasses", item)); bizModel.setDenyImportPackageNodes(parseBizStateByKey("denyImportPackageNodes", - item)); + item)); bizModel.setDenyImportPackageStems(parseBizStateByKey("denyImportPackageStems", - item)); + item)); bizModel.setDenyImportPackages(parseBizStateByKey("denyImportPackages", item)); bizModel - .setDenyImportResources(parseBizStateByKey("denyImportResources", item)); + .setDenyImportResources(parseBizStateByKey("denyImportResources", item)); bizModel.setWebContextPath(FastJsonUtils.getString(item, "webContextPath")); bizModel.setPriority(FastJsonUtils.getInteger(item, "priority")); bizModel.setBizClassLoader(getClassLoader(item)); diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java index 496fad5..9ebd916 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java @@ -34,7 +34,8 @@ public interface ArkMngService { * @param appName * @return */ - boolean isRelatedByModuleAndApp(int mId,String appName); + boolean isRelatedByModuleAndApp(int mId, String appName); + /** * 获取当前所有注册的 plugin 信息 * diff --git a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java index b732886..09dc07d 100644 --- a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java +++ b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java @@ -70,10 +70,10 @@ public class SofaDashboardConstants { public static final String ZOOKEEPER_PREFIX = "zookeeper://"; public static final String SOFA_PREFIX = "sofa://"; -// API接口类 - public static final String API_ARK_TAGS = "Ark相关接口"; - public static final String API_APPLICATION_TAGS = "Application相关接口"; - public static final String API_GOVERNANCE_TAGS = "Governance相关接口"; - public static final String API_WEB_TAGS = "Web相关接口"; + // API接口类 + public static final String API_ARK_TAGS = "Ark相关接口"; + public static final String API_APPLICATION_TAGS = "Application相关接口"; + public static final String API_GOVERNANCE_TAGS = "Governance相关接口"; + public static final String API_WEB_TAGS = "Web相关接口"; } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java index 1aa7f90..3bc0a56 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alipay.sofa.dashboard.configuration; import org.springframework.context.annotation.Bean; @@ -11,32 +27,21 @@ import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; - @Configuration @EnableSwagger2WebMvc public class Swagger2Config { @Bean public Docket createRestApi() { - return new Docket(DocumentationType.SWAGGER_2) - .useDefaultResponseMessages(false) - .apiInfo(apiInfo()) - .groupName("1.0版本") - .select() - .apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller")) - .paths(PathSelectors.any()) - .build(); + return new Docket(DocumentationType.SWAGGER_2).useDefaultResponseMessages(false) + .apiInfo(apiInfo()).groupName("1.0版本").select() + .apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller")) + .paths(PathSelectors.any()).build(); } private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("SOFADashboard APIs") - .description("SOFADashboard 接口对接文档") - .termsOfServiceUrl("http://localhost:8099/") - .version("1.0") - .build(); + return new ApiInfoBuilder().title("SOFADashboard APIs").description("SOFADashboard 接口对接文档") + .termsOfServiceUrl("http://localhost:8099/").version("1.0").build(); } - - } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java index 8142793..9f714b5 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ApplicationController.java @@ -35,7 +35,7 @@ * @author guolei.sgl (guolei.sgl@antfin.com) 18/12/7 下午5:15 */ @RestController -@Api(value = SofaDashboardConstants.API_APPLICATION_TAGS,tags = SofaDashboardConstants.API_APPLICATION_TAGS) +@Api(value = SofaDashboardConstants.API_APPLICATION_TAGS, tags = SofaDashboardConstants.API_APPLICATION_TAGS) @RequestMapping("/api/application") public class ApplicationController { diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java index b39d540..33a9957 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkMngController.java @@ -45,7 +45,7 @@ * @author: guolei.sgl (guolei.sgl@antfin.com) 18/12/19 上午11:06 * @since: **/ -@Api(value = SofaDashboardConstants.API_ARK_TAGS,tags = SofaDashboardConstants.API_ARK_TAGS) +@Api(value = SofaDashboardConstants.API_ARK_TAGS, tags = SofaDashboardConstants.API_ARK_TAGS) @RestController @RequestMapping("/api/ark") public class ArkMngController { @@ -93,8 +93,7 @@ public List queryArkPluginList() { * @param map * @return */ - @ApiOperation(value = "注册插件",tags = SofaDashboardConstants.API_ARK_TAGS) - + @ApiOperation(value = "注册插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 2) @RequestMapping("/register") public boolean registerPlugin(@RequestBody Map map) { @@ -107,7 +106,7 @@ public boolean registerPlugin(@RequestBody Map map) { return arkMngService.registerPlugin(arkPluginDO); } - @ApiOperation(value = "更新插件",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperation(value = "更新插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 3) @RequestMapping("/update-plugin") public boolean updatePlugin(@RequestBody ArkPluginDO arkPluginDO) { @@ -117,7 +116,7 @@ public boolean updatePlugin(@RequestBody ArkPluginDO arkPluginDO) { return arkMngService.updatePlugin(arkPluginDO); } - @ApiOperation(value = "更新插件版本",tags = SofaDashboardConstants.API_ARK_TAGS) + @ApiOperation(value = "更新插件版本", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 4) @RequestMapping("/register-new-version") public boolean registerNewVersion(@RequestBody Map map) { @@ -133,7 +132,8 @@ public boolean registerNewVersion(@RequestBody Map map) { } return arkMngService.addNewVersion(Integer.valueOf(id), version, address); } - @ApiOperation(value = "删除插件版本",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "删除插件版本", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 8) @RequestMapping("/delete-version") public ResponseEntity deleteVersion(@RequestParam("id") int id, @@ -150,7 +150,8 @@ public ResponseEntity deleteVersion(@RequestParam("id") int id, } return result; } - @ApiOperation(value = "删除插件",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "删除插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 9) @RequestMapping("/delete-plugin") public boolean deletePluginModel(@RequestParam("id") int id) { @@ -159,7 +160,8 @@ public boolean deletePluginModel(@RequestParam("id") int id) { } return arkMngService.removePlugins(id); } - @ApiOperation(value = "查询插件",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "查询插件", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 7) @RequestMapping("/search-plugin") public List searchPlugins(@RequestParam("pluginName") String pluginName) { @@ -169,13 +171,15 @@ public List searchPlugins(@RequestParam("pluginName") String plu } return arkMngService.fetchPluginsByName(pluginName); } - @ApiOperation(value = "关联应用",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "关联应用", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 5) @RequestMapping("/related-app") public boolean relatedApp(@RequestParam("id") int id, @RequestParam("appName") String appName) { return arkMngService.relatedAppToPlugin(id, appName) > 0; } - @ApiOperation(value = "取消关联应用",tags = SofaDashboardConstants.API_ARK_TAGS) + + @ApiOperation(value = "取消关联应用", tags = SofaDashboardConstants.API_ARK_TAGS) @ApiOperationSupport(order = 6) @RequestMapping("/cancel-related-app") public boolean cancelRelatedApp(@RequestParam("pluginName") String pluginName, diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties index 998c8a0..0b8a017 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties @@ -1,10 +1,10 @@ ## ark 管控端配置中心地址 ## mysql 数据库连接属性配置 -spring.datasource.url=jdbc:mysql://127.0.0.1:3306/SofaDashboardDB +spring.datasource.url=jdbc:mysql://mysql:3306/SofaDashboardDB spring.datasource.username=root spring.datasource.password=123456 ## zookeeper 注册中心地址 -com.alipay.sofa.dashboard.registry=zookeeper://127.0.0.1:2181 +com.alipay.sofa.dashboard.registry=zookeeper://zk01:2181 com.alipay.sofa.dashboard.redis.host=127.0.0.1 com.alipay.sofa.dashboard.redis.port=6379 -com.alipay.sofa.dashboard.zookeeper.address=127.0.0.1:2181 \ No newline at end of file +com.alipay.sofa.dashboard.zookeeper.address=zk01:2181 \ No newline at end of file From bbb5293f7d069482a67b3360fa089024650717a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Mon, 12 Jul 2021 16:32:17 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0docker-compose=E4=B8=80?= =?UTF-8?q?=E9=94=AE=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- .../docker/jenkins/Docker-compose.yml | 22 ++++++++ .../docker/sofadashboard/Docker-compose.yml | 52 +++++++++++++++++++ .../docker/sofadashboard/Dockerfile | 9 ++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 sofa-dashboard-backend/sofa-dashboard-web/docker/jenkins/Docker-compose.yml create mode 100644 sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Docker-compose.yml create mode 100644 sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Dockerfile diff --git a/.gitignore b/.gitignore index b606a64..d66696f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,7 @@ functions/mock .umi-production screenshot .firebase -application-localhost.properties \ No newline at end of file +application-localhost.properties +/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/sofa-dashboard-web-1.0.0-SNAPSHOT.jar +/sofa-dashboard-backend/sofa-dashboard-web/docker/jenkins/Jenkins/ +/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/SOFADashboard/ diff --git a/sofa-dashboard-backend/sofa-dashboard-web/docker/jenkins/Docker-compose.yml b/sofa-dashboard-backend/sofa-dashboard-web/docker/jenkins/Docker-compose.yml new file mode 100644 index 0000000..c8691a8 --- /dev/null +++ b/sofa-dashboard-backend/sofa-dashboard-web/docker/jenkins/Docker-compose.yml @@ -0,0 +1,22 @@ +version: '3.8' +services: + jenkins: + + image: jenkins/jenkins:lts + volumes: +# - ./Jenkins/jenkins_mount/jenkins/:/var/jenkins_mount/ + - ./Jenkins/data/jenkins/:/var/jenkins_home + - ./Jenkins/run/docker.sock:/var/run/docker.sock + - ./Jenkins/bin/docker:/usr/bin/docker + - ./Jenkins/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7 + ports: + - "4396:8080" + expose: + - "4396" + + privileged: true + user: root + restart: always + container_name: jenkins + environment: + JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties' diff --git a/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Docker-compose.yml b/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Docker-compose.yml new file mode 100644 index 0000000..95d1ed9 --- /dev/null +++ b/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Docker-compose.yml @@ -0,0 +1,52 @@ +version: '3.8' +services: + sofadashboard: + build: . + image: sofadashboard + depends_on: + - mysql + - zk01 + ports: + - "8099:8099" + links: + - zk01 + - mysql + + mysql: + container_name: mysql57 + image: mysql:5.7.31 + restart: always + ports: + - "3306:3306" + privileged: true + volumes: + - ./SOFADashboard/mysql57/log:/var/log/mysql +# - /dockerImages/DockerFileSharing/home/SOFADashboard/mysql57/conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf + - ./SOFADashboard/mysql57/data:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: "123456" + MYSQL_USER: 'root' + MYSQL_PASS: '123456' + command: [ + '--character-set-server=utf8mb4', + '--collation-server=utf8mb4_general_ci', + '--max_connections=3000' + ] + + zk01: + image: zookeeper:3.4.11 + restart: always + hostname: zk01 + container_name: zk01 + ports: + - "2181:2181" + volumes: + - ./SOFADashboard/zookeeper/zk01/data:/data + - ./SOFADashboard/zookeeper/zk01/datalog:/datalog + - ./SOFADashboard/zookeeper/zk01/logs:/logs + + +networks: + default: + external: + name: my_network diff --git a/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Dockerfile b/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Dockerfile new file mode 100644 index 0000000..dfd857f --- /dev/null +++ b/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/Dockerfile @@ -0,0 +1,9 @@ +FROM java:8 + +COPY *.jar /app.jar + +CMD ["--server.port=8099"] + +EXPOSE 8099 + +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file From 135e93a9ae1426cba472f2db6dcd5b5d08fef8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Mon, 12 Jul 2021 21:51:31 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E4=BD=BF=E7=94=A8dependentmanagement?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81=E7=BC=96=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sofa-dashboard-backend/pom.xml | 7 +++++++ sofa-dashboard-backend/sofa-dashboard-web/pom.xml | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sofa-dashboard-backend/pom.xml b/sofa-dashboard-backend/pom.xml index 2cf385f..ba8ea26 100644 --- a/sofa-dashboard-backend/pom.xml +++ b/sofa-dashboard-backend/pom.xml @@ -35,10 +35,17 @@ 1.0.17 1.14 1.3.2 + 2.0.8 + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j.version} + com.alipay.sofa sofa-dashboard-core diff --git a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml index c0c46d7..dac496f 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml +++ b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml @@ -22,7 +22,6 @@ com.github.xiaoymin knife4j-spring-boot-starter - 2.0.7 From b9200c868b3cd3f43b2a597c4df9ba2c933d3682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Mon, 12 Jul 2021 22:02:20 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sofa-dashboard-backend/pom.xml | 2 +- .../java/com/alipay/sofa/dashboard/service/ArkMngService.java | 3 +-- .../alipay/sofa/dashboard/configuration/Swagger2Config.java | 2 +- .../java/com/alipay/sofa/dashboard/utils/HostPortUtils.java | 3 --- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/sofa-dashboard-backend/pom.xml b/sofa-dashboard-backend/pom.xml index ba8ea26..0c26347 100644 --- a/sofa-dashboard-backend/pom.xml +++ b/sofa-dashboard-backend/pom.xml @@ -35,7 +35,7 @@ 1.0.17 1.14 1.3.2 - 2.0.8 + 2.0.7 diff --git a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java index 9ebd916..826036b 100644 --- a/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java +++ b/sofa-dashboard-backend/sofa-dashboard-arkmng/src/main/java/com/alipay/sofa/dashboard/service/ArkMngService.java @@ -91,9 +91,8 @@ public interface ArkMngService { */ List fetchPluginsByName(String pluginName); - /** + /*** * 关联应用和插件 - * * @param moduleId * @param appName * @return diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java index 3bc0a56..0be5883 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/configuration/Swagger2Config.java @@ -33,7 +33,7 @@ public class Swagger2Config { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2).useDefaultResponseMessages(false) - .apiInfo(apiInfo()).groupName("1.0版本").select() + .apiInfo(apiInfo()).groupName("default").select() .apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller")) .paths(PathSelectors.any()).build(); 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 7dcdc33..6478ba5 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 @@ -164,8 +164,5 @@ public static String fromDigital(Long ipv4) { 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); } } From 804ea73ab3a24a879bb7a2b3692925580e7dfc0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Mon, 12 Jul 2021 22:25:39 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=90=8E=E6=8C=89=E9=92=AE=E5=A4=84=E4=BA=8E?= =?UTF-8?q?=E6=8C=81=E7=BB=AD=E8=BD=AC=E5=9C=88=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sofa-dashboard-front/src/pages/Ark/index.jsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sofa-dashboard-front/src/pages/Ark/index.jsx b/sofa-dashboard-front/src/pages/Ark/index.jsx index 67ed631..b58c718 100644 --- a/sofa-dashboard-front/src/pages/Ark/index.jsx +++ b/sofa-dashboard-front/src/pages/Ark/index.jsx @@ -127,6 +127,7 @@ class Ark extends React.Component { const { form } = this.formRelatedAppRef.props; const { dispatch } = this.props; form.validateFields((err, values) => { + console.log("values"+values) if (err) { return; } @@ -154,6 +155,9 @@ class Ark extends React.Component { }); } else { message.info('关联失败,请联系管理员'); + this.setState({ + confirmRelatedAppLoading: false, + }); } }); }); From c921a5970baca0db286e04187951b3e94c5d69c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=95=8F=E9=94=8B?= <1464687785@qq.com> Date: Wed, 14 Jul 2021 22:49:28 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E5=AE=8C=E5=96=84Api=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sofa-dashboard-backend/pom.xml | 9 +++++ .../constants/SofaDashboardConstants.java | 5 +-- .../sofa-dashboard-web/pom.xml | 1 - .../controller/ArkAppMngController.java | 13 ++++++-- .../controller/InstanceController.java | 26 +++++++++++---- .../controller/ServiceManageController.java | 33 ++++++++++++++----- .../application-localhost.properties | 6 ++-- sofa-dashboard-front/src/pages/Ark/index.jsx | 1 - 8 files changed, 71 insertions(+), 23 deletions(-) diff --git a/sofa-dashboard-backend/pom.xml b/sofa-dashboard-backend/pom.xml index 0c26347..d98ee9c 100644 --- a/sofa-dashboard-backend/pom.xml +++ b/sofa-dashboard-backend/pom.xml @@ -36,6 +36,7 @@ 1.14 1.3.2 2.0.7 + 20.0 @@ -46,6 +47,14 @@ knife4j-spring-boot-starter ${knife4j.version} + + com.google.guava + guava + ${guava.version} + + + + com.alipay.sofa sofa-dashboard-core diff --git a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java index 09dc07d..98188db 100644 --- a/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java +++ b/sofa-dashboard-backend/sofa-dashboard-core/src/main/java/com/alipay/sofa/dashboard/constants/SofaDashboardConstants.java @@ -73,7 +73,8 @@ public class SofaDashboardConstants { // API接口类 public static final String API_ARK_TAGS = "Ark相关接口"; public static final String API_APPLICATION_TAGS = "Application相关接口"; - public static final String API_GOVERNANCE_TAGS = "Governance相关接口"; - public static final String API_WEB_TAGS = "Web相关接口"; + public static final String API_ARK_APPLICATION_TAGS ="Ark与application相关应用"; + public static final String API_INSTANCE_TAGS ="Instance相关接口"; + public static final String API_SERVICES_TAGS ="Services相关接口"; } diff --git a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml index dac496f..7c80f0e 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/pom.xml +++ b/sofa-dashboard-backend/sofa-dashboard-web/pom.xml @@ -27,7 +27,6 @@ com.google.guava guava - 20.0 diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java index 858b6a8..fb43f2a 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ArkAppMngController.java @@ -27,7 +27,9 @@ import com.alipay.sofa.dashboard.response.ResponseEntity; import com.alipay.sofa.dashboard.service.ArkMngService; import com.alipay.sofa.dashboard.spi.CommandPushManager; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -48,6 +50,7 @@ @RestController @RequestMapping("/api/arkapp") +@Api(value = SofaDashboardConstants.API_ARK_APPLICATION_TAGS,tags = SofaDashboardConstants.API_ARK_APPLICATION_TAGS) public class ArkAppMngController { private static final Logger LOGGER = LoggerFactory.getLogger(ArkAppMngController.class); @@ -60,6 +63,8 @@ public class ArkAppMngController { private ZkHelper zkHelper; @RequestMapping("/ark-app") + @ApiOperation(value = "获取插件的所有关联应用",tags = SofaDashboardConstants.API_ARK_APPLICATION_TAGS) + @ApiOperationSupport(order = 1) @Deprecated public AppModuleModel fetchArkApps(@RequestParam("pluginName") String pluginName,@RequestParam("appName") String appName, @RequestParam("version") String version) throws Exception { @@ -93,7 +98,8 @@ public AppModuleModel fetchArkApps(@RequestParam("pluginName") String pluginName appModuleModel.setIpUnitList(ipUnitList); return appModuleModel; } - + @ApiOperation(value = "推送命令",tags = SofaDashboardConstants.API_ARK_APPLICATION_TAGS) + @ApiOperationSupport(order = 2) @RequestMapping("/command") public boolean command(@RequestBody Map commandMap) { // parse commandMap @@ -106,7 +112,8 @@ public boolean command(@RequestBody Map commandMap) { } return true; } - + @ApiOperation(value = "fetchBiz状态信息",tags = SofaDashboardConstants.API_ARK_APPLICATION_TAGS) + @ApiOperationSupport(order = 3) @RequestMapping("biz-state-detail") public ClientResponseModel fetchBizState(@RequestParam("ip") String ip, @RequestParam("appName") String appName) { @@ -118,6 +125,8 @@ public ClientResponseModel fetchBizState(@RequestParam("ip") String ip, return new ClientResponseModel(); } + @ApiOperation(value = "获取Biz状态信息",tags = SofaDashboardConstants.API_ARK_APPLICATION_TAGS) + @ApiOperationSupport(order = 4) @RequestMapping("biz-state") public ResponseEntity getBizState(@RequestParam("ip") String ip, @RequestParam("appName") String appName, diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/InstanceController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/InstanceController.java index fd1f88e..577aca7 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/InstanceController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/InstanceController.java @@ -25,6 +25,7 @@ import com.alipay.sofa.dashboard.client.model.mappings.MappingsDescriptor; import com.alipay.sofa.dashboard.client.model.memory.MemoryDescriptor; import com.alipay.sofa.dashboard.client.model.thread.ThreadSummaryDescriptor; +import com.alipay.sofa.dashboard.constants.SofaDashboardConstants; import com.alipay.sofa.dashboard.model.InstanceRecord; import com.alipay.sofa.dashboard.model.RecordResponse; import com.alipay.sofa.dashboard.model.StampedValueEntity; @@ -33,6 +34,9 @@ import com.alipay.sofa.dashboard.utils.HostPortUtils; import com.alipay.sofa.dashboard.utils.MapUtils; import com.alipay.sofa.dashboard.utils.TreeNodeConverter; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; @@ -56,6 +60,7 @@ */ @RestController @RequestMapping("/api/instance") +@Api(value = SofaDashboardConstants.API_INSTANCE_TAGS,tags = SofaDashboardConstants.API_INSTANCE_TAGS) public class InstanceController { @Autowired @@ -64,6 +69,7 @@ public class InstanceController { @Autowired private MonitorService service; + @GetMapping public List instances( @RequestParam(value = "applicationName", required = false) String applicationName) { @@ -76,6 +82,8 @@ public List instances( .collect(Collectors.toList()); } + @ApiOperation(value = "获取实例环境",tags = SofaDashboardConstants.API_INSTANCE_TAGS) + @ApiOperationSupport(order = 1) @GetMapping("/{instanceId}/env") public RecordResponse getEnv( @PathVariable("instanceId") String instanceId) { @@ -104,7 +112,8 @@ public RecordResponse getEnv( .detail(TreeNodeConverter.convert(descriptor)) .build(); } - + @ApiOperation(value = "获取实例信息",tags = SofaDashboardConstants.API_INSTANCE_TAGS) + @ApiOperationSupport(order = 2) @GetMapping("/{instanceId}/info") public RecordResponse getInfo(@PathVariable("instanceId") String instanceId) { HostAndPort hostAndPort = HostPortUtils.getById(instanceId); @@ -127,7 +136,8 @@ public RecordResponse getInfo(@PathVariable("instanceId") String instanceId) { .detail(TreeNodeConverter.convert(descriptor)) .build(); } - + @ApiOperation(value = "获取实例健康状态",tags = SofaDashboardConstants.API_INSTANCE_TAGS) + @ApiOperationSupport(order = 3) @GetMapping("/{instanceId}/health") public RecordResponse getHealth(@PathVariable("instanceId") String instanceId) { HostAndPort hostAndPort = HostPortUtils.getById(instanceId); @@ -148,7 +158,8 @@ public RecordResponse getHealth(@PathVariable("instanceId") String instanceId) { String.format("%s:%d", hostAndPort.getHost(), hostAndPort.getPort())) .detail(TreeNodeConverter.convert(descriptor)).build(); } - + @ApiOperation(value = "获取实例日志",tags = SofaDashboardConstants.API_INSTANCE_TAGS) + @ApiOperationSupport(order = 4) @GetMapping("/{instanceId}/loggers") public RecordResponse getLoggers(@PathVariable("instanceId") String instanceId) { HostAndPort hostAndPort = HostPortUtils.getById(instanceId); @@ -157,7 +168,8 @@ public RecordResponse getLoggers(@PathVariable("instanceId") String instanceId) return RecordResponse.newBuilder().overview(new HashMap<>(16)) .detail(TreeNodeConverter.convert(descriptor)).build(); } - + @ApiOperation(value = "获取实例映射",tags = SofaDashboardConstants.API_INSTANCE_TAGS) + @ApiOperationSupport(order = 5) @GetMapping("/{instanceId}/mappings") public RecordResponse getMappings(@PathVariable("instanceId") String instanceId) { HostAndPort hostAndPort = HostPortUtils.getById(instanceId); @@ -186,13 +198,15 @@ public RecordResponse getMappings(@PathVariable("instanceId") String instanceId) .detail(TreeNodeConverter.convert(descriptor)) .build(); } - + @ApiOperation(value = "获取内存记录",tags = SofaDashboardConstants.API_INSTANCE_TAGS) + @ApiOperationSupport(order = 6) @GetMapping("/{instanceId}/memory") public List> getMemoryRecords(@PathVariable("instanceId") String instanceId) { HostAndPort hostAndPort = HostPortUtils.getById(instanceId); return service.fetchMemoryInfo(hostAndPort); } - + @ApiOperation(value = "获取线程记录",tags = SofaDashboardConstants.API_INSTANCE_TAGS) + @ApiOperationSupport(order = 7) @GetMapping("/{instanceId}/thread") public List> getThreadRecords(@PathVariable("instanceId") String instanceId) { HostAndPort hostAndPort = HostPortUtils.getById(instanceId); diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ServiceManageController.java b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ServiceManageController.java index 90a5902..e82abf0 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ServiceManageController.java +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/java/com/alipay/sofa/dashboard/controller/ServiceManageController.java @@ -18,12 +18,16 @@ import com.alipay.sofa.common.utils.StringUtil; import com.alipay.sofa.dashboard.cache.RegistryDataCache; +import com.alipay.sofa.dashboard.constants.SofaDashboardConstants; import com.alipay.sofa.dashboard.domain.RpcConsumer; import com.alipay.sofa.dashboard.domain.RpcProvider; import com.alipay.sofa.dashboard.domain.RpcService; import com.alipay.sofa.dashboard.model.ServiceAppModel; import com.alipay.sofa.dashboard.model.ServiceModel; import com.alipay.sofa.rpc.common.utils.StringUtils; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -46,11 +50,14 @@ **/ @RestController @RequestMapping("/api/service") +@Api(value = SofaDashboardConstants.API_SERVICES_TAGS,tags = SofaDashboardConstants.API_SERVICES_TAGS) public class ServiceManageController { @Autowired private RegistryDataCache registryDataCache; + @ApiOperation(value = "获取全部服务列表",tags = SofaDashboardConstants.API_SERVICES_TAGS) + @ApiOperationSupport(order = 1) @GetMapping("/all-service") public List queryServiceListByService(@RequestParam("query") String query) { List data = new ArrayList<>(); @@ -70,6 +77,8 @@ public List queryServiceListByService(@RequestParam("query") Strin * * @return */ + @ApiOperation(value = "获取服务列表-应用维度",tags = SofaDashboardConstants.API_SERVICES_TAGS) + @ApiOperationSupport(order = 2) @GetMapping("/all-app") public List> queryServiceListByApp(@RequestParam("query") String query) { List> data = new ArrayList<>(); @@ -110,6 +119,8 @@ public List> queryServiceListByApp(@RequestParam("query") St * @param appName * @return */ + @ApiOperation(value = "获取应用服务信息",tags = SofaDashboardConstants.API_SERVICES_TAGS) + @ApiOperationSupport(order = 2) @GetMapping("service-app") public ServiceAppModel queryServiceByAppName(@RequestParam("appName") String appName) { List providersData = new ArrayList<>(); @@ -152,33 +163,39 @@ private List fetchConsumerData(String serviceName) { return registryDataCache.fetchConsumersByService(serviceName); } - /** + /*** * 获取某个服务的所有提供方 - * + * @param serviceName * @return */ + @ApiOperation(value = "获取指定服务所有提供方",tags = SofaDashboardConstants.API_SERVICES_TAGS) + @ApiOperationSupport(order = 3) @GetMapping("query/providers") public List queryServiceProviders(@RequestParam("dataid") String serviceName) { String dataId = URLDecoder.decode(serviceName); return fetchProviderData(dataId); } - /** - * 获取某个服务的所有提供方 - * + /*** + * 获取某个服务的所有接受方 + * @param serviceName * @return */ + @ApiOperation(value = "获取指定服务所有接受方",tags = SofaDashboardConstants.API_SERVICES_TAGS) + @ApiOperationSupport(order = 4) @GetMapping("query/consumers") public List queryServiceConsumers(@RequestParam("dataid") String serviceName) { String dataId = URLDecoder.decode(serviceName); return fetchConsumerData(dataId); } - /** - * 获取某个服务的所有提供方 - * + /*** + * 获取某个服务的所有信息 + * @param serviceName * @return */ + @ApiOperation(value = "根据名字获取指定服务",tags = SofaDashboardConstants.API_SERVICES_TAGS) + @ApiOperationSupport(order = 5) @GetMapping("query/services") public List queryService(@RequestParam("serviceName") String serviceName) { List data = new ArrayList<>(); diff --git a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties index 0b8a017..998c8a0 100644 --- a/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties +++ b/sofa-dashboard-backend/sofa-dashboard-web/src/main/resources/application-localhost.properties @@ -1,10 +1,10 @@ ## ark 管控端配置中心地址 ## mysql 数据库连接属性配置 -spring.datasource.url=jdbc:mysql://mysql:3306/SofaDashboardDB +spring.datasource.url=jdbc:mysql://127.0.0.1:3306/SofaDashboardDB spring.datasource.username=root spring.datasource.password=123456 ## zookeeper 注册中心地址 -com.alipay.sofa.dashboard.registry=zookeeper://zk01:2181 +com.alipay.sofa.dashboard.registry=zookeeper://127.0.0.1:2181 com.alipay.sofa.dashboard.redis.host=127.0.0.1 com.alipay.sofa.dashboard.redis.port=6379 -com.alipay.sofa.dashboard.zookeeper.address=zk01:2181 \ No newline at end of file +com.alipay.sofa.dashboard.zookeeper.address=127.0.0.1:2181 \ No newline at end of file diff --git a/sofa-dashboard-front/src/pages/Ark/index.jsx b/sofa-dashboard-front/src/pages/Ark/index.jsx index b58c718..537f305 100644 --- a/sofa-dashboard-front/src/pages/Ark/index.jsx +++ b/sofa-dashboard-front/src/pages/Ark/index.jsx @@ -127,7 +127,6 @@ class Ark extends React.Component { const { form } = this.formRelatedAppRef.props; const { dispatch } = this.props; form.validateFields((err, values) => { - console.log("values"+values) if (err) { return; }