Skip to content

Commit

Permalink
fix(queue): Fix stupid spring wiring (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert authored and asher committed Sep 19, 2017
1 parent cbab4cc commit 77ff216
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Jedis>? {
if (mainConnection == previousConnection || previousConnection == null) {
return null
registry: Registry): Pool<Jedis> {
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<Jedis>,
redisQueueProperties: RedisQueueProperties,
clock: Clock,
Expand All @@ -67,7 +72,7 @@ class RedisQueueShovelConfiguration {
)


@Bean()
@Bean
@ConditionalOnBean(name = arrayOf("previousQueueJedisPool")) open fun redisQueueShovel(
@Qualifier("queueImpl") queueImpl: RedisQueue,
@Qualifier("previousQueueImpl") previousQueueImpl: RedisQueue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<QueueEvent> {
Expand Down

0 comments on commit 77ff216

Please sign in to comment.