mirror of https://github.com/apache/jclouds.git
Added optional timeout to EC2 listNodes strategy and made awaitCompletion update latch in finally block
This commit is contained in:
parent
315d5fb3ef
commit
4463b52051
|
@ -31,7 +31,6 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
@ -51,6 +50,7 @@ import com.google.common.base.Function;
|
|||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -58,10 +58,15 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
@Singleton
|
||||
public class EC2ListNodesStrategy implements ListNodesStrategy {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
|
||||
protected static Long maxTime;
|
||||
|
||||
protected final EC2AsyncClient client;
|
||||
protected final Supplier<Set<String>> regions;
|
||||
protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
|
||||
|
@ -100,7 +105,7 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
|
|||
return castToSpecificTypedFuture(client.getInstanceServices().describeInstancesInRegion(from));
|
||||
}
|
||||
|
||||
}, executor, null, logger, "reservations");
|
||||
}, executor, maxTime, logger, "reservations");
|
||||
|
||||
return concat(concat(reservations));
|
||||
}
|
||||
|
|
|
@ -137,8 +137,9 @@ public class FutureIterables {
|
|||
errors.incrementAndGet();
|
||||
logException(logger, logPrefix, total, complete.get(), errors.get(), start, e);
|
||||
errorMap.put(future.getKey(), e);
|
||||
} finally {
|
||||
doneSignal.countDown();
|
||||
}
|
||||
doneSignal.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,10 +149,11 @@ public class FutureIterables {
|
|||
}, exec);
|
||||
}
|
||||
try {
|
||||
if (maxTime != null)
|
||||
if (maxTime != null) {
|
||||
doneSignal.await(maxTime, TimeUnit.MILLISECONDS);
|
||||
else
|
||||
} else {
|
||||
doneSignal.await();
|
||||
}
|
||||
if (errors.get() > 0) {
|
||||
String message = message(logPrefix, total, complete.get(), errors.get(), start);
|
||||
RuntimeException exception = new RuntimeException(message);
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
@ -45,6 +44,7 @@ import org.jclouds.location.Region;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -76,7 +76,7 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
|
|||
.describeSpotInstanceRequestsInRegion(from);
|
||||
}
|
||||
|
||||
}, executor, null, logger, "reservations")), spotConverter), notNull());
|
||||
}, executor, maxTime, logger, "reservations")), spotConverter), notNull());
|
||||
|
||||
return concat(super.pollRunningInstances(), spots);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue