From 77ff216786e0507f09169f9cd349c557657dd5cf Mon Sep 17 00:00:00 2001 From: Rob Zienert Date: Tue, 19 Sep 2017 15:48:39 -0700 Subject: [PATCH] fix(queue): Fix stupid spring wiring (#1628) --- .../config/RedisQueueShovelConfiguration.kt | 19 ++++++++++++------- .../orca/q/metrics/AtlasQueueMonitor.kt | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/orca-queue-redis/src/main/kotlin/com/netflix/spinnaker/config/RedisQueueShovelConfiguration.kt b/orca-queue-redis/src/main/kotlin/com/netflix/spinnaker/config/RedisQueueShovelConfiguration.kt index aa992e76cb..197d43851a 100644 --- a/orca-queue-redis/src/main/kotlin/com/netflix/spinnaker/config/RedisQueueShovelConfiguration.kt +++ b/orca-queue-redis/src/main/kotlin/com/netflix/spinnaker/config/RedisQueueShovelConfiguration.kt @@ -21,10 +21,12 @@ import com.netflix.spinnaker.orca.q.redis.RedisDeadMessageHandler import com.netflix.spinnaker.orca.q.redis.RedisQueue import com.netflix.spinnaker.orca.q.QueueShovel import org.apache.commons.pool2.impl.GenericObjectPoolConfig +import org.springframework.beans.factory.BeanInitializationException import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.condition.ConditionalOnBean import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.context.ApplicationEventPublisher import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -35,22 +37,25 @@ import java.time.Duration @Configuration @ConditionalOnExpression("\${queue.redis.enabled:true}") -class RedisQueueShovelConfiguration { +open class RedisQueueShovelConfiguration { - @Bean(name = arrayOf("previousQueueJedisPool")) open fun previousQueueJedisPool( + @Bean + @ConditionalOnProperty("redis.connectionPrevious") + open fun previousQueueJedisPool( @Value("\${redis.connection:redis://localhost:6379}") mainConnection: String, @Value("\${redis.connectionPrevious:#{null}}") previousConnection: String?, @Value("\${redis.timeout:2000}") timeout: Int, redisPoolConfig: GenericObjectPoolConfig, - registry: Registry): Pool? { - if (mainConnection == previousConnection || previousConnection == null) { - return null + registry: Registry): Pool { + if (mainConnection == previousConnection) { + throw BeanInitializationException("previous Redis connection must not be the same as current connection") } return RedisConfiguration.createPool(redisPoolConfig, previousConnection, timeout, registry, "previousQueueJedisPool") } - @Bean(name = arrayOf("previousQueueImpl")) open fun previousRedisQueue( + @Bean(name = arrayOf("previousQueueImpl")) + @ConditionalOnBean(name = arrayOf("previousQueueJedisPool")) open fun previousRedisQueue( @Qualifier("previousQueueJedisPool") redisPool: Pool, redisQueueProperties: RedisQueueProperties, clock: Clock, @@ -67,7 +72,7 @@ class RedisQueueShovelConfiguration { ) - @Bean() + @Bean @ConditionalOnBean(name = arrayOf("previousQueueJedisPool")) open fun redisQueueShovel( @Qualifier("queueImpl") queueImpl: RedisQueue, @Qualifier("previousQueueImpl") previousQueueImpl: RedisQueue, diff --git a/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/metrics/AtlasQueueMonitor.kt b/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/metrics/AtlasQueueMonitor.kt index 1437a47e49..55701e0bf4 100644 --- a/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/metrics/AtlasQueueMonitor.kt +++ b/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/metrics/AtlasQueueMonitor.kt @@ -22,6 +22,7 @@ import com.netflix.spinnaker.orca.q.ApplicationAware import com.netflix.spinnaker.orca.q.Queue import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.boot.autoconfigure.condition.ConditionalOnBean import org.springframework.context.ApplicationListener import org.springframework.scheduling.annotation.Scheduled @@ -39,7 +40,7 @@ import javax.annotation.PostConstruct @ConditionalOnBean(MonitorableQueue::class) open class AtlasQueueMonitor @Autowired constructor( - private val queue: MonitorableQueue, + @Qualifier("queueImpl") private val queue: MonitorableQueue, private val registry: Registry, private val clock: Clock ) : ApplicationListener {