* @param size
* Size of the instance.
* @return Instance object in active state or NULL.
*/
public Instance getWorkingInstance(String zone, String name, String flavorId, int size) {
InstanceApi instanceApi = api.getInstanceApiForZone(zone);
for (int retries = 0; retries < 10; retries++) {
Instance instance = null;
try {
instance = instanceApi.create(flavorId, size, name);
} catch (Exception e) {
Uninterruptibles.sleepUninterruptibly(15, TimeUnit.SECONDS);
logger.error(Arrays.toString(e.getStackTrace()));
continue;
}
Instance updatedInstance = awaitAvailable(instance, instanceApi);
if (updatedInstance != null) {
return updatedInstance;
}
instanceApi.delete(instance.getId());
InstancePredicates.awaitDeleted(instanceApi).apply(instance);
}
return null;
}