feat(exporter): 提供exporter项目专注于提供外部访问接口

单独使用exporter项目提供外部接口可以方便针对外部接口进行管理,比如加入更强的安全认证
This commit is contained in:
2024-02-02 20:49:53 +08:00
parent 7c9ba2876f
commit 02f22070fd
10 changed files with 221 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package com.lanyuanxiaoyao.service.exporter;
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.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.retry.annotation.EnableRetry;
/**
* 启动类
*
* @author lanyuanxiaoyao
* @date 2023-04-30
*/
@EnableDiscoveryClient
@SpringBootApplication(
scanBasePackages = {"com.lanyuanxiaoyao.service"},
exclude = {
GsonAutoConfiguration.class,
DataSourceAutoConfiguration.class
}
)
@EnableConfigurationProperties
@EnableEncryptableProperties
@EnableRetry
public class ExporterApplication {
public static void main(String[] args) {
SpringApplication.run(ExporterApplication.class, args);
}
}

View File

@@ -0,0 +1,46 @@
package com.lanyuanxiaoyao.service.exporter.controller;
import com.eshore.odcp.hudi.connector.utils.NameHelper;
import com.lanyuanxiaoyao.service.configuration.entity.zookeeper.ZookeeperNode;
import com.lanyuanxiaoyao.service.exporter.entity.FlinkJobIdAndName;
import com.lanyuanxiaoyao.service.forest.service.InfoService;
import com.lanyuanxiaoyao.service.forest.service.ZookeeperService;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 出口
*
* @author lanyuanxiaoyao
* @date 2024-02-02
*/
@RestController
@RequestMapping("exporter")
@CacheConfig(cacheManager = "normal-cache")
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public class ExporterController {
private static final Logger logger = LoggerFactory.getLogger(ExporterController.class);
private final InfoService infoService;
private final ZookeeperService zookeeperService;
public ExporterController(InfoService infoService, ZookeeperService zookeeperService) {
this.infoService = infoService;
this.zookeeperService = zookeeperService;
}
@GetMapping("un_running_flink_job")
@Cacheable(value = "un_running_flink_job", sync = true)
public ImmutableList<FlinkJobIdAndName> unRunningFlinkJob() {
ImmutableList<String> locks = zookeeperService.getChildren(NameHelper.ZK_SYNC_RUNNING_LOCK_PATH).collect(ZookeeperNode::getPath);
return infoService.flinkJobList()
.reject(job -> locks.contains(NameHelper.syncFlinkName(job.getId(), job.getName())))
.collect(job -> new FlinkJobIdAndName(job.getId(), job.getName()));
}
}

View File

@@ -0,0 +1,31 @@
package com.lanyuanxiaoyao.service.exporter.entity;
/**
* @author lanyuanxiaoyao
* @date 2024-02-02
*/
public class FlinkJobIdAndName {
private final Long id;
private final String name;
public FlinkJobIdAndName(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "FlinkJobIdAndName{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

View File

@@ -0,0 +1,5 @@
spring:
application:
name: service-exporter
profiles:
include: random-port,common,discovery,metrics,forest

View File

@@ -0,0 +1,52 @@
<configuration>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<springProperty scope="context" name="LOKI_PUSH_URL" source="loki.url"/>
<springProperty scope="context" name="LOGGING_PARENT" source="logging.parent"/>
<springProperty scope="context" name="APP_NAME" source="spring.application.name"/>
<appender name="Loki" class="com.github.loki4j.logback.Loki4jAppender">
<metricsEnabled>true</metricsEnabled>
<http class="com.github.loki4j.logback.ApacheHttpSender">
<url>${LOKI_PUSH_URL:-http://localhost/loki/api/v1/push}</url>
</http>
<format>
<label>
<pattern>app=${APP_NAME:-none},host=${HOSTNAME:-none},level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [${HOSTNAME}] [%t] %logger #@# %m%n%wEx</pattern>
</message>
<sortByTime>true</sortByTime>
</format>
</appender>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(%5p) %clr([${HOSTNAME}]){yellow} %clr([%t]){magenta} %clr(%logger{40}){cyan} #@# %m%n%wEx</pattern>
</encoder>
</appender>
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGGING_PARENT:-.}/${APP_NAME:-run}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGGING_PARENT:-.}/archive/${APP_NAME:-run}-%d{yyyy-MM-dd}.gz</fileNamePattern>
<MaxHistory>7</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [${HOSTNAME}] [%t] %logger #@# %m%n%wEx</pattern>
</encoder>
</appender>
<logger name="com.zaxxer.hikari" level="ERROR"/>
<logger name="com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver" level="WARN"/>
<root level="INFO">
<appender-ref ref="Loki"/>
<appender-ref ref="Console"/>
<appender-ref ref="RollingFile"/>
</root>
</configuration>