Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Allow users to specify auto scaling instance counts for cms, consul, …
Browse files Browse the repository at this point in the history
…gateway, and vault clusters (#17)

* Allow users to specify auto scaling instance counts for cms, consul, gateway, and vault clusters

* update copyright year
  • Loading branch information
sdford authored Jan 19, 2017
1 parent 9cbb6e6 commit be83885
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 24 deletions.
26 changes: 22 additions & 4 deletions smaas-cf/smaas/cms-cluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# Copyright (c) 2016 Nike Inc.
# Copyright (c) 2017 Nike Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -129,6 +129,24 @@
Type="String"
))

desired_instances_param = template.add_parameter(Parameter(
"desiredInstances",
Description="Desired Number of Auto Scaling Instances",
Type="Number"
))

maximum_instances_param = template.add_parameter(Parameter(
"maximumInstances",
Description="Maximum Number of Auto Scaling Instances",
Type="Number"
))

minimum_instances_param = template.add_parameter(Parameter(
"minimumInstances",
Description="Minimum Number of Auto Scaling Instances",
Type="Number"
))

###
#
# Elastic Load Balancers
Expand Down Expand Up @@ -207,15 +225,15 @@

autoscaling_group = template.add_resource(AutoScalingGroup(
"CmsAutoScalingGroup",
DesiredCapacity=3,
DesiredCapacity=Ref(desired_instances_param),
HealthCheckGracePeriod=360,
HealthCheckType="ELB",
LaunchConfigurationName=Ref(launch_config),
LoadBalancerNames=[
Ref(load_balancer)
],
MaxSize=3,
MinSize=3,
MaxSize=Ref(maximum_instances_param),
MinSize=Ref(minimum_instances_param),
UpdatePolicy=UpdatePolicy(
AutoScalingRollingUpdate=AutoScalingRollingUpdate(
MaxBatchSize=1,
Expand Down
26 changes: 22 additions & 4 deletions smaas-cf/smaas/consul-cluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# Copyright (c) 2016 Nike Inc.
# Copyright (c) 2017 Nike Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -92,6 +92,24 @@
Type="String"
))

desired_instances_param = template.add_parameter(Parameter(
"desiredInstances",
Description="Desired Number of Auto Scaling Instances",
Type="Number"
))

maximum_instances_param = template.add_parameter(Parameter(
"maximumInstances",
Description="Maximum Number of Auto Scaling Instances",
Type="Number"
))

minimum_instances_param = template.add_parameter(Parameter(
"minimumInstances",
Description="Minimum Number of Auto Scaling Instances",
Type="Number"
))

subnet_id_refs = []
for zone_identifier in range(1, 4):
vpc_subnet_id = template.add_parameter(Parameter(
Expand Down Expand Up @@ -127,12 +145,12 @@

consul_autoscaling_group = template.add_resource(AutoScalingGroup(
"ConsulAutoScalingGroup",
DesiredCapacity=3,
DesiredCapacity=Ref(desired_instances_param),
HealthCheckGracePeriod=60,
HealthCheckType="EC2",
LaunchConfigurationName=Ref(consul_launch_config),
MaxSize=3,
MinSize=3,
MaxSize=Ref(maximum_instances_param),
MinSize=Ref(minimum_instances_param),
UpdatePolicy=UpdatePolicy(
AutoScalingRollingUpdate=AutoScalingRollingUpdate(
MaxBatchSize=1,
Expand Down
26 changes: 22 additions & 4 deletions smaas-cf/smaas/gateway-cluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# Copyright (c) 2016 Nike Inc.
# Copyright (c) 2017 Nike Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -161,6 +161,24 @@
Description="Key for waf lambda function artifact"
))

desired_instances_param = template.add_parameter(Parameter(
"desiredInstances",
Description="Desired Number of Auto Scaling Instances",
Type="Number"
))

maximum_instances_param = template.add_parameter(Parameter(
"maximumInstances",
Description="Maximum Number of Auto Scaling Instances",
Type="Number"
))

minimum_instances_param = template.add_parameter(Parameter(
"minimumInstances",
Description="Minimum Number of Auto Scaling Instances",
Type="Number"
))

###
#
# Elastic Load Balancer
Expand Down Expand Up @@ -262,15 +280,15 @@

gateway_autoscaling_group = template.add_resource(AutoScalingGroup(
"GatewayAutoScalingGroup",
DesiredCapacity=3,
DesiredCapacity=Ref(desired_instances_param),
HealthCheckGracePeriod=300,
HealthCheckType="ELB",
LaunchConfigurationName=Ref(gateway_launch_config),
LoadBalancerNames=[
Ref(gateway_load_balancer)
],
MaxSize=3,
MinSize=3,
MaxSize=Ref(maximum_instances_param),
MinSize=Ref(minimum_instances_param),
UpdatePolicy=UpdatePolicy(
AutoScalingRollingUpdate=AutoScalingRollingUpdate(
MaxBatchSize=1,
Expand Down
26 changes: 22 additions & 4 deletions smaas-cf/smaas/vault-cluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# Copyright (c) 2016 Nike Inc.
# Copyright (c) 2017 Nike Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -147,6 +147,24 @@
Type="String"
))

desired_instances_param = template.add_parameter(Parameter(
"desiredInstances",
Description="Desired Number of Auto Scaling Instances",
Type="Number"
))

maximum_instances_param = template.add_parameter(Parameter(
"maximumInstances",
Description="Maximum Number of Auto Scaling Instances",
Type="Number"
))

minimum_instances_param = template.add_parameter(Parameter(
"minimumInstances",
Description="Minimum Number of Auto Scaling Instances",
Type="Number"
))

###
#
# Elastic Load Balancer
Expand Down Expand Up @@ -251,15 +269,15 @@

vault_autoscaling_group = template.add_resource(AutoScalingGroup(
"VaultAutoScalingGroup",
DesiredCapacity=3,
DesiredCapacity=Ref(desired_instances_param),
HealthCheckGracePeriod=60,
HealthCheckType="EC2",
LaunchConfigurationName=Ref(vault_launch_config),
LoadBalancerNames=[
Ref(vault_load_balancer)
],
MaxSize=3,
MinSize=3,
MaxSize=Ref(maximum_instances_param),
MinSize=Ref(minimum_instances_param),
UpdatePolicy=UpdatePolicy(
AutoScalingRollingUpdate=AutoScalingRollingUpdate(
MaxBatchSize=1,
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/nike/cerberus/command/StackDelegate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Nike, Inc.
* Copyright (c) 2017 Nike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,6 +47,15 @@ public class StackDelegate {
required = true)
private String costcenter;

@Parameter(names = "--desired-instances", description = "Desired number of auto scaling instances.")
private int desiredInstances = 3;

@Parameter(names = "--max-instances", description = "Maximum number of auto scaling instances.")
private int maximumInstances = 3;

@Parameter(names = "--min-instances", description = "Minimum number of auto scaling instances")
private int minimumInstances = 3;

public String getAmiId() {
return amiId;
}
Expand All @@ -70,4 +79,16 @@ public String getOwnerEmail() {
public String getCostcenter() {
return costcenter;
}

public int getDesiredInstances() {
return desiredInstances;
}

public int getMaximumInstances() {
return maximumInstances;
}

public int getMinimumInstances() {
return minimumInstances;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Nike, Inc.
* Copyright (c) 2017 Nike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,6 +66,15 @@ public class UpdateStackCommand implements Command {
description = "Flag for overwriting existing CloudFormation template")
private boolean overwriteTemplate;

@Parameter(names = "--desired-instances", description = "Desired number of auto scaling instances.")
private Integer desiredInstances;

@Parameter(names = "--max-instances", description = "Maximum number of auto scaling instances.")
private Integer maximumInstances;

@Parameter(names = "--min-instances", description = "Minimum number of autos scaling instances")
private Integer minimumInstances;

@DynamicParameter(names = "-P", description = "Dynamic parameters for overriding the values for specific parameters in the CloudFormation.")
private Map<String, String> dynamicParameters = new HashMap<>();

Expand Down Expand Up @@ -105,6 +114,18 @@ public Map<String, String> getDynamicParameters() {
return dynamicParameters;
}

public Integer getDesiredInstances() {
return desiredInstances;
}

public Integer getMaximumInstances() {
return maximumInstances;
}

public Integer getMinimumInstances() {
return minimumInstances;
}

@Override
public String getCommandName() {
return COMMAND_NAME;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Nike, Inc.
* Copyright (c) 2017 Nike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,12 @@ public class LaunchConfigParametersDelegate {

private String userData;

private int desiredInstances;

private int maximumInstances;

private int minimumInstances;

public String getAmiId() {
return amiId;
}
Expand Down Expand Up @@ -64,4 +70,31 @@ public LaunchConfigParametersDelegate setUserData(String userData) {
this.userData = userData;
return this;
}

public int getDesiredInstances() {
return desiredInstances;
}

public LaunchConfigParametersDelegate setDesiredInstances(int desiredInstances) {
this.desiredInstances = desiredInstances;
return this;
}

public int getMaximumInstances() {
return maximumInstances;
}

public LaunchConfigParametersDelegate setMaximumInstances(int maximumInstances) {
this.maximumInstances = maximumInstances;
return this;
}

public int getMinimumInstances() {
return minimumInstances;
}

public LaunchConfigParametersDelegate setMinimumInstances(int minimumInstances) {
this.minimumInstances = minimumInstances;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Nike, Inc.
* Copyright (c) 2017 Nike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -108,6 +108,9 @@ public void run(final CreateCmsClusterCommand command) {
cmsParameters.getLaunchConfigParameters().setKeyPairName(command.getStackDelegate().getKeyPairName());
cmsParameters.getLaunchConfigParameters().setUserData(
ec2UserDataService.getUserData(StackName.CMS, command.getStackDelegate().getOwnerGroup()));
cmsParameters.getLaunchConfigParameters().setDesiredInstances(command.getStackDelegate().getDesiredInstances());
cmsParameters.getLaunchConfigParameters().setMinimumInstances(command.getStackDelegate().getMinimumInstances());
cmsParameters.getLaunchConfigParameters().setMaximumInstances(command.getStackDelegate().getMaximumInstances());

cmsParameters.getTagParameters().setTagEmail(command.getStackDelegate().getOwnerEmail());
cmsParameters.getTagParameters().setTagName(ConfigConstants.ENV_PREFIX + environmentMetadata.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Nike, Inc.
* Copyright (c) 2017 Nike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,6 +97,12 @@ public void run(final CreateConsulClusterCommand command) {
consulParameters.getLaunchConfigParameters().setKeyPairName(command.getStackDelegate().getKeyPairName());
consulParameters.getLaunchConfigParameters().setUserData(
ec2UserDataService.getUserData(StackName.CONSUL, command.getStackDelegate().getOwnerGroup()));
consulParameters.getLaunchConfigParameters().setDesiredInstances(
command.getStackDelegate().getDesiredInstances());
consulParameters.getLaunchConfigParameters().setMinimumInstances(
command.getStackDelegate().getMinimumInstances());
consulParameters.getLaunchConfigParameters().setMaximumInstances(
command.getStackDelegate().getMaximumInstances());

consulParameters.getTagParameters().setTagEmail(command.getStackDelegate().getOwnerEmail());
consulParameters.getTagParameters().setTagName(ConfigConstants.ENV_PREFIX + environmentMetadata.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Nike, Inc.
* Copyright (c) 2017 Nike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -185,6 +185,18 @@ private Map<String, String> getUpdateLaunchConfigParameters(final StackName stac
launchConfigParameters.getTagParameters().setTagCostcenter(command.getCostcenter());
}

if (command.getDesiredInstances() != null) {
launchConfigParameters.getLaunchConfigParameters().setDesiredInstances(command.getDesiredInstances());
}

if (command.getMinimumInstances() != null) {
launchConfigParameters.getLaunchConfigParameters().setMinimumInstances(command.getMinimumInstances());
}

if (command.getMaximumInstances() != null) {
launchConfigParameters.getLaunchConfigParameters().setMaximumInstances(command.getMaximumInstances());
}

updateSslConfigParameters(stackName, launchConfigParameters);

final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() {};
Expand Down
Loading

0 comments on commit be83885

Please sign in to comment.