Remove @EnableAsync On Main (#822)

* Remove @EnableAsync and @EnableScheduling to avoid conflicts. (#817)

* Remove @EnableAsync and @EnableScheduling to avoid conflicts.  Fixes #780

* Remove @EnableAsync on main branch
This commit is contained in:
Ryan Baxter
2021-07-01 13:33:28 -04:00
committed by GitHub
parent 9914395049
commit 32a184404f
7 changed files with 88 additions and 32 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration;
import org.springframework.cloud.commons.util.TaskSchedulerWrapper;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.restart.RestartEndpoint;
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySource;
@@ -47,8 +48,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author Ryan Baxter
@@ -66,8 +65,6 @@ public class KubernetesClientConfigReloadAutoConfiguration {
*/
@ConditionalOnProperty("spring.cloud.kubernetes.reload.enabled")
@ConditionalOnClass({ RestartEndpoint.class, ContextRefresher.class })
@EnableScheduling
@EnableAsync
protected static class ConfigReloadAutoConfigurationBeans {
/**
@@ -83,10 +80,11 @@ public class KubernetesClientConfigReloadAutoConfiguration {
public ConfigurationChangeDetector configMapPropertyChangePollingWatcher(ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy,
KubernetesClientConfigMapPropertySourceLocator configMapPropertySourceLocator,
AbstractEnvironment environment) {
AbstractEnvironment environment, TaskSchedulerWrapper taskScheduler) {
return new PollingConfigMapChangeDetector(environment, properties, strategy,
KubernetesClientConfigMapPropertySource.class, configMapPropertySourceLocator);
KubernetesClientConfigMapPropertySource.class, configMapPropertySourceLocator,
taskScheduler.getTaskScheduler());
}
/**
@@ -102,10 +100,11 @@ public class KubernetesClientConfigReloadAutoConfiguration {
public ConfigurationChangeDetector secretsPropertyChangePollingWatcher(ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy,
KubernetesClientSecretsPropertySourceLocator secretsPropertySourceLocator,
AbstractEnvironment environment) {
AbstractEnvironment environment, TaskSchedulerWrapper taskScheduler) {
return new PollingSecretsChangeDetector(environment, properties, strategy,
KubernetesClientSecretsPropertySource.class, secretsPropertySourceLocator);
KubernetesClientSecretsPropertySource.class, secretsPropertySourceLocator,
taskScheduler.getTaskScheduler());
}
/**

View File

@@ -27,12 +27,14 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration;
import org.springframework.cloud.commons.util.TaskSchedulerWrapper;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.restart.RestartEndpoint;
import org.springframework.cloud.kubernetes.commons.config.ConditionalOnKubernetesAndConfigEnabled;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.Assert;
/**
@@ -52,6 +54,17 @@ public class ConfigReloadAutoConfiguration {
@ConditionalOnClass({ RestartEndpoint.class, ContextRefresher.class })
protected static class ConfigReloadAutoConfigurationBeans {
@Bean("springCloudKubernetesTaskScheduler")
@ConditionalOnMissingBean
public TaskSchedulerWrapper taskScheduler() {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setThreadNamePrefix("spring-cloud-kubernetes-ThreadPoolTaskScheduler-");
threadPoolTaskScheduler.setDaemon(true);
return new TaskSchedulerWrapper(threadPoolTaskScheduler);
}
/**
* @param properties config reload properties
* @param ctx application context

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.kubernetes.commons.config.reload;
import java.time.Duration;
import java.util.List;
import javax.annotation.PostConstruct;
@@ -23,10 +24,12 @@ import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.task.TaskSchedulerBuilder;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.PeriodicTrigger;
/**
* A change detector that periodically retrieves configmaps and fire a reload when
@@ -44,21 +47,38 @@ public class PollingConfigMapChangeDetector extends ConfigurationChangeDetector
private Class propertySourceClass;
private TaskScheduler taskExecutor;
private Duration period = Duration.ofMillis(1500);
@Deprecated
public PollingConfigMapChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.propertySourceClass = propertySourceClass;
this.taskExecutor = new TaskSchedulerBuilder().build();
}
public PollingConfigMapChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator, TaskScheduler taskExecutor) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.propertySourceClass = propertySourceClass;
this.taskExecutor = taskExecutor;
this.period = properties.getPeriod();
}
@PostConstruct
public void init() {
this.log.info("Kubernetes polling configMap change detector activated");
PeriodicTrigger trigger = new PeriodicTrigger(period.toMillis());
trigger.setInitialDelay(period.toMillis());
taskExecutor.schedule(this::executeCycle, trigger);
}
@Scheduled(initialDelayString = "${spring.cloud.kubernetes.reload.period:15000}",
fixedDelayString = "${spring.cloud.kubernetes.reload.period:15000}")
public void executeCycle() {
boolean changedConfigMap = false;

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.kubernetes.commons.config.reload;
import java.time.Duration;
import java.util.List;
import javax.annotation.PostConstruct;
@@ -23,10 +24,12 @@ import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.task.TaskSchedulerBuilder;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.PeriodicTrigger;
/**
* A change detector that periodically retrieves secrets and fire a reload when something
@@ -44,21 +47,38 @@ public class PollingSecretsChangeDetector extends ConfigurationChangeDetector {
private Class propertySourceClass;
private TaskScheduler taskExecutor;
private Duration period = Duration.ofMillis(1500);
@Deprecated
public PollingSecretsChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator) {
super(environment, properties, strategy);
this.propertySourceClass = propertySourceClass;
this.propertySourceLocator = propertySourceLocator;
this.taskExecutor = new TaskSchedulerBuilder().build();
}
public PollingSecretsChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator, TaskScheduler taskExecutor) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.propertySourceClass = propertySourceClass;
this.taskExecutor = taskExecutor;
this.period = properties.getPeriod();
}
@PostConstruct
public void init() {
this.log.info("Kubernetes polling secrets change detector activated");
PeriodicTrigger trigger = new PeriodicTrigger(period.toMillis());
trigger.setInitialDelay(period.toMillis());
taskExecutor.schedule(this::executeCycle, trigger);
}
@Scheduled(initialDelayString = "${spring.cloud.kubernetes.reload.period:15000}",
fixedDelayString = "${spring.cloud.kubernetes.reload.period:15000}")
public void executeCycle() {
boolean changedSecrets = false;

View File

@@ -50,7 +50,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
@@ -60,7 +59,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>

View File

@@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration;
import org.springframework.cloud.commons.util.TaskSchedulerWrapper;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.restart.RestartEndpoint;
import org.springframework.cloud.kubernetes.commons.config.ConditionalOnKubernetesAndConfigEnabled;
@@ -50,8 +51,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.Assert;
/**
@@ -73,8 +72,6 @@ public class ConfigReloadAutoConfiguration {
*/
@ConditionalOnProperty("spring.cloud.kubernetes.reload.enabled")
@ConditionalOnClass({ RestartEndpoint.class, ContextRefresher.class })
@EnableScheduling
@EnableAsync
protected static class ConfigReloadAutoConfigurationBeans {
@Autowired
@@ -95,10 +92,12 @@ public class ConfigReloadAutoConfiguration {
@Conditional(PollingReloadDetectionMode.class)
public ConfigurationChangeDetector configMapPropertyChangePollingWatcher(ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy,
Fabric8ConfigMapPropertySourceLocator fabric8ConfigMapPropertySourceLocator) {
Fabric8ConfigMapPropertySourceLocator fabric8ConfigMapPropertySourceLocator,
TaskSchedulerWrapper taskSchedulerWrapper) {
return new PollingConfigMapChangeDetector(this.environment, properties, strategy,
Fabric8ConfigMapPropertySource.class, fabric8ConfigMapPropertySourceLocator);
Fabric8ConfigMapPropertySource.class, fabric8ConfigMapPropertySourceLocator,
taskSchedulerWrapper.getTaskScheduler());
}
/**
@@ -113,10 +112,12 @@ public class ConfigReloadAutoConfiguration {
@Conditional(PollingReloadDetectionMode.class)
public ConfigurationChangeDetector secretsPropertyChangePollingWatcher(ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy,
Fabric8SecretsPropertySourceLocator fabric8SecretsPropertySourceLocator) {
Fabric8SecretsPropertySourceLocator fabric8SecretsPropertySourceLocator,
TaskSchedulerWrapper taskScheduler) {
return new PollingSecretsChangeDetector(this.environment, properties, strategy,
Fabric8SecretsPropertySource.class, fabric8SecretsPropertySourceLocator);
Fabric8SecretsPropertySource.class, fabric8SecretsPropertySourceLocator,
taskScheduler.getTaskScheduler());
}
/**

View File

@@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.commons.util.TaskSchedulerWrapper;
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationChangeDetector;
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
@@ -41,8 +42,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author Ryan Baxter
@@ -58,8 +57,6 @@ public class ConfigReloadDefaultAutoConfiguration {
* Configuration reload must be enabled explicitly.
*/
@ConditionalOnProperty("spring.cloud.kubernetes.reload.enabled")
@EnableScheduling
@EnableAsync
protected static class ConfigReloadAutoConfigurationBeans {
@Autowired
@@ -95,10 +92,12 @@ public class ConfigReloadDefaultAutoConfiguration {
@Conditional(PollingReloadDetectionMode.class)
public ConfigurationChangeDetector configMapPropertyChangePollingWatcher(ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy,
Fabric8ConfigMapPropertySourceLocator fabric8ConfigMapPropertySourceLocator) {
Fabric8ConfigMapPropertySourceLocator fabric8ConfigMapPropertySourceLocator,
TaskSchedulerWrapper taskSchedulerWrapper) {
return new PollingConfigMapChangeDetector(this.environment, properties, strategy,
Fabric8ConfigMapPropertySource.class, fabric8ConfigMapPropertySourceLocator);
Fabric8ConfigMapPropertySource.class, fabric8ConfigMapPropertySourceLocator,
taskSchedulerWrapper.getTaskScheduler());
}
/**
@@ -113,10 +112,12 @@ public class ConfigReloadDefaultAutoConfiguration {
@Conditional(PollingReloadDetectionMode.class)
public ConfigurationChangeDetector secretsPropertyChangePollingWatcher(ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy,
Fabric8SecretsPropertySourceLocator fabric8SecretsPropertySourceLocator) {
Fabric8SecretsPropertySourceLocator fabric8SecretsPropertySourceLocator,
TaskSchedulerWrapper taskScheduler) {
return new PollingSecretsChangeDetector(this.environment, properties, strategy,
Fabric8SecretsPropertySource.class, fabric8SecretsPropertySourceLocator);
Fabric8SecretsPropertySource.class, fabric8SecretsPropertySourceLocator,
taskScheduler.getTaskScheduler());
}
/**