Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
AppConfig 1.1.2 Updates (#630)
Browse files Browse the repository at this point in the history
* Updated to match 1.2.2

* Updated Feature Gate for 1.1.2

* Fixed pom file indentation
  • Loading branch information
mrm9084 authored Feb 25, 2020
1 parent 66624d3 commit d0a3181
Show file tree
Hide file tree
Showing 68 changed files with 1,603 additions and 672 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

<modules>
<module>spring-cloud-azure-appconfiguration-config</module>
<module>spring-cloud-azure-appconfiguration-config-web</module>
<module>spring-cloud-azure-autoconfigure</module>
<module>spring-cloud-azure-context</module>
<module>spring-cloud-azure-dependencies</module>
Expand Down
27 changes: 27 additions & 0 deletions spring-cloud-azure-appconfiguration-config-web/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-azure</artifactId>
<version>1.1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-cloud-azure-appconfiguration-config-web</artifactId>
<name>Spring Cloud Azure App Configuration Config Web</name>
<description>Integration of Spring Cloud Config and Azure App Configuration Service</description>

<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-azure-appconfiguration-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.spring.cloud.config.web;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.endpoint.RefreshEndpoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.microsoft.azure.spring.cloud.config.AppConfigurationRefresh;

@Configuration
public class AppConfigurationWebAutoConfiguration {

@Configuration
@ConditionalOnClass(RefreshEndpoint.class)
static class AppConfigurationWatchAutoConfiguration {

@Bean
public ConfigListener configListener(AppConfigurationRefresh appConfigurationRefresh) {
return new ConfigListener(appConfigurationRefresh);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.spring.cloud.config;
package com.microsoft.azure.spring.cloud.config.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.ServletRequestHandledEvent;

import com.microsoft.azure.spring.cloud.config.AppConfigurationRefresh;

@Component
public class ConfigListener implements ApplicationListener<ServletRequestHandledEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigListener.class);

private AzureCloudConfigRefresh azureCloudConfigRefresh;
private AppConfigurationRefresh appConfigurationRefresh;

public ConfigListener(AzureCloudConfigRefresh azureCloudConfigRefresh) {
this.azureCloudConfigRefresh = azureCloudConfigRefresh;
public ConfigListener(AppConfigurationRefresh appConfigurationRefresh) {
this.appConfigurationRefresh = appConfigurationRefresh;
}

@Override
public void onApplicationEvent(ServletRequestHandledEvent event) {
try {
azureCloudConfigRefresh.refreshConfigurations();
appConfigurationRefresh.refreshConfigurations();
} catch (Exception e) {
LOGGER.error("Refresh failed with unexpected exception.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.microsoft.azure.spring.cloud.config.web.AppConfigurationWebAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.spring.cloud.config.web;

import static com.microsoft.azure.spring.cloud.config.web.TestConstants.CONN_STRING_PROP;
import static com.microsoft.azure.spring.cloud.config.web.TestConstants.STORE_ENDPOINT_PROP;
import static com.microsoft.azure.spring.cloud.config.web.TestConstants.TEST_CONN_STRING;
import static com.microsoft.azure.spring.cloud.config.web.TestConstants.TEST_STORE_NAME;
import static com.microsoft.azure.spring.cloud.config.web.TestUtils.propPair;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import com.microsoft.azure.spring.cloud.config.AppConfigurationAutoConfiguration;
import com.microsoft.azure.spring.cloud.config.AppConfigurationBootstrapConfiguration;

public class AppConfigurationWebAutoConfigurationTest {
private static final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withPropertyValues(propPair(CONN_STRING_PROP, TEST_CONN_STRING),
propPair(STORE_ENDPOINT_PROP, TEST_STORE_NAME))
.withConfiguration(AutoConfigurations.of(AppConfigurationBootstrapConfiguration.class,
AppConfigurationAutoConfiguration.class, AppConfigurationWebAutoConfiguration.class));

@Test
public void watchEnabledNotConfiguredShouldNotCreateWatch() {
contextRunner.run(context -> {
assertThat(context).hasSingleBean(ConfigListener.class);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.spring.cloud.config.web;

/**
* Test constants which can be shared across different test classes
*/
public class TestConstants {
private TestConstants() {
}

// Store specific configuration
public static final String CONFIG_ENABLED_PROP = "spring.cloud.azure.appconfiguration.enabled";
public static final String CONN_STRING_PROP = "spring.cloud.azure.appconfiguration.stores[0].connection-string";
public static final String STORE_ENDPOINT_PROP = "spring.cloud.azure.appconfiguration.stores[0].endpoint";
public static final String TEST_CONN_STRING =
"Endpoint=https://fake.test.config.io;Id=fake-conn-id;Secret=ZmFrZS1jb25uLXNlY3JldA==";
public static final String TEST_STORE_NAME = "store1";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.spring.cloud.config.web;

import java.util.List;

import com.azure.data.appconfiguration.models.ConfigurationSetting;
import com.microsoft.azure.spring.cloud.config.AppConfigurationProperties;
import com.microsoft.azure.spring.cloud.config.stores.ConfigStore;

/**
* Utility methods which can be used across different test classes
*/
public class TestUtils {
private TestUtils() {
}

static String propPair(String propName, String propValue) {
return String.format("%s=%s", propName, propValue);
}

static ConfigurationSetting createItem(String context, String key, String value, String label, String contentType) {
ConfigurationSetting item = new ConfigurationSetting();
item.setKey(context + key);
item.setValue(value);
item.setLabel(label);
item.setContentType(contentType);

return item;
}

static void addStore(AppConfigurationProperties properties, String storeEndpoint, String connectionString) {
addStore(properties, storeEndpoint, connectionString, null);
}

static void addStore(AppConfigurationProperties properties, String storeEndpoint, String connectionString,
String label) {
List<ConfigStore> stores = properties.getStores();
ConfigStore store = new ConfigStore();
store.setConnectionString(connectionString);
store.setEndpoint(storeEndpoint);
store.setLabel(label);
stores.add(store);
properties.setStores(stores);
}
}
32 changes: 10 additions & 22 deletions spring-cloud-azure-appconfiguration-config/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-azure</artifactId>
Expand All @@ -20,31 +20,22 @@
<artifactId>spring-boot-autoconfigure-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand All @@ -57,10 +48,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-azure-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand All @@ -70,6 +57,7 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!--Azure Java SDK-->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@
import com.microsoft.azure.spring.cloud.config.stores.ClientStore;

@Configuration
@ConditionalOnProperty(prefix = AzureCloudConfigProperties.CONFIG_PREFIX, name = "enabled", matchIfMissing = true)
public class AzureCloudConfigAutoConfiguration {
@ConditionalOnProperty(prefix = AppConfigurationProperties.CONFIG_PREFIX, name = "enabled", matchIfMissing = true)
public class AppConfigurationAutoConfiguration {

@Configuration
@ConditionalOnClass(RefreshEndpoint.class)
static class CloudWatchAutoConfiguration {
static class AppConfigurationWatchAutoConfiguration {

@Bean
public AzureCloudConfigRefresh getConfigWatch(AzureCloudConfigProperties properties,
AzureConfigPropertySourceLocator sourceLocator, ClientStore clientStore) {
return new AzureCloudConfigRefresh(properties, sourceLocator.getStoreContextsMap(), clientStore);
}

@Bean
public ConfigListener configListener(AzureCloudConfigRefresh azureCloudConfigWatch) {
return new ConfigListener(azureCloudConfigWatch);
public AppConfigurationRefresh getConfigWatch(AppConfigurationProperties properties,
AppConfigurationPropertySourceLocator sourceLocator, ClientStore clientStore) {
return new AppConfigurationRefresh(properties, sourceLocator.getStoreContextsMap(), clientStore);
}
}
}
Loading

0 comments on commit d0a3181

Please sign in to comment.