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

Commit

Permalink
Fix reboot command name, help message, and response close
Browse files Browse the repository at this point in the history
  • Loading branch information
sdford committed Jun 6, 2017
1 parent 290c2cf commit c30afb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
/**
* Command to reboot the CMS cluster.
*/
@Parameters(commandNames = COMMAND_NAME, commandDescription = "Performs a safe rolling reboot on instances in the given cluster.")
@Parameters(
commandNames = COMMAND_NAME,
commandDescription = "Performs a safe rolling reboot on instances in the given cluster, checking that " +
"the previous instance is healthy before rebooting the next one."
)
public class RollingRebootWithHealthCheckCommand implements Command {

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

@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 @@ -13,6 +13,7 @@
import com.nike.cerberus.service.Ec2Service;
import com.nike.cerberus.store.ConfigStore;
import com.nike.vault.client.http.HttpStatus;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Expand Down Expand Up @@ -189,17 +190,16 @@ private int executeHealthCheck(final String healthCheckUrl) {
.readTimeout(DEFAULT_HTTP_TIMEOUT, DEFAULT_HTTP_TIMEOUT_UNIT)
.build();

Request requestBuilder = new Request.Builder()
final Request requestBuilder = new Request.Builder()
.url(healthCheckUrl)
.get()
.build();

try {
final Response response = okHttpClient.newCall(requestBuilder).execute();
final Call healthCheckCall = okHttpClient.newCall(requestBuilder);

try(final Response response = healthCheckCall.execute()) {
logger.debug("Health check returned status: {}, URL: {}", response.code(), healthCheckUrl);
int responseCode = response.code();
response.close();
return responseCode;
return response.code();
} catch (IOException ioe) {
final String message = Chalk.on("Health check failed, Cause: {}, URL: {}").red().toString();
logger.debug(message, ioe.getMessage(), healthCheckUrl);
Expand All @@ -212,14 +212,18 @@ private int executeHealthCheck(final String healthCheckUrl) {
public boolean isRunnable(final RollingRebootWithHealthCheckCommand command) {

final StackName stackName = command.getStackName();
final String stackNameStr = stackName.getName();
final String stackId = configStore.getStackId(stackName);
final Map<String, String> stackParameters = cloudFormationService.getStackParameters(stackId);

if (HEALTH_CHECK_MAP.containsKey(stackName.getName()) && stackParameters.containsKey(MIN_INSTANCES_STACK_PARAMETER_KEY)) {
if (! HEALTH_CHECK_MAP.containsKey(stackNameStr)) {
logger.error("Cannot reboot cluster: {}. Allowed stacks: {}", stackName, HEALTH_CHECK_MAP.keySet());
return false;
} else if (! stackParameters.containsKey(MIN_INSTANCES_STACK_PARAMETER_KEY)) {
logger.error("Could not find parameter 'minInstances' on stack: {}", stackId);
return false;
} else {
return true;
}

logger.error("Cannot reboot cluster: {}. Allowed stacks: {}", stackName, HEALTH_CHECK_MAP.keySet());
return false;
}
}

0 comments on commit c30afb4

Please sign in to comment.