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

[All jobs done] Spring Boot Cloud Config #1230

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f19a5f8
style(springboot autoconfigure): use a PROPERTY_PREFIX instead of har…
lony2003 Mar 4, 2025
2b4022b
feat(springboot cloudconfig): A new library that implement a backend …
lony2003 Mar 4, 2025
0850990
Merge branch 'master' into development-cloudconfig
lony2003 Mar 5, 2025
6879d56
style(springboot cloudconfig): update file header
lony2003 Mar 5, 2025
736aaa2
style(springboot cloudconfig): change code style to match checkstyle
lony2003 Mar 5, 2025
02e3bbf
Merge branch 'master' into development-cloudconfig
lony2003 Mar 5, 2025
6303b5a
feat(springboot cloudconfig): Implement Configuration Cloud Config Im…
lony2003 Mar 6, 2025
781fbc1
Merge branch 'master' into development-cloudconfig
lony2003 Mar 6, 2025
c8c1958
fix(springboot cloudconfig): Update version of dapr-spring-parent
lony2003 Mar 6, 2025
33f1821
feat(springboot cloudconfig): test cases for cloud config
lony2003 Mar 7, 2025
7bb170d
fix(springboot cloudconfig): Fix problems of PropertySourceLoader
lony2003 Mar 7, 2025
1de8f47
Merge branch 'master' into development-cloudconfig
lony2003 Mar 7, 2025
1239f14
feat(springboot cloudconfig): Change the behavior of Config Type
lony2003 Mar 8, 2025
51bbffc
test(springboot cloudconfig): Implemented integration test for secret…
lony2003 Mar 8, 2025
802d0ec
Merge branch 'master' into development-cloudconfig
lony2003 Mar 8, 2025
034baad
test(springboot cloudconfig): fix integration test for secret and con…
lony2003 Mar 8, 2025
661f11e
docs(springboot cloudconfig): Write examples and docs for springboot …
lony2003 Mar 8, 2025
b2090a5
style(springboot cloudconfig): Clean comments
lony2003 Mar 10, 2025
e92ae51
docs(springboot cloudconfig): Fix typo of import
lony2003 Mar 10, 2025
41c6110
Merge branch 'master' into development-cloudconfig
lony2003 Mar 11, 2025
841b2f8
Merge branch 'master' into development-cloudconfig
lony2003 Mar 20, 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 @@ -16,8 +16,10 @@
import io.dapr.spring.data.DaprKeyValueAdapterResolver;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "dapr.client")
@ConfigurationProperties(prefix = DaprClientProperties.PROPERTY_PREFIX)
public class DaprClientProperties {
public static final String PROPERTY_PREFIX = "dapr.client";

private String httpEndpoint;
private String grpcEndpoint;
private Integer httpPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>dapr-spring-workflows</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-cloudconfig</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
79 changes: 79 additions & 0 deletions dapr-spring/dapr-spring-cloudconfig/pom.xml
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>
21 changes: 21 additions & 0 deletions dapr-spring/dapr-spring-cloudconfig/spotbugs-exclude.xml
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 {
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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?


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();
}

if (DaprCloudConfigClientManager.daprPreviewClient == null) {
DaprCloudConfigClientManager.daprPreviewClient = daprClientBuilder.buildPreviewClient();
}
}

public static DaprPreviewClient getDaprPreviewClient() {
return DaprCloudConfigClientManager.daprPreviewClient;
}

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());
}
if (daprConnectionDetails.grpcEndpoint() != null) {
builder.withPropertyOverride(Properties.GRPC_ENDPOINT, daprConnectionDetails.grpcEndpoint());
}
if (daprConnectionDetails.httpPort() != null) {
builder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprConnectionDetails.httpPort()));
}
if (daprConnectionDetails.grpcPort() != null) {
builder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprConnectionDetails.grpcPort()));
}
return builder;
}

public DaprCloudConfigProperties getDaprCloudConfigProperties() {
return daprCloudConfigProperties;
}

public DaprClientProperties getDaprClientConfig() {
return daprClientConfig;
}
}
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 {

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;
}

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;
}
}
Loading