@@ -25,50 +25,61 @@ import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
25
25
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
26
26
import org.springframework.boot.context.properties.ConfigurationProperties
27
27
import org.springframework.boot.context.properties.EnableConfigurationProperties
28
+ import org.springframework.context.ApplicationContext
28
29
import org.springframework.context.annotation.Bean
29
30
import org.springframework.context.annotation.Configuration
30
31
import org.springframework.context.annotation.Primary
31
32
32
33
@Configuration
33
34
@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
+ ) {
35
42
@Bean
36
43
@Primary
37
44
@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 () =
44
46
CompositeStorageService (
45
47
dynamicConfigService,
46
48
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)
49
51
)
50
52
51
53
@Bean
52
54
@ConditionalOnProperty(" spinnaker.migration.compositeStorageService.enabled" )
53
55
fun storageServiceMigrator (
54
- dynamicConfigService : DynamicConfigService ,
55
- registry : Registry ,
56
- properties : StorageServiceMigratorConfigurationProperties ,
57
- storageServices : List <StorageService >,
58
56
entityTagsDAO : EntityTagsDAO
59
57
) =
60
58
StorageServiceMigrator (
61
59
dynamicConfigService,
62
60
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) ,
65
63
entityTagsDAO
66
64
)
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
+ }
67
76
}
68
77
69
78
@ConfigurationProperties(" spinnaker.migration" )
70
79
data class StorageServiceMigratorConfigurationProperties (
71
80
var primaryClass : String? = null ,
72
81
var previousClass : String? = null ,
82
+ var primaryName : String? = null ,
83
+ var previousName : String? = null ,
73
84
var writeOnly : Boolean = false
74
85
)
0 commit comments