private static void deleteInstances()

in infrastructure/src/main/java/org/apache/geode/infrastructure/aws/DestroyCluster.java [105:146]


  private static void deleteInstances(String benchmarkTag) throws InterruptedException {
    // delete instances
    try {
      DescribeInstancesResponse dir = ec2.describeInstances(DescribeInstancesRequest.builder()
          .filters(Filter.builder()
              .name("tag:" + BenchmarkMetadata.PREFIX).values(benchmarkTag).build())
          .build());
      Stream<Instance> instanceStream = dir.reservations()
          .stream()
          .flatMap(reservation -> reservation.instances().stream());

      List<String> instanceIds = dir
          .reservations()
          .stream()
          .flatMap(reservation -> reservation
              .instances()
              .stream())
          .map(Instance::instanceId)
          .collect(Collectors.toList());

      ec2.terminateInstances(TerminateInstancesRequest.builder()
          .instanceIds(instanceIds)
          .build());
      System.out.println("Waiting for cluster instances to terminate.");
      while (ec2.describeInstances(DescribeInstancesRequest.builder()
          .instanceIds(instanceIds)
          .filters(Filter.builder()
              .name("instance-state-name")
              .values("pending", "running", "shutting-down", "stopping", "stopped")
              .build())
          .build()).reservations().stream().flatMap(reservation -> reservation.instances().stream())
          .count() > 0) {
        sleep(AwsBenchmarkMetadata.POLL_INTERVAL);
        System.out.println("Continuing to wait.");
      }

      System.out.println("Instances for cluster '" + benchmarkTag + "' deleted.");
    } catch (Exception e) {
      System.out.println("We got an exception while deleting the instances");
      System.out.println("Exception message: " + e);
    }
  }