From b82fc24f07a1b57606ca9d94a1e3843d4e89fdaf Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 14 Dec 2023 17:26:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(cloud-query):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1url=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/build-cloud-query.sh | 4 ++ pom.xml | 1 + .../src/main/resources/application.yml | 3 ++ service-cloud-query/pom.xml | 36 +++++++++++++ .../service/cloud/CloudController.java | 44 ++++++++++++++++ .../service/cloud/CloudQueryApplication.java | 29 +++++++++++ .../src/main/resources/application.yml | 5 ++ .../src/main/resources/logback-spring.xml | 51 +++++++++++++++++++ 8 files changed, 173 insertions(+) create mode 100755 bin/build-cloud-query.sh create mode 100644 service-cloud-query/pom.xml create mode 100644 service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java create mode 100644 service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudQueryApplication.java create mode 100644 service-cloud-query/src/main/resources/application.yml create mode 100644 service-cloud-query/src/main/resources/logback-spring.xml diff --git a/bin/build-cloud-query.sh b/bin/build-cloud-query.sh new file mode 100755 index 0000000..0739d83 --- /dev/null +++ b/bin/build-cloud-query.sh @@ -0,0 +1,4 @@ +#!/bin/bash +mvn -pl service-dependencies,service-configuration clean deploy -D skipTests -P local -s ~/.m2/settings-development.xml +mvn -pl service-cloud-query clean package spring-boot:repackage -D skipTests -s ~/.m2/settings-development.xml +ytp-transfer2 /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-cloud-query/target/service-cloud-query-1.0.0-SNAPSHOT.jar \ No newline at end of file diff --git a/pom.xml b/pom.xml index e037791..53aa2de 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,7 @@ service-loki-query service-test-query service-executor + service-cloud-query diff --git a/service-cli/service-cli-runner/src/main/resources/application.yml b/service-cli/service-cli-runner/src/main/resources/application.yml index 7388843..4ddf368 100644 --- a/service-cli/service-cli-runner/src/main/resources/application.yml +++ b/service-cli/service-cli-runner/src/main/resources/application.yml @@ -128,6 +128,9 @@ deploy: - name: service-flink-query source-jar: service-flink-query-1.0.0-SNAPSHOT.jar replicas: 10 + - name: service-cloud-query + source-jar: service-cloud-query-1.0.0-SNAPSHOT.jar + replicas: 5 - name: service-executor-manager source-jar: service-executor-manager-1.0.0-SNAPSHOT.jar replicas: 1 diff --git a/service-cloud-query/pom.xml b/service-cloud-query/pom.xml new file mode 100644 index 0000000..2c07405 --- /dev/null +++ b/service-cloud-query/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + com.lanyuanxiaoyao + hudi-service + 1.0.0-SNAPSHOT + + + service-cloud-query + + + + com.lanyuanxiaoyao + service-dependencies + 1.0.0-SNAPSHOT + + + com.lanyuanxiaoyao + service-configuration + 1.0.0-SNAPSHOT + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java new file mode 100644 index 0000000..0263b35 --- /dev/null +++ b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java @@ -0,0 +1,44 @@ +package com.lanyuanxiaoyao.service.cloud; + +import cn.hutool.core.util.StrUtil; +import java.util.List; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.ImmutableList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * 服务查询 + * + * @author lanyuanxiaoyao + * @date 2023-12-14 + */ +@RestController +@RequestMapping("cloud") +public class CloudController { + private static final Logger logger = LoggerFactory.getLogger(CloudQueryApplication.class); + + private final DiscoveryClient client; + + public CloudController(DiscoveryClient client) { + this.client = client; + } + + @GetMapping("services") + public ImmutableList infoQueryServices(@RequestParam("service_name") String serviceName) { + return Lists.immutable.ofAll(client.getServices()) + .select(name -> StrUtil.equals(name, serviceName)) + .flatCollect(name -> { + return Lists.immutable.ofAll(client.getInstances(name)) + .collect(instance -> instance.getUri().toString()); + }) + .toSortedList() + .toImmutable(); + } +} diff --git a/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudQueryApplication.java b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudQueryApplication.java new file mode 100644 index 0000000..b38d5e8 --- /dev/null +++ b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudQueryApplication.java @@ -0,0 +1,29 @@ +package com.lanyuanxiaoyao.service.cloud; + +import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.retry.annotation.EnableRetry; + +/** + * 启动类 + * + * @author lanyuanxiaoyao + * @date 2023-12-14 + */ +@EnableDiscoveryClient +@SpringBootApplication( + scanBasePackages = {"com.lanyuanxiaoyao.service"}, + exclude = {GsonAutoConfiguration.class} +) +@EnableConfigurationProperties +@EnableEncryptableProperties +@EnableRetry +public class CloudQueryApplication { + public static void main(String[] args) { + SpringApplication.run(CloudQueryApplication.class, args); + } +} diff --git a/service-cloud-query/src/main/resources/application.yml b/service-cloud-query/src/main/resources/application.yml new file mode 100644 index 0000000..08e3087 --- /dev/null +++ b/service-cloud-query/src/main/resources/application.yml @@ -0,0 +1,5 @@ +spring: + application: + name: service-cloud-query + profiles: + include: random-port,common,discovery,metrics \ No newline at end of file diff --git a/service-cloud-query/src/main/resources/logback-spring.xml b/service-cloud-query/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..f955921 --- /dev/null +++ b/service-cloud-query/src/main/resources/logback-spring.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + true + + ${LOKI_PUSH_URL:-http://localhost/loki/api/v1/push} + + + + + ${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} [${HOSTNAME}] ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} #@# : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}} + + true + + + + + + ${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}} + + + + + ${LOGGING_PARENT:-.}/${APP_NAME:-run}.log + + ${LOGGING_PARENT:-.}/archive/${APP_NAME:-run}-%d{yyyy-MM-dd}.gz + 7 + + + ${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} [${HOSTNAME}] ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} #@# : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}} + + + + + + + + + + + + \ No newline at end of file