Skip to content

Commit

Permalink
fix(migrations): Fix wiring secondarySqlStorage service bean
Browse files Browse the repository at this point in the history
  • Loading branch information
christosarvanitis committed Jan 27, 2025
1 parent f22ddd2 commit 5e2d571
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ class CompositeStorageServiceConfiguration(
beanName: String?
): StorageService {
return if (className != null && className.isNotBlank()) {
storageServices.first { it.javaClass.canonicalName == className }
val storageServiceClass = Class.forName(className)
storageServices.find { storageServiceClass.isInstance(it) }
?: throw IllegalStateException("No StorageService bean of class $className found")
} else {
applicationContext.getBean(beanName) as StorageService
beanName?.let { applicationContext.getBean(it) } as StorageService
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import com.netflix.spinnaker.kork.sql.config.DefaultSqlConfiguration
import com.netflix.spinnaker.kork.sql.config.SqlProperties
import java.time.Clock
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
Expand Down Expand Up @@ -58,22 +58,25 @@ class SqlConfiguration {
)

@Bean
@ConditionalOnBean(name = ["secondaryJooq"])
@ConditionalOnProperty("sql.enabled", "sql.secondary.enabled")
fun secondarySqlStorageService(
objectMapper: ObjectMapper,
registry: Registry,
@Qualifier("secondaryJooq") jooq: DSLContext,
@Autowired(required = false) @Qualifier("secondaryJooq") secondaryJooq: DSLContext?,
jooq: DSLContext,
sqlProperties: SqlProperties,
front50SqlProperties: Front50SqlProperties
): SqlStorageService =
SqlStorageService(
): SqlStorageService {
val effectiveJooq = secondaryJooq ?: jooq
return SqlStorageService(
objectMapper,
registry,
jooq,
effectiveJooq,
Clock.systemDefaultZone(),
sqlProperties.retries,
1000,
sqlProperties.connectionPools.filter { !it.value.default }.keys.first(),
front50SqlProperties
)
}
}

0 comments on commit 5e2d571

Please sign in to comment.