You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by he...@apache.org on 2019/11/25 18:52:23 UTC
[geode-benchmarks] branch develop updated: rewrite
createSecurityGroup method in LaunchCluster to fix logic errors (#117)
This is an automated email from the ASF dual-hosted git repository.
heybales pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-benchmarks.git
The following commit(s) were added to refs/heads/develop by this push:
new 3d02d10 rewrite createSecurityGroup method in LaunchCluster to fix logic errors (#117)
3d02d10 is described below
commit 3d02d107ad04303dfb2f9db4ba0ec64703511ad3
Author: Helena Bales <hb...@pivotal.io>
AuthorDate: Mon Nov 25 10:52:17 2019 -0800
rewrite createSecurityGroup method in LaunchCluster to fix logic errors (#117)
---
.../geode/infrastructure/aws/LaunchCluster.java | 95 ++++++++++++++--------
1 file changed, 63 insertions(+), 32 deletions(-)
diff --git a/infrastructure/src/main/java/org/apache/geode/infrastructure/aws/LaunchCluster.java b/infrastructure/src/main/java/org/apache/geode/infrastructure/aws/LaunchCluster.java
index d6c7fbf..ca7c7ae 100644
--- a/infrastructure/src/main/java/org/apache/geode/infrastructure/aws/LaunchCluster.java
+++ b/infrastructure/src/main/java/org/apache/geode/infrastructure/aws/LaunchCluster.java
@@ -46,6 +46,7 @@ import software.amazon.awssdk.services.ec2.model.CreatePlacementGroupRequest;
import software.amazon.awssdk.services.ec2.model.CreateSecurityGroupRequest;
import software.amazon.awssdk.services.ec2.model.CreateSecurityGroupResponse;
import software.amazon.awssdk.services.ec2.model.CreateTagsRequest;
+import software.amazon.awssdk.services.ec2.model.CreateTagsResponse;
import software.amazon.awssdk.services.ec2.model.DescribeImagesRequest;
import software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest;
import software.amazon.awssdk.services.ec2.model.DescribeInstancesResponse;
@@ -73,7 +74,8 @@ import org.apache.geode.infrastructure.BenchmarkMetadata;
public class LaunchCluster {
private static final long MAX_WAIT_INTERVAL = 2000;
private static final int MAX_DESCRIBE_RETRIES = 5;
- private static final int MAX_CREATE_RETRIES = 2;
+ private static final int MAX_CREATE_RETRIES = 3;
+ private static final int MAX_TAG_RETRIES = 3;
static Ec2Client ec2 = Ec2Client.create();
public static void main(String[] args) throws IOException, InterruptedException {
@@ -265,43 +267,72 @@ public class LaunchCluster {
*/
private static void createSecurityGroup(String benchmarkTag, List<Tag> tags)
throws InterruptedException {
+ CreateSecurityGroupResponse csgr = null;
String groupId;
- for (int create_retries = 0;; create_retries++) {
- CreateSecurityGroupResponse csgr =
- ec2.createSecurityGroup(CreateSecurityGroupRequest.builder()
- .groupName(AwsBenchmarkMetadata.securityGroup(benchmarkTag))
- .description(AwsBenchmarkMetadata.securityGroup(benchmarkTag))
- .build());
-
- groupId = csgr.groupId();
- DescribeSecurityGroupsRequest describeSecurityGroupsRequest =
- DescribeSecurityGroupsRequest.builder().groupIds(groupId).build();
- DescribeSecurityGroupsResponse describeSecurityGroupsResponse;
-
- for (int describe_retries = 0; describe_retries < MAX_DESCRIBE_RETRIES; describe_retries++) {
- try {
- describeSecurityGroupsResponse =
- ec2.describeSecurityGroups(describeSecurityGroupsRequest);
-
- if (!describeSecurityGroupsResponse.securityGroups().isEmpty()) {
- System.out.println("TEST SecurityGroup with id '" + groupId
- + "' is created and visible to subsequent commands.");
- ec2.createTags(CreateTagsRequest.builder().resources(groupId).tags(tags).build());
- System.out.println("Security Group for cluster '" + benchmarkTag + "' created.");
- return;
- }
- } catch (Ec2Exception e) {
- System.out.println(e.getMessage());
- // will retry or return from the method
+ for (int create_retries = 0; create_retries < MAX_CREATE_RETRIES; create_retries++) {
+ try {
+ csgr =
+ ec2.createSecurityGroup(CreateSecurityGroupRequest.builder()
+ .groupName(AwsBenchmarkMetadata.securityGroup(benchmarkTag))
+ .description(AwsBenchmarkMetadata.securityGroup(benchmarkTag))
+ .build());
+ break;
+ } catch (Exception exception) {
+ // try again
+ }
+ }
+
+ if (csgr == null) {
+ throw new RuntimeException(
+ "Security Group was not created after " + MAX_CREATE_RETRIES + " attempts.");
+ }
+
+ groupId = csgr.groupId();
+ DescribeSecurityGroupsRequest describeSecurityGroupsRequest =
+ DescribeSecurityGroupsRequest.builder().groupIds(groupId).build();
+
+ DescribeSecurityGroupsResponse describeSecurityGroupsResponse = null;
+ for (int describeRetries = 0; describeRetries < MAX_DESCRIBE_RETRIES; describeRetries++) {
+ try {
+ describeSecurityGroupsResponse = ec2.describeSecurityGroups(describeSecurityGroupsRequest);
+
+ if (!describeSecurityGroupsResponse.securityGroups().isEmpty()) {
+ System.out.println("Security Group with id '" + groupId
+ + "' is created and visible to subsequent commands.");
+ break;
}
- Thread.sleep(Math.min(getWaitTimeExp(describe_retries), MAX_WAIT_INTERVAL));
+ } catch (Ec2Exception exception) {
+ // try again
}
- if (create_retries == (MAX_CREATE_RETRIES - 1)) {
- throw new RuntimeException("Security Group with id '" + groupId
- + "' was not created or is invisible to subsequent commands.");
+ Thread.sleep(Math.min(getWaitTimeExp(describeRetries), MAX_WAIT_INTERVAL));
+ }
+
+ if (describeSecurityGroupsResponse == null) {
+ throw new RuntimeException("Security Group with id '" + groupId + "' was not visible after "
+ + MAX_DESCRIBE_RETRIES + " attempts;");
+ }
+
+ CreateTagsResponse createTagResponse = null;
+ for (int tagRetries = 0; tagRetries < MAX_TAG_RETRIES; tagRetries++) {
+ try {
+ createTagResponse =
+ ec2.createTags(CreateTagsRequest.builder().resources(groupId).tags(tags).build());
+
+ if (createTagResponse != null) {
+ System.out.println("Tags for cluster '" + benchmarkTag + "' created.");
+ break;
+ }
+ } catch (Exception exception) {
+ // try again
}
}
+
+ if (createTagResponse == null) {
+ throw new RuntimeException("Tags for cluster '" + benchmarkTag + "' were not created after "
+ + MAX_TAG_RETRIES + " attempts.");
+ }
+
}
/*