feature(web): 迁移接口调用到 forest 公共模块

This commit is contained in:
2023-05-01 16:48:55 +08:00
parent 8731f641ea
commit 243e162917
19 changed files with 29 additions and 189 deletions

View File

@@ -1,5 +1,5 @@
#!/bin/bash
mvn -pl service-configuration clean deploy -D skipTests -P local -s ~/.m2/settings-development.xml
mvn -pl service-configuration,service-forest clean deploy -D skipTests -P local -s ~/.m2/settings-development.xml
mvn -pl service-web clean package spring-boot:repackage -D skipTests -s ~/.m2/settings-development.xml
sshpass -p $(/Users/lanyuanxiaoyao/Project/Work/Host/keepassxc-password.sh SSH/iap/132.122.1.162) scp /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-web/target/service-web-1.0.0-SNAPSHOT.jar iap@132.122.1.162:/apps/iap/tmp/lanyuanxiaoyao
sshpass -p $(/Users/lanyuanxiaoyao/Project/Work/Host/keepassxc-password.sh SSH/iap/132.122.1.162) ssh -o 'StrictHostKeyChecking no' iap@132.122.1.162 'curl ftp://yyy:QeY\!68\)4nH1@132.121.122.15:2222 -T /apps/iap/tmp/lanyuanxiaoyao/service-web-1.0.0-SNAPSHOT.jar'

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.web.service;
package com.lanyuanxiaoyao.service.forest.service;
import com.dtflys.forest.annotation.BaseRequest;

View File

@@ -1,7 +1,6 @@
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;
@@ -19,7 +18,6 @@ import org.eclipse.collections.api.list.ImmutableList;
* @author lanyuanxiaoyao
* @date 2023-04-24
*/
@ForestClient
@BaseRequest(baseURL = "http://service-info-query")
public interface InfoService {
@Get("/info/job_id_alias")

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.web.service;
package com.lanyuanxiaoyao.service.forest.service;
import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.Get;

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.web.service;
package com.lanyuanxiaoyao.service.forest.service;
import com.dtflys.forest.annotation.BaseRequest;

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.web.service;
package com.lanyuanxiaoyao.service.forest.service;
import com.dtflys.forest.annotation.Get;
import com.dtflys.forest.annotation.Query;

View File

@@ -17,6 +17,11 @@
<artifactId>service-configuration</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lanyuanxiaoyao</groupId>
<artifactId>service-forest</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId>

View File

@@ -1,14 +0,0 @@
package com.lanyuanxiaoyao.service.web.configuration;
import org.springframework.context.annotation.Configuration;
/**
* 登录设置
*
* @author lanyuanxiaoyao
* @date 2023-04-30
*/
@Configuration
public class LoginConfiguration {
}

View File

@@ -1,20 +0,0 @@
package com.lanyuanxiaoyao.service.web.configuration.forest;
import com.dtflys.forest.converter.json.ForestJacksonConverter;
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
*/
@Configuration
public class ForestsConfiguration {
@Bean
public ForestJacksonConverter forestJacksonConverter() {
ForestJacksonConverter converter = new ForestJacksonConverter();
converter.getMapper().registerModule(new EclipseCollectionsModule());
return converter;
}
}

View File

@@ -1,53 +0,0 @@
package com.lanyuanxiaoyao.service.web.configuration.forest;
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 java.util.List;
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 SringCloudDiscovryInterceptor implements Interceptor<Object> {
private static final Logger logger = LoggerFactory.getLogger(SringCloudDiscovryInterceptor.class);
private final DiscoveryClient client;
public SringCloudDiscovryInterceptor(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)) {
List<ServiceInstance> instances = 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);
}
}

View File

