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

Commit

Permalink
Add rolling reboot for Vault (#52)
Browse files Browse the repository at this point in the history
* Shorten reboot command name + add Vault reboot functionality
* Major version increase due to renaming of reboot command
  • Loading branch information
sdford authored Jun 29, 2017
1 parent 2d5e812 commit 3231e9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

group=com.nike
artifactId=cerberus-lifecycle-cli
version=1.7.0
version=2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
public class RollingRebootWithHealthCheckCommand implements Command {

public static final String COMMAND_NAME = "rolling-reboot-with-health-check";
public static final String COMMAND_NAME = "rolling-reboot";

@Parameter(names = {"--stack-name"}, required = true, description = "The stack name to reboot.")
private StackName stackName = StackName.CMS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class RollingRebootWithHealthCheckOperation implements Operation<RollingR

private final static ImmutableMap<String, String> HEALTH_CHECK_MAP = ImmutableMap.of(
StackName.CMS.getName(), "http://%s:8080/healthcheck",
StackName.GATEWAY.getName(), "https://%s:443/sys/health"
// TODO: Test that command works with remaining stacks
// StackName.VAULT.getName(), "https://%s:8200/v1/sys/health?standbyok",
// StackName.CONSUL.getName(), "https://%s:8500/v1/sys/health"
StackName.GATEWAY.getName(), "https://%s:443/sys/health",
StackName.VAULT.getName(), "https://%s:8200/v1/sys/health?standbyok"
// TODO: upgrade Consul and use new healthcheck
// StackName.CONSUL.getName(), "http://%s:8580/v1/status/peers"
);

private final static int DEFAULT_HTTP_TIMEOUT = 15;
Expand All @@ -57,6 +57,8 @@ public class RollingRebootWithHealthCheckOperation implements Operation<RollingR

private final static int EXPECTED_NUM_FAILURES_AFTER_REBOOT = 3;

private final static int EXPECTED_NUM_SUCCESSES_BEFORE_REBOOT = 1;

private final static int HEALTH_CHECK_FAILED_CODE = -1;

private final ConfigStore configStore;
Expand Down Expand Up @@ -118,16 +120,20 @@ public void run(final RollingRebootWithHealthCheckCommand command) {
* Reboot an instance and make sure it comes back healthy
*/
private void rebootInstance(StackName stackName, String autoScalingGroupId, Instance instance) {

final String healthCheckUrlTmpl = HEALTH_CHECK_MAP.get(stackName.getName());
final String healthCheckUrl = String.format(healthCheckUrlTmpl, instance.getPublicDnsName());

logger.info("Checking that instance health check is reachable...");
waitForHealthCheckStatusCode(healthCheckUrl, HttpStatus.OK, EXPECTED_NUM_SUCCESSES_BEFORE_REBOOT);

final String instanceId = instance.getInstanceId();
logger.info("Setting instance state to standby: {}", instanceId);
autoScalingService.setInstanceStateToStandby(autoScalingGroupId, instanceId);

logger.info("Rebooting instance: {}", instanceId);
ec2Service.rebootEc2Instance(instanceId);

final String healthCheckUrlTmpl = HEALTH_CHECK_MAP.get(stackName.getName());
final String healthCheckUrl = String.format(healthCheckUrlTmpl, instance.getPublicDnsName());

// wait for health check fail to confirm box reboot
logger.info("Waiting for health check failure to confirm reboot...");
waitForHealthCheckStatusCode(healthCheckUrl, HEALTH_CHECK_FAILED_CODE, EXPECTED_NUM_FAILURES_AFTER_REBOOT);
Expand Down Expand Up @@ -201,7 +207,7 @@ private int executeHealthCheck(final String healthCheckUrl) {
logger.debug("Health check returned status: {}, URL: {}", response.code(), healthCheckUrl);
return response.code();
} catch (IOException ioe) {
final String message = Chalk.on("Health check failed, Cause: {}, URL: {}").red().toString();
final String message = Chalk.on("Health check failed, Cause: \"{}\", URL: {}").red().toString();
logger.debug(message, ioe.getMessage(), healthCheckUrl);
}

Expand Down

0 comments on commit 3231e9d

Please sign in to comment.