feature(forest): 增加 forest 模块
为模块间的 HTTP 请求创建一个公共模块,集中模块间的互操作
This commit is contained in:
54
pom.xml
54
pom.xml
@@ -16,6 +16,7 @@
|
|||||||
<module>service-yarn-query</module>
|
<module>service-yarn-query</module>
|
||||||
<module>service-flink-query</module>
|
<module>service-flink-query</module>
|
||||||
<module>service-web</module>
|
<module>service-web</module>
|
||||||
|
<module>service-forest</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -23,8 +24,45 @@
|
|||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
|
<build-tag>b1e11</build-tag>
|
||||||
|
|
||||||
|
<spring-boot.version>2.6.8</spring-boot.version>
|
||||||
|
<spring-cloud.version>2021.0.3</spring-cloud.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>b1e1</id>
|
||||||
|
<properties>
|
||||||
|
<build-tag>b1e1</build-tag>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>b1e11</id>
|
||||||
|
<properties>
|
||||||
|
<build-tag>b1e11</build-tag>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>b2e1</id>
|
||||||
|
<properties>
|
||||||
|
<build-tag>b2e1</build-tag>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>b5s119</id>
|
||||||
|
<properties>
|
||||||
|
<build-tag>b5s119</build-tag>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>b2s119</id>
|
||||||
|
<properties>
|
||||||
|
<build-tag>b2s119</build-tag>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.eshore.odcp.hudi.connector</groupId>
|
<groupId>com.eshore.odcp.hudi.connector</groupId>
|
||||||
@@ -127,17 +165,27 @@
|
|||||||
<artifactId>pulsar-client-admin</artifactId>
|
<artifactId>pulsar-client-admin</artifactId>
|
||||||
<version>2.8.0</version>
|
<version>2.8.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.hadoop</groupId>
|
||||||
|
<artifactId>hadoop-client</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.hadoop</groupId>
|
||||||
|
<artifactId>hadoop-yarn-client</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
<version>2.6.8</version>
|
<version>${spring-boot.version}</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-dependencies</artifactId>
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
<version>2021.0.3</version>
|
<version>${spring-cloud.version}</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -150,7 +198,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<version>2.6.8</version>
|
<version>${spring-boot.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
|
|||||||
27
service-forest/pom.xml
Normal file
27
service-forest/pom.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
|
<artifactId>hudi-service</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>service-forest</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
|
<artifactId>service-configuration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.dtflys.forest</groupId>
|
||||||
|
<artifactId>forest-spring-boot-starter</artifactId>
|
||||||
|
<version>1.5.30</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.forest.configuration;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
|
import com.dtflys.forest.converter.json.ForestJacksonConverter;
|
||||||
|
import com.dtflys.forest.springboot.annotation.ForestScan;
|
||||||
|
import com.dtflys.forest.springboot.properties.ForestConfigurationProperties;
|
||||||
|
import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2023-04-24
|
||||||
|
*/
|
||||||
|
@ForestScan(basePackages = {
|
||||||
|
"com.lanyuanxiaoyao.service.forest.service"
|
||||||
|
})
|
||||||
|
@Configuration
|
||||||
|
public class ForestsConfiguration {
|
||||||
|
@Bean
|
||||||
|
public ForestJacksonConverter forestJacksonConverter() {
|
||||||
|
ForestJacksonConverter converter = new ForestJacksonConverter();
|
||||||
|
converter.getMapper().registerModule(new EclipseCollectionsModule());
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@Bean
|
||||||
|
public ForestConfigurationProperties forestConfigurationProperties() {
|
||||||
|
ForestConfigurationProperties properties = new ForestConfigurationProperties();
|
||||||
|
properties.setBackend("httpclient");
|
||||||
|
properties.setInterceptors(ListUtil.of(SpringCloudDiscoveryInterceptor.class));
|
||||||
|
properties.setLogEnabled(false);
|
||||||
|
properties.setTimeout(60000);
|
||||||
|
return properties;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.forest.configuration;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.core.util.URLUtil;
|
||||||
|
import com.dtflys.forest.auth.BasicAuth;
|
||||||
|
import com.dtflys.forest.http.ForestAddress;
|
||||||
|
import com.dtflys.forest.http.ForestRequest;
|
||||||
|
import com.dtflys.forest.interceptor.Interceptor;
|
||||||
|
import java.net.URL;
|
||||||
|
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.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2023-04-24
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class SpringCloudDiscoveryInterceptor implements Interceptor<Object> {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SpringCloudDiscoveryInterceptor.class);
|
||||||
|
|
||||||
|
private final DiscoveryClient client;
|
||||||
|
|
||||||
|
public SpringCloudDiscoveryInterceptor(DiscoveryClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean beforeExecute(ForestRequest request) {
|
||||||
|
// Load
|
||||||
|
URL url = URLUtil.url(request.getUrl());
|
||||||
|
String host = url.getHost();
|
||||||
|
if (StrUtil.isNotBlank(host)) {
|
||||||
|
ImmutableList<ServiceInstance> instances = Lists.immutable.ofAll(client.getInstances(host));
|
||||||
|
if (ObjectUtil.isNotEmpty(instances)) {
|
||||||
|
int index = RandomUtil.randomInt(instances.size());
|
||||||
|
ServiceInstance instance = instances.get(index);
|
||||||
|
request.setAddress(new ForestAddress(instance.getScheme(), instance.getHost(), instance.getPort()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basic auth
|
||||||
|
BasicAuth basicAuth = new BasicAuth("AxhEbscwsJDbYMH2", "cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4");
|
||||||
|
basicAuth.enhanceAuthorization(request);
|
||||||
|
|
||||||
|
return Interceptor.super.beforeExecute(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.forest.service;
|
||||||
|
|
||||||
|
import com.dtflys.forest.annotation.BaseRequest;
|
||||||
|
import com.dtflys.forest.annotation.ForestClient;
|
||||||
|
import com.dtflys.forest.annotation.Get;
|
||||||
|
import com.dtflys.forest.annotation.Query;
|
||||||
|
import com.eshore.odcp.hudi.connector.entity.FlinkJob;
|
||||||
|
import com.eshore.odcp.hudi.connector.entity.SyncState;
|
||||||
|
import com.eshore.odcp.hudi.connector.entity.TableMeta;
|
||||||
|
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
|
||||||
|
import com.lanyuanxiaoyao.service.configuration.entity.info.JobAndMetas;
|
||||||
|
import com.lanyuanxiaoyao.service.configuration.entity.info.JobIdAndAlias;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Info 接口
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2023-04-24
|
||||||
|
*/
|
||||||
|
@ForestClient
|
||||||
|
@BaseRequest(baseURL = "http://service-info-query")
|
||||||
|
public interface InfoService {
|
||||||
|
@Get("/info/job_id_alias")
|
||||||
|
PageResponse<JobIdAndAlias> jobIdAndAlias(@Query Map<String, Object> queryMap);
|
||||||
|
|
||||||
|
@Get("/info/job_metas")
|
||||||
|
ImmutableList<JobAndMetas> jobAndMetas();
|
||||||
|
|
||||||
|
@Get("/info/flink_job/list")
|
||||||
|
ImmutableList<FlinkJob> flinkJobList();
|
||||||
|
|
||||||
|
@Get("/info/flink_job/detail")
|
||||||
|
FlinkJob flinkJobDetail(@Query("flink_job_id") Long flinkJobId);
|
||||||
|
|
||||||
|
@Get("/info/table_meta/list")
|
||||||
|
ImmutableList<TableMeta> tableMetaList();
|
||||||
|
|
||||||
|
@Get("/info/table_meta/list")
|
||||||
|
ImmutableList<TableMeta> tableMetaList(@Query("flink_job_id") Long flinkJobId);
|
||||||
|
|
||||||
|
@Get("/info/table_meta/detail")
|
||||||
|
TableMeta tableMetaDetail(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);
|
||||||
|
|
||||||
|
@Get("/info/sync_state/detail")
|
||||||
|
SyncState syncStateDetail(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user