-
Notifications
You must be signed in to change notification settings - Fork 215
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
Spring Boot Cloud Config #1230
base: master
Are you sure you want to change the base?
Spring Boot Cloud Config #1230
Changes from all commits
37726c0
8e8b5fb
3b55b4c
c318d8b
3fb8cab
6724b46
49c1ab6
b6de0b8
3359473
b7e660e
653bb12
1169c54
f5fab34
852d459
29fa755
74e36d4
716ecb7
ffc43d3
186b1bb
15fefb1
a31ce67
70d4eea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>dapr-spring-parent</artifactId> | ||
<version>0.15.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dapr-spring-cloudconfig</artifactId> | ||
<name>dapr-spring-cloudconfig</name> | ||
<description>Dapr Spring Cloud Config</description> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>dapr-spring-boot-autoconfigure</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>dapr-spring-data</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>dapr-spring-messaging</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>dapr-spring-workflows</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.spotbugs</groupId> | ||
<artifactId>spotbugs-maven-plugin</artifactId> | ||
<version>4.8.2.0</version> | ||
<configuration> | ||
<excludeFilterFile>./spotbugs-exclude.xml</excludeFilterFile> | ||
<failOnError>${spotbugs.fail}</failOnError> | ||
<xmlOutput>true</xmlOutput> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>validate</id> | ||
<phase>validate</phase> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<FindBugsFilter> | ||
<Match> | ||
<Package name="~io\.dapr\.spring.*"/> | ||
<Bug pattern="EI_EXPOSE_REP"/> | ||
</Match> | ||
|
||
<Match> | ||
<Package name="~io\.dapr\.spring.*"/> | ||
<Bug pattern="EI_EXPOSE_REP2"/> | ||
</Match> | ||
<Match> | ||
<Class name="~io.dapr.spring.boot.cloudconfig.configdata.*"/> | ||
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/> | ||
</Match> | ||
<Match> | ||
<Class name="~io.dapr.spring.boot.cloudconfig.*"/> | ||
<Bug pattern="MS_EXPOSE_REP"/> | ||
</Match> | ||
</FindBugsFilter> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2025 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.spring.boot.cloudconfig.autoconfigure; | ||
|
||
import io.dapr.client.DaprClient; | ||
import io.dapr.spring.boot.cloudconfig.config.DaprCloudConfigProperties; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@EnableConfigurationProperties(DaprCloudConfigProperties.class) | ||
@ConditionalOnProperty(name = DaprCloudConfigProperties.PROPERTY_PREFIX + ".enabled", matchIfMissing = true) | ||
@ConditionalOnClass(DaprClient.class) | ||
public class DaprCloudConfigAutoConfiguration { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2025 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.spring.boot.cloudconfig.config; | ||
|
||
import io.dapr.spring.boot.autoconfigure.client.DaprClientProperties; | ||
import io.dapr.spring.boot.autoconfigure.client.DaprConnectionDetails; | ||
|
||
class CloudConfigPropertiesDaprConnectionDetails implements DaprConnectionDetails { | ||
|
||
private final DaprClientProperties daprClientProperties; | ||
|
||
public CloudConfigPropertiesDaprConnectionDetails(DaprClientProperties daprClientProperties) { | ||
this.daprClientProperties = daprClientProperties; | ||
} | ||
|
||
@Override | ||
public String httpEndpoint() { | ||
return this.daprClientProperties.getHttpEndpoint(); | ||
} | ||
|
||
@Override | ||
public String grpcEndpoint() { | ||
return this.daprClientProperties.getGrpcEndpoint(); | ||
} | ||
|
||
@Override | ||
public Integer httpPort() { | ||
return this.daprClientProperties.getHttpPort(); | ||
} | ||
|
||
@Override | ||
public Integer grpcPort() { | ||
return this.daprClientProperties.getGrpcPort(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2025 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.spring.boot.cloudconfig.config; | ||
|
||
import io.dapr.client.DaprClient; | ||
import io.dapr.client.DaprClientBuilder; | ||
import io.dapr.client.DaprPreviewClient; | ||
import io.dapr.config.Properties; | ||
import io.dapr.spring.boot.autoconfigure.client.DaprClientProperties; | ||
import io.dapr.spring.boot.autoconfigure.client.DaprConnectionDetails; | ||
|
||
public class DaprCloudConfigClientManager { | ||
|
||
private static DaprClient daprClient; | ||
private static DaprPreviewClient daprPreviewClient; | ||
private final DaprCloudConfigProperties daprCloudConfigProperties; | ||
private final DaprClientProperties daprClientConfig; | ||
|
||
/** | ||
* Create a DaprCloudConfigClientManager to create Config-Specific Dapr Client. | ||
* | ||
* @param daprCloudConfigProperties Properties of Dapr Cloud Config | ||
* @param daprClientConfig Properties of Dapr Client | ||
*/ | ||
public DaprCloudConfigClientManager(DaprCloudConfigProperties daprCloudConfigProperties, | ||
DaprClientProperties daprClientConfig) { | ||
this.daprCloudConfigProperties = daprCloudConfigProperties; | ||
this.daprClientConfig = daprClientConfig; | ||
|
||
DaprClientBuilder daprClientBuilder = createDaprClientBuilder( | ||
createDaprConnectionDetails(daprClientConfig) | ||
); | ||
|
||
if (DaprCloudConfigClientManager.daprClient == null) { | ||
DaprCloudConfigClientManager.daprClient = daprClientBuilder.build(); | ||
Check warning on line 46 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java
|
||
} | ||
|
||
if (DaprCloudConfigClientManager.daprPreviewClient == null) { | ||
DaprCloudConfigClientManager.daprPreviewClient = daprClientBuilder.buildPreviewClient(); | ||
} | ||
} | ||
|
||
public static DaprPreviewClient getDaprPreviewClient() { | ||
return DaprCloudConfigClientManager.daprPreviewClient; | ||
Check warning on line 55 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java
|
||
} | ||
|
||
public static DaprClient getDaprClient() { | ||
return DaprCloudConfigClientManager.daprClient; | ||
} | ||
|
||
private DaprConnectionDetails createDaprConnectionDetails(DaprClientProperties properties) { | ||
return new CloudConfigPropertiesDaprConnectionDetails(properties); | ||
} | ||
|
||
DaprClientBuilder createDaprClientBuilder(DaprConnectionDetails daprConnectionDetails) { | ||
DaprClientBuilder builder = new DaprClientBuilder(); | ||
if (daprConnectionDetails.httpEndpoint() != null) { | ||
builder.withPropertyOverride(Properties.HTTP_ENDPOINT, daprConnectionDetails.httpEndpoint()); | ||
Check warning on line 69 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java
|
||
} | ||
if (daprConnectionDetails.grpcEndpoint() != null) { | ||
builder.withPropertyOverride(Properties.GRPC_ENDPOINT, daprConnectionDetails.grpcEndpoint()); | ||
Check warning on line 72 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java
|
||
} | ||
if (daprConnectionDetails.httpPort() != null) { | ||
builder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprConnectionDetails.httpPort())); | ||
Check warning on line 75 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java
|
||
} | ||
if (daprConnectionDetails.grpcPort() != null) { | ||
builder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprConnectionDetails.grpcPort())); | ||
Check warning on line 78 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java
|
||
} | ||
return builder; | ||
} | ||
|
||
public DaprCloudConfigProperties getDaprCloudConfigProperties() { | ||
return daprCloudConfigProperties; | ||
} | ||
|
||
public DaprClientProperties getDaprClientConfig() { | ||
return daprClientConfig; | ||
Check warning on line 88 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2025 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.spring.boot.cloudconfig.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* The properties for creating dapr client. | ||
*/ | ||
@ConfigurationProperties(DaprCloudConfigProperties.PROPERTY_PREFIX) | ||
public class DaprCloudConfigProperties { | ||
lony2003 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static final String PROPERTY_PREFIX = "dapr.cloudconfig"; | ||
|
||
/** | ||
* whether enable cloud config. | ||
*/ | ||
private Boolean enabled = true; | ||
|
||
/** | ||
* whether enable dapr client wait for sidecar, if no response, will throw IOException. | ||
*/ | ||
private Boolean waitSidecarEnabled = false; | ||
|
||
/** | ||
* retries of dapr client wait for sidecar. | ||
*/ | ||
private Integer waitSidecarRetries = 3; | ||
|
||
/** | ||
* get config timeout (include wait for dapr sidecar). | ||
*/ | ||
private Integer timeout = 2000; | ||
|
||
public Integer getTimeout() { | ||
return timeout; | ||
} | ||
|
||
public void setTimeout(Integer timeout) { | ||
this.timeout = timeout; | ||
} | ||
Check warning on line 52 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigProperties.java
|
||
|
||
public Boolean getEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(Boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public Boolean getWaitSidecarEnabled() { | ||
return waitSidecarEnabled; | ||
} | ||
|
||
public void setWaitSidecarEnabled(Boolean waitSidecarEnabled) { | ||
this.waitSidecarEnabled = waitSidecarEnabled; | ||
} | ||
|
||
public Integer getWaitSidecarRetries() { | ||
return waitSidecarRetries; | ||
} | ||
|
||
public void setWaitSidecarRetries(Integer waitSidecarRetries) { | ||
this.waitSidecarRetries = waitSidecarRetries; | ||
} | ||
Check warning on line 76 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigProperties.java
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lony2003 do we need to duplicate the DaprConnectionDetails, why are these different for the normal DaprConnectionDetails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No difference, just because the PropertyDaprConnectionDetails is protected and can't be used in another package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artur-ciocanu should we change the
PropertyDaprConnectionDetails
visibility so it can be reused?