Skip to content

Commit

Permalink
feat(cache): remove info we don't need about launch configs (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
emjburns authored Nov 7, 2018
1 parent 8751a82 commit cbac6db
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ open class EddaLaunchConfigurationCacheProvider(

override fun load(): AmazonLaunchConfigurationCache {
log.info("Loading cache for ${javaClass.simpleName}")
val configsByRegion = mutableMapOf<String, Set<AmazonLaunchConfiguration>>()
val refdAmisByRegion = mutableMapOf<String, MutableMap<String, MutableSet<AmazonLaunchConfiguration>>>()

val regions = workConfigurations.asSequence()
Expand All @@ -65,10 +64,9 @@ open class EddaLaunchConfigurationCacheProvider(
refdAmis.getOrPut(it.imageId) { mutableSetOf() }.add(it)
}

configsByRegion[region] = launchConfigs
refdAmisByRegion[region] = refdAmis
}
return AmazonLaunchConfigurationCache(configsByRegion, refdAmisByRegion, clock.millis(), "default")
return AmazonLaunchConfigurationCache(refdAmisByRegion, clock.millis(), "default")

}
}
Expand All @@ -79,24 +77,12 @@ open class EddaLaunchConfigurationCache(
) : InMemorySingletonCache<AmazonLaunchConfigurationCache>(eddaLaunchConfigurationCacheProvider::load)

data class AmazonLaunchConfigurationCache(
private val configsByRegion: Map<String, Set<AmazonLaunchConfiguration>>,
private val refdAmisByRegion: Map<String, Map<String, Set<AmazonLaunchConfiguration>>>,
private val lastUpdated: Long,
override val name: String?
) : Cacheable {
private val log: Logger = LoggerFactory.getLogger(javaClass)

/**
* @param params["region"]: return a Set<AmazonLaunchConfiguration> across all known accounts in region
*/
fun getLaunchConfigsByRegion(params: Parameters): Set<AmazonLaunchConfiguration> {
if (params.region != "") {
return configsByRegion[params.region] ?: emptySet()
} else {
throw IllegalArgumentException("Missing required region parameter")
}
}

fun getLaunchConfigsByRegionForImage(params: Parameters): Set<AmazonLaunchConfiguration> {
if (params.region != "" && params.id != "") {
return getRefdAmisForRegion(params.region).getOrDefault(params.id, emptySet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ object AmazonImageHandlerTest {
)
whenever(launchConfigurationCache.get()) doReturn
AmazonLaunchConfigurationCache(
mapOf(
"us-east-1" to setOf(defaultLaunchConfig)
),
mapOf(
"us-east-1" to mapOf("ami-132" to setOf(defaultLaunchConfig))
),
Expand Down

0 comments on commit cbac6db

Please sign in to comment.