diff --git a/bin/build-all.sh b/bin/build-all.sh index 9141cba..7df8d43 100644 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -1,9 +1,11 @@ #!/bin/bash mvn -pl service-dependencies,service-configuration,service-forest,service-executor,service-executor/service-executor-core clean source:jar deploy -D skipTests -P local -s ~/.m2/settings-development.xml +mvn -pl service-gateway clean package spring-boot:repackage -D skipTests -s ~/.m2/settings-development.xml mvn -pl service-flink-query,service-info-query,service-loki-query,service-pulsar-query,service-yarn-query,service-zookeeper-query,service-web clean package spring-boot:repackage -D skipTests -s ~/.m2/settings-development.xml -P b2b12 mvn -pl service-hudi-query,service-executor/service-executor-manager,service-executor/service-executor-task clean package -D skipTests -s ~/.m2/settings-development.xml -P b2b12 +ytp-transfer2 /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-gateway/target/service-gateway-1.0.0-SNAPSHOT.jar ytp-transfer2 /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-flink-query/target/service-flink-query-1.0.0-SNAPSHOT.jar ytp-transfer2 /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-hudi-query/target/service-hudi-query-1.0.0-SNAPSHOT.jar ytp-transfer2 /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-info-query/target/service-info-query-1.0.0-SNAPSHOT.jar diff --git a/bin/build-gateway.sh b/bin/build-gateway.sh new file mode 100755 index 0000000..2b51efc --- /dev/null +++ b/bin/build-gateway.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-gateway clean package spring-boot:repackage -D skipTests -s ~/.m2/settings-development.xml +ytp-transfer2 /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-gateway/target/service-gateway-1.0.0-SNAPSHOT.jar \ No newline at end of file diff --git a/pom.xml b/pom.xml index 47cd8cf..ba1e2fb 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,7 @@ pom service-configuration + service-gateway service-hudi-query service-info-query service-pulsar-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 acdd572..8af8d02 100644 --- a/service-cli/service-cli-runner/src/main/resources/application.yml +++ b/service-cli/service-cli-runner/src/main/resources/application.yml @@ -17,6 +17,8 @@ deploy: arguments: data_save_enable: true data_save_location: ${deploy.runtime.data-path} + - name: service-gateway + source-jar: service-gateway-1.0.0-SNAPSHOT.jar - name: service-scheduler source-jar: service-scheduler-1.0.0-SNAPSHOT.jar replicas: 1 diff --git a/service-gateway/pom.xml b/service-gateway/pom.xml new file mode 100644 index 0000000..d7a1412 --- /dev/null +++ b/service-gateway/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + com.lanyuanxiaoyao + hudi-service + 1.0.0-SNAPSHOT + + + service-gateway + + + + com.lanyuanxiaoyao + service-dependencies + 1.0.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-web + + + + + com.lanyuanxiaoyao + service-configuration + 1.0.0-SNAPSHOT + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + + + + org.apache.maven.plugins + maven-source-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/GatewayApplication.java b/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/GatewayApplication.java new file mode 100644 index 0000000..8054eb9 --- /dev/null +++ b/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/GatewayApplication.java @@ -0,0 +1,55 @@ +package com.lanyuanxiaoyao.service.gateway; + +import com.lanyuanxiaoyao.service.configuration.SecurityConfig; +import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; +import java.util.function.Function; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.gateway.route.Route; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.Buildable; +import org.springframework.cloud.gateway.route.builder.PredicateSpec; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; + +/** + * 启动类 + * + * @author lanyuanxiaoyao + * @date 2024-01-15 + */ +@EnableDiscoveryClient +@SpringBootApplication +@ComponentScan( + value = "com.lanyuanxiaoyao.service", + excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {SecurityConfig.class}) +) +@EnableConfigurationProperties +@EnableEncryptableProperties +public class GatewayApplication { + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } + + private Function> createRoute(String prefix, String target) { + return p -> p + .path(prefix + "/**") + .filters(filter -> filter.rewritePath("^" + prefix, "")) + .uri(target); + } + + @Bean + public RouteLocator routeLocator(RouteLocatorBuilder builder) { + return builder.routes() + .route("hudi", createRoute("/hudi_services/hudi_api", "lb://hudi-api")) + .route("queue", createRoute("/hudi_services/queue", "lb://center-queue")) + .route("scheduler", createRoute("/hudi_services/service_scheduler", "lb://service-scheduler")) + .route("web", createRoute("/hudi_services/service_web", "lb://service-web")) + .route("services", createRoute("/hudi_services/service_cloud_query", "lb://service-cloud-query")) + .build(); + } +} diff --git a/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/configuration/SecurityConfiguration.java b/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/configuration/SecurityConfiguration.java new file mode 100644 index 0000000..e9ca5e4 --- /dev/null +++ b/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/configuration/SecurityConfiguration.java @@ -0,0 +1,46 @@ +package com.lanyuanxiaoyao.service.gateway.configuration; + +import com.lanyuanxiaoyao.service.configuration.SecurityProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.web.server.SecurityWebFilterChain; + +/** + * web security + * + * @author lanyuanxiaoyao + * @date 2024-01-15 + */ +@Configuration +@EnableWebFluxSecurity +public class SecurityConfiguration { + @Bean + public SecurityWebFilterChain SecurityWebFilterChain(ServerHttpSecurity http) { + return http.authorizeExchange() + .pathMatchers("/actuator") + .authenticated() + .anyExchange() + .permitAll() + .and() + .httpBasic() + .and() + .csrf() + .disable() + .build(); + } + + @Bean + public MapReactiveUserDetailsService userDetailsService(SecurityProperties securityProperties) { + UserDetails user = User.builder() + .username(securityProperties.getUsername()) + .password("{noop}" + securityProperties.getDarkcode()) + .authorities(securityProperties.getAuthority()) + .build(); + return new MapReactiveUserDetailsService(user); + } +} diff --git a/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/configuration/WebConfiguration.java b/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/configuration/WebConfiguration.java new file mode 100644 index 0000000..1445af6 --- /dev/null +++ b/service-gateway/src/main/java/com/lanyuanxiaoyao/service/gateway/configuration/WebConfiguration.java @@ -0,0 +1,23 @@ +package com.lanyuanxiaoyao.service.gateway.configuration; + +import org.springframework.http.HttpHeaders; +import org.springframework.web.reactive.config.CorsRegistry; +import org.springframework.web.reactive.config.WebFluxConfigurer; + +/** + * web + * + * @author lanyuanxiaoyao + * @date 2024-01-15 + */ +public class WebConfiguration implements WebFluxConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowCredentials(true) + .allowedOriginPatterns("*") + .allowedHeaders("*") + .allowedMethods("*") + .exposedHeaders(HttpHeaders.SET_COOKIE); + } +} diff --git a/service-gateway/src/main/resources/application.yml b/service-gateway/src/main/resources/application.yml new file mode 100644 index 0000000..e4d3cb7 --- /dev/null +++ b/service-gateway/src/main/resources/application.yml @@ -0,0 +1,12 @@ +server: + port: 35690 +spring: + application: + name: service-gateway + profiles: + include: common,discovery,metrics + cloud: + gateway: + discovery: + locator: + enabled: true diff --git a/service-gateway/src/main/resources/logback-spring.xml b/service-gateway/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..9a06935 --- /dev/null +++ b/service-gateway/src/main/resources/logback-spring.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + 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 diff --git a/test/test.http b/test/test.http index d6110e5..21dc1d0 100644 --- a/test/test.http +++ b/test/test.http @@ -76,3 +76,6 @@ GET {{services-url}}/cloud/services?service_name=center-gateway-new ### Sync status GET {{web-url}}/overview/sync_running_status + +### +GET http://132.126.207.131:35690/hudi_services/service_web/pulsar/topic?pulsar_url=pulsar%3A%2F%2F132.122.113.167%3A16680%2C132.122.113.168%3A16680%2C132.122.113.171%3A16680%2C132.122.113.172%3A16680%2C132.122.115.163%3A16680%2C132.122.115.164%3A16680%2C132.122.115.165%3A16680%2C132.122.115.166%3A16680&topic=persistent%3A%2F%2Fodcp%2Fcrm_cfguse%2Fpriv_grant_his