Skip to content

Commit

Permalink
refactor(*): Remove ProviderSynchronizerTypeWrapper and usage from al…
Browse files Browse the repository at this point in the history
…l providers. (#3682)
  • Loading branch information
scottfrederick authored and jkschneider committed May 23, 2019
1 parent 1ebd099 commit 06cb8ac
Show file tree
Hide file tree
Showing 27 changed files with 85 additions and 434 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.cats.agent.Agent
import com.netflix.spinnaker.cats.provider.ProviderSynchronizerTypeWrapper
import com.netflix.spinnaker.clouddriver.appengine.AppengineCloudProvider
import com.netflix.spinnaker.clouddriver.appengine.provider.AppengineProvider
import com.netflix.spinnaker.clouddriver.appengine.provider.agent.AppenginePlatformApplicationCachingAgent
Expand All @@ -29,11 +28,9 @@ import com.netflix.spinnaker.clouddriver.appengine.provider.agent.AppengineServe
import com.netflix.spinnaker.clouddriver.appengine.security.AppengineNamedAccountCredentials
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsRepository
import com.netflix.spinnaker.clouddriver.security.ProviderUtils
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.DependsOn
import org.springframework.context.annotation.Scope

import java.util.concurrent.ConcurrentHashMap

Expand All @@ -55,26 +52,10 @@ class AppengineProviderConfig {
appengineProvider
}

@Bean
AppengineProviderSynchronizerTypeWrapper appengineProviderSynchronizerTypeWrapper() {
new AppengineProviderSynchronizerTypeWrapper()
}

class AppengineProviderSynchronizerTypeWrapper implements ProviderSynchronizerTypeWrapper {
@Override
Class getSynchronizerType() {
return AppengineProviderSynchronizer
}
}

class AppengineProviderSynchronizer { }

@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Bean
AppengineProviderSynchronizer synchronizeAppengineProvider(AppengineProvider appengineProvider,
AccountCredentialsRepository accountCredentialsRepository,
ObjectMapper objectMapper,
Registry registry) {
private static void synchronizeAppengineProvider(AppengineProvider appengineProvider,
AccountCredentialsRepository accountCredentialsRepository,
ObjectMapper objectMapper,
Registry registry) {
def scheduledAccounts = ProviderUtils.getScheduledAccounts(appengineProvider)
def allAccounts = ProviderUtils.buildThreadSafeSetOfAccounts(accountCredentialsRepository,
AppengineNamedAccountCredentials)
Expand Down Expand Up @@ -103,7 +84,5 @@ class AppengineProviderConfig {
if (!newlyAddedAgents.isEmpty()) {
appengineProvider.agents.addAll(newlyAddedAgents)
}

new AppengineProviderSynchronizer()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ package com.netflix.spinnaker.config
import com.netflix.spinnaker.clouddriver.appengine.config.AppengineConfigurationProperties
import com.netflix.spinnaker.clouddriver.appengine.health.AppengineHealthIndicator
import com.netflix.spinnaker.clouddriver.appengine.security.AppengineCredentialsInitializer
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.Scope
import org.springframework.scheduling.annotation.EnableScheduling

@Configuration
Expand All @@ -37,7 +35,6 @@ import org.springframework.scheduling.annotation.EnableScheduling
@ComponentScan(["com.netflix.spinnaker.clouddriver.appengine"])
@Import([ AppengineCredentialsInitializer ])
class AppengineConfiguration {
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Bean
@ConfigurationProperties("appengine")
AppengineConfigurationProperties appengineConfigurationProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.netflix.spinnaker.clouddriver.aws.provider.config
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.cats.agent.Agent
import com.netflix.spinnaker.cats.provider.ProviderSynchronizerTypeWrapper
import com.netflix.spinnaker.clouddriver.aws.provider.AwsInfrastructureProvider
import com.netflix.spinnaker.clouddriver.aws.provider.agent.AmazonElasticIpCachingAgent
import com.netflix.spinnaker.clouddriver.aws.provider.agent.AmazonInstanceTypeCachingAgent
Expand All @@ -34,11 +33,9 @@ import com.netflix.spinnaker.clouddriver.aws.security.NetflixAmazonCredentials
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsRepository
import com.netflix.spinnaker.clouddriver.security.ProviderUtils
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.DependsOn
import org.springframework.context.annotation.Scope

import java.util.concurrent.ConcurrentHashMap

Expand All @@ -64,28 +61,12 @@ class AwsInfrastructureProviderConfig {
awsInfrastructureProvider
}

@Bean
AwsInfrastructureProviderSynchronizerTypeWrapper awsInfrastructureProviderSynchronizerTypeWrapper() {
new AwsInfrastructureProviderSynchronizerTypeWrapper()
}

class AwsInfrastructureProviderSynchronizerTypeWrapper implements ProviderSynchronizerTypeWrapper {
@Override
Class getSynchronizerType() {
return AwsInfrastructureProviderSynchronizer
}
}

class AwsInfrastructureProviderSynchronizer {}

@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Bean
AwsInfrastructureProviderSynchronizer synchronizeAwsInfrastructureProvider(AwsInfrastructureProvider awsInfrastructureProvider,
AmazonClientProvider amazonClientProvider,
AccountCredentialsRepository accountCredentialsRepository,
@Qualifier("amazonObjectMapper") ObjectMapper amazonObjectMapper,
Registry registry,
EddaTimeoutConfig eddaTimeoutConfig) {
private static void synchronizeAwsInfrastructureProvider(AwsInfrastructureProvider awsInfrastructureProvider,
AmazonClientProvider amazonClientProvider,
AccountCredentialsRepository accountCredentialsRepository,
@Qualifier("amazonObjectMapper") ObjectMapper amazonObjectMapper,
Registry registry,
EddaTimeoutConfig eddaTimeoutConfig) {
def scheduledAccounts = ProviderUtils.getScheduledAccounts(awsInfrastructureProvider)
def allAccounts = ProviderUtils.buildThreadSafeSetOfAccounts(accountCredentialsRepository, NetflixAmazonCredentials)

Expand Down Expand Up @@ -115,7 +96,5 @@ class AwsInfrastructureProviderConfig {
}
}
}

new AwsInfrastructureProviderSynchronizer()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.cats.agent.Agent
import com.netflix.spinnaker.cats.agent.AgentProvider
import com.netflix.spinnaker.cats.provider.ProviderSynchronizerTypeWrapper
import com.netflix.spinnaker.clouddriver.aws.AmazonCloudProvider
import com.netflix.spinnaker.clouddriver.aws.provider.agent.AmazonApplicationLoadBalancerCachingAgent
import com.netflix.spinnaker.clouddriver.aws.provider.agent.AmazonCertificateCachingAgent
Expand All @@ -45,14 +44,11 @@ import com.netflix.spinnaker.clouddriver.aws.provider.agent.InstanceCachingAgent
import com.netflix.spinnaker.clouddriver.aws.provider.agent.LaunchConfigCachingAgent
import com.netflix.spinnaker.clouddriver.aws.provider.agent.ReservationReportCachingAgent
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.DependsOn
import org.springframework.context.annotation.Scope

import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ExecutorService
Expand Down Expand Up @@ -100,35 +96,19 @@ class AwsProviderConfig {
return Executors.newFixedThreadPool(reservationReportConfigurationProperties.threadPoolSize)
}

@Bean
AwsProviderSynchronizerTypeWrapper awsProviderSynchronizerTypeWrapper() {
new AwsProviderSynchronizerTypeWrapper()
}

class AwsProviderSynchronizerTypeWrapper implements ProviderSynchronizerTypeWrapper {
@Override
Class getSynchronizerType() {
return AwsProviderSynchronizer
}
}

class AwsProviderSynchronizer {}

@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Bean
AwsProviderSynchronizer synchronizeAwsProvider(AwsProvider awsProvider,
AmazonCloudProvider amazonCloudProvider,
AmazonClientProvider amazonClientProvider,
AmazonS3DataProvider amazonS3DataProvider,
AccountCredentialsRepository accountCredentialsRepository,
ObjectMapper objectMapper,
EddaApiFactory eddaApiFactory,
ApplicationContext ctx,
Registry registry,
ExecutorService reservationReportPool,
Collection<AgentProvider> agentProviders,
EddaTimeoutConfig eddaTimeoutConfig,
DynamicConfigService dynamicConfigService) {
private void synchronizeAwsProvider(AwsProvider awsProvider,
AmazonCloudProvider amazonCloudProvider,
AmazonClientProvider amazonClientProvider,
AmazonS3DataProvider amazonS3DataProvider,
AccountCredentialsRepository accountCredentialsRepository,
ObjectMapper objectMapper,
EddaApiFactory eddaApiFactory,
ApplicationContext ctx,
Registry registry,
ExecutorService reservationReportPool,
Collection<AgentProvider> agentProviders,
EddaTimeoutConfig eddaTimeoutConfig,
DynamicConfigService dynamicConfigService) {
def scheduledAccounts = ProviderUtils.getScheduledAccounts(awsProvider)
Set<NetflixAmazonCredentials> allAccounts = ProviderUtils.buildThreadSafeSetOfAccounts(accountCredentialsRepository, NetflixAmazonCredentials)

Expand Down Expand Up @@ -186,11 +166,10 @@ class AwsProviderConfig {

awsProvider.agents.addAll(newlyAddedAgents)
awsProvider.synchronizeHealthAgents()

new AwsProviderSynchronizer()
}

private void synchronizeReservationReportCachingAgentAccounts(AwsProvider awsProvider, Collection<NetflixAmazonCredentials> allAccounts) {
private static void synchronizeReservationReportCachingAgentAccounts(AwsProvider awsProvider,
Collection<NetflixAmazonCredentials> allAccounts) {
ReservationReportCachingAgent reservationReportCachingAgent = awsProvider.agents.find { agent ->
agent instanceof ReservationReportCachingAgent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ package com.netflix.spinnaker.clouddriver.aws.security

import com.amazonaws.auth.AWSCredentialsProvider
import com.netflix.spinnaker.cats.module.CatsModule
import com.netflix.spinnaker.cats.provider.ProviderSynchronizerTypeWrapper
import com.netflix.spinnaker.clouddriver.aws.security.config.CredentialsConfig
import com.netflix.spinnaker.clouddriver.aws.security.config.CredentialsLoader
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsRepository
import com.netflix.spinnaker.clouddriver.security.ProviderUtils
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

Expand Down Expand Up @@ -61,23 +59,21 @@ class AmazonCredentialsInitializer {
}

@Bean
List<? extends NetflixAmazonCredentials> netflixAmazonCredentials(CredentialsLoader<? extends NetflixAmazonCredentials> credentialsLoader,
CredentialsConfig credentialsConfig,
AccountCredentialsRepository accountCredentialsRepository,
DefaultAccountConfigurationProperties defaultAccountConfigurationProperties,
ApplicationContext applicationContext,
List<ProviderSynchronizerTypeWrapper> providerSynchronizerTypeWrappers) {
synchronizeAmazonAccounts(credentialsLoader, credentialsConfig, accountCredentialsRepository, defaultAccountConfigurationProperties, null, applicationContext, providerSynchronizerTypeWrappers)
List<? extends NetflixAmazonCredentials> netflixAmazonCredentials(
CredentialsLoader<? extends NetflixAmazonCredentials> credentialsLoader,
CredentialsConfig credentialsConfig,
AccountCredentialsRepository accountCredentialsRepository,
DefaultAccountConfigurationProperties defaultAccountConfigurationProperties) {

synchronizeAmazonAccounts(credentialsLoader, credentialsConfig, accountCredentialsRepository, defaultAccountConfigurationProperties, null)
}

private List<? extends NetflixAmazonCredentials> synchronizeAmazonAccounts(
CredentialsLoader<? extends NetflixAmazonCredentials> credentialsLoader,
CredentialsConfig credentialsConfig,
AccountCredentialsRepository accountCredentialsRepository,
DefaultAccountConfigurationProperties defaultAccountConfigurationProperties,
CatsModule catsModule,
ApplicationContext applicationContext,
List<ProviderSynchronizerTypeWrapper> providerSynchronizerTypeWrappers) {
CatsModule catsModule) {
if (!credentialsConfig.accounts && !credentialsConfig.defaultAssumeRole) {
def defaultEnvironment = defaultAccountConfigurationProperties.environment ?: defaultAccountConfigurationProperties.env
def defaultAccountType = defaultAccountConfigurationProperties.accountType ?: defaultAccountConfigurationProperties.env
Expand All @@ -100,10 +96,6 @@ class AmazonCredentialsInitializer {

ProviderUtils.unscheduleAndDeregisterAgents(namesOfDeletedAccounts, catsModule)

if ((namesOfDeletedAccounts || accountsToAdd) && catsModule) {
ProviderUtils.synchronizeAgentProviders(applicationContext, providerSynchronizerTypeWrappers)
}

accountCredentialsRepository.all.findAll {
it instanceof NetflixAmazonCredentials
} as List<NetflixAmazonCredentials>
Expand Down
Loading

0 comments on commit 06cb8ac

Please sign in to comment.