feature(web): 迁移接口调用到 forest 公共模块
This commit is contained in:
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.lanyuanxiaoyao.service.web.service;
|
||||
|
||||
import com.dtflys.forest.annotation.BaseRequest;
|
||||
|
||||
/**
|
||||
* Yarn 信息
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2023-04-21
|
||||
*/
|
||||
@BaseRequest(baseURL = "http://service-yarn-query-b1e11")
|
||||
public interface CompactionYarnService extends YarnService {
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1,36 +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.lanyuanxiaoyao.service.configuration.entity.pulsar.PulsarNamespace;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.pulsar.PulsarTenant;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.pulsar.PulsarTopic;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
|
||||
/**
|
||||
* Pulsar
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2023-04-28
|
||||
*/
|
||||
@BaseRequest(baseURL = "http://service-pulsar-query")
|
||||
public interface PulsarService {
|
||||
@Get("/pulsar/name")
|
||||
String name(@Query("pulsar_url") String pulsarUrl);
|
||||
|
||||
@Get("/pulsar/names")
|
||||
ImmutableList<String> names();
|
||||
|
||||
@Get("/pulsar/tenants")
|
||||
ImmutableList<PulsarTenant> tenants(@Query("name") String name);
|
||||
|
||||
@Get("/pulsar/namespaces")
|
||||
ImmutableList<PulsarNamespace> namespaces(@Query("name") String name, @Query("tenant") String tenant);
|
||||
|
||||
@Get("/pulsar/topic")
|
||||
PulsarTopic topic(@Query("name") String name, @Query("topic") String topic);
|
||||
|
||||
@Get("/pulsar/topics")
|
||||
ImmutableList<PulsarTopic> topics(@Query("name") String name, @Query("namespace") String namespace);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.lanyuanxiaoyao.service.web.service;
|
||||
|
||||
import com.dtflys.forest.annotation.BaseRequest;
|
||||
|
||||
/**
|
||||
* Yarn 信息
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2023-04-21
|
||||
*/
|
||||
@BaseRequest(baseURL = "http://service-yarn-query-b2s119")
|
||||
public interface SyncYarnService extends YarnService {
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.lanyuanxiaoyao.service.web.service;
|
||||
|
||||
import com.dtflys.forest.annotation.Get;
|
||||
import com.dtflys.forest.annotation.Query;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2023-04-23
|
||||
*/
|
||||
public interface YarnService {
|
||||
@Get("/job/list")
|
||||
ImmutableList<YarnApplication> jobList();
|
||||
|
||||
@Get("/job/list")
|
||||
ImmutableList<YarnApplication> jobListEquals(@Query("name") String name);
|
||||
|
||||
@Get("/job/list")
|
||||
ImmutableList<YarnApplication> jobListLike(@Query("text") String text);
|
||||
|
||||
@Get("/job/kill")
|
||||
void jobKill(@Query("application_id") String applicationId);
|
||||
|
||||
@Get("/job/detail")
|
||||
YarnApplication jobDetail(@Query("application_id") String applicationId);
|
||||
|
||||
@Get("/queue/list")
|
||||
ImmutableList<YarnQueue> queueList();
|
||||
|
||||
@Get("/queue/detail")
|
||||
YarnQueue queueDetail(@Query("name") String name);
|
||||
|
||||
@Get("/cluster/info")
|
||||
YarnRootQueue cluster();
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user