diff --git a/.gitignore b/.gitignore index 77e5f422d4..7adc4b799d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ ### Jrebel File ### *rebel.xml.bak *rebel.xml - +*.idx ### Common ### target @@ -28,4 +28,4 @@ ig** application-local.* .DS_Store -public/ \ No newline at end of file +public/!/extensions.idx diff --git a/pom.xml b/pom.xml index 55bcb95e88..8bc5992d43 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.shulie.takin takin-web - takin-web-5.9.0 + takin-web-5.10.2.2 pom https://github.com/shulieTech/Takin-web.git @@ -41,7 +41,7 @@ 3.8.0 yyyyMMddHHmmss - takin-web-5.9.0 + takin-web-5.10.2.2 common-2.0.2-SNAPSHOT common-2.0.0-SNAPSHOT 2.0.6.2 @@ -50,7 +50,7 @@ 3.5 2.3.0.RELEASE - 8.0.26 + 8.0.27 1.1.22 2.3 2.3.0 @@ -78,6 +78,10 @@ 9.1.22 2.12.4 5.4.0.12 + 2.16.0 + 1.2.9 + 9.0.67 + 1.2.83 @@ -344,7 +348,7 @@ io.shulie.amdb amdb-common - 1.0.3-SNAPSHOT + 1.1.3 org.mapstruct @@ -455,85 +459,85 @@ true - - - ossrh - - - - - org.apache.maven.plugins - maven-resources-plugin - 2.5 - - UTF-8 - - - - org.apache.maven.plugins - maven-scm-plugin - 1.0 - - - org.apache.maven.plugins - maven-release-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - -Xdoclint:none - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://s01.oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-jar-plugin - 2.2 - - - - true - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/takin-web-amdb-accessor/pom.xml b/takin-web-amdb-accessor/pom.xml index 6404a4a4b5..7c4b626439 100644 --- a/takin-web-amdb-accessor/pom.xml +++ b/takin-web-amdb-accessor/pom.xml @@ -20,7 +20,7 @@ takin-web io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 @@ -69,10 +69,22 @@ io.shulie.pradar log-protocol + + + fastjson + com.alibaba + + io.shulie.takin takin-common-utils + + + fastjson + com.alibaba + + org.mortbay.jetty @@ -106,6 +118,10 @@ log4j log4j + + fastjson + com.alibaba + diff --git a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/ApplicationEntranceClient.java b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/ApplicationEntranceClient.java index df13b698e8..f9e4e725df 100644 --- a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/ApplicationEntranceClient.java +++ b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/ApplicationEntranceClient.java @@ -18,7 +18,7 @@ public interface ApplicationEntranceClient { List getApplicationEntrances(String applicationName, String entranceType, String serviceName, int currentPage, int pageSize); LinkTopologyDTO getApplicationEntrancesTopology(boolean tempActivity, String applicationName, String linkId, String serviceName, - String method, String rpcType, String extend); + String method, String rpcType, String extend,boolean extFlag); String queryMetricsFromAMDB1(TempTopologyQuery1 tempTopologyQuery1); JSONObject queryMetricsFromAMDB2(TempTopologyQuery2 tempTopologyQuery2); diff --git a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/impl/ApplicationEntranceClientImpl.java b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/impl/ApplicationEntranceClientImpl.java index 9f95bc51b3..49bd453f86 100644 --- a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/impl/ApplicationEntranceClientImpl.java +++ b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/api/impl/ApplicationEntranceClientImpl.java @@ -78,7 +78,9 @@ public List getApplicationEntrances(String applicationName, Stri //查询所有的type entranceQueryParam.setRpcType(""); } - entranceQueryParam.setAppName(applicationName); + if (StringUtils.isNotBlank(applicationName)) { + entranceQueryParam.setAppName(applicationName); + } entranceQueryParam.setTenantAppKey(WebPluginUtils.traceTenantAppKey()); entranceQueryParam.setEnvCode(WebPluginUtils.traceEnvCode()); entranceQueryParam.setCurrentPage(currentPage); @@ -192,10 +194,21 @@ public List queryBatchMetrics(QueryMetricsFromAMDB queryMetricsFromA } } + /** + * @param tempActivity + * @param applicationName + * @param linkId + * @param serviceName + * @param method + * @param rpcType + * @param extend + * @param extFlag 是否查询扩展边信息,会返回数据库关联的库信息 + * @return + */ @Override public LinkTopologyDTO getApplicationEntrancesTopology(boolean tempActivity, String applicationName, String linkId, String serviceName, - String method, String rpcType, String extend) { + String method, String rpcType, String extend, boolean extFlag) { String url; if (tempActivity) { url = properties.getUrl().getAmdb() + APPLICATION_ENTRANCES_TOPOLOGY_PATH_TEMP; @@ -216,6 +229,8 @@ public LinkTopologyDTO getApplicationEntrancesTopology(boolean tempActivity, Str if (extend != null) { topologyQueryParam.setExtend(extend); } + // 是否关联查询出数据库的详情信息,默认false + topologyQueryParam.setExtFlag(extFlag); topologyQueryParam.setTenantAppKey(WebPluginUtils.traceTenantAppKey()); topologyQueryParam.setEnvCode(WebPluginUtils.traceEnvCode()); try { diff --git a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/application/ApplicationRemoteCallQueryDTO.java b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/application/ApplicationRemoteCallQueryDTO.java index 1f7d1ab413..c7c619bb2d 100644 --- a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/application/ApplicationRemoteCallQueryDTO.java +++ b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/application/ApplicationRemoteCallQueryDTO.java @@ -16,7 +16,7 @@ public class ApplicationRemoteCallQueryDTO { @JsonProperty("currentPage") private Integer currentPage; @JsonProperty("linkId") - private Integer linkId; + private String linkId; @JsonProperty("methodName") private String methodName; @JsonProperty("middlewareName") @@ -37,7 +37,7 @@ public class ApplicationRemoteCallQueryDTO { @JsonProperty("userName") private String userName; @JsonProperty("fieldNames") - private String fieldNames = "appName,serviceName,methodName,middlewareName,middlewareDetail,rpcType,extend,upAppName"; + private String fieldNames = "appName,serviceName,methodName,middlewareName,middlewareDetail,rpcType,extend,upAppName,rpcId,linkId"; /** * 客户端查询 */ diff --git a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/script/QueryLinkDetailDTO.java b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/script/QueryLinkDetailDTO.java index 933283a8d3..f864bb5e6d 100644 --- a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/script/QueryLinkDetailDTO.java +++ b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/script/QueryLinkDetailDTO.java @@ -4,6 +4,7 @@ import io.shulie.takin.web.amdb.bean.common.PagingDevice; import io.shulie.takin.web.amdb.bean.query.trace.EntranceRuleDTO; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -126,4 +127,13 @@ public class QueryLinkDetailDTO extends PagingDevice { */ private Integer queryType; + private String appName; + + /** + * 类名模糊查询 + */ + private String queryMethodName; + + @ApiModelProperty("调用类型") + String logType; } diff --git a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/trace/TraceInfoQueryDTO.java b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/trace/TraceInfoQueryDTO.java index 14a6bd8088..2846fe49cc 100644 --- a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/trace/TraceInfoQueryDTO.java +++ b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/query/trace/TraceInfoQueryDTO.java @@ -64,6 +64,11 @@ public class TraceInfoQueryDTO implements Serializable { */ private String methodName; + /** + * 方法名模糊查询 + */ + private String queryMethodName; + /** * 调用参数:request */ @@ -85,5 +90,11 @@ public class TraceInfoQueryDTO implements Serializable { */ private Integer queryType; + private String appName; + + private String rpcType; + private Integer clusterTest; + + String logType; } diff --git a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/result/application/ApplicationRemoteCallDTO.java b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/result/application/ApplicationRemoteCallDTO.java index 6df5f2a0bc..8c2c7c2b2b 100644 --- a/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/result/application/ApplicationRemoteCallDTO.java +++ b/takin-web-amdb-accessor/src/main/java/io/shulie/takin/web/amdb/bean/result/application/ApplicationRemoteCallDTO.java @@ -13,6 +13,8 @@ public class ApplicationRemoteCallDTO { @JsonProperty("appName") private String appName; + @JsonProperty("appId") + private Long appId; @JsonProperty("extend") private String extend; @JsonProperty("methodName") @@ -29,5 +31,6 @@ public class ApplicationRemoteCallDTO { private String upAppName; @JsonProperty("defaultWhiteInfo") private String defaultWhiteInfo; + private String rpcId; } \ No newline at end of file diff --git a/takin-web-app/pom.xml b/takin-web-app/pom.xml index d0fa560016..313e64ef60 100644 --- a/takin-web-app/pom.xml +++ b/takin-web-app/pom.xml @@ -4,7 +4,7 @@ io.shulie.takin takin-web - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml takin-web-app @@ -48,6 +48,10 @@ org.slf4j slf4j-log4j12 + + fastjson + com.alibaba + @@ -135,6 +139,10 @@ org.apache.logging.log4j log4j-api + + fastjson + com.alibaba + @@ -233,6 +241,10 @@ guava com.google.guava + + fastjson + com.alibaba + diff --git a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ResponseWrapAdvice.java b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ResponseWrapAdvice.java index 1f17b58577..25f9207f2b 100644 --- a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ResponseWrapAdvice.java +++ b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ResponseWrapAdvice.java @@ -4,9 +4,11 @@ import java.util.Set; import java.util.HashSet; +import io.shulie.takin.web.common.domain.ErrorInfo; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import com.github.pagehelper.PageInfo; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.MediaType; import org.springframework.http.HttpHeaders; import org.springframework.core.MethodParameter; @@ -58,8 +60,21 @@ public Object beforeBodyWrite(Object body, headers.add(Response.PAGE_TOTAL_HEADER); header.set(accessControlExposeHeaderName, String.join(",", headers)); } - if (body instanceof Response - || body instanceof WebResponse + if (body instanceof Response){ + Object data = ((Response) body).getData(); + ErrorInfo error = ((Response) body).getError(); + Boolean success = ((Response) body).getSuccess(); + String total = ((Response) body).getTotal(); + if (!success){ + return io.shulie.takin.common.beans.response.ResponseResult.fail(error.getMsg(),""); + } + if (StringUtils.isNotBlank(total)){ + return io.shulie.takin.common.beans.response.ResponseResult.success(data, Long.parseLong(total)); + } + return io.shulie.takin.common.beans.response.ResponseResult.success(data); + } + + if (body instanceof WebResponse || body instanceof File || body instanceof ResponseResult || body instanceof io.shulie.takin.common.beans.response.ResponseResult) { diff --git a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/SwaggerConfig.java b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/SwaggerConfig.java index f9c10ad383..d12425c78b 100644 --- a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/SwaggerConfig.java +++ b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/SwaggerConfig.java @@ -451,6 +451,25 @@ public Docket api_twoWeekIteration() { ; } + /** + * 权限改造 + * @return + */ + @Bean + public Docket api_deptAuth() { + return new Docket(DocumentationType.SWAGGER_2) + .pathProvider(this.pathProvider()) + .groupName("部门权限改造") + .select() + .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) + .paths(getRegex("/api/(dept|role).*")) + .build() + .directModelSubstitute(LocalDate.class, String.class) + .useDefaultResponseMessages(false) + .apiInfo(apiInfo()).enable(swaggerEnable) + ; + } + /** diff --git a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ThreadPoolConfig.java b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ThreadPoolConfig.java index 1292510638..7bd38d1518 100644 --- a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ThreadPoolConfig.java +++ b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/ThreadPoolConfig.java @@ -34,7 +34,7 @@ */ @Configuration public class ThreadPoolConfig { - /** + /** * 用于定时任务 * * @return 线程池 @@ -62,7 +62,21 @@ public ThreadPoolExecutor appRemoteApiFilterThreadPool() { public ThreadPoolExecutor jobThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-%d").build(); return new ThreadPoolExecutor(20, 40, 10L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); + } + + @Bean(name = "pressureResourceThreadPool") + public ThreadPoolExecutor pressureResouceThreadPool() { + ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("pressureResourceThreadPool-%d").build(); + return new ThreadPoolExecutor(20, 40, 10L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, + new ThreadPoolExecutor.AbortPolicy()); + } + + @Bean(name = "simpleFutureThreadPool") + public ThreadPoolExecutor simpleFutureThreadPool() { + ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("simpleFutureThreadPool-job-%d").build(); + return new ThreadPoolExecutor(5, 10, 10L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, + new ThreadPoolExecutor.AbortPolicy()); } /** @@ -98,7 +112,7 @@ public ThreadPoolExecutor remoteApiThreadPool() { public ThreadPoolExecutor traceManageThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-trace-%d").build(); return new ThreadPoolExecutor(5, 10, 10L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } /** @@ -110,10 +124,10 @@ public ThreadPoolExecutor traceManageThreadPool() { public ThreadPoolExecutor collectDataThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-collect-data-%d").build(); return new ThreadPoolExecutor(5, 10, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } - @Bean(name = "collectDataThreadPool_one") + @Bean(name = "collectDataThreadPool_one") public ThreadPoolExecutor collectDataThreadPool_one() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-collect-data-two-%d").build(); return new ThreadPoolExecutor(10, 50, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, @@ -133,7 +147,7 @@ public ThreadPoolExecutor collectDataThreadPool_three() { return new ThreadPoolExecutor(10, 50, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } - + /** * 漏数验证单独做 * @@ -143,7 +157,7 @@ public ThreadPoolExecutor collectDataThreadPool_three() { public ThreadPoolExecutor showdownVerifyThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-showdown-verify-%d").build(); return new ThreadPoolExecutor(5, 10, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } /** @@ -156,10 +170,10 @@ public ThreadPoolExecutor showdownVerifyThreadPool() { public ThreadPoolExecutor reportSummaryThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-summary-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } - - @Bean(name = "reportSummaryThreadPool_one") + + @Bean(name = "reportSummaryThreadPool_one") public ThreadPoolExecutor reportSummaryThreadPool_one() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-summary_one-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, @@ -179,7 +193,7 @@ public ThreadPoolExecutor reportSummaryThreadPool_three() { return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } - + /** * 四大报告Job分开线程池单独使用 * @@ -190,10 +204,10 @@ public ThreadPoolExecutor reportSummaryThreadPool_three() { public ThreadPoolExecutor reportTpsThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-tps-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } - - @Bean(name = "reportTpsThreadPool_one") + + @Bean(name = "reportTpsThreadPool_one") public ThreadPoolExecutor reportTpsThreadPool_one() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-tps-one-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, @@ -206,7 +220,7 @@ public ThreadPoolExecutor reportTpsThreadPool_two() { return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } - + /** * 四大报告Job分开线程池单独使用 * @@ -217,10 +231,10 @@ public ThreadPoolExecutor reportTpsThreadPool_two() { public ThreadPoolExecutor reportFinishThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-finish-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } - - @Bean(name = "reportFinishThreadPool_one") + + @Bean(name = "reportFinishThreadPool_one") public ThreadPoolExecutor reportFinishThreadPool_one() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-finish-one-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, @@ -233,7 +247,7 @@ public ThreadPoolExecutor reportFinishThreadPool_two() { return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } - + /** * 四大报告Job分开线程池单独使用 * @@ -244,10 +258,10 @@ public ThreadPoolExecutor reportFinishThreadPool_two() { public ThreadPoolExecutor reportMachineThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-machine-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } - - @Bean(name = "reportMachineThreadPool_one") + + @Bean(name = "reportMachineThreadPool_one") public ThreadPoolExecutor reportMachineThreadPool_one() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("job-report-machine-one-%d").build(); return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, @@ -260,7 +274,7 @@ public ThreadPoolExecutor reportMachineThreadPool_two() { return new ThreadPoolExecutor(10, 20, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } - + /** * 仅链路调试用的job * @@ -270,14 +284,14 @@ public ThreadPoolExecutor reportMachineThreadPool_two() { public ThreadPoolExecutor fastDebug() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("fast-debug-%d").build(); return new ThreadPoolExecutor(5, 10, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(2000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Bean(name = "modifyMonitorThreadPool") public ThreadPoolExecutor modifyMonitorExecutor() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("modify-monitor-%d").build(); return new ThreadPoolExecutor(5, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Bean(name = "schedulerPool") @@ -285,7 +299,7 @@ public TaskScheduler scheduler() { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setPoolSize(20); ThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("pradar-scheduler-thread-%d") - .daemon(true).build(); + .daemon(true).build(); taskScheduler.setThreadFactory(threadFactory); taskScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); return taskScheduler; @@ -295,29 +309,29 @@ public TaskScheduler scheduler() { public ThreadPoolExecutor runShellTaskExecutor() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("script-thread-%d").build(); return new ThreadPoolExecutor(5, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Bean(name = "loadDataThreadPool") public ThreadPoolExecutor loadDataTaskExecutor() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("loaddata-thread-%d").build(); return new ThreadPoolExecutor(5, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Bean(name = "agentDataThreadPool") public ThreadPoolExecutor agentDataTaskExecutor() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("agentdata-thread-%d").build(); return new ThreadPoolExecutor(5, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Bean(name = "backgroundMonitorThreadPool") public ThreadPoolExecutor backgroundMonitorThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("background-monitor-thread-%d") - .build(); + .build(); return new ThreadPoolExecutor(5, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Bean("asyncExecuteScriptThreadPool") @@ -345,7 +359,7 @@ public Executor myAsync() { public ThreadPoolExecutor runOPSShellTaskExecutor() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("ops-script-thread-%d").build(); return new ThreadPoolExecutor(1, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Primary @@ -387,7 +401,7 @@ public HttpMessageConverters restFileDownloadSupport() { public ThreadPoolExecutor queryAsyncThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("query-async-thread-%d").build(); return new ThreadPoolExecutor(1, 10, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } @Value("${poolConfig.e2e.coreSize: 50}") @@ -408,7 +422,7 @@ public ThreadPoolExecutor queryAsyncThreadPool() { public ThreadPoolExecutor e2eThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("e2e-job-%d").build(); return new ThreadPoolExecutor(e2eCoreSize, e2eMaxSize, 60L, TimeUnit.SECONDS, - new ArrayBlockingQueue<>(e2eQueueSize), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + new ArrayBlockingQueue<>(e2eQueueSize), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } /** @@ -420,7 +434,7 @@ public ThreadPoolExecutor e2eThreadPool() { public ThreadPoolExecutor agentAggregationThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("agent-aggregation-%d").build(); return new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), - nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } /** @@ -433,7 +447,7 @@ public ThreadPoolExecutor middlewareResolverThreadPool() { final int coreSize = Runtime.getRuntime().availableProcessors(); ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("middleware-resolver-%d").build(); return new ThreadPoolExecutor(coreSize, coreSize * 2, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), - nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } /** @@ -446,8 +460,8 @@ public ExecutorService agentHeartbeatThreadPool() { final int coreSize = Runtime.getRuntime().availableProcessors(); ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("agent-heartbeat-%d").build(); return TtlExecutors.getTtlExecutorService( - new ThreadPoolExecutor(coreSize, coreSize * 2, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), - nameThreadFactory, new ThreadPoolExecutor.DiscardPolicy())); + new ThreadPoolExecutor(coreSize, coreSize * 2, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), + nameThreadFactory, new ThreadPoolExecutor.DiscardPolicy())); } /** @@ -475,7 +489,7 @@ public ThreadPoolTaskExecutor springSessionRedisTaskExecutor() { public ThreadPoolExecutor stopTaskExecutor() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("stop-thread-%d").build(); return new ThreadPoolExecutor(10, 20, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), nameThreadFactory, - new ThreadPoolExecutor.DiscardOldestPolicy()); + new ThreadPoolExecutor.DiscardOldestPolicy()); } /** @@ -488,7 +502,7 @@ public ThreadPoolExecutor stopTaskExecutor() { public ThreadPoolExecutor bigFileThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("big-file-thread-%d").build(); return new ThreadPoolExecutor(10, 20, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5000), nameThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.AbortPolicy()); } /** @@ -498,15 +512,15 @@ public ThreadPoolExecutor bigFileThreadPool() { public ExecutorService cloudCallbackThreadPool() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("cloud-callback-%d").build(); return TtlExecutors.getTtlExecutorService( - new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, - new SynchronousQueue<>(), nameThreadFactory)); + new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, + new SynchronousQueue<>(), nameThreadFactory)); } @Bean(name = "dataCalibration") public ExecutorService dataCalibrationExecutor() { ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("data-calibration-%d").build(); return TtlExecutors.getTtlExecutorService(new ThreadPoolExecutor(10, 20, 60L, TimeUnit.SECONDS, - new ArrayBlockingQueue<>(1000), nameThreadFactory, new WaitingRejectedExecutionHandler())); + new ArrayBlockingQueue<>(1000), nameThreadFactory, new WaitingRejectedExecutionHandler())); } private static class WaitingRejectedExecutionHandler implements RejectedExecutionHandler { @@ -519,6 +533,7 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { } } } + /** * webIDE数据入库处理线程池 * @@ -537,7 +552,7 @@ public ThreadPoolExecutor performanceDebugThreadPool() { final int coreSize = Runtime.getRuntime().availableProcessors(); ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("performance-debug-%d").build(); return new ThreadPoolExecutor(coreSize, coreSize * 2, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), - nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } @Bean(name = "fileFailedPool") @@ -545,6 +560,6 @@ public ThreadPoolExecutor fileFailed() { int coreSize = Runtime.getRuntime().availableProcessors(); ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("file-failed-%d").build(); return new ThreadPoolExecutor(coreSize, coreSize * 2, 0, - TimeUnit.SECONDS, new LinkedBlockingQueue<>(400), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + TimeUnit.SECONDS, new LinkedBlockingQueue<>(400), nameThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } } diff --git a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/mybatis/TakinTenantLineInnerInterceptor.java b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/mybatis/TakinTenantLineInnerInterceptor.java index e39399e1ab..5817c4ba00 100644 --- a/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/mybatis/TakinTenantLineInnerInterceptor.java +++ b/takin-web-app/src/main/java/io/shulie/takin/web/app/conf/mybatis/TakinTenantLineInnerInterceptor.java @@ -151,7 +151,9 @@ public class TakinTenantLineInnerInterceptor extends TenantLineInnerInterceptor "t_warn_detail", "t_pressure_task_variety", "t_pressure_task_callback", - "t_interface_performance_result" + "t_interface_performance_result", + "t_tro_dept_level_name", + "t_tenant_resource" }; private String[] tableArrWithoutUserId = new String[] { diff --git a/takin-web-app/src/main/resources/application.properties b/takin-web-app/src/main/resources/application.properties index fea8b1408c..4e72e7d67a 100644 --- a/takin-web-app/src/main/resources/application.properties +++ b/takin-web-app/src/main/resources/application.properties @@ -90,6 +90,9 @@ mybatis-plus.configuration.map-underscore-to-camel-case=true mybatis-plus.mapper-locations[0]=classpath*:com/pamirs/takin/entity/mapper/**/*.xml mybatis-plus.mapper-locations[1]=classpath*:mappers/**/*.xml +takin.config.nacos.enbale=nacos +takin.config.nacos.addr=192.168.1.99:8848 + takin.config.zk.addr=192.168.1.154:2181 spring.performance.influxdb.database=performance spring.influxdb.url=http://${resource.influxdb.host:127.0.0.1}:${resource.influxdb.port:8086} @@ -168,4 +171,5 @@ cloud.influxdb.password: pradar cloud.influxdb.database: crank takin-web.server.config={"loginType": 3} -maven.pull.job.enable: true \ No newline at end of file +maven.pull.job.enable: true +agent.manager.host="" \ No newline at end of file diff --git a/takin-web-app/src/main/resources/kafka-sdk.properties b/takin-web-app/src/main/resources/kafka-sdk.properties new file mode 100644 index 0000000000..cdde69c802 --- /dev/null +++ b/takin-web-app/src/main/resources/kafka-sdk.properties @@ -0,0 +1,3 @@ +kafka.sdk.switch=true +kafka.sdk.bootstrap=192.168.1.61:9092 +kafka.poll.timeout=2000 diff --git a/takin-web-app/src/test/java/io/shulie/takin/web/biz/util/ZkHelperTest.java b/takin-web-app/src/test/java/io/shulie/takin/web/biz/util/ZkHelperTest.java index 8cce4239fb..b59d52c1eb 100644 --- a/takin-web-app/src/test/java/io/shulie/takin/web/biz/util/ZkHelperTest.java +++ b/takin-web-app/src/test/java/io/shulie/takin/web/biz/util/ZkHelperTest.java @@ -1,7 +1,7 @@ package io.shulie.takin.web.biz.util; import io.shulie.takin.web.app.Application; -import io.shulie.takin.web.biz.utils.ZkHelper; +import io.shulie.takin.web.biz.utils.PradarConfigPusher; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -17,7 +17,7 @@ public class ZkHelperTest { @Autowired - private ZkHelper zkHelper; + private PradarConfigPusher zkHelper; @Test public void test() { diff --git a/takin-web-biz-service/pom.xml b/takin-web-biz-service/pom.xml index f61bd4e413..5f574d3633 100644 --- a/takin-web-biz-service/pom.xml +++ b/takin-web-biz-service/pom.xml @@ -5,7 +5,7 @@ takin-web io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 @@ -38,6 +38,10 @@ slf4j-log4j12 org.slf4j + + fastjson + com.alibaba + @@ -47,6 +51,12 @@ io.shulie.takin takin-common-exception-starter + + + fastjson + com.alibaba + + io.shulie.takin @@ -70,6 +80,10 @@ cn.hutool hutool-all + + fastjson + com.alibaba + @@ -83,6 +97,14 @@ fastjson com.alibaba + + logback-classic + ch.qos.logback + + + logback-core + ch.qos.logback + @@ -111,6 +133,10 @@ guava com.google.guava + + fastjson + com.alibaba + @@ -142,6 +168,10 @@ jul-to-slf4j org.slf4j + + logback-classic + ch.qos.logback + @@ -170,6 +200,18 @@ commons-io commons-io + + fastjson + com.alibaba + + + logback-classic + ch.qos.logback + + + logback-core + ch.qos.logback + @@ -269,6 +311,12 @@ io.shulie.instrument.module module-pradar-core + + + fastjson + com.alibaba + + org.springframework.boot @@ -301,6 +349,17 @@ freemarker + + com.alibaba.nacos + nacos-client + 2.0.4 + + + com.alibaba + fastjson + ${fastjson.version} + + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/collector/ScheduleConfig.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/collector/ScheduleConfig.java index c91c1e1a25..aa4d2ba1c7 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/collector/ScheduleConfig.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/collector/ScheduleConfig.java @@ -108,4 +108,9 @@ public Executor jmeterHeartbeatAsyncServiceExecutor() { public ScheduledExecutorService pressureStopExecutor() { return Executors.newScheduledThreadPool(5, new NamedThreadFactory("pressure_stop", true)); } + + @Bean(name = "kafkaReceivePool") + public ScheduledExecutorService kafkaReceiveExecutor() { + return Executors.newScheduledThreadPool(10, new NamedThreadFactory("kafka_receive", true)); + } } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageQueryInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageQueryInput.java index 677872201f..daf2f0c6ab 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageQueryInput.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageQueryInput.java @@ -32,4 +32,10 @@ public class SceneManageQueryInput extends PagingContextExt { private String lastPtEndTime; private Integer isArchive; + + private Long deptId; + + private List userIdList; + + private List deptIdList; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageWrapperInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageWrapperInput.java index 20ecd8f742..1d0d393cc6 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageWrapperInput.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/input/scenemanage/SceneManageWrapperInput.java @@ -97,6 +97,8 @@ public class SceneManageWrapperInput extends ContextExt { private Long operateId; + private Long deptId; + private String operateName; private String machineId; diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageListOutput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageListOutput.java index 33566ac6f0..125601e926 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageListOutput.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageListOutput.java @@ -46,4 +46,7 @@ public class SceneManageListOutput extends ContextExt { @ApiModelProperty(value = "脚本解析结果") private String scriptAnalysisResult; + + @ApiModelProperty(value = "部门id") + private Long deptId; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageWrapperOutput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageWrapperOutput.java index 8cac0b6cea..9835937584 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageWrapperOutput.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/output/scene/manage/SceneManageWrapperOutput.java @@ -145,6 +145,8 @@ public class SceneManageWrapperOutput extends ContextExt { private String machineId; private Integer machineType; + private Long deptId; + @Data @EqualsAndHashCode(callSuper = true) public static class SceneBusinessActivityRefOutput extends SceneBusinessActivityRefBean { diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneManageServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneManageServiceImpl.java index 6ef6c091c8..025bf2539a 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneManageServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneManageServiceImpl.java @@ -392,6 +392,7 @@ public PageInfo queryPageList(SceneManageQueryInput query setTenantId(t.getTenantId()); setUserId(t.getUserId()); setUserName(null); + setDeptId(t.getDeptId()); setScriptAnalysisResult(t.getScriptAnalysisResult()); }}).collect(Collectors.toList()); Map threadNum = new HashMap<>(1); @@ -1092,6 +1093,7 @@ private void fillBase(SceneManageWrapperOutput wrapperOutput, SceneManageEntity wrapperOutput.setFeatures(sceneManageResult.getFeatures()); wrapperOutput.setScriptAnalysisResult(sceneManageResult.getScriptAnalysisResult()); wrapperOutput.setPtConfig(sceneManageResult.getPtConfig()); + wrapperOutput.setDeptId(sceneManageResult.getDeptId()); } /** @@ -1208,6 +1210,7 @@ private SceneManageCreateOrUpdateParam buildSceneManage(SceneManageWrapperInput param.setType(wrapperVO.getType() == null ? 0 : wrapperVO.getType()); param.setFeatures(wrapperVO.getFeatures()); param.setUserId(wrapperVO.getUserId()); + param.setDeptId(wrapperVO.getDeptId()); param.setTenantId(wrapperVO.getTenantId()); param.setEnvCode(wrapperVO.getEnvCode()); return param; diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneServiceImpl.java index d71025ff41..8cb05e906c 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scene/impl/CloudSceneServiceImpl.java @@ -45,6 +45,7 @@ import io.shulie.takin.adapter.api.model.response.scenemanage.SceneRequest.File; import io.shulie.takin.adapter.api.model.response.scenemanage.SceneRequest.Goal; import io.shulie.takin.adapter.api.model.response.scenemanage.SceneRequest.MonitoringGoal; +import io.shulie.takin.web.ext.util.WebPluginUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -128,7 +129,9 @@ public Boolean update(SceneRequest in) { } // 1. 创建场景 int updateRows = updateStepScene(in.getBasicInfo(), in.getConfig(), in.getAnalysisResult(), in.getDataValidation()); - if (updateRows == 0) {return false;} + if (updateRows == 0) { + return false; + } if (updateRows == 1) { long sceneId = in.getBasicInfo().getSceneId(); // 2. 更新场景&业务活动关联关系 @@ -168,9 +171,9 @@ public SceneDetailV2Response detail(long sceneId) { response.setDataValidation(getDataValidation(sceneId)); List monitoringGoal = getMonitoringGoal(sceneId); response.setDestroyMonitoringGoal( - monitoringGoal.stream().filter(t -> Integer.valueOf(0).equals(t.getType())).collect(Collectors.toList())); + monitoringGoal.stream().filter(t -> Integer.valueOf(0).equals(t.getType())).collect(Collectors.toList())); response.setWarnMonitoringGoal( - monitoringGoal.stream().filter(t -> !Integer.valueOf(0).equals(t.getType())).collect(Collectors.toList())); + monitoringGoal.stream().filter(t -> !Integer.valueOf(0).equals(t.getType())).collect(Collectors.toList())); return response; } @@ -186,7 +189,8 @@ public BasicInfo getBasicInfo(long sceneId) { SceneManageEntity scene = getScene(sceneId); // 解析拓展字段 String featureString = scene.getFeatures(); - Map feature = JSONObject.parseObject(featureString, new TypeReference>() {}); + Map feature = JSONObject.parseObject(featureString, new TypeReference>() { + }); // 获取值 String scriptIdString, businessFlowIdString; Object scriptIdResult = feature.get("scriptId"); @@ -220,7 +224,8 @@ public List getAnalysisResult(long sceneId) { String analysisResultString = scene.getScriptAnalysisResult(); if (StrUtil.isNotBlank(analysisResultString)) { return JSONObject.parseObject(analysisResultString, - new TypeReference>() {}); + new TypeReference>() { + }); } throw new TakinCloudException(TakinCloudExceptionEnum.SCENE_MANAGE_GET_ERROR, sceneId + "的脚本解析结果不存在"); } catch (JSONException e) { @@ -266,10 +271,10 @@ public Map getContent(long sceneId) { SceneManageEntity scene = getScene(sceneId); // 获取关联的信息 List activityRefList = sceneBusinessActivityRefMapper.selectList(Wrappers.lambdaQuery(SceneBusinessActivityRefEntity.class) - .eq(SceneBusinessActivityRefEntity::getSceneId, scene.getId())); + .eq(SceneBusinessActivityRefEntity::getSceneId, scene.getId())); // 构建mao结构 Map entityResult = activityRefList.stream() - .collect(Collectors.toMap(SceneBusinessActivityRefEntity::getBindRef, t -> t)); + .collect(Collectors.toMap(SceneBusinessActivityRefEntity::getBindRef, t -> t)); Map result = new HashMap<>(entityResult.size()); // 填充结果 entityResult.forEach((key, value) -> result.put(key, new Content() {{ @@ -285,7 +290,7 @@ public Map getContent(long sceneId) { }})); return result; } catch ( - JSONException e) { + JSONException e) { throw new TakinCloudException(TakinCloudExceptionEnum.SCENE_MANAGE_GET_ERROR, sceneId + "施压目标解析错误"); } } @@ -302,16 +307,16 @@ public Map getGoal(long sceneId) { SceneManageEntity scene = getScene(sceneId); // 获取关联的信息 List activityRefList = sceneBusinessActivityRefMapper.selectList(Wrappers.lambdaQuery(SceneBusinessActivityRefEntity.class) - .eq(SceneBusinessActivityRefEntity::getSceneId, scene.getId())); + .eq(SceneBusinessActivityRefEntity::getSceneId, scene.getId())); // 构建mao结构 Map stringResult = activityRefList.stream() - .collect(Collectors.toMap(SceneBusinessActivityRefEntity::getBindRef, SceneBusinessActivityRefEntity::getGoalValue)); + .collect(Collectors.toMap(SceneBusinessActivityRefEntity::getBindRef, SceneBusinessActivityRefEntity::getGoalValue)); Map result = new HashMap<>(stringResult.size()); // 填充结果 stringResult.forEach((key, value) -> result.put(key, JSONObject.parseObject(value, OldGoalModel.class).convert())); return result; } catch ( - JSONException e) { + JSONException e) { throw new TakinCloudException(TakinCloudExceptionEnum.SCENE_MANAGE_GET_ERROR, sceneId + "施压目标解析错误"); } } @@ -326,7 +331,8 @@ public Map getGoal(long sceneId) { public PtConfigExt getConfig(long sceneId) { try { SceneManageEntity scene = getScene(sceneId); - return JSONObject.parseObject(scene.getPtConfig(), new TypeReference() {}); + return JSONObject.parseObject(scene.getPtConfig(), new TypeReference() { + }); } catch (JSONException e) { throw new TakinCloudException(TakinCloudExceptionEnum.SCENE_MANAGE_GET_ERROR, sceneId + "压测线程组解析错误"); } @@ -344,10 +350,11 @@ public List getMonitoringGoal(long sceneId) { SceneManageEntity scene = getScene(sceneId); // 获取关联的信息 List slaResultList = sceneSlaRefMapper.selectList(Wrappers.lambdaQuery(SceneSlaRefEntity.class) - .eq(SceneSlaRefEntity::getSceneId, scene.getId())); + .eq(SceneSlaRefEntity::getSceneId, scene.getId())); // 构建mao结构 return slaResultList.stream().map(t -> { - Map condition = JSONObject.parseObject(t.getCondition(), new TypeReference>() {}); + Map condition = JSONObject.parseObject(t.getCondition(), new TypeReference>() { + }); String eventString = condition.getOrDefault(SceneManageConstant.EVENT, ""); String compareTypeString = condition.getOrDefault(SceneManageConstant.COMPARE_TYPE, "0"); String achieveTimesString = condition.getOrDefault(SceneManageConstant.ACHIEVE_TIMES, "0"); @@ -410,15 +417,17 @@ public SceneManageEntity getScene(long sceneId) throws TakinCloudException { * @return 压测场景主键 */ private Long createScene(BasicInfo basicInfo, - PtConfigExt config, List analysisResult, DataValidation dataValidation) { + PtConfigExt config, List analysisResult, DataValidation dataValidation) { Map feature = assembleFeature(basicInfo.getScriptId(), basicInfo.getBusinessFlowId(), dataValidation); // 组装数据实体类 SceneManageEntity sceneEntity = assembleSceneEntity(basicInfo.getSceneId(), basicInfo.getType(), basicInfo.getName(), - basicInfo.getScriptType(), config, feature, analysisResult); + basicInfo.getScriptType(), config, feature, analysisResult); + sceneEntity.setBusinessFlowId(Long.valueOf(String.valueOf(feature.getOrDefault("businessFlowId","0")))); // 设置创建者信息 sceneEntity.setUserId(CloudPluginUtils.getUserId()); sceneEntity.setEnvCode(CloudPluginUtils.getEnvCode()); sceneEntity.setTenantId(CloudPluginUtils.getTenantId()); + sceneEntity.setDeptId(WebPluginUtils.traceDeptId()); // 执行数据库操作 sceneManageMapper.insert(sceneEntity); // 回填自增主键 @@ -453,11 +462,11 @@ private Long createScene(BasicInfo basicInfo, * @return 数据库更新行数 - 应当为 1 */ private int updateStepScene(BasicInfo basicInfo, - PtConfigExt config, List analysisResult, DataValidation dataValidation) { + PtConfigExt config, List analysisResult, DataValidation dataValidation) { Map feature = assembleFeature(basicInfo.getScriptId(), basicInfo.getBusinessFlowId(), dataValidation); // 组装数据实体类 SceneManageEntity sceneEntity = assembleSceneEntity(basicInfo.getSceneId(), basicInfo.getType(), basicInfo.getName(), - basicInfo.getScriptType(), config, feature, analysisResult); + basicInfo.getScriptType(), config, feature, analysisResult); // 执行数据库操作 int updateRows = sceneManageMapper.updateById(sceneEntity); log.info("更新了业务活动「{}」。自增主键:{}。操作行数:{}。", basicInfo.getName(), sceneEntity.getId(), updateRows); @@ -475,14 +484,18 @@ private int updateStepScene(BasicInfo basicInfo, public void buildBusinessActivity(long sceneId, List content, Map goalMap) { for (Content t : content) { Goal goal = goalMap.get(t.getPathMd5()); - if (goal == null) {throw new TakinCloudException(TakinCloudExceptionEnum.SCENE_MANAGE_UPDATE_ERROR, "压测目标未能匹配:" + t.getPathMd5());} + if (goal == null) { + throw new TakinCloudException(TakinCloudExceptionEnum.SCENE_MANAGE_UPDATE_ERROR, "压测目标未能匹配:" + t.getPathMd5()); + } SceneBusinessActivityRefEntity activityRef = new SceneBusinessActivityRefEntity() {{ setSceneId(sceneId); setBindRef(t.getPathMd5()); setBusinessActivityName(t.getName()); setBusinessActivityId(t.getBusinessActivityId()); // 处理应用主键集合 - 兼容空值 - if (t.getApplicationId() == null) {t.setApplicationId(new ArrayList<>(0));} + if (t.getApplicationId() == null) { + t.setApplicationId(new ArrayList<>(0)); + } List applicationIdList = t.getApplicationId().stream().filter(StrUtil::isNotBlank).collect(Collectors.toList()); setApplicationIds(String.join(",", applicationIdList)); setGoalValue(JSONObject.toJSONString(OldGoalModel.convert(goal), SerializerFeature.PrettyFormat)); @@ -567,7 +580,7 @@ public void buildSla(long sceneId, List monitoringGoal) { put(SceneManageConstant.COMPARE_VALUE, mGoal.getFormulaNumber()); put(SceneManageConstant.COMPARE_TYPE, mGoal.getFormulaSymbol()); put(SceneManageConstant.EVENT, mGoal.getType() == 0 ? - SceneManageConstant.EVENT_DESTORY : SceneManageConstant.EVENT_WARN); + SceneManageConstant.EVENT_DESTORY : SceneManageConstant.EVENT_WARN); put(SceneManageConstant.ACHIEVE_TIMES, mGoal.getNumberOfIgnore()); }}; setSceneId(sceneId); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scenetask/CloudSceneTaskServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scenetask/CloudSceneTaskServiceImpl.java index 63e1202166..3fb4d6808e 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scenetask/CloudSceneTaskServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/scenetask/CloudSceneTaskServiceImpl.java @@ -1163,6 +1163,7 @@ public ReportEntity initReport(SceneManageWrapperOutput scene, SceneTaskStartInp //负责人默认启动人 report.setUserId(CloudPluginUtils.getUserId()); report.setSceneName(scene.getPressureTestSceneName()); + report.setDeptId(scene.getDeptId()); if (StringUtils.isNotBlank(scene.getFeatures())) { JSONObject features = JsonUtil.parse(scene.getFeatures()); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/schedule/impl/ScheduleServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/schedule/impl/ScheduleServiceImpl.java index 6f6adfe590..87689036cf 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/schedule/impl/ScheduleServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/cloud/biz/service/schedule/impl/ScheduleServiceImpl.java @@ -453,7 +453,12 @@ private void fileMappingIfNecessary(ScheduleStartRequestExt requestExt, List path.substring(path.lastIndexOf(SceneManageConstant.FILE_SPLIT)), Function.identity())); dataFile.forEach(file -> { String uri = file.getUri(); - file.setUri(fileMap.get(uri.substring(uri.lastIndexOf(SceneManageConstant.FILE_SPLIT)))); + // 文件名称 + String fileName = uri.substring(uri.lastIndexOf(SceneManageConstant.FILE_SPLIT)); + // 映射的路径 + String mapPath = fileMap.get(fileName); + // 如果没有映射就不做变更 + if (StringUtils.isNotBlank(mapPath)) {file.setUri(mapPath);} }); } } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/AbstractAgentConfigCache.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/AbstractAgentConfigCache.java index 3c276bf8b8..dd3ec50b19 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/AbstractAgentConfigCache.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/AbstractAgentConfigCache.java @@ -1,13 +1,13 @@ package io.shulie.takin.web.biz.cache; import java.util.Set; -import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import io.shulie.takin.web.biz.nacos.event.ShadowConfigRefreshEvent; import io.shulie.takin.web.biz.service.DistributedLock; -import io.shulie.takin.web.biz.service.impl.RedissonDistributedLock; import io.shulie.takin.web.common.util.CommonUtil; import io.shulie.takin.web.ext.util.WebPluginUtils; import lombok.extern.slf4j.Slf4j; @@ -15,6 +15,7 @@ import org.apache.commons.lang.exception.ExceptionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; import org.springframework.data.redis.core.RedisTemplate; /** @@ -42,6 +43,9 @@ public abstract class AbstractAgentConfigCache implements AgentCacheSupport getShadowJobs(String appName) { @@ -165,6 +173,7 @@ public ApplicationSwitchStatusDTO getPressureSwitch() { public void evictPressureSwitch() { pressureSwitchConfigCache.evict(null); + applicationContext.publishEvent(new SwitchConfigRefreshEvent()); } public List getShadowConsumer(String appName) { diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/agentimpl/ShadowKafkaClusterConfigAgentCache.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/agentimpl/ShadowKafkaClusterConfigAgentCache.java index 6d9bebecd2..bdbac4c8ce 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/agentimpl/ShadowKafkaClusterConfigAgentCache.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/cache/agentimpl/ShadowKafkaClusterConfigAgentCache.java @@ -17,7 +17,7 @@ @Component public class ShadowKafkaClusterConfigAgentCache extends AbstractAgentConfigCache> { - public static final String CACHE_NAME = "t:a:c:shadow:es"; + public static final String CACHE_NAME = "t:a:c:shadow:kafka"; @Autowired private DsService dsService; diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/AppAccessStatusJob.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/AppAccessStatusJob.java index f3b2f6e819..429fcb26bd 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/AppAccessStatusJob.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/AppAccessStatusJob.java @@ -17,7 +17,9 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -26,7 +28,10 @@ * @date 2021/6/15 5:30 下午 */ @Component -@ElasticSchedulerJob(jobName = "appAccessStatusJob", cron = "0/10 * * * * ?", description = "同步大数据应用状态", +@ElasticSchedulerJob( + jobName = "appAccessStatusJob", + cron = "0/20 * * * * ?", + description = "同步大数据应用状态", // 时效转移 misfire = true, // 重新执行 @@ -37,8 +42,8 @@ public class AppAccessStatusJob implements SimpleJob { @Autowired private ApplicationService applicationService; @Resource - @Qualifier("syncAppStatusThreadPool") - private ThreadPoolExecutor syncAppStatusThreadPool; + @Qualifier("jobThreadPool") + private ThreadPoolExecutor jobThreadPool; @Autowired private DistributedLock distributedLock; @@ -51,19 +56,21 @@ public void execute(ShardingContext shardingContext) { return; } List tenantInfoExts = WebPluginUtils.getTenantInfoList(); + List> futureList = new ArrayList<>(tenantInfoExts.size() << 1); for (TenantInfoExt ext : tenantInfoExts) { if (CollectionUtils.isEmpty(ext.getEnvs())) { continue; } - // 根据环境 分线程 - for (TenantEnv e : ext.getEnvs()) { - int shardKey = (ext.getTenantId() + e.getEnvCode()).hashCode() & Integer.MAX_VALUE; - if (shardKey % shardingContext.getShardingTotalCount() == shardingContext.getShardingItem()) { - String lockKey = JobRedisUtils.getJobRedis(ext.getTenantId(), e.getEnvCode(), shardingContext.getJobName()); - if (distributedLock.checkLock(lockKey)) { - continue; - } - syncAppStatusThreadPool.execute(() -> { + Runnable r = () -> { + // 根据环境 分线程 + for (TenantEnv e : ext.getEnvs()) { + int shardKey = (ext.getTenantId() + e.getEnvCode()).hashCode() & Integer.MAX_VALUE; + if (shardKey % shardingContext.getShardingTotalCount() == shardingContext.getShardingItem()) { + String lockKey = JobRedisUtils.getJobRedis(ext.getTenantId(), e.getEnvCode(), shardingContext.getJobName()); + if (distributedLock.checkLock(lockKey)) { + continue; + } + boolean tryLock = distributedLock.tryLock(lockKey, 0L, 1L, TimeUnit.MINUTES); if (!tryLock) { return; @@ -77,9 +84,15 @@ public void execute(ShardingContext shardingContext) { } finally { distributedLock.unLockSafely(lockKey); } - }); + } + } - } + }; + futureList.add(CompletableFuture.runAsync(r, jobThreadPool)); } + try { + CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).get(); + } catch (Exception ignore) {} } + } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceChangeJob.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceChangeJob.java new file mode 100644 index 0000000000..852c1b1f37 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceChangeJob.java @@ -0,0 +1,113 @@ +package io.shulie.takin.web.biz.job; + +import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.api.simple.SimpleJob; +import com.pamirs.takin.common.constant.AppSwitchEnum; +import com.pamirs.takin.entity.domain.dto.ApplicationSwitchStatusDTO; +import io.shulie.takin.job.annotation.ElasticSchedulerJob; +import io.shulie.takin.web.biz.cache.AgentConfigCacheManager; +import io.shulie.takin.web.biz.service.DistributedLock; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommandService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.service.pressureresource.common.ModuleEnum; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.biz.utils.job.JobRedisUtils; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 压测资源关联应用 + */ +@Component +@ElasticSchedulerJob(jobName = "PressureResourceChangeJob", + isSharding = false, + cron = "0/10 * * * * ? *", + description = "配置资源修改立即触发") +@Slf4j +public class PressureResourceChangeJob implements SimpleJob { + + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @Autowired + private PressureResourceCommandService pressureResourceCommandService; + + @Resource + @Qualifier("pressureResourceThreadPool") + private ThreadPoolExecutor pressureResourceThreadPool; + + @Resource + private DistributedLock distributedLock; + + @Resource + private PressureResourceMapper pressureResourceMapper; + + @Resource + private AgentConfigCacheManager agentConfigCacheManager; + + @PostConstruct + public void init(){ + execute(null); + } + + @Override + public void execute(ShardingContext shardingContext) { + // 如果压测开关关闭或者静默开关打开,则不发送命令 + if (!shouldSendCommand()) { + return; + } + // 查询所有压测资源准备配置 + List commandTaskVos = pressureResourceCommonService.getTaskFormRedis(); + if (CollectionUtils.isEmpty(commandTaskVos)) { + return; + } + commandTaskVos.forEach(taskVo -> { + String lockKey = JobRedisUtils.getRedisJobResource(1L, "change", taskVo.getResourceId()); + if (distributedLock.checkLock(lockKey)) { + return; + } + pressureResourceThreadPool.execute(() -> { + boolean tryLock = distributedLock.tryLock(lockKey, 0L, 60L, TimeUnit.SECONDS); + if (!tryLock) { + return; + } + try { + PressureResourceEntity resource = pressureResourceMapper.queryByIdNoTenant(taskVo.getResourceId()); + if (resource == null) { + log.warn("当前资源准备{}状态调整未查询到数据", taskVo.getResourceId()); + return; + } + ResourceContextUtil.setTenantContext(resource); + pressureResourceCommandService.pushCommand(taskVo); + } finally { + // 移除Redis数据 + pressureResourceCommonService.deleteCommandTask(taskVo); + distributedLock.unLockSafely(lockKey); + } + }); + }); + } + + /** + * 如果压测开关关闭或者静默开关打开,则不发送命令 + * + * @return + */ + private boolean shouldSendCommand() { + ApplicationSwitchStatusDTO pressureSwitch = agentConfigCacheManager.getPressureSwitch(); + return AppSwitchEnum.OPENED.getCode().equals(pressureSwitch.getSwitchStatus()) && AppSwitchEnum.CLOSED.getCode().equals(pressureSwitch.getSilenceSwitchOn()); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceCommandJob.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceCommandJob.java new file mode 100644 index 0000000000..1ef1403281 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceCommandJob.java @@ -0,0 +1,99 @@ +package io.shulie.takin.web.biz.job; + +import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.api.simple.SimpleJob; +import com.pamirs.takin.common.constant.AppSwitchEnum; +import com.pamirs.takin.entity.domain.dto.ApplicationSwitchStatusDTO; +import io.shulie.takin.job.annotation.ElasticSchedulerJob; +import io.shulie.takin.web.biz.cache.AgentConfigCacheManager; +import io.shulie.takin.web.biz.nacos.NacosConfigManager; +import io.shulie.takin.web.biz.service.DistributedLock; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommandService; +import io.shulie.takin.web.biz.service.pressureresource.common.ModuleEnum; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.biz.utils.job.JobRedisUtils; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDAO; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 压测资源关联应用 + */ +@Component +@ElasticSchedulerJob(jobName = "pressureResourceCommandJob", + isSharding = true, + cron = "0 0/10 * * * ?", + description = "下发验证命令") +@Slf4j +public class PressureResourceCommandJob implements SimpleJob { + + @Resource + private PressureResourceDAO pressureResourceDAO; + + @Autowired + private PressureResourceCommandService pressureResourceCommandService; + + @Resource + @Qualifier("pressureResourceThreadPool") + private ThreadPoolExecutor pressureResourceThreadPool; + + @Resource + private DistributedLock distributedLock; + + @Resource + private NacosConfigManager nacosConfigManager; + + @Override + public void execute(ShardingContext shardingContext) { + // 如果使用nacos做配置中心,则只在配置修改时才发送命令 + if (nacosConfigManager.useNacosForConfigCenter()) { + return; + } + // 查询所有压测资源准备配置 + List resourceList = pressureResourceDAO.getAll(); + if (CollectionUtils.isEmpty(resourceList)) { + log.warn("当前压测资源准备配置为空,暂不处理!!!"); + return; + } + // 按配置Id分片 + List filterList = resourceList.stream().filter(resouce -> + resouce.getId() % shardingContext.getShardingTotalCount() == shardingContext.getShardingItem()) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(filterList)) { + return; + } + filterList.forEach(resource -> { + String lockKey = JobRedisUtils.getRedisJobResource(1L, "command", resource.getId()); + if (distributedLock.checkLock(lockKey)) { + return; + } + pressureResourceThreadPool.execute(() -> { + boolean tryLock = distributedLock.tryLock(lockKey, 0L, 60L, TimeUnit.SECONDS); + if (!tryLock) { + return; + } + try { + ResourceContextUtil.setTenantContext(resource); + CommandTaskVo commandTaskVo = new CommandTaskVo(); + commandTaskVo.setResourceId(resource.getId()); + commandTaskVo.setModule(ModuleEnum.ALL.getCode()); + pressureResourceCommandService.pushCommand(commandTaskVo); + } finally { + distributedLock.unLockSafely(lockKey); + } + + }); + }); + } + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceJob.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceJob.java new file mode 100644 index 0000000000..b8d6f4a4fa --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceJob.java @@ -0,0 +1,76 @@ +package io.shulie.takin.web.biz.job; + +import com.alibaba.excel.util.CollectionUtils; +import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.api.simple.SimpleJob; +import io.shulie.takin.job.annotation.ElasticSchedulerJob; +import io.shulie.takin.web.biz.service.DistributedLock; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.utils.job.JobRedisUtils; +import io.shulie.takin.web.common.enums.ContextSourceEnum; +import io.shulie.takin.web.ext.entity.tenant.TenantCommonExt; +import io.shulie.takin.web.ext.entity.tenant.TenantInfoExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +@Component +@ElasticSchedulerJob(jobName = "pressureResourceJob", + isSharding = true, + cron = "0 0/1 * * * ? *", + description = "压测资源准备自动梳理") +@Slf4j +public class PressureResourceJob implements SimpleJob { + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @Resource + private DistributedLock distributedLock; + + @Resource + @Qualifier("pressureResourceThreadPool") + private ThreadPoolExecutor pressureResourceThreadPool; + + @Override + public void execute(ShardingContext shardingContext) { + List tenantInfoExts = WebPluginUtils.getTenantInfoList(); + for (TenantInfoExt ext : tenantInfoExts) { + if (CollectionUtils.isEmpty(ext.getEnvs())) { + continue; + } + // 开始数据层分片 + for (TenantInfoExt.TenantEnv e : ext.getEnvs()) { + // 分片key + int shardKey = (ext.getTenantId() + e.getEnvCode()).hashCode() & Integer.MAX_VALUE; + if (shardKey % shardingContext.getShardingTotalCount() == shardingContext.getShardingItem()) { + // 分布式锁 + String lockKey = JobRedisUtils.getJobRedis(ext.getTenantId(), e.getEnvCode(), shardingContext.getJobName()); + if (distributedLock.checkLock(lockKey)) { + continue; + } + pressureResourceThreadPool.execute(() -> { + try { + boolean tryLock = distributedLock.tryLock(lockKey, 0L, 60L, TimeUnit.SECONDS); + if (!tryLock) { + return; + } + WebPluginUtils.setTraceTenantContext( + new TenantCommonExt(ext.getTenantId(), ext.getTenantAppKey(), e.getEnvCode(), + ext.getTenantCode(), ContextSourceEnum.JOB.getCode())); + pressureResourceCommonService.processAutoPressureResource(); + } finally { + distributedLock.unLockSafely(lockKey); + } + }); + } + + } + } + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceRelateJob.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceRelateJob.java new file mode 100644 index 0000000000..0d5716b589 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceRelateJob.java @@ -0,0 +1,83 @@ +package io.shulie.takin.web.biz.job; + +import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.api.simple.SimpleJob; +import io.shulie.takin.job.annotation.ElasticSchedulerJob; +import io.shulie.takin.web.biz.service.DistributedLock; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.service.pressureresource.common.IsolateTypeEnum; +import io.shulie.takin.web.biz.utils.job.JobRedisUtils; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDAO; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 压测资源关联应用,数据源,表 + */ +@Component +@ElasticSchedulerJob(jobName = "pressureResourceRelateJob", + isSharding = true, + cron = "0 0/1 * * * ? *", + description = "压测资源准备-压测资源关联应用,数据源,表") +@Slf4j +public class PressureResourceRelateJob implements SimpleJob { + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @Resource + private PressureResourceDAO pressureResourceDAO; + + @Resource + @Qualifier("pressureResourceThreadPool") + private ThreadPoolExecutor pressureResourceThreadPool; + + @Resource + private DistributedLock distributedLock; + + @Override + public void execute(ShardingContext shardingContext) { + // 查询所有压测资源准备配置 + List resourceList = pressureResourceDAO.getAll(); + if (CollectionUtils.isEmpty(resourceList)) { + log.warn("当前压测资源准备配置为空,暂不处理!!!"); + return; + } + // 按配置Id分片 + List filterList = resourceList.stream().filter(resouce -> + resouce.getId() % shardingContext.getShardingTotalCount() == shardingContext.getShardingItem()) + .collect(Collectors.toList()); + + if (CollectionUtils.isEmpty(filterList)) { + return; + } + for (int i = 0; i < filterList.size(); i++) { + PressureResourceEntity resource = filterList.get(i); + String lockKey = JobRedisUtils.getRedisJobResource(1L, "default", "PressureResourceRelateJob" + resource.getId()); + if (distributedLock.checkLock(lockKey)) { + continue; + } + pressureResourceThreadPool.execute(() -> { + try { + boolean tryLock = distributedLock.tryLock(lockKey, 0L, 60L, TimeUnit.SECONDS); + if (!tryLock) { + return; + } + ResourceContextUtil.setTenantContext(resource); + pressureResourceCommonService.processAutoPressureResourceRelate(resource); + } finally { + distributedLock.unLockSafely(lockKey); + } + }); + } + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceRelateRemoteCallJob.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceRelateRemoteCallJob.java new file mode 100644 index 0000000000..a871964733 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/PressureResourceRelateRemoteCallJob.java @@ -0,0 +1,81 @@ +package io.shulie.takin.web.biz.job; + +import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.api.simple.SimpleJob; +import io.shulie.takin.job.annotation.ElasticSchedulerJob; +import io.shulie.takin.web.biz.service.DistributedLock; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.utils.job.JobRedisUtils; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDAO; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 压测资源关联远程调用 + */ +@Component +@ElasticSchedulerJob(jobName = "pressureResourceRelateRemoteCallJob", + isSharding = true, + cron = "0 0/1 * * * ? *", + description = "压测资源准备-压测资源关联远程调用") +@Slf4j +public class PressureResourceRelateRemoteCallJob implements SimpleJob { + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @Resource + private PressureResourceDAO pressureResourceDAO; + + @Resource + @Qualifier("pressureResourceThreadPool") + private ThreadPoolExecutor pressureResourceThreadPool; + + @Resource + private DistributedLock distributedLock; + + @Override + public void execute(ShardingContext shardingContext) { + // 查询所有压测资源准备配置 + List resourceList = pressureResourceDAO.getAll(); + if (CollectionUtils.isEmpty(resourceList)) { + log.warn("当前压测资源准备配置为空,暂不处理!!!"); + return; + } + // 按配置Id分片 + List filterList = resourceList.stream().filter(resouce -> + resouce.getId() % shardingContext.getShardingTotalCount() == shardingContext.getShardingItem()) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(filterList)) { + return; + } + + for (int i = 0; i < filterList.size(); i++) { + PressureResourceEntity resource = filterList.get(i); + String lockKey = JobRedisUtils.getRedisJobResource(1L, "default", "PressureResourceRelateRemoteCallJob" + resource.getId()); + if (distributedLock.checkLock(lockKey)) { + continue; + } + pressureResourceThreadPool.execute(() -> { + try { + boolean tryLock = distributedLock.tryLock(lockKey, 0L, 60L, TimeUnit.SECONDS); + if (!tryLock) { + return; + } + ResourceContextUtil.setTenantContext(resource); + pressureResourceCommonService.processAutoPressureResourceRelate_remoteCall(resource); + } finally { + distributedLock.unLockSafely(lockKey); + } + }); + } + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/ResourceContextUtil.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/ResourceContextUtil.java new file mode 100644 index 0000000000..c2a870affb --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/job/ResourceContextUtil.java @@ -0,0 +1,38 @@ +package io.shulie.takin.web.biz.job; + +import io.shulie.takin.web.common.enums.ContextSourceEnum; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import io.shulie.takin.web.ext.entity.tenant.TenantCommonExt; +import io.shulie.takin.web.ext.entity.tenant.TenantInfoExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/28 10:22 AM + */ +public class ResourceContextUtil { + /** + * 根据Resource设置上下文 + * + * @param resource + */ + public static void setTenantContext(PressureResourceEntity resource) { + if (resource == null) { + return; + } + TenantCommonExt commonExt = new TenantCommonExt(); + commonExt.setSource(ContextSourceEnum.JOB.getCode()); + commonExt.setEnvCode(resource.getEnvCode()); + commonExt.setTenantId(resource.getTenantId()); + TenantInfoExt tenantInfoExt = WebPluginUtils.getTenantInfo(resource.getTenantId()); + if (tenantInfoExt == null) { + return; + } + String tenantCode = tenantInfoExt.getTenantCode(); + String tenantAppKey = tenantInfoExt.getTenantAppKey(); + commonExt.setTenantAppKey(tenantAppKey); + commonExt.setTenantCode(tenantCode); + WebPluginUtils.setTraceTenantContext(commonExt); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/NacosConfigManager.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/NacosConfigManager.java new file mode 100644 index 0000000000..7afab96763 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/NacosConfigManager.java @@ -0,0 +1,310 @@ +package io.shulie.takin.web.biz.nacos; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.util.TypeUtils; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.common.utils.CollectionUtils; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.google.gson.Gson; +import com.pamirs.takin.common.constant.ConfigConstants; +import com.pamirs.takin.entity.domain.dto.config.WhiteListSwitchDTO; +import io.shulie.takin.web.biz.cache.AgentConfigCacheManager; +import io.shulie.takin.web.biz.cache.agentimpl.ApplicationApiManageAmdbCache; +import io.shulie.takin.web.biz.nacos.event.DynamicConfigRefreshEvent; +import io.shulie.takin.web.biz.nacos.event.ShadowConfigRefreshEvent; +import io.shulie.takin.web.biz.nacos.event.SwitchConfigRefreshEvent; +import io.shulie.takin.web.biz.pojo.bo.ConfigListQueryBO; +import io.shulie.takin.web.biz.pojo.request.fastagentaccess.AgentConfigQueryRequest; +import io.shulie.takin.web.biz.pojo.response.fastagentaccess.AgentConfigListResponse; +import io.shulie.takin.web.biz.service.fastagentaccess.AgentConfigService; +import io.shulie.takin.web.common.enums.ContextSourceEnum; +import io.shulie.takin.web.common.enums.fastagentaccess.AgentConfigTypeEnum; +import io.shulie.takin.web.data.dao.application.ApplicationDAO; +import io.shulie.takin.web.data.dao.fastagentaccess.impl.AgentConfigDAOImpl; +import io.shulie.takin.web.data.mapper.mysql.ClusterNacosConfigurationMapper; +import io.shulie.takin.web.data.model.mysql.ClusterNacosConfiguration; +import io.shulie.takin.web.data.param.application.ApplicationQueryParam; +import io.shulie.takin.web.data.param.fastagentaccess.AgentConfigQueryParam; +import io.shulie.takin.web.data.result.application.AgentConfigDetailResult; +import io.shulie.takin.web.data.result.application.ApplicationDetailResult; +import io.shulie.takin.web.ext.entity.tenant.TenantCommonExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.*; +import java.util.stream.Collectors; + +@Slf4j +@Component +public class NacosConfigManager { + + /** + * 业务线程池 + */ + private ThreadPoolExecutor threadPool; + + private Map configServices = new HashMap<>(); + + @Resource + private AgentConfigCacheManager agentConfigCacheManager; + + @Resource + private ApplicationApiManageAmdbCache applicationApiManageAmdbCache; + + @Resource + private AgentConfigDAOImpl agentConfigDAO; + + @Resource + private ClusterNacosConfigurationMapper clusterNacosConfigurationMapper; + + @Resource + private ApplicationDAO applicationDAO; + + @Resource + private AgentConfigService agentConfigService; + + @PostConstruct + public void init() { + List nacosEntities; + try { + nacosEntities = clusterNacosConfigurationMapper.selectAll(); + } catch (Exception e) { + return; + } + if (CollectionUtils.isEmpty(nacosEntities)) { + return; + } + try { + for (ClusterNacosConfiguration entity : nacosEntities) { + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, entity.getNacosServerAddr()); + if (entity.getNacosNamespace() != null) { + properties.put(PropertyKeyConst.NAMESPACE, entity.getNacosNamespace()); + } + ConfigService service = ConfigFactory.createConfigService(properties); + configServices.put(entity.getClusterName(), service); + } + } catch (Exception e) { + log.error("创建nacos连接时失败, 不使用nacos作为配置中心", e); + configServices = Collections.EMPTY_MAP; + return; + } + + ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("nacos-config-push-thread-%d").build(); + //丢弃任务,写异常日志,但是不抛出异常 + RejectedExecutionHandler handler = (r, executor) -> log.error("Task " + r.toString() + " rejected from " + executor.toString()); + int processors = Runtime.getRuntime().availableProcessors(); + threadPool = new ThreadPoolExecutor(processors + 1, 2 * processors, 1L, TimeUnit.MINUTES, + new LinkedBlockingQueue(100), factory, handler); + } + + /** + * 触发缓存失效 + * + * @param event + */ + @EventListener + public void refreshShadowConfigs(ShadowConfigRefreshEvent event) { + if (configServices.isEmpty()) { + return; + } + String appName = event.getAppName(); + TenantCommonExt commonExt = event.getCommonExt(); + String clusterName = queryClusterName(appName, commonExt.getEnvCode(), commonExt.getTenantId()); + if (clusterName == null) { + return; + } + if (!configServices.containsKey(clusterName)) { + log.warn("不存在应用指定的集群中心nacos配置,应用名称:{}, 集群名称:{}", appName, clusterName); + } + threadPool.submit(new ShadowConfigsRefreshTask(appName, commonExt, configServices.get(clusterName))); + } + + /** + * 刷新动态参数 + */ + @EventListener + public void refreshDynamicConfigs(DynamicConfigRefreshEvent event) { + if (configServices.isEmpty()) { + return; + } + String appName = event.getAppName(); + // 刷新全局配置 + if (appName == null) { + threadPool.submit(new GlobalDynamicConfigRefreshTask(event.getCommonExt())); + return; + } + WebPluginUtils.setTraceTenantContext(event.getCommonExt()); + // 刷新应用配置 + ApplicationDetailResult result = applicationDAO.getApplicationByTenantIdAndName(appName); + String clusterName = result.getClusterName(); + if (result == null || clusterName == null) { + return; + } + threadPool.submit(new ShadowConfigsRefreshTask(appName, event.getCommonExt(), configServices.get(clusterName))); + + } + + /** + * 推送开关配置和白名单开关 + * + * @param event + */ + @EventListener + public void refreshSwitchConfigs(SwitchConfigRefreshEvent event) { + threadPool.submit(new SwitchConfigRefreshTask()); + } + + public void pushNacosConfigs(String dataId, String group, ConfigService configService, String configs) { + try { + configService.publishConfig(dataId, group, configs); + } catch (NacosException e) { + log.error("推送配置到nacos发生异常,dataId:{}, group:{}, content:{}", dataId, group, configs); + } + } + + public String queryClusterName(String appName, String envCode, Long tenantId) { + if (configServices.isEmpty()) { + return null; + } + String key = buildCacheKey(appName, envCode, tenantId); + ApplicationQueryParam param = new ApplicationQueryParam(); + param.setApplicationName(appName); + param.setEnvCode(envCode); + param.setTenantId(tenantId); + List result = applicationDAO.getApplicationList(param); + if (result == null || result.isEmpty()) { + return null; + } + return result.get(0).getClusterName(); + } + + private String buildCacheKey(String appName, String envCode, Long tenantId) { + return String.format("%s:%s:%s", tenantId, envCode, appName); + } + + private Map buildApplicationDynamicConfigs(String appName, Long tenantId, String envCode, String userAppKey) { + // 租户全局配置 + AgentConfigQueryRequest queryRequest = new AgentConfigQueryRequest(); + queryRequest.setReadProjectConfig(false); + List globalConfigList = agentConfigService.list(queryRequest); + Map configMap = globalConfigList.stream().collect(Collectors.toMap(AgentConfigListResponse::getEnKey, x -> x, (v1, v2) -> v2)); + + AgentConfigQueryParam queryParam = new AgentConfigQueryParam(); + queryParam.setEffectMechanism(1); + queryParam.setTenantId(tenantId); + queryParam.setEnvCode(envCode); + queryParam.setType(AgentConfigTypeEnum.TENANT_GLOBAL.getVal()); + // 应用配置 + queryParam.setUserAppKey(userAppKey); + queryParam.setProjectName(appName); + Map appMap = new HashMap<>(); + List projectConfigList = agentConfigDAO.findProjectList(queryParam); + // 3、将应用配置替换掉全局配置 + for (AgentConfigDetailResult detailResult : projectConfigList) { + // 如果应用配置的key在全局配置中不存在,则直接跳过 + if (!configMap.containsKey(detailResult.getEnKey())) { + continue; + } + appMap.put(detailResult.getEnKey(),detailResult.getDefaultValue()); + } + return appMap; + } + + /** + * 是否使用nacos做配置中心 + * + * @return + */ + public boolean useNacosForConfigCenter() { + return !configServices.isEmpty(); + } + + /** + * 影子配置和应用动态参数配置 + */ + private class ShadowConfigsRefreshTask implements Runnable { + + private String appName; + private TenantCommonExt commonExt; + private ConfigService configService; + + public ShadowConfigsRefreshTask(String appName, TenantCommonExt commonExt, ConfigService configService) { + this.appName = appName; + this.commonExt = commonExt; + this.configService = configService; + } + + @Override + public void run() { + commonExt.setSource(ContextSourceEnum.FRONT.getCode()); + WebPluginUtils.setTraceTenantContext(commonExt); + + Map configs = new HashMap<>(); + configs.put("datasource", agentConfigCacheManager.getShadowDb(appName)); + configs.put("job", agentConfigCacheManager.getShadowJobs(appName)); + configs.put("mq", agentConfigCacheManager.getShadowConsumer(appName)); + configs.put("whitelist", agentConfigCacheManager.getRemoteCallConfig(appName)); + configs.put("hbase", agentConfigCacheManager.getShadowHbase(appName)); + configs.put("redis", agentConfigCacheManager.getShadowServer(appName)); + configs.put("es", agentConfigCacheManager.getShadowEsServers(appName)); + configs.put("mock", agentConfigCacheManager.getGuards(appName)); + Map> values = applicationApiManageAmdbCache.get(appName); + configs.put("trace_rule", values == null ? new HashMap<>() : values); + configs.put("dynamic_config", buildApplicationDynamicConfigs(appName, commonExt.getTenantId(), commonExt.getEnvCode(), commonExt.getTenantAppKey())); + pushNacosConfigs(appName, "APP", configService, new Gson().toJson(configs)); + } + } + + /** + * 全局动态参数配置刷新 + */ + private class GlobalDynamicConfigRefreshTask implements Runnable { + + private TenantCommonExt commonExt; + + public GlobalDynamicConfigRefreshTask(TenantCommonExt commonExt) { + this.commonExt = commonExt; + } + + @Override + public void run() { + // 全局配置 + WebPluginUtils.setTraceTenantContext(commonExt); + AgentConfigQueryRequest queryRequest = new AgentConfigQueryRequest(); + queryRequest.setReadProjectConfig(false); + List configListResponses = agentConfigService.list(queryRequest); + Map configMap = configListResponses.stream().collect(Collectors.toMap(AgentConfigListResponse::getEnKey, AgentConfigListResponse::getDefaultValue)); + // 全局配置每个nacos都推送 + configServices.entrySet().forEach(entry -> pushNacosConfigs("globalConfig", "GLOBAL_CONFIG", entry.getValue(), JSON.toJSONString(configMap))); + } + } + + /** + * 压测开关和白名单开关配置 + */ + private class SwitchConfigRefreshTask implements Runnable { + + @Override + public void run() { + Map values = new HashMap<>(); + WhiteListSwitchDTO switchDTO = new WhiteListSwitchDTO(); + switchDTO.setConfigCode(ConfigConstants.WHITE_LIST_SWITCH); + switchDTO.setSwitchFlagFix(agentConfigCacheManager.getAllowListSwitch()); + values.put("whiteListSwitch", switchDTO); + + values.put("globalSwithc", agentConfigCacheManager.getPressureSwitch()); + configServices.entrySet().forEach(entry -> pushNacosConfigs("clusterConfig", "CLUSTER_CONFIG", entry.getValue(), JSON.toJSONString(values))); + + } + } + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/DynamicConfigRefreshEvent.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/DynamicConfigRefreshEvent.java new file mode 100644 index 0000000000..05bf7e95a3 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/DynamicConfigRefreshEvent.java @@ -0,0 +1,23 @@ +package io.shulie.takin.web.biz.nacos.event; + +import io.shulie.takin.web.ext.entity.tenant.TenantCommonExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; + +public class DynamicConfigRefreshEvent { + + private String appName; + + private TenantCommonExt commonExt = WebPluginUtils.traceTenantCommonExt(); + + public DynamicConfigRefreshEvent(String appName) { + this.appName = appName; + } + + public String getAppName() { + return appName; + } + + public TenantCommonExt getCommonExt() { + return commonExt; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/ShadowConfigRefreshEvent.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/ShadowConfigRefreshEvent.java new file mode 100644 index 0000000000..62c80dda4b --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/ShadowConfigRefreshEvent.java @@ -0,0 +1,21 @@ +package io.shulie.takin.web.biz.nacos.event; + +import io.shulie.takin.web.ext.entity.tenant.TenantCommonExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; + +public class ShadowConfigRefreshEvent { + private String appName; + private TenantCommonExt commonExt = WebPluginUtils.traceTenantCommonExt(); + + public ShadowConfigRefreshEvent(String appName) { + this.appName = appName; + } + + public String getAppName() { + return appName; + } + + public TenantCommonExt getCommonExt() { + return commonExt; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/SwitchConfigRefreshEvent.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/SwitchConfigRefreshEvent.java new file mode 100644 index 0000000000..781c21c684 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/nacos/event/SwitchConfigRefreshEvent.java @@ -0,0 +1,8 @@ +package io.shulie.takin.web.biz.nacos.event; + +/** + * 开关刷新事件 + */ +public class SwitchConfigRefreshEvent { + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ApplicationDsCreateInputV2.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ApplicationDsCreateInputV2.java index 5da4652c5a..849b94b523 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ApplicationDsCreateInputV2.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ApplicationDsCreateInputV2.java @@ -3,6 +3,7 @@ import io.shulie.takin.web.ext.entity.UserCommonExt; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.Info; import lombok.Data; import javax.validation.Valid; @@ -16,20 +17,18 @@ @Valid @ApiModel public class ApplicationDsCreateInputV2 extends UserCommonExt { - - /** * 应用id */ @NotNull - @ApiModelProperty(name = "applicationId", value = "应用id",required =true) + @ApiModelProperty(name = "applicationId", value = "应用id", required = true) private Long applicationId; /** * 中间件类型 */ @NotNull - @ApiModelProperty(name = "middlewareType", value = "中间件类型",required =true) + @ApiModelProperty(name = "middlewareType", value = "中间件类型", required = true) private String middlewareType; @ApiModelProperty(name = "cacheType", value = "缓存模式") @@ -42,7 +41,7 @@ public class ApplicationDsCreateInputV2 extends UserCommonExt { * 方案类型 DsTypeEnum.Class */ @NotNull - @ApiModelProperty(name = "dsType", value = "方案类型",required =true) + @ApiModelProperty(name = "dsType", value = "方案类型", required = true) private Integer dsType; @ApiModelProperty(name = "shaDowUrl", value = "影子数据源") @@ -59,22 +58,22 @@ public class ApplicationDsCreateInputV2 extends UserCommonExt { * 其他配置信息 */ @NotNull - @ApiModelProperty(name = "extInfo", value = "其他配置信息",required =true) + @ApiModelProperty(name = "extInfo", value = "其他配置信息", required = true) private String extInfo; /** * 其他配置信息 */ - @ApiModelProperty(name = "agentSourceType",required =true) + @ApiModelProperty(name = "agentSourceType", required = true) private String agentSourceType; - @ApiModelProperty(name = "connectionPool",value = "中间件名称",required =true) + @ApiModelProperty(name = "connectionPool", value = "中间件名称", required = true) private String connectionPool; /** * 应用名称 */ - @ApiModelProperty(name = "applicationName", value = "应用名称",required =true) + @ApiModelProperty(name = "applicationName", value = "应用名称", required = true) private String applicationName; @@ -91,7 +90,20 @@ public class ApplicationDsCreateInputV2 extends UserCommonExt { /** * 老数据转换过来的标识 */ - private Boolean isOld =false; + private Boolean isOld = false; + /** + * 压测资源准备-资源Id + */ + private Long resourceId; + /** + * 压测资源准备-详情Id + */ + private Long detailId; + + /** + * 手工还是/自动 来源类型(0-手工,1-自动) + */ + private Integer type; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ShadowConsumerCreateInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ShadowConsumerCreateInput.java index 09599b6c22..2ff669fcd3 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ShadowConsumerCreateInput.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/input/application/ShadowConsumerCreateInput.java @@ -36,4 +36,8 @@ public class ShadowConsumerCreateInput { */ private String shadowconsumerEnable; + /** + * 来源标识 + */ + private Integer manualTag; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/activity/ActivityQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/activity/ActivityQueryRequest.java index 6cbf55f710..61bf3922f6 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/activity/ActivityQueryRequest.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/activity/ActivityQueryRequest.java @@ -31,4 +31,7 @@ public class ActivityQueryRequest extends PagingDevice { @ApiModelProperty(name= "type",value = "正常、虚拟:0:正常:1虚拟") private Integer type; + + @ApiModelProperty("部门id") + private Long deptId; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationEntranceTopologyQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationEntranceTopologyQueryRequest.java index 08b061b26a..e7ee7c9589 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationEntranceTopologyQueryRequest.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationEntranceTopologyQueryRequest.java @@ -33,4 +33,7 @@ public class ApplicationEntranceTopologyQueryRequest { private String nodeId; private EntranceTypeEnum type; + + // 原始的链路拓扑图 + private boolean isConvert; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationEntrancesAllQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationEntrancesAllQueryRequest.java new file mode 100644 index 0000000000..013792b5f1 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationEntrancesAllQueryRequest.java @@ -0,0 +1,21 @@ +package io.shulie.takin.web.biz.pojo.request.application; + +import com.pamirs.takin.entity.domain.PagingDevice; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author shiyajian + * create: 2020-12-29 + */ +@Data +@ApiModel("应用入口服务查询对象") +public class ApplicationEntrancesAllQueryRequest extends PagingDevice { + @ApiModelProperty("应用名称") + private String applicationName; + + @ApiModelProperty("服务名称") + private String serviceName; + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationQueryRequestV2.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationQueryRequestV2.java index b7fac93fd7..683059b631 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationQueryRequestV2.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/application/ApplicationQueryRequestV2.java @@ -28,4 +28,10 @@ public class ApplicationQueryRequestV2 extends PageBaseDTO { @ApiModelProperty("更新时间结束") private String updateEndTime; + + @ApiModelProperty("部门id") + private Long deptId; + + @ApiModelProperty("全量操作的时候,不要状态") + private boolean all = false; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/datasource/DataSourceQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/datasource/DataSourceQueryRequest.java index ef7834e0fc..ddc2adde55 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/datasource/DataSourceQueryRequest.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/datasource/DataSourceQueryRequest.java @@ -31,4 +31,6 @@ public class DataSourceQueryRequest extends PagingDevice { @ApiModelProperty("数据源地址") @Size(max = 100) private String jdbcUrl; + + private Long deptId; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/linkmanage/BusinessFlowPageQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/linkmanage/BusinessFlowPageQueryRequest.java index 95781e160a..103e2fc593 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/linkmanage/BusinessFlowPageQueryRequest.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/linkmanage/BusinessFlowPageQueryRequest.java @@ -5,10 +5,18 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.Date; + @Data @ApiModel("业务流程列表查询--入参") public class BusinessFlowPageQueryRequest extends PagingDevice { @ApiModelProperty("业务流程名称") private String businessFlowName; + + @ApiModelProperty("部门id") + private Long deptId; + + @ApiModelProperty("过滤时间范围") + private Date queryGmtModified; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/ExtInfo.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/ExtInfo.java new file mode 100644 index 0000000000..313ca8d57d --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/ExtInfo.java @@ -0,0 +1,23 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + + +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/1 10:10 AM + */ +@Data +public class ExtInfo { + /** + * 驱动名称 + */ + private String driver; + + private int maxActive; + + private int initalSize; + + private String schema; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MockDetailVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MockDetailVO.java new file mode 100644 index 0000000000..bf984fee70 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MockDetailVO.java @@ -0,0 +1,23 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class MockDetailVO { + @ApiModelProperty("平均响应时间") + private String responseTime; + + @ApiModelProperty("请求模板") + private List request; +} + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MockInfo.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MockInfo.java new file mode 100644 index 0000000000..a710c443d5 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MockInfo.java @@ -0,0 +1,21 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/16 12:32 PM + */ +@Data +public class MockInfo { + @ApiModelProperty("类型 0-json格式 1-脚本格式") + private String type; + + @ApiModelProperty("mock数据") + private String mockValue; + + @ApiModelProperty("响应时间") + private Integer responseTime; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MqConsumerFeature.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MqConsumerFeature.java new file mode 100644 index 0000000000..dba8593311 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/MqConsumerFeature.java @@ -0,0 +1,24 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/10/11 11:16 AM + */ +@Data +public class MqConsumerFeature { + @ApiModelProperty("集群名称") + private String clusterName; + + @ApiModelProperty("集群地址") + private String clusterAddr; + + @ApiModelProperty("生产或消费的线程数") + private Integer providerThreadCount; + + @ApiModelProperty("生产或消费的线程数") + private Integer consumerThreadCount; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceAppInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceAppInput.java new file mode 100644 index 0000000000..7dcdaf6b1d --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceAppInput.java @@ -0,0 +1,24 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author XINGCHEN + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +public class PressureResourceAppInput { + @ApiModelProperty("id") + private Long id; + + @ApiModelProperty("隔离方式(0-未设置 1-影子库 2-影子库/影子表 3-影子表)") + private Integer isolateType; + + @ApiModelProperty("节点数") + private Integer nodeNum; + + @ApiModelProperty("是否加入压测范围(0-否 1-是)") + private Integer joinPressure; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceAppRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceAppRequest.java new file mode 100644 index 0000000000..02d8a47cf3 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceAppRequest.java @@ -0,0 +1,33 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author XINGCHEN + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +public class PressureResourceAppRequest extends PageBaseDTO { + @ApiModelProperty("配置资源ID") + private Long resourceId; + + @ApiModelProperty("配置资源IDs") + private List resourceIds; + + @ApiModelProperty("应用名称") + private String appName; + + @ApiModelProperty("入口") + private String entry; + + @ApiModelProperty("状态(0正常-1不正常)") + private Integer status; + + @ApiModelProperty("是否加入压测范围(0-否 1-是)") + private Integer joinPressure; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceCheckVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceCheckVO.java new file mode 100644 index 0000000000..c3dcf79a09 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceCheckVO.java @@ -0,0 +1,21 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceCheckVO { + @ApiModelProperty("错误信息备注") + private String remark; + + @ApiModelProperty("是否成功") + private boolean success; +} + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceDetailInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceDetailInput.java new file mode 100644 index 0000000000..5cb1d996b6 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceDetailInput.java @@ -0,0 +1,48 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.springframework.beans.factory.annotation.Value; + +import java.util.Date; + +@Data +@ToString(callSuper = true) +public class PressureResourceDetailInput { + @ApiModelProperty("id") + private Long id; + + @ApiModelProperty("资源配置Id") + private Long resourceId; + + @ApiModelProperty("应用名称") + private String appName; + + @ApiModelProperty("入口URL") + private String entranceUrl; + + @ApiModelProperty("入口名称") + private String entranceName; + + @ApiModelProperty("rpcType") + private String rpcType; + + @ApiModelProperty("extend") + private String extend; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + private Integer type; + + @ApiModelProperty("linkId") + private String linkId; + + @ApiModelProperty("请求方式") + private String method; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtModified; +} \ No newline at end of file diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceDsRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceDsRequest.java new file mode 100644 index 0000000000..64d6ab1e94 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceDsRequest.java @@ -0,0 +1,19 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author XINGCHEN + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +public class PressureResourceDsRequest extends PageBaseDTO { + @ApiModelProperty("配置资源ID") + private Long resourceId; + + @ApiModelProperty("业务数据源") + private String bussinessDataBase; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceInput.java new file mode 100644 index 0000000000..0a6b33fca9 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceInput.java @@ -0,0 +1,48 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.influxdb.annotation.Column; + +import java.util.Date; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +public class PressureResourceInput extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置名称") + private String name; + + @ApiModelProperty("来源类型-手工/业务流程") + private Integer type; + + @ApiModelProperty("检测状态(0-未检测 1-检测中 2-检测完成)") + private Integer checkStatus; + + @ApiModelProperty("sourceId") + private Long sourceId; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtUpdate; + + @ApiModelProperty("归属人Id") + private Long userId; + + /** + * 详情明细 + */ + private List detailInputs; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceIsolateInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceIsolateInput.java new file mode 100644 index 0000000000..fb79b75e2f --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceIsolateInput.java @@ -0,0 +1,34 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.influxdb.annotation.Column; + +import java.util.Date; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +public class PressureResourceIsolateInput { + @Id + @Column(name = "`id`") + private Long id; + + @ApiModelProperty("资源配置名称") + private String name; + + @ApiModelProperty("来源类型-手工/业务流程") + private Integer type; + + @ApiModelProperty("隔离方式(0-未设置 1-影子库 2-影子库/影子表 3-影子表)") + private Integer isolateType; + + @ApiModelProperty("更新时间") + private Date gmtUpdate; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMockInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMockInput.java new file mode 100644 index 0000000000..9cf39c8b98 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMockInput.java @@ -0,0 +1,26 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceMockInput { + private Long resourceId; + + @ApiModelProperty(value = "远程调用Id") + private Long id; + + @ApiModelProperty("mock信息") + private MockInfo mockInfo; + + @ApiModelProperty("是否放行") + private Integer pass; +} + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMqConsumerCreateInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMqConsumerCreateInput.java new file mode 100644 index 0000000000..9505defb16 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMqConsumerCreateInput.java @@ -0,0 +1,73 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author shiyajian + * create: 2021-02-05 + */ +@Data +public class PressureResourceMqConsumerCreateInput { + @ApiModelProperty(value = "Id") + private Long id; + + /** + * topic + */ + @ApiModelProperty(value = "topic") + private String topic; + + /** + * topic + */ + @ApiModelProperty(value = "group") + private String group; + + @ApiModelProperty(value = "resourceId") + private Long resourceId; + + /** + * broker地址 + */ + private String brokerAddr; + + /** + * topicTokens + */ + private String topicTokens; + + /** + * systemIdToken + */ + private String systemIdToken; + + @ApiModelProperty(value = "消费者类型RABBITMQ/ROCKETMQ/KAFKA/KAFKA-其他") + private String mqType; + + private String applicationId; + + /** + * 是否消费(0-消费 1-不消费) + */ + private Integer consumerTag; + + @ApiModelProperty("是否影子集群(0-是 1否)") + private Integer isCluster; + + @ApiModelProperty("生产或消费(0-生产,1-消费)") + private Integer comsumerType; + + /** + * 来源标识 + */ + private Integer type; + + @ApiModelProperty("kafka的时候的集群信息") + private MqConsumerFeature mqConsumerFeature; + + @ApiModelProperty("批量Id") + private List ids; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMqConsumerQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMqConsumerQueryRequest.java new file mode 100644 index 0000000000..3a3dfa4469 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceMqConsumerQueryRequest.java @@ -0,0 +1,28 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author XINGCHEN + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +public class PressureResourceMqConsumerQueryRequest extends PageBaseDTO { + @ApiModelProperty("消费组") + private String queryTopicGroup; + + @ApiModelProperty("resourceId") + private Long resourceId; + + @ApiModelProperty("queryApplicationName") + private String queryApplicationName; + + @ApiModelProperty("mqType") + private String mqType; + + @ApiModelProperty("consumerTag") + private Integer consumerTag; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceQueryRequest.java new file mode 100644 index 0000000000..f8e50865e6 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceQueryRequest.java @@ -0,0 +1,19 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author XINGCHEN + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +public class PressureResourceQueryRequest extends PageBaseDTO { + @ApiModelProperty("资源配置名称") + private String name; + + @ApiModelProperty("id") + private Long id; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateDsInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateDsInput.java new file mode 100644 index 0000000000..e04062e715 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateDsInput.java @@ -0,0 +1,71 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateDsInput extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + private Long resourceId; + + @ApiModelProperty("应用名称") + private String appName; + + @ApiModelProperty("中间件名称") + private String middlewareName; + + @ApiModelProperty("状态") + private Integer status; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + private Integer type; + + @ApiModelProperty("唯一键") + private String uniqueKey; + + @ApiModelProperty("业务数据源") + private String businessDatabase; + + @ApiModelProperty("detailId") + private Long detailId; + + @ApiModelProperty("业务数据源用户名") + private String businessUserName; + + @ApiModelProperty("影子数据源") + private String shadowDatabase; + + @ApiModelProperty("影子数据源用户名") + private String shadowUserName; + + @ApiModelProperty("影子数据源密码") + private String shadowPassword; + + @ApiModelProperty("扩展信息") + private ExtInfo extInfo; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtModified; + + private List relationApps; +} + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateDsRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateDsRequest.java new file mode 100644 index 0000000000..d5674f58cb --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateDsRequest.java @@ -0,0 +1,43 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateDsRequest extends PageBaseDTO { + @Id + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + private Long resourceId; + + @ApiModelProperty("应用名称,模糊查询") + private String queryAppName; + + @ApiModelProperty("业务数据源,模糊查询") + private String queryBusinessDataBase; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("业务数据源") + private String businessDataBase; + + @ApiModelProperty("业务数据源用户名") + private String businessUserName; +} + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateRemoteCallRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateRemoteCallRequest.java new file mode 100644 index 0000000000..ce89816370 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateRemoteCallRequest.java @@ -0,0 +1,40 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateRemoteCallRequest extends PageBaseDTO { + @ApiModelProperty("resourceId") + private Long resourceId; + + @ApiModelProperty("远程调用服务Id") + private Long id; + + @ApiModelProperty("查询的接口名") + private String queryInterfaceName; + + @ApiModelProperty("接口类型") + private String interfaceChildType; + + @ApiModelProperty("是否放行(0:是 1:否)") + private Integer pass; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("entry") + private String entry; + + @ApiModelProperty("是否需要转换,查询mock") + private boolean convert; +} + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateTableInput.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateTableInput.java new file mode 100644 index 0000000000..d04397de0e --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateTableInput.java @@ -0,0 +1,62 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateTableInput extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("ids") + private List ids; + + @ApiModelProperty("资源配置Id") + private Long resourceId; + + @ApiModelProperty("数据源配置key") + private String dsKey; + + @ApiModelProperty("数据源配置Id") + private Long dsId; + + @ApiModelProperty("数据源") + private String database; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("业务表") + private String businessTable; + + @ApiModelProperty("影子表") + private String shadowTable; + + @ApiModelProperty("是否加入(0-加入 1-未加入)") + private Integer joinFlag; + + @ApiModelProperty("扩展信息") + private String extInfo; + + @ApiModelProperty("类型(0-手工 1-自动)") + private Integer type; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateTableRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateTableRequest.java new file mode 100644 index 0000000000..5e6b831773 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/pressureresource/PressureResourceRelateTableRequest.java @@ -0,0 +1,39 @@ +package io.shulie.takin.web.biz.pojo.request.pressureresource; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateTableRequest extends PageBaseDTO { + @Id + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + private Long resourceId; + + @ApiModelProperty("数据源ID") + private Long dsId; + + @ApiModelProperty("数据源Key") + private String dsKey; + + @ApiModelProperty("查询的业务表名") + private String queryBusinessTableName; + + @ApiModelProperty("业务表名") + private String businessTableName; + + @ApiModelProperty("配置状态") + private Integer status; +} + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployPageQueryRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployPageQueryRequest.java index f841acd01a..4bfa03ac0d 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployPageQueryRequest.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployPageQueryRequest.java @@ -45,4 +45,6 @@ public class ScriptManageDeployPageQueryRequest extends PagingDevice { @JsonProperty("businessFlow") private String businessFlowId; + private Long deptId; + } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployUpdateRequest.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployUpdateRequest.java index 6830bbbd07..5ef68480df 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployUpdateRequest.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/request/scriptmanage/ScriptManageDeployUpdateRequest.java @@ -70,4 +70,6 @@ public class ScriptManageDeployUpdateRequest implements Serializable { * 是否覆盖大文件 */ private Integer ifCoverBigFile; + + private boolean isPressureResource; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationEntrancesResponse.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationEntrancesResponse.java index 0d05af98ce..93be0fee52 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationEntrancesResponse.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationEntrancesResponse.java @@ -14,6 +14,7 @@ @Data @ApiModel("应用入口返回值信息") public class ApplicationEntrancesResponse extends WebOptionEntity { + private String appName; private String method; diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListByUpgradeResponse.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListByUpgradeResponse.java index cdacdbf2dc..6024fbeb80 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListByUpgradeResponse.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListByUpgradeResponse.java @@ -21,4 +21,6 @@ public class ApplicationListByUpgradeResponse { private Date gmtUpdate; + private Long deptId; + } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListResponseV2.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListResponseV2.java index b4caa18905..7847f85ee3 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListResponseV2.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ApplicationListResponseV2.java @@ -3,6 +3,7 @@ import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; +import io.shulie.takin.web.ext.entity.AuthQueryResponseCommonExt; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -11,7 +12,7 @@ * @date 2021/12/8 4:02 下午 */ @Data -public class ApplicationListResponseV2 { +public class ApplicationListResponseV2 extends AuthQueryResponseCommonExt { /** * 不是表id diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ShadowDetailResponse.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ShadowDetailResponse.java index a0fab60def..63ed76e47c 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ShadowDetailResponse.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/application/ShadowDetailResponse.java @@ -67,6 +67,11 @@ public class ShadowDetailResponse implements Serializable { @AllArgsConstructor @NoArgsConstructor public static class TableInfo { + @Info(describe = "压测资源准备-资源Id") + private Long resourceId; + + @Info(describe = "压测资源准备-详情Id") + private Long detailId; @Info(describe = "业务库") private String bizDatabase; @@ -96,7 +101,7 @@ public TableInfo(String bizDatabase, String bizTableName, Integer manualTag, Str this.bizTableName = bizTableName; this.shaDowTableName = shaDowTableName; this.isManual = manualTag == 1; - this.isCheck = isCheck ==1; + this.isCheck = isCheck == 1; } } } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/linkmanage/BusinessFlowListResponse.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/linkmanage/BusinessFlowListResponse.java index 77501edf52..fe4c08f9ff 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/linkmanage/BusinessFlowListResponse.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/pojo/response/linkmanage/BusinessFlowListResponse.java @@ -42,4 +42,6 @@ public class BusinessFlowListResponse extends AuthQueryResponseCommonExt implem @ApiModelProperty(name = "scriptDeployId", value = "脚本实例id") private Long scriptDeployId; + + private String features; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ApplicationService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ApplicationService.java index 87ce247119..81fa5d8248 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ApplicationService.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ApplicationService.java @@ -38,7 +38,7 @@ public interface ApplicationService { * @param userIdList * @return */ - List getApplicationsByUserIdList(List userIdList); + List getApplicationsByUserIdList(List userIdList, List deptIdList); /** * 带租户 @@ -298,6 +298,11 @@ public interface ApplicationService { */ PagingList pageApplication(ApplicationQueryRequestV2 request); + /** + * ee中调用 + * @param request + * @return + */ PagingList listApplicationByUpgrade(ApplicationListByUpgradeRequest request); Response operateCheck(List appIds, String operate); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ConfCenterService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ConfCenterService.java index ef0cb9b7ad..c393c3553c 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ConfCenterService.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/ConfCenterService.java @@ -70,6 +70,7 @@ import io.shulie.takin.common.beans.page.PagingList; import io.shulie.takin.web.biz.cache.AgentConfigCacheManager; import io.shulie.takin.web.biz.common.CommonService; +import io.shulie.takin.web.biz.nacos.event.ShadowConfigRefreshEvent; import io.shulie.takin.web.biz.service.linkmanage.AppRemoteCallService; import io.shulie.takin.web.biz.service.linkmanage.impl.WhiteListFileService; import io.shulie.takin.web.common.common.Response; @@ -99,6 +100,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationContext; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -148,6 +150,9 @@ public class ConfCenterService extends CommonService { @Resource(name = "redisTemplate") private RedisTemplate redisTemplate; + @Resource + private ApplicationContext applicationContext; + public static final String APPLICATION_CACHE_PREFIX = "application:cache"; @PostConstruct @@ -190,12 +195,20 @@ private void addPluginsConfig(ApplicationCreateParam applicationMnt) { @Transactional(rollbackFor = Exception.class) public void saveAgentRegisterApplication(ApplicationCreateParam tApplicationMnt) { - int applicationExist = applicationDAO.applicationExistByTenantIdAndAppName( - WebPluginUtils.traceTenantId(), WebPluginUtils.traceEnvCode(), tApplicationMnt.getApplicationName()); - if (applicationExist > 0) { + ApplicationDetailResult application = applicationDAO.getApplicationByTenantIdAndName(tApplicationMnt.getApplicationName()); + if(application != null){ OperationLogContextHolder.ignoreLog(); + // 先创建应用,再接探针,需要更新clusterName + if(application.getClusterName() == null){ + application.setClusterName(tApplicationMnt.getClusterName()); + applicationDAO.updateApplicationInfo(tApplicationMnt); + // 刚更新了clusteName, 向此cluste的nacos推送配置 + applicationContext.publishEvent(new ShadowConfigRefreshEvent(tApplicationMnt.getApplicationName())); + // 如果是刚通过注册创建的应用,则一点配置都没有,不需要向nacos推送 + } return; } + addApplication(tApplicationMnt); addApplicationToDataBuild(tApplicationMnt); addApplicationToLinkDetection(tApplicationMnt); @@ -257,7 +270,7 @@ private void addApplication(ApplicationCreateParam tApplicationMnt) { tApplicationMnt.setApplicationId(snowflake.next()); tApplicationMnt.setCacheExpTime( StringUtils.isEmpty(tApplicationMnt.getCacheExpTime()) ? "0" : tApplicationMnt.getCacheExpTime()); - + tApplicationMnt.setDeptId(WebPluginUtils.traceDeptId()); applicationDAO.insert(tApplicationMnt); try { @@ -730,41 +743,6 @@ public List queryBlackListByIds(List blistIds) { return tBListMntDao.queryBListByIds(blistIdList); } - /** - * 说明: 查询黑名单列表 - * - * @param bListQueryParam redis的key和负责人工号 - * @return 黑名单列表集合 - * @author shulie - */ - public Response queryBlackList(BListQueryParam bListQueryParam) { - Map paramMap = new HashMap<>(); - paramMap.put("pageNum", bListQueryParam.getCurrentPage()); - paramMap.put("pageSize", bListQueryParam.getPageSize()); - String redisKey = bListQueryParam.getRedisKey(); - PageHelper.startPage(PageInfo.getPageNum(paramMap), PageInfo.getPageSize(paramMap)); - List queryBlackList = tBListMntDao.queryBList(redisKey, "", WebPluginUtils.getQueryAllowUserIdList()); - if (CollectionUtils.isNotEmpty(queryBlackList)) { - for (TBList tbList : queryBlackList) { - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowUpdateUserIdList)) { - tbList.setCanEdit(allowUpdateUserIdList.contains(tbList.getUserId())); - } - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowDeleteUserIdList)) { - tbList.setCanRemove(allowDeleteUserIdList.contains(tbList.getUserId())); - } - List allowEnableDisableUserIdList = WebPluginUtils.getEnableDisableAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowEnableDisableUserIdList)) { - tbList.setCanEnableDisable(allowEnableDisableUserIdList.contains(tbList.getUserId())); - } - } - } - PageInfo pageInfo = new PageInfo<>(queryBlackList.isEmpty() ? Lists.newArrayList() : queryBlackList); - Response response = Response.success(pageInfo.getList(), - CollectionUtils.isEmpty(pageInfo.getList()) ? 0 : pageInfo.getTotal()); - return response; - } /** * 说明: 查询白名单列表,只供agent拦截使用,只选择USE_YN=1的白名单 @@ -2023,20 +2001,32 @@ public Response queryBList(BListQueryParam bListQueryParam) { paramMap.put("pageSize", bListQueryParam.getPageSize()); String redisKey = bListQueryParam.getRedisKey(); PageHelper.startPage(PageInfo.getPageNum(paramMap), PageInfo.getPageSize(paramMap)); - List queryBList = tBListMntDao.queryBList(redisKey, "", WebPluginUtils.getQueryAllowUserIdList()); + List queryBList = tBListMntDao.queryBList(redisKey, "", WebPluginUtils.queryAllowUserIdList(), WebPluginUtils.queryAllowDeptIdList()); if (CollectionUtils.isNotEmpty(queryBList)) { for (TBList tbList : queryBList) { - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowUpdateUserIdList)) { - tbList.setCanEdit(allowUpdateUserIdList.contains(tbList.getUserId())); + List allowUpdateUserIdList = WebPluginUtils.updateAllowUserIdList(); + List allowUpdateDeptIdList = WebPluginUtils.updateAllowDeptIdList(); + if (CollectionUtils.isNotEmpty(allowUpdateUserIdList) && !allowUpdateUserIdList.contains(tbList.getUserId())) { + tbList.setCanEdit(false); + } + if (CollectionUtils.isNotEmpty(allowUpdateDeptIdList) && !allowUpdateDeptIdList.contains(tbList.getDeptId())) { + tbList.setCanEdit(false); + } + List allowDeleteUserIdList = WebPluginUtils.deleteAllowUserIdList(); + List allowDeleteDeptIdList = WebPluginUtils.deleteAllowDeptIdList(); + if (CollectionUtils.isNotEmpty(allowDeleteUserIdList) && !allowDeleteUserIdList.contains(tbList.getUserId())) { + tbList.setCanRemove(false); + } + if (CollectionUtils.isNotEmpty(allowDeleteDeptIdList) && !allowDeleteDeptIdList.contains(tbList.getDeptId())) { + tbList.setCanRemove(false); } - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowDeleteUserIdList)) { - tbList.setCanRemove(allowDeleteUserIdList.contains(tbList.getUserId())); + List allowEnableDisableUserIdList = WebPluginUtils.enableDisableAllowUserIdList(); + List allowEnableDisableDeptIdList = WebPluginUtils.enableDisableAllowDeptIdList(); + if (CollectionUtils.isNotEmpty(allowEnableDisableUserIdList) && !allowEnableDisableUserIdList.contains(tbList.getUserId())) { + tbList.setCanEnableDisable(false); } - List allowEnableDisableUserIdList = WebPluginUtils.getEnableDisableAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowEnableDisableUserIdList)) { - tbList.setCanEnableDisable(allowEnableDisableUserIdList.contains(tbList.getUserId())); + if (CollectionUtils.isNotEmpty(allowEnableDisableDeptIdList) && !allowEnableDisableDeptIdList.contains(tbList.getDeptId())) { + tbList.setCanEnableDisable(false); } } } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/LinkTopologyService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/LinkTopologyService.java index 807b10ca3f..f851faf644 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/LinkTopologyService.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/LinkTopologyService.java @@ -136,7 +136,7 @@ public ApplicationEntranceTopologyResponse getApplicationEntrancesTopology( LinkTopologyDTO applicationEntrancesTopology = applicationEntranceClient.getApplicationEntrancesTopology( tempActivity, request.getApplicationName(), request.getLinkId(), request.getServiceName(), request.getMethod(), - request.getRpcType(), request.getExtend()); + request.getRpcType(), request.getExtend(),false); // final result ApplicationEntranceTopologyResponse applicationEntranceTopologyResponse diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/blacklist/BlacklistServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/blacklist/BlacklistServiceImpl.java index f1595b962e..5553d12c39 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/blacklist/BlacklistServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/blacklist/BlacklistServiceImpl.java @@ -21,6 +21,7 @@ import io.shulie.takin.web.common.enums.blacklist.BlacklistTypeEnum; import io.shulie.takin.web.common.exception.ExceptionCode; import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; import io.shulie.takin.web.common.vo.blacklist.BlacklistVO; import io.shulie.takin.web.data.dao.application.ApplicationDAO; import io.shulie.takin.web.data.dao.blacklist.BlackListDAO; @@ -166,7 +167,12 @@ public PagingList pageList(BlacklistSearchInput input) { if (pagingList.isEmpty()) { return PagingList.of(Lists.newArrayList(), pagingList.getTotal()); } + ApplicationDetailResult applicationById = applicationDAO.getApplicationById(input.getApplicationId()); + if (applicationById == null){ + throw new TakinWebException(TakinWebExceptionEnum.APPLICATION_MANAGE_NO_EXIST_ERROR, "该应用不存在"); + } for (BlacklistVO vo : pagingList.getList()) { + vo.setDeptId(applicationById.getDeptId()); WebPluginUtils.fillQueryResponse(vo); } return pagingList; diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/DsServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/DsServiceImpl.java index 0efb705ae6..4743de545e 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/DsServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/DsServiceImpl.java @@ -230,7 +230,7 @@ public Response dsQuery(Long applicationId) { ApplicationDsQueryParam queryParam = new ApplicationDsQueryParam(); queryParam.setApplicationId(applicationId); queryParam.setIsDeleted(0); - WebPluginUtils.fillQueryParam(queryParam); +// WebPluginUtils.fillQueryParam(queryParam); List dsResultList = applicationDsDAO.queryList(queryParam); List dsResponseList = Lists.newArrayList(); if (CollectionUtils.isNotEmpty(dsResultList)) { @@ -457,7 +457,7 @@ public List dsQueryV2(Long applicationId) { ApplicationDsQueryParam queryParam = new ApplicationDsQueryParam(); queryParam.setApplicationId(applicationId); queryParam.setIsDeleted(0); - WebPluginUtils.fillQueryParam(queryParam); +// WebPluginUtils.fillQueryParam(queryParam); this.filterAndSave(shadowDataBaseInfos, applicationId, queryParam); //这里为了拿到id,先存后查 List caches = dsCacheManageDAO.selectList(queryParam); @@ -470,9 +470,8 @@ public List dsQueryV2(Long applicationId) { response.addAll(dbs.stream().map(this::dbBuild).collect(Collectors.toList())); response.addAll(oldResponseList.stream().map(this::v1Build).collect(Collectors.toList())); response.forEach(r -> { - if (r.getIsManual() != null && !r.getIsManual()) { - r.setCanRemove(false); - } + r.setDeptId(detailResult.getDeptId()); + WebPluginUtils.fillQueryResponse(r); }); agentConfigCacheManager.evictShadowDb(detailResult.getApplicationName()); agentConfigCacheManager.evictShadowServer(detailResult.getApplicationName()); @@ -766,7 +765,7 @@ private void buildNewDataSource(ApplicationDsCreateInputV2 createRequestV2) { extObj.put(EXT_FLAG, "true"); if ("2".equals(tag) || "3".equals(tag)) { context = dataObj.getString("context"); - if("3".equals(tag)){ + if ("3".equals(tag)) { extObj.put(EXT_FLAG, "3"); } } @@ -835,7 +834,7 @@ private boolean validateOracleURL(String shadowUrl, String url, int dsType, @Override public List querySupperName(String middlewareType) { AbstractDsTemplateService templateService = templateServiceMap.get(middlewareType); - List list = templateService.queryDsSupperName(); + List list = templateService.queryDsSupperName(); List tmpList = list.stream().filter(a -> { if ("兼容老版本(影子库)".equals(a.getLabel()) || "兼容老版本(影子表)".equals(a.getLabel())) { return false; @@ -1133,8 +1132,9 @@ public ShadowTemplateSelect processSelect(String appName) { log.error("从amdb未获取到应用版本信息,当前应用名{}", appName); return select; } - // 获取所有探针版本 + // 获取所有探针版本,Agent版本有可能为空 List agentVersionList = dtoList.stream() + .filter(agentDto -> agentDto.getAgentVersion() != null) .map(agentDto -> agentDto.getAgentVersion()) .collect(Collectors.toList()); // 倒序排 diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/v2/ShaDowDbServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/v2/ShaDowDbServiceImpl.java index 702fbc29cb..d3cf0ac617 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/v2/ShaDowDbServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/dsManage/impl/v2/ShaDowDbServiceImpl.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Lists; import com.pamirs.attach.plugin.dynamic.one.Converter; import com.pamirs.takin.common.enums.ds.DsTypeEnum; import io.shulie.takin.web.biz.convert.db.parser.DbTemplateParser; @@ -9,11 +10,18 @@ import io.shulie.takin.web.biz.pojo.input.application.ApplicationDsUpdateInputV2; import io.shulie.takin.web.biz.pojo.response.application.ShadowDetailResponse; import io.shulie.takin.web.biz.service.dsManage.AbstractShaDowManageService; +import io.shulie.takin.web.biz.service.pressureresource.common.DataSourceUtil; import io.shulie.takin.web.common.exception.TakinWebException; import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; import io.shulie.takin.web.data.dao.application.ApplicationDsDbManageDAO; import io.shulie.takin.web.data.dao.application.ApplicationDsDbTableDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateDsDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateTableDAO; import io.shulie.takin.web.data.model.mysql.ApplicationDsDbManageEntity; +import io.shulie.takin.web.data.model.mysql.ApplicationDsDbTableEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateDsEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateTableEntityV2; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceTableQueryParam; import io.shulie.takin.web.data.result.application.ApplicationDsDbManageDetailResult; import io.shulie.takin.web.data.result.application.ApplicationDsDbTableDetailResult; import io.shulie.takin.web.ext.util.WebPluginUtils; @@ -24,20 +32,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** * @Author: 南风 * @Date: 2021/9/2 5:51 下午 - * */ @Service public class ShaDowDbServiceImpl extends AbstractShaDowManageService { @Autowired - private ApplicationDsDbManageDAO dbManageDAO; + private ApplicationDsDbManageDAO dbManageDAO; @Autowired private ApplicationDsDbTableDAO dsDbTableDAO; @@ -45,6 +51,12 @@ public class ShaDowDbServiceImpl extends AbstractShaDowManageService { @Autowired private DbTemplateParser templateParser; + @Autowired + private PressureResourceRelateDsDAO pressureResourceRelateDsDAO; + + @Autowired + private PressureResourceRelateTableDAO pressureResourceRelateTableDAO; + /** * 更新影子配置方案 * @@ -53,10 +65,10 @@ public class ShaDowDbServiceImpl extends AbstractShaDowManageService { @Override @Transactional(rollbackFor = Exception.class) public void updateShadowProgramme(ApplicationDsUpdateInputV2 inputV2) { - ApplicationDsDbManageEntity entity = this.buildEntity(inputV2,false); - dbManageDAO.updateById(inputV2.getId(),entity); - if(DsTypeEnum.SHADOW_TABLE.getCode().equals(entity.getDsType())){ - this.saveShadowTable(inputV2.getId(),entity.getShaDowFileExtedn()); + ApplicationDsDbManageEntity entity = this.buildEntity(inputV2, false); + dbManageDAO.updateById(inputV2.getId(), entity); + if (DsTypeEnum.SHADOW_TABLE.getCode().equals(entity.getDsType())) { + this.saveShadowTable_V2(inputV2, inputV2.getId(), entity.getShaDowFileExtedn()); } } @@ -68,53 +80,88 @@ public void updateShadowProgramme(ApplicationDsUpdateInputV2 inputV2) { */ @Override @Transactional(rollbackFor = Exception.class) - public void createShadowProgramme(ApplicationDsCreateInputV2 inputV2,Boolean isJson) { + public void createShadowProgramme(ApplicationDsCreateInputV2 inputV2, Boolean isJson) { //去重校验 ApplicationDsDbManageDetailResult result = dbManageDAO.selectOne(inputV2.getApplicationName(), - inputV2.getUrl(), inputV2.getUsername(),inputV2.getConnectionPool()); - if(Objects.nonNull(result)){ - throw new TakinWebException(TakinWebExceptionEnum.SHADOW_CONFIG_CREATE_ERROR,"业务数据源已存在"); + inputV2.getUrl(), inputV2.getUsername(), inputV2.getConnectionPool()); + boolean isInsertDb = true; + if (Objects.nonNull(result)) { + // 存在此数据了,但是从链路配置过来的,绑定一条关系 + if (inputV2.getResourceId() != null) { + // 绑定关系 + bindPressourceDs(result.getId(), inputV2); + isInsertDb = false; // 不需要新增了 + } else { + throw new TakinWebException(TakinWebExceptionEnum.SHADOW_CONFIG_CREATE_ERROR, "业务数据源已存在"); + } } - ApplicationDsDbManageEntity entity = this.buildEntity(inputV2,true); + ApplicationDsDbManageEntity entity = this.buildEntity(inputV2, true); entity.setId(null); //去除原id - dbManageDAO.saveOne(entity); - if(DsTypeEnum.SHADOW_TABLE.getCode().equals(entity.getDsType())){ - this.saveShadowTable(entity.getId(),entity.getShaDowFileExtedn()); + if (isInsertDb) { + dbManageDAO.saveOne(entity); + // 新增的时候,直接绑定一条关系 + if (inputV2.getResourceId() != null) { + // 绑定关系 + bindPressourceDs(entity.getId(), inputV2); + } + } else { + entity.setId(result.getId()); + } + if (DsTypeEnum.SHADOW_TABLE.getCode().equals(entity.getDsType())) { + this.saveShadowTable_V2(inputV2, entity.getId(), entity.getShaDowFileExtedn()); } } - private ApplicationDsDbManageEntity buildEntity(ApplicationDsCreateInputV2 inputV2,Boolean isCreate){ + private void bindPressourceDs(Long relateId, ApplicationDsCreateInputV2 inputV2) { + PressureResourceRelateDsEntityV2 dsEntity = new PressureResourceRelateDsEntityV2(); + dsEntity.setResourceId(inputV2.getResourceId()); + dsEntity.setDetailId(inputV2.getDetailId()); + dsEntity.setAppName(inputV2.getApplicationName()); + dsEntity.setBusinessUserName(inputV2.getUsername()); + dsEntity.setRelateId(relateId); + dsEntity.setBusinessDatabase(inputV2.getUrl()); + dsEntity.setType(inputV2.getType()); + dsEntity.setTenantId(WebPluginUtils.traceTenantId()); + dsEntity.setEnvCode(WebPluginUtils.traceEnvCode()); + dsEntity.setGmtCreate(new Date()); + pressureResourceRelateDsDAO.add_v2(Arrays.asList(dsEntity)); + } + + private ApplicationDsDbManageEntity buildEntity(ApplicationDsCreateInputV2 inputV2, Boolean isCreate) { ApplicationDsDbManageEntity entity = new ApplicationDsDbManageEntity(); WebPluginUtils.fillUserData(inputV2); - BeanUtils.copyProperties(inputV2,entity); + BeanUtils.copyProperties(inputV2, entity); entity.setDsType(inputV2.getDsType()); entity.setShaDowUrl(inputV2.getShaDowUrl()); entity.setShaDowUserName(inputV2.getShaDowUserName()); entity.setShaDowPwd(inputV2.getShaDowPassword()); entity.setUrl(inputV2.getUrl()); - entity.setUserName(Objects.equals("-",inputV2.getUsername())?"":inputV2.getUsername()); + entity.setUserName(Objects.equals("-", inputV2.getUsername()) ? "" : inputV2.getUsername()); entity.setConnPoolName(inputV2.getConnectionPool()); entity.setStatus(0); String extInfo = inputV2.getExtInfo(); - if(DsTypeEnum.SHADOW_TABLE.getCode().equals(inputV2.getDsType())){ + if (DsTypeEnum.SHADOW_TABLE.getCode().equals(inputV2.getDsType())) { extInfo = JSONObject.parseObject(inputV2.getExtInfo()).get("shaDowTaleInfo").toString(); } entity.setShaDowFileExtedn(extInfo); - if(isCreate){ + if (isCreate) { entity.setDbName(""); entity.setPwd(""); entity.setConfigJson(""); entity.setSource(1); - entity.setFileExtedn(inputV2.getParseConfig()); - entity.setConfigJson(inputV2.getIsOld()?"老转新":""); - if("other".equals(entity.getConnPoolName())){ - entity.setAgentSourceType( Converter.TemplateConverter.TemplateEnum._default.getKey()); - }else if("兼容老版本(影子表)".equals(entity.getConnPoolName()) - || "兼容老版本(影子库)".equals(entity.getConnPoolName())){ - entity.setAgentSourceType( Converter.TemplateConverter.TemplateEnum._2.getKey()); + // 链路梳理而来 + if (inputV2.getType() != null && inputV2.getType() == 1) { + entity.setSource(0); } - else{ + entity.setFileExtedn(inputV2.getParseConfig()); + entity.setConfigJson(inputV2.getIsOld() ? "老转新" : ""); + if ("other".equals(entity.getConnPoolName())) { + entity.setAgentSourceType(Converter.TemplateConverter.TemplateEnum._default.getKey()); + } else if ("兼容老版本(影子表)".equals(entity.getConnPoolName()) + || "兼容老版本(影子库)".equals(entity.getConnPoolName())) { + entity.setAgentSourceType(Converter.TemplateConverter.TemplateEnum._2.getKey()); + } else { Converter.TemplateConverter.TemplateEnum templateEnum = templateParser.convert(entity.getConnPoolName()); if (templateEnum != null) { entity.setAgentSourceType(templateEnum.getKey()); @@ -124,17 +171,143 @@ private ApplicationDsDbManageEntity buildEntity(ApplicationDsCreateInputV2 input return entity; } - private void saveShadowTable(Long recordId,String str){ - if(StringUtils.isBlank(str)){ + /** + * 保存影子表v2 + * + * @param recordId + * @param str + */ + private void saveShadowTable_V2(ApplicationDsCreateInputV2 inputV2, Long recordId, String str) { + if (StringUtils.isBlank(str)) { + return; + } + ApplicationDsDbManageDetailResult detailResult = dbManageDAO.selectOneById(recordId); + if (Objects.isNull(detailResult)) { + return; + } + // 历史数据集合 + List list = dsDbTableDAO.getList(detailResult.getUrl(), detailResult.getApplicationId(), + detailResult.getUserName()); + // 新数据集合 + List tableInfos = JSONArray.parseArray(str, ShadowDetailResponse.TableInfo.class); + List collect = tableInfos.stream().map(x -> { + ApplicationDsDbTableDetailResult result = new ApplicationDsDbTableDetailResult(); + result.setAppId(detailResult.getApplicationId()); + result.setUrl(detailResult.getUrl()); + result.setUserName(detailResult.getUserName()); + result.setBizDataBase(x.getBizDatabase()); + result.setBizTable(x.getBizTableName()); + result.setShadowTable(x.getShaDowTableName()); + result.setManualTag(x.getIsManual() ? 1 : 0); + result.setIsCheck(x.getIsCheck() ? 1 : 0); + return result; + }).collect(Collectors.toList()); + + Map> oldMap = list.stream().collect(Collectors.groupingBy(it -> fetchKey(it))); + Map> newMap = collect.stream().collect(Collectors.groupingBy(it -> fetchKey(it))); + + // 自动梳理的不需要删除 + if (inputV2.getResourceId() == null) { + // 删除,旧的数据不在新的数据里面的 + List delKeyList = oldMap.keySet().stream().filter(nKey -> !newMap.keySet().contains(nKey)).collect(Collectors.toList()); + List delIds = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(delKeyList)) { + delKeyList.stream().forEach(delKey -> { + oldMap.get(delKey).stream().forEach(old -> { + delIds.add(old.getId()); + }); + }); + if (CollectionUtils.isNotEmpty(delIds)) { + dsDbTableDAO.batchDeleted_V2(delIds); + + // 删除绑定关系 + PressureResourceTableQueryParam queryParam = new PressureResourceTableQueryParam(); + queryParam.setRelateIds(delIds); + pressureResourceRelateTableDAO.deleteByParam(queryParam); + } + } + } + // 新增,新的key数据不在旧的里面 + List insertKeyList = newMap.keySet().stream().filter(nKey -> !oldMap.keySet().contains(nKey)).collect(Collectors.toList()); + List insertList = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(insertKeyList)) { + insertKeyList.stream().forEach(insertKey -> { + insertList.addAll(newMap.get(insertKey)); + }); + List insertEntitys = dsDbTableDAO.batchSave_ext(insertList); + // 新增Id,绑定关系 + if (inputV2.getResourceId() != null) { + List relateTableList = insertEntitys.stream().map(table -> { + PressureResourceRelateTableEntityV2 tableEntityV2 = new PressureResourceRelateTableEntityV2(); + tableEntityV2.setRelateId(table.getId()); + tableEntityV2.setResourceId(inputV2.getResourceId()); + tableEntityV2.setDsKey(DataSourceUtil.generateDsKey_ext(inputV2.getUrl(), inputV2.getUsername())); + tableEntityV2.setType(inputV2.getType() == null ? 0 : inputV2.getType()); + tableEntityV2.setTenantId(WebPluginUtils.traceTenantId()); + tableEntityV2.setEnvCode(WebPluginUtils.traceEnvCode()); + tableEntityV2.setGmtCreate(new Date()); + return tableEntityV2; + }).collect(Collectors.toList()); + pressureResourceRelateTableDAO.add_V2(relateTableList); + } + } + + // 修改,交集,绑定关系 + List updateKeyList = oldMap.keySet().stream().filter(nKey -> newMap.keySet().contains(nKey)).collect(Collectors.toList()); + List relateTableList = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(updateKeyList)) { + if (inputV2.getResourceId() == null) { + updateKeyList.stream().forEach(updateKey -> { + oldMap.get(updateKey).stream().forEach(oldValue -> { + ApplicationDsDbTableEntity update = new ApplicationDsDbTableEntity(); + update.setId(oldValue.getId()); + update.setGmtUpdate(new Date()); + // 获取新的数据 + List newValues = newMap.get(updateKey); + if (CollectionUtils.isNotEmpty(newValues)) { + update.setIsCheck(newValues.get(0).getIsCheck()); + dsDbTableDAO.update_v2(update); + } + }); + }); + } + if (inputV2.getResourceId() != null) { + // 关系绑定 + updateKeyList.stream().forEach(updateKey -> { + List tmpList = oldMap.get(updateKey).stream().map(table -> { + PressureResourceRelateTableEntityV2 tableEntityV2 = new PressureResourceRelateTableEntityV2(); + tableEntityV2.setResourceId(inputV2.getResourceId()); + tableEntityV2.setRelateId(table.getId()); + tableEntityV2.setDsKey(DataSourceUtil.generateDsKey_ext(inputV2.getUrl(), inputV2.getUsername())); + tableEntityV2.setType(inputV2.getType() == null ? 0 : inputV2.getType()); + tableEntityV2.setTenantId(WebPluginUtils.traceTenantId()); + tableEntityV2.setEnvCode(WebPluginUtils.traceEnvCode()); + tableEntityV2.setGmtCreate(new Date()); + return tableEntityV2; + }).collect(Collectors.toList()); + relateTableList.addAll(tmpList); + }); + pressureResourceRelateTableDAO.add_V2(relateTableList); + } + } + } + + private String fetchKey(ApplicationDsDbTableDetailResult it) { + return String.format("%d#%s#%s#%s", it.getAppId(), it.getUrl(), it.getBizDataBase(), it.getBizTable()); + } + + private void saveShadowTable(Long recordId, String str) { + if (StringUtils.isBlank(str)) { return; } ApplicationDsDbManageDetailResult detailResult = dbManageDAO.selectOneById(recordId); - if(Objects.isNull(detailResult)){ + if (Objects.isNull(detailResult)) { return; } List list = dsDbTableDAO.getList(detailResult.getUrl(), detailResult.getApplicationId(), detailResult.getUserName()); - if(CollectionUtils.isNotEmpty(list)){ + if (CollectionUtils.isNotEmpty(list)) { dsDbTableDAO.batchDeleted(list); } List tableInfos = JSONArray.parseArray(str, ShadowDetailResponse.TableInfo.class); @@ -142,12 +315,12 @@ private void saveShadowTable(Long recordId,String str){ ApplicationDsDbTableDetailResult result = new ApplicationDsDbTableDetailResult(); result.setAppId(detailResult.getApplicationId()); result.setUrl(detailResult.getUrl()); - result.setUserName( detailResult.getUserName()); + result.setUserName(detailResult.getUserName()); result.setBizDataBase(x.getBizDatabase()); result.setBizTable(x.getBizTableName()); result.setShadowTable(x.getShaDowTableName()); result.setManualTag(x.getIsManual() ? 1 : 0); - result.setIsCheck(x.getIsCheck()?1:0); + result.setIsCheck(x.getIsCheck() ? 1 : 0); return result; }).collect(Collectors.toList()); dsDbTableDAO.batchSave(collect); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/fastagentaccess/impl/AgentConfigServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/fastagentaccess/impl/AgentConfigServiceImpl.java index 24dcbbd113..32ae002220 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/fastagentaccess/impl/AgentConfigServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/fastagentaccess/impl/AgentConfigServiceImpl.java @@ -21,6 +21,7 @@ import io.shulie.takin.web.amdb.api.AgentConfigClient; import io.shulie.takin.web.amdb.bean.query.fastagentaccess.AgentConfigQueryDTO; import io.shulie.takin.web.biz.constant.LoginConstant; +import io.shulie.takin.web.biz.nacos.event.DynamicConfigRefreshEvent; import io.shulie.takin.web.biz.pojo.bo.ConfigListQueryBO; import io.shulie.takin.web.biz.pojo.request.fastagentaccess.AgentConfigCreateRequest; import io.shulie.takin.web.biz.pojo.request.fastagentaccess.AgentConfigEffectQueryRequest; @@ -51,6 +52,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -75,6 +77,9 @@ public class AgentConfigServiceImpl implements AgentConfigService, CacheConstant @Autowired private AgentConfigService agentConfigService; + @Resource + private ApplicationContext applicationContext; + /** * 对应的zk地址key */ @@ -130,10 +135,10 @@ public List> getAllGlobalKey() { @Override public List getAllApplication(String keyword) { - List userIdList = WebPluginUtils.getQueryAllowUserIdList(); + List userIdList = WebPluginUtils.queryAllowUserIdList(); + List deptIdList = WebPluginUtils.queryAllowDeptIdList(); List applicationMntList = applicationDAO.getApplicationMntByUserIdsAndKeyword( - userIdList, - keyword); + userIdList, deptIdList, keyword); return applicationMntList.stream().map(ApplicationDetailResult::getApplicationName).collect( Collectors.toList()); } @@ -190,10 +195,10 @@ public void update(AgentConfigUpdateRequest updateRequest) { String projectName = updateRequest.getProjectName(); if (StrUtil.isBlank(projectName)) { this.updateWithoutProjectName(updateRequest, detailResult); - return; + }else{ + this.updateWithProjectName(updateRequest, detailResult); } - - this.updateWithProjectName(updateRequest, detailResult); + applicationContext.publishEvent(new DynamicConfigRefreshEvent(projectName)); } /** diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ActivityServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ActivityServiceImpl.java index a3b9586e46..c1f45b3329 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ActivityServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ActivityServiceImpl.java @@ -532,6 +532,7 @@ public PagingList pageActivities(ActivityQueryRequest requ param.setCurrent(request.getCurrent()); param.setPageSize(request.getPageSize()); param.setType(request.getType()); + param.setDeptId(request.getDeptId()); WebPluginUtils.fillQueryParam(param); PagingList activityListResultPagingList = activityDAO.pageActivities(param); @@ -553,6 +554,7 @@ public PagingList pageActivities(ActivityQueryRequest requ response.setCanDelete(result.getCanDelete()); response.setBusinessDomain(result.getBusinessDomain()); response.setActivityLevel(result.getActivityLevel()); + response.setDeptId(result.getDeptId()); WebPluginUtils.fillQueryResponse(response); return response; }).collect(Collectors.toList()); @@ -1035,7 +1037,7 @@ public List processAppNameByBusinessActiveId(Long activityId) { String extend = map.get(FeaturesConstants.EXTEND_KEY); LinkTopologyDTO applicationEntrancesTopology = applicationEntranceClient.getApplicationEntrancesTopology( false, linkManageTableEntity.getApplicationName(), null, serviceName, methodName, - rpcType, extend); + rpcType, extend,false); if (applicationEntrancesTopology == null || CollectionUtils.isEmpty(applicationEntrancesTopology.getNodes())) { return new ArrayList<>(Collections.singleton(linkManageTableEntity.getApplicationName())); } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationPluginsConfigServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationPluginsConfigServiceImpl.java index 1b83c02100..610f97ac2f 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationPluginsConfigServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationPluginsConfigServiceImpl.java @@ -20,6 +20,7 @@ import io.shulie.takin.web.common.context.OperationLogContextHolder; import io.shulie.takin.web.common.exception.ExceptionCode; import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; import io.shulie.takin.web.common.util.CommonUtil; import io.shulie.takin.web.data.dao.application.ApplicationDAO; import io.shulie.takin.web.data.dao.application.ApplicationPluginsConfigDAO; @@ -71,6 +72,10 @@ public PagingList getPageByParam(ApplicationPluginsC if (Objects.isNull(param) || Objects.isNull(param.getApplicationId())) { throw new TakinWebException(ExceptionCode.POD_NUM_EMPTY, "缺少参数"); } + ApplicationDetailResult applicationById = applicationDAO.getApplicationById(param.getApplicationId()); + if (applicationById == null){ + throw new TakinWebException(TakinWebExceptionEnum.APPLICATION_MANAGE_NO_EXIST_ERROR, "该应用不存在"); + } Long tenantId = WebPluginUtils.traceTenantId(); param.setTenantId(tenantId); IPage listPage = applicationPluginsConfigDAO.findListPage(param); @@ -87,6 +92,8 @@ public PagingList getPageByParam(ApplicationPluginsC //精度丢失问题 configVO.setApplicationId(record.getApplicationId() + ""); configVO.setId(record.getId() + ""); + configVO.setDeptId(applicationById.getDeptId()); + WebPluginUtils.fillQueryResponse(configVO); configVos.add(configVO); } return PagingList.of(configVos, listPage.getTotal()); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationServiceImpl.java index 085cc4c27c..64c5febe80 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ApplicationServiceImpl.java @@ -15,8 +15,7 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -134,6 +133,7 @@ import io.shulie.takin.web.ext.entity.tenant.TenantInfoExt; import io.shulie.takin.web.ext.util.WebPluginUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.dom4j.DocumentException; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -306,8 +306,8 @@ public void init() { } @Override - public List getApplicationsByUserIdList(List userIdList) { - return applicationDAO.getApplicationListByUserIds(userIdList); + public List getApplicationsByUserIdList(List userIdList, List deptIdList) { + return applicationDAO.getApplicationListByUserIds(userIdList, deptIdList); } //3.添加定时任务 @@ -557,6 +557,7 @@ public Response getApplicationInfo(String id) { Collections.singletonList(tApplicationMnt.getApplicationName())); ApplicationResult applicationResult = CollectionUtils.isEmpty(applicationResultList) ? null : applicationResultList.get(0); + // 取应用节点版本信息 ApplicationNodeQueryParam queryParam = new ApplicationNodeQueryParam(); queryParam.setCurrent(0); @@ -973,9 +974,10 @@ public String getUserSwitchStatusForVo() { @Override public List getApplicationName() { - List userIdList = WebPluginUtils.getQueryAllowUserIdList(); + List userIdList = WebPluginUtils.queryAllowUserIdList(); + List deptIdList = WebPluginUtils.queryAllowDeptIdList(); List applicationDetailResultList = applicationDAO.getApplicationListByUserIds( - userIdList); + userIdList, deptIdList); if (CollectionUtils.isEmpty(applicationDetailResultList)) { return Lists.newArrayList(); } @@ -1378,11 +1380,12 @@ public PagingList pageApplication(ApplicationQueryReq QueryApplicationParam queryApplicationParam = BeanUtil.copyProperties(request, QueryApplicationParam.class); queryApplicationParam.setTenantId(WebPluginUtils.traceTenantId()); queryApplicationParam.setEnvCode(WebPluginUtils.traceEnvCode()); - queryApplicationParam.setUserIds(WebPluginUtils.getQueryAllowUserIdList()); + queryApplicationParam.setUserIds(WebPluginUtils.queryAllowUserIdList()); + queryApplicationParam.setDeptIds(WebPluginUtils.queryAllowDeptIdList()); queryApplicationParam.setUpdateStartTime(request.getUpdateStartTime()); queryApplicationParam.setUpdateEndTime(request.getUpdateEndTime()); IPage applicationListResultPage = applicationDAO.pageByParam(queryApplicationParam); - + if (org.springframework.util.CollectionUtils.isEmpty(applicationListResultPage.getRecords())) { return PagingList.empty(); } @@ -1391,11 +1394,15 @@ public PagingList pageApplication(ApplicationQueryReq List responseList = records.stream().map(result -> { ApplicationListResponseV2 response = BeanUtil.copyProperties(result, ApplicationListResponseV2.class); response.setId(result.getApplicationId().toString()); - - // 跟应用详情再对比下,同步下状态 - Response vo = this.getApplicationInfo(response.getId()); - if (vo.getSuccess() && vo.getData() != null) { - response.setAccessStatus(vo.getData().getAccessStatus()); + WebPluginUtils.fillQueryResponse(response); + + // 非全量查询的时候,增加不需要处理状态 + if (!request.isAll()) { + // 跟应用详情再对比下,同步下状态,这个接口真慢 + Response vo = this.getApplicationInfo(response.getId()); + if (vo.getSuccess() && vo.getData() != null) { + response.setAccessStatus(vo.getData().getAccessStatus()); + } } return response; }).collect(Collectors.toList()); @@ -1408,7 +1415,8 @@ public PagingList listApplicationByUpgrade(App QueryApplicationByUpgradeParam param = BeanUtil.copyProperties(request, QueryApplicationByUpgradeParam.class); param.setTenantId(WebPluginUtils.traceTenantId()); param.setEnvCode(WebPluginUtils.traceEnvCode()); - param.setUserIds(WebPluginUtils.getQueryAllowUserIdList()); + param.setUserIds(WebPluginUtils.queryAllowUserIdList()); + param.setDeptIds(WebPluginUtils.queryAllowDeptIdList()); IPage applicationList = applicationDAO.getApplicationList(param); if (applicationList.getTotal() == 0) { return PagingList.empty(); @@ -2662,6 +2670,12 @@ ApplicationVo appEntryToVo(ApplicationDetailResult param, ApplicationResult appl } vo.setExceptionInfo(exceptionMsg); } + // 设置下在线节点数 + if (Objects.isNull(applicationResult) || applicationResult.getInstanceInfo() == null) { + vo.setOnlineNodeNum(0); + } else { + vo.setOnlineNodeNum(applicationResult.getInstanceInfo().getInstanceOnlineAmount()); + } vo.setUserId(param.getUserId()); WebPluginUtils.fillQueryResponse(vo); return vo; @@ -2683,6 +2697,7 @@ private ApplicationCreateParam voToAppEntity(ApplicationVo param) { dbData.setAccessStatus(param.getAccessStatus()); dbData.setExceptionInfo(param.getExceptionInfo()); dbData.setSwitchStatus(param.getSwitchStutus()); + dbData.setClusterName(param.getClusterName()); if (param.getAccessStatus() == null) { dbData.setAccessStatus(1); } else { diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/DataSourceServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/DataSourceServiceImpl.java index b72f697616..9ba2d1f7ef 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/DataSourceServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/DataSourceServiceImpl.java @@ -112,6 +112,7 @@ public void createDatasource(DataSourceCreateRequest createRequest) { createParam.setUsername(username); // 4、密码加密(AES128) createParam.setPassword(AESUtil.encrypt(password)); + createParam.setDeptId(WebPluginUtils.traceDeptId()); dataSourceDAO.insert(createParam); } @@ -136,7 +137,7 @@ public void updateDatasource(DataSourceUpdateRequest updateRequest) { throw new TakinWebException(ExceptionCode.DATASOURCE_UPDATE_ERROR, "不支持的数据源类型"); } // 3、判断当前登录用户是否有更新权限 - if (!checkUpdatePermission(idResult.getUserId())) { + if (!checkUpdatePermission(idResult.getUserId(),idResult.getDeptId())) { throw new TakinWebException(ExceptionCode.DATASOURCE_UPDATE_ERROR, "更新权限不足"); } // 4、除过本id外,检查名称是否重复 @@ -174,8 +175,9 @@ public void deleteDatasource(List datasourceIds) { if (CollectionUtils.isNotEmpty(dataSourceResultList)) { List userIdList = dataSourceResultList.stream().map(DataSourceResult::getUserId).collect( Collectors.toList()); + List deptIdList = dataSourceResultList.stream().map(DataSourceResult::getDeptId).collect(Collectors.toList()); // 判断数据源的权限、状态等情况; - if (!checkDeletePermission(userIdList)) { + if (!checkDeletePermission(userIdList,deptIdList)) { throw new TakinWebException(ExceptionCode.DATASOURCE_DELETE_ERROR, "数据权限不足"); } // 删除数据源 @@ -239,6 +241,7 @@ public PagingList listDatasource(DataSourceQueryRequest } queryParam.setName(name); queryParam.setJdbcUrl(jdbcUrl); + queryParam.setDeptId(queryParam.getDeptId()); if (CollectionUtils.isNotEmpty(filterDataSourceIdList)) { queryParam.setDataSourceIdList(filterDataSourceIdList); } @@ -463,21 +466,29 @@ private Boolean checkIsExistDataSource(Long id) { return Boolean.FALSE; } - private Boolean checkUpdatePermission(Long userId) { - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowUpdateUserIdList) - && !allowUpdateUserIdList.contains(userId)) { + private Boolean checkUpdatePermission(Long userId, Long deptId) { + List allowUpdateUserIdList = WebPluginUtils.updateAllowUserIdList(); + List allowUpdateDeptIdList = WebPluginUtils.updateAllowDeptIdList(); + if (CollectionUtils.isNotEmpty(allowUpdateUserIdList) && !allowUpdateUserIdList.contains(userId)) { + return Boolean.FALSE; + } + if (CollectionUtils.isNotEmpty(allowUpdateDeptIdList) && !allowUpdateDeptIdList.contains(deptId)){ return Boolean.FALSE; } return Boolean.TRUE; } - private Boolean checkDeletePermission(List userIdList) { - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); + private Boolean checkDeletePermission(List userIdList, List deptIdList) { + List allowDeleteUserIdList = WebPluginUtils.deleteAllowUserIdList(); + List allowDeleteDeptIdList = WebPluginUtils.deleteAllowDeptIdList(); if (CollectionUtils.isNotEmpty(allowDeleteUserIdList) && !allowDeleteUserIdList.containsAll(userIdList)) { return Boolean.FALSE; } + if (CollectionUtils.isNotEmpty(allowDeleteDeptIdList) + && !allowDeleteDeptIdList.containsAll(deptIdList)) { + return Boolean.FALSE; + } return Boolean.TRUE; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/OpsScriptManageServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/OpsScriptManageServiceImpl.java index 8470739ae1..0a895c22e6 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/OpsScriptManageServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/OpsScriptManageServiceImpl.java @@ -121,9 +121,8 @@ public void init() { @Override public PagingList page(OpsScriptParam param) { PageUtils.clearPageHelper(); - List userIdList = WebPluginUtils.getQueryAllowUserIdList(); + //运维脚本已不使用,不做权限改造 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.in(!CollectionUtils.isEmpty(userIdList), OpsScriptManageEntity::getUserId, userIdList); wrapper.orderByDesc(OpsScriptManageEntity::getGmtCreate); IPage listPage = opsScriptManageDAO.findListPage(param, wrapper); List opsScriptVOList = Lists.newArrayList(); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ShadowConsumerServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ShadowConsumerServiceImpl.java index 6381118ef4..e3b86424cf 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ShadowConsumerServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/impl/ShadowConsumerServiceImpl.java @@ -150,9 +150,6 @@ public PagingList pageMqConsumers(ShadowConsumerQueryInput lambdaQueryWrapper.eq(ShadowMqConsumerEntity::getStatus, request.getEnabled() ? ShadowConsumerConstants.ENABLE : ShadowConsumerConstants.DISABLE); } - if (CollectionUtils.isNotEmpty(WebPluginUtils.getQueryAllowUserIdList())) { - lambdaQueryWrapper.in(ShadowMqConsumerEntity::getUserId, WebPluginUtils.getQueryAllowUserIdList()); - } List totalResult; lambdaQueryWrapper.eq(ShadowMqConsumerEntity::getApplicationId, request.getApplicationId()); lambdaQueryWrapper.eq(ShadowMqConsumerEntity::getDeleted, ShadowConsumerConstants.LIVED); @@ -161,7 +158,7 @@ public PagingList pageMqConsumers(ShadowConsumerQueryInput if (request.getEnabled() == null || BooleanUtil.isFalse(request.getEnabled())) { amdbResult = queryAmdbDefaultEntrances(request, application.getApplicationName()); } - totalResult = mergeResult(amdbResult, dbResult); + totalResult = mergeResult(amdbResult, dbResult, application.getDeptId()); totalResult = filterResult(request, totalResult); return splitPage(request, totalResult); } @@ -188,7 +185,7 @@ private List filterResult(ShadowConsumerQueryInput request } private List mergeResult(List amdbResult, - List dbResult) { + List dbResult, Long deptId) { Map amdbMap = new HashMap<>(); Map entityMap = mqConfigTemplateDAO.selectToMapWithNameKey(); if (CollectionUtils.isNotEmpty(amdbResult)) { @@ -229,6 +226,7 @@ private List mergeResult(List amdb response.setIsManual(e.getManualTag() == 1); response.setCanRemove(response.getIsManual()); response.setShadowconsumerEnable(String.valueOf(e.getStatus())); + response.setDeptId(deptId); WebPluginUtils.fillQueryResponse(response); return response; }) @@ -664,9 +662,6 @@ public PagingList pageMqConsumersV2(ShadowConsumerQueryInp // if (StringUtils.isNotBlank(request.getShadowConsumerEnable())) { // lambdaQueryWrapper.eq(ShadowMqConsumerEntity::getStatus, request.getShadowConsumerEnable()); // } - if (CollectionUtils.isNotEmpty(WebPluginUtils.getQueryAllowUserIdList())) { - lambdaQueryWrapper.in(ShadowMqConsumerEntity::getUserId, WebPluginUtils.getQueryAllowUserIdList()); - } List totalResult; lambdaQueryWrapper.eq(ShadowMqConsumerEntity::getApplicationId, request.getApplicationId()); lambdaQueryWrapper.eq(ShadowMqConsumerEntity::getDeleted, ShadowConsumerConstants.LIVED); @@ -678,7 +673,7 @@ public PagingList pageMqConsumersV2(ShadowConsumerQueryInp if (StringUtils.isBlank(request.getShadowconsumerEnable()) || Objects.equals(request.getShadowconsumerEnable(), "0")) { amdbResult = queryAmdbDefaultEntrances(queryInput, application.getApplicationName()); } - totalResult = mergeResult(amdbResult, dbResult); + totalResult = mergeResult(amdbResult, dbResult, application.getDeptId()); totalResult = filterResult(queryInput, totalResult); return splitPage(queryInput, totalResult); } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/interfaceperformance/impl/PerformanceConfigServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/interfaceperformance/impl/PerformanceConfigServiceImpl.java index 03b4610a93..0c7f3d3c87 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/interfaceperformance/impl/PerformanceConfigServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/interfaceperformance/impl/PerformanceConfigServiceImpl.java @@ -99,6 +99,7 @@ public Long add(PerformanceConfigCreateInput input) { insertConfigEntity.setGmtModified(new Date()); // 设置归属人未当前创建人 insertConfigEntity.setUserId(WebPluginUtils.traceUserId()); + insertConfigEntity.setDeptId(WebPluginUtils.traceDeptId()); // 新增配置信息 Long returnObj = performanceConfigDAO.add(insertConfigEntity); /** @@ -186,7 +187,13 @@ public PagingList query(PerformanceConfigQueryRequest reque BeanUtils.copyProperties(request, param); AuthQueryParamCommonExt ext = new AuthQueryParamCommonExt(); WebPluginUtils.fillQueryParam(ext); - param.setUserIdList(ext.getUserIdList()); + if (CollectionUtils.isNotEmpty(ext.getUserIdList())){ + param.setUserIdList(ext.getUserIdList()); + } + if (CollectionUtils.isNotEmpty(ext.getDeptIdList())){ + param.setDeptIdList(ext.getDeptIdList()); + } + PagingList dtoPagingList = performanceConfigDAO.pageList(param); //转换下 List source = dtoPagingList.getList(); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/AppRemoteCallService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/AppRemoteCallService.java index 1bc1c7e5e7..ac08eb45e3 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/AppRemoteCallService.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/AppRemoteCallService.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; +import com.pamirs.takin.entity.domain.vo.TDictionaryVo; import io.shulie.takin.common.beans.component.SelectVO; import io.shulie.takin.common.beans.page.PagingList; import io.shulie.takin.web.amdb.bean.result.application.ApplicationRemoteCallDTO; @@ -104,6 +105,7 @@ public interface AppRemoteCallService { /** * 批量配置白名单 + * * @param request */ void batchConfig(AppRemoteCallConfigRequest request); @@ -125,18 +127,21 @@ public interface AppRemoteCallService { /** * 获取服务端应用的接口 + * * @return */ - Map> getListGroupByAppId(); + Map> getListGroupByAppId(); /** * 根据id批量逻辑删除 + * * @param ids */ void batchLogicDelByIds(List ids); /** * 批量保存 + * * @param list */ void batchSave(List list); @@ -159,4 +164,13 @@ public interface AppRemoteCallService { * 更新 */ void batchUpdateV2(AppRemoteCallBatchUpdateV2Request request); + + /** + * 接口类型 + * + * @param methodName + * @param voList + * @return + */ + Integer getInterfaceType(String methodName, List voList); } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/AppRemoteCallServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/AppRemoteCallServiceImpl.java index 44d6228260..dbe7cc4246 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/AppRemoteCallServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/AppRemoteCallServiceImpl.java @@ -198,11 +198,7 @@ public void update(AppRemoteCallUpdateInput input) { @Override public void batchConfig(AppRemoteCallConfigRequest request) { - if (WebPluginUtils.validateAdmin()) { - appRemoteCallDAO.updateListSelective(request.getType(), request.getAppIds(), null); - } else { - appRemoteCallDAO.updateListSelective(request.getType(), request.getAppIds(), WebPluginUtils.getUpdateAllowUserIdList()); - } + appRemoteCallDAO.updateListSelective(request.getType(), request.getAppIds(), null); } @Override @@ -310,6 +306,8 @@ public PagingList pagingList(AppRemoteCallQueryInput input) result.setTypeSelectVO(new SelectVO(entity.getName(), String.valueOf(entity.getValueOrder()))); // 支持类型 result.setInterfaceTypeSelectVO(getSelectVO(result.getInterfaceType(), voList)); + + result.setDeptId(detailResult.getDeptId()); // 补充权限 WebPluginUtils.fillQueryResponse(result); }); @@ -329,7 +327,8 @@ private String getMiddlewareName(List voList) { return String.join(",", middlewareNames); } - private Integer getInterfaceType(String methodName, List voList) { + @Override + public Integer getInterfaceType(String methodName, List voList) { InterfaceTypeMainEntity mainEntity = interfaceTypeMainDAO.selectByName(methodName); if (mainEntity == null) { if (CollectionUtils.isEmpty(voList)) { @@ -382,27 +381,27 @@ private PagingList getDbPagingList(AppRemoteCallQueryInput } /** - * 权限填充 用应用权限来控制 + * 权限填充 用应用权限来控制, 应用内部不再做一次权限控制 */ private void fillInPermissions(AppRemoteCallListVO listVO, ApplicationDetailResult detailResult) { - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - if (CollectionUtils.isEmpty(allowUpdateUserIdList)) { - //管理员 - listVO.setCanEdit(true); - } else { - //普通用户 - listVO.setCanEdit(allowUpdateUserIdList.contains(detailResult.getUserId())); - } - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); - if (CollectionUtils.isEmpty(allowDeleteUserIdList)) { - listVO.setCanRemove(true); - } else { - listVO.setCanRemove(allowDeleteUserIdList.contains(detailResult.getUserId())); - } - List allowEnableDisableUserIdList = WebPluginUtils.getEnableDisableAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowEnableDisableUserIdList)) { - listVO.setCanEnableDisable(allowEnableDisableUserIdList.contains(detailResult.getUserId())); - } +// List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); +// if (CollectionUtils.isEmpty(allowUpdateUserIdList)) { +// //管理员 +// listVO.setCanEdit(true); +// } else { +// //普通用户 +// listVO.setCanEdit(allowUpdateUserIdList.contains(detailResult.getUserId())); +// } +// List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); +// if (CollectionUtils.isEmpty(allowDeleteUserIdList)) { +// listVO.setCanRemove(true); +// } else { +// listVO.setCanRemove(allowDeleteUserIdList.contains(detailResult.getUserId())); +// } +// List allowEnableDisableUserIdList = WebPluginUtils.getEnableDisableAllowUserIdList(); +// if (CollectionUtils.isNotEmpty(allowEnableDisableUserIdList)) { +// listVO.setCanEnableDisable(allowEnableDisableUserIdList.contains(detailResult.getUserId())); +// } } @Override @@ -997,7 +996,6 @@ public void updateV2(AppRemoteCallUpdateV2Request request) { throw new TakinWebException(ExceptionCode.REMOTE_CALL_CONFIG_CHECK_ERROR, "应用不存在"); } this.checkRequest(request); - agentConfigCacheManager.evictRecallCalls(detailResult.getApplicationName()); if (Objects.isNull(request.getId())) { this.create(request); return; @@ -1018,7 +1016,7 @@ public void updateV2(AppRemoteCallUpdateV2Request request) { param.setMockReturnValue(request.getMockValue()); // param.setRemark(request.getRemark()); appRemoteCallDAO.update(param); - + agentConfigCacheManager.evictRecallCalls(detailResult.getApplicationName()); } @Override diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/ApplicationApiServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/ApplicationApiServiceImpl.java index 840b6bce24..b61b93d83f 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/ApplicationApiServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/ApplicationApiServiceImpl.java @@ -117,6 +117,7 @@ public Response registerApi(Map> register) { manage.setIsAgentRegiste(1); manage.setTenantId(WebPluginUtils.traceTenantId()); manage.setEnvCode(WebPluginUtils.traceEnvCode()); + manage.setDeptId(applicationDetailResult.getDeptId()); batch.add(manage); } @@ -133,6 +134,7 @@ public Response registerApi(Map> register) { manage.setIsAgentRegiste(1); manage.setTenantId(WebPluginUtils.traceTenantId()); manage.setEnvCode(WebPluginUtils.traceEnvCode()); + manage.setDeptId(applicationDetailResult.getDeptId()); batch.add(manage); } @@ -165,6 +167,7 @@ public Response registerApi(Map> register) { manage.setTenantId(single.getTenantId()); manage.setUserId(single.getUserId()); manage.setIsAgentRegiste(single.getIsAgentRegiste()); + manage.setDeptId(single.getDeptId()); applicationApiDAO.insertSelective(manage); } catch (TakinWebException e1) { log.error(e1.getMessage(), e1); @@ -229,8 +232,8 @@ public Response query(EntranceApiVo vo) { ApplicationApiQueryParam manage = new ApplicationApiQueryParam(); manage.setApplicationName(vo.getApplicationName()); manage.setApi(vo.getApi()); - - List dataList = applicationApiDAO.selectBySelective(manage, WebPluginUtils.getQueryAllowUserIdList()); + manage.setDeptId(vo.getDeptId()); + List dataList = applicationApiDAO.selectBySelective(manage, WebPluginUtils.queryAllowUserIdList(), WebPluginUtils.queryAllowDeptIdList() ); dataList.sort(Comparator.comparing(ApplicationApiManageResult::getCreateTime).reversed()); List pageData = @@ -240,14 +243,7 @@ public Response query(EntranceApiVo vo) { ApplicationApiManageVO dto = new ApplicationApiManageVO(); BeanUtils.copyProperties(data, dto); dto.setRequestMethod(data.getMethod()); - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowUpdateUserIdList)) { - dto.setCanEdit(allowUpdateUserIdList.contains(data.getUserId())); - } - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowDeleteUserIdList)) { - dto.setCanRemove(allowDeleteUserIdList.contains(data.getUserId())); - } + WebPluginUtils.fillQueryResponse(dto); dtoList.add(dto); }); /* PageInfo pageInfo = new PageInfo<>(pageData);*/ @@ -304,6 +300,7 @@ public Response create(ApiCreateVo vo) { createParam.setIsDeleted((byte) 0); createParam.setEnvCode(WebPluginUtils.traceEnvCode()); createParam.setTenantId(WebPluginUtils.traceTenantId()); + createParam.setDeptId(WebPluginUtils.traceDeptId()); boolean status = applicationApiDAO.check(vo.getApplicationName(), DictionaryCache.getObjectByParam(HTTP_METHOD_TYPE, Integer.parseInt(vo.getMethod())).getLabel(), vo.getApi()); if (status) return Response.fail("重复添加"); // 把旧的记录删除了,新的再添加 diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkGuardServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkGuardServiceImpl.java index 92d8851904..04a9bc38f8 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkGuardServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkGuardServiceImpl.java @@ -19,6 +19,9 @@ import io.shulie.takin.web.biz.utils.PageUtils; import io.shulie.takin.web.common.common.Response; import io.shulie.takin.web.common.constant.GuardEnableConstants; +import io.shulie.takin.web.common.exception.ExceptionCode; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; import io.shulie.takin.web.data.dao.application.ApplicationDAO; import io.shulie.takin.web.data.dao.application.LinkGuardDAO; import io.shulie.takin.web.data.param.application.LinkGuardCreateParam; @@ -65,19 +68,19 @@ public Response addGuard(LinkGuardVo vo) { } else { } if (StringUtils.isBlank(vo.getApplicationName()) || StringUtils.isBlank(vo.getMethodInfo())) { - return Response.fail(FALSE_CORE, "applicationName和methodInfo不能为空"); + throw new TakinWebException(ExceptionCode.GUARD_PARAM_ERROR, "applicationName和methodInfo不能为空"); } if (!vo.getMethodInfo().contains("#")) { - return Response.fail(FALSE_CORE, "类名方法名用'#'分割,如Aa#bb"); + throw new TakinWebException(ExceptionCode.GUARD_PARAM_ERROR, "类名方法名用'#'分割,如Aa#bb"); } LinkGuardQueryParam param = new LinkGuardQueryParam(); param.setMethodInfo(vo.getMethodInfo()); if (vo.getApplicationId() != null && !vo.getApplicationId().isEmpty()) { param.setAppId(Long.valueOf(vo.getApplicationId())); } - List dbList = tLinkGuardMapper.selectByExample(param, WebPluginUtils.getQueryAllowUserIdList()); + List dbList = tLinkGuardMapper.selectByExample(param, null); if (dbList != null && dbList.size() > 0) { - return Response.fail(FALSE_CORE, "同一个methodInfo只能设置一个挡板"); + throw new TakinWebException(ExceptionCode.GUARD_PARAM_ERROR, "同一个methodInfo只能设置一个挡板"); } LinkGuardCreateParam createParam = new LinkGuardCreateParam(); createParam.setIsEnable(vo.getIsEnable()); @@ -91,7 +94,7 @@ public Response addGuard(LinkGuardVo vo) { linkGuardDAO.insert2(createParam); } catch (Exception e) { log.error(e.getMessage(), e); - return Response.fail(FALSE_CORE, "创建挡板失败"); + throw new TakinWebException(ExceptionCode.GUARD_PARAM_ERROR, "创建挡板失败"); } applicationService.modifyAccessStatus(vo.getApplicationId(), AppAccessTypeEnum.UNUPLOAD.getValue(), null); configSyncService.syncGuard(WebPluginUtils.traceTenantCommonExt(), Long.parseLong(vo.getApplicationId()), vo.getApplicationName()); @@ -167,7 +170,7 @@ public Response> selectByExample(LinkGuardQueryParam param) { } } } - list = tLinkGuardMapper.selectByExample(param, WebPluginUtils.getQueryAllowUserIdList()); + list = tLinkGuardMapper.selectByExample(param, null); if (null != list && list.size() > 0) { if (param.getCurrentPage() == null || param.getPageSize() == null) { @@ -175,8 +178,12 @@ public Response> selectByExample(LinkGuardQueryParam param) { } else { page = PageUtils.getPage(true, param.getCurrentPage(), param.getPageSize(), list); } + ApplicationDetailResult applicationById = applicationDAO.getApplicationById(param.getAppId()); + if (applicationById == null){ + throw new TakinWebException(TakinWebExceptionEnum.APPLICATION_MANAGE_NO_EXIST_ERROR, "该应用不存在"); + } page.stream().forEach(guardEntity -> { - result.add(entityToVo(guardEntity)); + result.add(entityToVo(guardEntity,applicationById.getDeptId())); }); } return Response.success(result, CollectionUtils.isEmpty(list) ? 0 : list.size()); @@ -198,7 +205,7 @@ public Response> selectAll() { try { LinkGuardQueryParam param = new LinkGuardQueryParam(); param.setIsEnable(true); - list = tLinkGuardMapper.selectByExample(param, WebPluginUtils.getQueryAllowUserIdList()); + list = tLinkGuardMapper.selectByExample(param,null); } catch (Exception e) { log.error(e.getMessage(), e); return Response.fail(FALSE_CORE, "查询挡板失败", null); @@ -209,7 +216,7 @@ public Response> selectAll() { @Override public Response getById(Long id) { LinkGuardEntity guardEntity = tLinkGuardMapper.selectById(id); - LinkGuardVo vo = entityToVo(guardEntity); + LinkGuardVo vo = entityToVo(guardEntity, null); return Response.success(vo); } @@ -233,7 +240,7 @@ public List getAllEnabledGuard(String applicationId) { return tLinkGuardMapper.getAllEnabledGuard(applicationId); } - public LinkGuardVo entityToVo(LinkGuardEntity guardEntity) { + public LinkGuardVo entityToVo(LinkGuardEntity guardEntity, Long deptId) { if (guardEntity == null) { return null; } @@ -250,6 +257,7 @@ public LinkGuardVo entityToVo(LinkGuardEntity guardEntity) { } // 判断权限,需要把用户传入 vo.setUserId(guardEntity.getUserId()); + vo.setDeptId(deptId); WebPluginUtils.fillQueryResponse(vo); return vo; } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkManageServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkManageServiceImpl.java index 2c2acba759..90bd90f66c 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkManageServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/LinkManageServiceImpl.java @@ -89,7 +89,9 @@ import io.shulie.takin.web.data.dao.linkmanage.BusinessLinkManageDAO; import io.shulie.takin.web.data.dao.linkmanage.LinkManageDAO; import io.shulie.takin.web.data.dao.linkmanage.SceneDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDAO; import io.shulie.takin.web.data.dao.scene.SceneLinkRelateDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; import io.shulie.takin.web.data.param.activity.ActivityQueryParam; import io.shulie.takin.web.data.param.linkmanage.BusinessLinkManageQueryParam; import io.shulie.takin.web.data.param.linkmanage.LinkManageQueryParam; @@ -163,24 +165,26 @@ public class LinkManageServiceImpl implements LinkManageService { private ActivityDAO activityDAO; @Autowired private SceneLinkRelateDAO sceneLinkRelateDAO; + @Autowired + private PressureResourceDAO pressureResourceDAO; private static void iteratorChildNodes(TopologicalGraphNode parentNode, - List childList, - List nodes, - List relations) { + List childList, + List nodes, + List relations) { if (CollectionUtils.isEmpty(childList)) { return; } List filterChildList = childList.stream().filter(distinctByName(Category::getApplicationName)).collect( - Collectors.toList()); + Collectors.toList()); int index = 0; for (Category category : filterChildList) { TopologicalGraphNode childNode = new TopologicalGraphNode(); childNode.setKey(parentNode.getKey() + "." + index); NodeClassEnum nodeClassEnum = getNodeClassEnumByApplicationName( - category.getApplicationName()); + category.getApplicationName()); MiddlewareTypeEnum middlewareTypeEnum = getMiddlewareTypeEnumByApplicationName( - category.getApplicationName()); + category.getApplicationName()); childNode.setNodeType(nodeClassEnum.getCode()); childNode.setNodeClass(nodeClassEnum.getDesc()); if (middlewareTypeEnum != null) { @@ -355,67 +359,68 @@ public Response getBussisnessLinks(BusinessQueryVo vo) { queryVo.setIsChange(vo.getIschange()); queryVo.setSystemProcessName(vo.getTechLinkName()); queryVo.setDomain(vo.getDomain()); - List queryResult = tBusinessLinkManageTableMapper.selectBussinessLinkListBySelective2(queryVo, WebPluginUtils.getQueryAllowUserIdList()); + //老版本接口已经使用了 + List queryResult = tBusinessLinkManageTableMapper.selectBussinessLinkListBySelective2(queryVo, null); //用户ids List userIds = queryResult.stream() - .map(BusinessLinkDto::getUserId) - .filter(Objects::nonNull) - .collect(Collectors.toList()); + .map(BusinessLinkDto::getUserId) + .filter(Objects::nonNull) + .collect(Collectors.toList()); //用户信息Map key:userId value:user对象 Map userMap = WebPluginUtils.getUserMapByIds(userIds); List pageData = PageUtils.getPage(true, vo.getCurrentPage(), vo.getPageSize(), queryResult); if (CollectionUtils.isNotEmpty(pageData) && pageData.size() > 0) { pageData.forEach( - single -> { - BusinessActiveViewListDto dto = new BusinessActiveViewListDto(); - dto.setBusinessActiceId(single.getId()); - dto.setBusinessActiveName(single.getLinkName()); - dto.setCandelete(single.getCandelete()); - dto.setCreateTime(single.getCreateTime()); - dto.setIschange(single.getIschange()); - //负责人id - dto.setUserId(single.getUserId()); - //负责人name - String userName = Optional.ofNullable(userMap.get(single.getUserId())) - .map(UserExt::getName) - .orElse(""); - dto.setUserName(userName); - WebPluginUtils.fillQueryResponse(dto); - //新版本设置业务域 - if (StringUtils.isNotBlank(single.getBusinessDomain())) { - String desc = DictionaryCache.getObjectByParam("domain", - Integer.parseInt(single.getBusinessDomain())).getLabel(); - if (StringUtils.isNotBlank(desc)) { - dto.setBusinessDomain(desc); - } else { - //兼容历史版本 - LinkDomainEnum domainEnum = LinkDomainEnumMapping.getByCode(single.getBusinessDomain()); - dto.setBusinessDomain(domainEnum == null ? null : domainEnum.getDesc()); + single -> { + BusinessActiveViewListDto dto = new BusinessActiveViewListDto(); + dto.setBusinessActiceId(single.getId()); + dto.setBusinessActiveName(single.getLinkName()); + dto.setCandelete(single.getCandelete()); + dto.setCreateTime(single.getCreateTime()); + dto.setIschange(single.getIschange()); + //负责人id + dto.setUserId(single.getUserId()); + //负责人name + String userName = Optional.ofNullable(userMap.get(single.getUserId())) + .map(UserExt::getName) + .orElse(""); + dto.setUserName(userName); + WebPluginUtils.fillQueryResponse(dto); + //新版本设置业务域 + if (StringUtils.isNotBlank(single.getBusinessDomain())) { + String desc = DictionaryCache.getObjectByParam("domain", + Integer.parseInt(single.getBusinessDomain())).getLabel(); + if (StringUtils.isNotBlank(desc)) { + dto.setBusinessDomain(desc); + } else { + //兼容历史版本 + LinkDomainEnum domainEnum = LinkDomainEnumMapping.getByCode(single.getBusinessDomain()); + dto.setBusinessDomain(domainEnum == null ? null : domainEnum.getDesc()); + } } + TechLinkDto techLinkDto = single.getTechLinkDto(); + + if (techLinkDto != null) { + List middlewareInfos = + tMiddlewareInfoMapper.selectBySystemProcessId(techLinkDto.getLinkId()); + List middleWareStrings = middlewareInfos + .stream() + .map(entity -> + entity.getMiddlewareName() + " " + entity.getMiddlewareVersion() + ).collect(Collectors.toList()); + dto.setMiddleWareList(middleWareStrings); + dto.setSystemProcessName(single.getTechLinkDto().getTechLinkName()); + } + result.add(dto); } - TechLinkDto techLinkDto = single.getTechLinkDto(); - - if (techLinkDto != null) { - List middlewareInfos = - tMiddlewareInfoMapper.selectBySystemProcessId(techLinkDto.getLinkId()); - List middleWareStrings = middlewareInfos - .stream() - .map(entity -> - entity.getMiddlewareName() + " " + entity.getMiddlewareVersion() - ).collect(Collectors.toList()); - dto.setMiddleWareList(middleWareStrings); - dto.setSystemProcessName(single.getTechLinkDto().getTechLinkName()); - } - result.add(dto); - } ); } return Response.success(result, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size()); } private void convertBusinessLinkResponse(BusinessLinkResult businessLinkResult, - BusinessLinkResponse businessLinkResponse) { + BusinessLinkResponse businessLinkResponse) { businessLinkResponse.setId(businessLinkResult.getId()); businessLinkResponse.setLinkName(businessLinkResult.getLinkName()); businessLinkResponse.setEntrance(businessLinkResult.getEntrace()); @@ -455,9 +460,9 @@ public BusinessLinkResponse getBussisnessLinkDetail(String id) { Long systemProcessId = businessLinkResponse.getTechLinkResponse().getLinkId(); if (systemProcessId != null) { LinkManageResult linkManageResult = linkManageDAO.selectLinkManageById( - businessLinkResult.getTechLinkResult().getLinkId()); + businessLinkResult.getTechLinkResult().getLinkId()); businessLinkResponse.getTechLinkResponse().setMiddleWareResponses( - getMiddleWareResponses(linkManageResult.getApplicationName())); + getMiddleWareResponses(linkManageResult.getApplicationName())); //处理系统流程前端展示数据 TechLinkResponse techLinkResponse = businessLinkResponse.getTechLinkResponse(); String linkBody; @@ -527,7 +532,10 @@ public String deleteScene(String sceneId) { //过滤出可以设置为删除状态的业务活动id并设置为可以删除 enableBusinessActiveCanDelte(businessLinkIds); + // 删除压测资源准备 + pressureResourceDAO.delete(Long.valueOf(sceneId)); transactionManager.commit(status); + return "删除成功"; } catch (TakinWebException e) { transactionManager.rollback(status); @@ -545,27 +553,27 @@ private void enableBusinessActiveCanDelte(List businessLinkIds) { return; } List candeletedList = businessLinkIds.stream() - .map(single -> { - long count = sceneLinkRelateDAO.countByBusinessLinkId(single); - if (!(count > 0)) { - return single; - } - return 0L; - }).collect(Collectors.toList()); + .map(single -> { + long count = sceneLinkRelateDAO.countByBusinessLinkId(single); + if (!(count > 0)) { + return single; + } + return 0L; + }).collect(Collectors.toList()); tBusinessLinkManageTableMapper.cannotdelete(candeletedList, 0L); } @Override public Response> getScenes(SceneQueryVo vo) { - List sceneDtos = tSceneMapper.selectByRelatedQuery(vo, WebPluginUtils.getQueryAllowUserIdList()); + List sceneDtos = tSceneMapper.selectByRelatedQuery(vo, null); List pageData = PageUtils.getPage(true, vo.getCurrentPage(), vo.getPageSize(), sceneDtos); if (CollectionUtils.isEmpty(sceneDtos)) { return Response.success(pageData, 0); } //查询业务活动是否存在虚拟业务活动 List sceneIds = pageData.stream().map(SceneDto::getId).map(String::valueOf).collect( - Collectors.toList()); + Collectors.toList()); SceneLinkRelateParam relateParam = new SceneLinkRelateParam(); relateParam.setSceneIds(sceneIds); List relateResults = sceneLinkRelateDAO.getList(relateParam); @@ -575,25 +583,25 @@ public Response> getScenes(SceneQueryVo vo) { ActivityQueryParam param = new ActivityQueryParam(); param.setBusinessType(BusinessTypeEnum.VIRTUAL_BUSINESS.getType()); param.setActivityIds(relateResults.stream().map(SceneLinkRelateResult::getBusinessLinkId) - .map(Long::parseLong).collect(Collectors.toList())); + .map(Long::parseLong).collect(Collectors.toList())); List results = activityDAO.getActivityList(param); map = relateResults.stream().collect( - Collectors.toMap( - SceneLinkRelateResult::getSceneId, - data -> results.stream() - .filter(activity -> data.getBusinessLinkId().equals(String.valueOf(activity.getActivityId()))) - .collect(Collectors.toList()), - (List newValueList, List oldValueList) -> { - oldValueList.addAll(newValueList); - return oldValueList; - })); + Collectors.toMap( + SceneLinkRelateResult::getSceneId, + data -> results.stream() + .filter(activity -> data.getBusinessLinkId().equals(String.valueOf(activity.getActivityId()))) + .collect(Collectors.toList()), + (List newValueList, List oldValueList) -> { + oldValueList.addAll(newValueList); + return oldValueList; + })); } Map> finalMap = map; //用户ids List userIds = sceneDtos.stream().map(SceneDto::getUserId).filter(Objects::nonNull) - .collect(Collectors.toList()); + .collect(Collectors.toList()); Map userExtMap = WebPluginUtils.getUserMapByIds(userIds); pageData = pageData.stream().map(single -> { long count = sceneLinkRelateDAO.countBySceneId(single.getId()); @@ -620,19 +628,19 @@ public Response> getMiddleWareInfo(StatisticsQuery try { List list = tMiddlewareInfoMapper.selectforstatistics(vo); List pageData = PageUtils.getPage(true, vo.getCurrentPage(), vo.getPageSize(), - list); + list); pageData = pageData.stream().peek( - single -> { - long id = single.getMiddleWareId(); - List techLinkIds = tMiddlewareLinkRelateMapper.selectTechIdsByMiddleWareIds(id); - single.setSystemProcessCount(String.valueOf(techLinkIds.size())); - //统计业务流程条数 - if (CollectionUtils.isNotEmpty(techLinkIds)) { - int countBusinessProcess = sceneLinkRelateDAO.countByTechLinkIds(techLinkIds); - single.setBussinessProcessCount(String.valueOf(countBusinessProcess)); + single -> { + long id = single.getMiddleWareId(); + List techLinkIds = tMiddlewareLinkRelateMapper.selectTechIdsByMiddleWareIds(id); + single.setSystemProcessCount(String.valueOf(techLinkIds.size())); + //统计业务流程条数 + if (CollectionUtils.isNotEmpty(techLinkIds)) { + int countBusinessProcess = sceneLinkRelateDAO.countByTechLinkIds(techLinkIds); + single.setBussinessProcessCount(String.valueOf(countBusinessProcess)); + } } - } ).collect(Collectors.toList()); return Response.success(pageData, CollectionUtils.isEmpty(list) ? 0 : list.size()); @@ -707,8 +715,8 @@ public LinkHistoryInfoDto getChart() { String businessFlowTotalCount = String.valueOf(businessFlowTotalCountNum); String businessFlowPressureCount = "0"; String businessFlowPressureRate = - (businessFlowTotalCountNum == 0L || "0".equals(businessFlowPressureCount)) ? - "0" : String.valueOf(businessFlowTotalCountNum / Long.parseLong(businessFlowPressureCount)); + (businessFlowTotalCountNum == 0L || "0".equals(businessFlowPressureCount)) ? + "0" : String.valueOf(businessFlowTotalCountNum / Long.parseLong(businessFlowPressureCount)); dto.setBusinessFlowTotalCount(businessFlowTotalCount); dto.setBusinessFlowPressureCount(businessFlowPressureCount); dto.setBusinessFlowPressureRate(businessFlowPressureRate); @@ -718,7 +726,7 @@ public LinkHistoryInfoDto getChart() { String applicationTotalCount = String.valueOf(applicationTotalCountNum); String applicationPressureCount = "0"; String applicationPressureRate = (applicationTotalCountNum == 0L || "0".equals(applicationPressureCount)) ? - "0" : String.valueOf(applicationTotalCountNum / Long.parseLong(applicationPressureCount)); + "0" : String.valueOf(applicationTotalCountNum / Long.parseLong(applicationPressureCount)); dto.setApplicationTotalCount(applicationTotalCount); dto.setApplicationPressureCount(applicationPressureCount); dto.setApplicationPressureRate(applicationPressureRate); @@ -731,7 +739,7 @@ public List businessProcessMiddleWares(List ids) { List result = Lists.newArrayList(); List businessIds = - ids.stream().map(id -> Long.parseLong(String.valueOf(id))).collect(Collectors.toList()); + ids.stream().map(id -> Long.parseLong(String.valueOf(id))).collect(Collectors.toList()); //查系统流程id集合 List techIds = tBusinessLinkManageTableMapper.selectTechIdsByBusinessIds(businessIds); if (CollectionUtils.isEmpty(techIds)) { @@ -744,7 +752,7 @@ public List businessProcessMiddleWares(List ids) { } //查中间件信息 List midllewareIdslong = middleWareIds.stream() - .map(Long::parseLong).collect(Collectors.toList()); + .map(Long::parseLong).collect(Collectors.toList()); result = tMiddlewareInfoMapper.selectByIds(midllewareIdslong); @@ -755,7 +763,7 @@ public List businessProcessMiddleWares(List ids) { public List getAllMiddleWareTypeList() { List result = Lists.newArrayList(); List infos = tMiddlewareInfoMapper - .selectBySelective(new TMiddlewareInfo()); + .selectBySelective(new TMiddlewareInfo()); //按照中间件类型去重 infos.forEach(info -> { @@ -767,10 +775,10 @@ public List getAllMiddleWareTypeList() { result.add(entity); }); List distinct = result.stream() - .collect(Collectors.collectingAndThen(Collectors.toCollection( - () -> new TreeSet<>( - Comparator.comparing(MiddleWareEntity::getMiddleWareType))), - ArrayList::new)); + .collect(Collectors.collectingAndThen(Collectors.toCollection( + () -> new TreeSet<>( + Comparator.comparing(MiddleWareEntity::getMiddleWareType))), + ArrayList::new)); return distinct; } @@ -801,7 +809,7 @@ public List getAllSystemProcessCanrelateBusiness(Stri serachTable.setCanDelete(0); List tables = - tLinkManageTableMapper.selectBySelective(serachTable); + tLinkManageTableMapper.selectBySelective(serachTable); if (CollectionUtils.isNotEmpty(tables)) { tables.forEach(table -> { SystemProcessIdAndNameDto dto = new SystemProcessIdAndNameDto(); @@ -863,14 +871,14 @@ public void addBusinessFlow(BusinessFlowVo vo) throws Exception { private void diableDeleteBusinessActives(List relates) { List relateBusinessLinkIds = - relates.stream().map( - single -> { - if (single.getBusinessLinkId() != null) { - return Long.parseLong(single.getBusinessLinkId()); - } - return 0L; - } - ).collect(Collectors.toList()); + relates.stream().map( + single -> { + if (single.getBusinessLinkId() != null) { + return Long.parseLong(single.getBusinessLinkId()); + } + return 0L; + } + ).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(relateBusinessLinkIds)) { tBusinessLinkManageTableMapper.cannotdelete(relateBusinessLinkIds, 1L); @@ -936,6 +944,7 @@ private Long addScene(BusinessFlowVo vo) { param.setIsCore(Integer.parseInt(vo.getIsCore())); param.setIsChanged(0); param.setIsDeleted(0); + param.setDeptId(WebPluginUtils.traceDeptId()); sceneDAO.insert(param); return param.getId(); } @@ -948,28 +957,28 @@ private Long addScene(BusinessFlowVo vo) { private void infoCompletion(List relates) { //获取出所有的业务活动ID List businessIds - = relates - .stream() - .map(relate -> Long.parseLong(relate.getBusinessLinkId())).collect(Collectors.toList()); + = relates + .stream() + .map(relate -> Long.parseLong(relate.getBusinessLinkId())).collect(Collectors.toList()); List tables = - tBusinessLinkManageTableMapper.selectByPrimaryKeys(businessIds); + tBusinessLinkManageTableMapper.selectByPrimaryKeys(businessIds); Map> map - = tables.stream() - .collect(Collectors.groupingBy( - BusinessLinkManageTable::getLinkId)); + = tables.stream() + .collect(Collectors.groupingBy( + BusinessLinkManageTable::getLinkId)); relates.forEach( - relate -> { - Long businessLinkId = Long.parseLong(relate.getBusinessLinkId()); - List lists = map.get(businessLinkId); - if (CollectionUtils.isNotEmpty(lists)) { - BusinessLinkManageTable table = lists.get(0); - relate.setEntrance(table.getEntrace()); - relate.setTechLinkId(table.getRelatedTechLink()); + relate -> { + Long businessLinkId = Long.parseLong(relate.getBusinessLinkId()); + List lists = map.get(businessLinkId); + if (CollectionUtils.isNotEmpty(lists)) { + BusinessLinkManageTable table = lists.get(0); + relate.setEntrance(table.getEntrace()); + relate.setTechLinkId(table.getRelatedTechLink()); + } } - } ); } @@ -981,7 +990,7 @@ private void infoCompletion(List relates) { * @return - */ private List parsing(List children, String parentId, Long sceneId, - List result) { + List result) { for (BusinessFlowTree businessFlowTree : children) { SceneLinkRelateSaveParam relate = new SceneLinkRelateSaveParam(); BusinessFlowTree child = businessFlowTree; @@ -1011,7 +1020,7 @@ public BusinessFlowDto getBusinessFlowDetail(Long id) { Scene scene = tSceneMapper.selectByPrimaryKey(id); if (Objects.isNull(scene)) { throw new TakinWebException(TakinWebExceptionEnum.LINK_VALIDATE_ERROR, - id + "对应的业务流程不存在"); + id + "对应的业务流程不存在"); } dto.setId(String.valueOf(scene.getId())); @@ -1021,18 +1030,18 @@ public BusinessFlowDto getBusinessFlowDetail(Long id) { List relates = sceneLinkRelateDAO.selectBySceneId(id); List existBusinessActiveIds = - relates.stream().map(relate -> - { - ExistBusinessActiveDto single = new ExistBusinessActiveDto(); - single.setKey(relate.getFrontUuidKey()); - single.setId(relate.getBusinessLinkId()); - return single; - }).collect(Collectors.toList()); + relates.stream().map(relate -> + { + ExistBusinessActiveDto single = new ExistBusinessActiveDto(); + single.setKey(relate.getFrontUuidKey()); + single.setId(relate.getBusinessLinkId()); + return single; + }).collect(Collectors.toList()); dto.setExistBusinessActive(existBusinessActiveIds); List roots = sceneLinkRelateDAO.listRecursion(id, WebPluginUtils.traceTenantId(), - WebPluginUtils.traceEnvCode()); + WebPluginUtils.traceEnvCode()); dto.setRoots(roots); //中间件信息 @@ -1040,7 +1049,7 @@ public BusinessFlowDto getBusinessFlowDetail(Long id) { if (CollectionUtils.isNotEmpty(techLinkIds)) { List middleWareIdStrings = tMiddlewareLinkRelateMapper.selectMiddleWareIdsByTechIds(techLinkIds); List middleWareIds = middleWareIdStrings.stream().map(Long::parseLong).collect( - Collectors.toList()); + Collectors.toList()); List middleWareEntityList = Lists.newArrayList(); if (CollectionUtils.isNotEmpty(middleWareIds)) { @@ -1084,10 +1093,10 @@ private void recordBusinessFlowLog(BusinessFlowVo vo) throws Exception { List oldSceneLinkRelateList = sceneLinkRelateDAO.selectBySceneId(Long.parseLong(vo.getId())); List oldBusinessLinkIdList = oldSceneLinkRelateList.stream().map(SceneLinkRelateResult::getBusinessLinkId).map( - Long::parseLong).collect(Collectors.toList()); + Long::parseLong).collect(Collectors.toList()); List currentSceneLinkRelateList = parsingTree(vo, Long.parseLong(vo.getId())); List currentBusinessLinkIdList = currentSceneLinkRelateList.stream().map( - SceneLinkRelateSaveParam::getBusinessLinkId).map(Long::parseLong).collect(Collectors.toList()); + SceneLinkRelateSaveParam::getBusinessLinkId).map(Long::parseLong).collect(Collectors.toList()); List toDeleteIdList = Lists.newArrayList(); toDeleteIdList.addAll(oldBusinessLinkIdList); toDeleteIdList.removeAll(currentBusinessLinkIdList); @@ -1096,25 +1105,25 @@ private void recordBusinessFlowLog(BusinessFlowVo vo) throws Exception { toAddIdList.removeAll(oldBusinessLinkIdList); String selectiveContent = ""; if (oldScene.getSceneName().equals(vo.getSceneName()) - && CollectionUtils.isEmpty(toAddIdList) - && CollectionUtils.isEmpty(toDeleteIdList)) { + && CollectionUtils.isEmpty(toAddIdList) + && CollectionUtils.isEmpty(toDeleteIdList)) { OperationLogContextHolder.ignoreLog(); } if (CollectionUtils.isNotEmpty(toAddIdList)) { List businessLinkManageTableList = tBusinessLinkManageTableMapper - .selectBussinessLinkByIdList(toAddIdList); + .selectBussinessLinkByIdList(toAddIdList); if (CollectionUtils.isNotEmpty(businessLinkManageTableList)) { String addNodeNames = businessLinkManageTableList.stream().map(BusinessLinkManageTable::getLinkName) - .collect(Collectors.joining(",")); + .collect(Collectors.joining(",")); selectiveContent = selectiveContent + "|新增节点:" + addNodeNames; } } if (CollectionUtils.isNotEmpty(toDeleteIdList)) { List businessLinkManageTableList = tBusinessLinkManageTableMapper - .selectBussinessLinkByIdList(toDeleteIdList); + .selectBussinessLinkByIdList(toDeleteIdList); if (CollectionUtils.isNotEmpty(businessLinkManageTableList)) { String deleteNodeNames = businessLinkManageTableList.stream().map(BusinessLinkManageTable::getLinkName) - .collect(Collectors.joining(",")); + .collect(Collectors.joining(",")); selectiveContent = selectiveContent + "|删除节点:" + deleteNodeNames; } } @@ -1132,13 +1141,13 @@ private void enableBusinessDelete(BusinessFlowVo vo) { } List candeleteList = oldRelates.stream() - .map(single -> - { - if (single.getBusinessLinkId() == null) { - return 0L; - } - return Long.parseLong(single.getBusinessLinkId()); - }).collect(Collectors.toList()); + .map(single -> + { + if (single.getBusinessLinkId() == null) { + return 0L; + } + return Long.parseLong(single.getBusinessLinkId()); + }).collect(Collectors.toList()); if (CollectionUtils.isEmpty(candeleteList)) { return; } @@ -1171,10 +1180,10 @@ public List cascadeMiddleWareNameAndVersion(String middleWare info.setMiddlewareType(middleWareType); } List infos = - tMiddlewareInfoMapper.selectBySelective(info); + tMiddlewareInfoMapper.selectBySelective(info); if (CollectionUtils.isNotEmpty(infos)) { Map> groupByMiddleWareName = - infos.stream().collect(Collectors.groupingBy(TMiddlewareInfo::getMiddlewareName)); + infos.stream().collect(Collectors.groupingBy(TMiddlewareInfo::getMiddlewareName)); for (Map.Entry> entry : groupByMiddleWareName.entrySet()) { MiddleWareNameDto dto = new MiddleWareNameDto(); @@ -1184,13 +1193,13 @@ public List cascadeMiddleWareNameAndVersion(String middleWare List values = entry.getValue(); if (CollectionUtils.isNotEmpty(values)) { List children = values.stream().map( - single -> { - MiddleWareVersionDto versionDto = new MiddleWareVersionDto(); - String version = single.getMiddlewareVersion(); - versionDto.setLabel(version); - versionDto.setValue(version); - return versionDto; - } + single -> { + MiddleWareVersionDto versionDto = new MiddleWareVersionDto(); + String version = single.getMiddlewareVersion(); + versionDto.setLabel(version); + versionDto.setValue(version); + return versionDto; + } ).collect(Collectors.toList()); dto.setChildren(children); } @@ -1205,7 +1214,7 @@ public List getDistinctMiddleWareName() { List result = Lists.newArrayList(); List infos = tMiddlewareInfoMapper - .selectBySelective(new TMiddlewareInfo()); + .selectBySelective(new TMiddlewareInfo()); //按照中间件类型去重 infos.forEach(single -> { @@ -1215,8 +1224,8 @@ public List getDistinctMiddleWareName() { result.add(entity); }); return result.stream() - .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>( - Comparator.comparing(MiddleWareNameDto::getLabel))), ArrayList::new)); + .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>( + Comparator.comparing(MiddleWareNameDto::getLabel))), ArrayList::new)); } @Override @@ -1229,7 +1238,7 @@ public List getMiddleWareResponses(String applicationName) { List middleWareResponses = Lists.newArrayList(); List supportList = agentPluginSupportService.queryAgentPluginSupportList(); List applicationResultList = applicationDAO.getApplicationByName( - Collections.singletonList(applicationName)); + Collections.singletonList(applicationName)); if (CollectionUtils.isEmpty(applicationResultList)) { return middleWareResponses; } @@ -1239,7 +1248,7 @@ public List getMiddleWareResponses(String applicationName) { } for (LibraryResult libraryResult : libraryResults) { MiddleWareResponse middleWareResponse = agentPluginSupportService.convertLibInfo(supportList, - libraryResult.getLibraryName()); + libraryResult.getLibraryName()); if (!Objects.isNull(middleWareResponse)) { middleWareResponses.add(middleWareResponse); } @@ -1262,15 +1271,15 @@ public List getBusinessActiveByFlowId(Long busines List sceneLinkRelates = sceneLinkRelateDAO.selectBySceneId(businessFlowId); if (CollectionUtils.isNotEmpty(sceneLinkRelates)) { List businessActivityIds = sceneLinkRelates.stream().map(o -> Long.valueOf(o.getBusinessLinkId())) - .collect(Collectors.toList()); + .collect(Collectors.toList()); List businessLinkManageTables = tBusinessLinkManageTableMapper - .selectBussinessLinkByIdList(businessActivityIds); + .selectBussinessLinkByIdList(businessActivityIds); //因为businessLinkManageTables打乱了业务活动的顺序 所以使用businessActivityIds sceneBusinessActivityRefVOS = businessActivityIds.stream().map(activityId -> { BusinessActivityNameResponse businessActivityNameResponse = new BusinessActivityNameResponse(); businessActivityNameResponse.setBusinessActivityId(activityId); BusinessLinkManageTable linkManageTable = businessLinkManageTables.stream().filter( - link -> activityId.equals(link.getLinkId())).findFirst().orElse(null); + link -> activityId.equals(link.getLinkId())).findFirst().orElse(null); if (Objects.nonNull(linkManageTable)) { businessActivityNameResponse.setBusinessActivityName(linkManageTable.getLinkName()); businessActivityNameResponse.setType(linkManageTable.getType()); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/WhiteListServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/WhiteListServiceImpl.java index ef2eb45dea..a0b517afd5 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/WhiteListServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/linkmanage/impl/WhiteListServiceImpl.java @@ -568,16 +568,9 @@ public PageInfo queryWhitelist(WhiteListQueryVO vo) { // 重名白名单 List existWhite = getExistWhite(armdString, Lists.newArrayList()); + //去掉白名单中的权限限制,只留手工和非手工的 for (WhiteListVO dto : resList) { - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); if (dto.getIsDbValue()) { - if (CollectionUtils.isEmpty(allowUpdateUserIdList)) { - //管理员 - dto.setCanEdit(true); - } else { - //普通用户 - dto.setCanEdit(allowUpdateUserIdList.contains(dto.getUserId())); - } //手动新增的白名单才能编辑 if (dto.getIsHandwork() == null) { dto.setIsHandwork(true); @@ -594,13 +587,7 @@ public PageInfo queryWhitelist(WhiteListQueryVO vo) { // 补充标签 dto.setTags(getTags(existWhite, dto)); - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); if (dto.getIsDbValue()) { - if (CollectionUtils.isEmpty(allowDeleteUserIdList)) { - dto.setCanRemove(true); - } else { - dto.setCanRemove(allowDeleteUserIdList.contains(dto.getUserId())); - } // 非手工,不允许编辑 if (!dto.getIsHandwork()) { dto.setCanEdit(false); @@ -609,10 +596,6 @@ public PageInfo queryWhitelist(WhiteListQueryVO vo) { dto.setCanRemove(false); } - List allowEnableDisableUserIdList = WebPluginUtils.getEnableDisableAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowEnableDisableUserIdList)) { - dto.setCanEnableDisable(allowEnableDisableUserIdList.contains(dto.getUserId())); - } } PageInfo whiteListDtoPageInfo = new PageInfo<>(resList); whiteListDtoPageInfo.setTotal(totalResult.size()); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pradar/impl/PradarConfigServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pradar/impl/PradarConfigServiceImpl.java index 96af7a78d8..59cb9656d6 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pradar/impl/PradarConfigServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pradar/impl/PradarConfigServiceImpl.java @@ -1,17 +1,23 @@ package io.shulie.takin.web.biz.service.pradar.impl; import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson.JSON; import io.shulie.takin.common.beans.page.PagingList; import io.shulie.takin.web.biz.constant.BizOpConstants; +import io.shulie.takin.web.biz.nacos.NacosConfigManager; import io.shulie.takin.web.biz.pojo.request.pradar.PradarZkConfigCreateRequest; import io.shulie.takin.web.biz.pojo.request.pradar.PradarZkConfigDeleteRequest; import io.shulie.takin.web.biz.pojo.request.pradar.PradarZKConfigQueryRequest; import io.shulie.takin.web.biz.pojo.request.pradar.PradarZkConfigUpdateRequest; import io.shulie.takin.web.biz.pojo.response.pradar.PradarZKConfigResponse; import io.shulie.takin.web.biz.service.pradar.PradarConfigService; -import io.shulie.takin.web.biz.utils.ZkHelper; +import io.shulie.takin.web.biz.utils.PradarConfigPusher; import io.shulie.takin.web.common.context.OperationLogContextHolder; import io.shulie.takin.web.common.util.DataTransformUtil; import io.shulie.takin.web.data.dao.pradar.PradarZkConfigDAO; @@ -32,20 +38,31 @@ public class PradarConfigServiceImpl implements PradarConfigService { private PradarZkConfigDAO pradarZkConfigDAO; @Autowired - private ZkHelper zkHelper; + private PradarConfigPusher pradarConfigPusher; @Override public void initZooKeeperData() { // 放入zk,只放入系统的 + if (pradarConfigPusher.useNaocsForConfigCenter()) { + pradarConfigPusher.pushConfigToNacos(buildNacosConfigs()); + return; + } for (PradarZkConfigResult config : pradarZkConfigDAO.list()) { this.processZk(config.getZkPath(), config.getValue()); } } + private Map buildNacosConfigs() { + List configResults = pradarZkConfigDAO.list(); + Map values = new HashMap<>(); + configResults.stream().forEach(result -> values.put(result.getZkPath(), result.getValue())); + return values; + } + @Override public PagingList page(PradarZKConfigQueryRequest queryRequest) { PagingList page = pradarZkConfigDAO.page(WebPluginUtils.SYS_DEFAULT_TENANT_ID, - WebPluginUtils.SYS_DEFAULT_ENV_CODE, queryRequest); + WebPluginUtils.SYS_DEFAULT_ENV_CODE, queryRequest); if (page.getTotal() == 0) { return PagingList.empty(); } @@ -64,7 +81,7 @@ public void updateConfig(PradarZkConfigUpdateRequest updateRequest) { // 记录日志 OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_NAME, config.getZkPath()); - OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_VALUE,updateRequest.getValue()); + OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_VALUE, updateRequest.getValue()); } } @@ -82,8 +99,8 @@ public void addConfig(PradarZkConfigCreateRequest createRequest) { this.processZk(zkPath, createRequest.getValue()); // 记录日志 - OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_NAME,createRequest.getZkPath()); - OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_VALUE,createRequest.getValue()); + OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_NAME, createRequest.getZkPath()); + OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_VALUE, createRequest.getValue()); } } @@ -93,9 +110,13 @@ public void deleteConfig(PradarZkConfigDeleteRequest deleteRequest) { PradarZkConfigResult config = pradarZkConfigDAO.getById(deleteRequest.getId()); Assert.notNull(config, "配置不存在!"); if (pradarZkConfigDAO.deleteById(deleteRequest.getId())) { - zkHelper.deleteNode(config.getZkPath()); + if(pradarConfigPusher.useNaocsForConfigCenter()){ + pradarConfigPusher.pushConfigToNacos(buildNacosConfigs()); + }else{ + pradarConfigPusher.deleteNode(config.getZkPath()); + } // 记录日志 - OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_NAME,config.getZkPath()); + OperationLogContextHolder.addVars(BizOpConstants.Vars.CONFIG_NAME, config.getZkPath()); } } @@ -103,15 +124,19 @@ public void deleteConfig(PradarZkConfigDeleteRequest deleteRequest) { * 处理 zk * * @param zkPath zk 路径 - * @param value 值 + * @param value 值 */ private void processZk(String zkPath, String value) { + if(pradarConfigPusher.useNaocsForConfigCenter()){ + pradarConfigPusher.pushConfigToNacos(buildNacosConfigs()); + return; + } // 如果zk存在, 更新值 - if (zkHelper.isNodeExists(zkPath)) { - zkHelper.updateNode(zkPath, value); + if (pradarConfigPusher.isNodeExists(zkPath)) { + pradarConfigPusher.updateNode(zkPath, value); } else { // 不存在, 插入 - zkHelper.addPersistentNode(zkPath, value); + pradarConfigPusher.addPersistentNode(zkPath, value); } } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/FinishStatusEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/FinishStatusEnum.java new file mode 100644 index 0000000000..9f734ab99a --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/FinishStatusEnum.java @@ -0,0 +1,38 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 9:48 AM + */ +public enum FinishStatusEnum { + NO(0, "未开始"), + START_ING(1, "进行中"), + FINSH(2, "完成"); + + int code; + String name; + + FinishStatusEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public int getCode() { + return code; + } + + public String getName() { + return name; + } + + public static String getName(int code) { + FinishStatusEnum[] isolateTypeEnums = FinishStatusEnum.values(); + for (FinishStatusEnum isolateTypeEnum : isolateTypeEnums) { + if (isolateTypeEnum.getCode() == (code)) { + return isolateTypeEnum.getName(); + } + } + return FinishStatusEnum.NO.getName(); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceAppService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceAppService.java new file mode 100644 index 0000000000..f5ad3f8b58 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceAppService.java @@ -0,0 +1,37 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceAppInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceAppRequest; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceRelateAppVO; + +/** + * 压测资源配置 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +public interface PressureResourceAppService { + /** + * 应用检查列表查询 + * + * @param request + * @return + */ + PagingList appCheckList(PressureResourceAppRequest request); + + /** + * 修改 + */ + void update(PressureResourceAppInput input); + + /** + * 处理忽略应用 + * + * @param joinFlag + * @param resourceId + * @param appName + */ + void processIgnoreApp(Integer joinFlag, Long resourceId, String appName); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceCommandService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceCommandService.java new file mode 100644 index 0000000000..073e3b1db8 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceCommandService.java @@ -0,0 +1,20 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.biz.service.pressureresource.vo.agent.command.*; + +/** + * @author guann1n9 + * @date 2022/9/14 10:57 AM + */ +public interface PressureResourceCommandService { + + /** + * 下发命令并更新数据库 + * @param commandTaskVo + * @return + */ + void pushCommand(CommandTaskVo commandTaskVo); + + void processAck(TakinAck pressureResourceAck); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceCommonService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceCommonService.java new file mode 100644 index 0000000000..3317f66da9 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceCommonService.java @@ -0,0 +1,71 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceDetailInput; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; + +import java.util.List; + +/** + * 压测资源配置 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +public interface PressureResourceCommonService { + /** + * 自动处理压测准备 + */ + void processAutoPressureResource(); + + /** + * 自动处理压测准备-关联应用-数据库-表 + */ + void processAutoPressureResourceRelate(PressureResourceEntity resource); + + /** + * 自动处理压测准备-远程调用自动梳理 + */ + void processAutoPressureResourceRelate_remoteCall(PressureResourceEntity resource); + + /** + * 推送变更到Redis + * + * @param resoureIds + */ + void pushRedis(Long... resoureIds); + + /** + * 推送变更到Redis + * + * @param taskVo + */ + void pushRedisCommand(CommandTaskVo taskVo); + + /** + * 删除数据 + * + * @param taskVo + */ + void deleteCommandTask(CommandTaskVo taskVo); + + /** + * 从Redis里面获取数据 + */ + List getTaskFormRedis(); + + /** + * 从Redis里面获取数据 + */ + List getResourceIdsFormRedis(); + + /** + * 修改以后同步数据源相关到应用里面 + * + * @param resouceId + */ + void syncDs(Long resouceId); + + void processNotify(List detailInputs); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceDsService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceDsService.java new file mode 100644 index 0000000000..5c1184ef07 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceDsService.java @@ -0,0 +1,64 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateDsInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateDsRequest; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceRelateDsVO; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; + +/** + * 压测资源配置-数据源 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +public interface PressureResourceDsService { + /** + * 数据源新增 + */ + void add(PressureResourceRelateDsInput input); + + /** + * 通过数据源Id获取dsKey + */ + String getDsKey(Long dsId); + + /** + * 数据源新增 + */ + void update(PressureResourceRelateDsInput input); + + /** + * 数据源删除 + */ + void del(Long dsId); + + /** + * 数据源视图页面 + */ + PagingList listByDs(PressureResourceRelateDsRequest request); + + /** + * 应用视图页面 + */ + PagingList listByApp(PressureResourceRelateDsRequest request); + + /** + * 导入 + * + * @param file + * @param resouceId + */ + void importDsConfig(MultipartFile file, Long resouceId); + + /** + * 导出 + * + * @param response + * @param resourceId + */ + void export(HttpServletResponse response, Long resourceId); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceMqConsumerService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceMqConsumerService.java new file mode 100644 index 0000000000..0c89d69eb9 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceMqConsumerService.java @@ -0,0 +1,51 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceMqConsumerCreateInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceMqConsumerQueryRequest; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceMqComsumerVO; + +/** + * 压测资源配置 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +public interface PressureResourceMqConsumerService { + /** + * 分页 + * + * @param request + * @return + */ + PagingList list(PressureResourceMqConsumerQueryRequest request); + + /** + * 创建影子消费者 + * + * @param input + */ + void create(PressureResourceMqConsumerCreateInput input); + + /** + * 创建影子消费者 + * + * @param input + */ + void update(PressureResourceMqConsumerCreateInput input); + + /** + * 创建影子消费者 + * + * @param input + */ + void processConsumerTag(PressureResourceMqConsumerCreateInput input); + + /** + * 删除 + * + * @param id + */ + void delete(Long id); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceRemoteCallService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceRemoteCallService.java new file mode 100644 index 0000000000..5d79678eee --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceRemoteCallService.java @@ -0,0 +1,45 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.*; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceRelateRemoteCallVO; + +/** + * 压测资源配置-远程调用 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +public interface PressureResourceRemoteCallService { + /** + * 分页 + * + * @param request + * @return + */ + PagingList pageList(PressureResourceRelateRemoteCallRequest request); + + /** + * 修改 + * + * @param mockInput + */ + void update_v2(PressureResourceMockInput mockInput); + + /** + * 获取服务响应时间 + * + * @param id + * @return + */ + MockDetailVO mockDetail(Long id); + + /** + * 获取服务响应时间 + * + * @param mockInfo + * @return + */ + PressureResourceCheckVO check(MockInfo mockInfo); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceService.java new file mode 100644 index 0000000000..8e0142ce10 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceService.java @@ -0,0 +1,94 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceIsolateInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceQueryRequest; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceExtInfo; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceInfoVO; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceProcessStatusVO; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceVO; + +import java.util.Map; + +/** + * 压测资源配置 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +public interface PressureResourceService { + /** + * 新增 + * + * @param input + */ + void add(PressureResourceInput input); + + /** + * 新增 + * + * @param id + */ + void delete(Long id); + + + /** + * 修改 + * + * @param input + */ + void update(PressureResourceInput input); + + /** + * 分页 + * + * @param request + * @return + */ + PagingList list(PressureResourceQueryRequest request); + + /** + * 详情查询 + * + * @param request + * @return + */ + PressureResourceInfoVO detail(PressureResourceQueryRequest request); + + /** + * 修改数据隔离方式 + * + * @param isolateInput + */ + void updateIsolate(PressureResourceIsolateInput isolateInput); + + /** + * 处理进度 + * + * @return + */ + Map progress(Long id); + + /** + * 处理汇总信息-应用 + * + * @return + */ + PressureResourceExtInfo appInfo(Long id); + + /** + * 处理汇总信息-数据源 + * + * @return + */ + PressureResourceExtInfo dsInfo(Long id); + + /** + * 处理汇总信息-影子消费者 + * + * @return + */ + PressureResourceExtInfo mqInfo(Long id); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceTableService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceTableService.java new file mode 100644 index 0000000000..06dd0fa668 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/PressureResourceTableService.java @@ -0,0 +1,44 @@ +package io.shulie.takin.web.biz.service.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateTableInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateTableRequest; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceRelateTableVO; + +/** + * 压测资源配置-数据源 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +public interface PressureResourceTableService { + /** + * 数据源新增 + */ + void save_v2(PressureResourceRelateTableInput input); + + /** + * 更新 + * + * @param updateInput + */ + void update_v2(PressureResourceRelateTableInput updateInput); + + /** + * 批量新增或取消 + * + * @param updateInput + */ + void batchUpdate(PressureResourceRelateTableInput updateInput); + + void delete_v2(Long id); + + /** + * 分页 + * + * @param request + * @return + */ + PagingList pageList_v2(PressureResourceRelateTableRequest request); +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/CheckStatusEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/CheckStatusEnum.java new file mode 100644 index 0000000000..68ad4b29d5 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/CheckStatusEnum.java @@ -0,0 +1,38 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 9:48 AM + */ +public enum CheckStatusEnum { + CHECK_NO(0, "未检测"), + CHECK_ING(1, "检测中"), + CHECK_FIN(2, "检测完成"); + + int code; + String name; + + CheckStatusEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public int getCode() { + return code; + } + + public String getName() { + return name; + } + + public static String getName(int code) { + CheckStatusEnum[] isolateTypeEnums = CheckStatusEnum.values(); + for (CheckStatusEnum isolateTypeEnum : isolateTypeEnums) { + if (isolateTypeEnum.getCode() == (code)) { + return isolateTypeEnum.getName(); + } + } + return CheckStatusEnum.CHECK_NO.getName(); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/DataSourceUtil.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/DataSourceUtil.java new file mode 100644 index 0000000000..0393e84238 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/DataSourceUtil.java @@ -0,0 +1,17 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import com.pamirs.takin.common.util.MD5Util; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/7 3:56 PM + */ +public class DataSourceUtil { + public static String generateDsKey_ext(String businessDatabase, String userName) { + String key = String.format("%s-%s", + businessDatabase, userName); + return MD5Util.getMD5(key); + } + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/DbNameUtil.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/DbNameUtil.java new file mode 100644 index 0000000000..699e71a021 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/DbNameUtil.java @@ -0,0 +1,34 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import org.apache.commons.lang3.StringUtils; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 5:13 PM + */ +public class DbNameUtil { + /** + * 获取解析库名 + * + * @param url + * @return + */ + public static String getDbName(String url) { + if (StringUtils.isBlank(url)) { + return ""; + } + if (url.lastIndexOf("/") > 0) { + url = url.substring(url.lastIndexOf("/") + 1); + } + if (url.indexOf("?") > 0) { + url = url.substring(0, url.indexOf("?")); + } + return url; + } + + public static void main(String[] args) { + System.out.println(getDbName("jdbc:mysql://127.0.0.1/trodb?useUnicode=true")); + System.out.println(getDbName("jdbc:mysql://127.0.0.1/trodb")); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/IsolateTypeEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/IsolateTypeEnum.java new file mode 100644 index 0000000000..a397b059c4 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/IsolateTypeEnum.java @@ -0,0 +1,60 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import com.pamirs.takin.common.enums.ds.DsTypeEnum; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 9:48 AM + */ +public enum IsolateTypeEnum { + DEFAULT(0, "无"), + SHADOW_DB(1, "影子库"), + SHADOW_DB_TABLE(2, "影子库-影子表"), + SHADOW_TABLE(3, "影子表"); + + int code; + String name; + + IsolateTypeEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public int getCode() { + return code; + } + + public String getName() { + return name; + } + + public static String getName(int code) { + IsolateTypeEnum[] isolateTypeEnums = IsolateTypeEnum.values(); + for (IsolateTypeEnum isolateTypeEnum : isolateTypeEnums) { + if (isolateTypeEnum.getCode() == (code)) { + return isolateTypeEnum.getName(); + } + } + return IsolateTypeEnum.DEFAULT.getName(); + } + + private static String keyPre = "隔离方案-"; + + public static String getKeyName(int code) { + return keyPre + getName(code); + } + + public static int convertDsType(Integer isolateType) { + if (isolateType == SHADOW_DB.getCode()) { + return DsTypeEnum.SHADOW_DB.getCode(); + } + if (isolateType == SHADOW_DB_TABLE.getCode()) { + return DsTypeEnum.SHADOW_REDIS_SERVER.getCode(); + } + if (isolateType == SHADOW_TABLE.getCode()) { + return DsTypeEnum.SHADOW_TABLE.getCode(); + } + throw new RuntimeException("未有配置值,请检查隔离类型{}"); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/JoinFlagEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/JoinFlagEnum.java new file mode 100644 index 0000000000..cf59213568 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/JoinFlagEnum.java @@ -0,0 +1,37 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 9:48 AM + */ +public enum JoinFlagEnum { + YES(0, "加入"), + NO(1, "未加入"); + + int code; + String name; + + JoinFlagEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public int getCode() { + return code; + } + + public String getName() { + return name; + } + + public static String getName(int code) { + JoinFlagEnum[] isolateTypeEnums = JoinFlagEnum.values(); + for (JoinFlagEnum isolateTypeEnum : isolateTypeEnums) { + if (isolateTypeEnum.getCode() == (code)) { + return isolateTypeEnum.getName(); + } + } + return JoinFlagEnum.YES.getName(); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/ModuleEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/ModuleEnum.java new file mode 100644 index 0000000000..8b1bed275f --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/ModuleEnum.java @@ -0,0 +1,24 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 9:48 AM + */ +public enum ModuleEnum { + ALL("ALL"), + APP("APP"), + DS("DS"), + REMOTECALL("REMOTECALL"), + MQ("MQ"); + + String code; + + ModuleEnum(String code) { + this.code = code; + } + + public String getCode() { + return code; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/MqTypeEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/MqTypeEnum.java new file mode 100644 index 0000000000..2af3c739ef --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/MqTypeEnum.java @@ -0,0 +1,45 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import org.springframework.util.StringUtils; + +/** + * @author guann1n9 + * @date 2022/10/17 7:15 PM + */ +public enum MqTypeEnum { + + /** + * + */ + SF_KAKFA("KAFKA-其他"), + + KAFKA("KAFKA"), + + ROCKETMQ("ROCKETMQ"), + + RABBITMQ("RABBITMQ"); + + private String code; + + MqTypeEnum(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + + public static MqTypeEnum getByCode(String code){ + if(!StringUtils.hasText(code)){ + return null; + } + for (MqTypeEnum value : MqTypeEnum.values()) { + if(value.getCode().equals(code)){ + return value; + } + } + return null; + } + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PassEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PassEnum.java new file mode 100644 index 0000000000..61647fe7c5 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PassEnum.java @@ -0,0 +1,44 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 9:48 AM + */ +public enum PassEnum { + PASS_YES(0, "是"), + PASS_NO(1, "否"); + + int code; + String name; + + PassEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public int getCode() { + return code; + } + + public String getName() { + return name; + } + + public static List defaultPass = Arrays.asList("httpclient5", "jdk-http", "okhttpv3"); + + public static int defaultPass(String middlewareName) { + if (StringUtils.isBlank(middlewareName)) { + return PASS_NO.getCode(); + } + if (defaultPass.contains(middlewareName.toLowerCase())) { + return PASS_YES.getCode(); + } + return PASS_NO.getCode(); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PressureResourceTypeEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PressureResourceTypeEnum.java new file mode 100644 index 0000000000..588f379a94 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PressureResourceTypeEnum.java @@ -0,0 +1,51 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import org.springframework.util.StringUtils; + +/** + * @author guann1n9 + * @date 2022/9/14 6:52 PM + */ +public enum PressureResourceTypeEnum { + + /** + * 数据库 + */ + DATABASE("pressure_database"), + + /** + * 白名单 + */ + WHITELIST("pressure_whitelist"), + + /** + * 影子消费者 + */ + MQ("pressure_mq"); + + + private String code; + + + PressureResourceTypeEnum(String code) { + this.code = code; + } + + + public String getCode() { + return code; + } + + + public static PressureResourceTypeEnum getByCode(String code){ + if(!StringUtils.hasText(code)){ + return null; + } + for (PressureResourceTypeEnum value : PressureResourceTypeEnum.values()) { + if(value.getCode().equals(code)){ + return value; + } + } + return null; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PtUtils.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PtUtils.java new file mode 100644 index 0000000000..e272a6edd6 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/PtUtils.java @@ -0,0 +1,27 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import org.apache.commons.lang3.StringUtils; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/8 11:43 AM + */ +public class PtUtils { + public static boolean isShadow(String var) { + if (StringUtils.isBlank(var)) { + return false; + } + if (var.toUpperCase().startsWith("PT")) { + return true; + } + return false; + } + + public static String shadowTable(String table) { + if (StringUtils.isBlank(table)) { + return table; + } + return String.format("PT_%s", table); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/RemoteCallUtil.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/RemoteCallUtil.java new file mode 100644 index 0000000000..c96e3d7cdd --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/RemoteCallUtil.java @@ -0,0 +1,46 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +import com.alibaba.fastjson.JSON; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MockInfo; +import org.apache.commons.lang3.StringUtils; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/21 11:45 AM + */ +public class RemoteCallUtil { + /** + * 转换 + * "label": "未配置", + * "value": "0", + * "label": "白名单", + * "value": "1", + * "label": "Groovy脚本mock", + * "value": "2", + * "label": "转发mock", + * "value": "3", + * "label": "返回值mock", + * "value": "4", + * + * @return + */ + public static Integer getType(String mockReturnValue, Integer pass) { + // 优先匹配mock 假如存在mock的话,判断是什么mock值 + if (StringUtils.isNotBlank(mockReturnValue)) { + MockInfo mockInfo = JSON.parseObject(mockReturnValue, MockInfo.class); + // json格式 + if ("0".equals(mockInfo.getType())) { + return 4; // 返回值mock + } + if ("1".equals(mockInfo.getType())) { + return 2; // Groovy脚本mock + } + } + // 有设置是否通过,而且是未通过的情况,且mock没有值,则为未配置 + if (pass != null && pass == PassEnum.PASS_YES.getCode()) { + return 1; // 白名单 + } + return 0; // 未配置 + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/SourceTypeEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/SourceTypeEnum.java new file mode 100644 index 0000000000..5cdfee0ce1 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/SourceTypeEnum.java @@ -0,0 +1,23 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 3:43 PM + */ +public enum SourceTypeEnum { + MANUAL(0, "手工新增"), + AUTO(1, "系统自动"); + + private int code; + private String desc; + + SourceTypeEnum(int code, String desc) { + this.code = code; + this.desc = desc; + } + + public int getCode() { + return code; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/StatusEnum.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/StatusEnum.java new file mode 100644 index 0000000000..d86c230870 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/StatusEnum.java @@ -0,0 +1,38 @@ +package io.shulie.takin.web.biz.service.pressureresource.common; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/6 9:48 AM + */ +public enum StatusEnum { + NO(0, "未检测"), + FAIL(1, "检测失败"), + SUCCESS(2, "检测成功"); + + int code; + String name; + + StatusEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public int getCode() { + return code; + } + + public String getName() { + return name; + } + + public static String getName(int code) { + StatusEnum[] isolateTypeEnums = StatusEnum.values(); + for (StatusEnum isolateTypeEnum : isolateTypeEnums) { + if (isolateTypeEnum.getCode() == (code)) { + return isolateTypeEnum.getName(); + } + } + return StatusEnum.NO.getName(); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/CharSequenceJavaFileObject.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/CharSequenceJavaFileObject.java new file mode 100644 index 0000000000..8905dab901 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/CharSequenceJavaFileObject.java @@ -0,0 +1,27 @@ +package io.shulie.takin.web.biz.service.pressureresource.common.dy; + +import javax.tools.SimpleJavaFileObject; +import java.io.IOException; +import java.net.URI; + +public class CharSequenceJavaFileObject extends SimpleJavaFileObject { + + //表示java源代码 + private CharSequence content; + + protected CharSequenceJavaFileObject(String className, String content) { + super(URI.create("string:///" + className.replaceAll("\\.", "/") + Kind.SOURCE.extension), Kind.SOURCE); + this.content = content; + } + + /** + * 获取需要编译的源代码 + * @param ignoreEncodingErrors + * @return + * @throws IOException + */ + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return content; + } +} \ No newline at end of file diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/ClassFileManager.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/ClassFileManager.java new file mode 100644 index 0000000000..866a08ef42 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/ClassFileManager.java @@ -0,0 +1,47 @@ +package io.shulie.takin.web.biz.service.pressureresource.common.dy; + +import javax.tools.FileObject; +import javax.tools.ForwardingJavaFileManager; +import javax.tools.JavaFileManager; +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.security.SecureClassLoader; + +public class ClassFileManager extends ForwardingJavaFileManager { + + /** + * 存储编译后的代码数据 + */ + private JavaClassObject classJavaFileObject; + + protected ClassFileManager(JavaFileManager fileManager) { + super(fileManager); + } + + /** + * 编译后加载类 + *

+ * 返回一个匿名的SecureClassLoader: + * 加载由JavaCompiler编译后,保存在ClassJavaFileObject中的byte数组。 + */ + @Override + public ClassLoader getClassLoader(Location location) { + return new SecureClassLoader() { + @Override + protected Class findClass(String name) throws ClassNotFoundException { + byte[] bytes = classJavaFileObject.getBytes(); + return super.defineClass(name, bytes, 0, bytes.length); + } + }; + } + + /** + * 给编译器提供JavaClassObject,编译器会将编译结果写进去 + */ + @Override + public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { + this.classJavaFileObject = new JavaClassObject(className, kind); + return this.classJavaFileObject; + } + +} \ No newline at end of file diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DyClass.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DyClass.java new file mode 100644 index 0000000000..8c505e95c9 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DyClass.java @@ -0,0 +1,9 @@ +package io.shulie.takin.web.biz.service.pressureresource.common.dy; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/20 2:09 PM + */ +public class DyClass { +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DynamicCompiler.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DynamicCompiler.java new file mode 100644 index 0000000000..9da023895a --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DynamicCompiler.java @@ -0,0 +1,71 @@ +package io.shulie.takin.web.biz.service.pressureresource.common.dy; + +import javax.tools.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class DynamicCompiler { + private static JavaFileManager fileManager; + + public DynamicCompiler() { + this.fileManager = initManger(); + } + + private JavaFileManager initManger() { + if (fileManager != null) { + return fileManager; + } else { + JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); + DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); + fileManager = new ClassFileManager(javaCompiler.getStandardFileManager(diagnosticCollector, null, null)); + return fileManager; + } + } + + /** + * 编译源码并加载,获取Class对象 + * + * @param fullName + * @param sourceCode + * @return + * @throws ClassNotFoundException + */ + public Class compileAndLoad(String fullName, String sourceCode) throws ClassNotFoundException { + JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); + List javaFileObjectList = new ArrayList(); + javaFileObjectList.add(new CharSequenceJavaFileObject(fullName, sourceCode)); + boolean result = javaCompiler.getTask(null, fileManager, null, null, null, javaFileObjectList).call(); + if (result) { + return this.fileManager.getClassLoader(null).loadClass(fullName); + } else { + return Class.forName(fullName); + } + } + + /** + * 编译源码并加载,获取Class对象 + * + * @param fullName + * @param sourceCode + * @return + * @throws ClassNotFoundException + */ + public static boolean compile(String fullName, String sourceCode) throws ClassNotFoundException { + JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); + List javaFileObjectList = new ArrayList<>(); + javaFileObjectList.add(new CharSequenceJavaFileObject(fullName, sourceCode)); + boolean result = javaCompiler.getTask(null, fileManager, null, null, null, javaFileObjectList).call(); + return result; + } + + /** + * 关闭fileManager + * + * @throws IOException + */ + public void closeFileManager() throws IOException { + this.fileManager.close(); + } + +} \ No newline at end of file diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DynamicCompilerUtil.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DynamicCompilerUtil.java new file mode 100644 index 0000000000..0115b71479 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/DynamicCompilerUtil.java @@ -0,0 +1,67 @@ +package io.shulie.takin.web.biz.service.pressureresource.common.dy; + +import javax.tools.*; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +public class DynamicCompilerUtil { + public static void main(String[] args) throws Exception { + check("import com.example.demo.entity.User ;\nUser user = new User()\nuser.setName(\"挡板\");\nreturn user ;"); + } + + public static String check(String source) throws ClassNotFoundException { + JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); + DiagnosticCollector collector = new DiagnosticCollector<>(); + StandardJavaFileManager standardJavaFileManager = javaCompiler.getStandardFileManager(null, null, null); + JavaFileObject testFile = generateTest(source); + Iterable classes = Arrays.asList(testFile); + javaCompiler.getTask(null, standardJavaFileManager, collector, null, null, classes).call(); + List> diagnostics = collector.getDiagnostics(); + String rs = ""; + for (Diagnostic diagnostic : diagnostics) { + String msg = diagnostic.getMessage(Locale.ENGLISH); + if (msg.contains("类DyClass是公共的")) { + continue; + } + if (msg.contains("程序包") && msg.contains("不存在")) { + continue; + } + if (msg.contains("找不到符号")) { + continue; + } + rs = msg; + } + return rs; + } + + private static JavaFileObject generateTest(String source) { + String[] values = source.split("\n"); + StringBuilder src = new StringBuilder(); + src.append("package io.shulie.takin.web.biz.service.pressureresource.common.dy;\n"); + StringBuilder body = new StringBuilder(); + body.append("public class DyClass {\n"); + body.append("public String dyMethod() {\n"); + for (int i = 0; i < values.length; i++) { + if (values[i].trim().startsWith("import")) { + src.append(values[i]).append("\n"); + } else { + body.append(values[i]).append("\n"); + } + } + body.append("}\n"); + body.append("}\n"); + src.append(body); + StringObject so = null; + try { + String fullName = "io.shulie.takin.web.biz.service.pressureresource.common.dy.DyClass"; + so = new StringObject(fullName, src.toString()); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + return so; + + } +} \ No newline at end of file diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/JavaClassObject.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/JavaClassObject.java new file mode 100644 index 0000000000..2496f93409 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/JavaClassObject.java @@ -0,0 +1,45 @@ +package io.shulie.takin.web.biz.service.pressureresource.common.dy; + +import javax.tools.SimpleJavaFileObject; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URI; + +/** + * 存储编译后的字节码 + */ +public class JavaClassObject extends SimpleJavaFileObject { + + /** + * Compiler编译后的byte数据会存在这个ByteArrayOutputStream对象中, + * 后面可以取出,加载到JVM中。 + */ + private ByteArrayOutputStream byteArrayOutputStream; + + public JavaClassObject(String className, Kind kind) { + super(URI.create("string:///" + className.replaceAll("\\.", "/") + kind.extension), kind); + this.byteArrayOutputStream = new ByteArrayOutputStream(); + } + + /** + * 覆盖父类SimpleJavaFileObject的方法。 + * 该方法提供给编译器结果输出的OutputStream。 + * + * 编译器完成编译后,会将编译结果输出到该 OutputStream 中,我们随后需要使用它获取编译结果 + * + * @return + * @throws IOException + */ + @Override + public OutputStream openOutputStream() throws IOException { + return this.byteArrayOutputStream; + } + + /** + * FileManager会使用该方法获取编译后的byte,然后将类加载到JVM + */ + public byte[] getBytes() { + return this.byteArrayOutputStream.toByteArray(); + } +} \ No newline at end of file diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/StringObject.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/StringObject.java new file mode 100644 index 0000000000..2d7cc19d62 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/common/dy/StringObject.java @@ -0,0 +1,20 @@ +package io.shulie.takin.web.biz.service.pressureresource.common.dy; + +import javax.tools.SimpleJavaFileObject; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +public class StringObject extends SimpleJavaFileObject { + private String content = null; + + protected StringObject(String className, String contents) throws URISyntaxException { + super(new URI(className), Kind.SOURCE); + this.content = contents; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return content; + } +} \ No newline at end of file diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceAppServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceAppServiceImpl.java new file mode 100644 index 0000000000..7a04f1d3ab --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceAppServiceImpl.java @@ -0,0 +1,242 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import com.pamirs.takin.entity.domain.vo.ApplicationVo; +import io.shulie.takin.cloud.common.bean.scenemanage.SceneManageQueryBean; +import io.shulie.takin.cloud.data.dao.scene.manage.SceneManageDAO; +import io.shulie.takin.cloud.data.model.mysql.SceneManageEntity; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceAppInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceAppRequest; +import io.shulie.takin.web.biz.service.ApplicationService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceAppService; +import io.shulie.takin.web.biz.service.pressureresource.common.JoinFlagEnum; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceRelateAppVO; +import io.shulie.takin.web.biz.service.scenemanage.SceneManageService; +import io.shulie.takin.web.common.common.Response; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; +import io.shulie.takin.web.data.dao.SceneExcludedApplicationDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDetailDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateAppDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateAppMapper; +import io.shulie.takin.web.data.model.mysql.SceneExcludedApplicationEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceDetailEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateAppEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceAppQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDetailQueryParam; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +@Service +public class PressureResourceAppServiceImpl implements PressureResourceAppService { + private static Logger logger = LoggerFactory.getLogger(PressureResourceAppServiceImpl.class); + + @Resource + private SceneManageService sceneManageService; + + @Resource + private PressureResourceRelateAppDAO pressureResourceRelateAppDAO; + + @Resource + private PressureResourceDetailDAO pressureResourceDetailDAO; + + @Resource + private PressureResourceRelateAppMapper pressureResourceRelateAppMapper; + + @Resource + private ApplicationService applicationService; + + @Resource + private PressureResourceMapper pressureResourceMapper; + + @Resource + private SceneManageDAO sceneManageDAO; + + @Resource + private SceneExcludedApplicationDAO sceneExcludedApplicationDAO; + + @Resource + @Qualifier("simpleFutureThreadPool") + private ThreadPoolExecutor simpleFutureThreadPool; + + /** + * 应用检查列表 + * + * @param request + * @return + */ + @Override + public PagingList appCheckList(PressureResourceAppRequest request) { + // 校验Resource + PressureResourceEntity resourceEntity = pressureResourceMapper.selectById(request.getResourceId()); + if (resourceEntity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "配置未查询到"); + } + PressureResourceAppQueryParam param = new PressureResourceAppQueryParam(); + BeanUtils.copyProperties(request, param); + if (StringUtils.isNotBlank(request.getEntry())) { + param.setDetailId(Long.valueOf(request.getEntry())); + } + PagingList pageList = pressureResourceRelateAppDAO.pageList(param); + if (pageList.isEmpty()) { + return PagingList.of(Collections.emptyList(), pageList.getTotal()); + } + //转换下 + List source = pageList.getList(); + // 批量下应用状态 + List> futureList = Lists.newArrayList(); + source.stream().forEach(config -> { + CompletableFuture future = CompletableFuture.supplyAsync(() -> { + Long appId = applicationService.queryApplicationIdByAppName(config.getAppName()); + if (appId == null) { + logger.error("应用名Id为空{}", config.getAppName()); + ApplicationVo vo = new ApplicationVo(); + vo.setApplicationName(config.getAppName()); + return vo; + } + // 这里接口比较慢,并行去查 + Response voResponse = applicationService.getApplicationInfo(String.valueOf(appId)); + if (voResponse.getSuccess()) { + return voResponse.getData(); + } else { + logger.error("查询应用信息失败{}", config.getAppName()); + } + ApplicationVo vo = new ApplicationVo(); + vo.setApplicationName(config.getAppName()); + return vo; + }, simpleFutureThreadPool); + futureList.add(future); + }); + CompletableFuture cfAll = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[futureList.size()])); + CompletableFuture> listCompletableFuture = cfAll.thenApply(v -> futureList.stream().map(rs -> { + try { + return rs.get(); + } catch (Throwable e) { + logger.error("等待结果失败 {}", ExceptionUtils.getStackTrace(e)); + } + ApplicationVo vo = new ApplicationVo(); + vo.setApplicationName("default"); + return vo; + }).collect(Collectors.toList())); + final Map> appMap = listCompletableFuture.join().stream().collect(Collectors.groupingBy(ApplicationVo::getApplicationName)); + List returnList = source.stream().map(configDto -> { + PressureResourceRelateAppVO vo = new PressureResourceRelateAppVO(); + BeanUtils.copyProperties(configDto, vo); + // 设置主表隔离方式 + vo.setIsolateType(resourceEntity.getIsolateType()); + // 默认是0 + vo.setAgentNodeNum(0); + vo.setNodeNum(0); + // 默认不正常 + vo.setStatus(1); + vo.setId(String.valueOf(configDto.getId())); + // 获取应用信息 + ApplicationVo applicationVo = appMap.get(vo.getAppName()).stream().findFirst().get(); + vo.setNodeNum(applicationVo.getNodeNum() == null ? 0 : applicationVo.getNodeNum()); + vo.setAgentNodeNum(applicationVo.getOnlineNodeNum() == null ? 0 : applicationVo.getOnlineNodeNum()); + vo.setStatus("0".equals(String.valueOf(applicationVo.getAccessStatus())) ? 0 : 1); + vo.setRemark(applicationVo.getExceptionInfo()); + vo.setApplicationId(String.valueOf(applicationVo.getId())); + + // 未假如的话忽略 + if (configDto.getJoinPressure() == JoinFlagEnum.NO.getCode()) { + vo.setStatus(null); + } + return vo; + }).collect(Collectors.toList()); + return PagingList.of(returnList, pageList.getTotal()); + } + + /** + * 修改检查应用信息 + * + * @param input + */ + @Override + public void update(PressureResourceAppInput input) { + // 校验数据是否存在 + Long relationAppId = input.getId(); + if (relationAppId == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + PressureResourceRelateAppEntity entity = pressureResourceRelateAppMapper.selectById(relationAppId); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "未查询到指定数据"); + } + + PressureResourceRelateAppEntity updateEntity = new PressureResourceRelateAppEntity(); + updateEntity.setId(input.getId()); + if (input.getJoinPressure() != null) { + updateEntity.setJoinPressure(input.getJoinPressure()); + this.processIgnoreApp(updateEntity.getJoinPressure(), entity.getResourceId(), entity.getAppName()); + } + if (input.getNodeNum() != null) { + updateEntity.setNodeNum(input.getNodeNum()); + } + updateEntity.setGmtModified(new Date()); + pressureResourceRelateAppMapper.updateById(updateEntity); + } + + @Override + public void processIgnoreApp(Integer joinFlag, Long resourceId, String appName) { + // 通过ResouceId读取流程 + PressureResourceEntity resourceEntity = pressureResourceMapper.selectById(resourceId); + Long flowId = resourceEntity.getSourceId(); + if (flowId == null) { + return; + } + // 通过流程查询绑定的场景 + SceneManageQueryBean sceneManageQueryBean = new SceneManageQueryBean(); + sceneManageQueryBean.setBusinessFlowId(flowId); + List sceneManageEntityList = sceneManageDAO.queryScene(sceneManageQueryBean); + // 当不需要加入压测范围的时候,修改压测场景的忽略应用 + if (joinFlag.intValue() == JoinFlagEnum.NO.getCode()) { + if (CollectionUtils.isNotEmpty(sceneManageEntityList)) { + sceneManageEntityList.stream().forEach(sceneManageEntity -> { + // 忽略检测的应用 + Long appId = applicationService.queryApplicationIdByAppName(appName); + SceneExcludedApplicationEntity tmp = sceneExcludedApplicationDAO.query(sceneManageEntity.getId(), appId); + if (tmp == null) { + // 不存在则新增 + sceneManageService.createSceneExcludedApplication(sceneManageEntity.getId(), Arrays.asList(appId)); + } + }); + } + } + // 假如是加入压测范围的话,判断之前是否有设置到忽略应用列表 + if (joinFlag.intValue() == JoinFlagEnum.YES.getCode()) { + if (CollectionUtils.isNotEmpty(sceneManageEntityList)) { + sceneManageEntityList.stream().forEach(sceneManageEntity -> { + Long appId = applicationService.queryApplicationIdByAppName(appName); + SceneExcludedApplicationEntity tmp = sceneExcludedApplicationDAO.query(sceneManageEntity.getId(), appId); + if (tmp != null) { + // 存在则删除 + sceneExcludedApplicationDAO.removeBySceneIdAndAppId(sceneManageEntity.getId(), appId); + } + }); + } + } + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceCommandServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceCommandServiceImpl.java new file mode 100644 index 0000000000..bf65e46170 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceCommandServiceImpl.java @@ -0,0 +1,677 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.pamirs.takin.entity.domain.vo.TDictionaryVo; +import io.shulie.takin.common.beans.component.SelectVO; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.job.ResourceContextUtil; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MockInfo; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommandService; +import io.shulie.takin.web.biz.service.pressureresource.common.*; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.biz.service.pressureresource.vo.agent.command.*; +import io.shulie.takin.web.common.enums.application.AppRemoteCallConfigEnum; +import io.shulie.takin.web.common.secure.SecureUtil; +import io.shulie.takin.web.common.vo.agent.AgentRemoteCallVO; +import io.shulie.takin.web.data.dao.application.ApplicationDsManageDAO; +import io.shulie.takin.web.data.dao.application.InterfaceTypeMainDAO; +import io.shulie.takin.web.data.dao.application.RemoteCallConfigDAO; +import io.shulie.takin.web.data.dao.dictionary.DictionaryDataDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateDsDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateRemoteCallDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateTableDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateDsMapperV2; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateMqConsumerMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateTableMapperV2; +import io.shulie.takin.web.data.model.mysql.ApplicationDsManageEntity; +import io.shulie.takin.web.data.model.mysql.InterfaceTypeMainEntity; +import io.shulie.takin.web.data.model.mysql.RemoteCallConfigEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.*; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDsQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceRemoteCallQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceTableQueryParam; +import io.shulie.takin.web.ext.entity.tenant.TenantInfoExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author guann1n9 + * @date 2022/9/14 10:57 AM + */ +@Service +@Slf4j +public class PressureResourceCommandServiceImpl implements PressureResourceCommandService { + + private static final String PUSH_COMMAND_URL = "takin/command"; + + private static final String PUSH_CONFIG_URL = "takin/config"; + + @Value("${agent.manager.host}") + private String agentManagerHost; + + @Resource + private PressureResourceMapper resourceMapper; + @Resource + private PressureResourceRelateDsMapperV2 resourceRelateDsMapperV2; + @Resource + private PressureResourceRelateTableMapperV2 resourceRelateTableMapperV2; + @Resource + private PressureResourceRelateRemoteCallDAO pressureResourceRelateRemoteCallDAO; + @Resource + private PressureResourceRelateMqConsumerMapper mqConsumerMapper; + @Resource + private DictionaryDataDAO dictionaryDataDAO; + @Resource + private RemoteCallConfigDAO remoteCallConfigDAO; + @Resource + private InterfaceTypeMainDAO interfaceTypeMainDAO; + @Resource + private ApplicationDsManageDAO applicationDsManageDAO; + @Resource + private PressureResourceRelateDsDAO pressureResourceRelateDsDAO; + @Resource + private PressureResourceRelateTableDAO pressureResourceRelateTableDAO; + + /** + * 下发校验命令并更新数据库 + * + * @param taskVo + * @return + */ + @Override + public void pushCommand(CommandTaskVo taskVo) { + PressureResourceEntity resource = resourceMapper.selectById(taskVo.getResourceId()); + if (resource == null) { + return; + } + //下发数据源校验命令,校验通过后,再下发配置 + if (taskVo.getModule().equals(ModuleEnum.DS.getCode()) || taskVo.getModule().equals(ModuleEnum.ALL.getCode())) { + pushDataSourceCommands_v2(resource); + } + if (taskVo.getModule().equals(ModuleEnum.REMOTECALL.getCode()) || taskVo.getModule().equals(ModuleEnum.ALL.getCode())) { + //下发白名单配置,无需校验 + pushWhitelistConfigs(resource); + } + if (taskVo.getModule().equals(ModuleEnum.MQ.getCode()) || taskVo.getModule().equals(ModuleEnum.ALL.getCode())) { + //下发mq验证 + pushMqCommands(resource); + } + } + + + /** + * mq压测配置校验命令下发 + * + * @param resource + */ + private void pushMqCommands(PressureResourceEntity resource) { + List mqConsumerEntities = mqConsumerMapper.selectList(new QueryWrapper().lambda() + .eq(PressureResourceRelateMqConsumerEntity::getResourceId, resource.getId())); + if (CollectionUtils.isEmpty(mqConsumerEntities)) { + return; + } + + List dsManageIds = mqConsumerEntities.stream().filter(entity -> entity.getRelateDsManageId() != null).map(entity -> entity.getRelateDsManageId()).collect(Collectors.toList()); + if (!dsManageIds.isEmpty()) { + List manageEntities = applicationDsManageDAO.listByIds(dsManageIds); + Map mappings = new HashMap<>(); + manageEntities.forEach(applicationDsManageEntity -> mappings.put(applicationDsManageEntity.getId(), applicationDsManageEntity)); + + // 把application_ds_manage的属性填充到配置上 + mqConsumerEntities.stream().forEach(entity -> { + if (entity.getRelateDsManageId() != null) { + populateKafkaClusterProperties(entity, mappings.get(entity.getRelateDsManageId())); + } + }); + } + + //租户信息 + TenantInfoExt tenantInfoExt = WebPluginUtils.getTenantInfo(resource.getTenantId()); + //验证命令 + List commandList = mqConsumerEntities.stream().filter(mqConsumerEntity -> StringUtils.hasText(mqConsumerEntity.getApplicationName())) + .filter(mqConsumerEntity -> StringUtils.hasText(mqConsumerEntity.getMqType())) + .filter(mqConsumerEntity -> StringUtils.hasText(mqConsumerEntity.getTopic())) + .map(mqConsumerEntity -> mqResourceToCommand(resource, mqConsumerEntity, tenantInfoExt)) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(commandList)) { + return; + } + //下发命令 + boolean succ = sendCommand(commandList); + if (succ) { + pushCommandSuccess(resource.getId()); + } + } + + /** + * command参数转换 + * + * @return + */ + private TakinCommand mqResourceToCommand(PressureResourceEntity resource, PressureResourceRelateMqConsumerEntity mqConsumerEntity, TenantInfoExt tenantInfoExt) { + TakinCommand takinCommand = new TakinCommand(); + takinCommand.setCommandId(commandId(resource.getId(), mqConsumerEntity.getId())); + takinCommand.setAppName(mqConsumerEntity.getApplicationName()); + takinCommand.setAgentSpecification(TakinCommand.SIMULATOR_AGENT); + takinCommand.setEnvCode(resource.getEnvCode()); + takinCommand.setTenantCode(tenantInfoExt.getTenantCode()); + takinCommand.setCommandType(PressureResourceTypeEnum.MQ.getCode()); + Object config = mqResourceConfig(mqConsumerEntity); + if (Objects.isNull(config)) { + return null; + } + takinCommand.setCommandParam(JSON.toJSONString(Collections.singletonList(config))); + return takinCommand; + } + + /** + * 压测数据源命令 + * + * @param resource + * @return + */ + private void pushDataSourceCommands_v2(PressureResourceEntity resource) { + if (resource.getIsolateType() == IsolateTypeEnum.DEFAULT.getCode()) { + //未配置隔离类型 + return; + } + // 查询关联的数据源信息 + PressureResourceDsQueryParam dsQueryParam = new PressureResourceDsQueryParam(); + dsQueryParam.setResourceId(resource.getId()); + List dsEntities = pressureResourceRelateDsDAO.queryByParam_v2(dsQueryParam); + if (CollectionUtils.isEmpty(dsEntities)) { + return; + } + // 查询tables + PressureResourceTableQueryParam tableQueryParam = new PressureResourceTableQueryParam(); + tableQueryParam.setResourceId(resource.getId()); + List tmpList = pressureResourceRelateTableDAO.queryList_v2(tableQueryParam); + List tableEntities = tmpList.stream().filter(tmp -> tmp.getJoinFlag() == JoinFlagEnum.YES.getCode()).collect(Collectors.toList()); + + //appName分组 + Map> dsMap = dsEntities.stream().collect(Collectors.groupingBy(RelateDsEntity::getAppName)); + //dsKey分组 + Map> tableMap = tableEntities.stream().collect(Collectors.groupingBy(RelateTableEntity::getDsKey)); + + List list = new ArrayList<>(); + //遍历dsMap + dsMap.forEach((appName, appDsList) -> { + List collect = appDsList.stream().map(dsEntity -> { + String dsKey = DataSourceUtil.generateDsKey_ext(dsEntity.getBusinessDatabase(), dsEntity.getBusinessUserName()); + // 找到数据源和对应的表信息 + return mapping_v2(resource, dsEntity, tableMap.get(dsKey)); + }).filter(Objects::nonNull).collect(Collectors.toList()); + list.addAll(collect); + }); + //下发命令 + boolean succ = sendCommand(list); + if (succ) { + pushCommandSuccess(resource.getId()); + } + } + + private boolean sendCommand(List commandList) { + //下发命令 + String url = joinUrl(agentManagerHost, PUSH_COMMAND_URL); + String post = HttpUtil.post(url, JSON.toJSONString(commandList)); + Response response = JSON.parseObject(post, new TypeReference>() { + }); + if (response.getData() == null || !response.getData()) { + //未下发成功 下次循环触发 + return false; + } + return true; + } + + + private void pushCommandSuccess(Long resourceId) { + //更新数据库 + PressureResourceEntity update = new PressureResourceEntity(); + update.setId(resourceId); + update.setCheckStatus(CheckStatusEnum.CHECK_ING.getCode()); + resourceMapper.updateById(update); + } + + + private void pushWhitelistConfigs(PressureResourceEntity resource) { + PressureResourceRemoteCallQueryParam callQueryParam = new PressureResourceRemoteCallQueryParam(); + callQueryParam.setResourceId(resource.getId()); + PagingList pageList = pressureResourceRelateRemoteCallDAO.pageList_v2(callQueryParam); + if (pageList.isEmpty()) { + return; + } + //group by appName + Map> appMap = pageList.getList().stream().collect(Collectors.groupingBy(RelateRemoteCallEntity::getAppName)); + + TenantInfoExt tenantInfoExt = WebPluginUtils.getTenantInfo(resource.getTenantId()); + List configList = new ArrayList<>(); + //遍历dsMap + appMap.forEach((appName, remoteCallList) -> { + TakinConfig takinConfig = new TakinConfig(); + takinConfig.setConfigId(resource.getId().toString()); + takinConfig.setAppName(appName); + takinConfig.setAgentSpecification(TakinCommand.SIMULATOR_AGENT); + takinConfig.setEnvCode(resource.getEnvCode()); + takinConfig.setTenantCode(tenantInfoExt.getTenantCode()); + takinConfig.setConfigType(PressureResourceTypeEnum.WHITELIST.getCode()); + List collect = remoteCallList.stream() + .filter(remoteCallEntity -> !AppRemoteCallConfigEnum.CLOSE_CONFIGURATION.getType().equals(remoteCallEntity.getType())) + .map(this::mapping) + .filter(Objects::nonNull).collect(Collectors.toList()); + String configParam = ""; + try { + ObjectMapper mapper = new ObjectMapper(); + configParam = mapper.writeValueAsString(collect); + } catch (JsonProcessingException e) { + } + takinConfig.setConfigParam(configParam); + configList.add(takinConfig); + }); + //推送配置 + String url = joinUrl(agentManagerHost, PUSH_CONFIG_URL); + HttpUtil.post(url, JSON.toJSONString(configList)); + } + + + private AgentRemoteCallVO.RemoteCall mapping(RelateRemoteCallEntity remoteCallEntity) { + if (!StringUtils.hasText(remoteCallEntity.getServerAppName()) || remoteCallEntity.getType() == 0) { + return null; + } + List voList = dictionaryDataDAO.getDictByCode("REMOTE_CALL_TYPE"); + Map entityMap = remoteCallConfigDAO.selectToMapWithOrderKey(); + + AgentRemoteCallVO.RemoteCall remoteCall = new AgentRemoteCallVO.RemoteCall(); + remoteCall.setINTERFACE_NAME(remoteCallEntity.getInterfaceName()); + remoteCall.setTYPE(getSelectVO(remoteCallEntity.getInterfaceType(), voList).getLabel().toLowerCase()); + remoteCall.setCheckType(entityMap.get(remoteCallEntity.getType()).getCheckType()); + if (!StringUtils.hasText(remoteCallEntity.getMockReturnValue())) { + return remoteCall; + } + MockInfo mockInfo = JSON.parseObject(remoteCallEntity.getMockReturnValue(), MockInfo.class); + remoteCall.setContent(mockInfo.getMockValue()); + return remoteCall; + } + + private SelectVO getSelectVO(Integer interfaceType, List voList) { + InterfaceTypeMainEntity mainEntity = interfaceTypeMainDAO.selectByOrder(interfaceType); + if (mainEntity == null) { + String type = String.valueOf(interfaceType); + if (org.apache.commons.collections4.CollectionUtils.isEmpty(voList)) { + return new SelectVO("数据字典未找到类型", type); + } + List dictionaryVoList = voList.stream().filter(t -> type.equals(t.getValueCode())).collect(Collectors.toList()); + if (org.apache.commons.collections4.CollectionUtils.isEmpty(dictionaryVoList)) { + return new SelectVO("数据字典未找到类型", type); + } + TDictionaryVo vos = dictionaryVoList.get(0); + return new SelectVO(vos.getValueName(), type); + } else { + return new SelectVO(mainEntity.getName(), String.valueOf(mainEntity.getValueOrder())); + } + } + + + @Override + public void processAck(TakinAck takinAck) { + + String ackType = takinAck.getAckType(); + switch (ackType) { + case TakinAck.COMMAND: + //配置校验响应 + TakinCommandAck takinCommandAck = JSON.parseObject(JSON.toJSONString(takinAck.getAck()), TakinCommandAck.class); + processCommandAck(takinCommandAck); + break; + case TakinAck.CONFIG: + //配置生效响应 + TakinConfigAck takinConfigAck = JSON.parseObject(JSON.toJSONString(takinAck.getAck()), TakinConfigAck.class); + processConfigAck(takinConfigAck); + break; + default: + break; + + } + + + } + + /** + * 配置生效响应 + * + * @param configAck + */ + private void processConfigAck(TakinConfigAck configAck) { + long resourceId = Long.parseLong(configAck.getConfigId()); + PressureResourceEntity resource = resourceMapper.queryByIdNoTenant(resourceId); + if (resource == null) { + return; + } + //设置租户上下文 + ResourceContextUtil.setTenantContext(resource); + boolean success = configAck.isSuccess(); + PressureResourceTypeEnum resourceTypeEnum = PressureResourceTypeEnum.getByCode(configAck.getConfigType()); + switch (resourceTypeEnum) { + case DATABASE: + String dsResponse = success ? "配置生效" : configAck.getResponse(); + //更新ds 记录失败原因 + List dsEntities = resourceRelateDsMapperV2.selectList(new QueryWrapper().lambda() + .eq(PressureResourceRelateDsEntityV2::getResourceId, resourceId)); + dsEntities.forEach(dsEntity -> { + dsEntity.setRemark(dsEntity.getRemark() + ";" + dsResponse); + resourceRelateDsMapperV2.updateById(dsEntity); + }); + break; + case MQ: + String mqResponse = success ? "配置生效" : configAck.getResponse(); + //更新ds 记录失败原因 + List mqConsumerEntities = mqConsumerMapper.selectList(new QueryWrapper().lambda() + .eq(PressureResourceRelateMqConsumerEntity::getResourceId, resourceId)); + mqConsumerEntities.forEach(mqEntity -> { + mqEntity.setRemark(mqEntity.getRemark() + ";" + mqResponse); + mqConsumerMapper.updateById(mqEntity); + }); + break; + default: + break; + } + + } + + /** + * 压测配置校验响应处理 + * + * @param commandAck + */ + private void processCommandAck(TakinCommandAck commandAck) { + String commandId = commandAck.getCommandId(); + Long resourceId = getResourceId(commandId); + Long subId = getSubId(commandId); + + PressureResourceEntity resource = resourceMapper.queryByIdNoTenant(resourceId); + if (resource == null) { + return; + } + ResourceContextUtil.setTenantContext(resource); + + PressureResourceEntity update = new PressureResourceEntity(); + update.setId(resourceId); + update.setCheckTime(new Date()); + update.setCheckStatus(CheckStatusEnum.CHECK_FIN.getCode()); + resourceMapper.updateById(update); + //更新附属资源 + PressureResourceTypeEnum resourceTypeEnum = PressureResourceTypeEnum.getByCode(commandAck.getCommandType()); + switch (resourceTypeEnum) { + case DATABASE: + //更新ds表 + PressureResourceRelateDsEntityV2 dsEntity = resourceRelateDsMapperV2.selectById(subId); + if (dsEntity == null) { + throw new IllegalArgumentException("未找到对应的数据库资源"); + } + PressureResourceRelateDsEntityV2 updateDs = new PressureResourceRelateDsEntityV2(); + updateDs.setId(subId); + updateDs.setStatus(commandAck.isSuccess() ? 2 : 1); + updateDs.setRemark(commandAck.isSuccess() ? "影子资源连通" : commandAck.getResponse()); + resourceRelateDsMapperV2.updateById(updateDs); + + //更新table表 + String dsKey = DataSourceUtil.generateDsKey_ext(dsEntity.getBusinessDatabase(), dsEntity.getBusinessUserName()); + // 查询tables + PressureResourceTableQueryParam tableQueryParam = new PressureResourceTableQueryParam(); + tableQueryParam.setResourceId(resource.getId()); + tableQueryParam.setDsKey(dsKey); + List tmpList = pressureResourceRelateTableDAO.queryList_v2(tableQueryParam); + List tableEntities = tmpList.stream().filter(tmp -> tmp.getJoinFlag() == JoinFlagEnum.YES.getCode()).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(tableEntities)) { + tableEntities.forEach(table -> { + PressureResourceRelateTableEntityV2 v2 = new PressureResourceRelateTableEntityV2(); + v2.setId(table.getId()); + v2.setStatus(commandAck.isSuccess() ? 2 : 1); + v2.setRemark(commandAck.isSuccess() ? "影子表正确" : commandAck.getResponse()); + resourceRelateTableMapperV2.updateById(v2); + }); + } + //下发数据库配置 + if (commandAck.isSuccess()) { + pushPressureDatabaseConfig_v2(resource); + } + break; + case MQ: + PressureResourceRelateMqConsumerEntity consumerEntity = mqConsumerMapper.selectById(subId); + if (consumerEntity == null) { + throw new IllegalArgumentException("未找到对应的MQ资源"); + } + PressureResourceRelateMqConsumerEntity updateMq = new PressureResourceRelateMqConsumerEntity(); + updateMq.setId(subId); + updateMq.setStatus(commandAck.isSuccess() ? 2 : 1); + updateMq.setRemark(commandAck.isSuccess() ? "MQ资源配置正确" : commandAck.getResponse()); + mqConsumerMapper.updateById(updateMq); + //下发数据库配置 + if (commandAck.isSuccess()) { + pushPressureMqConfig(resource); + } + break; + default: + break; + } + } + + private void pushPressureMqConfig(PressureResourceEntity resource) { + //租户信息 + TenantInfoExt tenantInfoExt = WebPluginUtils.getTenantInfo(resource.getTenantId()); + + List mqConsumerEntities = mqConsumerMapper.selectList(new QueryWrapper().lambda() + .eq(PressureResourceRelateMqConsumerEntity::getResourceId, resource.getId())); + List validRecords = mqConsumerEntities.stream().filter(mqConsumerEntity -> StringUtils.hasText(mqConsumerEntity.getApplicationName())) + .filter(mqConsumerEntity -> StringUtils.hasText(mqConsumerEntity.getMqType())) + .filter(mqConsumerEntity -> StringUtils.hasText(mqConsumerEntity.getTopic())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(validRecords)) { + return; + } + //按照应用名称分组 + Map> appMap = validRecords.stream().collect(Collectors.groupingBy(PressureResourceRelateMqConsumerEntity::getApplicationName)); + List configList = new ArrayList<>(); + appMap.forEach((appName, mqList) -> { + List collect = mqList.stream().map(this::mqResourceConfig).filter(Objects::nonNull).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(collect)) { + return; + } + TakinConfig takinConfig = new TakinConfig(); + takinConfig.setConfigId(resource.getId().toString()); + takinConfig.setAppName(appName); + takinConfig.setAgentSpecification(TakinCommand.SIMULATOR_AGENT); + takinConfig.setEnvCode(resource.getEnvCode()); + takinConfig.setTenantCode(tenantInfoExt.getTenantCode()); + takinConfig.setConfigType(PressureResourceTypeEnum.MQ.getCode()); + takinConfig.setConfigParam(JSON.toJSONString(collect)); + configList.add(takinConfig); + }); + //推送配置 + String url = joinUrl(agentManagerHost, PUSH_CONFIG_URL); + HttpUtil.post(url, JSON.toJSONString(configList)); + } + + + private Object mqResourceConfig(PressureResourceRelateMqConsumerEntity mqConsumerEntity) { + MqTypeEnum mqTypeEnum = MqTypeEnum.getByCode(mqConsumerEntity.getMqType()); + switch (mqTypeEnum) { + case SF_KAKFA: + return SfKakfaConfig.mapping(mqConsumerEntity); + default: + return null; + } + } + + /** + * 校验通过,下发压测库配置 + * + * @param resource + */ + private void pushPressureDatabaseConfig_v2(PressureResourceEntity resource) { + //租户信息 + TenantInfoExt tenantInfoExt = WebPluginUtils.getTenantInfo(resource.getTenantId()); + + // 查询Resource + PressureResourceDsQueryParam dsQueryParam = new PressureResourceDsQueryParam(); + dsQueryParam.setResourceId(resource.getId()); + List dsEntities = pressureResourceRelateDsDAO.queryByParam_v2(dsQueryParam); + if (CollectionUtils.isEmpty(dsEntities)) { + return; + } + //appName分组 + Map> dsMap = dsEntities.stream().collect(Collectors.groupingBy(RelateDsEntity::getAppName)); + List configList = new ArrayList<>(); + dsMap.forEach((appName, dsList) -> { + TakinConfig takinConfig = new TakinConfig(); + takinConfig.setConfigId(resource.getId().toString()); + takinConfig.setAppName(appName); + takinConfig.setAgentSpecification(TakinCommand.SIMULATOR_AGENT); + takinConfig.setEnvCode(resource.getEnvCode()); + takinConfig.setTenantCode(tenantInfoExt.getTenantCode()); + takinConfig.setConfigType(PressureResourceTypeEnum.DATABASE.getCode()); + List collect = dsList.stream().map(dsEntity -> mapping_v2(resource.getIsolateType(), dsEntity)).collect(Collectors.toList()); + JdbcTableConfig jdbcTableConfig = new JdbcTableConfig(); + jdbcTableConfig.setData(collect); + takinConfig.setConfigParam(JSON.toJSONString(jdbcTableConfig)); + configList.add(takinConfig); + }); + //推送配置 + String url = joinUrl(agentManagerHost, PUSH_CONFIG_URL); + HttpUtil.post(url, JSON.toJSONString(configList)); + } + + private DataSourceConfig mapping_v2(Integer shadowType, RelateDsEntity dsEntity) { + DataSourceConfig dataSourceConfig = new DataSourceConfig(); + dataSourceConfig.setShadowType(shadowType); + dataSourceConfig.setUrl(dsEntity.getBusinessDatabase()); + dataSourceConfig.setUsername(dsEntity.getBusinessUserName()); + dataSourceConfig.setShadowUrl(dsEntity.getShadowDatabase()); + dataSourceConfig.setShadowUsername(dsEntity.getShadowUserName()); + dataSourceConfig.setShadowPassword(dsEntity.getShadowPassword()); + if (!shadowType.equals(IsolateTypeEnum.SHADOW_TABLE.getCode())) { + //非影子表模式 无表配置 + return dataSourceConfig; + } + String dsKey = DataSourceUtil.generateDsKey_ext(dsEntity.getBusinessDatabase(), dsEntity.getBusinessUserName()); + // 查询tables + PressureResourceTableQueryParam tableQueryParam = new PressureResourceTableQueryParam(); + tableQueryParam.setResourceId(dsEntity.getResourceId()); + tableQueryParam.setDsKey(dsKey); + List tmpList = pressureResourceRelateTableDAO.queryList_v2(tableQueryParam); + List tableEntities = tmpList.stream().filter(tmp -> tmp.getJoinFlag() == JoinFlagEnum.YES.getCode()).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(tableEntities)) { + tableEntities = tableEntities.stream().filter(it -> it.getJoinFlag() == JoinFlagEnum.YES.getCode()).collect(Collectors.toList()); + } + if (CollectionUtils.isEmpty(tableEntities)) { + dataSourceConfig.setDisabled(true); + return dataSourceConfig; + } + List bizTables = tableEntities.stream().map(RelateTableEntity::getBusinessTable).collect(Collectors.toList()); + dataSourceConfig.setBizTables(bizTables); + return dataSourceConfig; + } + + private TakinCommand mapping_v2(PressureResourceEntity resource, RelateDsEntity dsEntity, List tableEntities) { + if (!StringUtils.hasText(dsEntity.getBusinessDatabase()) + || !StringUtils.hasText(dsEntity.getBusinessUserName()) + || !StringUtils.hasText(dsEntity.getAppName())) { + return null; + } + TenantInfoExt tenantInfoExt = WebPluginUtils.getTenantInfo(resource.getTenantId()); + if (IsolateTypeEnum.SHADOW_TABLE.getCode() == resource.getIsolateType() && CollectionUtils.isEmpty(tableEntities)) { + //影子表模式无影子表 不再下发校验命令 推送禁用配置 + pushPressureDatabaseConfig_v2(resource); + return null; + } + TakinCommand takinCommand = new TakinCommand(); + takinCommand.setCommandId(commandId(resource.getId(), dsEntity.getId())); + takinCommand.setAppName(dsEntity.getAppName()); + takinCommand.setAgentSpecification(TakinCommand.SIMULATOR_AGENT); + takinCommand.setEnvCode(resource.getEnvCode()); + takinCommand.setTenantCode(tenantInfoExt.getTenantCode()); + takinCommand.setCommandType(PressureResourceTypeEnum.DATABASE.getCode()); + //命令 + JdbcTableCompareCommand tableCompareCommand = new JdbcTableCompareCommand(); + tableCompareCommand.setShadowType(resource.getIsolateType()); + DataSourceEntity bizDataSource = new DataSourceEntity(); + bizDataSource.setUrl(dsEntity.getBusinessDatabase()); + bizDataSource.setUserName(dsEntity.getBusinessUserName()); + tableCompareCommand.setBizDataSource(bizDataSource); + //影子表 + if (!CollectionUtils.isEmpty(tableEntities)) { + List tables = tableEntities.stream().map(RelateTableEntity::getBusinessTable).collect(Collectors.toList()); + tableCompareCommand.setTables(tables); + } + //影子库 + if (StringUtils.hasText(dsEntity.getShadowDatabase())) { + DataSourceEntity shadowDataSource = new DataSourceEntity(); + shadowDataSource.setUrl(dsEntity.getShadowDatabase()); + shadowDataSource.setUserName(dsEntity.getShadowUserName()); + shadowDataSource.setPassword(dsEntity.getShadowPassword()); + tableCompareCommand.setShadowDataSource(shadowDataSource); + } + takinCommand.setCommandParam(JSON.toJSONString(tableCompareCommand)); + return takinCommand; + } + + private String joinUrl(String host, String path) { + return host.endsWith("/") ? host + path : host + "/" + path; + } + + + private String commandId(Long resourceId, Long subId) { + return resourceId + "_" + subId; + } + + + private Long getResourceId(String commandId) { + String[] split = commandId.split("_"); + if (split.length != 2) { + throw new IllegalArgumentException("命令id校验失败:" + commandId); + } + return Long.parseLong(split[0]); + } + + private Long getSubId(String commandId) { + String[] split = commandId.split("_"); + if (split.length != 2) { + throw new IllegalArgumentException("命令id校验失败:" + commandId); + } + return Long.parseLong(split[1]); + } + + + private void populateKafkaClusterProperties(PressureResourceRelateMqConsumerEntity consumer, ApplicationDsManageEntity entity) { + if (entity == null) { + return; + } + JSONObject object = JSON.parseObject(SecureUtil.decrypt(entity.getParseConfig())); + consumer.setTopic(object.getString("topic")); + consumer.setBrokerAddr(object.getString("brokerAddr")); + consumer.setGroup(object.getString("group")); + consumer.setSystemIdToken(object.getString("systemIdToken")); + consumer.setTopicTokens(object.getString("topicTokens")); + + Map feature = new HashMap<>(); + feature.put("clusterName", object.getString("clusterName")); + feature.put("clusterAddr", object.getString("monitorUrl")); + feature.put("providerThreadCount", object.getInteger("poolSize")); + feature.put("messageConsumeThreadCount", object.getInteger("messageConsumeThreadCount")); + consumer.setFeature(JSON.toJSONString(feature)); + } + + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceCommonServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceCommonServiceImpl.java new file mode 100644 index 0000000000..ec7eece45d --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceCommonServiceImpl.java @@ -0,0 +1,885 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Maps; +import com.pamirs.pradar.Pradar; +import com.pamirs.takin.entity.domain.vo.ApplicationVo; +import com.pamirs.takin.entity.domain.vo.TDictionaryVo; +import io.shulie.amdb.common.dto.link.topology.AppShadowDatabaseDTO; +import io.shulie.amdb.common.dto.link.topology.LinkEdgeDTO; +import io.shulie.amdb.common.dto.link.topology.LinkNodeDTO; +import io.shulie.amdb.common.dto.link.topology.LinkTopologyDTO; +import io.shulie.amdb.common.enums.EdgeTypeEnum; +import io.shulie.amdb.common.enums.EdgeTypeGroupEnum; +import io.shulie.amdb.common.enums.NodeTypeEnum; +import io.shulie.takin.cloud.ext.content.trace.ContextExt; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.amdb.api.ApplicationClient; +import io.shulie.takin.web.amdb.api.ApplicationEntranceClient; +import io.shulie.takin.web.amdb.api.NotifyClient; +import io.shulie.takin.web.amdb.bean.common.EntranceTypeEnum; +import io.shulie.takin.web.amdb.bean.query.application.ApplicationRemoteCallQueryDTO; +import io.shulie.takin.web.amdb.bean.result.application.ApplicationRemoteCallDTO; +import io.shulie.takin.web.biz.pojo.input.application.AppRemoteCallUpdateInput; +import io.shulie.takin.web.biz.pojo.input.application.ApplicationDsCreateInputV2; +import io.shulie.takin.web.biz.pojo.request.activity.ActivityInfoQueryRequest; +import io.shulie.takin.web.biz.pojo.request.application.ApplicationEntranceTopologyQueryRequest; +import io.shulie.takin.web.biz.pojo.request.linkmanage.BusinessFlowPageQueryRequest; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MqConsumerFeature; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceDetailInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceInput; +import io.shulie.takin.web.biz.pojo.response.activity.ActivityResponse; +import io.shulie.takin.web.biz.pojo.response.application.ShadowDetailResponse; +import io.shulie.takin.web.biz.pojo.response.linkmanage.BusinessFlowListResponse; +import io.shulie.takin.web.biz.service.ActivityService; +import io.shulie.takin.web.biz.service.ApplicationService; +import io.shulie.takin.web.biz.service.ConfCenterService; +import io.shulie.takin.web.biz.service.dsManage.DsService; +import io.shulie.takin.web.biz.service.linkmanage.AppRemoteCallService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceService; +import io.shulie.takin.web.biz.service.pressureresource.common.*; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.biz.service.scene.SceneService; +import io.shulie.takin.web.common.common.Response; +import io.shulie.takin.web.common.enums.activity.BusinessTypeEnum; +import io.shulie.takin.web.common.enums.application.AppRemoteCallConfigEnum; +import io.shulie.takin.web.common.util.application.RemoteCallUtils; +import io.shulie.takin.web.data.dao.activity.ActivityDAO; +import io.shulie.takin.web.data.dao.application.AppRemoteCallDAO; +import io.shulie.takin.web.data.dao.application.InterfaceTypeChildDAO; +import io.shulie.takin.web.data.dao.dictionary.DictionaryDataDAO; +import io.shulie.takin.web.data.dao.pressureresource.*; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; +import io.shulie.takin.web.data.model.mysql.AppRemoteCallEntity; +import io.shulie.takin.web.data.model.mysql.InterfaceTypeChildEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.*; +import io.shulie.takin.web.data.param.activity.ActivityQueryParam; +import io.shulie.takin.web.data.param.application.AppRemoteCallQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDetailQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceQueryParam; +import io.shulie.takin.web.data.result.activity.ActivityListResult; +import io.shulie.takin.web.data.result.application.ApplicationDetailResult; +import io.shulie.takin.web.data.result.scene.SceneLinkRelateResult; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +@Service +public class PressureResourceCommonServiceImpl implements PressureResourceCommonService { + private static Logger logger = LoggerFactory.getLogger(PressureResourceCommonServiceImpl.class); + + @Resource + private PressureResourceService pressureResourceService; + + @Resource + private PressureResourceRelateTableDAO pressureResourceRelateTableDAO; + + @Resource + private PressureResourceRelateRemoteCallDAO pressureResourceRelateRemoteCallDAO; + + @Resource + private PressureResourceRelateMqComsumerDAO pressureResourceRelateMqComsumerDAO; + + @Resource + private PressureResourceRelateDsDAO pressureResourceRelateDsDAO; + + @Resource + private PressureResourceDetailDAO pressureResourceDetailDAO; + + @Resource + private PressureResourceDAO pressureResourceDAO; + + @Resource + private PressureResourceMapper pressureResourceMapper; + + @Resource + private PressureResourceRelateAppDAO pressureResourceRelateAppDAO; + + @Resource + private SceneService sceneService; + + @Resource + private ActivityDAO activityDao; + + @Resource + private ActivityService activityService; + + @Resource + private ApplicationEntranceClient applicationEntranceClient; + + @Resource + private NotifyClient notifyClient; + + @Resource + private ApplicationClient applicationClient; + + @Resource + private ApplicationService applicationService; + + @Resource + private DictionaryDataDAO dictionaryDataDAO; + + @Resource + private InterfaceTypeChildDAO interfaceTypeChildDAO; + + @Resource + private AppRemoteCallService appRemoteCallService; + + @Resource + private AppRemoteCallDAO appRemoteCallDAO; + + @Autowired + @Qualifier("redisTemplate") + private RedisTemplate redisTemplate; + + @Resource + @Qualifier("simpleFutureThreadPool") + private ThreadPoolExecutor simpleFutureThreadPool; + + @Autowired + private ConfCenterService confCenterService; + + private static String TAKIN_RESOURCE_MODIFY_KEY = "TAKIN:RESOURCE:MODIFY:KEY"; + + @Value("${takin.job.resource.interval:2}") + private int takinResourceInterval; + + private static final Pattern pattern = Pattern.compile("[0-9]"); + + private static final String UNKNOWN = "UNKNOWN"; + + @Resource + private DsService dsService; + + /** + * 自动处理压测资源准备任务 + */ + @Override + public void processAutoPressureResource() { + // 租户下的所有业务流程 + BusinessFlowPageQueryRequest queryRequest = new BusinessFlowPageQueryRequest(); + queryRequest.setCurrentPage(0); + queryRequest.setPageSize(1000); + if (takinResourceInterval > 0) { + queryRequest.setQueryGmtModified(DateUtil.offsetMinute(new Date(), -1 * takinResourceInterval)); + } + PagingList flowList = sceneService.getBusinessFlowList(queryRequest); + if (flowList == null || flowList.isEmpty() || CollectionUtils.isEmpty(flowList.getList())) { + logger.warn("当前租户{}下业务流程为空,暂不处理压测资源准备!!!", WebPluginUtils.traceTenantCode()); + return; + } + List responseList = flowList.getList(); + responseList.stream().forEach(flow -> { + // 业务流程Id + Long flowId = flow.getId(); + // 业务流程名称 + String sceneName = flow.getSceneName(); + PressureResourceQueryParam queryParam = new PressureResourceQueryParam(); + queryParam.setSourceId(flowId); + PagingList pageList = pressureResourceDAO.pageList(queryParam); + + PressureResourceInput pressureResourceInput = new PressureResourceInput(); + pressureResourceInput.setName(sceneName); + pressureResourceInput.setType(SourceTypeEnum.AUTO.getCode()); + pressureResourceInput.setCheckStatus(CheckStatusEnum.CHECK_NO.getCode()); + pressureResourceInput.setSourceId(flowId); + // 设置归属人 + pressureResourceInput.setUserId(flow.getUserId()); + boolean insertFlag = true; + if (!pageList.isEmpty() && !CollectionUtils.isEmpty(pageList.getList())) { + // 修改 + PressureResourceEntity tmpEntity = pageList.getList().get(0); + // 设置Id + pressureResourceInput.setId(tmpEntity.getId()); + pressureResourceInput.setUserId(tmpEntity.getUserId()); + insertFlag = false; + } + // 处理详情 + List detailInputs = Lists.newArrayList(); + + // 获取业务流程关联业务活动 + List relateResults = sceneService.getSceneLinkRelates(flowId); + if (CollectionUtils.isNotEmpty(relateResults)) { + List businessLinkIds = relateResults.stream().map(relate -> Long.valueOf(relate.getBusinessLinkId())).distinct().collect(Collectors.toList()); + ActivityQueryParam activityQueryParam = new ActivityQueryParam(); + activityQueryParam.setActivityIds(businessLinkIds); + // 查询业务活动 + List activityListResults = activityDao.getActivityList(activityQueryParam); + if (CollectionUtils.isNotEmpty(activityListResults)) { + for (int i = 0; i < activityListResults.size(); i++) { + ActivityListResult activityListResult = activityListResults.get(i); + // 查询业务活动详情 + ActivityInfoQueryRequest request = new ActivityInfoQueryRequest(); + request.setActivityId(activityListResult.getActivityId()); + ActivityResponse responseDetail = activityService.getActivityById(request); + + // 找到已经匹配的业务活动 + if (responseDetail.getBusinessType() != BusinessTypeEnum.VIRTUAL_BUSINESS.getType()) { + PressureResourceDetailInput detailInput = new PressureResourceDetailInput(); + detailInput.setAppName(responseDetail.getApplicationName()); + detailInput.setEntranceUrl(responseDetail.getServiceName()); + detailInput.setEntranceName(responseDetail.getActivityName()); + detailInput.setRpcType(responseDetail.getRpcType()); + detailInput.setMethod(responseDetail.getMethod()); + detailInput.setExtend(responseDetail.getExtend()); + detailInput.setLinkId(responseDetail.getLinkId()); + // 添加到集合中 + detailInputs.add(detailInput); + } + } + } + if (CollectionUtils.isNotEmpty(detailInputs)) { + pressureResourceInput.setDetailInputs(detailInputs); + } + } + + if (insertFlag) { + // 新增 + pressureResourceService.add(pressureResourceInput); + } else { + pressureResourceService.update(pressureResourceInput); + } + }); + } + + /** + * 通知AMDB构建链路拓扑 + * + * @param detailInputs + */ + @Override + public void processNotify(List detailInputs) { + detailInputs.stream().forEach(detail -> { + CompletableFuture.runAsync(() -> { + notifyClient.startApplicationEntrancesCalculate( + detail.getAppName(), + detail.getEntranceUrl(), + detail.getMethod(), + String.valueOf(detail.getType()), + detail.getExtend()); + }, simpleFutureThreadPool); + }); + } + + /** + * 自动梳理关联信息 + */ + @Override + public void processAutoPressureResourceRelate(PressureResourceEntity resource) { + List detailEntityList = getPressureResourceDetailList(resource.getId()); + if (CollectionUtils.isNotEmpty(detailEntityList)) { + try { + // 根据详情来处理 + for (int i = 0; i < detailEntityList.size(); i++) { + // 获取入口 + PressureResourceDetailEntity detailEntity = detailEntityList.get(i); + processRelate(detailEntity, resource); + } + } catch (Throwable e) { + logger.error(ExceptionUtils.getStackTrace(e)); + throw new RuntimeException(e); + } + } + } + + /** + * 自动梳理关联信息-远程调用单独处理 + */ + @Override + public void processAutoPressureResourceRelate_remoteCall(PressureResourceEntity resource) { + List detailEntityList = getPressureResourceDetailList(resource.getId()); + if (CollectionUtils.isNotEmpty(detailEntityList)) { + try { + List allEntitys = Lists.newArrayList(); + // 根据详情来处理 + for (int i = 0; i < detailEntityList.size(); i++) { + // 获取入口 + PressureResourceDetailEntity detailEntity = detailEntityList.get(i); + // 远程调用梳理 + List remoteCallEntityList = processRemoteCall_v2(detailEntity); + allEntitys.addAll(remoteCallEntityList); + } + if (CollectionUtils.isNotEmpty(allEntitys)) { + // 去重 + List insertList = allEntitys.stream().collect( + Collectors.collectingAndThen( + Collectors.toCollection( + () -> new TreeSet<>(Comparator.comparing(p -> p.getMd5()))), ArrayList::new)); + // 找到未添加的 + List unFindList = insertList.stream().filter(call -> !call.isFind()).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(unFindList)) { + unFindList.stream().forEach(call -> { + AppRemoteCallUpdateInput updateInput = new AppRemoteCallUpdateInput(); + Long appId = applicationService.queryApplicationIdByAppName(call.getAppName()); + updateInput.setApplicationId(appId); + updateInput.setAppName(call.getAppName()); + updateInput.setInterfaceName(call.getInterfaceName()); + updateInput.setInterfaceType(call.getInterfaceType()); + updateInput.setInterfaceChildType(call.getInterfaceChildType()); + updateInput.setType(AppRemoteCallConfigEnum.CLOSE_CONFIGURATION.getType()); + appRemoteCallService.update(updateInput); + }); + } + List findList = insertList.stream().filter(call -> call.isFind()).collect(Collectors.toList()); + pressureResourceRelateRemoteCallDAO.saveOrUpdate_v2(findList); + } + } catch (Throwable e) { + logger.error(ExceptionUtils.getStackTrace(e)); + throw new RuntimeException(e); + } + } + } + + private List getPressureResourceDetailList(Long resourceId) { + PressureResourceDetailQueryParam detailQueryParam = new PressureResourceDetailQueryParam(); + detailQueryParam.setResourceId(resourceId); + List detailEntityList = pressureResourceDetailDAO.getList(detailQueryParam); + return detailEntityList; + } + + @Override + public void pushRedis(Long... resoureIds) { + redisTemplate.opsForSet().add(TAKIN_RESOURCE_MODIFY_KEY, resoureIds); + } + + @Override + public void pushRedisCommand(CommandTaskVo taskVo) { + redisTemplate.opsForList().leftPush(TAKIN_RESOURCE_MODIFY_KEY, JSON.toJSONString(taskVo)); + } + + @Override + public void deleteCommandTask(CommandTaskVo taskVo) { + redisTemplate.opsForList().remove(TAKIN_RESOURCE_MODIFY_KEY, 0, JSON.toJSONString(taskVo)); + } + + @Override + public List getTaskFormRedis() { + List objs = redisTemplate.opsForList().range(TAKIN_RESOURCE_MODIFY_KEY, 0, -1); + if (CollectionUtils.isEmpty(objs)) { + return Collections.EMPTY_LIST; + } + return objs.stream().map(obj -> { + CommandTaskVo vo = JSON.parseObject(Objects.toString(obj), CommandTaskVo.class); + return vo; + }).collect(Collectors.toList()); + } + + @Override + public List getResourceIdsFormRedis() { + List list = Lists.newArrayList(); + try { + list = redisTemplate.opsForSet().pop(TAKIN_RESOURCE_MODIFY_KEY, 20); + if (CollectionUtils.isEmpty(list)) { + return Collections.EMPTY_LIST; + } + } catch (Throwable e) { + logger.error(ExceptionUtils.getStackTrace(e)); + } + return list; + } + + /** + * 通过链路拓扑图来处理关联应用,关联数据源,关联表 + * + * @param detailEntity + * @return + */ + private void processRelate(PressureResourceDetailEntity detailEntity, PressureResourceEntity resource) { + Long resourceId = detailEntity.getResourceId(); + // 链路拓扑图查询 + ApplicationEntranceTopologyQueryRequest request = new ApplicationEntranceTopologyQueryRequest(); + request.setApplicationName(detailEntity.getAppName()); + request.setLinkId(detailEntity.getLinkId()); + request.setMethod(detailEntity.getMethod()); + request.setRpcType(detailEntity.getRpcType()); + request.setExtend(detailEntity.getExtend()); + request.setServiceName(detailEntity.getEntranceUrl()); + request.setType(EntranceTypeEnum.getEnumByType(detailEntity.getRpcType())); + // 大数据查询拓扑图 + LinkTopologyDTO applicationEntrancesTopology = applicationEntranceClient.getApplicationEntrancesTopology( + false, request.getApplicationName(), request.getLinkId(), request.getServiceName(), request.getMethod(), + request.getRpcType(), request.getExtend(), true); + // 关联表和数据源处理 + if (applicationEntrancesTopology != null) { + // 获取应用节点 + List nodeDTOList = applicationEntrancesTopology.getNodes(); + // 处理关联应用 + List appEntityList = handleRelateApp(detailEntity, resourceId, nodeDTOList); + // 保存关联应用 + pressureResourceRelateAppDAO.saveOrUpdate(appEntityList); + + // 获取边集合 + List edgeDTOList = applicationEntrancesTopology.getEdges(); + // 隔离方案未设置,暂时不处理 + if (!(resource.getIsolateType() == IsolateTypeEnum.DEFAULT.getCode())) { + if (CollectionUtils.isEmpty(edgeDTOList)) { + return; + } + List dsCreateInputV2List = handleDsAndTable_relateAppDetail(resource, edgeDTOList, detailEntity); + + if (CollectionUtils.isNotEmpty(dsCreateInputV2List)) { + dsCreateInputV2List.stream().forEach(dsCreateInput -> { + // 同步到原始表之后,这里需要有权限控制,用应用的权限做控制 + ApplicationDetailResult appDetail = confCenterService.queryApplicationInfoById(dsCreateInput.getApplicationId()); + ContextExt contextExt = new ContextExt(); + contextExt.setUserId(appDetail.getUserId()); + WebPluginUtils.setCloudUserData(contextExt); + dsService.dsCreateConfig(dsCreateInput); + }); + } + } + // 处理影子消费者 + List mqComsuerList = handleMqConsumer(resourceId, edgeDTOList, detailEntity); + pressureResourceRelateMqComsumerDAO.saveOrUpdate(mqComsuerList); + } + } + + /** + * 处理关联应用 + * + * @param detailEntity + * @param resourceId + * @param nodeDTOList + * @return + */ + private List handleRelateApp(PressureResourceDetailEntity detailEntity, + Long resourceId, + List nodeDTOList) { + if (CollectionUtils.isEmpty(nodeDTOList)) { + return Collections.EMPTY_LIST; + } + List appNodeList = nodeDTOList.stream() + .filter(node -> { + if (node.getNodeType().equals(NodeTypeEnum.APP.getType()) && + !NodeTypeEnum.UNKNOWN.getType().equals(node.getNodeName())) { + return true; + } + return false; + }).collect(Collectors.toList()); + List appEntityList = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(appNodeList)) { + appNodeList.stream().forEach(appNode -> { + PressureResourceRelateAppEntity appEntity = new PressureResourceRelateAppEntity(); + appEntity.setAppName(appNode.getNodeName()); + appEntity.setResourceId(resourceId); + appEntity.setDetailId(detailEntity.getId()); + appEntity.setTenantId(WebPluginUtils.traceTenantId()); + appEntity.setEnvCode(WebPluginUtils.traceEnvCode()); + // 节点数默认为0 + appEntity.setNodeNum(0); + // 默认不正常 + appEntity.setStatus(1); + // 通过应用去查询状态 + Long appId = applicationService.queryApplicationIdByAppName(appEntity.getAppName()); + if (appId != null) { + Response voResponse = applicationService.getApplicationInfo(String.valueOf(appId)); + if (voResponse.getSuccess()) { + ApplicationVo applicationVo = voResponse.getData(); + appEntity.setNodeNum(applicationVo.getNodeNum() == null ? 0 : applicationVo.getNodeNum()); + appEntity.setStatus("0".equals(String.valueOf(applicationVo.getAccessStatus())) ? 0 : 1); + } + appEntity.setJoinPressure(JoinFlagEnum.YES.getCode()); + appEntity.setType(SourceTypeEnum.AUTO.getCode()); + appEntityList.add(appEntity); + } else { + + logger.warn("未查询到应用信息{} ", appEntity.getAppName()); + } + }); + } + return appEntityList; + } + + /** + * 处理影子消费者 + * + * @param resourceId + * @param edgeDTOList + * @param detailEntity + * @return + */ + private List handleMqConsumer(Long resourceId, + List edgeDTOList, + PressureResourceDetailEntity detailEntity) { + // 只要Mq消费的 + List mqEdgeList = edgeDTOList.stream().filter(edge -> { + // 目前只处理rabbitmq,rocketMq,kafka + if (edge.getEagleType().equals(EdgeTypeEnum.ROCKETMQ.getType()) + || edge.getEagleType().equals(EdgeTypeEnum.KAFKA.getType()) + || edge.getEagleType().equals(EdgeTypeEnum.RABBITMQ.getType())) { + return true; + } + return false; + }).collect(Collectors.toList()); + // 需要新增的影子消费者信息 + List mqConsumerEntityList = Lists.newArrayList(); + if (CollectionUtils.isEmpty(mqEdgeList)) { + return mqConsumerEntityList; + } + for (int i = 0; i < mqEdgeList.size(); i++) { + LinkEdgeDTO edge = mqEdgeList.get(i); + if (EdgeTypeEnum.UNKNOWN.getType().equals(edge.getAppName())) { + continue; + } + // 不是kafka的话,不处理客户端 + if (!edge.getEagleType().equals(EdgeTypeEnum.KAFKA.getType())) { + if (edge.getLogType().equals(String.valueOf(Pradar.LOG_TYPE_INVOKE_CLIENT))) { + continue; + } + } + // 影子Topic过滤掉 + String topic = edge.getService(); + if (PtUtils.isShadow(topic)) { + continue; + } + // 重试队列的也过滤掉 + if (topic.startsWith("%RETRY%")) { + continue; + } + PressureResourceRelateMqConsumerEntity mqEntity = new PressureResourceRelateMqConsumerEntity(); + mqEntity.setResourceId(resourceId); + mqEntity.setDetailId(detailEntity.getId()); + // 消费者 + mqEntity.setComsumerType(1); + mqEntity.setApplicationName(edge.getAppName()); + mqEntity.setIsCluster(1); + mqEntity.setMqType(edge.getEagleType()); + if (edge.getEagleType().equals(EdgeTypeEnum.KAFKA.getType())) { + // apache-kafka172.16.32.74:9092,172.16.32.137:9092,172.16.32.67:9092 + // kafka100.81.128.29:9092,100.81.128.30:9092,100.81.128.31:9092,100.81.128.32:9092,100.81.128.33:9092 + String serverAppName = ""; + if (edge.getLogType().equals(String.valueOf(Pradar.LOG_TYPE_INVOKE_CLIENT))) { + mqEntity.setComsumerType(0); + serverAppName = edge.getAppName(); + mqEntity.setApplicationName(edge.getServerAppName()); + } else if (edge.getLogType().equals(String.valueOf(Pradar.LOG_TYPE_INVOKE_SERVER))) { + // 消费 + mqEntity.setComsumerType(1); + // 判断下服务端是否是集群 + serverAppName = edge.getServerAppName(); + } else { + // 其他不处理 + continue; + } + if (serverAppName.contains(",")) { + // 是否集群 + mqEntity.setIsCluster(0); + // 集群地址解析出来 + MqConsumerFeature feature = new MqConsumerFeature(); + // 匹配第一个数字开头的,截取下ip地址 + Matcher matcher = pattern.matcher(serverAppName); + if (matcher.find()) { + String tmpServerAddr = serverAppName.substring(matcher.start()); + feature.setClusterAddr(tmpServerAddr); + // 设置的扩展字段中 + mqEntity.setFeature(JSON.toJSONString(feature)); + } + } + } + String group = StringUtils.isBlank(edge.getMethod()) ? "default" : edge.getMethod(); + mqEntity.setTopic(topic); + mqEntity.setGroup(group); + mqEntity.setTenantId(WebPluginUtils.traceTenantId()); + mqEntity.setEnvCode(WebPluginUtils.traceEnvCode()); + mqEntity.setGmtCreate(new Date()); + mqEntity.setConsumerTag(1); + mqEntity.setType(SourceTypeEnum.AUTO.getCode()); + mqConsumerEntityList.add(mqEntity); + } + return mqConsumerEntityList; + } + + /** + * 处理关联的数据源和table + * + * @param edgeDTOList + * @param detailEntity + * @return + */ + private List handleDsAndTable_relateAppDetail(PressureResourceEntity pressureResource, + List edgeDTOList, + PressureResourceDetailEntity detailEntity) { + // 获取所有的数据库操作信息 + List dbEdgeList = edgeDTOList.stream().filter(edge -> { + if (edge.getEagleTypeGroup().equals(EdgeTypeGroupEnum.DB.getType())) { + return true; + } + return false; + }).collect(Collectors.toList()); + + // 存储影子库表集合 + List dsCreateInputV2List = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(dbEdgeList)) { + // 按照URL分组,app#ds + Map> serviceMap = dbEdgeList.stream().collect(Collectors.groupingBy(dbEdge -> fetchKey(dbEdge))); + for (Map.Entry> entry : serviceMap.entrySet()) { + String key = entry.getKey(); + String appName = key.split("#")[0]; + String database = key.split("#")[1]; + if ("null".equals(appName)) { + continue; + } + // 库名 + String dbName = DbNameUtil.getDbName(database); + if (PtUtils.isShadow(dbName)) { + continue; + } + ApplicationDsCreateInputV2 dsCreateInputV2 = new ApplicationDsCreateInputV2(); + dsCreateInputV2.setResourceId(pressureResource.getId()); + dsCreateInputV2.setDetailId(detailEntity.getId()); + dsCreateInputV2.setTenantId(WebPluginUtils.traceTenantId()); + dsCreateInputV2.setEnvCode(WebPluginUtils.traceEnvCode()); + dsCreateInputV2.setType(1); + // 从任意的边里面获取数据源详情信息 + LinkEdgeDTO edgeDTO = entry.getValue().get(0); + List dsList = edgeDTO.getDsList(); + if (CollectionUtils.isEmpty(dsList)) { + logger.warn("应用数据源未梳理完成,{}", database); + } else { + // 业务数据源相关信息 + AppShadowDatabaseDTO appShadowDatabaseDTO = dsList.get(0); + dsCreateInputV2.setUsername(appShadowDatabaseDTO.getTableUser()); + dsCreateInputV2.setConnectionPool(appShadowDatabaseDTO.getConnectionPool()); + dsCreateInputV2.setMiddlewareType(appShadowDatabaseDTO.getMiddlewareType()); + } + // 通过应用名获取应用Id + Long appId = applicationService.queryApplicationIdByAppName(appName); + if (appId == null) { + logger.warn("应用名{}对应的应用Id不存在", appName); + continue; + } + dsCreateInputV2.setApplicationId(appId); + dsCreateInputV2.setApplicationName(appName); + dsCreateInputV2.setUrl(database); + dsCreateInputV2.setDsType(IsolateTypeEnum.convertDsType(pressureResource.getIsolateType())); + + List value = entry.getValue(); + // 没有设置隔离类型的话,暂时不处理关联表信息,减少没必要的数据梳理 + if (CollectionUtils.isNotEmpty(value) + && pressureResource.getIsolateType() == IsolateTypeEnum.SHADOW_TABLE.getCode()) { + List tableInfoList = Lists.newArrayList(); + for (int k = 0; k < value.size(); k++) { + // 存在逗号分割的数据 + String method = value.get(k).getMethod(); + if (StringUtils.isBlank(method)) { + continue; + } + String[] tables = method.split(","); + for (int j = 0; j < tables.length; j++) { + String tableName = tables[j]; + // 过滤掉影子的表 + if (PtUtils.isShadow(tableName)) { + continue; + } + if (StringUtils.isBlank(tableName)) { + logger.warn("链路梳理结果错误,表信息未梳理 {}", pressureResource.getId()); + continue; + } + // 影子表扩展信息 + ShadowDetailResponse.TableInfo tableInfo = new ShadowDetailResponse.TableInfo(); + tableInfo.setResourceId(pressureResource.getId()); + tableInfo.setDetailId(detailEntity.getId()); + tableInfo.setBizTableName(tableName); + // 系统自动处理影子表 + tableInfo.setShaDowTableName(PtUtils.shadowTable(tableName)); + tableInfo.setBizDatabase(dbName); + tableInfo.setIsManual(false); + tableInfo.setIsCheck(false); + + tableInfoList.add(tableInfo); + } + } + + // 设置影子库表 + if (CollectionUtils.isNotEmpty(tableInfoList)) { + Map shaDowTaleInfo = Maps.newHashMap(); + shaDowTaleInfo.put("shaDowTaleInfo", JSON.toJSONString(tableInfoList)); + dsCreateInputV2.setExtInfo(JSON.toJSONString(shaDowTaleInfo)); + } + } + dsCreateInputV2List.add(dsCreateInputV2); + } + } + return dsCreateInputV2List; + } + + /** + * 处理关联的远程调用信息 + * + * @param detailEntity + * @return + */ + private List processRemoteCall_v2(PressureResourceDetailEntity detailEntity) { + // 通过linkId去查询远程调用 + ApplicationRemoteCallQueryDTO callQueryDTO = new ApplicationRemoteCallQueryDTO(); + callQueryDTO.setLinkId(detailEntity.getLinkId()); + callQueryDTO.setQueryTye("2"); + callQueryDTO.setPageSize(1000); + callQueryDTO.setCurrentPage(0); + PagingList pageList = applicationClient.listApplicationRemoteCalls(callQueryDTO); + if (pageList.isEmpty()) { + return Collections.emptyList(); + } + // 获取所有应用 + List appIds = Lists.newArrayList(); + pageList.getList().stream().forEach(call -> { + Long appId = applicationService.queryApplicationIdByAppName(call.getAppName()); + call.setAppId(appId); + appIds.add(appId); + }); + + // 通过服务查询本地的远程调用信息 + AppRemoteCallQueryParam queryParam = new AppRemoteCallQueryParam(); + queryParam.setApplicationIds(appIds); + List appRemoteCallEntityList = appRemoteCallDAO.getRemoteCallMd5_ext(queryParam); + Map> md5Map = appRemoteCallEntityList.stream().collect(Collectors.groupingBy(AppRemoteCallEntity::getMd5)); + + // 数据字段增加后,也在枚举中增加下 + List voList = dictionaryDataDAO.getDictByCode("REMOTE_CALL_TYPE"); + Map childEntityMap = interfaceTypeChildDAO.selectToMapWithNameKey(); + List list = pageList.getList(); + // 保存 + List callEntityList = list.stream().map(item -> { + PressureResourceRelateRemoteCallEntityV2 callEntity = new PressureResourceRelateRemoteCallEntityV2(); + callEntity.setResourceId(detailEntity.getResourceId()); + callEntity.setDetailId(detailEntity.getId()); + callEntity.setAppName(item.getAppName()); + callEntity.setStatus(StatusEnum.NO.getCode()); + callEntity.setPass(PassEnum.PASS_NO.getCode()); + callEntity.setRpcId(item.getRpcId()); + callEntity.setInterfaceName(RemoteCallUtils.getInterfaceNameByRpcName(item.getMiddlewareName(), item.getServiceName(), item.getMethodName())); + callEntity.setInterfaceType(appRemoteCallService.getInterfaceType(item.getMiddlewareName(), voList)); + if (!childEntityMap.containsKey(item.getMiddlewareDetail())) { + callEntity.setInterfaceChildType(item.getMiddlewareName()); + } else { + callEntity.setInterfaceChildType(item.getMiddlewareDetail()); + } + callEntity.setMd5(RemoteCallUtils.buildRemoteCallName(callEntity.getAppName(), callEntity.getInterfaceName(), callEntity.getInterfaceType())); + callEntity.setManualTag(0); + callEntity.setTenantId(WebPluginUtils.traceTenantId()); + callEntity.setEnvCode(WebPluginUtils.traceEnvCode()); + // 通过服务查询本地的远程调用信息 + String md5 = RemoteCallUtils.buildRemoteCallName(callEntity.getAppName(), callEntity.getInterfaceName(), callEntity.getInterfaceType()); + List md5List = md5Map.get(md5); + callEntity.setPass(PassEnum.defaultPass(callEntity.getInterfaceChildType())); + callEntity.setFind(false); + if (CollectionUtils.isNotEmpty(md5List)) { + // 是否放行 - 调用方和非调用方为非http类型的,默认自动放行,开关:开;其余的为关 + // 0 http 2 feign 1 double + if (callEntity.getInterfaceType() != 0 || callEntity.getInterfaceType() != 2) { + callEntity.setPass(PassEnum.PASS_YES.getCode()); + } + // 已经找到调用,加个标识,后续直接查询 + callEntity.setFind(true); + } + callEntity.setStatus(CheckStatusEnum.CHECK_NO.getCode()); + // 设置检测状态,放行的默认不检测,状态默认为检测成功 + if (callEntity.getPass() == PassEnum.PASS_YES.getCode()) { + callEntity.setStatus(CheckStatusEnum.CHECK_FIN.getCode()); + } + return callEntity; + }).collect(Collectors.toList()); + return callEntityList; + } + + // 应用+数据源 + private String fetchKey(LinkEdgeDTO dbEdge) { + return dbEdge.getServerAppName() + "#" + dbEdge.getService(); + } + + /** + * 同步修改数据源配置到应用上 + * + * @param resouceId + */ + @Override + public void syncDs(Long resouceId) { + // 读取resourceId + PressureResourceEntity resourceEntity = pressureResourceMapper.selectById(resouceId); + // 判断隔离方式 + if (resourceEntity == null) { + return; + } + int isolateType = resourceEntity.getIsolateType().intValue(); + if (isolateType == IsolateTypeEnum.DEFAULT.getCode()) { + logger.warn("{}格式方式未设置,暂不同步", resourceEntity.getName()); + return; + } + // 影子库 + if (isolateType == IsolateTypeEnum.SHADOW_DB_TABLE.getCode()) { + processShadowDatabase(resourceEntity); + } + } + + /** + * 同步影子库 + * + * @param resourceEntity + */ + private void processShadowDatabase(PressureResourceEntity resourceEntity) { + // 1、查询影子库信息 + //Long resourceId = resourceEntity.getId(); + //PressureResourceDsQueryParam dsQueryParam = new PressureResourceDsQueryParam(); + //dsQueryParam.setResourceId(resourceId); + //List dsList = pressureResourceRelateDsDAO.queryByParam(dsQueryParam); + //// 处理应用关联的数据源 + //if (CollectionUtils.isEmpty(dsList)) { + // return; + //} + //// 按应用分组 + //Map> dsAppNameMap = dsList.stream() + // .filter(ds -> StringUtils.isNotBlank(ds.getAppName())) + // .collect(Collectors.groupingBy(PressureResourceRelateDsEntity::getAppName)); +// + //List appShadowDatabaseDTOList = Lists.newArrayList(); + //for (Map.Entry> entry : dsAppNameMap.entrySet()) { + // // 根据应用名查询应用Id + // ApplicationDetailResult applicationDetailResult = applicationService.queryTApplicationMntByName(entry.getKey()); + // List tmpDsList = entry.getValue(); + // for (int i = 0; i < tmpDsList.size(); i++) { + // PressureResourceRelateDsEntity dsEntity = dsList.get(i); + // AppShadowDatabaseDTO appShadowDatabaseDTO = new AppShadowDatabaseDTO(); + // appShadowDatabaseDTO.setAppName(dsEntity.getAppName()); + // appShadowDatabaseDTO.setConnectionPool(dsEntity.getMiddlewareName()); + // appShadowDatabaseDTO.setMiddlewareType(dsEntity.getMiddlewareType()); + // appShadowDatabaseDTO.setDataSource(dsEntity.getBusinessDatabase()); + // appShadowDatabaseDTO.setTableUser(dsEntity.getBusinessUserName()); + // appShadowDatabaseDTO.setShadowDataSource(dsEntity.getShadowDatabase()); + // appShadowDatabaseDTO.setType("_2"); + // appShadowDatabaseDTOList.add(appShadowDatabaseDTO); + // } +// + // ApplicationDsQueryParam queryParam = new ApplicationDsQueryParam(); + // queryParam.setApplicationId(applicationDetailResult.getApplicationId()); + // queryParam.setSourceId(resourceId); + // queryParam.setIsDeleted(0); + // WebPluginUtils.fillQueryParam(queryParam); + // //filterAndSave(appShadowDatabaseDTOList, applicationDetailResult.getApplicationId(), queryParam); + //} + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceDsServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceDsServiceImpl.java new file mode 100644 index 0000000000..f7fec3e528 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceDsServiceImpl.java @@ -0,0 +1,569 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import cn.hutool.core.collection.ListUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.ExtInfo; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateDsInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateDsRequest; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateTableInput; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceDsService; +import io.shulie.takin.web.biz.service.pressureresource.common.*; +import io.shulie.takin.web.biz.service.pressureresource.vo.*; +import io.shulie.takin.web.biz.utils.xlsx.ExcelUtils; +import io.shulie.takin.web.common.enums.ContextSourceEnum; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; +import io.shulie.takin.web.common.vo.excel.ExcelSheetVO; +import io.shulie.takin.web.data.dao.application.ApplicationDsDbManageDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateAppDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateDsDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateTableDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateDsMapperV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.*; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceAppQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDsQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceTableQueryParam; +import io.shulie.takin.web.data.result.application.ApplicationDsDbManageDetailResult; +import io.shulie.takin.web.ext.entity.tenant.TenantInfoExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.mortbay.util.ajax.JSON; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/31 7:37 PM + */ +@Service +public class PressureResourceDsServiceImpl implements PressureResourceDsService { + private static Logger logger = LoggerFactory.getLogger(PressureResourceDsServiceImpl.class); + + @Resource + private PressureResourceRelateDsDAO pressureResourceRelateDsDAO; + + @Resource + private PressureResourceRelateTableDAO pressureResourceRelateTableDAO; + + private PressureResourceRelateDsMapperV2 pressureResourceRelateDsMapperV2; + + @Resource + private PressureResourceMapper pressureResourceMapper; + + @Resource + private PressureResourceRelateAppDAO pressureResourceRelateAppDAO; + + @Autowired + private ApplicationDsDbManageDAO dbManageDAO; + + /** + * 新增 + * + * @param input + */ + @Override + public void add(PressureResourceRelateDsInput input) { + // 批量给拆分到不同应用里面去,应用视角需要分页查询 + List appNames = input.getRelationApps(); + if (CollectionUtils.isEmpty(appNames)) { + return; + } + // 判断数据源是否已存在 + PressureResourceDsQueryParam param = new PressureResourceDsQueryParam(); + param.setBussinessDatabase(input.getBusinessDatabase()); + param.setResourceId(input.getResourceId()); + List list = null;//pressureResourceRelateDsDAO.queryByParam(param); + if (CollectionUtils.isNotEmpty(list)) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "数据源已存在"); + } + List dsEntitys = appNames.stream().map(appName -> { + PressureResourceRelateDsEntityV2 tmpEntity = new PressureResourceRelateDsEntityV2(); + + BeanUtils.copyProperties(input, tmpEntity); + tmpEntity.setAppName(appName); + tmpEntity.setGmtCreate(new Date()); + + ExtInfo extInfo = input.getExtInfo(); + //tmpEntity.setExtInfo(JSON.toString(extInfo)); + return tmpEntity; + }).collect(Collectors.toList()); + //pressureResourceRelateDsDAO.add(dsEntitys); + } + + @Override + public String getDsKey(Long dsId) { + PressureResourceRelateDsEntityV2 entity = pressureResourceRelateDsMapperV2.selectById(dsId); + return "";//DataSourceUtil.generateDsKey(entity.getResourceId(), entity.getBusinessDatabase()); + } + + @Override + public void update(PressureResourceRelateDsInput input) { + if (input.getId() == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + // 判断是否存在 + PressureResourceRelateDsEntityV2 entity = null;//pressureResourceRelateDsMapper.selectById(input.getId()); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "未查询到指定数据"); + } + + PressureResourceRelateDsEntityV2 updateEntity = new PressureResourceRelateDsEntityV2(); + updateEntity.setId(input.getId()); + updateEntity.setStatus(input.getStatus()); + updateEntity.setBusinessDatabase(input.getBusinessDatabase()); + updateEntity.setBusinessUserName(input.getBusinessUserName()); + //updateEntity.setShadowDatabase(input.getShadowDatabase()); + //updateEntity.setShadowUserName(input.getShadowUserName()); + //updateEntity.setShadowPassword(input.getShadowPassword()); + //updateEntity.set + } + + /** + * 删除 + * + * @param dsId + */ + @Override + public void del(Long dsId) { + if (dsId == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "参数ID未传递!"); + } + PressureResourceRelateDsEntityV2 v2 = pressureResourceRelateDsMapperV2.selectById(dsId); + if (v2 != null) { + ApplicationDsDbManageDetailResult detailResult = dbManageDAO.selectOneById(v2.getRelateId()); + pressureResourceRelateDsMapperV2.deleteById(v2.getId()); + // 关联的数据源也删除掉 + if (detailResult != null) { + dbManageDAO.removeRecord(v2.getRelateId()); + } + } + } + + /** + * 数据源视图页面,内存分页 + * + * @param request + * @return + */ + @Override + public PagingList listByDs(PressureResourceRelateDsRequest request) { + // 查询所有的数据源信息 + PressureResourceDsQueryParam param = new PressureResourceDsQueryParam(); + param.setResourceId(request.getResourceId()); + param.setStatus(request.getStatus()); + // 数据源模糊查询 + param.setQueryBussinessDatabase(request.getQueryBusinessDataBase()); + + List dsList = pressureResourceRelateDsDAO.queryByParam_v2(param); + // 相同数据源合并 + List listVO = Lists.newArrayList(); + Map> dsMap = dsList.stream().filter(app -> StringUtils.isNotBlank(app.getAppName())) + .collect(Collectors.groupingBy(ds -> + DataSourceUtil.generateDsKey_ext(ds.getBusinessDatabase(), ds.getBusinessUserName()))); + + for (Map.Entry> entry : dsMap.entrySet()) { + List tmpList = entry.getValue(); + List appNames = tmpList.stream().map(ds -> ds.getAppName()).collect(Collectors.toList()); + PressureResourceRelateDsVO tmpVO = new PressureResourceRelateDsVO(); + tmpVO.setAppList(Collections.EMPTY_LIST); + BeanUtils.copyProperties(tmpList.get(0), tmpVO); + tmpVO.setDatabase(DbNameUtil.getDbName(tmpList.get(0).getBusinessDatabase())); + // 这里的Id是数据源+用户名 + tmpVO.setDsKey(entry.getKey()); + + tmpVO.setResourceId(String.valueOf(tmpList.get(0).getResourceId())); + if (StringUtils.isNotBlank(tmpVO.getBusinessDatabase())) { + String bussinessDatabase = tmpVO.getBusinessDatabase(); + tmpVO.setDatabase(DbNameUtil.getDbName(bussinessDatabase)); + } + // 通过应用获取是否加入压测范围 + PressureResourceAppQueryParam appQueryParam = new PressureResourceAppQueryParam(); + appQueryParam.setAppNames(appNames); + appQueryParam.setResourceId(request.getResourceId()); + List appEntitys = pressureResourceRelateAppDAO.queryList(appQueryParam); + if (CollectionUtils.isNotEmpty(appEntitys)) { + Map> appMap = appEntitys.stream() + .collect(Collectors.groupingBy(app -> app.getAppName())); + List appVOList = appNames.stream() + .map(app -> { + PressureResourceRelateAppVO appVO = new PressureResourceRelateAppVO(); + appVO.setAppName(app); + appVO.setJoinPressure(JoinFlagEnum.NO.getCode()); + if (appMap.containsKey(app)) { + appVO.setJoinPressure(appMap.get(app).get(0).getJoinPressure()); + } + return appVO; + }).collect(Collectors.toList()); + tmpVO.setAppList(appVOList); + } + tmpVO.setSize(tmpList.size()); + listVO.add(tmpVO); + } + List pageList = ListUtil.page(request.getCurrentPage(), request.getPageSize(), listVO); + return PagingList.of(pageList, listVO.size()); + } + + /** + * 应用视图 + * + * @param request + * @return + */ + @Override + public PagingList listByApp(PressureResourceRelateDsRequest request) { + // 查询所有的数据源信息 + PressureResourceDsQueryParam param = new PressureResourceDsQueryParam(); + param.setResourceId(request.getResourceId()); + param.setQueryAppName(request.getQueryAppName()); + List dsList = pressureResourceRelateDsDAO.queryByParam_v2(param); + // 相同数据源合并 + List listVO = Lists.newArrayList(); + Map> appMap = dsList.stream().collect(Collectors.groupingBy(ds -> ds.getAppName())); + for (Map.Entry> entry : appMap.entrySet()) { + List tmpList = entry.getValue(); + PressureResourceRelateDsVO tmpVO = new PressureResourceRelateDsVO(); + BeanUtils.copyProperties(tmpList.get(0), tmpVO); + tmpVO.setId(String.valueOf(tmpList.get(0).getId())); + tmpVO.setResourceId(String.valueOf(tmpList.get(0).getResourceId())); + List dsVOList = tmpList.stream().map(ds -> { + PressureResourceDsVO tmpDs = new PressureResourceDsVO(); + tmpDs.setBusinessDataBase(ds.getBusinessDatabase()); + tmpDs.setStatus(ds.getStatus()); + return tmpDs; + }).collect(Collectors.toList()); + + tmpVO.setDsList(dsVOList); + tmpVO.setSize(tmpList.size()); + listVO.add(tmpVO); + } + List pageList = ListUtil.page(request.getCurrentPage(), request.getPageSize(), listVO); + return PagingList.of(pageList, listVO.size()); + } + + /** + * 导入数据源配置 + * + * @param file + * @param resourceId + */ + @Override + public void importDsConfig(MultipartFile file, Long resourceId) { + String originalFilename = file.getOriginalFilename(); + if (StringUtils.isBlank(originalFilename)) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_CONFIG_FILE_VALIDATE_ERROR, "文件不存在!"); + } + if (!originalFilename.endsWith(".xlsx")) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, + "文件格式不正确,必须为xlsx格式文件,请重新导出配置文件!"); + } + // 简单校验 + PressureResourceEntity resourceEntity = pressureResourceMapper.selectById(resourceId); + if (resourceEntity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "资源配置未获取到"); + } + // 读取xlsx文件 + Map>> stringArrayListHashMap = ExcelUtils.readExcelForXlsx(file, 0); + if (stringArrayListHashMap.isEmpty()) { + return; + } + // 数据校验 + // 保存到DB + int isolateType = resourceEntity.getIsolateType(); + String keyName = IsolateTypeEnum.getKeyName(isolateType); + // 影子表单独处理 + if (isolateType == IsolateTypeEnum.SHADOW_TABLE.getCode()) { + processShadowTable(keyName, resourceId, stringArrayListHashMap); + } else { + // 影子库处理 + processShadowDB(keyName, resourceId, stringArrayListHashMap); + } + } + + /** + * 导出 + * + * @param response + * @param resourceId + */ + @Override + public void export(HttpServletResponse response, Long resourceId) { + PressureResourceEntity resourceEntity = pressureResourceMapper.queryByIdNoTenant(resourceId); + if (resourceEntity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "资源配置未获取到"); + } + TenantInfoExt tenantInfo = WebPluginUtils.getTenantInfo(resourceEntity.getTenantId()); + String tenantCode = ""; + String tenantAppKey = ""; + if (tenantInfo != null) { + tenantCode = tenantInfo.getTenantCode(); + tenantAppKey = tenantInfo.getTenantAppKey(); + } + // 复制上下文 + WebPluginUtils.setTraceTenantContext(resourceEntity.getTenantId(), + tenantAppKey, resourceEntity.getEnvCode(), tenantCode, ContextSourceEnum.HREF.getCode()); + + // 判断隔离方式 + if (resourceEntity.getIsolateType() == IsolateTypeEnum.SHADOW_TABLE.getCode()) { + // 影子表导出 + exportShadowTable(response, resourceEntity); + } else { + // 影子库导出 + exportShadowDB(response, resourceEntity); + } + } + + /** + * 导出影子库 + * + * @param response + * @param resource + */ + private void exportShadowDB(HttpServletResponse response, PressureResourceEntity resource) { + // 查询所有影子库 + PressureResourceDsQueryParam dsQueryParam = new PressureResourceDsQueryParam(); + dsQueryParam.setResourceId(resource.getId()); + List dsEntityList = null;//pressureResourceRelateDsDAO.queryByParam(dsQueryParam); + List shadowDbExcelVOList = Lists.newArrayList(); + List> sheets = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(dsEntityList)) { + shadowDbExcelVOList = dsEntityList.stream().map(entity -> { + ShadowDbExcelVO excelVO = new ShadowDbExcelVO(); + excelVO.setBusinessDatabase(entity.getBusinessDatabase()); + //excelVO.setShadowDatabase(entity.getShadowDatabase()); + excelVO.setIsolateType(IsolateTypeEnum.getName(resource.getIsolateType())); + //excelVO.setShadowUsername(entity.getShadowUserName()); + //excelVO.setShadowPassword(entity.getShadowPassword()); + return excelVO; + }).collect(Collectors.toList()); + } + ExcelSheetVO shadowDbSheet = new ExcelSheetVO<>(); + shadowDbSheet.setData(shadowDbExcelVOList); + shadowDbSheet.setExcelModelClass(ShadowDbExcelVO.class); + shadowDbSheet.setSheetName(IsolateTypeEnum.getKeyName(resource.getIsolateType())); + shadowDbSheet.setSheetNum(1); + sheets.add(shadowDbSheet); + try { + ExcelUtils.exportExcelManySheet(response, resource.getName() + "_隔离配置", sheets); + } catch (Exception e) { + logger.error("配置导出错误: {}", ExceptionUtils.getStackTrace(e)); + } + } + + /** + * 导出影子表 + * + * @param response + * @param resource + */ + private void exportShadowTable(HttpServletResponse response, PressureResourceEntity resource) { + // 查询当前配置下的所有数据源信息 + PressureResourceDsQueryParam dsQueryParam = new PressureResourceDsQueryParam(); + dsQueryParam.setResourceId(resource.getId()); + List dsEntityList = null;//pressureResourceRelateDsDAO.queryByParam(dsQueryParam); + List> sheets = new ArrayList<>(); + List shadowTableExcelVOList = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(dsEntityList)) { + // 查询影子表 + PressureResourceTableQueryParam tableQueryParam = new PressureResourceTableQueryParam(); + tableQueryParam.setResourceId(resource.getId()); + List tableEntityList = null;//pressureResourceRelateTableDAO.queryList(tableQueryParam); + // 按照数据源分组下 + Map> dsMap = Maps.newConcurrentMap();//dsEntityList.stream().collect(Collectors.groupingBy(item -> DataSourceUtil.generateDsKey(item.getResourceId(), item.getBusinessDatabase()))); + if (CollectionUtils.isNotEmpty(tableEntityList)) { + Map> tableEntityMap = Maps.newHashMap();//tableEntityList.stream().collect(Collectors.groupingBy(item -> item.getDsKey())); + for (Map.Entry> entry : tableEntityMap.entrySet()) { + List dsList = dsMap.get(entry.getKey()); + if (CollectionUtils.isNotEmpty(dsList)) { + PressureResourceRelateDsEntityV2 tmpDs = dsList.get(0); + if (tmpDs != null && tmpDs.getId() != null) { + List list = entry.getValue().stream().map(table -> { + ShadowTableExcelVO excelVO = new ShadowTableExcelVO(); + excelVO.setBusinessDatabase(tmpDs.getBusinessDatabase()); + excelVO.setDatabase(DbNameUtil.getDbName(tmpDs.getBusinessDatabase())); + excelVO.setIsolateType(IsolateTypeEnum.getName(resource.getIsolateType())); + //excelVO.setShadowTable(table.getShadowTable()); + //excelVO.setBusinessTable(table.getBusinessTable()); + return excelVO; + }).collect(Collectors.toList()); + shadowTableExcelVOList.addAll(list); + } + } + } + } else { + for (Map.Entry> entry : dsMap.entrySet()) { + ShadowTableExcelVO excelVO = new ShadowTableExcelVO(); + excelVO.setBusinessDatabase(entry.getValue().get(0).getBusinessDatabase()); + excelVO.setDatabase(DbNameUtil.getDbName(excelVO.getBusinessDatabase())); + excelVO.setIsolateType(IsolateTypeEnum.getName(resource.getIsolateType())); + shadowTableExcelVOList.add(excelVO); + } + } + } + ExcelSheetVO shadowTableSheet = new ExcelSheetVO<>(); + shadowTableSheet.setData(shadowTableExcelVOList); + shadowTableSheet.setExcelModelClass(ShadowTableExcelVO.class); + shadowTableSheet.setSheetName(IsolateTypeEnum.getKeyName(resource.getIsolateType())); + shadowTableSheet.setSheetNum(1); + sheets.add(shadowTableSheet); + try { + ExcelUtils.exportExcelManySheet(response, resource.getName() + "_隔离配置", sheets); + } catch (Exception e) { + logger.error("配置导出错误: {}", ExceptionUtils.getStackTrace(e)); + } + } + + /** + * 处理影子表 + * + * @param resourceId + * @param stringArrayListHashMap + */ + private void processShadowTable(String keyName, Long resourceId, Map>> stringArrayListHashMap) { + ArrayList> isolateType_ShadowTable = stringArrayListHashMap.get(keyName); + if (CollectionUtils.isEmpty(isolateType_ShadowTable)) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "sheet列未找到数据"); + } + // 解析数据 + List tableList = Lists.newArrayList(); + for (int i = 0; i < isolateType_ShadowTable.size(); i++) { + ArrayList mess = isolateType_ShadowTable.get(i); + // 业务数据源地址 + String bussinessDatabase = ""; + String businessTable = ""; + String shadowTable = ""; + try { + bussinessDatabase = mess.get(0); + // 业务表 + businessTable = mess.get(3); + // 影子表 + shadowTable = mess.get(4); + } catch (Throwable e) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "文件缺少必填项,请检查!"); + } + PressureResourceRelateTableInput input = new PressureResourceRelateTableInput(); + input.setDatabase(bussinessDatabase); + input.setBusinessTable(businessTable); + input.setShadowTable(shadowTable); + + // 导入数据 + tableList.add(input); + } + // 按照URL分组 + Map> tableMap = tableList.stream().collect(Collectors.groupingBy(PressureResourceRelateTableInput::getDatabase)); + List tableEntityList = Lists.newArrayList(); + for (Map.Entry> entry : tableMap.entrySet()) { + // 数据源 + String database = entry.getKey(); + // 判断数据源是否存在 + PressureResourceDsQueryParam queryParam = new PressureResourceDsQueryParam(); + queryParam.setResourceId(resourceId); + queryParam.setBussinessDatabase(database); + List dsEntityList = pressureResourceRelateDsDAO.queryByParam_v2(queryParam); + if (CollectionUtils.isEmpty(dsEntityList)) { + // TODO,新增数据源 + continue; + } + // 根据dsKey去更新 dsKey = resource_id + business_database + String dsKey = null;//DataSourceUtil.generateDsKey(resourceId, database); + List inputs = entry.getValue(); + for (int i = 0; i < inputs.size(); i++) { + PressureResourceRelateTableInput input = inputs.get(i); + PressureResourceRelateTableEntityV2 entity = new PressureResourceRelateTableEntityV2(); + entity.setResourceId(resourceId); + entity.setDsKey(dsKey); + //entity.setBusinessTable(input.getBusinessTable()); + //entity.setShadowTable(input.getShadowTable()); + //entity.setJoinFlag(JoinFlagEnum.NO.getCode()); + entity.setType(SourceTypeEnum.MANUAL.getCode()); + entity.setStatus(StatusEnum.NO.getCode()); + entity.setGmtCreate(new Date()); + entity.setTenantId(WebPluginUtils.traceTenantId()); + entity.setEnvCode(WebPluginUtils.traceEnvCode()); + tableEntityList.add(entity); + } + } + // 批量保存 + pressureResourceRelateTableDAO.saveOrUpdate(tableEntityList); + } + + /** + * 处理影子库 + * + * @param resourceId + * @param stringArrayListHashMap + */ + private void processShadowDB(String keyName, Long resourceId, Map>> stringArrayListHashMap) { + ArrayList> isolateType_Shadowdb = stringArrayListHashMap.get(keyName); + if (CollectionUtils.isEmpty(isolateType_Shadowdb)) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "sheet列未找到数据"); + } + // 解析列表值 + for (int i = 1; i < isolateType_Shadowdb.size(); i++) { + ArrayList mess = isolateType_Shadowdb.get(i); + // 至少要填三列 + if (mess.size() < 3) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "缺少数据,请检查文件是否正确"); + } + // 获取每列值 + String bussinessDatabase = mess.get(0); + String shadowDatabase = mess.get(2); + String userName = ""; + String password = ""; + try { + // 账号密码可以不填写 + userName = mess.get(3); + password = mess.get(4); + } catch (Throwable e) { + } + if (StringUtils.isBlank(shadowDatabase)) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "影子数据源为空!"); + } + // 按业务数据源查询,是否存在 + PressureResourceDsQueryParam queryParam = new PressureResourceDsQueryParam(); + queryParam.setResourceId(resourceId); + queryParam.setBussinessDatabase(bussinessDatabase); + List dsEntityList = null;//pressureResourceRelateDsDAO.queryByParam(queryParam); + if (CollectionUtils.isEmpty(dsEntityList)) { + // 新增 + PressureResourceRelateDsEntityV2 dsInput = new PressureResourceRelateDsEntityV2(); + dsInput.setResourceId(resourceId); + dsInput.setBusinessDatabase(bussinessDatabase); + //dsInput.setShadowDatabase(shadowDatabase); + //dsInput.setShadowUserName(userName); + //dsInput.setShadowPassword(password); + // 手工新增 + dsInput.setType(SourceTypeEnum.MANUAL.getCode()); + //pressureResourceRelateDsMapperV2.insert(dsInput); + } else { + // update + PressureResourceRelateDsEntityV2 updateEntity = new PressureResourceRelateDsEntityV2(); + //updateEntity.setShadowDatabase(shadowDatabase); + //updateEntity.setShadowUserName(userName); + //updateEntity.setShadowPassword(password); + updateEntity.setGmtModified(new Date()); + + // 直接走批量更新,会将所有应用关联的数据源全部更新掉 + QueryWrapper whereWrapper = new QueryWrapper<>(); + whereWrapper.eq("resource_id", resourceId); + whereWrapper.eq("business_database", bussinessDatabase); + //pressureResourceRelateDsMapperV2.update(updateEntity, whereWrapper); + } + } + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceMqConsumerServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceMqConsumerServiceImpl.java new file mode 100644 index 0000000000..fdecf5dfba --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceMqConsumerServiceImpl.java @@ -0,0 +1,328 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MqConsumerFeature; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceMqConsumerCreateInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceMqConsumerQueryRequest; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceMqConsumerService; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceMqComsumerVO; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; +import io.shulie.takin.web.data.dao.application.ApplicationDAO; +import io.shulie.takin.web.data.dao.application.ApplicationDsDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateMqComsumerDAO; +import io.shulie.takin.web.data.mapper.mysql.ApplicationDsManageMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateMqConsumerMapper; +import io.shulie.takin.web.data.model.mysql.ApplicationDsManageEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateMqConsumerEntity; +import io.shulie.takin.web.data.param.application.ApplicationDsCreateParam; +import io.shulie.takin.web.data.param.application.ApplicationDsQueryParam; +import io.shulie.takin.web.data.param.application.ApplicationDsUpdateParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceMqConsumerQueryParam; +import io.shulie.takin.web.data.result.application.ApplicationDetailResult; +import io.shulie.takin.web.data.result.application.ApplicationDsResult; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 压测资源配置 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +@Service +public class PressureResourceMqConsumerServiceImpl implements PressureResourceMqConsumerService { + private static Logger logger = LoggerFactory.getLogger(PressureResourceMqConsumerServiceImpl.class); + + @Resource + private PressureResourceRelateMqConsumerMapper pressureResourceRelateMqConsumerMapper; + @Resource + private PressureResourceRelateMqComsumerDAO pressureResourceRelateMqComsumerDAO; + + @Resource + private ApplicationDsDAO applicationDsDAO; + + @Resource + private ApplicationDAO applicationDAO; + + @Resource + private ApplicationDsManageMapper applicationDsManageMapper; + + /** + * 创建影子消费者 + * + * @param request + */ + @Override + public void create(PressureResourceMqConsumerCreateInput request) { + validata(request); + PressureResourceMqConsumerQueryParam queryParam = new PressureResourceMqConsumerQueryParam(); + queryParam.setResourceId(request.getResourceId()); + queryParam.setTopic(request.getTopic()); + queryParam.setGroup(request.getGroup()); + queryParam.setMqType(request.getMqType()); + List exists = pressureResourceRelateMqComsumerDAO.queryList(queryParam); + if (CollectionUtils.isNotEmpty(exists)) { + throw new RuntimeException( + String.format("类型为[%s],对应的topic[%s] group[%s]已存在", + request.getMqType(), + request.getTopic(), + request.getGroup())); + } + PressureResourceRelateMqConsumerEntity shadowMqConsumerEntity = convertEntity(request); + shadowMqConsumerEntity.setId(null); + shadowMqConsumerEntity.setGmtCreate(new Date()); + shadowMqConsumerEntity.setGmtModified(new Date()); + // kafka-其他集群模式 + if ("KAFKA-其他".equals(request.getMqType())) { + Long dsId = insertShadowClusterKafkaDsManage(shadowMqConsumerEntity); + shadowMqConsumerEntity.setRelateDsManageId(dsId); + } + pressureResourceRelateMqComsumerDAO.add(shadowMqConsumerEntity); + } + + /** + * 分页 + * + * @param request + * @return + */ + @Override + public PagingList list(PressureResourceMqConsumerQueryRequest request) { + PressureResourceMqConsumerQueryParam param = new PressureResourceMqConsumerQueryParam(); + BeanUtils.copyProperties(request, param); + PagingList pageList = pressureResourceRelateMqComsumerDAO.pageList(param); + if (pageList.isEmpty()) { + return PagingList.of(Collections.emptyList(), pageList.getTotal()); + } + //转换下 + List source = pageList.getList(); + List returnList = source.stream().map(configDto -> { + PressureResourceMqComsumerVO vo = new PressureResourceMqComsumerVO(); + BeanUtils.copyProperties(configDto, vo); + Long applicationId = configDto.getApplicationId(); + if (applicationId != null) { + vo.setApplicationId(String.valueOf(applicationId)); + ApplicationDetailResult detail = applicationDAO.getApplicationById(applicationId); + vo.setApplicationName(detail == null ? "" : detail.getApplicationName()); + } + vo.setId(String.valueOf(configDto.getId())); + // 转换下feature + if (StringUtils.isNotBlank(vo.getFeature())) { + vo.setMqConsumerFeature(JSON.parseObject(vo.getFeature(), MqConsumerFeature.class)); + } + // kafka的时候,如果是生产者,不需要展示消费组,设置为空 + if (vo.getMqType().contains("KAFKA") && vo.getComsumerType() == 0) { + vo.setGroup(""); + } + return vo; + }).collect(Collectors.toList()); + + return PagingList.of(returnList, pageList.getTotal()); + } + + private void validata(PressureResourceMqConsumerCreateInput request) { + } + + /** + * 修改 + * + * @param request + */ + @Override + public void update(PressureResourceMqConsumerCreateInput request) { + if (request.getId() == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + // 判断是否存在 + PressureResourceRelateMqConsumerEntity entity = pressureResourceRelateMqConsumerMapper.selectById(request.getId()); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "未查询到指定数据"); + } + PressureResourceMqConsumerQueryParam queryParam = new PressureResourceMqConsumerQueryParam(); + queryParam.setResourceId(request.getResourceId()); + queryParam.setTopic(request.getTopic()); + queryParam.setGroup(request.getGroup()); + queryParam.setMqType(request.getMqType()); + List exists = pressureResourceRelateMqComsumerDAO.queryList(queryParam); + if (CollectionUtils.isNotEmpty(exists)) { + // 判断是否属于同一个Id + PressureResourceRelateMqConsumerEntity mqConsumer = exists.get(0); + if (!mqConsumer.getId().equals(request.getId())) { + throw new RuntimeException( + String.format("类型为[%s],对应的topic[%s] group[%s]已存在", + request.getMqType(), + request.getTopic(), + request.getGroup())); + } + } + // 更新 + PressureResourceRelateMqConsumerEntity updateEntity = convertEntity(request); + updateEntity.setGmtModified(new Date()); + + // 更新应用配置的旧表 + if ("KAFKA-其他".equals(request.getMqType())) { + if (entity.getRelateDsManageId() == null) { + Long dsManageId = insertShadowClusterKafkaDsManage(updateEntity); + updateEntity.setRelateDsManageId(dsManageId); + } else { + ApplicationDsUpdateParam updateParam = new ApplicationDsUpdateParam(); + updateParam.setId(entity.getRelateDsManageId()); + updateParam.setUrl(request.getTopic()); + updateParam.setStatus(entity.getConsumerTag()); + String config = buildConfig(updateEntity); + updateParam.setConfig(config); + updateParam.setParseConfig(config); + applicationDsDAO.update(updateParam); + } + } + pressureResourceRelateMqConsumerMapper.updateById(updateEntity); + + } + + /** + * 处理消费状态 + * + * @param input + */ + @Override + public void processConsumerTag(PressureResourceMqConsumerCreateInput input) { + if (CollectionUtils.isEmpty(input.getIds()) && input.getId() == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数未指定"); + } + PressureResourceRelateMqConsumerEntity updateEntity = new PressureResourceRelateMqConsumerEntity(); + updateEntity.setConsumerTag(input.getConsumerTag()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (CollectionUtils.isNotEmpty(input.getIds())) { + queryWrapper.in("id", input.getIds()); + } + if (input.getId() != null) { + queryWrapper.eq("id", input.getId()); + } + pressureResourceRelateMqConsumerMapper.update(updateEntity, queryWrapper); + + // 更新application_ds_manage表 + List consumerEntities = pressureResourceRelateMqConsumerMapper.selectList(queryWrapper); + List dsManageIds = consumerEntities.stream().filter(entity -> entity.getRelateDsManageId() != null).map(entity -> entity.getRelateDsManageId()).collect(Collectors.toList()); + if (!dsManageIds.isEmpty()) { + ApplicationDsManageEntity entity = new ApplicationDsManageEntity(); + entity.setStatus(input.getConsumerTag()); + QueryWrapper dsManageEntityQueryWrapper = new QueryWrapper<>(); + if (CollectionUtils.isNotEmpty(input.getIds())) { + queryWrapper.in("id", dsManageIds); + } + applicationDsManageMapper.update(entity, dsManageEntityQueryWrapper); + } + + } + + @Override + public void delete(Long id) { + if (id == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + PressureResourceRelateMqConsumerEntity consumerEntity = pressureResourceRelateMqConsumerMapper.selectById(id); + if (consumerEntity == null) { + return; + } + if (consumerEntity.getRelateDsManageId() != null) { + applicationDsManageMapper.deleteById(consumerEntity.getRelateDsManageId()); + } + pressureResourceRelateMqConsumerMapper.deleteById(id); + } + + private PressureResourceRelateMqConsumerEntity convertEntity(PressureResourceMqConsumerCreateInput request) { + PressureResourceRelateMqConsumerEntity shadowMqConsumerEntity = new PressureResourceRelateMqConsumerEntity(); + shadowMqConsumerEntity.setId(request.getId()); + shadowMqConsumerEntity.setResourceId(request.getResourceId()); + shadowMqConsumerEntity.setTopic(request.getTopic()); + shadowMqConsumerEntity.setGroup(StringUtils.isBlank(request.getGroup()) ? "default" : request.getGroup()); + shadowMqConsumerEntity.setBrokerAddr(request.getBrokerAddr()); + shadowMqConsumerEntity.setTopicTokens(request.getTopicTokens()); + shadowMqConsumerEntity.setSystemIdToken(request.getSystemIdToken()); + shadowMqConsumerEntity.setMqType(request.getMqType()); + String applicationId = request.getApplicationId(); + if (StringUtils.isNotBlank(applicationId)) { + shadowMqConsumerEntity.setApplicationId(Long.valueOf(applicationId)); + } + // 是否消费 + shadowMqConsumerEntity.setConsumerTag(request.getConsumerTag()); + shadowMqConsumerEntity.setComsumerType(request.getComsumerType()); + shadowMqConsumerEntity.setIsCluster(request.getIsCluster()); + // 设置来源标识 + shadowMqConsumerEntity.setType(request.getType()); + if (request.getMqConsumerFeature() != null) { + shadowMqConsumerEntity.setFeature(JSON.toJSONString(request.getMqConsumerFeature())); + } + return shadowMqConsumerEntity; + } + + /** + * 写入application_ds_manage表 + * + * @param entity + * @return + */ + private Long insertShadowClusterKafkaDsManage(PressureResourceRelateMqConsumerEntity entity) { + ApplicationDsCreateParam createParam = new ApplicationDsCreateParam(); + createParam.setUrl(entity.getTopic()); + createParam.setUrl(entity.getTopic()); + String config = buildConfig(entity); + createParam.setConfig(config); + createParam.setParseConfig(config); + createParam.setApplicationId(entity.getApplicationId()); + if (entity.getApplicationId() != null && entity.getApplicationName() == null) { + entity.setApplicationName(applicationDAO.getApplicationById(entity.getApplicationId()).getApplicationName()); + } + createParam.setApplicationName(entity.getApplicationName()); + createParam.setCreateTime(new Date()); + createParam.setUpdateTime(new Date()); + createParam.setDbType(4); + createParam.setDsType(5); + WebPluginUtils.fillUserData(createParam); + createParam.setStatus(entity.getConsumerTag()); + + // 是否有存储过的数据 + ApplicationDsQueryParam queryParam = new ApplicationDsQueryParam(); + queryParam.setApplicationId(entity.getApplicationId()); + queryParam.setUrl(entity.getTopic()); + List dsResults = applicationDsDAO.queryList(new ApplicationDsQueryParam()); + if (!dsResults.isEmpty()) { + Optional optional = dsResults.stream().filter(applicationDsResult -> config.equals(JSON.parseObject(applicationDsResult.getConfig()).toJSONString())).findFirst(); + if (optional.isPresent()) { + return optional.get().getId(); + } + } + return Long.valueOf(applicationDsDAO.insert(createParam)); + } + + private String buildConfig(PressureResourceRelateMqConsumerEntity entity) { + Map objectMap = new HashMap<>(); + objectMap.put("key", entity.getTopic()); + objectMap.put("topic", entity.getTopic()); + objectMap.put("topicTokens", entity.getTopicTokens()); + objectMap.put("group", entity.getGroup()); + objectMap.put("brokerAddr", entity.getBrokerAddr()); + objectMap.put("systemIdToken", entity.getSystemIdToken()); + if (entity.getFeature() != null) { + Map feature = JSON.parseObject(entity.getFeature(), Map.class); + objectMap.put("clusterName", feature.get("clusterName")); + objectMap.put("monitorUrl", feature.get("clusterAddr")); + objectMap.put("poolSize", feature.get("providerThreadCount")); + objectMap.put("messageConsumeThreadCount", feature.get("consumerThreadCount")); + } + return JSON.toJSONString(objectMap); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceRemoteCallServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceRemoteCallServiceImpl.java new file mode 100644 index 0000000000..4cb14c3b21 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceRemoteCallServiceImpl.java @@ -0,0 +1,226 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import cn.hutool.core.collection.ListUtil; +import com.alibaba.fastjson.JSON; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.amdb.api.TraceClient; +import io.shulie.takin.web.amdb.bean.query.trace.TraceInfoQueryDTO; +import io.shulie.takin.web.amdb.bean.result.trace.EntryTraceInfoDTO; +import io.shulie.takin.web.biz.pojo.request.pressureresource.*; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceRemoteCallService; +import io.shulie.takin.web.biz.service.pressureresource.common.CheckStatusEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.PassEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.RemoteCallUtil; +import io.shulie.takin.web.biz.service.pressureresource.common.dy.DynamicCompilerUtil; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceRelateRemoteCallVO; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; +import io.shulie.takin.web.data.dao.application.AppRemoteCallDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateRemoteCallDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateRemoteCallMapperV2; +import io.shulie.takin.web.data.model.mysql.AppRemoteCallEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateRemoteCallEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateRemoteCallEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceRemoteCallQueryParam; +import io.shulie.takin.web.data.result.application.AppRemoteCallResult; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/16 12:06 PM + */ +@Service +public class PressureResourceRemoteCallServiceImpl implements PressureResourceRemoteCallService { + private static Logger logger = LoggerFactory.getLogger(PressureResourceRemoteCallServiceImpl.class); + + @Resource + private PressureResourceRelateRemoteCallDAO pressureResourceRelateRemoteCallDAO; + + @Resource + private PressureResourceRelateRemoteCallMapperV2 pressureResourceRelateRemoteCallMapperV2; + + @Resource + private TraceClient traceClient; + + @Resource + private AppRemoteCallDAO appRemoteCallDAO; + + /** + * @param request + * @return + */ + @Override + public PagingList pageList(PressureResourceRelateRemoteCallRequest request) { + PressureResourceRemoteCallQueryParam param = new PressureResourceRemoteCallQueryParam(); + BeanUtils.copyProperties(request, param); + PagingList pageList = pressureResourceRelateRemoteCallDAO.pageList_v2(param); + + if (pageList.isEmpty()) { + return PagingList.of(Collections.emptyList(), pageList.getTotal()); + } + //转换下 + List source = pageList.getList(); + List returnList = source.stream().map(configDto -> { + PressureResourceRelateRemoteCallVO vo = new PressureResourceRelateRemoteCallVO(); + BeanUtils.copyProperties(configDto, vo); + vo.setId(String.valueOf(configDto.getId())); + // 调用依赖 + if (StringUtils.isNotBlank(vo.getAppName()) && StringUtils.isNotBlank(vo.getServerAppName())) { + vo.setInvoke(vo.getAppName() + "调用" + vo.getServerAppName()); + } + // mock调整 + if (StringUtils.isNotBlank(vo.getMockReturnValue())) { + vo.setMockInfo(JSON.parseObject(vo.getMockReturnValue(), MockInfo.class)); + } + return vo; + }).collect(Collectors.toList()); + return PagingList.of(returnList, pageList.getTotal()); + } + + /** + * 更新mock + * + * @param mockInput + */ + @Override + public void update_v2(PressureResourceMockInput mockInput) { + Long id = mockInput.getId(); + if (id == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + PressureResourceRelateRemoteCallEntityV2 entity = pressureResourceRelateRemoteCallMapperV2.selectById(id); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "远程调用不存在!"); + } + + PressureResourceRelateRemoteCallEntityV2 update = new PressureResourceRelateRemoteCallEntityV2(); + update.setId(id); + if (mockInput.getPass() != null) { + update.setPass(mockInput.getPass()); + } + // 假如是放行,默认不检测,检测状态直接置为成功 + if (update.getPass() != null && update.getPass() == PassEnum.PASS_YES.getCode()) { + update.setStatus(CheckStatusEnum.CHECK_FIN.getCode()); + } + AppRemoteCallResult callResult = appRemoteCallDAO.queryOne(entity.getAppName(), entity.getInterfaceType(), entity.getInterfaceName()); + AppRemoteCallEntity updateEntity = new AppRemoteCallEntity(); + updateEntity.setId(callResult.getId()); + // 转换白名单类型 + String mockReturnValue = mockInput.getMockInfo() == null ? null : JSON.toJSONString(mockInput.getMockInfo()); + updateEntity.setType(RemoteCallUtil.getType(mockReturnValue, update.getPass())); + // mockReturnValue更新到app_remote_call表中 + if (mockInput.getMockInfo() != null) { + // 转换到远程调用 + updateEntity.setMockReturnValue(mockInput.getMockInfo().getMockValue()); + } + updateEntity.setGmtModified(update.getGmtModified()); + appRemoteCallDAO.updateById(updateEntity); + + // 更新冗余 + pressureResourceRelateRemoteCallMapperV2.updateById(update); + } + + /** + * 获取服务平均响应时间,id为远程调用服务Id + * + * @param id + * @return + */ + @Override + public MockDetailVO mockDetail(Long id) { + MockDetailVO mockDetailVO = new MockDetailVO(); + mockDetailVO.setRequest(Collections.emptyList()); + mockDetailVO.setResponseTime("0"); + // 远程调用服务Id + PressureResourceRelateRemoteCallEntityV2 call = pressureResourceRelateRemoteCallMapperV2.selectById(id); + if (call == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "数据未找到"); + } + TraceInfoQueryDTO traceInfoQueryDTO = new TraceInfoQueryDTO(); + traceInfoQueryDTO.setQueryType(1); + traceInfoQueryDTO.setAppName(call.getAppName()); + if (call.getInterfaceName().contains("#")) { + traceInfoQueryDTO.setServiceName(call.getInterfaceName().split("#")[0]); + traceInfoQueryDTO.setQueryMethodName(call.getInterfaceName().split("#")[1]); + } else { + traceInfoQueryDTO.setServiceName(call.getInterfaceName()); + } + traceInfoQueryDTO.setLogType("2"); + traceInfoQueryDTO.setSortField("startDate"); + traceInfoQueryDTO.setSortType("desc"); + traceInfoQueryDTO.setPageNum(0); + traceInfoQueryDTO.setPageSize(20); + PagingList pageList = null; + try { + pageList = traceClient.listEntryTraceInfo(traceInfoQueryDTO); + if (pageList == null || pageList.isEmpty()) { + return mockDetailVO; + } + } catch (Throwable e) { + return mockDetailVO; + } + Double avg = pageList.getList().stream().mapToLong(EntryTraceInfoDTO::getCost).average().orElse(0D); + mockDetailVO.setResponseTime(String.valueOf(Math.floor(avg))); + List requests = pageList.getList().stream().map(mock -> { + String response = mock.getResponse(); + if (response.startsWith("{{") && response.endsWith("}}")) { + response = response.substring(1); + response = response.substring(0, response.length() - 1); + } + return response; + }).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(requests)) { + mockDetailVO.setRequest(ListUtil.sub(requests, 1, 2)); + } + return mockDetailVO; + } + + /** + * 校验 + * + * @param mockInfo + * @return + */ + @Override + public PressureResourceCheckVO check(MockInfo mockInfo) { + PressureResourceCheckVO checkVO = new PressureResourceCheckVO(); + checkVO.setSuccess(true); + + if (StringUtils.isBlank(mockInfo.getMockValue())) { + checkVO.setRemark("mock数据为空!"); + checkVO.setSuccess(false); + return checkVO; + } + if (mockInfo.getType().equals("0")) { + try { + JSON.parseObject(mockInfo.getMockValue()); + } catch (Throwable e) { + checkVO.setSuccess(false); + checkVO.setRemark(e.getMessage()); + } + } else { + try { + String remark = DynamicCompilerUtil.check(mockInfo.getMockValue()); + if (StringUtils.isNotBlank(remark)) { + checkVO.setRemark(remark); + checkVO.setSuccess(false); + } + } catch (Throwable e) { + checkVO.setRemark(e.getMessage()); + checkVO.setSuccess(false); + } + } + return checkVO; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceServiceImpl.java new file mode 100644 index 0000000000..47defc636b --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceServiceImpl.java @@ -0,0 +1,662 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Maps; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.*; +import io.shulie.takin.web.biz.service.pressureresource.*; +import io.shulie.takin.web.biz.service.pressureresource.common.CheckStatusEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.JoinFlagEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.ModuleEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.SourceTypeEnum; +import io.shulie.takin.web.biz.service.pressureresource.vo.*; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; +import io.shulie.takin.web.common.util.ActivityUtil; +import io.shulie.takin.web.data.dao.linkmanage.SceneDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDetailDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateAppDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateDsDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceDetailMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateDsMapperV2; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateTableMapperV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.*; +import io.shulie.takin.web.data.param.linkmanage.SceneCreateParam; +import io.shulie.takin.web.data.param.linkmanage.SceneUpdateParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDetailQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDsQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceQueryParam; +import io.shulie.takin.web.data.result.linkmange.SceneResult; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:53 PM + */ +@Service +public class PressureResourceServiceImpl implements PressureResourceService { + private static Logger logger = LoggerFactory.getLogger(PressureResourceServiceImpl.class); + + @Resource + private PressureResourceDAO pressureResourceDAO; + + @Resource + private PressureResourceMapper pressureResourceMapper; + + @Resource + private PressureResourceRelateDsMapperV2 pressureResourceRelateDsMapperV2; + + @Resource + private PressureResourceRelateTableMapperV2 pressureResourceRelateTableMapperV2; + + @Resource + private PressureResourceDetailDAO pressureResourceDetailDAO; + + @Resource + private PressureResourceDetailMapper pressureResourceDetailMapper; + + @Resource + private PressureResourceRelateAppDAO pressureResourceRelateAppDAO; + + @Resource + private PressureResourceRelateDsDAO pressureResourceRelateDsDAO; + + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @Resource + private SceneDAO sceneDAO; + + @Resource + private PressureResourceAppService pressureResourceAppService; + + @Resource + private PressureResourceDsService pressureResourceDsService; + + @Resource + private PressureResourceMqConsumerService pressureResourceMqConsumerService; + + @Resource + private PressureResourceRemoteCallService pressureResourceRemoteCallService; + + /** + * 新增 + * + * @param input + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void add(PressureResourceInput input) { + if (StringUtils.isBlank(input.getName())) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "参数未传递"); + } + PressureResourceEntity entity = pressureResourceDAO.queryByName(input.getName()); + if (entity != null) { + // 业务流程名字可重复,这里处理下 + if (input.getType().intValue() == SourceTypeEnum.AUTO.getCode()) { + input.setName(input.getName() + "_" + DateUtil.formatDateTime(new Date())); + } else { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, input.getName() + "已存在"); + } + } + // 压测资源配置 + PressureResourceEntity insertEntity = new PressureResourceEntity(); + insertEntity.setName(input.getName()); + // 来源Id,业务流程Id + insertEntity.setSourceId(input.getSourceId()); + insertEntity.setType(input.getType()); + insertEntity.setUserId(input.getUserId()); + insertEntity.setGmtCreate(new Date()); + insertEntity.setGmtModified(new Date()); + Long resourceId = pressureResourceDAO.add(insertEntity); + + // 获取详情 + List detailInputs = input.getDetailInputs(); + if (CollectionUtils.isNotEmpty(detailInputs)) { + List insertEntityList = convertEntitys(input.getType(), resourceId, detailInputs); + pressureResourceDetailDAO.batchInsert(insertEntityList); + } + + // 手工的新增流程 + if (input.getType().intValue() == SourceTypeEnum.MANUAL.getCode()) { + // 新增业务流程 + SceneCreateParam sceneCreateParam = new SceneCreateParam(); + sceneCreateParam.setSceneName(input.getName()); + sceneCreateParam.setType(1); + Long sourceId = sceneDAO.insert(sceneCreateParam); + + // 更新sourceId + PressureResourceEntity updateResource = new PressureResourceEntity(); + updateResource.setId(resourceId); + updateResource.setSourceId(sourceId); + pressureResourceMapper.updateById(updateResource); + } + pressureResourceCommonService.processNotify(detailInputs); + } + + @Override + public void delete(Long resourceId) { + if (resourceId == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "参数未传递"); + } + PressureResourceEntity resourceEntity = pressureResourceMapper.selectById(resourceId); + if (resourceEntity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "数据不存在"); + } + if (resourceEntity.getType().intValue() == SourceTypeEnum.AUTO.getCode()) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "此链路自动新增,无法删除"); + } + // 删除主表 + pressureResourceMapper.deleteById(resourceId); + // 删除详情 + QueryWrapper detailWrapper = new QueryWrapper<>(); + detailWrapper.eq("resource_id", resourceId); + pressureResourceDetailMapper.delete(detailWrapper); + + // 删除数据源 + QueryWrapper dsWrapper = new QueryWrapper<>(); + dsWrapper.eq("resource_id", resourceId); + pressureResourceRelateDsMapperV2.delete(dsWrapper); + + // 删除表 + QueryWrapper tableWrapper = new QueryWrapper<>(); + tableWrapper.eq("resource_id", resourceId); + pressureResourceRelateTableMapperV2.delete(tableWrapper); + + // 删除流程 + SceneUpdateParam updateParam = new SceneUpdateParam(); + updateParam.setId(resourceEntity.getSourceId()); + updateParam.setIsDeleted(1); + sceneDAO.update(updateParam); + } + + /** + * 转换 + * + * @param type + * @param resourceId + * @param detailInputs + * @return + */ + private List convertEntitys(int type, Long resourceId, List detailInputs) { + if (CollectionUtils.isEmpty(detailInputs)) { + return Collections.EMPTY_LIST; + } + List insertEntityList = detailInputs.stream().map(detail -> { + PressureResourceDetailEntity detailEntity = new PressureResourceDetailEntity(); + BeanUtils.copyProperties(detail, detailEntity); + + detailEntity.setId(null); + // 来源类型 + detailEntity.setType(type); + detailEntity.setResourceId(resourceId); + String linkId = ActivityUtil.createLinkId(detail.getEntranceUrl(), detail.getMethod(), + detail.getAppName(), detail.getRpcType(), detail.getExtend()); + detailEntity.setLinkId(linkId); + detailEntity.setGmtCreate(new Date()); + detailEntity.setGmtModified(new Date()); + detailEntity.setTenantId(WebPluginUtils.traceTenantId()); + detailEntity.setEnvCode(WebPluginUtils.traceEnvCode()); + return detailEntity; + }).collect(Collectors.toList()); + return insertEntityList; + } + + /** + * 修改 + * + * @param input + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void update(PressureResourceInput input) { + if (input.getId() == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + // 判断是否存在 + PressureResourceEntity entity = pressureResourceMapper.selectById(input.getId()); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "未查询到指定数据"); + } + PressureResourceQueryParam param = new PressureResourceQueryParam(); + param.setName(input.getName()); + PressureResourceEntity nameEntity = pressureResourceDAO.queryByName(input.getName()); + if (nameEntity != null && !nameEntity.getId().equals(input.getId())) { + if (input.getType().intValue() == SourceTypeEnum.MANUAL.getCode()) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, input.getName() + "已存在"); + } else { + input.setName(input.getName() + DateUtil.formatDateTime(new Date())); + } + } + PressureResourceEntity updateResourceEntity = new PressureResourceEntity(); + updateResourceEntity.setId(input.getId()); + updateResourceEntity.setName(input.getName()); + // 系统自动扫描的,不要更新时间,排序有影响 + if (input.getType().equals(SourceTypeEnum.AUTO.getCode())) { + updateResourceEntity.setGmtModified(new Date()); + } + updateResourceEntity.setUserId(input.getUserId()); + pressureResourceMapper.updateById(updateResourceEntity); + + SceneResult sceneResult = sceneDAO.getSceneDetail(entity.getSourceId()); + if (sceneResult != null && !sceneResult.getSceneName().equals(input.getName())) { + SceneUpdateParam updateParam = new SceneUpdateParam(); + updateParam.setId(sceneResult.getId()); + updateParam.setSceneName(input.getName()); + updateParam.setUpdateTime(new Date()); + sceneDAO.update(updateParam); + } + // 修改详情 + PressureResourceDetailQueryParam detailParam = new PressureResourceDetailQueryParam(); + detailParam.setResourceId(input.getId()); + List oldList = pressureResourceDetailDAO.getList(detailParam); + List newList = convertEntitys(input.getType(), input.getId(), input.getDetailInputs()); + + Map> newMap = newList.stream().collect(Collectors.groupingBy(ele -> fetchKey(ele))); + Map> oldMap = oldList.stream().collect(Collectors.groupingBy(ele -> fetchKey(ele))); + //判断需要新增的,不在oldMap里面的 + List insertEntitys = Lists.newArrayList(); + List updateEntitys = Lists.newArrayList(); + for (Map.Entry> entry : newMap.entrySet()) { + String tmpKey = entry.getKey(); + if (!oldMap.containsKey(tmpKey)) { + // 相同URL和请求方式只有一个 + insertEntitys.add(entry.getValue().get(0)); + } else { + // 判断下名字是否被修改 + PressureResourceDetailEntity old = oldMap.get(tmpKey).get(0); + PressureResourceDetailEntity neww = newMap.get(tmpKey).get(0); + if (old != null && StringUtils.isNotBlank(old.getEntranceName()) && !old.getEntranceName().equals(neww.getEntranceName())) { + updateEntitys.add(neww); + } + } + } + if (CollectionUtils.isNotEmpty(insertEntitys)) { + pressureResourceDetailDAO.batchInsert(insertEntitys); + } + if (CollectionUtils.isNotEmpty(updateEntitys)) { + // 修改名称 + updateEntitys.stream().forEach(tmp -> { + pressureResourceDetailDAO.updateEntranceName(tmp); + }); + } + // 自动梳理出来的不做删除操作 + if (input.getType().intValue() != SourceTypeEnum.AUTO.getCode()) { + // 删除的,不在newMap里面的, + List deleteIds = Lists.newArrayList(); + for (Map.Entry> entry : oldMap.entrySet()) { + String tmpKey = entry.getKey(); + if (!newMap.containsKey(tmpKey)) { + Long id = entry.getValue().get(0).getId(); + if (id != null) { + deleteIds.add(id); + } + } + } + if (CollectionUtils.isNotEmpty(deleteIds)) { + pressureResourceDetailMapper.deleteBatchIds(deleteIds); + } + } + + // 把最新的链路去处理链路拓扑 + PressureResourceDetailQueryParam newDetailParam = new PressureResourceDetailQueryParam(); + detailParam.setResourceId(input.getId()); + List newDetailList = pressureResourceDetailDAO.getList(newDetailParam); + List detailInputs = newDetailList.stream().map(tmp -> { + PressureResourceDetailInput in = new PressureResourceDetailInput(); + BeanUtils.copyProperties(tmp, in); + return in; + }).collect(Collectors.toList()); + pressureResourceCommonService.processNotify(detailInputs); + } + + private String fetchKey(PressureResourceDetailEntity ele) { + return String.format("%s|%s|%s|%s|%s", ele.getEntranceUrl(), ele.getMethod(), ele.getAppName(), ele.getRpcType(), ele.getExtend()); + } + + /** + * 列表查询 + * + * @param request + * @return + */ + @Override + public PagingList list(PressureResourceQueryRequest request) { + PressureResourceQueryParam param = new PressureResourceQueryParam(); + BeanUtils.copyProperties(request, param); + + PagingList pageList = pressureResourceDAO.pageList(param); + if (pageList.isEmpty()) { + return PagingList.of(Collections.emptyList(), pageList.getTotal()); + } + //转换下 + List source = pageList.getList(); + List configIds = source.stream().map(configDto -> configDto.getId()).collect(Collectors.toList()); + PressureResourceDetailQueryParam queryParam = new PressureResourceDetailQueryParam(); + queryParam.setResourceIds(configIds); + List detailEntities = pressureResourceDetailDAO.getList(queryParam); + Map> detailMap = Maps.newHashMap(); + if (CollectionUtils.isNotEmpty(detailEntities)) { + detailMap = detailEntities.stream().collect(Collectors.groupingBy(entity -> String.valueOf(entity.getResourceId()))); + } + Map> finalDetailMap = detailMap; + List returnList = source.stream().map(configDto -> { + PressureResourceVO vo = new PressureResourceVO(); + BeanUtils.copyProperties(configDto, vo); + vo.setId(String.valueOf(configDto.getId())); + // 设置详情条数 + vo.setDetailCount(finalDetailMap.getOrDefault(String.valueOf(configDto.getId()), Collections.EMPTY_LIST).size()); + // 未开始 + vo.setStatus(processStatus(configDto.getId())); + // 处理下状态 + return vo; + }).collect(Collectors.toList()); + + return PagingList.of(returnList, pageList.getTotal()); + } + + private int processStatus(Long id) { + Map processMap = null; + try { + processMap = progress(id); + } catch (Throwable e) { + logger.error(ExceptionUtils.getStackTrace(e)); + } + // 应用状态是完成,如果其他未开始或已完成,状态就为已完成 + Integer appStatus = processMap.get(ModuleEnum.APP.getCode()); + Integer size = processMap.entrySet().stream() + .filter(entry -> { + if (!entry.getKey().equals(ModuleEnum.APP.getCode())) { + if (entry.getValue() == FinishStatusEnum.NO.getCode() || + entry.getValue() == FinishStatusEnum.FINSH.getCode()) { + return true; + } + } + return false; + }).map(entry -> entry.getValue()).collect(Collectors.toList()).size(); + + if (appStatus == FinishStatusEnum.FINSH.getCode() && size == processMap.size() - 1) { + return FinishStatusEnum.FINSH.getCode(); + } + List status = processMap.entrySet().stream().map(entry -> entry.getValue()).collect(Collectors.toList()); + Integer normal = status.stream().filter(var -> var == FinishStatusEnum.FINSH.getCode()).collect(Collectors.toList()).size(); + Integer ing = status.stream().filter(var -> var == FinishStatusEnum.START_ING.getCode()).collect(Collectors.toList()).size(); + if (ing > 0) { + return FinishStatusEnum.START_ING.getCode(); // 进行中 + } + if (normal == status.size()) { + return FinishStatusEnum.FINSH.getCode();//已完成 + } + return FinishStatusEnum.NO.getCode(); // 未开始 + } + + /** + * 详情 + * + * @param request + * @return + */ + @Override + public PressureResourceInfoVO detail(PressureResourceQueryRequest request) { + PressureResourceInfoVO infoVO = new PressureResourceInfoVO(); + + PressureResourceEntity resourceEntity = pressureResourceMapper.selectById(request.getId()); + if (resourceEntity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "数据不存在"); + } + infoVO.setId(String.valueOf(resourceEntity.getId())); + infoVO.setName(resourceEntity.getName()); + // 判断是否有链路信息 + PressureResourceDetailQueryParam param = new PressureResourceDetailQueryParam(); + param.setResourceId(request.getId()); + List detailList = pressureResourceDetailDAO.getList(param); + if (CollectionUtils.isEmpty(detailList)) { + return infoVO; + } + List detailVOList = detailList.stream().map(detail -> { + PressureResourceDetailVO tmpDetailVo = new PressureResourceDetailVO(); + BeanUtils.copyProperties(detail, tmpDetailVo); + tmpDetailVo.setValue(String.valueOf(detail.getId())); + tmpDetailVo.setId(String.valueOf(detail.getId())); + tmpDetailVo.setResourceId(String.valueOf(detail.getResourceId())); + return tmpDetailVo; + }).collect(Collectors.toList()); + infoVO.setDetailInputs(detailVOList); + return infoVO; + } + + /** + * 修改隔离方式 + * + * @param isolateInput + */ + @Override + public void updateIsolate(PressureResourceIsolateInput isolateInput) { + if (isolateInput.getId() == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + // 判断是否存在 + PressureResourceEntity entity = pressureResourceMapper.selectById(isolateInput.getId()); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.INTERFACE_PERFORMANCE_QUERY_ERROR, "未查询到指定数据"); + } + // 修改主表隔离方式 + PressureResourceEntity updateEntity = new PressureResourceEntity(); + updateEntity.setId(entity.getId()); + updateEntity.setIsolateType(isolateInput.getIsolateType()); + updateEntity.setGmtModified(new Date()); + pressureResourceMapper.updateById(updateEntity); + } + + /** + * 处理进度 + * + * @param id + * @return + */ + @Override + public Map progress(Long id) { + Map statusMap = Maps.newHashMap(); + statusMap.put(ModuleEnum.APP.getCode(), FinishStatusEnum.NO.getCode()); + statusMap.put(ModuleEnum.DS.getCode(), FinishStatusEnum.NO.getCode()); + statusMap.put(ModuleEnum.REMOTECALL.getCode(), FinishStatusEnum.NO.getCode()); + statusMap.put(ModuleEnum.MQ.getCode(), FinishStatusEnum.NO.getCode()); + + // 查看应用状态 + PressureResourceAppRequest appRequest = new PressureResourceAppRequest(); + appRequest.setResourceId(id); + PagingList pageList = pressureResourceAppService.appCheckList(appRequest); + if (!pageList.isEmpty()) { + List appVOList = pageList.getList(); + // 判断状态是否都是正常的,不需要检查的,status会设置为null + int normal = appVOList.stream().filter(app -> app.getStatus() == null || app.getStatus() == 0).collect(Collectors.toList()).size(); + if (normal == appVOList.size()) { + statusMap.put(ModuleEnum.APP.getCode(), FinishStatusEnum.FINSH.getCode()); + } + // 存在正常的,进行中 + if (appVOList.size() - normal > 0) { + statusMap.put(ModuleEnum.APP.getCode(), FinishStatusEnum.START_ING.getCode()); + } + } + + // 影子资源检查 + PressureResourceDsQueryParam dsQueryParam = new PressureResourceDsQueryParam(); + dsQueryParam.setResourceId(id); + List dsEntityList = pressureResourceRelateDsDAO.queryByParam_v2(dsQueryParam); + if (CollectionUtils.isNotEmpty(dsEntityList)) { + // 判断状态是否都是正常的 + int normal = dsEntityList.stream().filter(ds -> ds.getStatus() == CheckStatusEnum.CHECK_FIN.getCode()).collect(Collectors.toList()).size(); + if (normal == dsEntityList.size()) { + statusMap.put(ModuleEnum.DS.getCode(), FinishStatusEnum.FINSH.getCode()); + } + // 存在正常的,进行中 + if (dsEntityList.size() - normal > 0) { + statusMap.put(ModuleEnum.DS.getCode(), FinishStatusEnum.START_ING.getCode()); + } + } + + // 远程调用 + PressureResourceRelateRemoteCallRequest callRequest = new PressureResourceRelateRemoteCallRequest(); + callRequest.setResourceId(id); + callRequest.setPageSize(2000); + callRequest.setConvert(true); + PagingList callPagingList = pressureResourceRemoteCallService.pageList(callRequest); + if (!callPagingList.isEmpty()) { + List callVOList = callPagingList.getList(); + // 判断状态是否都是正常的 + int normal = callVOList.stream().filter(app -> app.getStatus() == CheckStatusEnum.CHECK_FIN.getCode()).collect(Collectors.toList()).size(); + if (normal == callVOList.size()) { + statusMap.put(ModuleEnum.REMOTECALL.getCode(), FinishStatusEnum.FINSH.getCode()); + } + // 存在正常的,进行中 + if (callVOList.size() - normal > 0) { + statusMap.put(ModuleEnum.REMOTECALL.getCode(), FinishStatusEnum.START_ING.getCode()); + } + } + + // 影子MQ检查 + PressureResourceMqConsumerQueryRequest mqRequest = new PressureResourceMqConsumerQueryRequest(); + mqRequest.setResourceId(id); + mqRequest.setPageSize(2000); + PagingList mqPageList = pressureResourceMqConsumerService.list(mqRequest); + if (!mqPageList.isEmpty()) { + List appVOList = mqPageList.getList(); + // 判断状态是否都是正常的 + int normal = appVOList.stream().filter(app -> app.getStatus() == CheckStatusEnum.CHECK_FIN.getCode()).collect(Collectors.toList()).size(); + if (normal == appVOList.size()) { + statusMap.put(ModuleEnum.MQ.getCode(), FinishStatusEnum.FINSH.getCode()); + } + // 存在正常的,进行中 + if (appVOList.size() - normal > 0) { + statusMap.put(ModuleEnum.MQ.getCode(), FinishStatusEnum.START_ING.getCode()); + } + } + return statusMap; + } + + /** + * 处理页面汇总数据 + * + * @return + */ + @Override + public PressureResourceExtInfo appInfo(Long id) { + PressureResourceExtInfo extInfo = new PressureResourceExtInfo(); + extInfo.setTotalSize(0); + extInfo.setExceptionSize(0); + extInfo.setNormalSize(0); + + PressureResourceEntity entity = pressureResourceMapper.selectById(id); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "配置不存在"); + } + PressureResourceAppRequest appRequest = new PressureResourceAppRequest(); + appRequest.setResourceId(id); + appRequest.setPageSize(500); + PagingList pageList = pressureResourceAppService.appCheckList(appRequest); + if (!pageList.isEmpty()) { + List appVOList = pageList.getList(); + if (CollectionUtils.isNotEmpty(appVOList)) { + // 总的应用数 + extInfo.setTotalSize(appVOList.size()); + // 正常的应用数 + Long normalSize = appVOList.stream().filter(app -> app.getStatus() == 0 || app.getJoinPressure() == JoinFlagEnum.NO.getCode()).count(); + extInfo.setNormalSize(normalSize.intValue()); + extInfo.setExceptionSize(appVOList.size() - normalSize.intValue()); + } + } + // 检测时间都是一批的 + extInfo.setCheckTime(entity.getCheckTime()); + extInfo.setUserName(WebPluginUtils.getUserName(entity.getUserId(), WebPluginUtils.getUserMapByIds(Arrays.asList(entity.getUserId())))); + return extInfo; + } + + /** + * 汇总信息-数据源 + * + * @param id + * @return + */ + @Override + public PressureResourceExtInfo dsInfo(Long id) { + PressureResourceExtInfo extInfo = new PressureResourceExtInfo(); + extInfo.setTotalSize(0); + extInfo.setExceptionSize(0); + extInfo.setNormalSize(0); + + PressureResourceEntity entity = pressureResourceMapper.selectById(id); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "配置不存在"); + } + PressureResourceRelateDsRequest dsRequest = new PressureResourceRelateDsRequest(); + dsRequest.setResourceId(id); + dsRequest.setPageSize(2000); + PagingList pageList = pressureResourceDsService.listByDs(dsRequest); + if (!pageList.isEmpty()) { + List resourceRelateDsVOS = pageList.getList(); + if (CollectionUtils.isNotEmpty(resourceRelateDsVOS)) { + extInfo.setTotalSize(resourceRelateDsVOS.size()); + Long normalSize = resourceRelateDsVOS.stream().filter(ds -> ds.getStatus() == 2).count(); + extInfo.setNormalSize(normalSize.intValue()); + extInfo.setExceptionSize(extInfo.getTotalSize() - extInfo.getNormalSize()); + } + } + // 检测时间都是一批的 + extInfo.setCheckTime(entity.getCheckTime()); + extInfo.setUserName(WebPluginUtils.getUserName(entity.getUserId(), WebPluginUtils.getUserMapByIds(Arrays.asList(entity.getUserId())))); + return extInfo; + } + + /** + * 汇总信息-影子消费者 + * + * @param id + * @return + */ + @Override + public PressureResourceExtInfo mqInfo(Long id) { + PressureResourceExtInfo extInfo = new PressureResourceExtInfo(); + extInfo.setTotalSize(0); + extInfo.setExceptionSize(0); + extInfo.setNormalSize(0); + + PressureResourceEntity entity = pressureResourceMapper.selectById(id); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "配置不存在"); + } + PressureResourceMqConsumerQueryRequest mqRequest = new PressureResourceMqConsumerQueryRequest(); + mqRequest.setResourceId(id); + mqRequest.setPageSize(2000); + PagingList pageList = pressureResourceMqConsumerService.list(mqRequest); + if (!pageList.isEmpty()) { + List resourceRelateDsVOS = pageList.getList(); + if (CollectionUtils.isNotEmpty(resourceRelateDsVOS)) { + extInfo.setTotalSize(resourceRelateDsVOS.size()); + Long normalSize = resourceRelateDsVOS.stream().filter(ds -> ds.getStatus() == 2).count(); + extInfo.setNormalSize(normalSize.intValue()); + extInfo.setExceptionSize(extInfo.getTotalSize() - extInfo.getNormalSize()); + } + } + // 检测时间都是一批的 + extInfo.setCheckTime(entity.getCheckTime()); + extInfo.setUserName(WebPluginUtils.getUserName(entity.getUserId(), WebPluginUtils.getUserMapByIds(Arrays.asList(entity.getUserId())))); + return extInfo; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceTableServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceTableServiceImpl.java new file mode 100644 index 0000000000..61b152f043 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/impl/PressureResourceTableServiceImpl.java @@ -0,0 +1,228 @@ +package io.shulie.takin.web.biz.service.pressureresource.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateTableInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateTableRequest; +import io.shulie.takin.web.biz.service.ApplicationService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceDsService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceTableService; +import io.shulie.takin.web.biz.service.pressureresource.common.DataSourceUtil; +import io.shulie.takin.web.biz.service.pressureresource.common.DbNameUtil; +import io.shulie.takin.web.biz.service.pressureresource.vo.PressureResourceRelateTableVO; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; +import io.shulie.takin.web.data.dao.application.ApplicationDsDbTableDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateDsDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateTableDAO; +import io.shulie.takin.web.data.mapper.mysql.ApplicationDsDbTableMapper; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateTableMapperV2; +import io.shulie.takin.web.data.model.mysql.ApplicationDsDbTableEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateTableEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateDsEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateTableEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDsQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceTableQueryParam; +import io.shulie.takin.web.data.result.application.ApplicationDsDbTableDetailResult; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/1 8:36 PM + */ +@Service +public class PressureResourceTableServiceImpl implements PressureResourceTableService { + private static Logger logger = LoggerFactory.getLogger(PressureResourceTableServiceImpl.class); + + @Resource + private PressureResourceRelateTableDAO pressureResourceRelateTableDAO; + + @Resource + private PressureResourceRelateTableMapperV2 pressureResourceRelateTableMapperV2; + + @Resource + private PressureResourceDsService pressureResourceDsService; + + @Resource + private PressureResourceRelateDsDAO pressureResourceRelateDsDAO; + + @Autowired + private ApplicationDsDbTableDAO applicationDsDbTableDAO; + + @Resource + private ApplicationService applicationService; + + @Autowired + private ApplicationDsDbTableDAO dsDbTableDAO; + + @Autowired + private ApplicationDsDbTableMapper applicationDsDbTableMapper; + + /** + * 新增 + * + * @param input + */ + @Override + public void save_v2(PressureResourceRelateTableInput input) { + // 判断数据源是否存在 + PressureResourceDsQueryParam dsQueryParam = new PressureResourceDsQueryParam(); + dsQueryParam.setResourceId(input.getResourceId()); + dsQueryParam.setId(input.getDsId()); + List dsEntityList = pressureResourceRelateDsDAO.queryByParam_v2(dsQueryParam); + if (CollectionUtils.isEmpty(dsEntityList)) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "关联数据源信息不存在"); + } + // 只有有一个 + RelateDsEntity dsEntity = dsEntityList.get(0); + // 判断业务表是否存在,找到当前数据源下关联的表信息 + PressureResourceTableQueryParam queryParam = new PressureResourceTableQueryParam(); + queryParam.setResourceId(input.getResourceId()); + queryParam.setDsKey(DataSourceUtil.generateDsKey_ext(dsEntity.getBusinessDatabase(), dsEntity.getBusinessUserName())); + List v2 = pressureResourceRelateTableDAO.queryList_v2(queryParam); + + Long appId = applicationService.queryApplicationIdByAppName(dsEntity.getAppName()); + if (CollectionUtils.isNotEmpty(v2)) { + // 判断表是否存在 + List vList = v2.stream().filter(v -> input.getBusinessTable().equals(v.getBusinessTable())).collect(Collectors.toList()); + if (vList.size() > 0) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "业务表已存在"); + } + } + // 新增 + ApplicationDsDbTableDetailResult detailResult = new ApplicationDsDbTableDetailResult(); + detailResult.setBizTable(input.getBusinessTable()); + detailResult.setShadowTable(input.getShadowTable()); + detailResult.setUrl(dsEntity.getBusinessDatabase()); + detailResult.setUserName(dsEntity.getBusinessUserName()); + detailResult.setBizDataBase(DbNameUtil.getDbName(dsEntity.getBusinessDatabase())); + detailResult.setAppId(appId); + detailResult.setManualTag(input.getType() == 0 ? 1 : 0); + // 加入就是选中 + detailResult.setIsCheck(input.getJoinFlag() == 0 ? 1 : 0); + List dsdbList = applicationDsDbTableDAO.batchSave_ext(Arrays.asList(detailResult)); + + // 保存关联关系 + List relateTableList = dsdbList.stream().map(table -> { + PressureResourceRelateTableEntityV2 tableEntityV2 = new PressureResourceRelateTableEntityV2(); + tableEntityV2.setResourceId(input.getResourceId()); + tableEntityV2.setRelateId(table.getId()); + tableEntityV2.setDsKey(input.getDsKey()); + tableEntityV2.setType(input.getType()); + tableEntityV2.setTenantId(WebPluginUtils.traceTenantId()); + tableEntityV2.setEnvCode(WebPluginUtils.traceEnvCode()); + tableEntityV2.setGmtCreate(new Date()); + return tableEntityV2; + }).collect(Collectors.toList()); + pressureResourceRelateTableDAO.add_V2(relateTableList); + } + + /** + * update + * + * @param updateInput + */ + @Override + public void update_v2(PressureResourceRelateTableInput updateInput) { + if (updateInput.getId() == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + // 判断是否存在 + PressureResourceRelateTableEntityV2 entity = pressureResourceRelateTableMapperV2.selectById(updateInput.getId()); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "未查询到指定数据"); + } + // 找到关联的Id + Long relateId = entity.getRelateId(); + ApplicationDsDbTableEntity updateEntity = new ApplicationDsDbTableEntity(); + updateEntity.setId(relateId); + updateEntity.setBizTable(updateInput.getBusinessTable()); + updateEntity.setShadowTable(updateInput.getShadowTable()); + // 是否选中,加入就选中 + updateEntity.setIsCheck(updateInput.getJoinFlag() == 0 ? 1 : 0); + updateEntity.setGmtUpdate(new Date()); + applicationDsDbTableMapper.updateById(updateEntity); + } + + /** + * 批量加入或取消 + * + * @param updateInput + */ + @Override + public void batchUpdate(PressureResourceRelateTableInput updateInput) { + if (CollectionUtils.isEmpty(updateInput.getIds())) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_OP_ERROR, "参数未传递"); + } + // 查询所有 + List relateTableEntityV2List = pressureResourceRelateTableMapperV2.selectBatchIds(updateInput.getIds()); + List ids = relateTableEntityV2List.stream().map(relate -> relate.getRelateId()).collect(Collectors.toList()); + + ApplicationDsDbTableEntity updateEntity = new ApplicationDsDbTableEntity(); + // 是否选中,加入就选中 + updateEntity.setIsCheck(updateInput.getJoinFlag() == 0 ? 1 : 0); + updateEntity.setGmtUpdate(new Date()); + + QueryWrapper updateWrapper = new QueryWrapper<>(); + updateWrapper.in("id", ids); + applicationDsDbTableMapper.update(updateEntity, updateWrapper); + } + + @Override + public void delete_v2(Long id) { + if (id == null) { + throw new TakinWebException(TakinWebExceptionEnum.ERROR_COMMON, "参数Id未指定"); + } + // 判断是否存在 + PressureResourceRelateTableEntityV2 entity = pressureResourceRelateTableMapperV2.selectById(id); + if (entity == null) { + throw new TakinWebException(TakinWebExceptionEnum.PRESSURE_RESOURCE_QUERY_ERROR, "未查询到指定数据"); + } + // 找到关联的Id + Long relateId = entity.getRelateId(); + applicationDsDbTableMapper.deleteById(relateId); + + // 关联关系也删除 + pressureResourceRelateTableMapperV2.deleteById(id); + } + + /** + * 分页 + * + * @param request + * @return + */ + @Override + public PagingList pageList_v2(PressureResourceRelateTableRequest request) { + PressureResourceTableQueryParam param = new PressureResourceTableQueryParam(); + BeanUtils.copyProperties(request, param); + PagingList pageList = pressureResourceRelateTableDAO.pageList_v2(param); + + if (pageList.isEmpty()) { + return PagingList.of(Collections.emptyList(), pageList.getTotal()); + } + //转换下 + List source = pageList.getList(); + List returnList = source.stream().map(configDto -> { + PressureResourceRelateTableVO vo = new PressureResourceRelateTableVO(); + BeanUtils.copyProperties(configDto, vo); + vo.setId(String.valueOf(configDto.getId())); + return vo; + }).collect(Collectors.toList()); + return PagingList.of(returnList, pageList.getTotal()); + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/CommandTaskVo.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/CommandTaskVo.java new file mode 100644 index 0000000000..58ea08d020 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/CommandTaskVo.java @@ -0,0 +1,42 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +/** + * @author xingchen + * @description: TODO + * @date 2022/10/18 5:44 PM + */ +public class CommandTaskVo { + /** + * 模块 + */ + private String module; + + /** + * resourceId + */ + private Long resourceId; + + public String getModule() { + return module; + } + + public void setModule(String module) { + this.module = module; + } + + public Long getResourceId() { + return resourceId; + } + + public void setResourceId(Long resourceId) { + this.resourceId = resourceId; + } + + @Override + public String toString() { + return "CommandTaskVo{" + + "module='" + module + '\'' + + ", resourceId=" + resourceId + + '}'; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceDetailVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceDetailVO.java new file mode 100644 index 0000000000..f239f585b1 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceDetailVO.java @@ -0,0 +1,52 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceDetailVO extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("给前端搞个ID的字符串") + private String value; + + @ApiModelProperty("资源配置Id") + private String resourceId; + + @ApiModelProperty("应用名称") + private String appName; + + @ApiModelProperty("入口URL") + private String entranceUrl; + + @ApiModelProperty("入口名称") + private String entranceName; + + @ApiModelProperty("rpcType") + private String rpcType; + + @ApiModelProperty("extend") + private String extend; + + @ApiModelProperty("请求方式") + private String method; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceDsVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceDsVO.java new file mode 100644 index 0000000000..7474dc2360 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceDsVO.java @@ -0,0 +1,20 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceDsVO { + @ApiModelProperty("状态") + private int status; + + @ApiModelProperty("业务数据源") + private String businessDataBase; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceExtInfo.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceExtInfo.java new file mode 100644 index 0000000000..3fafc944c5 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceExtInfo.java @@ -0,0 +1,31 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceExtInfo { + @ApiModelProperty("识别总数") + private Integer totalSize; + + @ApiModelProperty("正常个数") + private Integer normalSize; + + @ApiModelProperty("异常个数") + private Integer exceptionSize; + + @ApiModelProperty("最新检测时间") + private Date checkTime; + + @ApiModelProperty("负责人") + private String userName; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceInfoVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceInfoVO.java new file mode 100644 index 0000000000..d3a8ed1233 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceInfoVO.java @@ -0,0 +1,41 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.influxdb.annotation.Column; + +import java.util.Date; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceInfoVO { + @Id + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("资源配置名称") + private String name; + + @ApiModelProperty("来源类型-手工/业务流程") + private int type; + + @ApiModelProperty("状态 0-未开始 1-已开始") + private int status; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtUpdate; + + @ApiModelProperty("明细") + List detailInputs; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceMqComsumerVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceMqComsumerVO.java new file mode 100644 index 0000000000..6135d55a89 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceMqComsumerVO.java @@ -0,0 +1,91 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.takin.web.biz.pojo.request.pressureresource.MqConsumerFeature; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceMqComsumerVO { + /** + * 主键id + */ + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("资源配置Id") + private Long resourceId; + + /** + * topic + */ + private String topic; + + /** + * topic + */ + private String group; + + /** + * broker地址 + */ + private String brokerAddr; + + /** + * topicTokens + */ + private String topicTokens; + + /** + * systemIdToken + */ + private String systemIdToken; + + /** + * MQ类型 + */ + private String mqType; + + /** + * 应用id + */ + private String applicationId; + + private String applicationName; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("是否消费(0-消费 1-不消费 )") + private Integer consumerTag; + + /** + * 是否删除,0正常,1删除 + */ + private Integer deleted; + + /** + * 拓展字段 + */ + private String feature; + + @ApiModelProperty("remark") + private String remark; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + private Integer type; + + @ApiModelProperty("是否影子集群(0-是 1否)") + private Integer isCluster; + + @ApiModelProperty("生产或消费(0-生产,1-消费)") + private Integer comsumerType; + + private MqConsumerFeature mqConsumerFeature; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceProcessStatusVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceProcessStatusVO.java new file mode 100644 index 0000000000..17382686b5 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceProcessStatusVO.java @@ -0,0 +1,22 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * 进度状态 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceProcessStatusVO { + @ApiModelProperty("类型(APP-应用检查,DS-影子隔离 REMORECALL-远程调用 )") + private String type; + + @ApiModelProperty("状态(0-未开始 1-进行中 2-完成)") + private Integer status; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateAppVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateAppVO.java new file mode 100644 index 0000000000..858b9e9733 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateAppVO.java @@ -0,0 +1,60 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.influxdb.annotation.Column; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateAppVO extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("资源配置Id") + private String resourceId; + + @ApiModelProperty("详情Id") + private String detailId; + + @ApiModelProperty("应用名称") + private String appName; + + @ApiModelProperty("应用Id") + private String applicationId; + + @ApiModelProperty("状态 0-正常 1-不正常") + @Column(name = "`status`") + private Integer status; + + @ApiModelProperty("隔离方式(0-无 1-影子库 2-影子库/影子表 3-影子表)") + private Integer isolateType; + + @ApiModelProperty("节点数") + private Integer nodeNum; + + @ApiModelProperty("探针节点数") + private Integer agentNodeNum; + + @ApiModelProperty("是否加入压测范围(0-否 1-是)") + private Integer joinPressure; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtModified; + + @ApiModelProperty("异常备注") + private String remark; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateDsVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateDsVO.java new file mode 100644 index 0000000000..78deaa9b16 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateDsVO.java @@ -0,0 +1,89 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.biz.pojo.request.pressureresource.ExtInfo; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateDsVO extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("资源配置Id") + private String resourceId; + + @ApiModelProperty("应用名称") + private String appName; + + @ApiModelProperty("数据源+用户名") + private String dsKey; + + @ApiModelProperty("中间件类型") + private String middlewareType; + + @ApiModelProperty("(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("业务数据源") + private String businessDatabase; + + @ApiModelProperty("库名") + private String database; + + @ApiModelProperty("业务数据源用户名") + private String businessUserName; + + @ApiModelProperty("影子数据源") + private String shadowDatabase; + + @ApiModelProperty("影子数据源用户名") + private String shadowUserName; + + @ApiModelProperty("影子数据源密码") + private String shadowPassword; + + @ApiModelProperty("扩展信息") + private ExtInfo extInfo; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + private Integer type; + + @ApiModelProperty("remark") + private String remark; + + @ApiModelProperty("唯一键") + private String uniqueKey; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtModified; + + private List relationApps; + + @ApiModelProperty("关联应用信息") + private List appList; + + @ApiModelProperty("关联数据信息") + private List dsList; + + private Integer size; + +} + + + diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateRemoteCallCheckVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateRemoteCallCheckVO.java new file mode 100644 index 0000000000..cd97b1faf2 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateRemoteCallCheckVO.java @@ -0,0 +1,22 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MockInfo; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.influxdb.annotation.Column; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateRemoteCallCheckVO { + private String type; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateRemoteCallVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateRemoteCallVO.java new file mode 100644 index 0000000000..70a57d4079 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateRemoteCallVO.java @@ -0,0 +1,89 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MockInfo; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.influxdb.annotation.Column; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateRemoteCallVO extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("资源配置Id") + private String resourceId; + + @ApiModelProperty("detail_id") + private String detailId; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("接口名") + private String interfaceName; + + @ApiModelProperty("接口类型") + private Integer interfaceType; + + @ApiModelProperty("服务端应用名") + private String serverAppName; + + @ApiModelProperty("应用名") + private String appName; + + @ApiModelProperty("备注") + private String remark; + + @ApiModelProperty("配置类型0:未配置,1:白名单配置,2:返回值mock,3:转发mock") + private Integer type; + + @ApiModelProperty("是否放行(0:是 1:否)") + private Integer pass; + + @ApiModelProperty("mock返回值") + private String mockReturnValue; + + @ApiModelProperty("所属用户") + private Long userId; + + @ApiModelProperty("是否同步") + private Integer isSynchronize; + + @ApiModelProperty("接口子类型") + private String interfaceChildType; + + @ApiModelProperty("是否手动录入 0:否;1:是") + private Integer manualTag; + + @ApiModelProperty("应用名,接口名称,接口类型,租户id,环境code求md5") + private String md5; + + @ApiModelProperty("是否有效 0:有效;1:无效") + private Integer isDeleted; + + @Column(name = "`gmt_create`") + private Date gmtCreate; + + @Column(name = "`gmt_modified`") + private Date gmtModified; + + /** + * 调用依赖 + */ + private String invoke; + + @ApiModelProperty("mock数据") + private MockInfo mockInfo; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateTableVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateTableVO.java new file mode 100644 index 0000000000..0318423856 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceRelateTableVO.java @@ -0,0 +1,53 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.influxdb.annotation.Column; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceRelateTableVO extends TenantBaseEntity { + @Id + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("资源配置Id") + private String resourceId; + + @ApiModelProperty("数据源Key") + private String dsKey; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("业务表") + private String businessTable; + + @ApiModelProperty("影子表") + private String shadowTable; + + @ApiModelProperty("是否加入") + private int joinFlag; + + @ApiModelProperty("类型(0-手工 1-自动)") + private int type; + + @ApiModelProperty("扩展信息") + private int extInfo; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceVO.java new file mode 100644 index 0000000000..cf28e8c228 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/PressureResourceVO.java @@ -0,0 +1,52 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import io.shulie.surge.data.common.doc.annotation.Id; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.influxdb.annotation.Column; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@ToString(callSuper = true) +public class PressureResourceVO { + @Id + @ApiModelProperty("ID") + private String id; + + @ApiModelProperty("资源配置名称") + private String name; + + @ApiModelProperty("来源类型-手工/业务流程") + private int type; + + @ApiModelProperty("隔离方式(0-无 1-影子库 2-影子库/影子表 3-影子表)") + private int isolateType; + + @ApiModelProperty("状态(0-未开始 1-已开始)") + private int status; + + @ApiModelProperty("链路类型") + private Integer configType; + + @ApiModelProperty("明细条数") + private Integer detailCount; + + @ApiModelProperty("检测状态(0-未检测 1-检测中 2-检测完成)") + private Integer checkStatus; + + @ApiModelProperty("检测时间") + private Date checkTime; + + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @ApiModelProperty("更新时间") + private Date gmtUpdate; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/ShadowDbExcelVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/ShadowDbExcelVO.java new file mode 100644 index 0000000000..0896bf4b0f --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/ShadowDbExcelVO.java @@ -0,0 +1,31 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.metadata.BaseRowModel; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class ShadowDbExcelVO extends BaseRowModel implements Serializable { + @ColumnWidth(50) + @ExcelProperty(value = {"Takin为您生成了影子库账号和密码(如不用系统生成的账号或密码,请替换新的账号密码到此表中", "业务数据源地址"}, index = 0) + private String businessDatabase; + + @ColumnWidth(25) + @ExcelProperty(value = {"Takin为您生成了影子库账号和密码(如不用系统生成的账号或密码,请替换新的账号密码到此表中", "隔离方案"}, index = 1) + private String isolateType; + + @ColumnWidth(50) + @ExcelProperty(value = {"Takin为您生成了影子库账号和密码(如不用系统生成的账号或密码,请替换新的账号密码到此表中", "影子数据源地址(请提供)"}, index = 2) + private String shadowDatabase; + + @ColumnWidth(25) + @ExcelProperty(value = {"Takin为您生成了影子库账号和密码(如不用系统生成的账号或密码,请替换新的账号密码到此表中", "影子库账号"}, index = 3) + private String shadowUsername; + + @ColumnWidth(25) + @ExcelProperty(value = {"Takin为您生成了影子库账号和密码(如不用系统生成的账号或密码,请替换新的账号密码到此表中", "影子库密码"}, index = 4) + private String shadowPassword; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/ShadowTableExcelVO.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/ShadowTableExcelVO.java new file mode 100644 index 0000000000..3e73aec74f --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/ShadowTableExcelVO.java @@ -0,0 +1,31 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.metadata.BaseRowModel; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class ShadowTableExcelVO extends BaseRowModel implements Serializable { + @ColumnWidth(50) + @ExcelProperty(value = "业务数据源地址", index = 0) + private String businessDatabase; + + @ColumnWidth(30) + @ExcelProperty(value = "隔离方式", index = 1) + private String isolateType; + + @ColumnWidth(30) + @ExcelProperty(value = "业务库", index = 2) + private String database; + + @ColumnWidth(30) + @ExcelProperty(value = "业务表", index = 3) + private String businessTable; + + @ColumnWidth(30) + @ExcelProperty(value = "是否加入影子表(请提供)", index = 4) + private String shadowTable; +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/DataSourceConfig.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/DataSourceConfig.java new file mode 100644 index 0000000000..25905eddd6 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/DataSourceConfig.java @@ -0,0 +1,114 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; +import java.util.List; + +public class DataSourceConfig implements Serializable { + + /** + * 业务库url + */ + private String url; + + /** + * 业务库用户名 + */ + private String username; + + /** + * 数据源类型 0:影子库 1:影子表 2:影子库+影子表 + */ + private int shadowType; + + /** + * 影子库url + */ + private String shadowUrl; + + /** + * 影子库用户名 + */ + private String shadowUsername; + + /** + * 影子库密码 + */ + private String shadowPassword; + + /** + * 启用 或 禁用 + */ + private boolean disabled; + + + /** + * 业务表名称 + */ + private List bizTables; + + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getShadowUrl() { + return shadowUrl; + } + + public void setShadowUrl(String shadowUrl) { + this.shadowUrl = shadowUrl; + } + + public String getShadowUsername() { + return shadowUsername; + } + + public void setShadowUsername(String shadowUsername) { + this.shadowUsername = shadowUsername; + } + + public String getShadowPassword() { + return shadowPassword; + } + + public void setShadowPassword(String shadowPassword) { + this.shadowPassword = shadowPassword; + } + + public int getShadowType() { + return shadowType; + } + + public void setShadowType(int shadowType) { + this.shadowType = shadowType; + } + + + public boolean isDisabled() { + return disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public List getBizTables() { + return bizTables; + } + + public void setBizTables(List bizTables) { + this.bizTables = bizTables; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/DataSourceEntity.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/DataSourceEntity.java new file mode 100644 index 0000000000..c0ae6483f6 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/DataSourceEntity.java @@ -0,0 +1,52 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; + +public class DataSourceEntity implements Serializable { + + private String url; + private String userName; + private String password; + private String driverClassName; + private String connectionPool; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getDriverClassName() { + return driverClassName; + } + + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + public String getConnectionPool() { + return connectionPool; + } + + public void setConnectionPool(String connectionPool) { + this.connectionPool = connectionPool; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/JdbcTableCompareCommand.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/JdbcTableCompareCommand.java new file mode 100644 index 0000000000..3cf5844790 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/JdbcTableCompareCommand.java @@ -0,0 +1,44 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; +import java.util.List; + +public class JdbcTableCompareCommand implements Serializable { + + private Integer shadowType; + private List tables; + private DataSourceEntity bizDataSource; + private DataSourceEntity shadowDataSource; + + public Integer getShadowType() { + return shadowType; + } + + public void setShadowType(Integer shadowType) { + this.shadowType = shadowType; + } + + public List getTables() { + return tables; + } + + public void setTables(List tables) { + this.tables = tables; + } + + public DataSourceEntity getBizDataSource() { + return bizDataSource; + } + + public void setBizDataSource(DataSourceEntity bizDataSource) { + this.bizDataSource = bizDataSource; + } + + public DataSourceEntity getShadowDataSource() { + return shadowDataSource; + } + + public void setShadowDataSource(DataSourceEntity shadowDataSource) { + this.shadowDataSource = shadowDataSource; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/JdbcTableConfig.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/JdbcTableConfig.java new file mode 100644 index 0000000000..5e8221d930 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/JdbcTableConfig.java @@ -0,0 +1,22 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; +import java.util.List; + +/** + * @author guann1n9 + * @date 2022/9/14 8:13 PM + */ +public class JdbcTableConfig implements Serializable { + + private List data; + + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/Response.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/Response.java new file mode 100644 index 0000000000..0880e2d0a7 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/Response.java @@ -0,0 +1,73 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Data; + +/** + * @author guann1n9 + * @date 2022/5/5 5:29 PM + */ +@Data +@Builder +public class Response { + public Response() { + } + + public Response(Integer code, String message, T data) { + this.code = code; + this.message = message; + this.data = data; + } + + /** + * 200正常 401 未获取到登录信息 500异常 + */ + public static Integer SUCCESS = 200; + + public static Integer AUTH_ERROR = 401; + + public static Integer SERVER_ERROR = 500; + + + /** + * 响应码 200正常 401 未获取到登录信息 500异常 + */ + @ApiModelProperty("响应码 200正常 401 未获取到登录信息 500异常") + private Integer code; + + /** + * 响应消息 + */ + @ApiModelProperty("响应消息") + private String message; + + /** + * 业务返回 + */ + @ApiModelProperty("业务返回") + private T data; + + + public static Response success(T data) { + return Response.builder().code(200).message("Success").data(data).build(); + } + + public static Response success(T data, String message) { + return Response.builder().code(200).message(message).data(data).build(); + } + + public static Response error(String message) { + return Response.error(SERVER_ERROR, message); + } + + public static Response authError(String message) { + return Response.error(AUTH_ERROR, message); + } + + public static Response error(Integer code, String message) { + return Response.builder().code(code).message(message).data(null).build(); + } + + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/SfKakfaConfig.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/SfKakfaConfig.java new file mode 100644 index 0000000000..5ebb4ae781 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/SfKakfaConfig.java @@ -0,0 +1,135 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import com.alibaba.fastjson.JSON; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MqConsumerFeature; +import io.shulie.takin.web.biz.service.pressureresource.common.MqTypeEnum; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateMqConsumerEntity; +import org.springframework.util.StringUtils; + +import java.io.Serializable; + +/** + * @author guann1n9 + * @date 2022/10/17 5:16 PM + */ +public class SfKakfaConfig implements Serializable { + + private String key; + + private String topic; + + private String topicTokens; + + private String group; + + private String systemIdToken; + + private String clusterName; + + private String monitorUrl; + + private Integer poolSize; + + private Integer messageConsumeThreadCount; + + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getTopicTokens() { + return topicTokens; + } + + public void setTopicTokens(String topicTokens) { + this.topicTokens = topicTokens; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public String getSystemIdToken() { + return systemIdToken; + } + + public void setSystemIdToken(String systemIdToken) { + this.systemIdToken = systemIdToken; + } + + public String getClusterName() { + return clusterName; + } + + public void setClusterName(String clusterName) { + this.clusterName = clusterName; + } + + public String getMonitorUrl() { + return monitorUrl; + } + + public void setMonitorUrl(String monitorUrl) { + this.monitorUrl = monitorUrl; + } + + public Integer getPoolSize() { + return poolSize; + } + + public void setPoolSize(Integer poolSize) { + this.poolSize = poolSize; + } + + public Integer getMessageConsumeThreadCount() { + return messageConsumeThreadCount; + } + + public void setMessageConsumeThreadCount(Integer messageConsumeThreadCount) { + this.messageConsumeThreadCount = messageConsumeThreadCount; + } + + + /** + * 对象转换 + * @param mqConsumerEntity + * @return + */ + public static SfKakfaConfig mapping(PressureResourceRelateMqConsumerEntity mqConsumerEntity){ + if(!mqConsumerEntity.getMqType().equals(MqTypeEnum.SF_KAKFA.getCode())){ + //非顺丰kafka配置,跳过 + return null; + } + SfKakfaConfig sfKakfaConfig = new SfKakfaConfig(); + sfKakfaConfig.setKey(mqConsumerEntity.getTopic()); + sfKakfaConfig.setTopic(mqConsumerEntity.getTopic()); + sfKakfaConfig.setTopicTokens(mqConsumerEntity.getTopicTokens()); + sfKakfaConfig.setGroup(mqConsumerEntity.getGroup()); + sfKakfaConfig.setSystemIdToken(mqConsumerEntity.getSystemIdToken()); + if(!StringUtils.hasText(mqConsumerEntity.getFeature())){ + return sfKakfaConfig; + } + MqConsumerFeature mqConsumerFeature = JSON.parseObject(mqConsumerEntity.getFeature(), MqConsumerFeature.class); + sfKakfaConfig.setClusterName(mqConsumerFeature.getClusterName()); + sfKakfaConfig.setMonitorUrl(mqConsumerFeature.getClusterAddr()); + sfKakfaConfig.setPoolSize(mqConsumerFeature.getProviderThreadCount()); + sfKakfaConfig.setMessageConsumeThreadCount(mqConsumerFeature.getConsumerThreadCount()); + return sfKakfaConfig; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinAck.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinAck.java new file mode 100644 index 0000000000..67fa121e17 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinAck.java @@ -0,0 +1,66 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +/** + * @author guann1n9 + * @date 2022/9/14 11:56 PM + */ +public class TakinAck { + + public static final String COMMAND = "COMMAND"; + + public static final String CONFIG = "CONFIG"; + + private String tenantCode; + + + private String envCode; + + + private String appName; + + + private String ackType; + + private T ack; + + + public String getTenantCode() { + return tenantCode; + } + + public void setTenantCode(String tenantCode) { + this.tenantCode = tenantCode; + } + + public String getEnvCode() { + return envCode; + } + + public void setEnvCode(String envCode) { + this.envCode = envCode; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getAckType() { + return ackType; + } + + public void setAckType(String ackType) { + this.ackType = ackType; + } + + public T getAck() { + return ack; + } + + public void setAck(T ack) { + this.ack = ack; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinCommand.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinCommand.java new file mode 100644 index 0000000000..c576965542 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinCommand.java @@ -0,0 +1,93 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; + +/** + * @author guann1n9 + * @date 2022/9/14 10:16 AM + */ +public class TakinCommand implements Serializable { + + public static final String SIMULATOR_AGENT = "simulator-agent"; + + /** + * resource id 确保唯一 + */ + private String commandId; + + + private String commandType; + + + private String tenantCode; + + + private String agentSpecification; + + + private String envCode; + + + private String appName; + + + private String commandParam; + + + public String getCommandId() { + return commandId; + } + + public void setCommandId(String commandId) { + this.commandId = commandId; + } + + public String getCommandType() { + return commandType; + } + + public String getAgentSpecification() { + return agentSpecification; + } + + public void setAgentSpecification(String agentSpecification) { + this.agentSpecification = agentSpecification; + } + + public void setCommandType(String commandType) { + this.commandType = commandType; + } + + public String getTenantCode() { + return tenantCode; + } + + public void setTenantCode(String tenantCode) { + this.tenantCode = tenantCode; + } + + public String getEnvCode() { + return envCode; + } + + public void setEnvCode(String envCode) { + this.envCode = envCode; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getCommandParam() { + return commandParam; + } + + public void setCommandParam(String commandParam) { + this.commandParam = commandParam; + } + +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinCommandAck.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinCommandAck.java new file mode 100644 index 0000000000..40d3e3d425 --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinCommandAck.java @@ -0,0 +1,64 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; + +/** + * @author guann1n9 + * @date 2022/9/14 1:46 PM + */ +public class TakinCommandAck implements Serializable { + + /** + * 命令id + */ + private String commandId; + + /** + * 命令类型 + */ + private String commandType; + + /** + * 探针检查结果 + */ + private boolean success; + + /** + * 命令响应 + */ + private String response; + + + public String getCommandId() { + return commandId; + } + + public void setCommandId(String commandId) { + this.commandId = commandId; + } + + public String getCommandType() { + return commandType; + } + + public void setCommandType(String commandType) { + this.commandType = commandType; + } + + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinConfig.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinConfig.java new file mode 100644 index 0000000000..5e72a5b8be --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinConfig.java @@ -0,0 +1,99 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; + +/** + * @author guann1n9 + * @date 2022/9/14 10:12 PM + */ +public class TakinConfig implements Serializable { + + /** + * resource id 确保唯一 + */ + private String configId; + + + private String configType; + + + private String tenantCode; + + + private String envCode; + + + private String appName; + + + private String agentSpecification; + + + private String configParam; + + private String nacosServerAddr; + + public String getConfigId() { + return configId; + } + + public void setConfigId(String configId) { + this.configId = configId; + } + + public String getConfigType() { + return configType; + } + + public void setConfigType(String configType) { + this.configType = configType; + } + + public String getConfigParam() { + return configParam; + } + + public void setConfigParam(String configParam) { + this.configParam = configParam; + } + + public String getAgentSpecification() { + return agentSpecification; + } + + public void setAgentSpecification(String agentSpecification) { + this.agentSpecification = agentSpecification; + } + + public String getTenantCode() { + return tenantCode; + } + + public void setTenantCode(String tenantCode) { + this.tenantCode = tenantCode; + } + + public String getEnvCode() { + return envCode; + } + + public void setEnvCode(String envCode) { + this.envCode = envCode; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getNacosServerAddr() { + return nacosServerAddr; + } + + public void setNacosServerAddr(String nacosServerAddr) { + this.nacosServerAddr = nacosServerAddr; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinConfigAck.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinConfigAck.java new file mode 100644 index 0000000000..4efffa895e --- /dev/null +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/pressureresource/vo/agent/command/TakinConfigAck.java @@ -0,0 +1,57 @@ +package io.shulie.takin.web.biz.service.pressureresource.vo.agent.command; + +import java.io.Serializable; + +/** + * @author guann1n9 + * @date 2022/9/14 10:12 PM + */ +public class TakinConfigAck implements Serializable { + + /** + * resource id 确保唯一 + */ + private String configId; + + + private String configType; + + + private boolean success; + + + private String response; + + + public String getConfigId() { + return configId; + } + + public void setConfigId(String configId) { + this.configId = configId; + } + + public String getConfigType() { + return configType; + } + + public void setConfigType(String configType) { + this.configType = configType; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } +} diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/report/impl/ReportServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/report/impl/ReportServiceImpl.java index a3dbf4567f..8afa101b1c 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/report/impl/ReportServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/report/impl/ReportServiceImpl.java @@ -103,9 +103,12 @@ public ResponseResult> listReport(ReportQueryParam param) { ResponseResult> reportResponseList = cloudReportApi.listReport(new ReportQueryReq() {{ setSceneId(param.getSceneId()); setReportId(param.getReportId()); + setDeptId(param.getDeptId()); setSceneName(param.getSceneName()); setStartTime(param.getStartTime()); setEndTime(param.getEndTime()); + setUserIds(WebPluginUtils.queryAllowUserIdList()); + setDeptIds(WebPluginUtils.queryAllowDeptIdList()); setPageSize(param.getPageSize()); setPageNumber(param.getCurrentPage() + 1); setFilterSql(String.join(",", userIdList)); @@ -123,6 +126,7 @@ public ResponseResult> listReport(ReportQueryParam param) { ReportDTO result = BeanUtil.copyProperties(t, ReportDTO.class); result.setUserName(userName); result.setUserId(userId); + WebPluginUtils.fillQueryResponse(result); return result; }).collect(Collectors.toList()); return ResponseResult.success(dtoList, reportResponseList.getTotalNum()); @@ -193,17 +197,6 @@ public ReportDetailTempOutput tempReportDetail(Long sceneId) { ReportDetailTempOutput output = new ReportDetailTempOutput(); BeanUtils.copyProperties(result, output); - List allowStartStopUserIdList = WebPluginUtils.getStartStopAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowStartStopUserIdList)) { - Long userId = output.getUserId(); - if (userId == null || !allowStartStopUserIdList.contains(userId)) { - output.setCanStartStop(Boolean.FALSE); - } else { - output.setCanStartStop(Boolean.TRUE); - } - } else { - output.setCanStartStop(Boolean.TRUE); - } fillExecuteMan(output); return output; diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/ApplicationBusinessActivityServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/ApplicationBusinessActivityServiceImpl.java index 22a1e2787c..9fa5314787 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/ApplicationBusinessActivityServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/ApplicationBusinessActivityServiceImpl.java @@ -47,17 +47,17 @@ public class ApplicationBusinessActivityServiceImpl implements ApplicationBusine @Override public List processAppNameByBusinessActiveId(Long businessActivityId) { BusinessLinkManageTableEntity businessLinkManageTableEntity = businessLinkManageTableMapper.selectById( - businessActivityId); + businessActivityId); if (businessLinkManageTableEntity == null) { return Lists.newArrayList(); } // 虚拟入口 返回数据 if (businessLinkManageTableEntity.getType() != null && businessLinkManageTableEntity.getType().equals( - BusinessTypeEnum.VIRTUAL_BUSINESS.getType())) { + BusinessTypeEnum.VIRTUAL_BUSINESS.getType())) { return Lists.newArrayList(); } LinkManageTableEntity linkManageTableEntity = linkManageTableMapper.selectById( - businessLinkManageTableEntity.getRelatedTechLink()); + businessLinkManageTableEntity.getRelatedTechLink()); if (linkManageTableEntity == null) { return Lists.newArrayList(); } @@ -72,7 +72,7 @@ public List processAppNameByBusinessActiveId(Long businessActivityId) { String extend = map.get(FeaturesConstants.EXTEND_KEY); LinkTopologyDTO applicationEntrancesTopology = applicationEntranceClient.getApplicationEntrancesTopology( false, linkManageTableEntity.getApplicationName(), - null, serviceName, methodName, rpcType, extend); + null, serviceName, methodName, rpcType, extend, false); if (applicationEntrancesTopology == null) { return Lists.newArrayList(); } @@ -81,8 +81,8 @@ public List processAppNameByBusinessActiveId(Long businessActivityId) { return Lists.newArrayList(); } return nodes.stream() - .filter(node -> node.getNodeType().equals(NodeTypeEnum.APP.getType())) - .map(LinkNodeDTO::getNodeName) - .collect(Collectors.toList()); + .filter(node -> node.getNodeType().equals(NodeTypeEnum.APP.getType())) + .map(LinkNodeDTO::getNodeName) + .collect(Collectors.toList()); } } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/SceneServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/SceneServiceImpl.java index 5b9da1af3c..190887477d 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/SceneServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scene/impl/SceneServiceImpl.java @@ -7,7 +7,10 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.pamirs.takin.entity.domain.dto.linkmanage.ScriptJmxNode; import io.shulie.takin.cloud.common.utils.CommonUtil; @@ -30,6 +33,7 @@ import io.shulie.takin.web.biz.pojo.request.linkmanage.BusinessFlowParseRequest; import io.shulie.takin.web.biz.pojo.request.linkmanage.BusinessFlowUpdateRequest; import io.shulie.takin.web.biz.pojo.request.linkmanage.SceneLinkRelateRequest; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceInput; import io.shulie.takin.web.biz.pojo.request.scriptmanage.PluginConfigCreateRequest; import io.shulie.takin.web.biz.pojo.request.scriptmanage.ScriptManageDeployCreateRequest; import io.shulie.takin.web.biz.pojo.request.scriptmanage.ScriptManageDeployUpdateRequest; @@ -40,6 +44,7 @@ import io.shulie.takin.web.biz.pojo.response.linkmanage.BusinessFlowThreadResponse; import io.shulie.takin.web.biz.pojo.response.scriptmanage.ScriptManageDeployDetailResponse; import io.shulie.takin.web.biz.service.ActivityService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceService; import io.shulie.takin.web.biz.service.scene.ApplicationBusinessActivityService; import io.shulie.takin.web.biz.service.scene.SceneService; import io.shulie.takin.web.biz.service.scenemanage.SceneManageService; @@ -61,8 +66,10 @@ import io.shulie.takin.web.data.dao.linkmanage.SceneDAO; import io.shulie.takin.web.data.dao.scene.SceneLinkRelateDAO; import io.shulie.takin.web.data.dao.scriptmanage.ScriptManageDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; import io.shulie.takin.web.data.mapper.mysql.SceneMapper; import io.shulie.takin.web.data.model.mysql.SceneEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; import io.shulie.takin.web.data.param.activity.ActivityExistsQueryParam; import io.shulie.takin.web.data.param.activity.ActivityQueryParam; import io.shulie.takin.web.data.param.linkmanage.SceneCreateParam; @@ -134,6 +141,8 @@ public class SceneServiceImpl implements SceneService { private ApplicationBusinessActivityService applicationBusinessActivityService; @Resource private ApplicationDAO applicationDAO; + @Resource + private PressureResourceMapper pressureResourceMapper; @Override public List nodeLinkToBusinessActivity(List nodes, Long sceneId) { @@ -279,13 +288,19 @@ public BusinessFlowDetailResponse parseScriptAndSave(BusinessFlowParseRequest bu } testPlanName = testPlan.get(0).getTestName(); } + boolean isPressureResouce = false; + if (businessFlowParseRequest.getId() != null) { + SceneResult sceneResult = sceneDao.getSceneDetail(businessFlowParseRequest.getId()); + isPressureResouce = sceneResult.isPressureResource(); + testPlanName = sceneResult.getSceneName(); + } String businessFlowName = null; - if (businessFlowParseRequest.getId() == null) { - SceneCreateParam createParam = saveBusinessFlow(businessFlowParseRequest.getSource(), testPlanName, data, fileManageCreateRequest, businessFlowParseRequest.getPluginList()); + if (isPressureResouce || businessFlowParseRequest.getId() == null) { + SceneCreateParam createParam = saveBusinessFlow(businessFlowParseRequest.getSource(), testPlanName, data, fileManageCreateRequest, businessFlowParseRequest.getPluginList(), isPressureResouce, businessFlowParseRequest.getId()); businessFlowParseRequest.setId(createParam.getId()); businessFlowName = createParam.getSceneName(); } else { - SceneResult sceneResult = updateBusinessFlow(businessFlowParseRequest.getId(), businessFlowParseRequest.getScriptFile(), null, data, businessFlowParseRequest.getPluginList()); + SceneResult sceneResult = updateBusinessFlow(businessFlowParseRequest.getId(), businessFlowParseRequest.getScriptFile(), null, data, businessFlowParseRequest.getPluginList(), testPlanName); businessFlowName = sceneResult.getSceneName(); } @@ -297,27 +312,29 @@ public BusinessFlowDetailResponse parseScriptAndSave(BusinessFlowParseRequest bu @Transactional(rollbackFor = Exception.class) public SceneCreateParam saveBusinessFlow(Integer source, String testName, List data, FileManageUpdateRequest fileManageCreateRequest, - List pluginList) { - SceneQueryParam sceneQueryParam = new SceneQueryParam(); - sceneQueryParam.setSceneName(testName); - List sceneResultList = sceneDao.selectListByName(sceneQueryParam); - if (CollectionUtils.isNotEmpty(sceneResultList)) { - testName = testName + "_" + DateUtil.formatDateTime(new Date()); - } - //保存业务流程 + List pluginList, boolean isPressureResource, Long extId) { SceneCreateParam sceneCreateParam = new SceneCreateParam(); sceneCreateParam.setSceneName(testName); - sceneCreateParam.setLinkRelateNum(0); - sceneCreateParam.setScriptJmxNode(JsonHelper.bean2Json(data)); - sceneCreateParam.setTotalNodeNum(JmxUtil.getNodeNumByType(NodeTypeEnum.SAMPLER, data)); - if (source != null) { - sceneCreateParam.setType(source); - } else { - sceneCreateParam.setType(SceneTypeEnum.JMETER_UPLOAD_SCENE.getType()); + sceneCreateParam.setId(extId); + sceneCreateParam.setDeptId(WebPluginUtils.traceDeptId()); + if (!isPressureResource) { + SceneQueryParam sceneQueryParam = new SceneQueryParam(); + sceneQueryParam.setSceneName(testName); + List sceneResultList = sceneDao.selectListByName(sceneQueryParam); + if (CollectionUtils.isNotEmpty(sceneResultList)) { + testName = testName + "_" + DateUtil.formatDateTime(new Date()); + } + sceneCreateParam.setLinkRelateNum(0); + sceneCreateParam.setScriptJmxNode(JsonHelper.bean2Json(data)); + sceneCreateParam.setTotalNodeNum(JmxUtil.getNodeNumByType(NodeTypeEnum.SAMPLER, data)); + if (source != null) { + sceneCreateParam.setType(source); + } else { + sceneCreateParam.setType(SceneTypeEnum.JMETER_UPLOAD_SCENE.getType()); + } + WebPluginUtils.fillCloudUserData(sceneCreateParam); + sceneDao.insert(sceneCreateParam); } - WebPluginUtils.fillCloudUserData(sceneCreateParam); - sceneDao.insert(sceneCreateParam); - //新增脚本文件 ScriptManageDeployCreateRequest createRequest = new ScriptManageDeployCreateRequest(); //脚本文件名称去重 @@ -343,6 +360,10 @@ public SceneCreateParam saveBusinessFlow(Integer source, String testName, List scriptNodes = JsonHelper.json2List(sceneResult.getScriptJmxNode(), ScriptNode.class); //将节点树处理成线程组在最外层的形式 List scriptNodeByType = JmxUtil.getScriptNodeByType(NodeTypeEnum.THREAD_GROUP, scriptNodes); @@ -405,7 +430,7 @@ public SceneResult getScene(Long id) { @Override public BusinessFlowDetailResponse uploadDataFile(BusinessFlowDataFileRequest businessFlowDataFileRequest) { - updateBusinessFlow(businessFlowDataFileRequest.getId(), null, businessFlowDataFileRequest, null, businessFlowDataFileRequest.getPluginList()); + updateBusinessFlow(businessFlowDataFileRequest.getId(), null, businessFlowDataFileRequest, null, businessFlowDataFileRequest.getPluginList(), ""); BusinessFlowDetailResponse result = new BusinessFlowDetailResponse(); result.setId(businessFlowDataFileRequest.getId()); return result; @@ -637,8 +662,10 @@ public PagingList getBusinessFlowList(BusinessFlowPage queryParam.setSceneName(flowName == null ? null : flowName.replace("%", "\\%").replace("-", "\\-").replace("_", "\\_")); queryParam.setCurrent(queryRequest.getCurrent()); queryParam.setPageSize(queryRequest.getPageSize()); + queryParam.setDeptId(queryRequest.getDeptId()); WebPluginUtils.fillQueryParam(queryParam); queryParam.setIgnoreType(SceneTypeEnum.PERFORMANCE_AUTO_SCENE.getType()); + queryParam.setQueryGmtModified(queryRequest.getQueryGmtModified()); PagingList pageList = sceneDao.selectPageList(queryParam); List responses = LinkManageConvert.INSTANCE.ofSceneResultList(pageList.getList()); @@ -651,6 +678,7 @@ public PagingList getBusinessFlowList(BusinessFlowPage if (user != null) { r.setUserName(user.getName()); } + WebPluginUtils.fillQueryResponse(r); }); } return PagingList.of(responses, pageList.getTotal()); @@ -680,6 +708,9 @@ public List businessActivityFlowList() { if (CollectionUtils.isNotEmpty(queryParam.getUserIdList())) { wrapper.in(SceneEntity::getUserId, queryParam.getUserIdList()); } + if (CollectionUtils.isNotEmpty(queryParam.getDeptIdList())){ + wrapper.in(SceneEntity::getDeptId, queryParam.getDeptIdList()); + } return sceneMapper.selectList(wrapper); } @@ -726,12 +757,22 @@ public void updateBusinessFlow(BusinessFlowUpdateRequest businessFlowUpdateReque sceneUpdateParam.setSceneLevel(businessFlowUpdateRequest.getSceneLevel()); sceneUpdateParam.setIsCore(businessFlowUpdateRequest.getIsCore()); sceneDao.update(sceneUpdateParam); + + // 同步更新压测准备 + if (StringUtils.isNotBlank(businessFlowUpdateRequest.getSceneName())) { + PressureResourceEntity entity = new PressureResourceEntity(); + entity.setName(businessFlowUpdateRequest.getSceneName()); + entity.setGmtModified(new Date()); + QueryWrapper updateWrapper = new QueryWrapper<>(); + updateWrapper.eq("source_id", businessFlowUpdateRequest.getId()); + pressureResourceMapper.update(entity, updateWrapper); + } } @Transactional(rollbackFor = Exception.class) public SceneResult updateBusinessFlow(Long businessFlowId, FileManageUpdateRequest scriptFile, BusinessFlowDataFileRequest businessFlowDataFileRequest, List data, - List pluginList) { + List pluginList, String testPlanName) { SceneResult sceneResult = sceneDao.getSceneDetail(businessFlowId); if (sceneResult == null) { throw new TakinWebException(TakinWebExceptionEnum.LINK_QUERY_ERROR, "没有找到对应的业务流程!"); @@ -742,9 +783,8 @@ public SceneResult updateBusinessFlow(Long businessFlowId, FileManageUpdateReque if (scriptManageDeployResult == null) { throw new TakinWebException(TakinWebExceptionEnum.LINK_QUERY_ERROR, "没有找到业务流程对应的脚本!"); } - ScriptManageDeployDetailResponse result = scriptManageService.getScriptManageDeployDetail(oldScriptDeployId); - List fileManageResponseList = result.getFileManageResponseList(); + List fileManageResponseList = fileManageResponseList = result.getFileManageResponseList(); ScriptManageDeployUpdateRequest updateRequest = new ScriptManageDeployUpdateRequest(); updateRequest.setId(oldScriptDeployId); updateRequest.setMVersion(ScriptMVersionEnum.SCRIPT_M_1.getCode()); @@ -783,7 +823,9 @@ public SceneResult updateBusinessFlow(Long businessFlowId, FileManageUpdateReque updateFileManageRequests.add(scriptFile); updateFileManageRequests.addAll(LinkManageConvert.INSTANCE.ofFileManageResponseList(dataFileManageResponseList)); // 将最新的附件信息处理合并到一起 - updateFileManageRequests.addAll(LinkManageConvert.INSTANCE.ofFileManageResponseList(result.getAttachmentManageResponseList())); + if (CollectionUtils.isNotEmpty(result.getAttachmentManageResponseList())) { + updateFileManageRequests.addAll(LinkManageConvert.INSTANCE.ofFileManageResponseList(result.getAttachmentManageResponseList())); + } updateRequest.setFileManageUpdateRequests(updateFileManageRequests); } // 设置插件信息 diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ScriptManageServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ScriptManageServiceImpl.java index 5fbd0cc082..fdcf79bbde 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ScriptManageServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ScriptManageServiceImpl.java @@ -1349,10 +1349,15 @@ public PagingList pageQueryScriptManage( scriptManageDeployPageQueryParam.setCurrent(scriptManageDeployPageQueryRequest.getCurrent()); scriptManageDeployPageQueryParam.setPageSize(scriptManageDeployPageQueryRequest.getPageSize()); scriptManageDeployPageQueryParam.setScriptType(0); - List userIdList = WebPluginUtils.getQueryAllowUserIdList(); + List userIdList = WebPluginUtils.queryAllowUserIdList(); if (CollectionUtils.isNotEmpty(userIdList)) { scriptManageDeployPageQueryParam.setUserIdList(userIdList); } + List deptIdList = WebPluginUtils.queryAllowDeptIdList(); + if (CollectionUtils.isNotEmpty(deptIdList)){ + scriptManageDeployPageQueryParam.setDeptIdList(deptIdList); + } + scriptManageDeployPageQueryParam.setDeptId(scriptManageDeployPageQueryRequest.getDeptId()); PagingList scriptManageDeployResults = scriptManageDAO .pageQueryRecentScriptManageDeploy( scriptManageDeployPageQueryParam); @@ -1365,9 +1370,6 @@ public PagingList pageQueryScriptManage( .collect(Collectors.toList()); //用户信息Map key:userId value:user对象 Map userMap = WebPluginUtils.getUserMapByIds(userIds); - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); - List allowDownloadUserIdList = WebPluginUtils.getDownloadAllowUserIdList(); List scriptManageDeployResponses = scriptManageDeployResults.getList().stream() .map(scriptManageDeployResult -> { ScriptManageDeployResponse scriptManageDeployResponse = new ScriptManageDeployResponse(); @@ -1378,8 +1380,6 @@ public PagingList pageQueryScriptManage( .map(UserExt::getName).orElse(""); scriptManageDeployResponse.setUserName(userName); - WebPluginUtils.fillQueryResponse(scriptManageDeployResponse); - //m1版本不能在脚本管理页面进行编辑和删除操作 if (ScriptMVersionEnum.isM_1(scriptManageDeployResult.getMVersion())) { scriptManageDeployResponse.setCanEdit(false); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ShellScriptManageServiceImpl.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ShellScriptManageServiceImpl.java index 873e9d9503..0b7911c01e 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ShellScriptManageServiceImpl.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/scriptmanage/ShellScriptManageServiceImpl.java @@ -345,10 +345,14 @@ public PagingList pageQueryScriptManage(ShellScriptMana queryParam.setPageSize(input.getPageSize()); // 脚本类型 queryParam.setScriptType(1); - List userIdList = WebPluginUtils.getQueryAllowUserIdList(); + List userIdList = WebPluginUtils.queryAllowUserIdList(); if (CollectionUtils.isNotEmpty(userIdList)) { queryParam.setUserIdList(userIdList); } + List deptIdList = WebPluginUtils.queryAllowDeptIdList(); + if (CollectionUtils.isNotEmpty(deptIdList)) { + queryParam.setDeptIdList(deptIdList); + } PagingList scriptManageDeployResults = scriptManageDAO .pageQueryRecentScriptManageDeploy(queryParam); if (CollectionUtils.isEmpty(scriptManageDeployResults.getList())) { @@ -359,23 +363,13 @@ public PagingList pageQueryScriptManage(ShellScriptMana ScriptManageDeployResult::getUserId).collect(Collectors.toList()); //用户信息Map key:userId value:user对象 Map userMap = WebPluginUtils.getUserMapByIds(userIds); - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); + List outputs = scriptManageDeployResults.getList().stream().map( scriptManageDeployResult -> { ShellScriptManageOutput shellScriptManageOutput = new ShellScriptManageOutput(); BeanUtils.copyProperties(scriptManageDeployResult, shellScriptManageOutput); shellScriptManageOutput.setScripDeployId(scriptManageDeployResult.getId()); - if (CollectionUtils.isNotEmpty(allowUpdateUserIdList)) { - shellScriptManageOutput.setCanEdit( - allowUpdateUserIdList.contains(scriptManageDeployResult.getUserId())); - } - if (CollectionUtils.isNotEmpty(allowDeleteUserIdList)) { - shellScriptManageOutput.setCanRemove( - allowDeleteUserIdList.contains(scriptManageDeployResult.getUserId())); - } - //负责人id shellScriptManageOutput.setUserId(scriptManageDeployResult.getUserId()); //负责人名称 @@ -383,6 +377,7 @@ public PagingList pageQueryScriptManage(ShellScriptMana .map(UserExt::getName) .orElse(""); shellScriptManageOutput.setUserName(userName); + WebPluginUtils.fillQueryResponse(shellScriptManageOutput); return shellScriptManageOutput; }).collect(Collectors.toList()); setTagList(outputs); diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/simplify/ShadowJobConfigService.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/simplify/ShadowJobConfigService.java index ebd1c9123e..ec9669610e 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/simplify/ShadowJobConfigService.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/service/simplify/ShadowJobConfigService.java @@ -20,6 +20,8 @@ import io.shulie.takin.web.biz.utils.Estimate; import io.shulie.takin.web.biz.utils.XmlUtil; import io.shulie.takin.web.common.common.Response; +import io.shulie.takin.web.common.exception.TakinWebException; +import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; import io.shulie.takin.web.data.dao.application.ApplicationDAO; import io.shulie.takin.web.data.dao.application.ApplicationShadowJobDAO; import io.shulie.takin.web.data.param.application.ShadowJobCreateParam; @@ -212,7 +214,10 @@ public Response queryByPage(ShadowJobConfigQuery query) { if (StringUtils.isBlank(query.getOrderBy())) { query.setOrderBy("id desc"); } - query.setUserIds(WebPluginUtils.getQueryAllowUserIdList()); + ApplicationDetailResult applicationById = applicationDAO.getApplicationById(query.getApplicationId()); + if (applicationById == null){ + throw new TakinWebException(TakinWebExceptionEnum.APPLICATION_MANAGE_NO_EXIST_ERROR, "当前应用不存在"); + } List tShadowJobConfigs = tShadowJobConfigMapper.selectList(query); PageInfo pageInfo = new PageInfo<>(tShadowJobConfigs); List configVos = new ArrayList<>(); @@ -229,18 +234,8 @@ public Response queryByPage(ShadowJobConfigQuery query) { vo.setActive(tShadowJobConfig.getActive()); vo.setUpdateTime(tShadowJobConfig.getUpdateTime()); vo.setRemark(tShadowJobConfig.getRemark()); - List allowUpdateUserIdList = WebPluginUtils.getUpdateAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowUpdateUserIdList)) { - vo.setCanEdit(allowUpdateUserIdList.contains(tShadowJobConfig.getUserId())); - } - List allowDeleteUserIdList = WebPluginUtils.getDeleteAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowDeleteUserIdList)) { - vo.setCanRemove(allowDeleteUserIdList.contains(tShadowJobConfig.getUserId())); - } - List allowEnableDisableUserIdList = WebPluginUtils.getEnableDisableAllowUserIdList(); - if (CollectionUtils.isNotEmpty(allowEnableDisableUserIdList)) { - vo.setCanEnableDisable(allowEnableDisableUserIdList.contains(tShadowJobConfig.getUserId())); - } + + vo.setDeptId(applicationById.getDeptId()); vo.setUserId(tShadowJobConfig.getUserId()); WebPluginUtils.fillQueryResponse(vo); configVos.add(vo); @@ -260,7 +255,6 @@ public List queryByAppName(String appName) { query.setOrderBy("id desc"); } query.setApplicationId(tApplicationMnt.getApplicationId()); - query.setUserIds(WebPluginUtils.getQueryAllowUserIdList()); List tShadowJobConfigs = tShadowJobConfigMapper.selectList(query); try { for (TShadowJobConfig tShadowJobConfig : tShadowJobConfigs) { diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/ZkHelper.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/PradarConfigPusher.java similarity index 57% rename from takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/ZkHelper.java rename to takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/PradarConfigPusher.java index 87ccdcb8c6..50c8461600 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/ZkHelper.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/PradarConfigPusher.java @@ -2,6 +2,11 @@ import javax.annotation.PostConstruct; +import com.alibaba.fastjson.JSON; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; @@ -11,13 +16,16 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.Map; +import java.util.Properties; + /** * @author liuchuan * @date 2021/11/11 8:59 下午 */ @Slf4j @Service -public class ZkHelper { +public class PradarConfigPusher { @Value("${takin.config.zk.addr}") private String zkAddr; @@ -25,17 +33,54 @@ public class ZkHelper { @Value("${takin.config.zk.timeout: 3000}") private Integer timeout; + @Value("${takin.config.nacos.enbale: false}") + private String nacosEnbaled; + + @Value("${takin.config.nacos.addr}") + private String nacosAddr; + private CuratorFramework client; + private ConfigService configService; + + private static final String DATA_ID = "pradarConfig"; + private static final String GROUP = "PRADAR_CONFIG"; + @PostConstruct public void init() { - client = CuratorFrameworkFactory - .builder() - .connectString(zkAddr) - .sessionTimeoutMs(timeout) - .retryPolicy(new ExponentialBackoffRetry(1000, 3)) - .build(); - client.start(); + if("nacos".equals(nacosEnbaled)){ + try { + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, nacosAddr); + configService = ConfigFactory.createConfigService(properties); + } catch (Exception e) { + configService = null; + log.info("初始化pradar config的nacos客户端失败, nacos地址:{}, 不实用nacos作为配置中心", nacosAddr, e); + } + } + + try { + client = CuratorFrameworkFactory + .builder() + .connectString(zkAddr) + .sessionTimeoutMs(timeout) + .retryPolicy(new ExponentialBackoffRetry(1000, 3)) + .build(); + client.start(); + } catch (Exception e) { + log.error("初始化pradar config的zk客户端失败, zk地址:{},不使用zk作为配置中心", zkAddr, e); + } + + + } + + /** + * 是否使用nacos做配置中心 + * + * @return + */ + public boolean useNaocsForConfigCenter() { + return configService != null; } /** @@ -96,14 +141,14 @@ public boolean isNodeExists(String path) { /** * 创建永久节点与值 * - * @param path 路径 + * @param path 路径 * @param value 值 */ public void addPersistentNode(String path, String value) { try { client.create().creatingParentContainersIfNeeded() - .withMode(CreateMode.PERSISTENT) - .forPath(path, value.getBytes()); + .withMode(CreateMode.PERSISTENT) + .forPath(path, value.getBytes()); } catch (Exception e) { log.error("创建zk数据节点失败;path={},data={}", path, value, e); throw new RuntimeException(String.format("创建永久节点失败, 错误信息: %s", e.getMessage())); @@ -113,7 +158,7 @@ public void addPersistentNode(String path, String value) { /** * 更新节点的值 * - * @param path 路径 + * @param path 路径 * @param value 值 */ public void updateNode(String path, String value) { @@ -139,4 +184,20 @@ public void deleteNode(String path) { } } + public void pushConfigToNacos(Map config) { + try { + String serviceConfig = configService.getConfig(DATA_ID, GROUP, 3000); + Map serviceConfigMap; + if (serviceConfig != null){ + serviceConfigMap = JSON.parseObject(serviceConfig, Map.class); + serviceConfigMap.putAll(config); + } else { + serviceConfigMap = config; + } + configService.publishConfig(DATA_ID, GROUP, JSON.toJSONString(serviceConfigMap)); + } catch (NacosException e) { + log.error("推送配置到nacos发生异常,dataId:{}, group:{}, config:{}", DATA_ID, GROUP, config, e); + } + } + } diff --git a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/job/JobRedisUtils.java b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/job/JobRedisUtils.java index 255c24f722..8fd3fb7d0d 100644 --- a/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/job/JobRedisUtils.java +++ b/takin-web-biz-service/src/main/java/io/shulie/takin/web/biz/utils/job/JobRedisUtils.java @@ -41,6 +41,10 @@ public static String getRedisJobReport(Long tenantId,String envCode,Long reportI return String.format(REDIS_JOB_REPORT,tenantId,envCode,reportId); } + public static String getRedisJobResource(Long tenantId,String envCode,Object key) { + return String.format(REDIS_JOB_REPORT,tenantId,envCode,key); + } + /** * 获取job分布式锁 * @param tenantId diff --git a/takin-web-bom/pom.xml b/takin-web-bom/pom.xml index 12f39863ed..65ceb886ff 100644 --- a/takin-web-bom/pom.xml +++ b/takin-web-bom/pom.xml @@ -5,11 +5,11 @@ 4.0.0 io.shulie.takin takin-web-bom - takin-web-5.9.0 + takin-web-5.10.2.2 pom - takin-web-5.9.0 + takin-web-5.10.2.2 1.0.3 diff --git a/takin-web-common/pom.xml b/takin-web-common/pom.xml index 4eeab85547..5962bbcef3 100644 --- a/takin-web-common/pom.xml +++ b/takin-web-common/pom.xml @@ -19,12 +19,17 @@ io.shulie.takin takin-web - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml takin-web-common + + org.beanshell + bsh + 2.0b5 + io.shulie.takin @@ -52,6 +57,12 @@ org.springframework.boot spring-boot-starter-data-redis + + + logback-classic + ch.qos.logback + + @@ -84,6 +95,7 @@ mysql mysql-connector-java + ${mysql-jdbc.version} org.apache.httpcomponents @@ -112,10 +124,22 @@ io.shulie.takin takin-common-exception-starter + + + fastjson + com.alibaba + + io.shulie.takin takin-common-utils + + + fastjson + com.alibaba + + @@ -131,6 +155,12 @@ io.shulie.instrument.module module-pradar-core provided + + + fastjson + com.alibaba + + cn.afterturn @@ -187,6 +217,22 @@ ganymed-ssh2 262 + + ch.qos.logback + logback-classic + ${logback.version} + + + logback-core + ch.qos.logback + + + + + ch.qos.logback + logback-core + ${logback.version} + diff --git a/takin-web-common/src/main/java/io/shulie/takin/cloud/common/bean/scenemanage/SceneManageQueryBean.java b/takin-web-common/src/main/java/io/shulie/takin/cloud/common/bean/scenemanage/SceneManageQueryBean.java index b324b7fc98..43796cdf57 100644 --- a/takin-web-common/src/main/java/io/shulie/takin/cloud/common/bean/scenemanage/SceneManageQueryBean.java +++ b/takin-web-common/src/main/java/io/shulie/takin/cloud/common/bean/scenemanage/SceneManageQueryBean.java @@ -38,7 +38,15 @@ public class SceneManageQueryBean extends ContextExt { private Integer isDeleted; - private Integer isArchive; + private Integer isArchive; private List statusList; + + private Long deptId; + + private List userIdList; + + private List deptIdList; + + private Long businessFlowId; } diff --git a/takin-web-common/src/main/java/io/shulie/takin/web/common/enums/scene/SceneTypeEnum.java b/takin-web-common/src/main/java/io/shulie/takin/web/common/enums/scene/SceneTypeEnum.java index 9f910f96f0..d683d35195 100644 --- a/takin-web-common/src/main/java/io/shulie/takin/web/common/enums/scene/SceneTypeEnum.java +++ b/takin-web-common/src/main/java/io/shulie/takin/web/common/enums/scene/SceneTypeEnum.java @@ -12,7 +12,8 @@ public enum SceneTypeEnum { NORMAL_SCENE(0, "手工创建枚举"), JMETER_UPLOAD_SCENE(1, "jmeter上传创建"), - PERFORMANCE_AUTO_SCENE(2, "单接口压测场景创建"); + PERFORMANCE_AUTO_SCENE(2, "单接口压测场景创建"), + PRESSURE_RESOURCE_AUTO_SCENE(3, "压测准备创建"); private Integer type; private String desc; diff --git a/takin-web-common/src/main/java/io/shulie/takin/web/common/exception/TakinWebExceptionEnum.java b/takin-web-common/src/main/java/io/shulie/takin/web/common/exception/TakinWebExceptionEnum.java index 812a216134..c6d0406466 100644 --- a/takin-web-common/src/main/java/io/shulie/takin/web/common/exception/TakinWebExceptionEnum.java +++ b/takin-web-common/src/main/java/io/shulie/takin/web/common/exception/TakinWebExceptionEnum.java @@ -181,9 +181,9 @@ public enum TakinWebExceptionEnum implements ExceptionReadable { */ DATA_SIGN_ERROR("19800-" + ErrorConstant.DATA_SIGN_ERROR, "数据签名异常"), - DATA_SIGN_CLEAR_ERROR("19800-" + ErrorConstant.DATA_SIGN_ERROR, "数据正在清理中,暂时无法开启"), + DATA_SIGN_CLEAR_ERROR("19800-" + ErrorConstant.DATA_SIGN_ERROR, "数据正在清理中,暂时无法开启"), - /** + /** * 接口压测 */ INTERFACE_PERFORMANCE_PARAM_ERROR("1900-" + ErrorConstant.DELETE_ERROR, "接口压测删除异常"), @@ -196,6 +196,12 @@ public enum TakinWebExceptionEnum implements ExceptionReadable { INTERFACE_PERFORMANCE_SCRIPT_CREATE_ERROR("1907-" + ErrorConstant.ADD_ERROR, "生成脚本异常"), INTERFACE_PERFORMANCE_SCENE_OP_ERROR("1908-" + ErrorConstant.ADD_ERROR, "场景操作异常"), + /** + * 压测资源 + */ + PRESSURE_RESOURCE_OP_ERROR("1909-" + ErrorConstant.UPDATE_ERROR, "操作异常"), + PRESSURE_RESOURCE_QUERY_ERROR("1910-" + ErrorConstant.QUERY_ERROR, "查询异常"), + PRESSURE_RESOURCE_CONFIG_FILE_VALIDATE_ERROR("1911-" + ErrorConstant.FILE_VALIDATE_ERROR, "配置文件校验异常"), ; private final String errorCode; diff --git a/takin-web-common/src/main/java/io/shulie/takin/web/common/util/ActivityUtil.java b/takin-web-common/src/main/java/io/shulie/takin/web/common/util/ActivityUtil.java index e43767369f..6877d51b32 100644 --- a/takin-web-common/src/main/java/io/shulie/takin/web/common/util/ActivityUtil.java +++ b/takin-web-common/src/main/java/io/shulie/takin/web/common/util/ActivityUtil.java @@ -7,6 +7,7 @@ import io.shulie.takin.cloud.ext.content.enums.RpcTypeEnum; import io.shulie.takin.web.common.enums.activity.BusinessTypeEnum; import lombok.Data; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; /** @@ -36,23 +37,31 @@ public static boolean isNormalBusiness(Integer type) { * @return linkId 链路id */ public static String createLinkId(String serviceName, String methodName, String appName, String rpcType, String extend) { - StringBuilder tags = new StringBuilder(); - tags.append(serviceName) - .append("|").append(methodName) - .append("|").append(appName) - .append("|").append(rpcType); - if (StringUtils.isNotBlank(extend)) { - tags.append("|").append(extend); - } - try { - return MD5Tool.getMD5(tags.toString()); - } catch (Exception e) { - return UUID.randomUUID().toString(); + StringBuffer tags = new StringBuffer(); + tags.append(objectToString(serviceName, "")) + .append("|") + .append(objectToString(methodName, "")) + .append("|") + .append(objectToString(appName, "")) + .append("|") + .append(objectToString(rpcType, "")) + .append("|") + .append(objectToString(extend, "")); + // 保持跟amdb生成的md5一致 + return MD5Tool.md5(tags.toString()); + } + + private static String objectToString(Object value, String defaultStr) { + if (value == null || "null".equalsIgnoreCase(value.toString())) { + return ""; } + return ObjectUtils.toString(value); } public static String buildEntrance(String methodName, String serviceName, String rpcType) { - if (StrUtil.isBlank(methodName)) {methodName = "METHOD_NAME";} + if (StrUtil.isBlank(methodName)) { + methodName = "METHOD_NAME"; + } /* if (RpcTypeEnum.MQ.getValue().equals(rpcType)) { return StringUtils.join(Lists.newArrayList(serviceName, rpcType), "|"); @@ -110,11 +119,11 @@ public static EntranceJoinEntity covertEntrance(String dbEntrance) { public static String toEntrance(EntranceJoinEntity entranceJoinEntity) { return StringUtils.join( - Lists.newArrayList( - entranceJoinEntity.getMethodName(), - entranceJoinEntity.getServiceName(), - entranceJoinEntity.getRpcType() - ), "|" + Lists.newArrayList( + entranceJoinEntity.getMethodName(), + entranceJoinEntity.getServiceName(), + entranceJoinEntity.getRpcType() + ), "|" ); } @@ -166,7 +175,7 @@ public static EntranceJoinEntity covertVirtualEntranceV2(String dbEntrance) { */ public static EntranceJoinEntity getEntranceJoinEntityByEntranceAndType(String entrance, Integer type) { return ActivityUtil.isNormalBusiness(type) ? ActivityUtil.covertEntrance(entrance) - : ActivityUtil.covertVirtualEntranceV2(entrance); + : ActivityUtil.covertVirtualEntranceV2(entrance); } @Data diff --git a/takin-web-common/src/main/java/io/shulie/takin/web/common/util/Bytes.java b/takin-web-common/src/main/java/io/shulie/takin/web/common/util/Bytes.java new file mode 100644 index 0000000000..0f4dcd1deb --- /dev/null +++ b/takin-web-common/src/main/java/io/shulie/takin/web/common/util/Bytes.java @@ -0,0 +1,916 @@ +package io.shulie.takin.web.common.util; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +public class Bytes { + + public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; + + public static final Charset UTF_8 = Charset.forName("UTF-8"); + public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); + + /** + * Size of boolean in bytes + */ + public static final int SIZEOF_BOOLEAN = Byte.SIZE / Byte.SIZE; + + /** + * Size of byte in bytes + */ + public static final int SIZEOF_BYTE = SIZEOF_BOOLEAN; + + /** + * Size of char in bytes + */ + public static final int SIZEOF_CHAR = Character.SIZE / Byte.SIZE; + + /** + * Size of double in bytes + */ + public static final int SIZEOF_DOUBLE = Double.SIZE / Byte.SIZE; + + /** + * Size of float in bytes + */ + public static final int SIZEOF_FLOAT = Float.SIZE / Byte.SIZE; + + /** + * Size of int in bytes + */ + public static final int SIZEOF_INT = Integer.SIZE / Byte.SIZE; + + /** + * Size of long in bytes + */ + public static final int SIZEOF_LONG = Long.SIZE / Byte.SIZE; + + /** + * Size of short in bytes + */ + public static final int SIZEOF_SHORT = Short.SIZE / Byte.SIZE; + + /** + * Estimate of size cost to pay beyond payload in jvm for instance of byte []. + * Estimate based on study of jhat and jprofiler numbers. + */ + // JHat says BU is 56 bytes. + // SizeOf which uses java.lang.instrument says 24 bytes. (3 longs?) + public static final int ESTIMATED_HEAP_TAX = 16; + + /** + * Put bytes at the specified byte array position. + * @param tgtBytes the byte array + * @param tgtOffset position in the array + * @param srcBytes array to write out + * @param srcOffset source offset + * @param srcLength source length + * @return incremented offset + */ + public static int putBytes(byte[] tgtBytes, int tgtOffset, byte[] srcBytes, + int srcOffset, int srcLength) { + System.arraycopy(srcBytes, srcOffset, tgtBytes, tgtOffset, srcLength); + return tgtOffset + srcLength; + } + + /** + * Write a single byte out to the specified byte array position. + * @param bytes the byte array + * @param offset position in the array + * @param b byte to write out + * @return incremented offset + */ + public static int putByte(byte[] bytes, int offset, byte b) { + bytes[offset] = b; + return offset + 1; + } + + /** + * Returns a new byte array, copied from the passed ByteBuffer. + * @param bb A ByteBuffer + * @return the byte array + */ + public static byte[] toBytes(ByteBuffer bb) { + int length = bb.limit(); + byte[] result = new byte[length]; + System.arraycopy(bb.array(), bb.arrayOffset(), result, 0, length); + return result; + } + + /** + * @param b Presumed UTF-8 encoded byte array. + * @return String made from b + */ + public static String toString(final byte[] b) { + if (b == null) { + return null; + } + return toString(b, 0, b.length); + } + + /** + * Joins two byte arrays together using a separator. + * @param b1 The first byte array. + * @param sep The separator to use. + * @param b2 The second byte array. + */ + public static String toString(final byte[] b1, String sep, final byte[] b2) { + return toString(b1, 0, b1.length) + sep + toString(b2, 0, b2.length); + } + + /** + * This method will convert utf8 encoded bytes into a string. + * + * @param b Presumed UTF-8 encoded byte array. + * @param off offset into array + * @param len length of utf-8 sequence + * @return String made from b or null + */ + public static String toString(final byte[] b, int off, int len) { + if (b == null) { + return null; + } + if (len == 0) { + return ""; + } + return new String(b, off, len, UTF_8); + + } + + /** + * Write a printable representation of a byte array. + * + * @param b byte array + * @return string + * @see #toStringBinary(byte[], int, int) + */ + public static String toStringBinary(final byte[] b) { + if (b == null) + return "null"; + return toStringBinary(b, 0, b.length); + } + + /** + * Converts the given byte buffer, from its array offset to its limit, to + * a string. The position and the mark are ignored. + * + * @param buf a byte buffer + * @return a string representation of the buffer's binary contents + */ + public static String toStringBinary(ByteBuffer buf) { + if (buf == null) + return "null"; + return toStringBinary(buf.array(), buf.arrayOffset(), buf.limit()); + } + + /** + * Write a printable representation of a byte array. Non-printable + * characters are hex escaped in the format \\x%02X, eg: + * \x00 \x05 etc + * + * @param b array to write out + * @param off offset to start at + * @param len length to write + * @return string output + */ + public static String toStringBinary(final byte[] b, int off, int len) { + StringBuilder result = new StringBuilder(); + String first = new String(b, off, len, ISO_8859_1); + for (int i = 0; i < first.length(); ++i) { + int ch = first.charAt(i) & 0xFF; + if ((ch >= '0' && ch <= '9') + || (ch >= 'A' && ch <= 'Z') + || (ch >= 'a' && ch <= 'z') + || " `~!@#$%^&*()-_=+[]{}\\|;:'\",.<>/?".indexOf(ch) >= 0) { + result.append(first.charAt(i)); + } else { + result.append(String.format("\\x%02X", ch)); + } + } + return result.toString(); + } + + private static boolean isHexDigit(char c) { + return (c >= 'A' && c <= 'F') || + (c >= '0' && c <= '9'); + } + + /** + * Takes a ASCII digit in the range A-F0-9 and returns + * the corresponding integer/ordinal value. + * @param ch The hex digit. + * @return The converted hex value as a byte. + */ + public static byte toBinaryFromHex(byte ch) { + if (ch >= 'A' && ch <= 'F') + return (byte) ((byte) 10 + (byte) (ch - 'A')); + // else + return (byte) (ch - '0'); + } + + public static byte[] toBytesBinary(String in) { + // this may be bigger than we need, but lets be safe. + byte[] b = new byte[in.length()]; + int size = 0; + for (int i = 0; i < in.length(); ++i) { + char ch = in.charAt(i); + if (ch == '\\') { + // begin hex escape: + char next = in.charAt(i + 1); + if (next != 'x') { + // invalid escape sequence, ignore this one. + b[size++] = (byte) ch; + continue; + } + // ok, take next 2 hex digits. + char hd1 = in.charAt(i + 2); + char hd2 = in.charAt(i + 3); + + // they need to be A-F0-9: + if (!isHexDigit(hd1) || + !isHexDigit(hd2)) { + // bogus escape code, ignore: + continue; + } + // turn hex ASCII digit -> number + byte d = (byte) ((toBinaryFromHex((byte) hd1) << 4) + toBinaryFromHex((byte) hd2)); + + b[size++] = d; + i += 3; // skip 3 + } else { + b[size++] = (byte) ch; + } + } + // resize: + byte[] b2 = new byte[size]; + System.arraycopy(b, 0, b2, 0, size); + return b2; + } + + /** + * Converts a string to a UTF-8 byte array. + * @param s string + * @return the byte array + */ + public static byte[] toBytes(String s) { + return s.getBytes(UTF_8); + } + + /** + * Convert a boolean to a byte array. True becomes -1 + * and false becomes 0. + * + * @param b value + * @return b encoded in a byte array. + */ + public static byte[] toBytes(final boolean b) { + return new byte[] { b ? (byte) -1 : (byte) 0 }; + } + + /** + * Reverses {@link #toBytes(boolean)} + * @param b array + * @return True or false. + */ + public static boolean toBoolean(final byte[] b) { + if (b.length != 1) { + throw new IllegalArgumentException("Array has wrong size: " + b.length); + } + return b[0] != (byte) 0; + } + + /** + * Convert a long value to a byte array using big-endian. + * + * @param val value to convert + * @return the byte array + */ + public static byte[] toBytes(long val) { + byte[] b = new byte[8]; + for (int i = 7; i > 0; i--) { + b[i] = (byte) val; + val >>>= 8; + } + b[0] = (byte) val; + return b; + } + + /** + * Converts a byte array to a long value. Reverses + * {@link #toBytes(long)} + * @param bytes array + * @return the long value + */ + public static long toLong(byte[] bytes) { + return toLong(bytes, 0, SIZEOF_LONG); + } + + /** + * Converts a byte array to a long value. Assumes there will be + * {@link #SIZEOF_LONG} bytes available. + * + * @param bytes bytes + * @param offset offset + * @return the long value + */ + public static long toLong(byte[] bytes, int offset) { + return toLong(bytes, offset, SIZEOF_LONG); + } + + /** + * Converts a byte array to a long value. + * + * @param bytes array of bytes + * @param offset offset into array + * @param length length of data (must be {@link #SIZEOF_LONG}) + * @return the long value + * @throws IllegalArgumentException if length is not {@link #SIZEOF_LONG} or + * if there's not enough room in the array at the offset indicated. + */ + public static long toLong(byte[] bytes, int offset, final int length) { + if (length != SIZEOF_LONG || offset + length > bytes.length) { + throw explainWrongLengthOrOffset(bytes, offset, length, SIZEOF_LONG); + } + long l = 0; + for (int i = offset; i < offset + length; i++) { + l <<= 8; + l ^= bytes[i] & 0xFF; + } + return l; + } + + private static IllegalArgumentException + explainWrongLengthOrOffset(final byte[] bytes, + final int offset, + final int length, + final int expectedLength) { + String reason; + if (length != expectedLength) { + reason = "Wrong length: " + length + ", expected " + expectedLength; + } else { + reason = "offset (" + offset + ") + length (" + length + ") exceed the" + + " capacity of the array: " + bytes.length; + } + return new IllegalArgumentException(reason); + } + + /** + * Put a long value out to the specified byte array position. + * @param bytes the byte array + * @param offset position in the array + * @param val long to write out + * @return incremented offset + * @throws IllegalArgumentException if the byte array given doesn't have + * enough room at the offset specified. + */ + public static int putLong(byte[] bytes, int offset, long val) { + if (bytes.length - offset < SIZEOF_LONG) { + throw new IllegalArgumentException("Not enough room to put a long at" + + " offset " + offset + " in a " + bytes.length + " byte array"); + } + for (int i = offset + 7; i > offset; i--) { + bytes[i] = (byte) val; + val >>>= 8; + } + bytes[offset] = (byte) val; + return offset + SIZEOF_LONG; + } + + /** + * Presumes float encoded as IEEE 754 floating-point "single format" + * @param bytes byte array + * @return Float made from passed byte array. + */ + public static float toFloat(byte[] bytes) { + return toFloat(bytes, 0); + } + + /** + * Presumes float encoded as IEEE 754 floating-point "single format" + * @param bytes array to convert + * @param offset offset into array + * @return Float made from passed byte array. + */ + public static float toFloat(byte[] bytes, int offset) { + return Float.intBitsToFloat(toInt(bytes, offset, SIZEOF_INT)); + } + + /** + * @param bytes byte array + * @param offset offset to write to + * @param f float value + * @return New offset in bytes + */ + public static int putFloat(byte[] bytes, int offset, float f) { + return putInt(bytes, offset, Float.floatToRawIntBits(f)); + } + + /** + * @param f float value + * @return the float represented as byte [] + */ + public static byte[] toBytes(final float f) { + // Encode it as int + return Bytes.toBytes(Float.floatToRawIntBits(f)); + } + + /** + * @param bytes byte array + * @return Return double made from passed bytes. + */ + public static double toDouble(final byte[] bytes) { + return toDouble(bytes, 0); + } + + /** + * @param bytes byte array + * @param offset offset where double is + * @return Return double made from passed bytes. + */ + public static double toDouble(final byte[] bytes, final int offset) { + return Double.longBitsToDouble(toLong(bytes, offset, SIZEOF_LONG)); + } + + /** + * @param bytes byte array + * @param offset offset to write to + * @param d value + * @return New offset into array bytes + */ + public static int putDouble(byte[] bytes, int offset, double d) { + return putLong(bytes, offset, Double.doubleToLongBits(d)); + } + + /** + * Serialize a double as the IEEE 754 double format output. The resultant + * array will be 8 bytes long. + * + * @param d value + * @return the double represented as byte [] + */ + public static byte[] toBytes(final double d) { + // Encode it as a long + return Bytes.toBytes(Double.doubleToRawLongBits(d)); + } + + /** + * Convert an int value to a byte array + * @param val value + * @return the byte array + */ + public static byte[] toBytes(int val) { + byte[] b = new byte[4]; + for (int i = 3; i > 0; i--) { + b[i] = (byte) val; + val >>>= 8; + } + b[0] = (byte) val; + return b; + } + + /** + * Converts a byte array to an int value + * @param bytes byte array + * @return the int value + */ + public static int toInt(byte[] bytes) { + return toInt(bytes, 0, SIZEOF_INT); + } + + /** + * Converts a byte array to an int value + * @param bytes byte array + * @param offset offset into array + * @return the int value + */ + public static int toInt(byte[] bytes, int offset) { + return toInt(bytes, offset, SIZEOF_INT); + } + + /** + * Converts a byte array to an int value + * @param bytes byte array + * @param offset offset into array + * @param length length of int (has to be {@link #SIZEOF_INT}) + * @return the int value + * @throws IllegalArgumentException if length is not {@link #SIZEOF_INT} or + * if there's not enough room in the array at the offset indicated. + */ + public static int toInt(byte[] bytes, int offset, final int length) { + if (length != SIZEOF_INT || offset + length > bytes.length) { + throw explainWrongLengthOrOffset(bytes, offset, length, SIZEOF_INT); + } + int n = 0; + for (int i = offset; i < (offset + length); i++) { + n <<= 8; + n ^= bytes[i] & 0xFF; + } + return n; + } + + /** + * Put an int value out to the specified byte array position. + * @param bytes the byte array + * @param offset position in the array + * @param val int to write out + * @return incremented offset + * @throws IllegalArgumentException if the byte array given doesn't have + * enough room at the offset specified. + */ + public static int putInt(byte[] bytes, int offset, int val) { + if (bytes.length - offset < SIZEOF_INT) { + throw new IllegalArgumentException("Not enough room to put an int at" + + " offset " + offset + " in a " + bytes.length + " byte array"); + } + for (int i = offset + 3; i > offset; i--) { + bytes[i] = (byte) val; + val >>>= 8; + } + bytes[offset] = (byte) val; + return offset + SIZEOF_INT; + } + + /** + * Convert a short value to a byte array of {@link #SIZEOF_SHORT} bytes long. + * @param val value + * @return the byte array + */ + public static byte[] toBytes(short val) { + byte[] b = new byte[SIZEOF_SHORT]; + b[1] = (byte) val; + val >>= 8; + b[0] = (byte) val; + return b; + } + + /** + * Converts a byte array to a short value + * @param bytes byte array + * @return the short value + */ + public static short toShort(byte[] bytes) { + return toShort(bytes, 0, SIZEOF_SHORT); + } + + /** + * Converts a byte array to a short value + * @param bytes byte array + * @param offset offset into array + * @return the short value + */ + public static short toShort(byte[] bytes, int offset) { + return toShort(bytes, offset, SIZEOF_SHORT); + } + + /** + * Converts a byte array to a short value + * @param bytes byte array + * @param offset offset into array + * @param length length, has to be {@link #SIZEOF_SHORT} + * @return the short value + * @throws IllegalArgumentException if length is not {@link #SIZEOF_SHORT} + * or if there's not enough room in the array at the offset indicated. + */ + public static short toShort(byte[] bytes, int offset, final int length) { + if (length != SIZEOF_SHORT || offset + length > bytes.length) { + throw explainWrongLengthOrOffset(bytes, offset, length, SIZEOF_SHORT); + } + short n = 0; + n ^= bytes[offset] & 0xFF; + n <<= 8; + n ^= bytes[offset + 1] & 0xFF; + return n; + } + + /** + * This method will get a sequence of bytes from pos -> limit, + * but will restore pos after. + * @param buf + * @return byte array + */ + public static byte[] getBytes(ByteBuffer buf) { + int savedPos = buf.position(); + byte[] newBytes = new byte[buf.remaining()]; + buf.get(newBytes); + buf.position(savedPos); + return newBytes; + } + + /** + * Put a short value out to the specified byte array position. + * @param bytes the byte array + * @param offset position in the array + * @param val short to write out + * @return incremented offset + * @throws IllegalArgumentException if the byte array given doesn't have + * enough room at the offset specified. + */ + public static int putShort(byte[] bytes, int offset, short val) { + if (bytes.length - offset < SIZEOF_SHORT) { + throw new IllegalArgumentException("Not enough room to put a short at" + + " offset " + offset + " in a " + bytes.length + " byte array"); + } + bytes[offset + 1] = (byte) val; + val >>= 8; + bytes[offset] = (byte) val; + return offset + SIZEOF_SHORT; + } + + /** + * Convert a BigDecimal value to a byte array + * + * @param val + * @return the byte array + */ + public static byte[] toBytes(BigDecimal val) { + byte[] valueBytes = val.unscaledValue().toByteArray(); + byte[] result = new byte[valueBytes.length + SIZEOF_INT]; + int offset = putInt(result, 0, val.scale()); + putBytes(result, offset, valueBytes, 0, valueBytes.length); + return result; + } + + /** + * Converts a byte array to a BigDecimal + * + * @param bytes + * @return the char value + */ + public static BigDecimal toBigDecimal(byte[] bytes) { + return toBigDecimal(bytes, 0, bytes.length); + } + + /** + * Converts a byte array to a BigDecimal value + * + * @param bytes + * @param offset + * @param length + * @return the char value + */ + public static BigDecimal toBigDecimal(byte[] bytes, int offset, final int length) { + if (bytes == null || length < SIZEOF_INT + 1 || + (offset + length > bytes.length)) { + return null; + } + + int scale = toInt(bytes, offset); + byte[] tcBytes = new byte[length - SIZEOF_INT]; + System.arraycopy(bytes, offset + SIZEOF_INT, tcBytes, 0, length - SIZEOF_INT); + return new BigDecimal(new BigInteger(tcBytes), scale); + } + + /** + * Put a BigDecimal value out to the specified byte array position. + * + * @param bytes the byte array + * @param offset position in the array + * @param val BigDecimal to write out + * @return incremented offset + */ + public static int putBigDecimal(byte[] bytes, int offset, BigDecimal val) { + if (bytes == null) { + return offset; + } + + byte[] valueBytes = val.unscaledValue().toByteArray(); + byte[] result = new byte[valueBytes.length + SIZEOF_INT]; + offset = putInt(result, offset, val.scale()); + return putBytes(result, offset, valueBytes, 0, valueBytes.length); + } + + /** + * @param a lower half + * @param b upper half + * @return New array that has a in lower half and b in upper half. + */ + public static byte[] add(final byte[] a, final byte[] b) { + return add(a, b, EMPTY_BYTE_ARRAY); + } + + /** + * @param a first third + * @param b second third + * @param c third third + * @return New array made from a, b and c + */ + public static byte[] add(final byte[] a, final byte[] b, final byte[] c) { + byte[] result = new byte[a.length + b.length + c.length]; + System.arraycopy(a, 0, result, 0, a.length); + System.arraycopy(b, 0, result, a.length, b.length); + System.arraycopy(c, 0, result, a.length + b.length, c.length); + return result; + } + + /** + * @param a array + * @param length amount of bytes to grab + * @return First length bytes from a + */ + public static byte[] head(final byte[] a, final int length) { + if (a.length < length) { + return null; + } + byte[] result = new byte[length]; + System.arraycopy(a, 0, result, 0, length); + return result; + } + + /** + * @param a array + * @param length amount of bytes to snarf + * @return Last length bytes from a + */ + public static byte[] tail(final byte[] a, final int length) { + if (a.length < length) { + return null; + } + byte[] result = new byte[length]; + System.arraycopy(a, a.length - length, result, 0, length); + return result; + } + + /** + * @param a array + * @param length new array size + * @return Value in a plus length prepended 0 bytes + */ + public static byte[] padHead(final byte[] a, final int length) { + byte[] padding = new byte[length]; + for (int i = 0; i < length; i++) { + padding[i] = 0; + } + return add(padding, a); + } + + /** + * @param a array + * @param length new array size + * @return Value in a plus length appended 0 bytes + */ + public static byte[] padTail(final byte[] a, final int length) { + byte[] padding = new byte[length]; + for (int i = 0; i < length; i++) { + padding[i] = 0; + } + return add(a, padding); + } + + /** + * @param bytes array to hash + * @param offset offset to start from + * @param length length to hash + * */ + public static int hashCode(byte[] bytes, int offset, int length) { + int hash = 1; + for (int i = offset; i < offset + length; i++) + hash = (31 * hash) + bytes[i]; + return hash; + } + + /** + * @param t operands + * @return Array of byte arrays made from passed array of Text + */ + public static byte[][] toByteArrays(final String[] t) { + byte[][] result = new byte[t.length][]; + for (int i = 0; i < t.length; i++) { + result[i] = Bytes.toBytes(t[i]); + } + return result; + } + + /** + * @param column operand + * @return A byte array of a byte array where first and only entry is + * column + */ + public static byte[][] toByteArrays(final String column) { + return toByteArrays(toBytes(column)); + } + + /** + * @param column operand + * @return A byte array of a byte array where first and only entry is + * column + */ + public static byte[][] toByteArrays(final byte[] column) { + byte[][] result = new byte[1][]; + result[0] = column; + return result; + } + + public static byte[] incrementBytes(byte[] value, long amount) + { + byte[] val = value; + if (val.length < SIZEOF_LONG) { + // Hopefully this doesn't happen too often. + byte[] newvalue; + if (val[0] < 0) { + newvalue = new byte[] { -1, -1, -1, -1, -1, -1, -1, -1 }; + } else { + newvalue = new byte[SIZEOF_LONG]; + } + System.arraycopy(val, 0, newvalue, newvalue.length - val.length, + val.length); + val = newvalue; + } else if (val.length > SIZEOF_LONG) { + throw new IllegalArgumentException("Increment Bytes - value too big: " + + val.length); + } + if (amount == 0) + return val; + if (val[0] < 0) { + return binaryIncrementNeg(val, amount); + } + return binaryIncrementPos(val, amount); + } + + /* increment/deincrement for positive value */ + private static byte[] binaryIncrementPos(byte[] value, long amount) { + long amo = amount; + int sign = 1; + if (amount < 0) { + amo = -amount; + sign = -1; + } + for (int i = 0; i < value.length; i++) { + int cur = ((int) amo % 256) * sign; + amo = (amo >> 8); + int val = value[value.length - i - 1] & 0x0ff; + int total = val + cur; + if (total > 255) { + amo += sign; + total %= 256; + } else if (total < 0) { + amo -= sign; + } + value[value.length - i - 1] = (byte) total; + if (amo == 0) + return value; + } + return value; + } + + /* increment/deincrement for negative value */ + private static byte[] binaryIncrementNeg(byte[] value, long amount) { + long amo = amount; + int sign = 1; + if (amount < 0) { + amo = -amount; + sign = -1; + } + for (int i = 0; i < value.length; i++) { + int cur = ((int) amo % 256) * sign; + amo = (amo >> 8); + int val = ((~value[value.length - i - 1]) & 0x0ff) + 1; + int total = cur - val; + if (total >= 0) { + amo += sign; + } else if (total < -256) { + amo -= sign; + total %= 256; + } + value[value.length - i - 1] = (byte) total; + if (amo == 0) + return value; + } + return value; + } + + /** + * Writes a string as a fixed-size field, padded with zeros. + */ + public static void writeStringFixedSize(final DataOutput out, String s, + int size) throws IOException { + byte[] b = toBytes(s); + if (b.length > size) { + throw new IOException("Trying to write " + b.length + " bytes (" + + toStringBinary(b) + ") into a field of length " + size); + } + + out.writeBytes(s); + for (int i = 0; i < size - s.length(); ++i) + out.writeByte(0); + } + + /** + * Reads a fixed-size field and interprets it as a string padded with zeros. + */ + public static String readStringFixedSize(final DataInput in, int size) + throws IOException { + byte[] b = new byte[size]; + in.readFully(b); + int n = b.length; + while (n > 0 && b[n - 1] == 0) + --n; + + return toString(b, 0, n); + } + +} \ No newline at end of file diff --git a/takin-web-common/src/main/java/io/shulie/takin/web/common/util/MD5Tool.java b/takin-web-common/src/main/java/io/shulie/takin/web/common/util/MD5Tool.java index 77c06abe70..aaafb30642 100644 --- a/takin-web-common/src/main/java/io/shulie/takin/web/common/util/MD5Tool.java +++ b/takin-web-common/src/main/java/io/shulie/takin/web/common/util/MD5Tool.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileInputStream; import java.security.MessageDigest; +import java.util.Locale; public class MD5Tool { public static void main(String[] args) throws Exception { @@ -14,7 +15,7 @@ public static void main(String[] args) throws Exception { /** * 逻辑: - * + *

* 1.获取md5对象,通过"信息摘要"获取实例构造("MD5"). * 2.md5对象对("字符串的"字节形式"-得到的数组)进行摘要",那么会返回一个"摘要的字节数组" * 3.摘要字节数组中的"每个二进制值"字节形式,"转成十六进制形式",然后再把这些值给拼接起来,就是MD5值了 @@ -50,7 +51,7 @@ public static String getMD5(String str) throws Exception { * 3.其实还是通过mdt.digest();获取到字节数组,但是前期必须要有一个方法必须是md5.update(),即"信息摘要对象"要先更新 * 4."信息摘要更新"里面有(byte[] input),说明是读取流获取到的数组,所以我们就用这个方法. * 5.所以最终的逻辑就是: - * + *

* 1.获取文件的读取流 * 2.不停的读取流中的"内容"放入字符串,放一部分就"更新"一部分.直到全部完毕 * 3.然后调用md5.digest();就会得到有内容的字节数组,剩下的就和上边一样了. @@ -77,4 +78,23 @@ public static String getMD5(File file) throws Exception { } return MD5; } + + public static String md5(String text) { + MessageDigest md5 = null; + try { + md5 = MessageDigest.getInstance("MD5"); + } catch (Exception e) { + e.printStackTrace(); + return text; + } + + byte[] byteArray = Bytes.toBytes(text); + byte[] md5Bytes = md5.digest(byteArray); + StringBuffer hexValue = new StringBuffer(); + for (int i = 0; i < md5Bytes.length; i++) { + int val = ((int) md5Bytes[i]) & 0xff; + hexValue.append(String.format("%02X", val).toLowerCase(Locale.ROOT)); + } + return hexValue.toString(); + } } diff --git a/takin-web-common/src/main/java/io/shulie/takin/web/common/vo/application/ApplicationApiManageVO.java b/takin-web-common/src/main/java/io/shulie/takin/web/common/vo/application/ApplicationApiManageVO.java index 9e9874ad72..c3ba4fd0ea 100644 --- a/takin-web-common/src/main/java/io/shulie/takin/web/common/vo/application/ApplicationApiManageVO.java +++ b/takin-web-common/src/main/java/io/shulie/takin/web/common/vo/application/ApplicationApiManageVO.java @@ -3,6 +3,7 @@ import java.util.Date; import java.io.Serializable; +import io.shulie.takin.web.ext.entity.AuthQueryResponseCommonExt; import lombok.Data; import com.fasterxml.jackson.annotation.JsonFormat; @@ -12,7 +13,7 @@ * @date 2020/7/7 10:40 */ @Data -public class ApplicationApiManageVO implements Serializable { +public class ApplicationApiManageVO extends AuthQueryResponseCommonExt { /** * 主键 */ diff --git a/takin-web-data/pom.xml b/takin-web-data/pom.xml index f2ec98e079..b0e9621bb3 100644 --- a/takin-web-data/pom.xml +++ b/takin-web-data/pom.xml @@ -21,7 +21,7 @@ io.shulie.takin takin-web - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml takin-web-data @@ -79,6 +79,14 @@ log4j log4j + + logback-classic + ch.qos.logback + + + logback-core + ch.qos.logback + @@ -94,6 +102,10 @@ guava com.google.guava + + fastjson + com.alibaba + provided diff --git a/takin-web-data/src/main/java/com/pamirs/takin/cloud/entity/domain/dto/report/CloudReportDTO.java b/takin-web-data/src/main/java/com/pamirs/takin/cloud/entity/domain/dto/report/CloudReportDTO.java index 5378c5a080..d8e8564630 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/cloud/entity/domain/dto/report/CloudReportDTO.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/cloud/entity/domain/dto/report/CloudReportDTO.java @@ -46,4 +46,6 @@ public class CloudReportDTO extends ContextExt { @ApiModelProperty(value = "压测不通过的原因") private String errorMsg; + private Long deptId; + } diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/dao/confcenter/TBListMntDao.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/dao/confcenter/TBListMntDao.java index df8f7ff42a..ba380d013b 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/dao/confcenter/TBListMntDao.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/dao/confcenter/TBListMntDao.java @@ -43,7 +43,7 @@ public interface TBListMntDao { * @author shulie */ List queryBList(@Param("redisKey") String redisKey, - @Param("principalNo") String principalNo,@Param("userIds") List userIds); + @Param("principalNo") String principalNo,@Param("userIds") List userIds, @Param("deptIds") List deptIds); /** * 说明: 根据id查询黑名单信息 diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/report/ReportDTO.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/report/ReportDTO.java index 5c3936d8aa..cce9dd11d6 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/report/ReportDTO.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/report/ReportDTO.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.util.Date; +import io.shulie.takin.web.ext.entity.AuthQueryResponseCommonExt; import io.shulie.takin.web.ext.entity.UserCommonExt; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -13,7 +14,7 @@ * @date 2020-04-17 */ @Data -public class ReportDTO extends UserCommonExt implements Serializable { +public class ReportDTO extends AuthQueryResponseCommonExt implements Serializable { private static final long serialVersionUID = 4235565595934721788L; diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/scenemanage/SceneManageWrapperDTO.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/scenemanage/SceneManageWrapperDTO.java index a724ae9040..2e140a8bff 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/scenemanage/SceneManageWrapperDTO.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/dto/scenemanage/SceneManageWrapperDTO.java @@ -82,6 +82,7 @@ public class SceneManageWrapperDTO implements Serializable { @ApiModelProperty(name = "scheduleInterval", value = "漏数时间间隔") private Integer scheduleInterval; + private Long deptId; /** * 是否是绝对脚本路径 */ diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/entity/TBList.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/entity/TBList.java index 8a0a03e8f5..f440083656 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/entity/TBList.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/entity/TBList.java @@ -25,6 +25,7 @@ public class TBList extends BaseEntity { @ApiModelProperty(name = "useYn", value = "是否启用:1启用 0禁用") private String useYn; + private Long deptId; private Boolean canEdit = true; @@ -126,6 +127,14 @@ public void setCanEnableDisable(Boolean canEnableDisable) { this.canEnableDisable = canEnableDisable; } + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + /** * 2018年5月17日 * diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/ApplicationVo.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/ApplicationVo.java index 89b7a7f2e5..4b3d3567bf 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/ApplicationVo.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/ApplicationVo.java @@ -38,6 +38,9 @@ public class ApplicationVo extends AuthQueryResponseCommonExt implements Seriali @ApiModelProperty(name = "nodeNum", value = "节点数量") private Integer nodeNum; + @ApiModelProperty(name = "onlineNodeNum", value = "节点数量") + private Integer onlineNodeNum; + @ApiModelProperty(name = "exceptionInfo", value = "异常信息") private String exceptionInfo; @@ -76,4 +79,7 @@ public class ApplicationVo extends AuthQueryResponseCommonExt implements Seriali @ApiModelProperty(name = "silenceEnable", value = "静默开关,true:开") private Boolean silenceEnable = true; + + @ApiModelProperty(name = "clusterName", value = "应用所在集群名称") + private String clusterName; } diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/entracemanage/EntranceApiVo.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/entracemanage/EntranceApiVo.java index 8f395dc3cf..047e722306 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/entracemanage/EntranceApiVo.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/entracemanage/EntranceApiVo.java @@ -17,4 +17,6 @@ public class EntranceApiVo extends PagingDevice { private String applicationName; @ApiModelProperty(name = "api", value = "入口地址") private String api; + @ApiModelProperty(name = "deptId", value = "部门id") + private Long deptId; } diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/report/ReportQueryParam.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/report/ReportQueryParam.java index e5d02dbd2c..57f277c084 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/report/ReportQueryParam.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/report/ReportQueryParam.java @@ -59,4 +59,7 @@ public class ReportQueryParam extends PagingDevice implements Serializable { */ @ApiModelProperty(value = "报告结束时间") private String reportEndTime; + + @ApiModelProperty(value = "部门id") + private Long deptId; } diff --git a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/scenemanage/SceneManageQueryVO.java b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/scenemanage/SceneManageQueryVO.java index 33a17bd480..070711bfc2 100644 --- a/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/scenemanage/SceneManageQueryVO.java +++ b/takin-web-data/src/main/java/com/pamirs/takin/entity/domain/vo/scenemanage/SceneManageQueryVO.java @@ -41,4 +41,10 @@ public class SceneManageQueryVO extends PagingContextExt { private Long configId; + private Long deptId; + + private List userIdList; + + private List deptIdList; + } diff --git a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/report/ReportDaoImpl.java b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/report/ReportDaoImpl.java index 7a2734523b..53ced08a6e 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/report/ReportDaoImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/report/ReportDaoImpl.java @@ -28,6 +28,7 @@ import io.shulie.takin.cloud.ext.content.enums.NodeTypeEnum; import io.shulie.takin.cloud.ext.content.script.ScriptNode; import io.shulie.takin.web.common.util.RedisClientUtil; +import io.shulie.takin.web.ext.util.WebPluginUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -58,6 +59,7 @@ public int insert(ReportInsertParam param) { entity.setGmtCreate(insertDate); entity.setGmtUpdate(insertDate); entity.setStartTime(insertDate); + entity.setDeptId(WebPluginUtils.traceDeptId()); return reportMapper.insert(entity); } return 0; diff --git a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/scene/manage/impl/SceneManageDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/scene/manage/impl/SceneManageDAOImpl.java index fca53f1b30..6bf9fd9770 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/scene/manage/impl/SceneManageDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/dao/scene/manage/impl/SceneManageDAOImpl.java @@ -63,18 +63,7 @@ public SceneManageEntity getSceneById(Long id) { @Override public List getPageList(SceneManageQueryBean queryBean) { - // 补充用户过滤信息信息 - String userIds = ""; - if (StrUtil.isNotBlank(CloudPluginUtils.getContext().getFilterSql())) { - userIds = CloudPluginUtils.getContext().getFilterSql(); - // 去除左右的括号 - if (userIds.lastIndexOf("(") == 0 - && userIds.lastIndexOf(")") == userIds.length() - 1) { - userIds = userIds.substring(1, userIds.length() - 1); - } - } - List userIdList = Arrays.stream(userIds.split(",")) - .filter(StrUtil::isNotBlank).collect(Collectors.toList()); + // 组装查询条件 LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(SceneManageEntity.class) .eq(!Objects.isNull(queryBean.getSceneId()), SceneManageEntity::getId, queryBean.getSceneId()) @@ -87,7 +76,9 @@ public List getPageList(SceneManageQueryBean queryBean) { .eq(Objects.nonNull(queryBean.getIsArchive()), SceneManageEntity::getIsArchive, queryBean.getIsArchive()) .eq(SceneManageEntity::getTenantId, CloudPluginUtils.getContext().getTenantId()) .eq(SceneManageEntity::getEnvCode, CloudPluginUtils.getContext().getEnvCode()) - .in(userIdList.size() > 0, SceneManageEntity::getUserId, userIdList) + .eq(!Objects.isNull(queryBean.getDeptId()),SceneManageEntity::getDeptId, queryBean.getDeptId()) + .in(!CollectionUtils.isEmpty(queryBean.getUserIdList()), SceneManageEntity::getUserId, queryBean.getUserIdList()) + .in(!CollectionUtils.isEmpty(queryBean.getDeptIdList()), SceneManageEntity::getDeptId, queryBean.getDeptIdList()) .orderByDesc(SceneManageEntity::getLastPtTime) .orderByDesc(SceneManageEntity::getId); return this.baseMapper.selectList(wrapper); diff --git a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/model/mysql/SceneManageEntity.java b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/model/mysql/SceneManageEntity.java index 52555c3c81..766819c84b 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/model/mysql/SceneManageEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/model/mysql/SceneManageEntity.java @@ -121,6 +121,8 @@ public class SceneManageEntity { private Long customerId; @TableField(value = "is_archive") private Integer isArchive; + @TableField(value = "business_flow_id") + private Long businessFlowId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/param/scenemanage/SceneManageCreateOrUpdateParam.java b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/param/scenemanage/SceneManageCreateOrUpdateParam.java index 143fda335a..22c29fe91e 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/cloud/data/param/scenemanage/SceneManageCreateOrUpdateParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/cloud/data/param/scenemanage/SceneManageCreateOrUpdateParam.java @@ -40,4 +40,6 @@ public class SceneManageCreateOrUpdateParam extends ContextExt { private String ptConfig; + private Long deptId; + } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/SceneExcludedApplicationDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/SceneExcludedApplicationDAO.java index a71d28250f..55fb850660 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/SceneExcludedApplicationDAO.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/SceneExcludedApplicationDAO.java @@ -2,6 +2,7 @@ import java.util.List; +import io.shulie.takin.web.data.model.mysql.SceneExcludedApplicationEntity; import io.shulie.takin.web.data.param.CreateSceneExcludedApplicationParam; /** @@ -35,5 +36,18 @@ public interface SceneExcludedApplicationDAO { */ void removeBySceneId(Long sceneId); + /** + * 删除场景对应的忽略应用 + * + * @param sceneId 场景id + */ + void removeBySceneIdAndAppId(Long sceneId,Long appId); + + /** + * + * @param sceneId 场景id + */ + SceneExcludedApplicationEntity query(Long sceneId, Long appId); + } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/activity/impl/ActivityDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/activity/impl/ActivityDAOImpl.java index 78c2b2bf91..5da0fea0c6 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/activity/impl/ActivityDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/activity/impl/ActivityDAOImpl.java @@ -152,6 +152,7 @@ public Long createActivityNew(ActivityCreateParam param) { businessLinkManageTableEntity.setBindBusinessId(param.getBindBusinessId()); } businessLinkManageTableEntity.setPersistence(param.isPersistence()); + businessLinkManageTableEntity.setDeptId(WebPluginUtils.traceDeptId()); businessLinkManageTableMapper.insert(businessLinkManageTableEntity); param.setLinkId(businessLinkManageTableEntity.getLinkId()); return businessLinkManageTableEntity.getLinkId(); @@ -321,6 +322,9 @@ public PagingList pageActivities(ActivityQueryParam param) { page.setOrders(Lists.newArrayList(OrderItem.desc("CREATE_TIME"))); LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (param.getDeptId() != null){ + lambdaQueryWrapper.eq(BusinessLinkManageTableEntity::getDeptId, param.getDeptId()); + } if (StringUtils.isNotBlank(param.getActivityName())) { lambdaQueryWrapper.like(BusinessLinkManageTableEntity::getLinkName, param.getActivityName()); } @@ -336,6 +340,9 @@ public PagingList pageActivities(ActivityQueryParam param) { if (CollectionUtils.isNotEmpty(param.getUserIdList())) { lambdaQueryWrapper.in(BusinessLinkManageTableEntity::getUserId, param.getUserIdList()); } + if (CollectionUtils.isNotEmpty(param.getDeptIdList())) { + lambdaQueryWrapper.in(BusinessLinkManageTableEntity::getDeptId, param.getDeptIdList()); + } if(param.getType() != null) { lambdaQueryWrapper.eq(BusinessLinkManageTableEntity::getType, param.getType()); } @@ -376,6 +383,7 @@ public PagingList pageActivities(ActivityQueryParam param) { result.setCreateTime(entity.getCreateTime()); result.setUpdateTime(entity.getUpdateTime()); result.setBusinessDomain(entity.getBusinessDomain()); + result.setDeptId(entity.getDeptId()); result.setCanDelete(entity.getCanDelete()); if (entity.getRelatedTechLink() != null) { LinkManageTableEntity linkManageTableEntity = linkMap.get( @@ -469,6 +477,7 @@ private ActivityListResult toListResult(BusinessLinkManageTableEntity entity) { r.setIsDeleted(entity.getIsDeleted()); r.setEntrace(entity.getEntrace()); r.setUserId(entity.getUserId()); + r.setDeptId(entity.getDeptId()); r.setCreateTime(entity.getCreateTime()); r.setUpdateTime(entity.getUpdateTime()); r.setBusinessDomain(entity.getBusinessDomain()); diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAO.java index 7005360c58..03d6318f15 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAO.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAO.java @@ -101,7 +101,8 @@ public interface ApplicationApiDAO { * @param userIds 用户主键 * @return 数据项 */ - List selectBySelective(@Param("record") ApplicationApiQueryParam record, @Param("userIds") List userIds); + List selectBySelective(@Param("record") ApplicationApiQueryParam record, + @Param("userIds") List userIds, @Param("deptIds") List deptIds); /** * 批量新增 diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAOImpl.java index dcc4e623ac..258d77e653 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationApiDAOImpl.java @@ -45,6 +45,7 @@ public int insert(ApplicationApiCreateParam param) { entity.setTenantId(param.getTenantId()); entity.setUserId(param.getUserId()); entity.setIsAgentRegiste(param.getIsAgentRegiste()); + entity.setDeptId(param.getDeptId()); return apiManageMapper.insert(entity); } @@ -137,8 +138,8 @@ public List querySimpleWithTenant(ApplicationApiPara } @Override - public List selectBySelective(ApplicationApiQueryParam record, List userIds) { - List query = apiManageMapper.selectBySelective(record, userIds); + public List selectBySelective(ApplicationApiQueryParam record, List userIds, List deptIds) { + List query = apiManageMapper.selectBySelective(record, userIds, deptIds); if (CollectionUtils.isEmpty(query)) { return Lists.newArrayList(); } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAO.java index 37511d998b..538809b336 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAO.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAO.java @@ -80,7 +80,7 @@ public interface ApplicationDAO { * @param userIdList * @return */ - List getApplicationListByUserIds(List userIdList); + List getApplicationListByUserIds(List userIdList, List deptIdList); /** * 获取应用 @@ -268,7 +268,7 @@ public interface ApplicationDAO { * @param keyword * @return */ - List getApplicationMntByUserIdsAndKeyword(List userIds, String keyword); + List getApplicationMntByUserIdsAndKeyword(List userIds, List deptIdList, String keyword); /** * 判断是否存在 diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAOImpl.java index 459191eaa7..51d0c1225d 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDAOImpl.java @@ -254,12 +254,15 @@ private List toAppResult(List applicationR } @Override - public List getApplicationListByUserIds(List userIdList) { + public List getApplicationListByUserIds(List userIdList, List deptIdList) { List applicationDetailResultList = Lists.newArrayList(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!CollectionUtils.isEmpty(userIdList)) { wrapper.in(ApplicationMntEntity::getUserId, userIdList); } + if (!CollectionUtils.isEmpty(deptIdList)) { + wrapper.in(ApplicationMntEntity::getDeptId, deptIdList); + } List entityList = applicationMntMapper.selectList(wrapper); if (CollectionUtils.isEmpty(entityList)) { return applicationDetailResultList; @@ -305,6 +308,9 @@ public List getApplicationList(ApplicationQueryParam pa if (StringUtils.isNotBlank(param.getEnvCode())) { wrapper.eq(ApplicationMntEntity::getEnvCode, param.getEnvCode()); } + if(StringUtils.isNotBlank(param.getApplicationName())){ + wrapper.eq(ApplicationMntEntity::getApplicationName, param.getApplicationName()); + } return getApplicationDetailResults(wrapper); } @@ -312,8 +318,11 @@ public List getApplicationList(ApplicationQueryParam pa public List getAllApplicationName(ApplicationQueryParam param) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.select(ApplicationMntEntity::getApplicationName); - if (CollectionUtils.isNotEmpty(WebPluginUtils.getQueryAllowUserIdList())) { - wrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.getQueryAllowUserIdList()); + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowUserIdList())) { + wrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.queryAllowUserIdList()); + } + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowDeptIdList())) { + wrapper.in(ApplicationMntEntity::getDeptId, WebPluginUtils.queryAllowDeptIdList()); } List entities = applicationMntMapper.selectList(wrapper); return entities.stream() @@ -521,8 +530,11 @@ public List getDashboardAppData() { queryWrapper.select(ApplicationMntEntity::getApplicationId, ApplicationMntEntity::getApplicationName, ApplicationMntEntity::getNodeNum, ApplicationMntEntity::getAgentVersion); - if (CollectionUtils.isNotEmpty(WebPluginUtils.getQueryAllowUserIdList())) { - queryWrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.getQueryAllowUserIdList()); + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowUserIdList())) { + queryWrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.queryAllowUserIdList()); + } + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowDeptIdList())) { + queryWrapper.in(ApplicationMntEntity::getDeptId, WebPluginUtils.queryAllowDeptIdList()); } List applicationMntEntities = applicationMntMapper.selectList(queryWrapper); if (CollectionUtils.isEmpty(applicationMntEntities)) { @@ -541,10 +553,10 @@ public List getAllApplicationByStatus(List sta } @Override - public List getApplicationMntByUserIdsAndKeyword(List userIds, String keyword) { + public List getApplicationMntByUserIdsAndKeyword(List userIds, List deptIdList, String keyword) { List allApplications = applicationMntMapper.getApplicationMntByUserIdsAndKeyword(userIds, - keyword); + deptIdList, keyword); if (CollectionUtils.isEmpty(allApplications)) { return Lists.newArrayList(); } @@ -565,8 +577,11 @@ public PagingList queryApplicationList(ApplicationQuery if (CollectionUtils.isNotEmpty(queryParam.getApplicationIds())) { queryWrapper.in(ApplicationMntEntity::getApplicationId, queryParam.getApplicationIds()); } - if (CollectionUtils.isNotEmpty(WebPluginUtils.getQueryAllowUserIdList())) { - queryWrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.getQueryAllowUserIdList()); + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowUserIdList())) { + queryWrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.queryAllowUserIdList()); + } + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowDeptIdList())) { + queryWrapper.in(ApplicationMntEntity::getDeptId, WebPluginUtils.queryAllowDeptIdList()); } queryWrapper.orderByDesc(ApplicationMntEntity::getApplicationId); if (queryParam.getPageSize() > 0) { @@ -644,8 +659,11 @@ public String getIdByName(String applicationName) { @Override public Long getApplicationCount() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (CollectionUtils.isNotEmpty(WebPluginUtils.getQueryAllowUserIdList())) { - queryWrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.getQueryAllowUserIdList()); + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowUserIdList())) { + queryWrapper.in(ApplicationMntEntity::getUserId, WebPluginUtils.queryAllowUserIdList()); + } + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowDeptIdList())) { + queryWrapper.in(ApplicationMntEntity::getDeptId, WebPluginUtils.queryAllowDeptIdList()); } return applicationMntMapper.selectCount(queryWrapper); } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDAOImpl.java index ef0f907885..cf2fb6f916 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDAOImpl.java @@ -54,7 +54,8 @@ public int insert(ApplicationDsCreateParam createParam) { //数据加密处理 aes(entity); - return applicationDsManageMapper.insert(entity); + applicationDsManageMapper.insert(entity); + return entity.getId().intValue(); } /** diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDbTableDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDbTableDAO.java index d171b37482..64848d81e3 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDbTableDAO.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/ApplicationDsDbTableDAO.java @@ -1,5 +1,6 @@ package io.shulie.takin.web.data.dao.application; +import io.shulie.takin.web.data.model.mysql.ApplicationDsDbTableEntity; import io.shulie.takin.web.data.result.application.ApplicationDsDbTableDetailResult; import java.util.List; @@ -12,11 +13,22 @@ */ public interface ApplicationDsDbTableDAO { - List getList(String url,Long appId,String userName); + List getList(String url, Long appId, String userName); - void batchSave(List list); + List queryList(String url, Long appId, String userName, String bizTable); + void batchSave(List list); - void batchDeleted(List list); + void saveOrUpdate(List list); + + List batchSave_ext(List list); + + void batchDeleted(List list); + + void batchDeleted_V2(List list); + + ApplicationDsDbTableEntity getOne(Long id); + + void update_v2(ApplicationDsDbTableEntity entity); } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbManageDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbManageDAOImpl.java index c0eb80c17b..2a8494a01d 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbManageDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbManageDAOImpl.java @@ -27,7 +27,7 @@ * @date 2021-08-30 10:59:59 */ @Service -public class ApplicationDsDbManageDAOImpl extends ServiceImpl implements ApplicationDsDbManageDAO, MPUtil { +public class ApplicationDsDbManageDAOImpl extends ServiceImpl implements ApplicationDsDbManageDAO, MPUtil { @Override public List selectList(ApplicationDsQueryParam param) { @@ -40,11 +40,11 @@ public List selectList(ApplicationDsQueryPara } if (!Objects.isNull(param.getIsDeleted())) { lambdaQueryWrapper.eq(ApplicationDsDbManageEntity::getIsDeleted, param.getIsDeleted()); - }else{ + } else { lambdaQueryWrapper.eq(ApplicationDsDbManageEntity::getIsDeleted, 0); } if (CollectionUtils.isNotEmpty(param.getUserIdList())) { - if(!param.getUserIdList().contains(1)){ + if (!param.getUserIdList().contains(1)) { lambdaQueryWrapper.in(ApplicationDsDbManageEntity::getUserId, param.getUserIdList()); } } @@ -69,8 +69,8 @@ public ApplicationDsDbManageDetailResult selectOneById(Long id) { @Override public void updateById(Long id, ApplicationDsDbManageEntity entity) { LambdaQueryWrapper lambdaQueryWrapper = this.getLambdaQueryWrapper(); - lambdaQueryWrapper.eq(ApplicationDsDbManageEntity::getId,id); - this.update(entity,lambdaQueryWrapper); + lambdaQueryWrapper.eq(ApplicationDsDbManageEntity::getId, id); + this.update(entity, lambdaQueryWrapper); } @Override @@ -104,7 +104,7 @@ private ApplicationDsDbManageEntity getEntity(ApplicationDsDbManageDetailResult return null; } ApplicationDsDbManageEntity entity = new ApplicationDsDbManageEntity(); - BeanUtils.copyProperties( result,entity); + BeanUtils.copyProperties(result, entity); return result; } @@ -116,13 +116,14 @@ private List getEntitys(List lambdaQueryWrapper = this.getLambdaQueryWrapper(); - lambdaQueryWrapper.eq(ApplicationDsDbManageEntity::getApplicationName,appName) - .eq(ApplicationDsDbManageEntity::getUrl,url) - .eq(ApplicationDsDbManageEntity::getUserName,userName) - .eq(ApplicationDsDbManageEntity::getConnPoolName,connPoolName) - .eq(ApplicationDsDbManageEntity::getIsDeleted,0); + lambdaQueryWrapper.eq(ApplicationDsDbManageEntity::getApplicationName, appName) + .eq(ApplicationDsDbManageEntity::getUrl, url) + .eq(ApplicationDsDbManageEntity::getUserName, userName) + .eq(ApplicationDsDbManageEntity::getConnPoolName, connPoolName) + .eq(ApplicationDsDbManageEntity::getIsDeleted, 0); + lambdaQueryWrapper.last(" limit 1"); return getApplicationDsDbManageDetailResult(this.getOne(lambdaQueryWrapper)); } } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbTableDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbTableDAOImpl.java index 2bcfceeda3..0aaed4ba12 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbTableDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/application/impl/ApplicationDsDbTableDAOImpl.java @@ -10,6 +10,7 @@ import io.shulie.takin.web.data.result.application.ApplicationDsDbTableDetailResult; import io.shulie.takin.web.data.util.MPUtil; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @@ -24,17 +25,30 @@ * @date 2021-09-15 17:21:41 */ @Service -public class ApplicationDsDbTableDAOImpl extends ServiceImpl +public class ApplicationDsDbTableDAOImpl extends ServiceImpl implements ApplicationDsDbTableDAO, MPUtil { - @Override public List getList(String url, Long appId, String userName) { LambdaQueryWrapper lambdaQueryWrapper = this.getLambdaQueryWrapper() - .eq(ApplicationDsDbTableEntity::getAppId,appId) - .eq(ApplicationDsDbTableEntity::getUrl,url) - .eq(ApplicationDsDbTableEntity::getUserName,userName) - .eq(ApplicationDsDbTableEntity::getIsDeleted,0); + .eq(ApplicationDsDbTableEntity::getAppId, appId) + .eq(ApplicationDsDbTableEntity::getUrl, url) + .eq(ApplicationDsDbTableEntity::getUserName, userName) + .eq(ApplicationDsDbTableEntity::getIsDeleted, 0); + List list = this.list(lambdaQueryWrapper); + return getApplicationDsDbTableDetailResults(list); + } + + @Override + public List queryList(String url, Long appId, String userName, String bizTable) { + LambdaQueryWrapper lambdaQueryWrapper = this.getLambdaQueryWrapper() + .eq(ApplicationDsDbTableEntity::getAppId, appId) + .eq(ApplicationDsDbTableEntity::getUrl, url) + .eq(ApplicationDsDbTableEntity::getUserName, userName) + .eq(ApplicationDsDbTableEntity::getIsDeleted, 0); + if (StringUtils.isNotBlank(bizTable)) { + lambdaQueryWrapper.eq(ApplicationDsDbTableEntity::getBizTable, bizTable); + } List list = this.list(lambdaQueryWrapper); return getApplicationDsDbTableDetailResults(list); } @@ -46,6 +60,17 @@ public void batchSave(List list) { this.saveBatch(entities); } + @Override + public void saveOrUpdate(List list) { + } + + @Override + public List batchSave_ext(List list) { + List entities = this.getEntitys(list); + this.saveBatch(entities); + return entities; + } + @Override public void batchDeleted(List list) { List entities = this.getEntitys(list); @@ -53,6 +78,21 @@ public void batchDeleted(List list) { this.removeByIds(ids); } + @Override + public void batchDeleted_V2(List ids) { + this.removeByIds(ids); + } + + @Override + public ApplicationDsDbTableEntity getOne(Long id) { + return this.getById(id); + } + + @Override + public void update_v2(ApplicationDsDbTableEntity entity) { + this.updateById(entity); + } + private ApplicationDsDbTableDetailResult getApplicationDsDbTableDetailResult(ApplicationDsDbTableEntity entity) { if (Objects.isNull(entity)) { return null; diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/blacklist/BlackListDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/blacklist/BlackListDAOImpl.java index 340e485fb6..0c30369268 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/blacklist/BlackListDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/blacklist/BlackListDAOImpl.java @@ -20,6 +20,7 @@ import io.shulie.takin.web.data.param.blacklist.BlacklistUpdateParam; import io.shulie.takin.web.data.result.blacklist.BlacklistResult; import io.shulie.takin.web.ext.entity.tenant.TenantCommonExt; +import io.shulie.takin.web.ext.util.WebPluginUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -45,6 +46,7 @@ public int insert(BlackListCreateParam param) { entity.setUseYn(param.getUseYn()); entity.setGmtCreate(param.getCreateTime()); entity.setGmtModified(param.getUpdateTime()); + entity.setDeptId(WebPluginUtils.traceDeptId()); return blackListMapper.insert(entity); } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/datasource/DataSourceDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/datasource/DataSourceDAOImpl.java index a5877568f5..74594d0e89 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/datasource/DataSourceDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/datasource/DataSourceDAOImpl.java @@ -60,9 +60,15 @@ public PagingList selectPage(DataSourceQueryParam queryParam) if (CollectionUtils.isNotEmpty(queryParam.getDataSourceIdList())) { wrapper.in(TakinDbresourceEntity::getId, queryParam.getDataSourceIdList()); } + if (queryParam.getDeptId() != null){ + wrapper.eq(TakinDbresourceEntity::getDeptId, queryParam.getDeptId()); + } // 数据权限 - if (CollectionUtils.isNotEmpty(WebPluginUtils.getQueryAllowUserIdList())) { - wrapper.in(TakinDbresourceEntity::getUserId, WebPluginUtils.getQueryAllowUserIdList()); + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowUserIdList())) { + wrapper.in(TakinDbresourceEntity::getUserId, WebPluginUtils.queryAllowUserIdList()); + } + if (CollectionUtils.isNotEmpty(WebPluginUtils.queryAllowDeptIdList())) { + wrapper.in(TakinDbresourceEntity::getDeptId, WebPluginUtils.queryAllowDeptIdList()); } Page page = new Page<>(queryParam.getCurrent(), queryParam.getPageSize()); wrapper.orderByDesc(TakinDbresourceEntity::getUpdateTime); @@ -134,6 +140,7 @@ public DataSourceResult selectSingle(DataSourceSingleQueryParam queryParam) { dataSourceResult.setCreateTime(datasourceEntity.getCreateTime()); dataSourceResult.setUpdateTime(datasourceEntity.getUpdateTime()); dataSourceResult.setUserId(datasourceEntity.getUserId()); + dataSourceResult.setDeptId(datasourceEntity.getDeptId()); return dataSourceResult; } return null; diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/impl/SceneExcludedApplicationDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/impl/SceneExcludedApplicationDAOImpl.java index 07b9216828..5302ef9572 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/impl/SceneExcludedApplicationDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/impl/SceneExcludedApplicationDAOImpl.java @@ -20,7 +20,7 @@ */ @Service public class SceneExcludedApplicationDAOImpl - implements SceneExcludedApplicationDAO, MPUtil { + implements SceneExcludedApplicationDAO, MPUtil { @Autowired private SceneExcludedApplicationMapper sceneExcludedApplicationMapper; @@ -28,15 +28,15 @@ public class SceneExcludedApplicationDAOImpl @Override public boolean saveBatch(List createSceneExcludedApplicationParams) { return SqlHelper.retBool(sceneExcludedApplicationMapper.insertBatch( - createSceneExcludedApplicationParams)); + createSceneExcludedApplicationParams)); } @Override public List listApplicationIdsBySceneId(Long sceneId) { return sceneExcludedApplicationMapper.selectObjs(this.getLambdaQueryWrapper() - .select(SceneExcludedApplicationEntity::getApplicationId) - .eq(SceneExcludedApplicationEntity::getSceneId, sceneId)).stream() - .map(obj -> Long.valueOf(obj.toString())).collect(Collectors.toList()); + .select(SceneExcludedApplicationEntity::getApplicationId) + .eq(SceneExcludedApplicationEntity::getSceneId, sceneId)).stream() + .map(obj -> Long.valueOf(obj.toString())).collect(Collectors.toList()); } @Override @@ -44,5 +44,22 @@ public void removeBySceneId(Long sceneId) { sceneExcludedApplicationMapper.delete(this.getLambdaQueryWrapper().eq(SceneExcludedApplicationEntity::getSceneId, sceneId)); } + @Override + public void removeBySceneIdAndAppId(Long sceneId, Long appId) { + sceneExcludedApplicationMapper.delete(this.getLambdaQueryWrapper() + .eq(SceneExcludedApplicationEntity::getSceneId, sceneId) + .eq(SceneExcludedApplicationEntity::getApplicationId, appId)); + + } + + @Override + public SceneExcludedApplicationEntity query(Long sceneId, Long appId) { + return sceneExcludedApplicationMapper.selectOne(this.getLambdaQueryWrapper() + .select(SceneExcludedApplicationEntity::getApplicationId) + .eq(SceneExcludedApplicationEntity::getSceneId, sceneId) + .eq(SceneExcludedApplicationEntity::getApplicationId, appId) + .last("limit 1")); + } + } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAO.java index 830e03e24c..50465b812f 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAO.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAO.java @@ -14,7 +14,7 @@ * @date 2020/11/4 2:56 下午 */ public interface SceneDAO { - int insert(SceneCreateParam param); + Long insert(SceneCreateParam param); /** * 指定责任人-业务流程 diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAOImpl.java index 11b13fc801..990448b2b6 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/linkmanage/SceneDAOImpl.java @@ -40,12 +40,12 @@ public class SceneDAOImpl implements SceneDAO { private SceneMapper sceneMapper; @Override - public int insert(SceneCreateParam param) { + public Long insert(SceneCreateParam param) { SceneEntity entity = new SceneEntity(); BeanUtils.copyProperties(param, entity); - int count = sceneMapper.insert(entity); + sceneMapper.insert(entity); param.setId(entity.getId()); - return count; + return entity.getId(); } /** @@ -58,7 +58,7 @@ public int insert(SceneCreateParam param) { public int allocationUser(SceneUpdateParam param) { LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper(); wrapper.set(SceneEntity::getUserId, param.getUserId()) - .eq(SceneEntity::getId, param.getId()); + .eq(SceneEntity::getId, param.getId()); return sceneMapper.update(null, wrapper); } @@ -74,10 +74,10 @@ public List selectList(SceneQueryParam queryParam) { } queryWrapper.eq(SceneEntity::getIsDeleted, 0); queryWrapper.select( - SceneEntity::getId, - SceneEntity::getSceneName, - SceneEntity::getTenantId, - SceneEntity::getUserId); + SceneEntity::getId, + SceneEntity::getSceneName, + SceneEntity::getTenantId, + SceneEntity::getUserId); List sceneEntityList = sceneMapper.selectList(queryWrapper); if (CollectionUtils.isNotEmpty(sceneEntityList)) { sceneResultList = sceneEntityList.stream().map(sceneEntity -> { @@ -104,10 +104,10 @@ public List selectListByName(SceneQueryParam queryParam) { } queryWrapper.eq(SceneEntity::getIsDeleted, 0); queryWrapper.select( - SceneEntity::getId, - SceneEntity::getSceneName, - SceneEntity::getTenantId, - SceneEntity::getUserId); + SceneEntity::getId, + SceneEntity::getSceneName, + SceneEntity::getTenantId, + SceneEntity::getUserId); List sceneEntityList = sceneMapper.selectList(queryWrapper); if (CollectionUtils.isNotEmpty(sceneEntityList)) { sceneResultList = sceneEntityList.stream().map(sceneEntity -> { @@ -134,7 +134,9 @@ public int update(SceneUpdateParam sceneUpdateParam) { @Override public SceneResult getSceneDetail(Long id) { SceneEntity sceneEntity = sceneMapper.selectById(id); - if (sceneEntity == null) {return null;} + if (sceneEntity == null) { + return null; + } return BeanUtil.copyProperties(sceneEntity, SceneResult.class); } @@ -148,12 +150,21 @@ public PagingList selectPageList(ScenePageQueryParam param) { if (!StringUtils.isEmpty(param.getSceneName())) { lambdaQueryWrapper.like(SceneEntity::getSceneName, "\\" + param.getSceneName()); } + if (param.getDeptId() != null){ + lambdaQueryWrapper.eq(SceneEntity::getDeptId, param.getDeptId()); + } if (CollectionUtils.isNotEmpty(param.getUserIdList())) { lambdaQueryWrapper.in(SceneEntity::getUserId, param.getUserIdList()); } + if (CollectionUtils.isNotEmpty(param.getDeptIdList())) { + lambdaQueryWrapper.in(SceneEntity::getDeptId, param.getDeptIdList()); + } if (param.getIgnoreType() != null) { lambdaQueryWrapper.ne(SceneEntity::getType, param.getIgnoreType()); } + if (param.getQueryGmtModified() != null) { + lambdaQueryWrapper.ge(SceneEntity::getUpdateTime, param.getQueryGmtModified()); + } lambdaQueryWrapper.eq(SceneEntity::getIsDeleted, 0); lambdaQueryWrapper.orderByDesc(SceneEntity::getUpdateTime); Page sceneEntityPage = sceneMapper.selectPage(page, lambdaQueryWrapper); @@ -161,16 +172,16 @@ public PagingList selectPageList(ScenePageQueryParam param) { return PagingList.of(Lists.newArrayList(), 0); } List sceneResultList = BusinessLinkManageConvert.INSTANCE.ofSceneEntityList( - sceneEntityPage.getRecords()); + sceneEntityPage.getRecords()); return PagingList.of(sceneResultList, sceneEntityPage.getTotal()); } @Override public boolean existsScene(Long tenantId, String envCode) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(SceneEntity.class) - .eq(SceneEntity::getTenantId, tenantId) - .eq(SceneEntity::getEnvCode, envCode) - .eq(SceneEntity::getIsDeleted, 0); + .eq(SceneEntity::getTenantId, tenantId) + .eq(SceneEntity::getEnvCode, envCode) + .eq(SceneEntity::getIsDeleted, 0); return SqlHelper.retBool(sceneMapper.selectCount(wrapper)); } } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/AppDataSourceDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/AppDataSourceDAO.java new file mode 100644 index 0000000000..8fd2d6792b --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/AppDataSourceDAO.java @@ -0,0 +1,14 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceAppDataSourceEntity; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:22 AM + */ +public interface AppDataSourceDAO { + void saveOrUpdate(List entitys); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/MockInfo.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/MockInfo.java new file mode 100644 index 0000000000..d0123c62f2 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/MockInfo.java @@ -0,0 +1,21 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/16 12:32 PM + */ +@Data +public class MockInfo { + @ApiModelProperty("类型 0-json格式 1-脚本格式") + private String type; + + @ApiModelProperty("mock数据") + private String mockValue; + + @ApiModelProperty("响应时间") + private Integer responseTime; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceDAO.java new file mode 100644 index 0000000000..f50f957ecf --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceDAO.java @@ -0,0 +1,48 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceQueryParam; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +public interface PressureResourceDAO { + /** + * 新增 + * + * @param insertEntity + * @return + */ + Long add(PressureResourceEntity insertEntity); + + /** + * 列表分页查询 + * + * @param param + * @return + */ + PagingList pageList(PressureResourceQueryParam param); + + /** + * 按名称查询 + * + * @param name + * @return + */ + PressureResourceEntity queryByName(String name); + + /** + * 获取所有 + * + * @return + */ + List getAll(); + + + void delete(Long sourceId); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceDetailDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceDetailDAO.java new file mode 100644 index 0000000000..79c5276e64 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceDetailDAO.java @@ -0,0 +1,30 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceDetailEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDetailQueryParam; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 6:54 PM + */ +public interface PressureResourceDetailDAO { + /** + * 按条件查询 + * + * @param params + * @return + */ + List getList(PressureResourceDetailQueryParam params); + + /** + * 新增 + * + * @param insertList + */ + void batchInsert(List insertList); + + void updateEntranceName(PressureResourceDetailEntity detailEntity); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateAppDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateAppDAO.java new file mode 100644 index 0000000000..5e3db1e6f6 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateAppDAO.java @@ -0,0 +1,36 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateAppEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceAppQueryParam; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +public interface PressureResourceRelateAppDAO { + /** + * 分页 + * + * @param param + * @return + */ + PagingList pageList(PressureResourceAppQueryParam param); + + /** + * 内部查询 + * + * @param param + * @return + */ + List queryList(PressureResourceAppQueryParam param); + + /** + * 存在则更新 + */ + void saveOrUpdate(List list); + +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateDsDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateDsDAO.java new file mode 100644 index 0000000000..815cfbef3f --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateDsDAO.java @@ -0,0 +1,29 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateDsEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateDsEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDsQueryParam; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +public interface PressureResourceRelateDsDAO { + /** + * 新增 + * + * @param dsEntitys + */ + void add_v2(List dsEntitys); + + /** + * 按条件查询列表页 + * + * @param param + * @return + */ + List queryByParam_v2(PressureResourceDsQueryParam param); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateMqComsumerDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateMqComsumerDAO.java new file mode 100644 index 0000000000..7403caa780 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateMqComsumerDAO.java @@ -0,0 +1,44 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateMqConsumerEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceMqConsumerQueryParam; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +public interface PressureResourceRelateMqComsumerDAO { + /** + * 列表分页查询 + * + * @param param + * @return + */ + PagingList pageList(PressureResourceMqConsumerQueryParam param); + + /** + * 新增 + * + * @param mqConsumerEntity + */ + void add(PressureResourceRelateMqConsumerEntity mqConsumerEntity); + + /** + * 内部条件查询 + * + * @param param + * @return + */ + List queryList(PressureResourceMqConsumerQueryParam param); + + /** + * 批量操作 + * + * @param mqConsumerEntityList + */ + void saveOrUpdate(List mqConsumerEntityList); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateRemoteCallDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateRemoteCallDAO.java new file mode 100644 index 0000000000..875ea2345b --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateRemoteCallDAO.java @@ -0,0 +1,31 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateRemoteCallEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateRemoteCallEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceRemoteCallQueryParam; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +public interface PressureResourceRelateRemoteCallDAO { + /** + * 批量保存 + * + * @param remoteCallEntityList + */ + void saveOrUpdate_v2(List remoteCallEntityList); + + /** + * 分页 + * + * @param param + * @return + */ + PagingList pageList_v2(PressureResourceRemoteCallQueryParam param); + +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateTableDAO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateTableDAO.java new file mode 100644 index 0000000000..080b829633 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/PressureResourceRelateTableDAO.java @@ -0,0 +1,45 @@ +package io.shulie.takin.web.data.dao.pressureresource; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateTableEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateTableEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceTableQueryParam; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +public interface PressureResourceRelateTableDAO { + /** + * 新增 + * + * @param dsEntitys + */ + void add_V2(List dsEntitys); + + /** + * 分页 + * + * @param param + * @return + */ + PagingList pageList_v2(PressureResourceTableQueryParam param); + + /** + * @param param + * @return + */ + List queryList_v2(PressureResourceTableQueryParam param); + + /** + * 批量保存 + * + * @param tableEntitys + */ + void saveOrUpdate(List tableEntitys); + + void deleteByParam(PressureResourceTableQueryParam queryParam); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/AppDataSourceDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/AppDataSourceDAOImpl.java new file mode 100644 index 0000000000..3f0142d54b --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/AppDataSourceDAOImpl.java @@ -0,0 +1,29 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import io.shulie.takin.web.data.dao.pressureresource.AppDataSourceDAO; +import io.shulie.takin.web.data.mapper.mysql.AppDataSourceMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceAppDataSourceEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:23 AM + */ +@Service +public class AppDataSourceDAOImpl implements AppDataSourceDAO { + private static Logger logger = LoggerFactory.getLogger(AppDataSourceDAOImpl.class); + + @Resource + private AppDataSourceMapper appDataSourceMapper; + + @Override + public void saveOrUpdate(List list) { + appDataSourceMapper.saveOrUpdate(list); + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceDAOImpl.java new file mode 100644 index 0000000000..cf075a07ac --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceDAOImpl.java @@ -0,0 +1,92 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceQueryParam; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +@Service +public class PressureResourceDAOImpl implements PressureResourceDAO { + private static Logger logger = LoggerFactory.getLogger(PressureResourceDAOImpl.class); + + @Resource + private PressureResourceMapper pressureResourceMapper; + + /** + * 新增 + * + * @param insertEntity + */ + @Override + public Long add(PressureResourceEntity insertEntity) { + pressureResourceMapper.insert(insertEntity); + return insertEntity.getId(); + } + + /** + * 分页查询 + * + * @param param + * @return + */ + @Override + public PagingList pageList(PressureResourceQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper(param); + Page page = new Page<>(param.getCurrent() + 1, param.getPageSize()); + queryWrapper.orderByDesc("gmt_create"); + IPage pageList = pressureResourceMapper.selectPage(page, queryWrapper); + if (pageList.getRecords().isEmpty()) { + return PagingList.empty(); + } + return PagingList.of(pageList.getRecords(), pageList.getTotal()); + } + + @Override + public PressureResourceEntity queryByName(String name) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("name", name); + queryWrapper.last(" limit 1"); + return pressureResourceMapper.selectOne(queryWrapper); + } + + @Override + public List getAll() { + return pressureResourceMapper.getAll(); + } + + @Override + public void delete(Long sourceId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("source_id", sourceId); + pressureResourceMapper.delete(queryWrapper); + } + + private QueryWrapper getWrapper(PressureResourceQueryParam param) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (param == null) { + return queryWrapper; + } + if (param.getName() != null) { + queryWrapper.like("name", param.getName()); + } + if (param.getSourceId() != null) { + queryWrapper.eq("source_id", param.getSourceId()); + } + return queryWrapper; + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceDetailDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceDetailDAOImpl.java new file mode 100644 index 0000000000..dae450d402 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceDetailDAOImpl.java @@ -0,0 +1,73 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceDetailDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceDetailMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceDetailEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDetailQueryParam; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 6:59 PM + */ +@Service +public class PressureResourceDetailDAOImpl implements PressureResourceDetailDAO { + private static Logger logger = LoggerFactory.getLogger(PressureResourceDAOImpl.class); + + @Resource + private PressureResourceDetailMapper pressureResourceDetailMapper; + + @Override + public List getList(PressureResourceDetailQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper(param); + return pressureResourceDetailMapper.selectList(queryWrapper); + } + + /** + * 批量新增 + * + * @param insertList + */ + @Override + public void batchInsert(List insertList) { + if (CollectionUtils.isEmpty(insertList)) { + return; + } + pressureResourceDetailMapper.saveOrUpdate(insertList); + } + + @Override + public void updateEntranceName(PressureResourceDetailEntity detailEntity) { + PressureResourceDetailEntity update = new PressureResourceDetailEntity(); + update.setEntranceName(detailEntity.getEntranceName()); + QueryWrapper updateWrapper = new QueryWrapper<>(); + updateWrapper.eq("link_id", detailEntity.getLinkId()); + pressureResourceDetailMapper.update(update, updateWrapper); + } + + private QueryWrapper getWrapper(PressureResourceDetailQueryParam param) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (param == null) { + return queryWrapper; + } + if (param.getResourceId() != null) { + queryWrapper.eq("resource_id", param.getResourceId()); + } + if (CollectionUtils.isNotEmpty(param.getResourceIds())) { + queryWrapper.in("resource_id", param.getResourceIds()); + } + if (StringUtils.isNotBlank(param.getLinkId())) { + queryWrapper.eq("link_id", param.getLinkId()); + } + return queryWrapper; + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateAppDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateAppDAOImpl.java new file mode 100644 index 0000000000..803dc272f3 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateAppDAOImpl.java @@ -0,0 +1,102 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateAppDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateAppMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateAppEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceAppQueryParam; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/31 2:37 PM + */ +@Service +public class PressureResourceRelateAppDAOImpl implements PressureResourceRelateAppDAO { + private static Logger logger = LoggerFactory.getLogger(PressureResourceRelateAppDAOImpl.class); + + @Resource + private PressureResourceRelateAppMapper pressureResourceRelateAppMapper; + + /** + * 分页 + * + * @param param + * @return + */ + @Override + public PagingList pageList(PressureResourceAppQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper(param); + Page page = new Page<>(param.getCurrent() + 1, param.getPageSize()); + queryWrapper.orderByDesc("gmt_modified"); + IPage pageList = pressureResourceRelateAppMapper.selectPage(page, queryWrapper); + if (pageList.getRecords().isEmpty()) { + return PagingList.empty(); + } + return PagingList.of(pageList.getRecords(), pageList.getTotal()); + } + + @Override + public List queryList(PressureResourceAppQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper(param); + return pressureResourceRelateAppMapper.selectList(queryWrapper); + } + + /** + * 保存或更新 + * + * @param list + */ + @Override + public void saveOrUpdate(List list) { + if (CollectionUtils.isEmpty(list)) { + return; + } + list.stream().forEach(appEntity -> { + pressureResourceRelateAppMapper.saveOrUpdate(appEntity); + }); + } + + private QueryWrapper getWrapper(PressureResourceAppQueryParam param) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (param == null) { + return queryWrapper; + } + if (StringUtils.isNotBlank(param.getAppName())) { + queryWrapper.like("app_name", param.getAppName()); + } + if (CollectionUtils.isNotEmpty(param.getAppNames())) { + queryWrapper.in("app_name", param.getAppNames()); + } + if (param.getStatus() != null) { + queryWrapper.eq("status", param.getStatus()); + } + if (param.getJoinPressure() != null) { + queryWrapper.eq("join_pressure", param.getJoinPressure()); + } + if (param.getDetailId() != null) { + queryWrapper.eq("detail_id", param.getDetailId()); + } + if (CollectionUtils.isNotEmpty(param.getDetailIds())) { + queryWrapper.in("detail_id", param.getDetailIds()); + } + if (param.getResourceId() != null) { + queryWrapper.eq("resource_id", param.getResourceId()); + } + if (CollectionUtils.isNotEmpty(param.getResourceIds())) { + queryWrapper.in("resource_id", param.getResourceIds()); + } + return queryWrapper; + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateDsDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateDsDAOImpl.java new file mode 100644 index 0000000000..87e9677339 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateDsDAOImpl.java @@ -0,0 +1,109 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Lists; +import io.shulie.takin.web.data.dao.application.ApplicationDsDbManageDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateDsDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateDsMapperV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateDsEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateDsEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceDsQueryParam; +import io.shulie.takin.web.data.result.application.ApplicationDsDbManageDetailResult; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/31 7:41 PM + */ +@Service +public class PressureResourceRelateDsDAOImpl implements PressureResourceRelateDsDAO { + private static Logger logger = LoggerFactory.getLogger(PressureResourceRelateDsDAOImpl.class); + + @Resource + private PressureResourceRelateDsMapperV2 pressureResourceRelateDsMapperV2; + + @Autowired + private ApplicationDsDbManageDAO dbManageDAO; + + /** + * 批量新增 + * + * @param dsEntitys + */ + @Override + public void add_v2(List dsEntitys) { + if (CollectionUtils.isNotEmpty(dsEntitys)) { + dsEntitys.stream().forEach(entity -> { + pressureResourceRelateDsMapperV2.saveOrUpdate(entity); + }); + } + } + + @Override + public List queryByParam_v2(PressureResourceDsQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper_v2(param); + List resultLists = pressureResourceRelateDsMapperV2.selectList(queryWrapper); + if (CollectionUtils.isEmpty(resultLists)) { + return Collections.emptyList(); + } + List rsList = Lists.newArrayList(); + // 转换下所有数据源关联信息 + for (int i = 0; i < resultLists.size(); i++) { + // 关联数据源信息 + PressureResourceRelateDsEntityV2 v2 = resultLists.get(i); + ApplicationDsDbManageDetailResult dsDbManageDetailResult = dbManageDAO.selectOneById(v2.getRelateId()); + if (dsDbManageDetailResult == null) { + logger.warn("关联数据源为空,{}", v2.getRelateId()); + continue; + } + RelateDsEntity dsEntity = RelateConvert.dsManageConvertRelateDs(dsDbManageDetailResult); + dsEntity.setId(v2.getId()); + dsEntity.setResourceId(v2.getResourceId()); + dsEntity.setDetailId(v2.getDetailId()); + dsEntity.setStatus(v2.getStatus()); + dsEntity.setRemark(v2.getRemark()); + dsEntity.setType(v2.getType()); + + rsList.add(dsEntity); + } + return rsList; + } + + private QueryWrapper getWrapper_v2(PressureResourceDsQueryParam param) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (param == null) { + return queryWrapper; + } + // 模糊查询 + if (StringUtils.isNotBlank(param.getQueryBussinessDatabase())) { + queryWrapper.like("business_database", param.getQueryBussinessDatabase()); + } + // 模糊查询 + if (StringUtils.isNotBlank(param.getQueryAppName())) { + queryWrapper.like("app_name", param.getQueryAppName()); + } + if (StringUtils.isNotBlank(param.getBussinessDatabase())) { + queryWrapper.eq("business_database", param.getBussinessDatabase()); + } + if (param.getResourceId() != null) { + queryWrapper.eq("resource_id", param.getResourceId()); + } + if (param.getStatus() != null) { + queryWrapper.eq("status", param.getStatus()); + } + if (param.getId() != null) { + queryWrapper.eq("id", param.getId()); + } + return queryWrapper; + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateMqComsumerDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateMqComsumerDAOImpl.java new file mode 100644 index 0000000000..8d79aa1fec --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateMqComsumerDAOImpl.java @@ -0,0 +1,191 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.common.secure.SecureUtil; +import io.shulie.takin.web.data.dao.application.ApplicationDsDAO; +import io.shulie.takin.web.data.dao.application.ApplicationDsManageDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateMqComsumerDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateMqConsumerMapper; +import io.shulie.takin.web.data.model.mysql.ApplicationDsManageEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateMqConsumerEntity; +import io.shulie.takin.web.data.param.application.ApplicationDsQueryParam; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceMqConsumerQueryParam; +import io.shulie.takin.web.data.result.application.ApplicationDsResult; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:54 PM + */ +@Service +public class PressureResourceRelateMqComsumerDAOImpl implements PressureResourceRelateMqComsumerDAO { + @Resource + private PressureResourceRelateMqConsumerMapper pressureResourceRelateMqConsumerMapper; + + @Resource + private ApplicationDsDAO applicationDsDAO; + + @Resource + private ApplicationDsManageDAO applicationDsManageDAO; + + @Override + public PagingList pageList(PressureResourceMqConsumerQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper(param); + Page page = new Page<>(param.getCurrent() + 1, param.getPageSize()); + queryWrapper.orderByDesc("gmt_modified"); + IPage pageList = pressureResourceRelateMqConsumerMapper.selectPage(page, queryWrapper); + + List dsManageIds = pageList.getRecords().stream().filter(entity -> entity.getRelateDsManageId() != null).map(entity -> entity.getRelateDsManageId()).collect(Collectors.toList()); + if (!dsManageIds.isEmpty()) { + List manageEntities = applicationDsManageDAO.listByIds(dsManageIds); + Map mappings = new HashMap<>(); + manageEntities.forEach(applicationDsManageEntity -> mappings.put(applicationDsManageEntity.getId(), applicationDsManageEntity)); + + // 把application_ds_manage的属性填充到配置上 + pageList.getRecords().stream().forEach(entity -> { + if (entity.getRelateDsManageId() != null) { + populateProperties(entity, mappings.get(entity.getRelateDsManageId())); + } + }); + } + + if (pageList.getRecords().isEmpty()) { + return PagingList.empty(); + } + return PagingList.of(pageList.getRecords(), pageList.getTotal()); + } + + /** + * 新增 + * + * @param mqConsumerEntity + */ + @Override + public void add(PressureResourceRelateMqConsumerEntity mqConsumerEntity) { + pressureResourceRelateMqConsumerMapper.insert(mqConsumerEntity); + } + + @Override + public List queryList(PressureResourceMqConsumerQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper(param); + List resultLists = pressureResourceRelateMqConsumerMapper.selectList(queryWrapper); + if (CollectionUtils.isEmpty(resultLists)) { + return Collections.emptyList(); + } + return resultLists; + } + + /** + * 保存或更新 + * + * @param mqConsumerEntityList + */ + @Override + public void saveOrUpdate(List mqConsumerEntityList) { + if (CollectionUtils.isEmpty(mqConsumerEntityList)) { + return; + } + // 每次梳理链路时,如果没有关联上旧表的mq,都是尝试关联下 + mqConsumerEntityList.stream().forEach(entity -> { + + Map params = new HashMap<>(); + params.put("tenant_id", entity.getTenantId()); + params.put("env_code", entity.getEnvCode()); + params.put("resource_id", entity.getResourceId()); + params.put("`topic`", entity.getTopic()); + params.put("`group`", entity.getGroup()); + params.put("mq_type", entity.getMqType()); + // 根据唯一键查询 + List entities = pressureResourceRelateMqConsumerMapper.selectByMap(params); + if (entities.isEmpty()) { + entity.setRelateDsManageId(getRelateDsManageId(entity)); + pressureResourceRelateMqConsumerMapper.insert(entity); + return; + } + // 查到了数据 + PressureResourceRelateMqConsumerEntity exists = entities.get(0); + // 关联上application_ds_manage表 + if ("KAFKA-其他".equals(exists.getMqType())) { + if (exists.getRelateDsManageId() != null) { + return; + } + Long relateDsManageId = getRelateDsManageId(exists); + if (relateDsManageId != null) { + exists.setRelateDsManageId(relateDsManageId); + exists.setGmtModified(new Date()); + pressureResourceRelateMqConsumerMapper.updateById(exists); + } + return; + } + return; + }); + } + + private Long getRelateDsManageId(PressureResourceRelateMqConsumerEntity entity) { + ApplicationDsQueryParam param = new ApplicationDsQueryParam(); + param.setApplicationId(entity.getApplicationId()); + param.setUrl(entity.getTopic()); + List dsResults = applicationDsDAO.queryList(param); + if (!dsResults.isEmpty()) { + return dsResults.get(0).getId(); + } + return null; + } + + private QueryWrapper getWrapper(PressureResourceMqConsumerQueryParam param) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (param == null) { + return queryWrapper; + } + // 模糊查询 + if (StringUtils.isNotBlank(param.getTopic())) { + queryWrapper.eq("`topic`", param.getTopic()); + } + if (StringUtils.isNotBlank(param.getGroup())) { + queryWrapper.eq("`group`", param.getGroup()); + } + if (param.getResourceId() != null) { + queryWrapper.eq("resource_id", param.getResourceId()); + } + if (StringUtils.isNotBlank(param.getMqType())) { + queryWrapper.eq("mq_type", param.getMqType()); + } + if (param.getConsumerTag() != null) { + queryWrapper.eq("consumer_tag", param.getConsumerTag()); + } + if (StringUtils.isNotBlank(param.getQueryTopicGroup())) { + queryWrapper.and(tmp -> tmp.like("`topic`", param.getQueryTopicGroup()).or().like("`group`", param.getQueryTopicGroup())); + } + if (StringUtils.isNotBlank(param.getQueryApplicationName())) { + queryWrapper.like("application_name", param.getQueryApplicationName()); + } + return queryWrapper; + } + + private void populateProperties(PressureResourceRelateMqConsumerEntity consumer, ApplicationDsManageEntity entity) { + JSONObject object = JSON.parseObject(SecureUtil.decrypt(entity.getParseConfig())); + consumer.setTopic(object.getString("topic")); + consumer.setBrokerAddr(object.getString("brokerAddr")); + consumer.setGroup(object.getString("group")); + consumer.setSystemIdToken(object.getString("systemIdToken")); + consumer.setTopicTokens(object.getString("topicTokens")); + Map feature = new HashMap<>(); + feature.put("clusterName", object.getString("clusterName")); + feature.put("clusterAddr", object.getString("monitorUrl")); + feature.put("providerThreadCount", object.getInteger("poolSize")); + feature.put("consumerThreadCount", object.getInteger("messageConsumeThreadCount")); + consumer.setFeature(JSON.toJSONString(feature)); + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateRemoteCallDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateRemoteCallDAOImpl.java new file mode 100644 index 0000000000..b73884f747 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateRemoteCallDAOImpl.java @@ -0,0 +1,168 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Lists; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.dao.application.AppRemoteCallDAO; +import io.shulie.takin.web.data.dao.application.ApplicationDAO; +import io.shulie.takin.web.data.dao.pressureresource.MockInfo; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateRemoteCallDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateRemoteCallMapperV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateRemoteCallEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateRemoteCallEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceRemoteCallQueryParam; +import io.shulie.takin.web.data.result.application.AppRemoteCallResult; +import io.shulie.takin.web.data.result.application.ApplicationDetailResult; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/14 11:09 AM + */ +@Service +public class PressureResourceRelateRemoteCallDAOImpl implements PressureResourceRelateRemoteCallDAO { + + public static final String APPLICATION_CACHE_PREFIX = "application:cache"; + + @Resource + private PressureResourceRelateRemoteCallMapperV2 pressureResourceRelateRemoteCallMapperV2; + + @Resource + private AppRemoteCallDAO appRemoteCallDAO; + + @Autowired + @Qualifier("redisTemplate") + private RedisTemplate redisTemplate; + + @Resource + private ApplicationDAO applicationDAO; + + /** + * 存在则更新 + * + * @param remoteCallEntityList + */ + @Override + public void saveOrUpdate_v2(List remoteCallEntityList) { + if (CollectionUtils.isEmpty(remoteCallEntityList)) { + return; + } + remoteCallEntityList.stream().forEach(remote -> { + if (remote.isFind()) { + pressureResourceRelateRemoteCallMapperV2.saveOrUpdate(remote); + } + }); + } + + public Long queryApplicationIdByAppName(String appName) { + // 添加缓存:agent心跳接口太过于频繁 + String key = generateApplicationCacheKey(appName); + String applicationId = (String) redisTemplate.opsForHash().get(APPLICATION_CACHE_PREFIX, key); + if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(applicationId)) { + return Long.valueOf(applicationId); + } + ApplicationDetailResult detailResult = applicationDAO.getByName(appName); + Long result = null; + if (detailResult != null) { + result = detailResult.getApplicationId(); + redisTemplate.opsForHash().put(APPLICATION_CACHE_PREFIX, key, String.valueOf(result)); + } + return result; + } + + // 生成应用缓存key + public static String generateApplicationCacheKey(String applicationName) { + return String.format("%s:%s:%s", WebPluginUtils.traceTenantId(), WebPluginUtils.traceEnvCode(), applicationName); + } + + private Boolean isSynchronize(Integer isSynchronize) { + return isSynchronize != null && isSynchronize > 0; + } + + /** + * 分页 + * + * @param param + * @return + */ + @Override + public PagingList pageList_v2(PressureResourceRemoteCallQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper_v2(param); + Page page = new Page<>(param.getCurrent() + 1, param.getPageSize()); + queryWrapper.orderByAsc("rpc_id"); + IPage pageList = pressureResourceRelateRemoteCallMapperV2.selectPage(page, queryWrapper); + if (pageList.getRecords().isEmpty()) { + return PagingList.empty(); + } + List v2List = pageList.getRecords(); + List callEntityList = Lists.newArrayList(); + for (int i = 0; i < v2List.size(); i++) { + PressureResourceRelateRemoteCallEntityV2 v2 = v2List.get(i); + RelateRemoteCallEntity call = new RelateRemoteCallEntity(); + BeanUtils.copyProperties(v2, call); + + if (!param.isConvert()) { + AppRemoteCallResult callResult = appRemoteCallDAO.queryOne(v2.getAppName(), v2.getInterfaceType(), v2.getInterfaceName()); + // 设置下mock值 + MockInfo mockInfo = new MockInfo(); + Integer type = callResult.getType(); + call.setType(callResult.getType()); + if (type == 2) { + // groovy脚本mock + mockInfo.setType(String.valueOf(1)); + mockInfo.setMockValue(callResult.getMockReturnValue()); + call.setMockReturnValue(JSON.toJSONString(mockInfo)); + } + if (type == 4) { + mockInfo.setType(String.valueOf(0)); + mockInfo.setMockValue(callResult.getMockReturnValue()); + call.setMockReturnValue(JSON.toJSONString(mockInfo)); + } + call.setServerAppName(callResult.getServerAppName()); + } + callEntityList.add(call); + } + return PagingList.of(callEntityList, pageList.getTotal()); + } + + private QueryWrapper getWrapper_v2(PressureResourceRemoteCallQueryParam param) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (param == null) { + return queryWrapper; + } + // 模糊查询 + if (StringUtils.isNotBlank(param.getQueryInterfaceName())) { + queryWrapper.like("interface_name", param.getQueryInterfaceName()); + } + if (param.getResourceId() != null) { + queryWrapper.eq("resource_id", param.getResourceId()); + } + if (param.getInterfaceChildType() != null) { + queryWrapper.eq("interface_child_type", param.getInterfaceChildType()); + } + if (param.getPass() != null) { + queryWrapper.eq("pass", param.getPass()); + } + if (param.getStatus() != null) { + queryWrapper.eq("status", param.getStatus()); + } + if (StringUtils.isNotBlank(param.getEntry())) { + queryWrapper.eq("detail_id", param.getEntry()); + } + return queryWrapper; + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateTableDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateTableDAOImpl.java new file mode 100644 index 0000000000..24bb5fd74a --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/PressureResourceRelateTableDAOImpl.java @@ -0,0 +1,162 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Lists; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.data.dao.application.ApplicationDsDbTableDAO; +import io.shulie.takin.web.data.dao.pressureresource.PressureResourceRelateTableDAO; +import io.shulie.takin.web.data.mapper.mysql.PressureResourceRelateTableMapperV2; +import io.shulie.takin.web.data.model.mysql.ApplicationDsDbTableEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateTableEntityV2; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateTableEntity; +import io.shulie.takin.web.data.param.pressureresource.PressureResourceTableQueryParam; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/9/1 8:38 PM + */ +@Service +public class PressureResourceRelateTableDAOImpl + implements PressureResourceRelateTableDAO { + private static Logger logger = LoggerFactory.getLogger(PressureResourceRelateTableDAOImpl.class); + + @Resource + private PressureResourceRelateTableMapperV2 pressureResourceRelateTableMapperV2; + + @Autowired + private ApplicationDsDbTableDAO dsDbTableDAO; + + /** + * 新增 + * + * @param dsEntitys + */ + @Override + public void add_V2(List dsEntitys) { + if (CollectionUtils.isEmpty(dsEntitys)) { + return; + } + dsEntitys.stream().forEach(dsEntity -> { + pressureResourceRelateTableMapperV2.saveOrUpdate(dsEntity); + }); + } + + + /** + * 分页查询 + * + * @param param + * @return + */ + @Override + public PagingList pageList_v2(PressureResourceTableQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper_v2(param); + Page page = new Page<>(param.getCurrent() + 1, param.getPageSize()); + queryWrapper.orderByDesc("gmt_modified"); + IPage pageList = pressureResourceRelateTableMapperV2.selectPage(page, queryWrapper); + if (pageList.getRecords().isEmpty()) { + return PagingList.empty(); + } + return PagingList.of(fixTable(pageList.getRecords()), pageList.getTotal()); + } + + /** + * 查询 + * + * @param param + * @return + */ + @Override + public List queryList_v2(PressureResourceTableQueryParam param) { + QueryWrapper queryWrapper = this.getWrapper_v2(param); + List list = pressureResourceRelateTableMapperV2.selectList(queryWrapper); + if (CollectionUtils.isEmpty(list)) { + return Collections.EMPTY_LIST; + } + List rsList = fixTable(list); + return rsList; + } + + private List fixTable(List list) { + List rsList = Lists.newArrayList(); + // 转换关联表信息 + for (int i = 0; i < list.size(); i++) { + PressureResourceRelateTableEntityV2 v2 = list.get(i); + Long relateId = v2.getRelateId(); + ApplicationDsDbTableEntity dsDbTableEntity = dsDbTableDAO.getOne(relateId); + if (dsDbTableEntity == null) { + logger.warn("关联数据表为空{}", relateId); + continue; + } + RelateTableEntity tableEntity = new RelateTableEntity(); + tableEntity.setId(v2.getId()); + tableEntity.setResourceId(v2.getResourceId()); + tableEntity.setDsKey(v2.getDsKey()); + tableEntity.setStatus(v2.getStatus()); + tableEntity.setRemark(v2.getRemark()); + tableEntity.setBusinessTable(dsDbTableEntity.getBizTable()); + tableEntity.setShadowTable(dsDbTableEntity.getShadowTable()); + tableEntity.setType(dsDbTableEntity.getManualTag() == 1 ? 0 : 1); + // 是否选中 0=未选中,1=选中 + tableEntity.setJoinFlag(dsDbTableEntity.getIsCheck() == 1 ? 0 : 1); + rsList.add(tableEntity); + } + return rsList; + } + + @Override + public void saveOrUpdate(List tableEntitys) { + if (CollectionUtils.isEmpty(tableEntitys)) { + return; + } + tableEntitys.stream().forEach(table -> { + //pressureResourceRelateTableMapper.saveOrUpdate(table); + }); + } + + @Override + public void deleteByParam(PressureResourceTableQueryParam queryParam) { + QueryWrapper deleteWrapper = getWrapper_v2(queryParam); + pressureResourceRelateTableMapperV2.delete(deleteWrapper); + } + + private QueryWrapper getWrapper_v2(PressureResourceTableQueryParam param) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (param == null) { + return queryWrapper; + } + // 模糊查询 + if (StringUtils.isNotBlank(param.getQueryBusinessTableName())) { + queryWrapper.like("business_table", param.getQueryBusinessTableName()); + } + if (StringUtils.isNotBlank(param.getBusinessTableName())) { + queryWrapper.eq("business_table", param.getBusinessTableName()); + } + if (param.getStatus() != null) { + queryWrapper.eq("status", param.getStatus()); + } + if (StringUtils.isNotBlank(param.getDsKey())) { + queryWrapper.eq("ds_key", param.getDsKey()); + } + if (param.getResourceId() != null) { + queryWrapper.eq("resource_id", param.getResourceId()); + } + if (CollectionUtils.isNotEmpty(param.getRelateIds())) { + queryWrapper.in("relate_id", param.getRelateIds()); + } + return queryWrapper; + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/RelateConvert.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/RelateConvert.java new file mode 100644 index 0000000000..7330b30533 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/pressureresource/impl/RelateConvert.java @@ -0,0 +1,45 @@ +package io.shulie.takin.web.data.dao.pressureresource.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.pamirs.attach.plugin.dynamic.one.Type; +import com.pamirs.takin.common.enums.ds.DsTypeEnum; +import io.shulie.takin.web.data.model.mysql.pressureresource.RelateDsEntity; +import io.shulie.takin.web.data.result.application.ApplicationDsDbManageDetailResult; +import org.apache.commons.lang3.StringUtils; + +/** + * @author xingchen + * @description: TODO + * @date 2022/10/26 3:48 PM + */ +public class RelateConvert { + /** + * 应用详情关联数据源转换为压测资源准备数据源信息 + * + * @param convert + * @return + */ + public static RelateDsEntity dsManageConvertRelateDs(ApplicationDsDbManageDetailResult convert) { + final RelateDsEntity dsEntity = new RelateDsEntity(); + String shaDowFileExtedn = convert.getShaDowFileExtedn(); + if (StringUtils.isNotBlank(shaDowFileExtedn) && + (DsTypeEnum.SHADOW_REDIS_SERVER.getCode().equals(convert.getDsType()) + || DsTypeEnum.SHADOW_DB.getCode().equals(convert.getDsType()))) { + // 获取影子数据源和地址 + JSONObject dataObj = JSON.parseObject(shaDowFileExtedn); + String shadowUrl = dataObj.getString("shadowUrl"); + String shadowPwd = dataObj.getString("shadowPwd"); + String shadowUserName = dataObj.getString("shadowUserName"); + dsEntity.setShadowDatabase(shadowUrl); + dsEntity.setShadowUserName(shadowUserName); + dsEntity.setShadowPassword(shadowPwd); + } + dsEntity.setAppName(convert.getApplicationName()); + dsEntity.setBusinessUserName(convert.getUserName()); + dsEntity.setBusinessDatabase(convert.getUrl()); + dsEntity.setMiddlewareName(convert.getConnPoolName()); + dsEntity.setMiddlewareType(Type.MiddleWareType.LINK_POOL.value()); + return dsEntity; + } +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/scriptmanage/impl/ScriptManageDAOImpl.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/scriptmanage/impl/ScriptManageDAOImpl.java index 7c737a9143..ac39c77d45 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/scriptmanage/impl/ScriptManageDAOImpl.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/dao/scriptmanage/impl/ScriptManageDAOImpl.java @@ -35,6 +35,7 @@ import io.shulie.takin.web.data.result.scriptmanage.ScriptExecuteResult; import io.shulie.takin.web.data.result.scriptmanage.ScriptManageDeployResult; import io.shulie.takin.web.data.result.scriptmanage.ScriptManageResult; +import io.shulie.takin.web.ext.util.WebPluginUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; @@ -114,6 +115,7 @@ public ScriptManageDeployResult createScriptManageDeploy(ScriptManageDeployCreat scriptManageEntity.setScriptVersion(scriptManageDeployCreateParam.getScriptVersion()); scriptManageEntity.setFeature(scriptManageDeployCreateParam.getFeature()); scriptManageEntity.setMVersion(scriptManageDeployCreateParam.getMVersion()); + scriptManageEntity.setDeptId(WebPluginUtils.traceDeptId()); scriptManageMapper.insert(scriptManageEntity); scriptManageDeployCreateParam.setScriptId(scriptManageEntity.getId()); } @@ -247,6 +249,12 @@ public PagingList pageQueryRecentScriptManageDeploy( if (CollectionUtils.isNotEmpty(param.getUserIdList())) { wrapper.in(ScriptManageEntity::getUserId, param.getUserIdList()); } + if (CollectionUtils.isNotEmpty(param.getDeptIdList())) { + wrapper.in(ScriptManageEntity::getDeptId, param.getDeptIdList()); + } + if (param.getDeptId() != null){ + wrapper.eq(ScriptManageEntity::getDeptId, param.getDeptId()); + } Page scriptManageEntityPage = scriptManageMapper.selectPage(page, wrapper); if (scriptManageEntityPage == null) { return PagingList.empty(); diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/AppDataSourceMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/AppDataSourceMapper.java new file mode 100644 index 0000000000..b7bd786228 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/AppDataSourceMapper.java @@ -0,0 +1,27 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceAppDataSourceEntity; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface AppDataSourceMapper + extends BaseMapper { + @Insert("") + void saveOrUpdate(@Param("list") List list); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationApiManageMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationApiManageMapper.java index de77179679..2ed3f7f916 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationApiManageMapper.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationApiManageMapper.java @@ -28,7 +28,8 @@ public interface ApplicationApiManageMapper extends BaseMapper querySimpleWithTenant(ApplicationApiParam apiParam); - List selectBySelective(@Param("record") ApplicationApiQueryParam record, @Param("userIds") List userIds); + List selectBySelective(@Param("record") ApplicationApiQueryParam record, + @Param("userIds") List userIds, @Param("deptIds") List deptIds); int insertBatch(@Param("list") List list); diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationDsDbTableMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationDsDbTableMapper.java index f3275f7c50..49d16afcec 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationDsDbTableMapper.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationDsDbTableMapper.java @@ -1,7 +1,7 @@ package io.shulie.takin.web.data.mapper.mysql; -import io.shulie.takin.web.data.model.mysql.ApplicationDsDbTableEntity; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.ApplicationDsDbTableEntity; /** * 业务数据库表(ApplicationDsDbTable)表数据库 mapper @@ -10,6 +10,5 @@ * @date 2021-09-15 17:21:41 */ public interface ApplicationDsDbTableMapper extends BaseMapper { - } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationMntMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationMntMapper.java index 5ceecda850..14d6850dc3 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationMntMapper.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ApplicationMntMapper.java @@ -58,7 +58,7 @@ void updateAppNodeNum(@Param("param") NodeNumParam param, @Param("envCode") Stri List getAllApplicationByStatus(@Param("statusList") List statusList); List getApplicationMntByUserIdsAndKeyword(@Param("userIds") List userIds, - @Param("keyword") String keyword); + @Param("deptIds") List deptIds,@Param("keyword") String keyword); List getAllApplications(); diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ClusterNacosConfigurationMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ClusterNacosConfigurationMapper.java new file mode 100644 index 0000000000..e304fc974a --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/ClusterNacosConfigurationMapper.java @@ -0,0 +1,21 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import io.shulie.takin.web.data.model.mysql.ClusterNacosConfiguration; + +import java.util.List; + +/** + * Ecs中心的nacos服务信息(EcsCenterNacosEntity)表数据库 mapper + */ +public interface ClusterNacosConfigurationMapper { + + /** + * 查询所有 + * + * @return + */ + @InterceptorIgnore(tenantLine = "true") + List selectAll(); + +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceDetailMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceDetailMapper.java new file mode 100644 index 0000000000..345636c59f --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceDetailMapper.java @@ -0,0 +1,27 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceDetailEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface PressureResourceDetailMapper + extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + @Insert("") + void saveOrUpdate(@Param("list") List list); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceMapper.java new file mode 100644 index 0000000000..791d78f612 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceMapper.java @@ -0,0 +1,22 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceAppDataSourceEntity; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceEntity; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface PressureResourceMapper + extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + @Select("select * from t_pressure_resource where is_delete=0") + List getAll(); + + @InterceptorIgnore(tenantLine = "true") + @Select("select * from t_pressure_resource where id = #{id} and is_delete=0") + PressureResourceEntity queryByIdNoTenant(@Param("id") Long id); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateAppMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateAppMapper.java new file mode 100644 index 0000000000..1c862b8dfe --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateAppMapper.java @@ -0,0 +1,28 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateAppEntity; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +public interface PressureResourceRelateAppMapper + extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + @Insert("") + void saveOrUpdate(@Param("item") PressureResourceRelateAppEntity item); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateDsMapperV2.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateDsMapperV2.java new file mode 100644 index 0000000000..b6a2f83c02 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateDsMapperV2.java @@ -0,0 +1,20 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateDsEntityV2; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +public interface PressureResourceRelateDsMapperV2 + extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + @Insert("") + void saveOrUpdate(@Param("item") PressureResourceRelateDsEntityV2 item); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateMqConsumerMapper.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateMqConsumerMapper.java new file mode 100644 index 0000000000..de62b85e8d --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateMqConsumerMapper.java @@ -0,0 +1,23 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateMqConsumerEntity; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +public interface PressureResourceRelateMqConsumerMapper + extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + @Insert("") + void saveOrUpdate(@Param("item") PressureResourceRelateMqConsumerEntity item); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateRemoteCallMapperV2.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateRemoteCallMapperV2.java new file mode 100644 index 0000000000..9db6312015 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateRemoteCallMapperV2.java @@ -0,0 +1,28 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateRemoteCallEntityV2; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +public interface PressureResourceRelateRemoteCallMapperV2 + extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + @Insert("") + void saveOrUpdate(@Param("item") PressureResourceRelateRemoteCallEntityV2 item); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateTableMapperV2.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateTableMapperV2.java new file mode 100644 index 0000000000..2a656bfe86 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/mapper/mysql/PressureResourceRelateTableMapperV2.java @@ -0,0 +1,20 @@ +package io.shulie.takin.web.data.mapper.mysql; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.shulie.takin.web.data.model.mysql.pressureresource.PressureResourceRelateTableEntityV2; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +public interface PressureResourceRelateTableMapperV2 + extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + @Insert("") + void saveOrUpdate(@Param("item") PressureResourceRelateTableEntityV2 item); +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationApiManageEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationApiManageEntity.java index 1072d99a0e..4c090cff86 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationApiManageEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationApiManageEntity.java @@ -69,4 +69,7 @@ public class ApplicationApiManageEntity extends UserBaseEntity { @TableField(value = "is_agent_registe") private Integer isAgentRegiste; + + @TableField(value = "dept_id") + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationDsDbManageEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationDsDbManageEntity.java index 5036f717d3..ca54e93586 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationDsDbManageEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationDsDbManageEntity.java @@ -120,5 +120,4 @@ public class ApplicationDsDbManageEntity extends NewBaseEntity implements Serial private String sign; private Long customerId; - } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationEcsCenterEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationEcsCenterEntity.java new file mode 100644 index 0000000000..b5341437cb --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationEcsCenterEntity.java @@ -0,0 +1,32 @@ +package io.shulie.takin.web.data.model.mysql; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.annocation.EnableSign; +import io.shulie.takin.web.data.model.mysql.base.NewBaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.io.Serializable; + +@Data +@EqualsAndHashCode(callSuper = true) +@TableName(value = "t_application_esc_center_relation") +@ToString(callSuper = true) +@EnableSign +public class ApplicationEcsCenterEntity extends NewBaseEntity implements Serializable { + private static final long serialVersionUID = 339110573700927775L; + + /** + * 应用id + */ + private Long applicationId; + + /** + * ecs中心名称 + */ + private String ecsCenterName; + + private String applicationName; + +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationMntEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationMntEntity.java index d9ee325048..6bfb01b6d2 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationMntEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ApplicationMntEntity.java @@ -142,4 +142,16 @@ public class ApplicationMntEntity extends UserBaseEntity { @TableField(value = "PRADAR_VERSION") private String pradarVersion; + /** + * 部门id + */ + @TableField(value = "dept_id") + private Long deptId; + + /** + * 集群名称 + */ + @TableField("cluster_name") + private String clusterName; + } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BlackListEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BlackListEntity.java index 4b18c9e31d..fa298f4d28 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BlackListEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BlackListEntity.java @@ -77,4 +77,7 @@ public class BlackListEntity extends UserBaseEntity { private String principalNo; private String value; + + @TableField(value = "dept_id") + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BusinessLinkManageTableEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BusinessLinkManageTableEntity.java index 8ee612b422..151f857056 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BusinessLinkManageTableEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/BusinessLinkManageTableEntity.java @@ -128,4 +128,10 @@ public class BusinessLinkManageTableEntity extends UserBaseEntity { @TableField(value = "persistence") private boolean persistence = true; + + /** + * 部门id + */ + @TableField(value = "dept_id") + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ClusterNacosConfiguration.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ClusterNacosConfiguration.java new file mode 100644 index 0000000000..39f6334206 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ClusterNacosConfiguration.java @@ -0,0 +1,52 @@ +package io.shulie.takin.web.data.model.mysql; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.annocation.EnableSign; +import lombok.Data; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; + +@Data +@TableName(value = "t_cluster_nacos_configuration") +@ToString(callSuper = true) +@EnableSign +public class ClusterNacosConfiguration implements Serializable { + + private static final long serialVersionUID = 339110573810927775L; + + /** + * 主键 + */ + @TableId(type = IdType.AUTO,value = "id") + private Long id; + + /** + * ecs中心名称 + */ + private String clusterName; + + /** + * nacos服务地址 + */ + private String nacosServerAddr; + + /** + * nacos命名空间 + */ + private String nacosNamespace; + + /** + * 创建时间 + */ + private Date gmtCreate; + + /** + * 更新时间 + */ + private Date gmtUpdate; + +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/InterfacePerformanceConfigEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/InterfacePerformanceConfigEntity.java index c4b644da57..73dc4681ed 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/InterfacePerformanceConfigEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/InterfacePerformanceConfigEntity.java @@ -121,6 +121,9 @@ public class InterfacePerformanceConfigEntity extends TenantBaseEntity { @TableField(value = "user_id") private Long userId; + @TableField(value = "dept_id") + private Long deptId; + /** * 修改人 */ diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/SceneEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/SceneEntity.java index 89a75441b1..3b3eecfda1 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/SceneEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/SceneEntity.java @@ -103,4 +103,10 @@ public class SceneEntity extends UserBaseEntity { @TableField(value = "features") private String features; + + /** + * 部门id + */ + @TableField(value = "dept_id") + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ScriptManageEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ScriptManageEntity.java index 8e98aaf558..f6331e6d5b 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ScriptManageEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/ScriptManageEntity.java @@ -60,4 +60,9 @@ public class ScriptManageEntity extends UserBaseEntity { @TableField(value = "sign",fill = FieldFill.INSERT) private String sign; + /** + * 部门id + */ + @TableField(value = "dept_id") + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/TakinDbresourceEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/TakinDbresourceEntity.java index 08d37fb2c0..15d8d916d0 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/TakinDbresourceEntity.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/TakinDbresourceEntity.java @@ -71,6 +71,9 @@ public class TakinDbresourceEntity extends UserBaseEntity { @TableField(value = "is_deleted") private Boolean isDeleted; + @TableField(value = "dept_id") + private Long deptId; + public static final String COL_ID = "id"; public static final String COL_TYPE = "type"; diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceAppDataSourceEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceAppDataSourceEntity.java new file mode 100644 index 0000000000..87b7e12052 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceAppDataSourceEntity.java @@ -0,0 +1,85 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@TableName(value = "t_pressure_resource_app_database") +@ToString(callSuper = true) +public class PressureResourceAppDataSourceEntity extends TenantBaseEntity { + @TableId(value = "ID", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("应用名称") + @TableField(value = "`app_name`") + private String appName; + + @ApiModelProperty("业务数据源") + @TableField(value = "`data_source`") + private String dataSource; + + @ApiModelProperty("影子数据源") + @TableField(value = "`shadow_data_source`") + private String shadowDataSource; + + @ApiModelProperty("数据库类型名称") + @TableField(value = "`db_name`") + private String dbName; + + @ApiModelProperty("用户名") + @TableField(value = "`table_user`") + private String tableUser; + + @ApiModelProperty("用户密码") + @TableField(value = "`password`") + private String password; + + @ApiModelProperty("中间件类型") + @TableField(value = "`middleware_type`") + private String middlewareType; + + @ApiModelProperty("连接池名称") + @TableField(value = "`connection_pool`") + private String connectionPool; + + @ApiModelProperty("附加信息") + @TableField(value = "`ext_info`") + private String extInfo; + + @ApiModelProperty("类型") + @TableField(value = "`type`") + private String type; + + @ApiModelProperty("动态配置") + @TableField(value = "`attachment`") + private String attachment; + + @ApiModelProperty("唯一健(md5(app_name,data_source,table_user))") + @TableField(value = "`uniqueKey`") + private String uniqueKey; + + @TableField(value = "user_app_key") + private String userAppKey; + + @TableField(value = "`gmt_create`") + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @TableField(value = "`gmt_modified`") + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceDetailEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceDetailEntity.java new file mode 100644 index 0000000000..655d790218 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceDetailEntity.java @@ -0,0 +1,70 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@TableName(value = "t_pressure_resource_detail") +@ToString(callSuper = true) +public class PressureResourceDetailEntity extends TenantBaseEntity { + @TableId(value = "ID", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + @TableField(value = "`resource_id`") + private Long resourceId; + + @ApiModelProperty("应用名称") + @TableField(value = "`app_name`") + private String appName; + + @ApiModelProperty("入口URL") + @TableField(value = "`entrance_url`") + private String entranceUrl; + + @ApiModelProperty("入口名称") + @TableField(value = "`entrance_name`") + private String entranceName; + + @ApiModelProperty("请求方式") + @TableField(value = "`method`") + private String method; + + @ApiModelProperty("rpcType") + @TableField(value = "`rpc_type`") + private String rpcType; + + @ApiModelProperty("extend") + @TableField(value = "`extend`") + private String extend; + + @ApiModelProperty("linkId") + @TableField(value = "`link_id`") + private String linkId; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + @TableField(value = "`type`") + private Integer type; + + @TableField(value = "`gmt_create`") + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @TableField(value = "`gmt_modified`") + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceEntity.java new file mode 100644 index 0000000000..0905a3c359 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceEntity.java @@ -0,0 +1,66 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@TableName(value = "t_pressure_resource") +@ToString(callSuper = true) +public class PressureResourceEntity extends TenantBaseEntity { + @TableId(value = "ID", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置名称") + @TableField(value = "`name`") + private String name; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + @TableField(value = "`type`") + private Integer type; + + @ApiModelProperty("隔离方式(0-未设置 1-影子库 2-影子库/影子表 3-影子表)") + @TableField(value = "`isolate_type`") + private Integer isolateType; + + @ApiModelProperty("状态(0-未开始 1-已开始)") + @TableField(value = "`status`") + private Integer status; + + @ApiModelProperty("检测状态(0-未检测 1-检测中 2-检测完成)") + @TableField(value = "`check_status`") + private Integer checkStatus; + + @ApiModelProperty("来源的Id") + @TableField(value = "`source_id`") + private Long sourceId; + + @ApiModelProperty("归属人Id") + @TableField(value = "user_id") + private Long userId; + + @TableField(value = "`check_time`") + @ApiModelProperty("检测时间") + private Date checkTime; + + @TableField(value = "`gmt_create`") + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @TableField(value = "`gmt_modified`") + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateAppEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateAppEntity.java new file mode 100644 index 0000000000..9921d8376b --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateAppEntity.java @@ -0,0 +1,62 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@TableName(value = "t_pressure_resource_relate_app") +@ToString(callSuper = true) +public class PressureResourceRelateAppEntity extends TenantBaseEntity { + @TableId(value = "ID", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + @TableField(value = "`resource_id`") + private Long resourceId; + + @ApiModelProperty("配置详情Id") + @TableField(value = "`detail_id`") + private Long detailId; + + @ApiModelProperty("应用名称") + @TableField(value = "`app_name`") + private String appName; + + @ApiModelProperty("状态(0-正常-1-不正常)") + @TableField(value = "`status`") + private Integer status; + + @ApiModelProperty("节点数") + @TableField(value = "`node_num`") + private Integer nodeNum; + + @ApiModelProperty("是否加入压测范围(0-否 1-是)") + @TableField(value = "`join_pressure`") + private Integer joinPressure; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + @TableField(value = "`type`") + private Integer type; + + @TableField(value = "`gmt_create`") + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @TableField(value = "`gmt_modified`") + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateDsEntityV2.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateDsEntityV2.java new file mode 100644 index 0000000000..7291796cd2 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateDsEntityV2.java @@ -0,0 +1,70 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@TableName(value = "t_pressure_resource_relate_ds") +@ToString(callSuper = true) +public class PressureResourceRelateDsEntityV2 extends TenantBaseEntity { + @TableId(value = "ID", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + @TableField(value = "`resource_id`") + private Long resourceId; + + @ApiModelProperty("应用名称") + @TableField(value = "`app_name`") + private String appName; + + @ApiModelProperty("链路详情Id") + @TableField(value = "`detail_id`") + private Long detailId; + + @ApiModelProperty("业务数据源") + @TableField(value = "`business_database`") + private String businessDatabase; + + @ApiModelProperty("业务数据源用户名") + @TableField(value = "`business_user_name`") + private String businessUserName; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + @TableField(value = "`status`") + private Integer status; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + @TableField(value = "`type`") + private Integer type; + + @ApiModelProperty("remark") + @TableField(value = "`remark`") + private String remark; + + @ApiModelProperty("关联数据源Id") + @TableField(value = "`relate_id`") + private Long relateId; + + @TableField(value = "`gmt_create`") + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @TableField(value = "`gmt_modified`") + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateMqConsumerEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateMqConsumerEntity.java new file mode 100644 index 0000000000..7678452713 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateMqConsumerEntity.java @@ -0,0 +1,136 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.annocation.EnableSign; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + + +/** + * 影子消费者 + */ +@Data +@TableName(value = "t_pressure_resource_relate_shadow_mq_consumer") +public class PressureResourceRelateMqConsumerEntity extends TenantBaseEntity { + /** + * 主键id + */ + @TableId(value = "ID", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + @TableField(value = "`resource_id`") + private Long resourceId; + + @ApiModelProperty("详情Id") + @TableField(value = "`detail_id`") + private Long detailId; + + /** + * topic + */ + @TableField(value = "`topic`") + private String topic; + + /** + * topic + */ + @TableField(value = "`group`") + private String group; + + /** + * broker地址 + */ + @TableField(value = "`broker_addr`") + private String brokerAddr; + + /** + * topicTokens + */ + @TableField(value = "`topic_tokens`") + private String topicTokens; + + /** + * systemIdToken + */ + @TableField(value = "`systemId_Token`") + private String systemIdToken; + + /** + * MQ类型 + */ + @TableField(value = "`mq_type`") + private String mqType; + + /** + * 应用id + */ + @TableField(value = "`application_id`") + private Long applicationId; + /** + * 应用id + */ + @TableField(value = "`application_name`") + private String applicationName; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + @TableField(value = "`status`") + private Integer status; + + @ApiModelProperty("是否消费(0-消费 1-不消费 )") + @TableField(value = "`consumer_tag`") + private Integer consumerTag; + + /** + * 是否删除,0正常,1删除 + */ + @TableField(value = "`deleted`") + private Integer deleted; + + /** + * 拓展字段 + */ + @TableField(value = "`feature`") + private String feature; + + @ApiModelProperty("remark") + @TableField(value = "`remark`") + private String remark; + + @ApiModelProperty("来源类型(0-手工,1-自动)") + @TableField(value = "`type`") + private Integer type; + + @ApiModelProperty("是否影子集群(0-是 1否)") + @TableField(value = "`is_cluster`") + private Integer isCluster; + + @ApiModelProperty("生产或消费(0-生产,1-消费)") + @TableField(value = "`comsumer_type`") + private Integer comsumerType; + + /** + * 创建时间 + */ + @TableField(value = "gmt_create") + private Date gmtCreate; + + /** + * 更新时间 + */ + @TableField(value = "gmt_modified") + private Date gmtModified; + + /** + * 关联application_ds_manage表的字段 + */ + @TableField(value = "relate_ds_manage_id") + private Long relateDsManageId; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateRemoteCallEntityV2.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateRemoteCallEntityV2.java new file mode 100644 index 0000000000..0161ac42dd --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateRemoteCallEntityV2.java @@ -0,0 +1,92 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@TableName(value = "t_pressure_resource_relate_remote_call") +@ToString(callSuper = true) +public class PressureResourceRelateRemoteCallEntityV2 extends TenantBaseEntity { + @TableId(value = "id", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + @TableField(value = "`resource_id`") + private Long resourceId; + + @ApiModelProperty("detail_id") + @TableField(value = "`detail_id`") + private Long detailId; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + @TableField(value = "`status`") + private Integer status; + + @ApiModelProperty("接口名") + @TableField(value = "`interface_name`") + private String interfaceName; + + @ApiModelProperty("接口类型") + @TableField(value = "`interface_type`") + private Integer interfaceType; + + @ApiModelProperty("应用名") + @TableField(value = "`app_name`") + private String appName; + + @ApiModelProperty("备注") + @TableField(value = "`remark`") + private String remark; + + @ApiModelProperty("是否放行(0:是 1:否)") + @TableField(value = "`pass`") + private Integer pass; + + @ApiModelProperty("rpcId") + @TableField(value = "`rpc_id`") + private String rpcId; + + @ApiModelProperty("接口子类型") + @TableField(value = "`interface_child_type`") + private String interfaceChildType; + + @ApiModelProperty("是否手动录入 0:否;1:是") + @TableField(value = "`manual_tag`") + private Integer manualTag; + + @TableField(value = "`gmt_create`") + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @TableField(value = "`gmt_modified`") + @ApiModelProperty("更新时间") + private Date gmtModified; + + @ApiModelProperty("应用名,接口名称,接口类型,租户id,环境code求md5") + @TableField(value = "`md5`") + private String md5; + + /** + * 是否找到客户端调用 + */ + @TableField(exist = false) + private boolean isFind; + + @ApiModelProperty("mock返回值") + @TableField(exist = false) + private String mockReturnValue; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateTableEntityV2.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateTableEntityV2.java new file mode 100644 index 0000000000..0d9ad48ccb --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/PressureResourceRelateTableEntityV2.java @@ -0,0 +1,58 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.shulie.takin.web.data.model.mysql.base.TenantBaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 10:24 AM + */ +@Data +@TableName(value = "t_pressure_resource_relate_table") +@ToString(callSuper = true) +public class PressureResourceRelateTableEntityV2 extends TenantBaseEntity { + @TableId(value = "ID", type = IdType.AUTO) + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("资源配置Id") + @TableField(value = "`resource_id`") + private Long resourceId; + + @ApiModelProperty("数据源唯一键") + @TableField(value = "`ds_key`") + private String dsKey; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + @TableField(value = "`status`") + private Integer status; + + @ApiModelProperty("类型(0-手工 1-自动)") + @TableField(value = "`type`") + private Integer type; + + @ApiModelProperty("关联表Id") + @TableField(value = "`relate_id`") + private Long relateId; + + @ApiModelProperty("备注") + @TableField(value = "`remark`") + private String remark; + + @TableField(value = "`gmt_create`") + @ApiModelProperty("创建时间") + private Date gmtCreate; + + @TableField(value = "`gmt_modified`") + @ApiModelProperty("更新时间") + private Date gmtModified; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateDsEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateDsEntity.java new file mode 100644 index 0000000000..08a9a33002 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateDsEntity.java @@ -0,0 +1,27 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/10/31 6:41 PM + */ +@Data +public class RelateDsEntity extends PressureResourceRelateDsEntityV2 { + @ApiModelProperty("中间件名称 druid, hikari,c3p0等") + private String middlewareName; + + @ApiModelProperty("中间件类型 缓存/连接池") + private String middlewareType; + + @ApiModelProperty("影子数据源") + private String shadowDatabase; + + @ApiModelProperty("影子数据源用户名") + private String shadowUserName; + + @ApiModelProperty("影子数据源密码") + private String shadowPassword; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateRemoteCallEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateRemoteCallEntity.java new file mode 100644 index 0000000000..4af789775b --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateRemoteCallEntity.java @@ -0,0 +1,20 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 扩展类,主要是旧表的字段信息,需要放到新表展示 + * + * @author xingchen + * @description: TODO + * @date 2022/10/31 6:52 PM + */ +@Data +public class RelateRemoteCallEntity extends PressureResourceRelateRemoteCallEntityV2 { + @ApiModelProperty("配置类型0:未配置,1:白名单配置,2:返回值mock,3:转发mock") + private Integer type; + + @ApiModelProperty("服务端应用名") + private String serverAppName; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateTableEntity.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateTableEntity.java new file mode 100644 index 0000000000..c84d33b3f7 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/model/mysql/pressureresource/RelateTableEntity.java @@ -0,0 +1,21 @@ +package io.shulie.takin.web.data.model.mysql.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/10/31 6:42 PM + */ +@Data +public class RelateTableEntity extends PressureResourceRelateTableEntityV2 { + @ApiModelProperty("业务表") + private String businessTable; + + @ApiModelProperty("影子表") + private String shadowTable; + + @ApiModelProperty("是否加入(0-加入 1-未加入)") + private Integer joinFlag; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/activity/ActivityQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/activity/ActivityQueryParam.java index 14b0969e2e..c53fbe2256 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/activity/ActivityQueryParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/activity/ActivityQueryParam.java @@ -46,4 +46,9 @@ public class ActivityQueryParam extends AuthQueryParamCommonExt { * 类型 */ private Integer type; + + /** + * 部门id + */ + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/AppDatabaseInputParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/AppDatabaseInputParam.java new file mode 100644 index 0000000000..e153840038 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/AppDatabaseInputParam.java @@ -0,0 +1,56 @@ +package io.shulie.takin.web.data.param.application; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/8/30 9:41 AM + */ +@ApiModel(value = "AppDatabaseInputParam", description = "agent上报应用数据源信息") +@Data +public class AppDatabaseInputParam { + @ApiModelProperty(name = "appName", value = "应用名称", required = true) + private String appName; + + @ApiModelProperty(name = "dataSource", value = "业务数据源", required = false) + private String dataSource; + + @ApiModelProperty(name = "shadow_data_source", value = "影子数据源", required = false) + private String shadowDataSource; + + @ApiModelProperty(name = "dbName", value = "数据库类型", required = true) + private String dbName; + + @ApiModelProperty(name = "tableUser", value = "用户名称", required = true) + private String tableUser; + + @ApiModelProperty(name = "password", value = "密码", required = true) + private String password; + + @ApiModelProperty(name = "middlewareType", value = "中间件类型", required = true) + private String middlewareType; + + @ApiModelProperty(name = "connectionPool", value = "连接池类型(durid等)", required = true) + private String connectionPool; + + @ApiModelProperty(name = "type", value = "type,来源", required = false) + private String type; + + @ApiModelProperty(name = "extInfo", value = "附加信息", required = false) + private String extInfo; + + @ApiModelProperty(name = "attachment", value = "附件", required = false) + private String attachment; + + @ApiModelProperty(name = "userAppKey", value = "userAppKey", required = true) + private String userAppKey; + + @ApiModelProperty(name = "envCode", value = "envCode", required = true) + private String envCode; + + @ApiModelProperty(name = "tenantId", value = "tenantId", required = false) + private String tenantId; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiCreateParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiCreateParam.java index 29184ecd53..d8508ab32e 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiCreateParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiCreateParam.java @@ -44,6 +44,8 @@ public class ApplicationApiCreateParam extends TenantCommonExt { */ private Long userId; + private Long deptId; + /** * 是否有效 0:有效;1:无效 */ diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiQueryParam.java index 9a5241909c..471e1f20ce 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiQueryParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationApiQueryParam.java @@ -52,4 +52,6 @@ public class ApplicationApiQueryParam extends TenantCommonExt { private String method; private Integer isAgentRegiste; + + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationCreateParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationCreateParam.java index c511a9dc54..47383078f1 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationCreateParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/ApplicationCreateParam.java @@ -71,6 +71,8 @@ public class ApplicationCreateParam extends UserCommonExt { private String alarmPerson; private String pradarVersion; + private String clusterName; + /** * 2018年5月17日 * diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationByUpgradeParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationByUpgradeParam.java index 785e3fd4b4..6c6f791bfb 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationByUpgradeParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationByUpgradeParam.java @@ -24,6 +24,7 @@ public class QueryApplicationByUpgradeParam extends PageBaseDTO { private List appIds; private List userIds; + private List deptIds; private Long tenantId; private String envCode; diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationParam.java index 30899c9175..0ca7702b80 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/application/QueryApplicationParam.java @@ -26,6 +26,10 @@ public class QueryApplicationParam extends PageBaseDTO { private List userIds; + private List deptIds; + + private Long deptId; + private Long tenantId; private String envCode; diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceCreateParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceCreateParam.java index 9cccaccfab..9f979b9064 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceCreateParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceCreateParam.java @@ -32,4 +32,9 @@ public class DataSourceCreateParam { * 数据源密码 */ private String password; + + /** + * 部门id + */ + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceQueryParam.java index d107538a6c..8dec6f2ba4 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceQueryParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/datasource/DataSourceQueryParam.java @@ -30,4 +30,9 @@ public class DataSourceQueryParam extends PagingDevice { * 数据源id集合 */ private List dataSourceIdList; + + /** + * 部门id + */ + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/interfaceperformance/PerformanceConfigQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/interfaceperformance/PerformanceConfigQueryParam.java index 32f30f7995..919c94d45a 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/interfaceperformance/PerformanceConfigQueryParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/interfaceperformance/PerformanceConfigQueryParam.java @@ -15,4 +15,6 @@ public class PerformanceConfigQueryParam extends PageBaseDTO { private String queryName; private List userIdList; + + private List deptIdList; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/linkmanage/SceneCreateParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/linkmanage/SceneCreateParam.java index 0d8f495cbc..693872be0e 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/linkmanage/SceneCreateParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/linkmanage/SceneCreateParam.java @@ -76,4 +76,9 @@ public class SceneCreateParam extends ContextExt { */ private Integer totalNodeNum; + /** + * 部门id + */ + private Long deptId; + private String features; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceAppQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceAppQueryParam.java new file mode 100644 index 0000000000..b7af3622ff --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceAppQueryParam.java @@ -0,0 +1,42 @@ +package io.shulie.takin.web.data.param.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/5/19 2:56 下午 + */ +@Data +public class PressureResourceAppQueryParam extends PageBaseDTO { + @ApiModelProperty("配置资源ID") + private Long resourceId; + + @ApiModelProperty("配置资源ID") + private List resourceIds; + + @ApiModelProperty("应用名称") + private String appName; + + @ApiModelProperty("入口") + private String entranceUrl; + + @ApiModelProperty("状态(0-正常 1-不正常)") + private Integer status; + + @ApiModelProperty("是否加入压测范围(0-否 1-是)") + private Integer joinPressure; + + @ApiModelProperty("配置详情Id") + private Long detailId; + + private List appNames; + + private List detailIds; +} + + diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceDetailQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceDetailQueryParam.java new file mode 100644 index 0000000000..9ec30c252f --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceDetailQueryParam.java @@ -0,0 +1,19 @@ +package io.shulie.takin.web.data.param.pressureresource; + +import lombok.Data; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/5/19 2:56 下午 + */ +@Data +public class PressureResourceDetailQueryParam { + private Long resourceId; + + private List resourceIds; + + private String linkId; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceDsQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceDsQueryParam.java new file mode 100644 index 0000000000..37549ab1bf --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceDsQueryParam.java @@ -0,0 +1,30 @@ +package io.shulie.takin.web.data.param.pressureresource; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/5/19 2:56 下午 + */ +@Data +public class PressureResourceDsQueryParam { + @ApiModelProperty("业务数据源,模糊查询") + private String queryBussinessDatabase; + + @ApiModelProperty("业务数据源,等值查询") + private String bussinessDatabase; + + @ApiModelProperty("资源配置ID") + private Long resourceId; + + @ApiModelProperty("应用名称,模糊查询") + private String queryAppName; + + @ApiModelProperty("状态(0-未检测 1-检测失败 2-检测成功)") + private Integer status; + + @ApiModelProperty("数据源Id") + private Long id; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceMqConsumerQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceMqConsumerQueryParam.java new file mode 100644 index 0000000000..0af91baaf6 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceMqConsumerQueryParam.java @@ -0,0 +1,34 @@ +package io.shulie.takin.web.data.param.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/5/19 2:56 下午 + */ +@Data +public class PressureResourceMqConsumerQueryParam extends PageBaseDTO { + @ApiModelProperty("topic") + private String topic; + + @ApiModelProperty("group") + private String group; + + @ApiModelProperty("资源配置ID") + private Long resourceId; + + @ApiModelProperty("mqType") + private String mqType; + + @ApiModelProperty("模糊查询,消费组") + private String queryTopicGroup; + + @ApiModelProperty("queryApplicationName") + private String queryApplicationName; + + @ApiModelProperty("consumerTag") + private Integer consumerTag; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceQueryParam.java new file mode 100644 index 0000000000..9bd4a2aaa3 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceQueryParam.java @@ -0,0 +1,22 @@ +package io.shulie.takin.web.data.param.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/5/19 2:56 下午 + */ +@Data +public class PressureResourceQueryParam extends PageBaseDTO { + private String name; + + @ApiModelProperty("来源ID") + private Long sourceId; + + private List userIdList; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceRemoteCallQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceRemoteCallQueryParam.java new file mode 100644 index 0000000000..c9a6d893f5 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceRemoteCallQueryParam.java @@ -0,0 +1,37 @@ +package io.shulie.takin.web.data.param.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author xingchen + * @description: TODO + * @date 2022/5/19 2:56 下午 + */ +@Data +public class PressureResourceRemoteCallQueryParam extends PageBaseDTO { + @ApiModelProperty("resourceId") + private Long resourceId; + + @ApiModelProperty("查询的接口名") + private String queryInterfaceName; + + @ApiModelProperty("接口类型") + private String interfaceChildType; + + @ApiModelProperty("是否放行(0:是 1:否)") + private Integer pass; + + @ApiModelProperty("状态") + private Integer status; + + @ApiModelProperty("linkId") + private String linkId; + + @ApiModelProperty("入口的detailId") + private String entry; + + @ApiModelProperty("是否需要转换,查询mock") + private boolean convert; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceTableQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceTableQueryParam.java new file mode 100644 index 0000000000..1d665a17e9 --- /dev/null +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/pressureresource/PressureResourceTableQueryParam.java @@ -0,0 +1,33 @@ +package io.shulie.takin.web.data.param.pressureresource; + +import io.shulie.takin.web.common.pojo.dto.PageBaseDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author xingchen + * @description: TODO + * @date 2022/5/19 2:56 下午 + */ +@Data +public class PressureResourceTableQueryParam extends PageBaseDTO { + @ApiModelProperty("业务数据源,模糊查询") + private String queryBusinessTableName; + + @ApiModelProperty("业务数据源,等值匹配") + private String businessTableName; + + @ApiModelProperty("资源配置Id") + private Long resourceId; + + @ApiModelProperty("状态,等值查询") + private Integer status; + + @ApiModelProperty("数据源key") + private String dsKey; + + @ApiModelProperty("relateIds") + private List relateIds; +} diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scene/ScenePageQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scene/ScenePageQueryParam.java index 6b678b918e..1320e7d3ed 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scene/ScenePageQueryParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scene/ScenePageQueryParam.java @@ -1,8 +1,11 @@ package io.shulie.takin.web.data.param.scene; import io.shulie.takin.web.ext.entity.AuthQueryParamCommonExt; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.Date; + /** * @author zhaoyong */ @@ -12,4 +15,9 @@ public class ScenePageQueryParam extends AuthQueryParamCommonExt { private String sceneName; private Integer ignoreType; + + private Long deptId; + + @ApiModelProperty("过滤时间范围") + private Date queryGmtModified; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scriptmanage/ScriptManageDeployPageQueryParam.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scriptmanage/ScriptManageDeployPageQueryParam.java index c5332121d9..ad38a97999 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scriptmanage/ScriptManageDeployPageQueryParam.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/param/scriptmanage/ScriptManageDeployPageQueryParam.java @@ -45,6 +45,10 @@ public class ScriptManageDeployPageQueryParam extends PagingDevice { */ private List userIdList; + private List deptIdList; + + private Long deptId; + /** * 脚本类型 */ diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/activity/ActivityListResult.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/activity/ActivityListResult.java index 03eb450547..e06fbf96ab 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/activity/ActivityListResult.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/activity/ActivityListResult.java @@ -101,4 +101,9 @@ public class ActivityListResult { * 应用名 */ private String applicationName; + + /** + * 部门id + */ + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationDetailResult.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationDetailResult.java index 1996ace6bb..6f47aa4581 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationDetailResult.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationDetailResult.java @@ -36,4 +36,6 @@ public class ApplicationDetailResult extends TenantCommonExt { private String pradarVersion; private Long userId; private String md5; + private Long deptId; + private String clusterName; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResult.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResult.java index 9844a02f80..93cf584ee9 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResult.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResult.java @@ -22,6 +22,8 @@ public class ApplicationListResult { private Date updateTime; + private Long deptId; + private Integer accessStatus; /** diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResultByUpgrade.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResultByUpgrade.java index 06394138f9..1635e08204 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResultByUpgrade.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationListResultByUpgrade.java @@ -20,4 +20,5 @@ public class ApplicationListResultByUpgrade { private Integer nodeNum; + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationPluginsConfigVO.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationPluginsConfigVO.java index 116bc1d5ba..9345cc970c 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationPluginsConfigVO.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/application/ApplicationPluginsConfigVO.java @@ -1,5 +1,6 @@ package io.shulie.takin.web.data.result.application; +import io.shulie.takin.web.ext.entity.AuthQueryResponseCommonExt; import lombok.Data; import java.util.Date; @@ -11,7 +12,7 @@ * @date 2021-05-18 16:48:12 */ @Data -public class ApplicationPluginsConfigVO { +public class ApplicationPluginsConfigVO extends AuthQueryResponseCommonExt { private String id; private String configValueName; /** diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/datasource/DataSourceResult.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/datasource/DataSourceResult.java index 34b0895765..ffc0d952e2 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/datasource/DataSourceResult.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/datasource/DataSourceResult.java @@ -68,4 +68,9 @@ public class DataSourceResult extends TenantCommonExt { * 是否有效 0:有效;1:无效 */ private Boolean isDeleted; + + /** + * 部门id + */ + private Long deptId; } diff --git a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/linkmange/SceneResult.java b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/linkmange/SceneResult.java index edf2537971..d143b03601 100644 --- a/takin-web-data/src/main/java/io/shulie/takin/web/data/result/linkmange/SceneResult.java +++ b/takin-web-data/src/main/java/io/shulie/takin/web/data/result/linkmange/SceneResult.java @@ -1,6 +1,9 @@ package io.shulie.takin.web.data.result.linkmange; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import lombok.Data; +import org.apache.commons.lang3.StringUtils; import java.time.LocalDateTime; import java.util.Date; @@ -78,4 +81,13 @@ public class SceneResult { private Integer totalNodeNum; private String features; + + private Long deptId; + + public boolean isPressureResource() { + if (StringUtils.isBlank(scriptJmxNode)) { + return true; + } + return false; + } } diff --git a/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/cloud/report/TReportMapper.xml b/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/cloud/report/TReportMapper.xml index 033b332e93..2a4d947701 100644 --- a/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/cloud/report/TReportMapper.xml +++ b/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/cloud/report/TReportMapper.xml @@ -122,9 +122,24 @@ and `tenant_id` = #{param.tenantId} + + and `dept_id` = #{param.deptId} + and `env_code` = #{param.envCode} + + AND user_id IN + + #{userId} + + + + AND dept_id IN + + #{deptId} + + order by id desc diff --git a/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/confcenter/tBListMntMapper.xml b/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/confcenter/tBListMntMapper.xml index ace105878b..eb56a40687 100644 --- a/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/confcenter/tBListMntMapper.xml +++ b/takin-web-data/src/main/resources/com/pamirs/takin/entity/mapper/confcenter/tBListMntMapper.xml @@ -35,7 +35,8 @@ CREATE_TIME, UPDATE_TIME, tenant_id, - USER_ID + USER_ID, + dept_id from t_black_list @@ -48,6 +49,12 @@ #{userId} + + AND dept_id IN + + #{deptId} + + order by UPDATE_TIME desc diff --git a/takin-web-data/src/main/resources/mappers/ApplicationApiManageMapper.xml b/takin-web-data/src/main/resources/mappers/ApplicationApiManageMapper.xml index d141111bf7..ac632ac4de 100644 --- a/takin-web-data/src/main/resources/mappers/ApplicationApiManageMapper.xml +++ b/takin-web-data/src/main/resources/mappers/ApplicationApiManageMapper.xml @@ -13,11 +13,12 @@ + ID, APPLICATION_ID, APPLICATION_NAME, CREATE_TIME, UPDATE_TIME, IS_DELETED, api, - `method`,USER_ID,TENANT_ID,ENV_CODE + `method`,USER_ID,TENANT_ID,ENV_CODE,dept_id diff --git a/takin-web-data/src/main/resources/mappers/ApplicationMntMapper.xml b/takin-web-data/src/main/resources/mappers/ApplicationMntMapper.xml index 518ce896c0..d34179c016 100644 --- a/takin-web-data/src/main/resources/mappers/ApplicationMntMapper.xml +++ b/takin-web-data/src/main/resources/mappers/ApplicationMntMapper.xml @@ -71,6 +71,12 @@ #{item,jdbcType=BIGINT} + + AND dept_id in + + #{item,jdbcType=BIGINT} + + AND APPLICATION_NAME LIKE CONCAT('%',#{keyword,jdbcType=VARCHAR},'%') @@ -250,6 +256,9 @@ ALARM_PERSON=#{alarmPerson}, + + CLUSTER_NAME=#{clusterName}, + UPDATE_TIME=now() where APPLICATION_ID=#{applicationId} @@ -371,7 +380,7 @@ + select from t_cluster_nacos_configuration + + diff --git a/takin-web-entrypoint/pom.xml b/takin-web-entrypoint/pom.xml index d1a49059dc..8b0d45ceb3 100644 --- a/takin-web-entrypoint/pom.xml +++ b/takin-web-entrypoint/pom.xml @@ -5,7 +5,7 @@ takin-web io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 @@ -17,7 +17,6 @@ - io.shulie.takin @@ -57,6 +56,10 @@ jul-to-slf4j org.slf4j + + logback-classic + ch.qos.logback + diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/agent/AgentPushController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/agent/AgentPushController.java index a527745b7a..785531d854 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/agent/AgentPushController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/agent/AgentPushController.java @@ -1,52 +1,44 @@ package io.shulie.takin.web.entrypoint.controller.agent; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; - import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; - -import com.pamirs.takin.common.ResponseOk; import com.pamirs.takin.common.ResponseError; -import com.pamirs.takin.entity.domain.vo.JarVersionVo; -import com.pamirs.takin.entity.domain.vo.ApplicationVo; -import com.pamirs.takin.entity.domain.vo.TUploadNeedVo; -import com.pamirs.takin.entity.domain.vo.TUploadInterfaceVo; +import com.pamirs.takin.common.ResponseOk; import com.pamirs.takin.entity.domain.dto.NodeUploadDataDTO; import com.pamirs.takin.entity.domain.query.ShadowJobConfigQuery; +import com.pamirs.takin.entity.domain.vo.ApplicationVo; +import com.pamirs.takin.entity.domain.vo.JarVersionVo; +import com.pamirs.takin.entity.domain.vo.TUploadInterfaceVo; +import com.pamirs.takin.entity.domain.vo.TUploadNeedVo; import io.shulie.takin.channel.bean.CommandPacket; +import io.shulie.takin.web.biz.constant.BizOpConstants; +import io.shulie.takin.web.biz.service.ApplicationService; +import io.shulie.takin.web.biz.service.ConfCenterService; +import io.shulie.takin.web.biz.service.UploadInterfaceService; +import io.shulie.takin.web.biz.service.linkmanage.ApplicationApiService; +import io.shulie.takin.web.biz.service.perfomanceanaly.ReportDetailService; +import io.shulie.takin.web.biz.service.perfomanceanaly.TraceManageService; +import io.shulie.takin.web.biz.service.simplify.ShadowJobConfigService; import io.shulie.takin.web.biz.utils.XmlUtil; import io.shulie.takin.web.common.common.Response; import io.shulie.takin.web.common.constant.AgentUrls; -import io.shulie.takin.web.biz.constant.BizOpConstants; -import io.shulie.takin.web.biz.service.ConfCenterService; +import io.shulie.takin.web.common.context.OperationLogContextHolder; import io.shulie.takin.web.common.exception.ExceptionCode; -import io.shulie.takin.web.biz.service.ApplicationService; import io.shulie.takin.web.common.exception.TakinWebException; -import io.shulie.takin.web.biz.service.UploadInterfaceService; import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; -import io.shulie.takin.web.common.context.OperationLogContextHolder; -import io.shulie.takin.web.biz.service.simplify.ShadowJobConfigService; -import io.shulie.takin.web.biz.service.linkmanage.ApplicationApiService; import io.shulie.takin.web.data.param.application.ConfigReportInputParam; -import io.shulie.takin.web.biz.service.perfomanceanaly.TraceManageService; -import io.shulie.takin.web.biz.service.perfomanceanaly.ReportDetailService; -import lombok.extern.slf4j.Slf4j; import io.swagger.annotations.Api; -import org.springframework.http.MediaType; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; /** * @author TODO @@ -226,4 +218,6 @@ public void uploadTraceInfo(@RequestBody CommandPacket commandPacket) { public void uploadConfigInfo(@Validated @RequestBody ConfigReportInputParam inputParam) { reportDetailService.uploadConfigInfo(inputParam); } + + } diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/ApplicationEntranceController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/ApplicationEntranceController.java index 12809afdd5..f86dda208b 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/ApplicationEntranceController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/ApplicationEntranceController.java @@ -4,10 +4,14 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import cn.hutool.core.collection.ListUtil; import com.google.common.collect.Lists; import io.shulie.amdb.common.dto.link.entrance.ServiceInfoDTO; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.common.beans.response.ResponseResult; import io.shulie.takin.web.amdb.api.ApplicationEntranceClient; import io.shulie.takin.web.amdb.bean.common.EntranceTypeEnum; +import io.shulie.takin.web.biz.pojo.request.application.ApplicationEntrancesAllQueryRequest; import io.shulie.takin.web.biz.pojo.request.application.ApplicationEntrancesSampleTypeQueryRequest; import io.shulie.takin.web.biz.service.LinkTopologyService; import io.shulie.takin.web.common.exception.TakinWebException; @@ -63,39 +67,77 @@ public class ApplicationEntranceController { public List getEntranceTypes() { EntranceTypeEnum[] values = EntranceTypeEnum.values(); return Stream.of(values) - .map(item -> { - WebOptionEntity webOptionEntity = new WebOptionEntity(); - webOptionEntity.setLabel(item.name()); - webOptionEntity.setValue(item.name()); - return webOptionEntity; - }).collect(Collectors.toList()); + .map(item -> { + WebOptionEntity webOptionEntity = new WebOptionEntity(); + webOptionEntity.setLabel(item.name()); + webOptionEntity.setValue(item.name()); + return webOptionEntity; + }).collect(Collectors.toList()); } @GetMapping() @ApiOperation("获得入口服务列表") public List getApplicationEntrances(@Validated - ApplicationEntrancesQueryRequest request) { + ApplicationEntrancesQueryRequest request) { + List applicationEntrances = applicationEntranceClient.getApplicationEntrances( + request.getApplicationName(), request.getType().getType(), request.getServiceName(), 1, 500); + if (CollectionUtils.isEmpty(applicationEntrances)) { + return Lists.newArrayList(); + } + return applicationEntrances.stream() + .filter(item -> !item.getServiceName().startsWith("PT_")) + .map(item -> { + ApplicationEntrancesResponse applicationEntrancesResponse = new ApplicationEntrancesResponse(); + applicationEntrancesResponse.setMethod(item.getMethodName()); + applicationEntrancesResponse.setRpcType(item.getRpcType()); + applicationEntrancesResponse.setExtend(item.getExtend()); + applicationEntrancesResponse.setServiceName(item.getServiceName()); + applicationEntrancesResponse.setLabel( + ActivityUtil.serviceNameLabel(item.getServiceName(), item.getMethodName())); + applicationEntrancesResponse.setValue( + ActivityUtil.createLinkId(item.getServiceName(), item.getMethodName(), + item.getAppName(), item.getRpcType(), item.getExtend())); + return applicationEntrancesResponse; + // 增加去重 + }).distinct().collect(Collectors.toList()); + } + + + @GetMapping(value = "/pageList") + @ApiOperation("获得入口服务列表page") + public ResponseResult getApplicationEntrances_page( + ApplicationEntrancesAllQueryRequest request) { + List list = this.getApplicationEntrances_all(request); + List pageList = ListUtil.page(request.getCurrentPage(), request.getPageSize(), list); + return ResponseResult.success(PagingList.of(pageList, list.size())); + } + + @GetMapping(value = "/list") + @ApiOperation("获得入口服务列表all") + public List getApplicationEntrances_all( + ApplicationEntrancesAllQueryRequest request) { List applicationEntrances = applicationEntranceClient.getApplicationEntrances( - request.getApplicationName(), request.getType().getType(),request.getServiceName(), 1, 500); + request.getApplicationName(), null, request.getServiceName(), 1, 1000); if (CollectionUtils.isEmpty(applicationEntrances)) { return Lists.newArrayList(); } return applicationEntrances.stream() - .filter(item -> !item.getServiceName().startsWith("PT_")) - .map(item -> { - ApplicationEntrancesResponse applicationEntrancesResponse = new ApplicationEntrancesResponse(); - applicationEntrancesResponse.setMethod(item.getMethodName()); - applicationEntrancesResponse.setRpcType(item.getRpcType()); - applicationEntrancesResponse.setExtend(item.getExtend()); - applicationEntrancesResponse.setServiceName(item.getServiceName()); - applicationEntrancesResponse.setLabel( - ActivityUtil.serviceNameLabel(item.getServiceName(), item.getMethodName())); - applicationEntrancesResponse.setValue( - ActivityUtil.createLinkId(item.getServiceName(), item.getMethodName(), - item.getAppName(), item.getRpcType(), item.getExtend())); - return applicationEntrancesResponse; - // 增加去重 - }).distinct().collect(Collectors.toList()); + .filter(item -> !item.getServiceName().startsWith("PT_")) + .map(item -> { + ApplicationEntrancesResponse applicationEntrancesResponse = new ApplicationEntrancesResponse(); + applicationEntrancesResponse.setMethod(item.getMethodName()); + applicationEntrancesResponse.setRpcType(item.getRpcType()); + applicationEntrancesResponse.setExtend(item.getExtend()); + applicationEntrancesResponse.setServiceName(item.getServiceName()); + applicationEntrancesResponse.setAppName(item.getAppName()); + applicationEntrancesResponse.setLabel( + ActivityUtil.serviceNameLabel(item.getServiceName(), item.getMethodName())); + applicationEntrancesResponse.setValue( + ActivityUtil.createLinkId(item.getServiceName(), item.getMethodName(), + item.getAppName(), item.getRpcType(), item.getExtend())); + return applicationEntrancesResponse; + // 增加去重 + }).distinct().collect(Collectors.toList()); } @GetMapping("/bySamplerType") @@ -118,7 +160,7 @@ public List getApplicationEntrances(@Validated App applicationEntrancesResponse.setLabel(item.getMethodName() + "|" + item.getServiceName()); // 只有这个地方用到 applicationEntrancesResponse.setValue( - ActivityUtil.buildEntrance(item.getMethodName(),item.getServiceName(),item.getRpcType())); + ActivityUtil.buildEntrance(item.getMethodName(), item.getServiceName(), item.getRpcType())); return applicationEntrancesResponse; // 增加去重 }).distinct().collect(Collectors.toList()); @@ -134,7 +176,7 @@ public List getApplicationEntrances(@Validated App @ApiOperation("获得入口服务拓扑图") @GetMapping("topology") public ApplicationEntranceTopologyResponse getApplicationEntrancesTopology(@Validated - ApplicationEntranceTopologyQueryRequest request) { + ApplicationEntranceTopologyQueryRequest request) { if (StringUtils.isEmpty(request.getApplicationName())) { throw new TakinWebException(ExceptionCode.APP_LINK_TOPOLOGY_ERROR, "没有应用名"); } @@ -145,19 +187,19 @@ public ApplicationEntranceTopologyResponse getApplicationEntrancesTopology(@Vali @ApiOperation("标记未知节点") public Boolean updateUnknownNodeToOuter(@Validated @RequestBody ApplicationEntranceTopologyQueryRequest request) { return applicationEntranceClient.updateUnknownNodeToOuter(request.getApplicationName(), request.getLinkId(), - request.getServiceName(), request.getMethod(), - request.getRpcType(), request.getExtend(), request.getNodeId()); + request.getServiceName(), request.getMethod(), + request.getRpcType(), request.getExtend(), request.getNodeId()); } @GetMapping("/all") @ApiOperation("获取应用下所有入口服务列表") public List getApplicationAllEntrances(String appName) { - if(StringUtils.isBlank(appName)){ + if (StringUtils.isBlank(appName)) { log.error("应用名称不能为空"); return Collections.emptyList(); } List applicationEntrances = applicationEntranceClient.getApplicationEntrances( - appName, "",null, 0, 500); + appName, "", null, 0, 500); if (CollectionUtils.isEmpty(applicationEntrances)) { return Lists.newArrayList(); } @@ -186,7 +228,7 @@ public List getApplicationAllEntrances(String appN @GetMapping("/allByActivity") @ApiOperation("获取应用下创建业务活动所有入口服务列表") public List getApplicationAllEntrancesByActivity(String appName) { - if(StringUtils.isBlank(appName)){ + if (StringUtils.isBlank(appName)) { log.error("应用名称不能为空"); return Collections.emptyList(); } @@ -196,16 +238,16 @@ public List getApplicationAllEntrancesByActivity(S } return activities.stream() .filter(item -> { - String entrace = item.getEntrace(); - String[] entraceArray = entrace.split("\\|"); - return 4 == entraceArray.length; + String entrace = item.getEntrace(); + String[] entraceArray = entrace.split("\\|"); + return 4 == entraceArray.length; }).map(item -> { String entrace = item.getEntrace(); String[] entraceArray = entrace.split("\\|"); ApplicationEntrancesResponse applicationEntrancesResponse = new ApplicationEntrancesResponse(); HashMap nameAndId = new HashMap(); - nameAndId.put("linkId",item.getLinkId()); - nameAndId.put("linkName",item.getLinkName()); + nameAndId.put("linkId", item.getLinkId()); + nameAndId.put("linkName", item.getLinkName()); applicationEntrancesResponse.setActivityNameAndId(nameAndId); applicationEntrancesResponse.setLabel( ActivityUtil.serviceNameLabel(entraceArray[2], entraceArray[1])); diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareJarController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareJarController.java index cc18d3df5e..dee516c8c0 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareJarController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareJarController.java @@ -167,17 +167,6 @@ public PagingList list( .map(item -> BeanUtil.copyProperties(item, MiddlewareJarResponse.class)) .collect(Collectors.toList()); - if (!collect.isEmpty()) { - boolean tempCanEdit; - if (WebPluginUtils.validateAdmin()) { - tempCanEdit = true; - } else { - tempCanEdit = WebPluginUtils.traceUser() == null || WebPluginUtils.getUpdateAllowUserIdList().contains(WebPluginUtils.traceUser().getId()); - } - final boolean canEdit = tempCanEdit; - collect.forEach(response -> response.setCanEdit(canEdit)); - } - return PagingList.of(collect, page.getTotal()); } diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareSummaryController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareSummaryController.java index 1077d7bc76..4a8f5597a6 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareSummaryController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/application/MiddlewareSummaryController.java @@ -117,14 +117,6 @@ public PagingList list( final List collect = page.getRecords().parallelStream() .map(item -> BeanUtil.copyProperties(item, MiddlewareSummaryResponse.class)).collect( Collectors.toList()); - // 1.无权限模块:默认可编辑 2.有权限模块:管理员可编辑,子账号被授权可编辑 - if(WebPluginUtils.traceUser() == null) { - collect.parallelStream().forEach(item -> item.setCanEdit(Boolean.TRUE)); - } else { - boolean canEdit = WebPluginUtils.validateAdmin() || WebPluginUtils.getUpdateAllowUserIdList().contains(WebPluginUtils.traceUser().getId()); - collect.parallelStream().forEach(item -> item.setCanEdit(canEdit)); - } - return PagingList.of(collect, page.getTotal()); } diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/businessflow/BusinessFlowController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/businessflow/BusinessFlowController.java index e31bd3c933..ab31e2b4bb 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/businessflow/BusinessFlowController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/businessflow/BusinessFlowController.java @@ -209,11 +209,12 @@ public ResponseResult getThreadGroupDetail(@NotNull moduleCode = BizOpConstants.ModuleCode.BUSINESS_PROCESS, needAuth = ActionTypeEnum.QUERY ) - public PagingList getBusinessFlowList(@ApiParam("业务流程名称") String businessFlowName, Integer current, Integer pageSize) { + public PagingList getBusinessFlowList(@ApiParam("业务流程名称") String businessFlowName, @ApiParam("部门id") Long deptId, Integer current, Integer pageSize) { BusinessFlowPageQueryRequest queryRequest = new BusinessFlowPageQueryRequest(); queryRequest.setCurrentPage(current); queryRequest.setPageSize(pageSize); queryRequest.setBusinessFlowName(businessFlowName); + queryRequest.setDeptId(deptId); return sceneService.getBusinessFlowList(queryRequest); } diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/confcenter/ApplicationController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/confcenter/ApplicationController.java index 6075083263..f3a618d9cc 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/confcenter/ApplicationController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/confcenter/ApplicationController.java @@ -82,8 +82,8 @@ public class ApplicationController { @GetMapping("/application/center/list") @ApiOperation("|_ 应用列表查询接口") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.QUERY ) public PagingList pageApplicationWithAuth(ApplicationQueryRequestV2 request) { return applicationService.pageApplication(request); @@ -92,28 +92,29 @@ public PagingList pageApplicationWithAuth(Application @GetMapping("/application/center/list/dictionary") @ApiOperation("应用列表查询接口") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.QUERY ) public Response> getApplicationListNoAuth(ApplicationQueryRequestV2 request) { + request.setAll(true); return applicationService.getApplicationList(request); } @GetMapping("/console/application/center/app/info") @ApiOperation("应用详情查询接口") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.QUERY ) public Response getApplicationInfoWithAuth( - @ApiParam(name = "id", value = "系统id") @RequestParam String id) { + @ApiParam(name = "id", value = "系统id") @RequestParam String id) { return applicationService.getApplicationInfo(id); } @GetMapping("/application/center/app/info/dictionary") @ApiOperation("应用详情查询接口") public Response getApplicationInfoNoAuth( - @ApiParam(name = "id", value = "系统id") String id + @ApiParam(name = "id", value = "系统id") String id ) { return applicationService.getApplicationInfo(id); } @@ -127,13 +128,13 @@ public Response getApplicationInfoNoAuth( @PostMapping("/console/application/center/app/info") @ApiOperation("新增应用接口") @ModuleDef( - moduleName = BizOpConstants.Modules.APPLICATION_MANAGE, - subModuleName = BizOpConstants.SubModules.BASIC_INFO, - logMsgKey = BizOpConstants.Message.MESSAGE_BASIC_INFO_CREATE + moduleName = BizOpConstants.Modules.APPLICATION_MANAGE, + subModuleName = BizOpConstants.SubModules.BASIC_INFO, + logMsgKey = BizOpConstants.Message.MESSAGE_BASIC_INFO_CREATE ) @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.CREATE + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.CREATE ) public Response addApplication(@RequestBody ApplicationVo vo) { OperationLogContextHolder.operationType(BizOpConstants.OpTypes.CREATE); @@ -144,13 +145,13 @@ public Response addApplication(@RequestBody ApplicationVo vo) { @PutMapping("/console/application/center/app/info") @ApiOperation("编辑应用") @ModuleDef( - moduleName = BizOpConstants.Modules.APPLICATION_MANAGE, - subModuleName = BizOpConstants.SubModules.BASIC_INFO, - logMsgKey = BizOpConstants.Message.MESSAGE_BASIC_INFO_UPDATE + moduleName = BizOpConstants.Modules.APPLICATION_MANAGE, + subModuleName = BizOpConstants.SubModules.BASIC_INFO, + logMsgKey = BizOpConstants.Message.MESSAGE_BASIC_INFO_UPDATE ) @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.UPDATE + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.UPDATE ) public Response modifyApplication(@RequestBody ApplicationVo vo) { OperationLogContextHolder.operationType(BizOpConstants.OpTypes.UPDATE); @@ -160,16 +161,16 @@ public Response modifyApplication(@RequestBody ApplicationVo vo) { @ApiOperation("删除应用接口") @DeleteMapping("/console/application/center/app/info") @ModuleDef( - moduleName = BizOpConstants.Modules.APPLICATION_MANAGE, - subModuleName = BizOpConstants.SubModules.BASIC_INFO, - logMsgKey = BizOpConstants.Message.MESSAGE_BASIC_INFO_DELETE + moduleName = BizOpConstants.Modules.APPLICATION_MANAGE, + subModuleName = BizOpConstants.SubModules.BASIC_INFO, + logMsgKey = BizOpConstants.Message.MESSAGE_BASIC_INFO_DELETE ) @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.DELETE + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.DELETE ) public Response deleteApplication( - @RequestBody ApplicationVo vo) { + @RequestBody ApplicationVo vo) { if (vo == null || StringUtil.isEmpty(vo.getId())) { return Response.fail(FALSE_CODE, "id 不能为空"); } @@ -187,7 +188,7 @@ public Response deleteApplication( @GetMapping("/application/center/app/switch/calculate") public Response appSwitchForce(@RequestParam(value = "uid", required = false) Long uid) { TenantCommonExt tenantCommonExt = WebPluginUtils.traceTenantCommonExt(); - if(uid != null && !uid.equals(tenantCommonExt.getTenantId())) { + if (uid != null && !uid.equals(tenantCommonExt.getTenantId())) { return Response.fail("租户不匹配"); } return applicationService.calculateUserSwitch(tenantCommonExt); @@ -196,14 +197,14 @@ public Response appSwitchForce(@RequestParam(value = "uid", required = false) Lo @ApiOperation("获取下载导出配置地址") @GetMapping("/application/center/app/config/url") public Response getExportDownloadConfigUrl(@ApiParam(name = "id", value = "系统id") @NotNull String id, - HttpServletRequest request) { + HttpServletRequest request) { return applicationService.buildExportDownLoadConfigUrl(id, request); } @ApiOperation("|_ 应用配置导出") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "应用id", - paramType = "query", dataType = "int") + @ApiImplicitParam(name = "id", value = "应用id", + paramType = "query", dataType = "int") }) @GetMapping("/application/center/app/config/export") public void export(@RequestParam("id") Long applicationId, HttpServletResponse response) { @@ -213,10 +214,10 @@ public void export(@RequestParam("id") Long applicationId, HttpServletResponse r @ApiOperation("|_ 应用配置导入") @PostMapping("/application/center/app/config/import") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "应用id", - paramType = "form", dataType = "int"), - @ApiImplicitParam(name = "file", value = "导入的 excel", - paramType = "form", dataType = "file") + @ApiImplicitParam(name = "id", value = "应用id", + paramType = "form", dataType = "int"), + @ApiImplicitParam(name = "file", value = "导入的 excel", + paramType = "form", dataType = "file") }) public Response importApplicationConfig(@RequestParam MultipartFile file, @RequestParam Long id) { return applicationService.importApplicationConfig(file, id); @@ -231,8 +232,8 @@ public Response appDsConfigIsNewVersion() { @PostMapping("/application/center/unstallAllAgent") @ApiOperation("一键卸载探针") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.QUERY ) public void uninstallAllAgent(@RequestBody AppUninstallAgentVO vo) { applicationService.uninstallAllAgent(vo.getAppIds()); @@ -241,8 +242,8 @@ public void uninstallAllAgent(@RequestBody AppUninstallAgentVO vo) { @PostMapping("/application/center/resumeAllAgent") @ApiOperation("一键恢复探针") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.QUERY ) public void resumeAllAgent(@RequestBody AppUninstallAgentVO vo) { applicationService.resumeAllAgent(vo.getAppIds()); @@ -255,37 +256,37 @@ public void resumeAllAgent(@RequestBody AppUninstallAgentVO vo) { needAuth = ActionTypeEnum.QUERY ) public Response operateCheck(@RequestBody AppOperateAgentCheckVO vo) { - return applicationService.operateCheck(vo.getAppIds(),vo.getOperate()); + return applicationService.operateCheck(vo.getAppIds(), vo.getOperate()); } @ApiOperation("编辑静默开关接口") @PutMapping("/application/center/app/switch/silence") @ModuleDef( - moduleName = BizOpConstants.Modules.CONFIG_CENTER, - subModuleName = BizOpConstants.SubModules.PRESSURE_CONFIG_SWITCH, - logMsgKey = BizOpConstants.Message.MESSAGE_PRESSURE_TEST_SWITCH_ACTION + moduleName = BizOpConstants.Modules.CONFIG_CENTER, + subModuleName = BizOpConstants.SubModules.PRESSURE_CONFIG_SWITCH, + logMsgKey = BizOpConstants.Message.MESSAGE_PRESSURE_TEST_SWITCH_ACTION ) @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.CONFIG_CENTER, - needAuth = ActionTypeEnum.ENABLE_DISABLE + moduleCode = BizOpConstants.ModuleCode.CONFIG_CENTER, + needAuth = ActionTypeEnum.ENABLE_DISABLE ) public Response UpdateAppSilenceSwitch(@RequestBody ApplicationVo vo) { if (vo == null || vo.getSilenceEnable() == null) { return Response.fail(FALSE_CODE, "silenceEnable 不能为空"); } OperationLogContextHolder.operationType( - vo.getSilenceEnable() ? BizOpConstants.OpTypes.OPEN : BizOpConstants.OpTypes.CLOSE); + vo.getSilenceEnable() ? BizOpConstants.OpTypes.OPEN : BizOpConstants.OpTypes.CLOSE); OperationLogContextHolder.addVars(BizOpConstants.Vars.ACTION, - vo.getSilenceEnable() ? BizOpConstants.OpTypes.OPEN : BizOpConstants.OpTypes.CLOSE); + vo.getSilenceEnable() ? BizOpConstants.OpTypes.OPEN : BizOpConstants.OpTypes.CLOSE); return applicationService.userAppSilenceSwitch(WebPluginUtils.traceTenantCommonExt(), vo.getSilenceEnable()); } @ApiOperation("获取静默开关状态接口") @GetMapping("/application/center/app/switch/silence") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.CONFIG_CENTER, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.CONFIG_CENTER, + needAuth = ActionTypeEnum.QUERY ) public Response appSilenceSwitch() { return applicationService.userAppSilenceSwitchInfo(); @@ -294,11 +295,11 @@ public Response appSilenceSwitch() { @ApiOperation("按租户查询上报数据接口") @GetMapping("/application/center/app/report/config/info") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.CONFIG_CENTER, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.CONFIG_CENTER, + needAuth = ActionTypeEnum.QUERY ) public Response AppConfigReportInfo(@ApiParam(name = "bizType", value = "业务类型") @NotNull Integer bizType, - @ApiParam(name = "appName", value = "应用名称") String appName) { + @ApiParam(name = "appName", value = "应用名称") String appName) { return applicationService.getApplicationReportConfigInfo(bizType, appName); } @@ -310,11 +311,11 @@ public Response AppConfigReportInfo(@ApiParam(name = "bizType", value = "业务 @GetMapping("/application/center/app/monitorDetailes") @ApiOperation("应用监控查询接口") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.QUERY ) public Response> getApplicationVisualInfo( - @Valid ApplicationVisualInfoQueryRequest request) { + @Valid ApplicationVisualInfoQueryRequest request) { return applicationService.getApplicationVisualInfo(request); } @@ -326,8 +327,8 @@ public Response> getApplicationVisualInfo( @PostMapping("/application/center/app/attendService") @ApiOperation("关注应用服务接口") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.CREATE + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.CREATE ) public void attendApplicationService(@RequestBody ApplicationVisualInfoQueryRequest request) throws Exception { if (null == request.getAttend()) { @@ -339,8 +340,8 @@ public void attendApplicationService(@RequestBody ApplicationVisualInfoQueryRequ @GetMapping("/application/center/app/activityList") @ApiOperation("关联业务活动") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.QUERY + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.QUERY ) public Response getApplicationActivityList(@Valid ApplicationVisualInfoQueryRequest request) { Response> response = applicationService.getApplicationVisualInfo(request); @@ -361,8 +362,8 @@ public Response getApplicationActivityList(@Valid ApplicationVisualInfoQueryRequ @PostMapping("/application/center/app/gotoActivityInfo") @ApiOperation("跳转业务活动详情") @AuthVerification( - moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, - needAuth = ActionTypeEnum.CREATE + moduleCode = BizOpConstants.ModuleCode.APPLICATION_MANAGE, + needAuth = ActionTypeEnum.CREATE ) public Map gotoActivityInfo(@Validated @RequestBody ActivityCreateRequest request) throws Exception { HashMap result = new HashMap<>(1); @@ -374,27 +375,27 @@ public Map gotoActivityInfo(@Validated @RequestBody ActivityCreat entity = activityService.getActivityByName(temporaryKey); if (null != entity) { result.put(entity.getLinkId(), false); - }else { + } else { List applicationEntrances = applicationEntranceClient.getApplicationEntrances( - request.getApplicationName(), "",null,1,500); + request.getApplicationName(), "", null, 1, 500); if (CollectionUtils.isNotEmpty(applicationEntrances)) { List responseList = applicationEntrances.stream() - .filter(item -> !item.getServiceName().startsWith("PT_")) - .map(item -> { - ApplicationEntrancesResponse applicationEntrancesResponse = new ApplicationEntrancesResponse(); - applicationEntrancesResponse.setMethod(item.getMethodName()); - applicationEntrancesResponse.setRpcType(item.getRpcType()); - applicationEntrancesResponse.setExtend(item.getExtend()); - applicationEntrancesResponse.setServiceName(item.getServiceName()); - applicationEntrancesResponse.setLabel( - ActivityUtil.serviceNameLabel(item.getServiceName(), item.getMethodName())); - applicationEntrancesResponse.setValue( - ActivityUtil.createLinkId(item.getServiceName(), item.getMethodName(), - item.getAppName(), item.getRpcType(), item.getExtend())); - return applicationEntrancesResponse; - // 增加去重 - }).distinct().filter(item -> item.getLabel().equals(request.getLabel())).collect( - Collectors.toList()); + .filter(item -> !item.getServiceName().startsWith("PT_")) + .map(item -> { + ApplicationEntrancesResponse applicationEntrancesResponse = new ApplicationEntrancesResponse(); + applicationEntrancesResponse.setMethod(item.getMethodName()); + applicationEntrancesResponse.setRpcType(item.getRpcType()); + applicationEntrancesResponse.setExtend(item.getExtend()); + applicationEntrancesResponse.setServiceName(item.getServiceName()); + applicationEntrancesResponse.setLabel( + ActivityUtil.serviceNameLabel(item.getServiceName(), item.getMethodName())); + applicationEntrancesResponse.setValue( + ActivityUtil.createLinkId(item.getServiceName(), item.getMethodName(), + item.getAppName(), item.getRpcType(), item.getExtend())); + return applicationEntrancesResponse; + // 增加去重 + }).distinct().filter(item -> item.getLabel().equals(request.getLabel())).collect( + Collectors.toList()); if (CollectionUtils.isNotEmpty(responseList)) { request.setLinkId(responseList.get(0).getValue()); } diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/dashboard/WorkBenchController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/dashboard/WorkBenchController.java index a278bd1784..3b42741aa7 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/dashboard/WorkBenchController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/dashboard/WorkBenchController.java @@ -23,7 +23,7 @@ */ @RestController -@RequestMapping("api/workbench") +@RequestMapping("api/takinworkbench") @Api(tags = "WorkBenchController", value = "工作台接口") @Slf4j public class WorkBenchController { diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/interfaceperformance/PerformanceConfigController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/interfaceperformance/PerformanceConfigController.java index 8162a13a97..c004860a2a 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/interfaceperformance/PerformanceConfigController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/interfaceperformance/PerformanceConfigController.java @@ -27,7 +27,7 @@ * @date 2022/5/19 1:33 下午 */ @RestController -@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/interfaceperformance/config") +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "interfaceperformance/config") @Api(tags = "接口: 接口压测") @Slf4j public class PerformanceConfigController { diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/ApplicationApiController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/ApplicationApiController.java index daabe94811..59690e4c65 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/ApplicationApiController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/ApplicationApiController.java @@ -91,12 +91,13 @@ public Response pullV1(@RequestParam(value = "appName") String appName) { needAuth = ActionTypeEnum.QUERY ) public Response query(@ApiParam(name = "applicationName", value = "应用名") String applicationName, - @ApiParam(name = "api", value = "入口名") String api, + @ApiParam(name = "api", value = "入口名") String api, @ApiParam(name = "deptId", value = "部门id") Long deptId, Integer current, Integer pageSize) { EntranceApiVo vo = new EntranceApiVo(); vo.setApplicationName(applicationName); vo.setApi(api); + vo.setDeptId(deptId); vo.setPageSize(pageSize); vo.setCurrentPage(current); try { diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/LinkGuardController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/LinkGuardController.java index 688444e880..f802db4682 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/LinkGuardController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/linkmanage/LinkGuardController.java @@ -8,6 +8,7 @@ import io.shulie.takin.common.beans.annotation.ActionTypeEnum; import io.shulie.takin.common.beans.annotation.AuthVerification; import io.shulie.takin.common.beans.annotation.ModuleDef; +import io.shulie.takin.common.beans.response.ResponseResult; import io.shulie.takin.web.biz.constant.BizOpConstants; import io.shulie.takin.web.biz.service.linkmanage.LinkGuardService; import io.shulie.takin.web.common.common.Response; @@ -68,7 +69,6 @@ public Response storetechLink(@RequestBody LinkGuardVo vo) { OperationLogContextHolder.operationType(BizOpConstants.OpTypes.CREATE); OperationLogContextHolder.addVars(BizOpConstants.Vars.CLASS_METHOD_NAME, vo.getMethodInfo()); return linkGuardService.addGuard(vo); - } /** diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pradar/PradarConfigController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pradar/PradarConfigController.java index 8a5bec7cbc..56132fd50f 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pradar/PradarConfigController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pradar/PradarConfigController.java @@ -52,6 +52,7 @@ public PagingList pageList(PradarZKConfigQueryRequest qu return pradarConfigService.page(queryRequest); } + @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST}) @ApiOperation("PRADAR配置修改") @ModuleDef( diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResourceAckController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResourceAckController.java new file mode 100644 index 0000000000..a45e26ca95 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResourceAckController.java @@ -0,0 +1,34 @@ +package io.shulie.takin.web.entrypoint.controller.pressureresource; + +import com.alibaba.fastjson.JSON; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommandService; +import io.shulie.takin.web.biz.service.pressureresource.vo.agent.command.TakinAck; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/pressureResource/agent") +@Api(tags = "接口: 压测资源探针检测结果上报") +@Slf4j +public class PressureResourceAckController { + + @Autowired + private PressureResourceCommandService pressureResourceCommandService; + + + @PostMapping("/ack") + public void commandAck(@RequestBody TakinAck takinAck){ + log.info("收到压测资源响应:{}", JSON.toJSONString(takinAck)); + pressureResourceCommandService.processAck(takinAck); + } + + + +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResourceShadowMqController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResourceShadowMqController.java new file mode 100644 index 0000000000..3192f20af5 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResourceShadowMqController.java @@ -0,0 +1,82 @@ +package io.shulie.takin.web.entrypoint.controller.pressureresource; + +import io.shulie.takin.common.beans.response.ResponseResult; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceMqConsumerCreateInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceMqConsumerQueryRequest; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceMqConsumerService; +import io.shulie.takin.web.biz.service.pressureresource.common.ModuleEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.SourceTypeEnum; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @author xingchen + * @description: TODO + * @date 2022/10/11 9:46 AM + */ +@RestController +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/pressureResource/mqconsumer") +@Api(tags = "接口: 关联表") +@Slf4j +public class PressureResourceShadowMqController { + @Resource + private PressureResourceMqConsumerService pressureResourceMqConsumerService; + + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @ApiOperation("链路压测资源-新增影子消费者") + @RequestMapping(value = "/create", method = RequestMethod.POST) + public ResponseResult create(@RequestBody PressureResourceMqConsumerCreateInput request) { + request.setType(SourceTypeEnum.MANUAL.getCode()); + pressureResourceMqConsumerService.create(request); + + CommandTaskVo taskVo = new CommandTaskVo(); + taskVo.setResourceId(request.getResourceId()); + taskVo.setModule(ModuleEnum.MQ.getCode()); + pressureResourceCommonService.pushRedisCommand(taskVo); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-修改影子消费者") + @RequestMapping(value = "/update", method = RequestMethod.POST) + public ResponseResult update(@RequestBody PressureResourceMqConsumerCreateInput request) { + pressureResourceMqConsumerService.update(request); + + CommandTaskVo taskVo = new CommandTaskVo(); + taskVo.setResourceId(request.getResourceId()); + taskVo.setModule(ModuleEnum.MQ.getCode()); + pressureResourceCommonService.pushRedisCommand(taskVo); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-修改影子消费者-开启/关闭消费") + @RequestMapping(value = "/consumerTag", method = RequestMethod.POST) + public ResponseResult consumerTag(@RequestBody PressureResourceMqConsumerCreateInput request) { + pressureResourceMqConsumerService.processConsumerTag(request); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-分页") + @RequestMapping(value = "/list", method = RequestMethod.GET) + public ResponseResult list(PressureResourceMqConsumerQueryRequest request) { + return ResponseResult.success(pressureResourceMqConsumerService.list(request)); + } + + @ApiOperation("链路压测资源-删除") + @RequestMapping(value = "/del", method = RequestMethod.GET) + public ResponseResult del(PressureResourceMqConsumerCreateInput input) { + pressureResourceMqConsumerService.delete(input.getId()); + return ResponseResult.success(); + } +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureAppController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureAppController.java new file mode 100644 index 0000000000..87ffe956f3 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureAppController.java @@ -0,0 +1,49 @@ +package io.shulie.takin.web.entrypoint.controller.pressureresource; + +import io.shulie.takin.common.beans.response.ResponseResult; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceAppInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceAppRequest; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceAppService; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 链路资源-应用检查 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:51 PM + */ +@RestController +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/pressureResource/app") +@Api(tags = "接口: 链路资源-应用检查") +@Slf4j +public class PressureResoureAppController { + private static Logger logger = LoggerFactory.getLogger(PressureResoureAppController.class); + + @Resource + private PressureResourceAppService pressureResourceAppService; + + @ApiOperation("链路压测资源-修改") + @RequestMapping(value = "/update", method = RequestMethod.POST) + public ResponseResult update(@RequestBody PressureResourceAppInput input) { + pressureResourceAppService.update(input); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-应用检查列表") + @RequestMapping(value = "/checkList", method = RequestMethod.GET) + public ResponseResult detail(PressureResourceAppRequest request) { + return ResponseResult.success(pressureResourceAppService.appCheckList(request)); + } +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureController.java new file mode 100644 index 0000000000..ccc3beb58d --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureController.java @@ -0,0 +1,111 @@ +package io.shulie.takin.web.entrypoint.controller.pressureresource; + +import io.shulie.takin.common.beans.response.ResponseResult; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceIsolateInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceQueryRequest; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceService; +import io.shulie.takin.web.biz.service.pressureresource.common.CheckStatusEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.SourceTypeEnum; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.shulie.takin.web.ext.util.WebPluginUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 链路资源配置 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:51 PM + */ +@RestController +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/pressureResource") +@Api(tags = "接口: 链路资源配置") +@Slf4j +public class PressureResoureController { + private static Logger logger = LoggerFactory.getLogger(PressureResoureController.class); + + @Resource + private PressureResourceService pressureResourceService; + + @ApiOperation("链路压测资源新增") + @RequestMapping(value = "/create", method = RequestMethod.POST) + public ResponseResult create(@RequestBody PressureResourceInput input) { + // 这里只是页面手工新增入口 + input.setType(SourceTypeEnum.MANUAL.getCode()); + input.setCheckStatus(CheckStatusEnum.CHECK_NO.getCode()); + input.setUserId(WebPluginUtils.traceUserId()); + pressureResourceService.add(input); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源修改") + @RequestMapping(value = "/update", method = RequestMethod.POST) + public ResponseResult update(@RequestBody PressureResourceInput input) { + input.setType(SourceTypeEnum.MANUAL.getCode()); + pressureResourceService.update(input); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源删除") + @RequestMapping(value = "/del", method = RequestMethod.GET) + public ResponseResult del(PressureResourceInput input) { + pressureResourceService.delete(input.getId()); + return ResponseResult.success(); + } + + @ApiOperation("设置数据隔离方式") + @RequestMapping(value = "/updateIsolate", method = RequestMethod.POST) + public ResponseResult updateIsolate(@RequestBody PressureResourceIsolateInput input) { + pressureResourceService.updateIsolate(input); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源查询") + @RequestMapping(value = "/list", method = RequestMethod.GET) + public ResponseResult list(PressureResourceQueryRequest request) { + return ResponseResult.success(pressureResourceService.list(request)); + } + + @ApiOperation("链路压测资源查询-详情-编辑链路") + @RequestMapping(value = "/detailList", method = RequestMethod.GET) + public ResponseResult detailList(PressureResourceQueryRequest request) { + return ResponseResult.success(pressureResourceService.detail(request)); + } + + @ApiOperation("链路压测资源查询-汇总数据-应用") + @RequestMapping(value = "/appInfo", method = RequestMethod.GET) + public ResponseResult appInfo(PressureResourceQueryRequest request) { + return ResponseResult.success(pressureResourceService.appInfo(request.getId())); + } + + @ApiOperation("链路压测资源查询-汇总数据-数据源") + @RequestMapping(value = "/dsInfo", method = RequestMethod.GET) + public ResponseResult dsInfo(PressureResourceQueryRequest request) { + return ResponseResult.success(pressureResourceService.dsInfo(request.getId())); + } + + @ApiOperation("链路压测资源查询-汇总数据-mq信息") + @RequestMapping(value = "/mqInfo", method = RequestMethod.GET) + public ResponseResult mqInfo(PressureResourceQueryRequest request) { + return ResponseResult.success(pressureResourceService.mqInfo(request.getId())); + } + + //@ApiModelProperty("类型(1-应用检查,2-影子隔离 3-远程调用 )") + //@ApiModelProperty("状态(0-未开始 1-进行中 2-完成)") + @ApiOperation("链路压测资源查询-汇总数据-进度") + @RequestMapping(value = "/progress", method = RequestMethod.GET) + public ResponseResult progress(PressureResourceQueryRequest request) { + return ResponseResult.success(pressureResourceService.progress(request.getId())); + } +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureDsController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureDsController.java new file mode 100644 index 0000000000..fa8af35de9 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureDsController.java @@ -0,0 +1,92 @@ +package io.shulie.takin.web.entrypoint.controller.pressureresource; + +import io.shulie.takin.common.beans.response.ResponseResult; +import io.shulie.takin.web.biz.pojo.request.pressureresource.*; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceDsService; +import io.shulie.takin.web.biz.service.pressureresource.common.ModuleEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.SourceTypeEnum; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; + +/** + * 链路资源配置-数据源隔离 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:51 PM + */ +@RestController +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/pressureResource/ds") +@Api(tags = "接口: 数据源隔离") +@Slf4j +public class PressureResoureDsController { + private static Logger logger = LoggerFactory.getLogger(PressureResoureDsController.class); + + @Resource + private PressureResourceDsService pressureResourceDsService; + + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @ApiOperation("链路压测资源-数据源-新增") + @RequestMapping(value = "/create", method = RequestMethod.POST) + public ResponseResult create(@RequestBody PressureResourceRelateDsInput input) { + input.setType(SourceTypeEnum.MANUAL.getCode()); + pressureResourceDsService.add(input); + + CommandTaskVo taskVo = new CommandTaskVo(); + taskVo.setResourceId(input.getResourceId()); + taskVo.setModule(ModuleEnum.DS.getCode()); + pressureResourceCommonService.pushRedisCommand(taskVo); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-数据源视图") + @RequestMapping(value = "/listByDs", method = RequestMethod.GET) + public ResponseResult listByDs(PressureResourceRelateDsRequest request) { + return ResponseResult.success(pressureResourceDsService.listByDs(request)); + } + + @ApiOperation("链路压测资源-数据源-删除") + @RequestMapping(value = "/del", method = RequestMethod.GET) + public ResponseResult del(PressureResourceRelateDsInput input) { + pressureResourceDsService.del(input.getId()); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-应用视图") + @RequestMapping(value = "/listByApp", method = RequestMethod.GET) + public ResponseResult listByApp(PressureResourceRelateDsRequest request) { + return ResponseResult.success(pressureResourceDsService.listByApp(request)); + } + + @ApiOperation("链路压测资源-导入影子资源") + @RequestMapping(value = "/import", method = RequestMethod.POST) + public ResponseResult importDsConfig(@RequestParam MultipartFile file, @RequestParam Long resourceId) { + pressureResourceDsService.importDsConfig(file, resourceId); + + CommandTaskVo taskVo = new CommandTaskVo(); + taskVo.setResourceId(resourceId); + taskVo.setModule(ModuleEnum.DS.getCode()); + pressureResourceCommonService.pushRedisCommand(taskVo); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-导出影子资源") + @RequestMapping(value = "/export", method = RequestMethod.GET) + public ResponseResult exportDsConfig(HttpServletResponse response, Long resourceId) { + pressureResourceDsService.export(response, resourceId); + return ResponseResult.success(); + } +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureRemoteCallController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureRemoteCallController.java new file mode 100644 index 0000000000..4e0cbc16e5 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureRemoteCallController.java @@ -0,0 +1,59 @@ +package io.shulie.takin.web.entrypoint.controller.pressureresource; + +import io.shulie.takin.common.beans.response.ResponseResult; +import io.shulie.takin.web.biz.pojo.request.pressureresource.MockInfo; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceMockInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateRemoteCallRequest; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceRemoteCallService; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 链路资源配置-远程调用 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:51 PM + */ +@RestController +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/pressureResource/remotecall") +@Api(tags = "接口: 远程调用") +@Slf4j +public class PressureResoureRemoteCallController { + @Resource + private PressureResourceRemoteCallService pressureResourceRemoteCallService; + + @ApiOperation("链路压测资源-远程调用列表") + @RequestMapping(value = "/list", method = RequestMethod.GET) + public ResponseResult list(PressureResourceRelateRemoteCallRequest request) { + return ResponseResult.success(pressureResourceRemoteCallService.pageList(request)); + } + + @ApiOperation("链路压测资源-远程调用-update") + @RequestMapping(value = "/update", method = RequestMethod.POST) + public ResponseResult mock(@RequestBody PressureResourceMockInput input) { + pressureResourceRemoteCallService.update_v2(input); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-远程调用-平均响应时间") + @RequestMapping(value = "/config", method = RequestMethod.GET) + public ResponseResult config(PressureResourceRelateRemoteCallRequest input) { + return ResponseResult.success(pressureResourceRemoteCallService.mockDetail(input.getId())); + } + + @ApiOperation("链路压测资源-远程调用-校验脚本") + @RequestMapping(value = "/mockcheck", method = RequestMethod.POST) + public ResponseResult check(@RequestBody MockInfo input) { + return ResponseResult.success(pressureResourceRemoteCallService.check(input)); + } + +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureTableController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureTableController.java new file mode 100644 index 0000000000..169d9723fa --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/pressureresource/PressureResoureTableController.java @@ -0,0 +1,89 @@ +package io.shulie.takin.web.entrypoint.controller.pressureresource; + +import io.shulie.takin.common.beans.response.ResponseResult; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateTableInput; +import io.shulie.takin.web.biz.pojo.request.pressureresource.PressureResourceRelateTableRequest; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceCommonService; +import io.shulie.takin.web.biz.service.pressureresource.PressureResourceTableService; +import io.shulie.takin.web.biz.service.pressureresource.common.ModuleEnum; +import io.shulie.takin.web.biz.service.pressureresource.common.SourceTypeEnum; +import io.shulie.takin.web.biz.service.pressureresource.vo.CommandTaskVo; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 链路资源配置-影子表配置 + * + * @author xingchen + * @description: TODO + * @date 2022/8/30 2:51 PM + */ +@RestController +@RequestMapping(value = ApiUrls.TAKIN_API_URL + "/pressureResource/table") +@Api(tags = "接口: 关联表") +@Slf4j +public class PressureResoureTableController { + @Resource + private PressureResourceTableService pressureResourceTableService; + + @Resource + private PressureResourceCommonService pressureResourceCommonService; + + @ApiOperation("链路压测资源-影子表新增") + @RequestMapping(value = "/save", method = RequestMethod.POST) + public ResponseResult save(@RequestBody PressureResourceRelateTableInput input) { + input.setType(SourceTypeEnum.MANUAL.getCode()); + pressureResourceTableService.save_v2(input); + + CommandTaskVo taskVo = new CommandTaskVo(); + taskVo.setResourceId(input.getResourceId()); + taskVo.setModule(ModuleEnum.DS.getCode()); + pressureResourceCommonService.pushRedisCommand(taskVo); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-影子表列表") + @RequestMapping(value = "/list", method = RequestMethod.GET) + public ResponseResult list(PressureResourceRelateTableRequest request) { + return ResponseResult.success(pressureResourceTableService.pageList_v2(request)); + } + + @ApiOperation("链路压测资源-影子表-修改") + @RequestMapping(value = "/update", method = RequestMethod.POST) + public ResponseResult update(@RequestBody PressureResourceRelateTableInput input) { + pressureResourceTableService.update_v2(input); + + CommandTaskVo taskVo = new CommandTaskVo(); + taskVo.setResourceId(input.getResourceId()); + taskVo.setModule(ModuleEnum.DS.getCode()); + pressureResourceCommonService.pushRedisCommand(taskVo); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-影子表-修改加入状态") + @RequestMapping(value = "/batchUpdate", method = RequestMethod.POST) + public ResponseResult batchUpdate(@RequestBody PressureResourceRelateTableInput input) { + pressureResourceTableService.batchUpdate(input); + + CommandTaskVo taskVo = new CommandTaskVo(); + taskVo.setResourceId(input.getResourceId()); + taskVo.setModule(ModuleEnum.DS.getCode()); + pressureResourceCommonService.pushRedisCommand(taskVo); + return ResponseResult.success(); + } + + @ApiOperation("链路压测资源-影子表-删除") + @RequestMapping(value = "/del", method = RequestMethod.GET) + public ResponseResult del(PressureResourceRelateTableInput input) { + pressureResourceTableService.delete_v2(input.getId()); + return ResponseResult.success(); + } +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/scenemanage/SceneManageController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/scenemanage/SceneManageController.java index 4fd3486cd9..39bd21d5b0 100644 --- a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/scenemanage/SceneManageController.java +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/scenemanage/SceneManageController.java @@ -39,6 +39,7 @@ import io.shulie.takin.web.common.exception.TakinWebException; import io.shulie.takin.web.common.exception.TakinWebExceptionEnum; import io.shulie.takin.web.common.util.JsonUtil; +import io.shulie.takin.web.ext.util.WebPluginUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -252,7 +253,8 @@ public Response> getList(@ApiParam(name = "current", @ApiParam(name = "lastPtEndTime", value = "压测结束时间") String lastPtEndTime, @ApiParam(name = "recovery", value = "是否是回收站") Boolean recovery, @ApiParam(name = "source", value = "来源") Integer source, - @ApiParam(name = "configId", value = "单压测主键") Long configId + @ApiParam(name = "configId", value = "单压测主键") Long configId, + @ApiParam(name = "deptId", value = "部门id") Long deptId ) { SceneManageQueryVO queryVO = new SceneManageQueryVO(); @@ -264,6 +266,9 @@ public Response> getList(@ApiParam(name = "current", queryVO.setTagId(tagId); queryVO.setLastPtStartTime(lastPtStartTime); queryVO.setLastPtEndTime(lastPtEndTime); + queryVO.setDeptId(deptId); + queryVO.setUserIdList(WebPluginUtils.queryAllowUserIdList()); + queryVO.setDeptIdList(WebPluginUtils.queryAllowDeptIdList()); if(Objects.isNull(recovery)){ recovery = false; } diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/controller/TrafficRecorderController.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/controller/TrafficRecorderController.java new file mode 100644 index 0000000000..2dcae52674 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/controller/TrafficRecorderController.java @@ -0,0 +1,96 @@ +package io.shulie.takin.web.entrypoint.controller.traffic.recorder.controller; + +import io.shulie.takin.common.beans.annotation.ActionTypeEnum; +import io.shulie.takin.common.beans.annotation.AuthVerification; +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.common.beans.response.ResponseResult; +import io.shulie.takin.web.biz.constant.BizOpConstants; +import io.shulie.takin.web.common.constant.ApiUrls; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request.TrafficRecorderExportCsvRequest; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request.TrafficRecorderQueryRequest; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request.TrafficRecorderTaskConfigRequest; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.response.TrafficRecorderResponse; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.service.TrafficRecorderService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * @author chenxingxing + * @date 2023/2/7 10:57 上午 + */ +@RestController +@RequestMapping(ApiUrls.TAKIN_API_URL + "/traffic/recorder") +@Api(tags = "接口: 流量录制接口") +@Slf4j +public class TrafficRecorderController { + + @Resource + TrafficRecorderService trafficRecorderService; + + @GetMapping("/list") + @ApiOperation("分页查询流量记录") + public PagingList query(TrafficRecorderQueryRequest request) { + return trafficRecorderService.queryTrafficRecorder(request); + } + + + @GetMapping("/queryAppList") + @ApiOperation("分页查询流量记录") + public ResponseResult> queryAppList() { + List appList = new ArrayList<>(); + appList.add("servicebusiness_pro"); + appList.add("querybusiness_pro"); + appList.add("importantbusiness_pro"); + appList.add("call_esframework"); + appList.add("transactbusiness_pro"); + appList.add("logservice_pro"); + return ResponseResult.success(appList); + } + + @GetMapping("/queryServiceList") + @ApiOperation("分页查询流量记录") + public ResponseResult> queryServiceList(@RequestParam String appName) { + List serviceList = new ArrayList<>(); + serviceList.add("/servicebusiness/tingYun/queryTingYuPlatformSwitch"); + serviceList.add("/servicequerybusiness/operationservice/theFirstToRecommendForYou"); + serviceList.add("/serviceimportantbusiness/query/getPhoneByDetailTip.htm"); + serviceList.add("/serviceimportantbusiness/home/resourceQueryNew"); + serviceList.add("/servicetransactbusiness/query/flow/getCarefullyChosen"); + serviceList.add("/servicebusiness/onlineService/jumpNew"); + return ResponseResult.success(serviceList); + } + + @GetMapping("/createTask") + @ApiOperation("创建任务") + public ResponseResult createTask(TrafficRecorderTaskConfigRequest request) { + + //写入配置表 + Long taskId = 123L; + + return ResponseResult.success(taskId); + } + + + @GetMapping("/checkTaskStatus") + @ApiOperation("查询任务状态") + public ResponseResult checkTaskStatus(@RequestParam Long taskId) { + + return ResponseResult.success(); + } + + @GetMapping("/exportCsv") + @ApiOperation("导出csv") + public ResponseResult exportCsv(TrafficRecorderExportCsvRequest request) { + + return ResponseResult.success(); + } + + + +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderExportCsvRequest.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderExportCsvRequest.java new file mode 100644 index 0000000000..223d18774c --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderExportCsvRequest.java @@ -0,0 +1,34 @@ +package io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request; + +import io.shulie.takin.common.beans.page.PagingDevice; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +/** + * @author chenxingxing + * @date 2023/2/7 1:47 下午 + */ +@Data +@ApiModel(value = "TrafficRecorderResponse", description = "任务配置入参") +public class TrafficRecorderExportCsvRequest extends PagingDevice { + + @ApiModelProperty("应用名") + private String appName; + + @ApiModelProperty("请求服务名称") + private String ServiceName; + + @ApiModelProperty("中间件类型") + private Integer serviceType; + + @ApiModelProperty("请求类型") + private Integer kind; + + @ApiModelProperty("租户标识") + private String tenantCode; + + @ApiModelProperty("总大小") + private Integer size; +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderQueryRequest.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderQueryRequest.java new file mode 100644 index 0000000000..88959f8102 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderQueryRequest.java @@ -0,0 +1,35 @@ +package io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request; + +import io.shulie.takin.common.beans.page.PagingDevice; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author by: hezhongqi + * @Package io.shulie.takin.web.plugin.app.pojo.request.trace + * @ClassName: TraceLogQueryRequest + * @Description: TODO + * @Date: 2021/10/25 17:13 + */ +@Data +@ApiModel(value = "TrafficRecorderResponse", description = "流量录制入参") +public class TrafficRecorderQueryRequest extends PagingDevice { + + @ApiModelProperty("应用名") + private String appName; + + @ApiModelProperty("请求服务名称") + private String ServiceName; + + @ApiModelProperty("中间件类型") + private Integer serviceType; + + @ApiModelProperty("请求类型") + private Integer kind; + + @ApiModelProperty("租户标识") + private String tenantCode; + + +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderTaskConfigRequest.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderTaskConfigRequest.java new file mode 100644 index 0000000000..5e7a298e1c --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/request/TrafficRecorderTaskConfigRequest.java @@ -0,0 +1,40 @@ +package io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request; + + +import io.shulie.takin.common.beans.page.PagingDevice; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @author chenxingxing + * @date 2023/2/7 11:59 上午 + */ +@Data +@ApiModel(value = "TrafficRecorderResponse", description = "任务配置入参") +public class TrafficRecorderTaskConfigRequest extends PagingDevice { + + @ApiModelProperty("应用名") + private String appName; + + @ApiModelProperty("请求服务名称") + private String ServiceName; + + @ApiModelProperty("中间件类型") + private Integer serviceType; + + @ApiModelProperty("请求类型") + private Integer kind; + + @ApiModelProperty("租户标识") + private String tenantCode; + + @ApiModelProperty("录制起始时间") + private LocalDateTime recordBeginTime; + + @ApiModelProperty("录制结束时间") + private LocalDateTime recordEndTime; + +} \ No newline at end of file diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/response/TrafficRecorderResponse.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/response/TrafficRecorderResponse.java new file mode 100644 index 0000000000..8199f1f869 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/pojo/response/TrafficRecorderResponse.java @@ -0,0 +1,75 @@ +package io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.response; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author chenxingxing + * @date 2023/2/3 3:56 下午 + */ +@Data +@ApiModel(value = "TrafficRecorderResponse", description = "流量录制出参") +public class TrafficRecorderResponse { + + @ApiModelProperty("业务主键") + private Long id; + + @ApiModelProperty("租户编码") + private String tenantCode; + + @ApiModelProperty("应用名编码") + private String appName; + + @ApiModelProperty("请求服务名") + private String requestServiceName; + + @ApiModelProperty("请求服务地址") + private String requestAddress; + + @ApiModelProperty("机房:亦庄、西咸") + private String machineRoom; + + @ApiModelProperty("请求服务名") + private Integer serviceType; + + @ApiModelProperty("请求服务地址") + private Integer kind; + + @ApiModelProperty("请求头") + private Integer requestHeader; + + @ApiModelProperty("请求体") + private String requestBody; + + @ApiModelProperty("响应头") + private String responseHeader; + + @ApiModelProperty("响应体") + private String responseBody; + + @ApiModelProperty("清洗请求服务名") + private String cleanRequestServiceName; + + @ApiModelProperty("清洗请求地址") + private String cleanRequestAddress; + + @ApiModelProperty("清洗后的请求头") + private String cleanRequestHeader; + + @ApiModelProperty("清洗后的body体") + private String cleanRequestBody; + + @ApiModelProperty("清洗后的响应头") + private String cleanResponseHeader; + + @ApiModelProperty("清洗后的响应体") + private String cleanResponseBody; + + @ApiModelProperty("记录时间") + private String recordTime; + + @ApiModelProperty("创建时间") + private String gmtCreate; + +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/service/TrafficRecorderService.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/service/TrafficRecorderService.java new file mode 100644 index 0000000000..98799da7fc --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/service/TrafficRecorderService.java @@ -0,0 +1,15 @@ +package io.shulie.takin.web.entrypoint.controller.traffic.recorder.service; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request.TrafficRecorderQueryRequest; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.response.TrafficRecorderResponse; + + +/** + * @author chenxingxing + * @date 2023/2/3 3:05 下午 + */ +public interface TrafficRecorderService { + + PagingList queryTrafficRecorder(TrafficRecorderQueryRequest request); +} diff --git a/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/service/impl/TrafficRecorderServiceImpl.java b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/service/impl/TrafficRecorderServiceImpl.java new file mode 100644 index 0000000000..582b314e18 --- /dev/null +++ b/takin-web-entrypoint/src/main/java/io/shulie/takin/web/entrypoint/controller/traffic/recorder/service/impl/TrafficRecorderServiceImpl.java @@ -0,0 +1,24 @@ +package io.shulie.takin.web.entrypoint.controller.traffic.recorder.service.impl; + +import io.shulie.takin.common.beans.page.PagingList; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.request.TrafficRecorderQueryRequest; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.pojo.response.TrafficRecorderResponse; +import io.shulie.takin.web.entrypoint.controller.traffic.recorder.service.TrafficRecorderService; +import org.springframework.stereotype.Service; + +/** + * @author chenxingxing + * @date 2023/2/3 3:06 下午 + */ +@Service +public class TrafficRecorderServiceImpl implements TrafficRecorderService { + + @Override + public PagingList queryTrafficRecorder(TrafficRecorderQueryRequest request) { + // 1.获取当前租户,组装租户查询条件 + // 2.根据应用获取机房信息 + // 3.生成流量任务 + // 4.返回响应结果 + return null; + } +} diff --git a/takin-web-eventcenter/pom.xml b/takin-web-eventcenter/pom.xml index ae545a99e6..5413ae754d 100644 --- a/takin-web-eventcenter/pom.xml +++ b/takin-web-eventcenter/pom.xml @@ -5,7 +5,7 @@ takin-web io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 @@ -16,6 +16,12 @@ io.shulie.takin takin-common-utils + + + fastjson + com.alibaba + + diff --git a/takin-web-ext/pom.xml b/takin-web-ext/pom.xml index 329c34abcb..3181c5118b 100644 --- a/takin-web-ext/pom.xml +++ b/takin-web-ext/pom.xml @@ -5,12 +5,12 @@ takin-web io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 takin-web-ext - takin-web-5.9.0 + takin-web-5.10.2.2 pom takin-web-ext-api diff --git a/takin-web-ext/takin-web-ext-api/pom.xml b/takin-web-ext/takin-web-ext-api/pom.xml index c05ffa65ef..5a54217cba 100644 --- a/takin-web-ext/takin-web-ext-api/pom.xml +++ b/takin-web-ext/takin-web-ext-api/pom.xml @@ -5,20 +5,26 @@ takin-web-ext io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 takin-web-ext-api - takin-web-5.9.0 + takin-web-5.10.2.2 io.shulie.takin takin-common-utils provided + + + fastjson + com.alibaba + + org.projectlombok @@ -63,6 +69,11 @@ RELEASE compile + + com.alibaba + fastjson + ${fastjson.version} + diff --git a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebDataAuthExtApi.java b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebDataAuthExtApi.java index 45fb057907..05d74b51ad 100644 --- a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebDataAuthExtApi.java +++ b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebDataAuthExtApi.java @@ -10,39 +10,26 @@ * 数据权限,用于控制数据模块的权限 */ public interface WebDataAuthExtApi extends ExtensionPoint { - /** - * 获取查询权限用户 - * todo 后续废弃 - * - * @return - */ - List getQueryAllowUserIdList(); /** - * 获取更新权限用户 - * todo 后续废弃 - * + * 相关操作允许的用户id * @return */ - List getUpdateAllowUserIdList(); + List queryAllowUserIdList(); + List updateAllowUserIdList(); + List deleteAllowUserIdList(); + List enableDisableAllowUserIdList(); + List startStopAllowUserIdList(); + List downloadAllowUserIdList(); /** - * 获取删除权限用户 - * todo 后续废弃 - * + * 相关操作允许的部门id * @return */ - List getDeleteAllowUserIdList(); - - /** - * 获取启动关闭权限用户 - * todo 后续废弃 - * - * @return - */ - List getEnableDisableAllowUserIdList(); - - List getDownloadAllowUserIdList(); - - List getStartStopAllowUserIdList(); + List queryAllowDeptIdList(); + List updateAllowDeptIdList(); + List deleteAllowDeptIdList(); + List enableDisableAllowDeptIdList(); + List startStopAllowDeptIdList(); + List downloadAllowDeptIdList(); } diff --git a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebUserAuthExtApi.java b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebUserAuthExtApi.java index b60a8119cc..9a2c54b643 100644 --- a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebUserAuthExtApi.java +++ b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/auth/WebUserAuthExtApi.java @@ -15,4 +15,6 @@ public interface WebUserAuthExtApi extends ExtensionPoint { * @return - */ boolean validateAdmin(); + + boolean validateAgentAuth(String userAppKey, String tenantAppKey, String envCode, String userIdHeader, String agentExpand); } diff --git a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/user/WebUserExtApi.java b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/user/WebUserExtApi.java index 9a7470b239..d6e95736d9 100644 --- a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/user/WebUserExtApi.java +++ b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/api/user/WebUserExtApi.java @@ -67,6 +67,16 @@ public interface WebUserExtApi extends ExtensionPoint { */ Map getUserMapByIds(List userIds); + /** + * 根据用户ids 获取应用 + * 用于:查询用户数据 + * todo :或许想办法如何废弃 + * + * @param userIds - + * @return - + */ + Map getUserMap(List userIds); + /** * 查询所有用户 * 用于:初始化白名单文件 @@ -98,9 +108,9 @@ public interface WebUserExtApi extends ExtensionPoint { * @param traceContextExt 溯源数据对象 */ void setCloudUserData(ContextExt traceContextExt); - - Long getCustomerId(); - + + Long getCustomerId(); + /** * 获取系统个人信息 * @@ -136,8 +146,8 @@ public interface WebUserExtApi extends ExtensionPoint { * @return */ UserExt getUser(); - - /** + + /** * 获取登录用户 * * @return - @@ -179,6 +189,12 @@ public interface WebUserExtApi extends ExtensionPoint { */ Integer traceSource(); + /** + * 获取当前登录用户最低部门id + * @return + */ + Long traceDeptId(); + //********************************http线程上下文模块**********************************// /** diff --git a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/AuthQueryParamCommonExt.java b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/AuthQueryParamCommonExt.java index f90ed53317..72471ba2e1 100644 --- a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/AuthQueryParamCommonExt.java +++ b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/AuthQueryParamCommonExt.java @@ -14,5 +14,11 @@ @Data @EqualsAndHashCode(callSuper = true) public class AuthQueryParamCommonExt extends TenantCommonExt { + private List userIdList; + + /** + * 允许的id列表 + */ + private List deptIdList; } diff --git a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/UserCommonExt.java b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/UserCommonExt.java index 0f1f1c222d..b5c93ef497 100644 --- a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/UserCommonExt.java +++ b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/entity/UserCommonExt.java @@ -27,4 +27,10 @@ public class UserCommonExt extends TenantCommonExt { @ApiModelProperty(value = "客户Id") private Long customerId; + + @ApiModelProperty(value = "部门id") + private Long deptId; + + @ApiModelProperty(value = "部门名称") + private String deptName; } diff --git a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/util/WebPluginUtils.java b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/util/WebPluginUtils.java index 9634181e0c..d0564b557f 100644 --- a/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/util/WebPluginUtils.java +++ b/takin-web-ext/takin-web-ext-api/src/main/java/io/shulie/takin/web/ext/util/WebPluginUtils.java @@ -167,7 +167,7 @@ public static Map getUserMapByIds(List userIds) { userIds = userIds.stream().filter(Objects::nonNull) .distinct() .collect(Collectors.toList()); - Map userMap = userApi.getUserMapByIds(userIds); + Map userMap = userApi.getUserMap(userIds); if (null != userMap) { return userMap; } @@ -224,6 +224,13 @@ public static UserExt queryUserFromCache(String userAppKey) { return null; } + public static Long traceDeptId(){ + if (userApi != null) { + return userApi.traceDeptId(); + } + return null; + } + public static Class getClassByName(String className) { try { // 先扫描用户插件 @@ -253,34 +260,86 @@ public static List selectByName(String userName) { * * @return - */ - public static List getQueryAllowUserIdList() { + public static List queryAllowUserIdList() { + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.queryAllowUserIdList(); + } + return Lists.newArrayList(); + } + + public static List updateAllowUserIdList() { if (Objects.nonNull(dataAuthApi)) { - return dataAuthApi.getQueryAllowUserIdList(); + return dataAuthApi.updateAllowUserIdList(); } return Lists.newArrayList(); } - public static List getUpdateAllowUserIdList() { + public static List deleteAllowUserIdList() { if (Objects.nonNull(dataAuthApi)) { - return dataAuthApi.getUpdateAllowUserIdList(); + return dataAuthApi.deleteAllowUserIdList(); } return Lists.newArrayList(); } - public static List getDeleteAllowUserIdList() { + public static List enableDisableAllowUserIdList(){ if (Objects.nonNull(dataAuthApi)) { - return dataAuthApi.getDeleteAllowUserIdList(); + return dataAuthApi.enableDisableAllowUserIdList(); } return Lists.newArrayList(); } - public static List getDownloadAllowUserIdList() { + public static List startStopAllowUserIdList(){ + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.startStopAllowUserIdList(); + } + return Lists.newArrayList(); + } + + public static List downloadAllowUserIdList() { + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.downloadAllowUserIdList(); + } + return Lists.newArrayList(); + } + + public static List queryAllowDeptIdList(){ + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.queryAllowDeptIdList(); + } + return Lists.newArrayList(); + } + + public static List updateAllowDeptIdList(){ + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.updateAllowDeptIdList(); + } + return Lists.newArrayList(); + } + public static List deleteAllowDeptIdList(){ + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.deleteAllowDeptIdList(); + } + return Lists.newArrayList(); + } + public static List enableDisableAllowDeptIdList(){ + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.enableDisableAllowDeptIdList(); + } + return Lists.newArrayList(); + } + public static List startStopAllowDeptIdList(){ + if (Objects.nonNull(dataAuthApi)) { + return dataAuthApi.startStopAllowDeptIdList(); + } + return Lists.newArrayList(); + } + public static List downloadAllowDeptIdList(){ if (Objects.nonNull(dataAuthApi)) { - return dataAuthApi.getDownloadAllowUserIdList(); + return dataAuthApi.downloadAllowDeptIdList(); } return Lists.newArrayList(); } - + /** * 返回租户id * @@ -294,26 +353,19 @@ public static Long getCustomerId() { } return CUSTOMER_ID; } - - public static List getStartStopAllowUserIdList() { - if (Objects.nonNull(dataAuthApi)) { - return dataAuthApi.getStartStopAllowUserIdList(); - } - return Lists.newArrayList(); - } - public static List getEnableDisableAllowUserIdList() { + public static boolean validateAdmin() { if (Objects.nonNull(dataAuthApi)) { - return dataAuthApi.getEnableDisableAllowUserIdList(); + return userAuthExtApi.validateAdmin(); } - return Lists.newArrayList(); + return false; } - public static boolean validateAdmin() { + public static boolean validateAgentAuth(String userAppKey, String tenantAppKey, String envCode, String userIdHeader, String agentExpand){ if (Objects.nonNull(dataAuthApi)) { - return userAuthExtApi.validateAdmin(); + return userAuthExtApi.validateAgentAuth(userAppKey,tenantAppKey,envCode, userIdHeader,agentExpand); } - return false; + return true; } //********************************用户权限模块**********************************// @@ -732,6 +784,9 @@ public static TenantCommonExt traceTenantCommonExt() { ext.setEnvCode(traceEnvCode()); ext.setTenantAppKey(traceTenantAppKey()); ext.setTenantCode(traceTenantCode()); + if (userApi != null){ + ext.setSource(userApi.traceSource()); + } return ext; } //********************************http线程上下文模块**********************************// diff --git a/takin-web-ext/takin-web-ext-jmeter/pom.xml b/takin-web-ext/takin-web-ext-jmeter/pom.xml index 9698de4520..dfb7b3be50 100644 --- a/takin-web-ext/takin-web-ext-jmeter/pom.xml +++ b/takin-web-ext/takin-web-ext-jmeter/pom.xml @@ -5,13 +5,13 @@ takin-web-ext io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 takin-web-ext-jmeter - takin-web-5.9.0 + takin-web-5.10.2.2 UTF-8 @@ -64,6 +64,18 @@ org.apache.logging.log4j log4j-slf4j-impl + + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-1.2-api + @@ -77,5 +89,20 @@ rhino 1.7.14 + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-1.2-api + ${log4j.version} + diff --git a/takin-web-service-adapters/pom.xml b/takin-web-service-adapters/pom.xml index 05254ee92f..0bf4ef7419 100644 --- a/takin-web-service-adapters/pom.xml +++ b/takin-web-service-adapters/pom.xml @@ -20,7 +20,7 @@ takin-web io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 diff --git a/takin-web-service-adapters/takin-web-adapter/pom.xml b/takin-web-service-adapters/takin-web-adapter/pom.xml index 3e73cd9172..d33f2e7e04 100644 --- a/takin-web-service-adapters/takin-web-adapter/pom.xml +++ b/takin-web-service-adapters/takin-web-adapter/pom.xml @@ -5,7 +5,7 @@ takin-web-service-adapters io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/pom.xml b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/pom.xml index 5344b77b4a..d8240d4205 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/pom.xml +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/pom.xml @@ -5,7 +5,7 @@ takin-web-adapter io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/report/ReportQueryReq.java b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/report/ReportQueryReq.java index 426985465f..52583a4433 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/report/ReportQueryReq.java +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/report/ReportQueryReq.java @@ -6,6 +6,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.List; + /** * @author shiyajian * create: 2020-10-20 @@ -52,4 +54,9 @@ public class ReportQueryReq extends PagingContextExt { @ApiModelProperty(value = "报告类型") private Integer type; + private Long deptId; + + private List deptIds; + + private List userIds; } diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/scenemanage/SceneManageQueryReq.java b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/scenemanage/SceneManageQueryReq.java index 5bde24badb..8baa7d4661 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/scenemanage/SceneManageQueryReq.java +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/request/scenemanage/SceneManageQueryReq.java @@ -4,6 +4,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.List; + /** * @author 无涯 * @date 2020/10/22 8:07 下午 @@ -29,4 +31,9 @@ public class SceneManageQueryReq extends PagingContextExt { private Integer isArchive; + private Long deptId; + + private List userIdList; + + private List deptIdList; } diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/report/ReportResp.java b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/report/ReportResp.java index c19b132bd1..c71e9b27da 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/report/ReportResp.java +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/report/ReportResp.java @@ -51,4 +51,6 @@ public class ReportResp extends ContextExt { private Long scriptId; + private Long deptId; + } diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageListResp.java b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageListResp.java index e0cfbac045..e8793c7d6d 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageListResp.java +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageListResp.java @@ -44,4 +44,6 @@ public class SceneManageListResp extends ContextExt { @ApiModelProperty(value = "是否存在脚本解析结果") private Boolean hasAnalysisResult; + @ApiModelProperty(value = "部门id") + private Long deptId; } diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageWrapperResp.java b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageWrapperResp.java index 7e17d3312b..9d5bb16c84 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageWrapperResp.java +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-api/src/main/java/io/shulie/takin/adapter/api/model/response/scenemanage/SceneManageWrapperResp.java @@ -107,6 +107,8 @@ public class SceneManageWrapperResp extends ContextExt { @ApiModelProperty(name = "scheduleInterval", value = "漏数时间间隔") private Integer scheduleInterval; + private Long deptId; + @Data @EqualsAndHashCode(callSuper = true) public static class SceneBusinessActivityRefResp extends SceneBusinessActivityRefBean { diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/pom.xml b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/pom.xml index 28f3c299f4..96b84a1ba9 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/pom.xml +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/pom.xml @@ -5,7 +5,7 @@ takin-web-adapter io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 diff --git a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/src/main/java/io/shulie/takin/adapter/cloud/impl/scene/manage/CloudSceneManageApiImpl.java b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/src/main/java/io/shulie/takin/adapter/cloud/impl/scene/manage/CloudSceneManageApiImpl.java index 060de4c684..de7ba51fa9 100644 --- a/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/src/main/java/io/shulie/takin/adapter/cloud/impl/scene/manage/CloudSceneManageApiImpl.java +++ b/takin-web-service-adapters/takin-web-adapter/takin-web-adapter-cloud/src/main/java/io/shulie/takin/adapter/cloud/impl/scene/manage/CloudSceneManageApiImpl.java @@ -60,6 +60,7 @@ import io.shulie.takin.adapter.api.model.response.scenemanage.ScriptCheckResp; import io.shulie.takin.adapter.api.model.response.strategy.StrategyResp; import io.shulie.takin.utils.json.JsonHelper; +import io.shulie.takin.web.ext.util.WebPluginUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -100,6 +101,7 @@ public Long saveScene(SceneManageWrapperReq req) { SceneManageWrapperReq request = JsonHelper.json2Bean(JsonHelper.bean2Json(req), SceneManageWrapperReq.class); SceneManageWrapperInput input = new SceneManageWrapperInput(); dataModelConvert(request, input); + input.setDeptId(WebPluginUtils.traceDeptId()); return cloudSceneManageService.addSceneManage(input); } @@ -156,6 +158,9 @@ public ResponseResult> getSceneList(SceneManageQueryRe queryVO.setLastPtStartTime(req.getLastPtStartTime()); queryVO.setLastPtEndTime(req.getLastPtEndTime()); queryVO.setIsArchive(req.getIsArchive() == null?0:req.getIsArchive()); + queryVO.setDeptId(req.getDeptId()); + queryVO.setUserIdList(req.getUserIdList()); + queryVO.setDeptIdList(req.getDeptIdList()); PageInfo pageInfo = cloudSceneManageService.queryPageList(queryVO); // 转换 List list = pageInfo.getList().stream() diff --git a/takin-web-service-adapters/takin-web-config/pom.xml b/takin-web-service-adapters/takin-web-config/pom.xml index 6c3eb411b7..0278e41796 100644 --- a/takin-web-service-adapters/takin-web-config/pom.xml +++ b/takin-web-service-adapters/takin-web-config/pom.xml @@ -20,7 +20,7 @@ takin-web-service-adapters io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-common/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-common/pom.xml index 1d4021f9f2..7f900b9e4e 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-common/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-common/pom.xml @@ -20,7 +20,7 @@ takin-web-config io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-api/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-api/pom.xml index 6fd22d92af..037a6a40d5 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-api/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-api/pom.xml @@ -20,7 +20,7 @@ takin-web-config io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/pom.xml index 1423fccf2d..86a2581102 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/pom.xml @@ -20,7 +20,7 @@ takin-web-service-adapters io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../../pom.xml 4.0.0 diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-common/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-common/pom.xml index 53a9e6c57c..12e4fd9569 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-common/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-common/pom.xml @@ -20,7 +20,7 @@ takin-web-config-sync-http io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-impl/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-impl/pom.xml index 4e0145665b..47d69fb5c6 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-impl/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-http/takin-web-config-sync-http-impl/pom.xml @@ -5,7 +5,7 @@ takin-web-config-sync-http io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 @@ -28,6 +28,12 @@ io.shulie.takin takin-common-utils + + + fastjson + com.alibaba + + org.springframework diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/pom.xml index 165e90c2c0..f2343467de 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/pom.xml @@ -20,7 +20,7 @@ takin-web-config io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 takin-web-config-sync-zk diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-common/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-common/pom.xml index e73107aea8..dddd644cb3 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-common/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-common/pom.xml @@ -5,7 +5,7 @@ takin-web-config-sync-zk io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 diff --git a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-impl/pom.xml b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-impl/pom.xml index cdc0252851..5f1d75c9ca 100644 --- a/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-impl/pom.xml +++ b/takin-web-service-adapters/takin-web-config/takin-web-config-sync-zk/takin-web-config-sync-zk-impl/pom.xml @@ -20,7 +20,7 @@ takin-web-config-sync-zk io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 ../pom.xml 4.0.0 @@ -85,6 +85,12 @@ io.shulie.takin takin-common-utils + + + fastjson + com.alibaba + + diff --git a/takin-web-service-adapters/takin-web-diff/pom.xml b/takin-web-service-adapters/takin-web-diff/pom.xml index 8ada7395be..7df2072cb8 100644 --- a/takin-web-service-adapters/takin-web-diff/pom.xml +++ b/takin-web-service-adapters/takin-web-diff/pom.xml @@ -5,7 +5,7 @@ takin-web-service-adapters io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 pom diff --git a/takin-web-service-adapters/takin-web-diff/takin-web-diff-api/pom.xml b/takin-web-service-adapters/takin-web-diff/takin-web-diff-api/pom.xml index eaf835ffaa..9d418575ae 100644 --- a/takin-web-service-adapters/takin-web-diff/takin-web-diff-api/pom.xml +++ b/takin-web-service-adapters/takin-web-diff/takin-web-diff-api/pom.xml @@ -20,7 +20,7 @@ takin-web-diff io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 diff --git a/takin-web-service-adapters/takin-web-diff/takin-web-diff-cloud/pom.xml b/takin-web-service-adapters/takin-web-diff/takin-web-diff-cloud/pom.xml index 1a0c6464b5..156c568587 100644 --- a/takin-web-service-adapters/takin-web-diff/takin-web-diff-cloud/pom.xml +++ b/takin-web-service-adapters/takin-web-diff/takin-web-diff-cloud/pom.xml @@ -20,7 +20,7 @@ takin-web-diff io.shulie.takin - takin-web-5.9.0 + takin-web-5.10.2.2 4.0.0 takin-web-diff-cloud