@@ -6,8 +6,8 @@ import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
import com.lanyuanxiaoyao.service.forest.service.YarnService;
import com.lanyuanxiaoyao.service.web.entity.YarnApplicationVO;
import com.lanyuanxiaoyao.service.web.service.YarnService;
import com.lanyuanxiaoyao.service.web.utils.ComparatorUtil;
import java.util.Comparator;
import java.util.Map;
@@ -26,6 +26,12 @@ import org.eclipse.collections.api.map.ImmutableMap;
public class BaseController {
private static final int SUCCESS_STATUS = 0;
private static final String SUCCESS_MESSAGE = "OK";
private static final ImmutableMap<String, Function<YarnApplication, Long>> SORT_MAP = Maps.immutable.of(
"startedTime",
YarnApplication::getStartedTime,
"finishedTime",
YarnApplication::getFinishedTime
);
protected AmisResponse responseData(Map<String, Object> data) {
return AmisResponse.builder()
@@ -70,13 +76,6 @@ public class BaseController {
.build();
}
private static final ImmutableMap<String, Function<YarnApplication, Long>> SORT_MAP = Maps.immutable.of(
"startedTime",
YarnApplication::getStartedTime,
"finishedTime",
YarnApplication::getFinishedTime
);
protected AmisResponse jobList(
YarnService yarnService,
Integer page,

View File

@@ -1,7 +1,7 @@
package com.lanyuanxiaoyao.service.web.controller;
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
import com.lanyuanxiaoyao.service.web.service.CompactionYarnService;
import com.lanyuanxiaoyao.service.forest.service.CompactionYarnService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;

View File

@@ -1,8 +1,8 @@
package com.lanyuanxiaoyao.service.web.controller;
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
import com.lanyuanxiaoyao.service.forest.service.PulsarService;
import com.lanyuanxiaoyao.service.web.entity.TopicVO;
import com.lanyuanxiaoyao.service.web.service.PulsarService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;

View File

@@ -1,7 +1,7 @@
package com.lanyuanxiaoyao.service.web.controller;
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
import com.lanyuanxiaoyao.service.web.service.SyncYarnService;
import com.lanyuanxiaoyao.service.forest.service.SyncYarnService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;

View File

@@ -8,11 +8,11 @@ import com.eshore.odcp.hudi.connector.entity.TableMeta;
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.info.JobIdAndAlias;
import com.lanyuanxiaoyao.service.forest.service.CompactionYarnService;
import com.lanyuanxiaoyao.service.forest.service.InfoService;
import com.lanyuanxiaoyao.service.forest.service.SyncYarnService;
import com.lanyuanxiaoyao.service.web.entity.SyncStateVO;
import com.lanyuanxiaoyao.service.web.entity.TableVO;
import com.lanyuanxiaoyao.service.web.service.CompactionYarnService;
import com.lanyuanxiaoyao.service.web.service.InfoService;
import com.lanyuanxiaoyao.service.web.service.SyncYarnService;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -39,7 +39,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("table")
public class TableController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(TableController.class);
private static final ExecutorService EXECUTOR = Executors.newWorkStealingPool(20);
private final InfoService infoService;
private final SyncYarnService syncYarnService;
private final CompactionYarnService compactionYarnService;
@@ -51,8 +51,6 @@ public class TableController extends BaseController {
this.compactionYarnService = compactionYarnService;
}
private static final ExecutorService EXECUTOR = Executors.newWorkStealingPool(20);
@GetMapping("list")
public AmisResponse list(
@RequestParam(value = "page", defaultValue = "1") Integer page,

View File

@@ -1,7 +1,6 @@
package com.lanyuanxiaoyao.service.web.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;

View File

@@ -15,11 +15,11 @@ public class TableVO {
private final String flinkJobId;
private final FlinkJob flinkJob;
private final TableMeta tableMeta;
private final SyncStateVO syncState;
private String syncJobName;
private YarnApplicationVO syncApp;
private String compactionJobName;
private YarnApplicationVO compactionApp;
private final SyncStateVO syncState;
public TableVO(FlinkJob flinkJob, TableMeta tableMeta, SyncStateVO syncState) {
this.flinkJobId = ObjectUtil.isNull(flinkJob) ? null : flinkJob.getId().toString();

View File

@@ -1,46 +0,0 @@
package com.lanyuanxiaoyao.service.web.service;
import com.dtflys.forest.annotation.BaseRequest;
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
*/
@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);
}

View File

@@ -1,35 +1,9 @@
server:
port: 38000
spring:
application:
name: service-web
main:
banner-mode: off
profiles:
include: common,eureka,metrics,forest
jackson:
serialization:
fail-on-empty-beans: false
default-property-inclusion: non_null
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
prometheus:
enabled: true
metrics:
export:
jmx:
enabled: false
eureka:
instance:
hostname: localhost
prefer-ip-address: true
instance-id: ${spring.application.name}-${eureka.instance.hostname}-${random.uuid}-${datetime}
client:
service-url:
defaultZone: http://localhost:35670/eureka/
forest:
interceptors: com.lanyuanxiaoyao.service.web.configuration.forest.SringCloudDiscovryInterceptor
log-enabled: false
timeout: 60000
server:
port: 38000