Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:refactor] Optimize code for shenyu-spring-boot-starter #5873

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8db8f83
[type:refactor] Optimize code for shenyu-spring-boot-starter
po-168 Dec 30, 2024
5625d98
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Dec 31, 2024
2b5aaca
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Dec 31, 2024
2e66148
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 2, 2025
6c4c32f
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 2, 2025
b500adb
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 3, 2025
3e16b58
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 6, 2025
1354dee
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 9, 2025
0e632b2
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 13, 2025
0260989
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 14, 2025
f7da397
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 15, 2025
1d9213c
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 16, 2025
2809aff
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 17, 2025
4180145
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 18, 2025
8354483
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 18, 2025
743a426
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 20, 2025
0bf6fd7
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 21, 2025
a3bca5f
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 21, 2025
4d32aa4
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 22, 2025
5b35a8b
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 22, 2025
03f36a6
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 23, 2025
ac37229
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 24, 2025
c8fb60e
Merge branch 'master' into dev-shenyu-spring-boot-starter
Aias00 Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ShenyuClientConfig shenyuClientConfig() {
* @return the shenyu discovery config
*/
@Bean
@ConditionalOnProperty(prefix = "shenyu.discovery", name = "enable", matchIfMissing = false, havingValue = "true")
@ConditionalOnProperty(prefix = "shenyu.discovery", name = "enable", havingValue = "true")
@ConfigurationProperties(prefix = "shenyu.discovery")
public ShenyuDiscoveryConfig shenyuDiscoveryConfig() {
return new ShenyuDiscoveryConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.util.Objects;
import java.util.Properties;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ public GrpcClientEventListener grpcClientEventListener(final ShenyuClientConfig
ShenyuClientConfig.ClientPropertiesConfig clientPropertiesConfig = clientConfig.getClient().get(RpcTypeEnum.GRPC.getName());
Properties props = clientPropertiesConfig == null ? null : clientPropertiesConfig.getProps();
String discoveryMode = env.getProperty("shenyu.discovery.type", ShenyuClientConstants.DISCOVERY_LOCAL_MODE);
if (props != null) {
if (Objects.nonNull(props)) {
props.setProperty(ShenyuClientConstants.DISCOVERY_LOCAL_MODE_KEY, Boolean.valueOf(ShenyuClientConstants.DISCOVERY_LOCAL_MODE.equals(discoveryMode)).toString());
}
return new GrpcClientEventListener(clientConfig, shenyuClientRegisterRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shenyu.springboot.starter.client.springmvc;

import java.util.Objects;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.client.auto.config.ClientRegisterConfiguration;
Expand Down Expand Up @@ -70,7 +71,7 @@ public SpringMvcClientEventListener springHttpClientEventListener(final ShenyuCl
Properties props = Optional.ofNullable(clientPropertiesConfig).map(ClientPropertiesConfig::getProps).orElse(null);
String applicationName = env.getProperty("spring.application.name");
String discoveryMode = env.getProperty("shenyu.discovery.type", ShenyuClientConstants.DISCOVERY_LOCAL_MODE);
if (props != null) {
if (Objects.nonNull(props)) {
String appName = props.getProperty(ShenyuClientConstants.APP_NAME);
if (StringUtils.isBlank(appName) && StringUtils.isBlank(applicationName)) {
throw new IllegalArgumentException("spring.application.name or shenyu.client.http.props.appName must not be empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.netty.channel.ChannelOption;
import io.netty.channel.WriteBufferWaterMark;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.shenyu.common.config.NettyHttpProperties;
import org.apache.shenyu.common.exception.ShenyuException;
import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping;
Expand Down Expand Up @@ -95,16 +96,17 @@ public NettyReactiveWebServerFactory nettyReactiveWebServerFactory(final ObjectP
NettyHttpProperties.SniProperties sniProperties = nettyHttpProperties.getSni();
if (sniProperties.getEnabled()) {
ShenyuSniAsyncMapping shenyuSniAsyncMapping = shenyuSniAsyncMappingProvider.getIfAvailable();
if (shenyuSniAsyncMapping == null) {
if (Objects.isNull(shenyuSniAsyncMapping)) {
throw new ShenyuException("Can not find shenyuSniAsyncMapping bean");
}
if ("manual".equals(sniProperties.getMod())) {
if (sniProperties.getCertificates() == null || sniProperties.getCertificates().isEmpty()) {
List<SslCrtAndKeyFile> sslCrtAndKeyFiles = sniProperties.getCertificates();
if (CollectionUtils.isEmpty(sslCrtAndKeyFiles)) {
throw new ShenyuException("At least one certificate is required");
}

// Use the first certificate as the default certificate (this default certificate will not actually be used)
List<SslCrtAndKeyFile> certificates = sniProperties.getCertificates();
List<SslCrtAndKeyFile> certificates = sslCrtAndKeyFiles;
for (SslCrtAndKeyFile certificate : certificates) {
try {
shenyuSniAsyncMapping.addSslCertificate(certificate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.kubernetes.client.openapi.models.V1Service;
import io.kubernetes.client.openapi.models.V1ServiceList;
import io.kubernetes.client.util.generic.GenericKubernetesApi;
import org.apache.commons.collections4.MapUtils;
import org.apache.shenyu.common.config.NettyHttpProperties;
import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping;
import org.apache.shenyu.common.exception.ShenyuException;
Expand All @@ -55,6 +56,8 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -96,7 +99,6 @@ public Controller ingressController(final SharedInformerFactory sharedInformerFa
.build());
// TODO support config in application.yaml
builder.withWorkerCount(2);
// builder.withReadyFunc(ingressReconciler::informerReady);
return builder.withReconciler(ingressReconciler).withName("ingressController").build();
}

Expand Down Expand Up @@ -254,14 +256,15 @@ public SharedIndexInformer<V1Ingress> ingressInformer(final ApiClient apiClient,
public TcpSslContextSpec tcpSslContextSpec(final ObjectProvider<NettyHttpProperties> properties, final ApiClient apiClient) throws ApiException {
NettyHttpProperties nettyHttpProperties = Optional.ofNullable(properties.getIfAvailable()).orElse(new NettyHttpProperties());
NettyHttpProperties.SniProperties sniProperties = nettyHttpProperties.getSni();
if (sniProperties != null && sniProperties.getEnabled() && "k8s".equals(sniProperties.getMod())) {
if (Objects.nonNull(sniProperties) && sniProperties.getEnabled() && "k8s".equals(sniProperties.getMod())) {
String defaultName = Optional.ofNullable(sniProperties.getDefaultK8sSecretName()).orElse("default-ingress-crt");
String defaultNamespace = Optional.ofNullable(sniProperties.getDefaultK8sSecretNamespace()).orElse("default");
CoreV1Api coreV1Api = new CoreV1Api(apiClient);
V1Secret secret = coreV1Api.readNamespacedSecret(defaultName, defaultNamespace, "true");
if (secret.getData() != null) {
InputStream crtStream = new ByteArrayInputStream(secret.getData().get("tls.crt"));
InputStream keyStream = new ByteArrayInputStream(secret.getData().get("tls.key"));
Map<String, byte[]> secretData = secret.getData();
if (MapUtils.isEmpty(secretData)) {
InputStream crtStream = new ByteArrayInputStream(secretData.get("tls.crt"));
InputStream keyStream = new ByteArrayInputStream(secretData.get("tls.key"));
return TcpSslContextSpec.forServer(crtStream, keyStream);
} else {
throw new ShenyuException(String.format("Can not read cert and key from default secret %s/%s", defaultNamespace, defaultName));
Expand Down
Loading