Ejemplo n.º 1
0
 public Future<TerminateInstancesResult> terminateInstancesAsync(
     AmazonEC2Client client, Instance... instances) {
   List<String> ids =
       Arrays.stream(instances).map(i -> i.getInstanceId()).collect(Collectors.toList());
   TerminateInstancesRequest request = new TerminateInstancesRequest(ids);
   Future<TerminateInstancesResult> f =
       circuitBreaker.callWithCircuitBreaker(
           () -> Futures.future(() -> client.terminateInstances(request), executionContext));
   PartialFunction<Throwable, Future<TerminateInstancesResult>> recovery =
       new PFBuilder<Throwable, Future<TerminateInstancesResult>>()
           .match(
               AmazonClientException.class,
               ex -> ex.isRetryable(),
               ex -> terminateInstancesAsync(client, instances))
           .build();
   return f.recoverWith(recovery, executionContext);
 }
Ejemplo n.º 2
0
 public void terminateEC2(String... ec2id) {
   TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest();
   amazonClient.terminateInstances(terminateInstancesRequest.withInstanceIds(ec2id));
 }