|
72 | 72 |
|
73 | 73 | public class LaunchCluster { |
74 | 74 | private static final long MAX_WAIT_INTERVAL = 2000; |
75 | | - private static final int MAX_RETRIES = 5; |
| 75 | + private static final int MAX_DESCRIBE_RETRIES = 5; |
| 76 | + private static final int MAX_CREATE_RETRIES = 2; |
76 | 77 | static Ec2Client ec2 = Ec2Client.create(); |
77 | 78 |
|
78 | 79 | public static void main(String[] args) throws IOException, InterruptedException { |
@@ -264,38 +265,43 @@ private static void createLaunchTemplate(String benchmarkTag, Image newestImage) |
264 | 265 | */ |
265 | 266 | private static void createSecurityGroup(String benchmarkTag, List<Tag> tags) |
266 | 267 | throws InterruptedException { |
267 | | - CreateSecurityGroupResponse csgr = ec2.createSecurityGroup(CreateSecurityGroupRequest.builder() |
268 | | - .groupName(AwsBenchmarkMetadata.securityGroup(benchmarkTag)) |
269 | | - .description(AwsBenchmarkMetadata.securityGroup(benchmarkTag)) |
270 | | - .build()); |
271 | | - |
272 | | - String groupId = csgr.groupId(); |
273 | | - int retries = 0; |
274 | | - DescribeSecurityGroupsRequest describeSecurityGroupsRequest = |
275 | | - DescribeSecurityGroupsRequest.builder().groupIds(groupId).build(); |
276 | | - DescribeSecurityGroupsResponse describeSecurityGroupsResponse; |
277 | | - |
278 | | - while (true) { |
279 | | - try { |
280 | | - describeSecurityGroupsResponse = ec2.describeSecurityGroups(describeSecurityGroupsRequest); |
281 | | - |
282 | | - if (!describeSecurityGroupsResponse.securityGroups().isEmpty()) { |
283 | | - System.out.println("SecurityGroup with id '" + groupId |
284 | | - + "' is created and visible to subsequent commands."); |
285 | | - break; |
| 268 | + String groupId; |
| 269 | + |
| 270 | + for (int create_retries = 0;; create_retries++) { |
| 271 | + CreateSecurityGroupResponse csgr = |
| 272 | + ec2.createSecurityGroup(CreateSecurityGroupRequest.builder() |
| 273 | + .groupName(AwsBenchmarkMetadata.securityGroup(benchmarkTag)) |
| 274 | + .description(AwsBenchmarkMetadata.securityGroup(benchmarkTag)) |
| 275 | + .build()); |
| 276 | + |
| 277 | + groupId = csgr.groupId(); |
| 278 | + DescribeSecurityGroupsRequest describeSecurityGroupsRequest = |
| 279 | + DescribeSecurityGroupsRequest.builder().groupIds(groupId).build(); |
| 280 | + DescribeSecurityGroupsResponse describeSecurityGroupsResponse; |
| 281 | + |
| 282 | + for (int describe_retries = 0; describe_retries < MAX_DESCRIBE_RETRIES; describe_retries++) { |
| 283 | + try { |
| 284 | + describeSecurityGroupsResponse = |
| 285 | + ec2.describeSecurityGroups(describeSecurityGroupsRequest); |
| 286 | + |
| 287 | + if (!describeSecurityGroupsResponse.securityGroups().isEmpty()) { |
| 288 | + System.out.println("TEST SecurityGroup with id '" + groupId |
| 289 | + + "' is created and visible to subsequent commands."); |
| 290 | + ec2.createTags(CreateTagsRequest.builder().resources(groupId).tags(tags).build()); |
| 291 | + System.out.println("Security Group for cluster '" + benchmarkTag + "' created."); |
| 292 | + return; |
| 293 | + } |
| 294 | + } catch (Ec2Exception e) { |
| 295 | + System.out.println(e.getMessage()); |
| 296 | + // will retry or return from the method |
286 | 297 | } |
287 | | - } catch (Ec2Exception e) { |
288 | | - System.out.println(e.getMessage()); |
289 | | - // will retry or return from the method |
| 298 | + Thread.sleep(Math.min(getWaitTimeExp(describe_retries), MAX_WAIT_INTERVAL)); |
290 | 299 | } |
291 | | - if (++retries >= MAX_RETRIES) { |
| 300 | + if (create_retries == (MAX_CREATE_RETRIES - 1)) { |
292 | 301 | throw new RuntimeException("Security Group with id '" + groupId |
293 | 302 | + "' was not created or is invisible to subsequent commands."); |
294 | 303 | } |
295 | | - Thread.sleep(Math.min(getWaitTimeExp(retries), MAX_WAIT_INTERVAL)); |
296 | 304 | } |
297 | | - ec2.createTags(CreateTagsRequest.builder().resources(groupId).tags(tags).build()); |
298 | | - System.out.println("Security Group for cluster '" + benchmarkTag + "' created."); |
299 | 305 | } |
300 | 306 |
|
301 | 307 | /* |
|
0 commit comments