Skip to content

Commit

Permalink
Update down command to work with gyro core 0.99.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Collins committed Jan 22, 2020
1 parent 37a7a03 commit 9777864
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (System.getenv('TRAVIS_BRANCH') && System.getenv('TRAVIS_PULL_REQUEST') == 'f
}

group = 'gyro'
version = '0.99.0-SNAPSHOT'
version = '0.99.1-SNAPSHOT'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -48,13 +48,13 @@ repositories {
}

dependencies {
api 'gyro:gyro-core:0.99.0-SNAPSHOT'
api 'gyro:gyro-core:0.99.1-SNAPSHOT'

implementation 'com.psddev:dari-util:3.3.607-xe0f27a'
implementation 'org.yaml:snakeyaml:1.24'
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.4.0.201906121030-r'
implementation 'us.monoid.web:resty:0.3.2'
implementation 'gyro:gyro-aws-provider:0.99.0-SNAPSHOT'
implementation 'gyro:gyro-aws-provider:0.99.1-SNAPSHOT'
implementation enforcedPlatform('software.amazon.awssdk:bom:2.5.70')
implementation 'software.amazon.awssdk:s3'
implementation 'software.amazon.awssdk:apache-client'
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/gyro/sample/command/DownCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package gyro.sample.command;

import java.util.List;
import java.util.stream.Collectors;

import gyro.aws.AwsCredentials;
import gyro.aws.autoscaling.AutoScalingGroupResource;
import gyro.aws.ec2.InstanceResource;
Expand All @@ -13,9 +16,6 @@
import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.awssdk.services.ec2.model.InstanceStateName;

import java.util.List;
import java.util.stream.Collectors;

@Command(name = "down", description = "Stop AWS instances and clear instances in autoscaling groups.")
public class DownCommand extends AbstractConfigCommand {

Expand Down Expand Up @@ -51,23 +51,28 @@ public void doExecute(RootScope current, RootScope pending, State state) {
autoscalingGroups.forEach(this::displayAutoScalingGroup);
}

if (GyroCore.ui().readBoolean(Boolean.FALSE, "\nAre you sure you want to stop instances and clear the auto scaling groups listed above?")) {
if (GyroCore.ui()
.readBoolean(
Boolean.FALSE,
"\nAre you sure you want to stop instances and clear the auto scaling groups listed above?")) {
instances.forEach(this::stopInstance);
autoscalingGroups.forEach(this::clearAutoscalingGroup);
}
}

private boolean isInstanceRunning(InstanceResource instance) {
return InstanceStateName.RUNNING.toString().equals(instance.getState());
return InstanceStateName.RUNNING.toString().equals(instance.getGyroInstanceState());
}

private void displayInstance(InstanceResource instance) {
GyroCore.ui().write("- [%s] %s\n", instance.getLocation(), instance.getInstanceId());
GyroCore.ui().write("- [%s] %s\n", instance.getGyroInstanceLocation(), instance.getGyroInstanceId());
}

private void stopInstance(InstanceResource instance) {
try (Ec2Client client = InstanceResource.createClient(Ec2Client.class, instance.credentials(AwsCredentials.class))) {
client.stopInstances(r -> r.instanceIds(instance.getInstanceId()));
try (Ec2Client client = InstanceResource.createClient(
Ec2Client.class,
instance.credentials(AwsCredentials.class))) {
client.stopInstances(r -> r.instanceIds(instance.getGyroInstanceId()));
}
}

Expand All @@ -80,7 +85,9 @@ private void displayAutoScalingGroup(AutoScalingGroupResource group) {
}

private void clearAutoscalingGroup(AutoScalingGroupResource group) {
try (AutoScalingClient client = AutoScalingGroupResource.createClient(AutoScalingClient.class, group.credentials(AwsCredentials.class))) {
try (AutoScalingClient client = AutoScalingGroupResource.createClient(
AutoScalingClient.class,
group.credentials(AwsCredentials.class))) {
client.updateAutoScalingGroup(r -> r
.autoScalingGroupName(group.getName())
.maxSize(0)
Expand Down

0 comments on commit 9777864

Please sign in to comment.