in infrastructure/src/main/java/org/apache/geode/infrastructure/aws/LaunchCluster.java [332:400]
private static void createSecurityGroup(String benchmarkTag, List<Tag> tags)
throws InterruptedException {
CreateSecurityGroupResponse csgr = null;
String groupId;
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;
}
} catch (Ec2Exception exception) {
// try again
}
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.");
}
}