Skip to content

Commit

Permalink
chore(params): map to actual object (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
emjburns authored Oct 26, 2018
1 parent 8cd496e commit 75566b7
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ class AmazonAutoScalingGroupHandler(

override fun getCandidates(workConfiguration: WorkConfiguration): List<AmazonAutoScalingGroup>? {
val params = Parameters(
mapOf(
"account" to workConfiguration.account.accountId!!,
"region" to workConfiguration.location,
"environment" to workConfiguration.account.environment
)
account = workConfiguration.account.accountId!!,
region = workConfiguration.location,
environment = workConfiguration.account.environment
)

return serverGroupProvider.getAll(params).also { serverGroups ->
Expand All @@ -144,11 +142,9 @@ class AmazonAutoScalingGroupHandler(
checkReferences(
serverGroups = candidates,
params = Parameters(
mapOf(
"account" to workConfiguration.account.accountId!!,
"region" to workConfiguration.location,
"environment" to workConfiguration.account.environment
)
account = workConfiguration.account.accountId!!,
region = workConfiguration.location,
environment = workConfiguration.account.environment
)
)

Expand Down Expand Up @@ -183,12 +179,10 @@ class AmazonAutoScalingGroupHandler(
workConfiguration: WorkConfiguration
): AmazonAutoScalingGroup? {
val params = Parameters(
mapOf(
"autoScalingGroupName" to resourceId,
"account" to workConfiguration.account.accountId!!,
"region" to workConfiguration.location,
"environment" to workConfiguration.account.environment
)
id = resourceId,
account = workConfiguration.account.accountId!!,
region = workConfiguration.location,
environment = workConfiguration.account.environment
)

return serverGroupProvider.getOne(params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ open class EddaAmazonElasticLoadBalancerProvider(

override fun getAll(params: Parameters): List<AmazonElasticLoadBalancer>? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getELBs()
}
Expand All @@ -51,11 +51,11 @@ open class EddaAmazonElasticLoadBalancerProvider(

override fun getOne(params: Parameters): AmazonElasticLoadBalancer? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getELB(params["loadBalancerName"] as String)
return getELB(params.id)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ open class EddaAmazonImageProvider(

override fun getAll(params: Parameters): List<AmazonImage>? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getAmis()
}
Expand All @@ -51,11 +51,11 @@ open class EddaAmazonImageProvider(

override fun getOne(params: Parameters): AmazonImage? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getAmi(params["imageId"] as String)
return getAmi(params.id)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ open class EddaAmazonSecurityGroupProvider(
private val log: Logger = LoggerFactory.getLogger(javaClass)
override fun getAll(params: Parameters): List<AmazonSecurityGroup>? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getSecurityGroups()
}
Expand All @@ -45,11 +45,11 @@ open class EddaAmazonSecurityGroupProvider(

override fun getOne(params: Parameters): AmazonSecurityGroup? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getSecurityGroup(params["groupId"] as String)
return getSecurityGroup(params.id)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ open class EddaAutoScalingGroupProvider(
private val log: Logger = LoggerFactory.getLogger(javaClass)
override fun getAll(params: Parameters): List<AmazonAutoScalingGroup>? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getServerGroups()
}
Expand All @@ -50,11 +50,11 @@ open class EddaAutoScalingGroupProvider(

override fun getOne(params: Parameters): AmazonAutoScalingGroup? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getServerGroup(params["autoScalingGroupName"] as String)
return getServerGroup(params.id)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ open class EddaImagesUsedByInstancesProvider(
* currently referenced by running EC2 instances in the region
*/
override fun getAll(params: Parameters): Set<String> {
if (params.containsKey("region")) {
return imagesUsedByInstancesCache.get().elementAt(0).refdAmisByRegion[params["region"]] ?: emptySet()
if (params.region != "") {
return imagesUsedByInstancesCache.get().elementAt(0).refdAmisByRegion[params.region] ?: emptySet()
} else {
throw IllegalArgumentException("Missing required region parameter")
}
Expand All @@ -66,11 +66,9 @@ open class EddaImagesUsedByInstancesProvider(
.flatMap { edda ->
instanceProvider.getAll(
Parameters(
mapOf(
"region" to region,
"account" to edda.account.accountId!!,
"environment" to edda.account.environment
)
region = region,
account = edda.account.accountId!!,
environment = edda.account.environment
)
) ?: emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ open class EddaInstanceProvider(
private val log: Logger = LoggerFactory.getLogger(javaClass)
override fun getAll(params: Parameters): List<AmazonInstance>? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getNonTerminatedInstances()
}
Expand All @@ -50,11 +50,11 @@ open class EddaInstanceProvider(

override fun getOne(params: Parameters): AmazonInstance? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getSingleInstance(params["instanceId"] as String)
return getSingleInstance(params.id)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ open class EddaLaunchConfigurationCacheProvider(
* @param params["region"]: return a Set<AmazonLaunchConfiguration> across all known accounts in region
*/
override fun getAll(params: Parameters): Set<AmazonLaunchConfiguration> {
if (params.containsKey("region")) {
return launchConfigCache.get().elementAt(0).configsByRegion[params["region"]] ?: emptySet()
if (params.region != "") {
return launchConfigCache.get().elementAt(0).configsByRegion[params.region] ?: emptySet()
} else {
throw IllegalArgumentException("Missing required region parameter")
}
Expand Down Expand Up @@ -77,11 +77,9 @@ open class EddaLaunchConfigurationCacheProvider(
.flatMap { edda ->
launchConfigurationProvider.getAll(
Parameters(
mapOf(
"region" to region,
"account" to edda.account.accountId!!,
"environment" to edda.account.environment
)
region = region,
account = edda.account.accountId!!,
environment = edda.account.environment
)
) ?: emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ open class EddaLaunchConfigurationProvider(
private val log: Logger = LoggerFactory.getLogger(javaClass)
override fun getAll(params: Parameters): List<AmazonLaunchConfiguration>? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getLaunchConfigurations()
}
Expand All @@ -50,11 +50,11 @@ open class EddaLaunchConfigurationProvider(

override fun getOne(params: Parameters): AmazonLaunchConfiguration? {
withEddaClient(
region = params["region"] as String,
accountId = params["account"] as String,
environment = params["environment"] as String
region = params.region,
accountId = params.account,
environment = params.environment
)?.run {
return getLaunchConfiguration(params["launchConfigurationName"] as String)
return getLaunchConfiguration(params.id)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ class AmazonImageHandler(

override fun getCandidates(workConfiguration: WorkConfiguration): List<AmazonImage>? {
val params = Parameters(
mapOf(
"account" to workConfiguration.account.accountId!!,
"region" to workConfiguration.location,
"environment" to workConfiguration.account.environment
)
account = workConfiguration.account.accountId!!,
region = workConfiguration.location,
environment = workConfiguration.account.environment
)

return imageProvider.getAll(params).also { images ->
Expand All @@ -199,11 +197,9 @@ class AmazonImageHandler(
checkReferences(
images = candidates,
params = Parameters(
mapOf(
"account" to workConfiguration.account.accountId!!,
"region" to workConfiguration.location,
"environment" to workConfiguration.account.environment
)
account = workConfiguration.account.accountId!!,
region = workConfiguration.location,
environment = workConfiguration.account.environment
)
)
return candidates
Expand Down Expand Up @@ -268,7 +264,7 @@ class AmazonImageHandler(
) { usedByResource ->
image.set(USED_BY_INSTANCES, true)
resourceUseTrackingRepository.recordUse(image.resourceId, usedByResource)
log.debug("Image {} ({}) in {} is USED_BY_INSTANCES", image.imageId, image.name, params["region"])
log.debug("Image {} ({}) in {} is USED_BY_INSTANCES", image.imageId, image.name, params.region)
}
}
}
Expand Down Expand Up @@ -303,7 +299,7 @@ class AmazonImageHandler(
},
image
) { usedByResource ->
log.debug("Image {} ({}) in {} is USED_BY_LAUNCH_CONFIGURATIONS", image.imageId, image.name, params["region"])
log.debug("Image {} ({}) in {} is USED_BY_LAUNCH_CONFIGURATIONS", image.imageId, image.name, params.region)
resourceUseTrackingRepository.recordUse(image.resourceId, usedByResource)
image.set(USED_BY_LAUNCH_CONFIGURATIONS, true)
}
Expand Down Expand Up @@ -350,12 +346,12 @@ class AmazonImageHandler(
if (isAncestor(imageDescrToImageId, image) || isAncestor(otherImageDescrToImageId, image)) {
image.set(IS_BASE_OR_ANCESTOR, true)
image.set(NAIVE_EXCLUSION, true)
log.debug("Image {} ({}) in {} is IS_BASE_OR_ANCESTOR", image.imageId, image.name, params["region"])
log.debug("Image {} ({}) in {} is IS_BASE_OR_ANCESTOR", image.imageId, image.name, params.region)
}

if (otherImagesIdToAccount.containsKey(image.imageId)) {
image.set(HAS_SIBLINGS_IN_OTHER_ACCOUNTS, true)
log.debug("Image {} ({}) in {} is HAS_SIBLINGS_IN_OTHER_ACCOUNTS", image.imageId, image.name, params["region"])
log.debug("Image {} ({}) in {} is HAS_SIBLINGS_IN_OTHER_ACCOUNTS", image.imageId, image.name, params.region)
}
}
}
Expand Down Expand Up @@ -399,14 +395,12 @@ class AmazonImageHandler(
): List<Pair<AmazonImage, Account>> {
val result: MutableList<Pair<AmazonImage, Account>> = mutableListOf()
accountProvider.getAccounts().filter {
it.type == AWS && it.accountId != params["account"]
it.type == AWS && it.accountId != params.account
}.forEach { account ->
account.regions?.forEach { region ->
log.info("Looking for other images in {}/{}", account.accountId, region)
imageProvider.getAll(
Parameters(
mapOf("account" to account.accountId!!, "region" to region.name, "environment" to account.environment)
)
Parameters(account = account.accountId!!, region = region.name, environment = account.environment)
)?.forEach { image ->
result.add(Pair(image, account))
}
Expand All @@ -426,12 +420,10 @@ class AmazonImageHandler(

override fun getCandidate(resourceId: String, resourceName: String, workConfiguration: WorkConfiguration): AmazonImage? {
val params = Parameters(
mapOf(
"imageId" to resourceId,
"account" to workConfiguration.account.accountId!!,
"region" to workConfiguration.location,
"environment" to workConfiguration.account.environment
)
id = resourceId,
account = workConfiguration.account.accountId!!,
region = workConfiguration.location,
environment = workConfiguration.account.environment
)

return imageProvider.getOne(params)
Expand Down
Loading

0 comments on commit 75566b7

Please sign in to comment.