Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit 480917a

Browse files
srekapallimergify[bot]
authored andcommitted
feat(sql): Enables composite storage service to be backed by SQL stor… (#641)
* feat(sql): Enables composite storage service to be backed by SQL storage services. In order to wire up with storage services of same type, configuration now accepts bean name instead of storage service class names. We only need service class names or bean names. * feat(sql): Use injected prop beans instead of loose reference to properties * feat(sql): Added usage comment for H2
1 parent 4db11f4 commit 480917a

File tree

7 files changed

+315
-156
lines changed

7 files changed

+315
-156
lines changed

front50-sql/front50-sql.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ dependencies {
2626
testImplementation "org.testcontainers:postgresql"
2727
testImplementation "org.postgresql:postgresql"
2828

29+
// Only used for Initializing Datasource. For actual CRUD, test containers preferred.
30+
testImplementation "com.h2database:h2"
31+
2932
}
3033

3134
test {

front50-sql/src/main/kotlin/com/netflix/spinnaker/config/CompositeStorageServiceConfiguration.kt

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,61 @@ import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
2525
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
2626
import org.springframework.boot.context.properties.ConfigurationProperties
2727
import org.springframework.boot.context.properties.EnableConfigurationProperties
28+
import org.springframework.context.ApplicationContext
2829
import org.springframework.context.annotation.Bean
2930
import org.springframework.context.annotation.Configuration
3031
import org.springframework.context.annotation.Primary
3132

3233
@Configuration
3334
@EnableConfigurationProperties(StorageServiceMigratorConfigurationProperties::class)
34-
class CompositeStorageServiceConfiguration() {
35+
class CompositeStorageServiceConfiguration(
36+
private val storageServices: List<StorageService>,
37+
private val applicationContext: ApplicationContext,
38+
private val properties: StorageServiceMigratorConfigurationProperties,
39+
private val dynamicConfigService: DynamicConfigService,
40+
private val registry: Registry
41+
) {
3542
@Bean
3643
@Primary
3744
@ConditionalOnProperty("spinnaker.migration.compositeStorageService.enabled")
38-
fun compositeStorageService(
39-
dynamicConfigService: DynamicConfigService,
40-
registry: Registry,
41-
properties: StorageServiceMigratorConfigurationProperties,
42-
storageServices: List<StorageService>
43-
) =
45+
fun compositeStorageService() =
4446
CompositeStorageService(
4547
dynamicConfigService,
4648
registry,
47-
storageServices.first { it.javaClass.canonicalName.equals(properties.primaryClass) },
48-
storageServices.first { it.javaClass.canonicalName.equals(properties.previousClass) }
49+
findStorageService(properties.primaryClass, properties.primaryName),
50+
findStorageService(properties.previousClass, properties.previousName)
4951
)
5052

5153
@Bean
5254
@ConditionalOnProperty("spinnaker.migration.compositeStorageService.enabled")
5355
fun storageServiceMigrator(
54-
dynamicConfigService: DynamicConfigService,
55-
registry: Registry,
56-
properties: StorageServiceMigratorConfigurationProperties,
57-
storageServices: List<StorageService>,
5856
entityTagsDAO: EntityTagsDAO
5957
) =
6058
StorageServiceMigrator(
6159
dynamicConfigService,
6260
registry,
63-
storageServices.first { it.javaClass.canonicalName.equals(properties.primaryClass) },
64-
storageServices.first { it.javaClass.canonicalName.equals(properties.previousClass) },
61+
findStorageService(properties.primaryClass, properties.primaryName),
62+
findStorageService(properties.previousClass, properties.previousName),
6563
entityTagsDAO
6664
)
65+
66+
private fun findStorageService(
67+
className: String?,
68+
beanName: String?
69+
): StorageService {
70+
return if (className != null && className.isNotBlank()) {
71+
storageServices.first { it.javaClass.canonicalName == className }
72+
} else {
73+
applicationContext.getBean(beanName) as StorageService
74+
}
75+
}
6776
}
6877

6978
@ConfigurationProperties("spinnaker.migration")
7079
data class StorageServiceMigratorConfigurationProperties(
7180
var primaryClass: String? = null,
7281
var previousClass: String? = null,
82+
var primaryName: String? = null,
83+
var previousName: String? = null,
7384
var writeOnly: Boolean = false
7485
)

front50-sql/src/main/kotlin/com/netflix/spinnaker/config/SqlConfiguration.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import com.netflix.spinnaker.front50.model.SqlStorageService
2323
import com.netflix.spinnaker.kork.sql.config.DefaultSqlConfiguration
2424
import com.netflix.spinnaker.kork.sql.config.SqlProperties
2525
import org.jooq.DSLContext
26+
import org.springframework.beans.factory.annotation.Qualifier
27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
2628
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
2729
import org.springframework.context.annotation.Bean
2830
import org.springframework.context.annotation.Configuration
@@ -47,6 +49,26 @@ class SqlConfiguration : CommonStorageServiceDAOConfig() {
4749
jooq,
4850
Clock.systemDefaultZone(),
4951
sqlProperties.retries,
50-
1000
52+
1000,
53+
if (sqlProperties.connectionPools.keys.size > 1)
54+
sqlProperties.connectionPools.filter { it.value.default }.keys.first() else sqlProperties.connectionPools.keys.first()
55+
)
56+
57+
@Bean
58+
@ConditionalOnBean(name = ["secondaryJooq"])
59+
fun secondarySqlStorageService(
60+
objectMapper: ObjectMapper,
61+
registry: Registry,
62+
@Qualifier("secondaryJooq") jooq: DSLContext,
63+
sqlProperties: SqlProperties
64+
): SqlStorageService =
65+
SqlStorageService(
66+
objectMapper,
67+
registry,
68+
jooq,
69+
Clock.systemDefaultZone(),
70+
sqlProperties.retries,
71+
1000,
72+
sqlProperties.connectionPools.filter { !it.value.default }.keys.first()
5173
)
5274
}

0 commit comments

Comments
 (0)