make FutureIterables covariant compatible + update tests

This commit is contained in:
danikov 2012-04-16 13:18:41 +01:00
parent 5a3d2a11d6
commit fff1c7dc2d
35 changed files with 222 additions and 168 deletions

View File

@ -72,7 +72,7 @@ public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBala
@Override @Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() { public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
return transform(concat(transformParallel(regions.get(), new Function<String, Future<Set<LoadBalancer>>>() { return transform(concat(transformParallel(regions.get(), new Function<String, Future<? extends Set<LoadBalancer>>>() {
@Override @Override
public ListenableFuture<Set<LoadBalancer>> apply(String from) { public ListenableFuture<Set<LoadBalancer>> apply(String from) {

View File

@ -56,6 +56,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Iterables2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -170,8 +171,8 @@ public class CloudSigmaComputeServiceAdapter implements
*/ */
@Override @Override
public Iterable<DriveInfo> listImages() { public Iterable<DriveInfo> listImages() {
Iterable<DriveInfo> drives = transformParallel(client.listStandardDrives(), Iterable<? extends DriveInfo> drives = transformParallel(client.listStandardDrives(),
new Function<String, Future<DriveInfo>>() { new Function<String, Future<? extends DriveInfo>>() {
@Override @Override
public Future<DriveInfo> apply(String input) { public Future<DriveInfo> apply(String input) {
@ -190,7 +191,7 @@ public class CloudSigmaComputeServiceAdapter implements
return "seedDriveCache()"; return "seedDriveCache()";
} }
}, executor, null, logger, "drives"); }, executor, null, logger, "drives");
return filter(drives, PREINSTALLED_DISK); return Iterables2.concreteCopy(filter(drives, PREINSTALLED_DISK));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -65,7 +65,7 @@ public class DescribeImagesParallel implements
Iterable<Entry<String, DescribeImagesOptions>> queries) { Iterable<Entry<String, DescribeImagesOptions>> queries) {
return concat(transformParallel( return concat(transformParallel(
queries, queries,
new Function<Entry<String, DescribeImagesOptions>, Future<Set<? extends org.jclouds.ec2.domain.Image>>>() { new Function<Entry<String, DescribeImagesOptions>, Future<? extends Set<? extends org.jclouds.ec2.domain.Image>>>() {
@Override @Override
public Future<Set<? extends org.jclouds.ec2.domain.Image>> apply( public Future<Set<? extends org.jclouds.ec2.domain.Image>> apply(

View File

@ -92,7 +92,7 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
protected Iterable<? extends RunningInstance> pollRunningInstances() { protected Iterable<? extends RunningInstance> pollRunningInstances() {
Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel( Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel(
regions.get(), new Function<String, Future<Set<? extends Reservation<? extends RunningInstance>>>>() { regions.get(), new Function<String, Future<? extends Set<? extends Reservation<? extends RunningInstance>>>>() {
@Override @Override
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) { public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {

View File

@ -58,6 +58,7 @@ import org.jclouds.elasticstack.domain.ServerStatus;
import org.jclouds.elasticstack.domain.WellKnownImage; import org.jclouds.elasticstack.domain.WellKnownImage;
import org.jclouds.elasticstack.reference.ElasticStackConstants; import org.jclouds.elasticstack.reference.ElasticStackConstants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Iterables2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -162,11 +163,11 @@ public class ElasticStackComputeServiceAdapter implements
*/ */
@Override @Override
public Iterable<DriveInfo> listImages() { public Iterable<DriveInfo> listImages() {
Iterable<DriveInfo> drives = transformParallel(preinstalledImages.keySet(), Iterable<? extends DriveInfo> drives = transformParallel(preinstalledImages.keySet(),
new Function<String, Future<DriveInfo>>() { new Function<String, Future<? extends DriveInfo>>() {
@Override @Override
public Future<DriveInfo> apply(String input) { public Future<? extends DriveInfo> apply(String input) {
try { try {
return Futures.immediateFuture(cache.getUnchecked(input)); return Futures.immediateFuture(cache.getUnchecked(input));
} catch (CacheLoader.InvalidCacheLoadException e) { } catch (CacheLoader.InvalidCacheLoadException e) {
@ -183,7 +184,7 @@ public class ElasticStackComputeServiceAdapter implements
} }
}, executor, null, logger, "drives"); }, executor, null, logger, "drives");
return filter(drives, notNull()); return Iterables2.concreteCopy(filter(drives, notNull()));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -27,12 +27,12 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getLast; import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient; import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.util.Maps2.uniqueIndex;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
@ -119,6 +119,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Lists;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
@ -287,26 +288,27 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Singleton @Singleton
public static class OrgCatalogSupplier implements public static class OrgCatalogSupplier implements
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> { Supplier<Map<String, Map<String, Catalog>>> {
protected final Supplier<Map<String, Org>> orgSupplier; protected final Supplier<Map<String, Org>> orgSupplier;
protected final Function<Org, Iterable<org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg; protected final Function<Org, Iterable<Catalog>> allCatalogsInOrg;
@Inject @Inject
protected OrgCatalogSupplier(Supplier<Map<String, Org>> orgSupplier, protected OrgCatalogSupplier(Supplier<Map<String, Org>> orgSupplier,
Function<Org, Iterable<org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) { Function<Org, Iterable<Catalog>> allCatalogsInOrg) {
this.orgSupplier = orgSupplier; this.orgSupplier = orgSupplier;
this.allCatalogsInOrg = allCatalogsInOrg; this.allCatalogsInOrg = allCatalogsInOrg;
} }
@Override @Override
public Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>> get() { public Map<String, Map<String, Catalog>> get() {
return transformValues( return transformValues(
transformValues(orgSupplier.get(), allCatalogsInOrg), transformValues(orgSupplier.get(), allCatalogsInOrg),
new Function<Iterable<org.jclouds.vcloud.domain.Catalog>, Map<String, org.jclouds.vcloud.domain.Catalog>>() { new Function<Iterable<? extends Catalog>,
Map<String, Catalog>>() {
@Override @Override
public Map<String, org.jclouds.vcloud.domain.Catalog> apply( public Map<String, Catalog> apply(
Iterable<org.jclouds.vcloud.domain.Catalog> from) { Iterable<? extends Catalog> from) {
return uniqueIndex(from, name); return uniqueIndex(from, name);
} }
@ -338,37 +340,37 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<URI, org.jclouds.vcloud.domain.VDC>> provideURIToVDC( protected Supplier<Map<URI, VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
URItoVDC supplier) { URItoVDC supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, org.jclouds.vcloud.domain.VDC>>( return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, VDC>>(
authException, seconds, supplier); authException, seconds, supplier);
} }
@Singleton @Singleton
public static class URItoVDC implements Supplier<Map<URI, org.jclouds.vcloud.domain.VDC>> { public static class URItoVDC implements Supplier<Map<URI, VDC>> {
private final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap; private final Supplier<Map<String, Map<String, VDC>>> orgVDCMap;
@Inject @Inject
URItoVDC(Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap) { URItoVDC(Supplier<Map<String, Map<String, VDC>>> orgVDCMap) {
this.orgVDCMap = orgVDCMap; this.orgVDCMap = orgVDCMap;
} }
@Override @Override
public Map<URI, org.jclouds.vcloud.domain.VDC> get() { public Map<URI, VDC> get() {
return uniqueIndex(concat(transform(orgVDCMap.get().values(), return uniqueIndex(concat(transform(orgVDCMap.get().values(),
new Function<Map<String, org.jclouds.vcloud.domain.VDC>, Iterable<org.jclouds.vcloud.domain.VDC>>() { new Function<Map<String, VDC>, Iterable<VDC>>() {
@Override @Override
public Iterable<org.jclouds.vcloud.domain.VDC> apply( public Iterable<VDC> apply(
Map<String, org.jclouds.vcloud.domain.VDC> from) { Map<String, VDC> from) {
return from.values(); return from.values();
} }
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() { })), new Function<VDC, URI>() {
@Override @Override
public URI apply(org.jclouds.vcloud.domain.VDC from) { public URI apply(VDC from) {
return from.getHref(); return from.getHref();
} }
@ -447,43 +449,43 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache( protected Supplier<Map<String, Map<String, Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogSupplier supplier) { OrgCatalogSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>>( return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Catalog>>>(
authException, seconds, supplier); authException, seconds, supplier);
} }
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache( protected Supplier<Map<String, Map<String, VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgVDCSupplier supplier) { OrgVDCSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>>( return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, VDC>>>(
authException, seconds, supplier); authException, seconds, supplier);
} }
@Singleton @Singleton
public static class OrgVDCSupplier implements Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> { public static class OrgVDCSupplier implements Supplier<Map<String, Map<String, VDC>>> {
protected final Supplier<Map<String, Org>> orgSupplier; protected final Supplier<Map<String, Org>> orgSupplier;
private final Function<Org, Iterable<org.jclouds.vcloud.domain.VDC>> allVDCsInOrg; private final Function<Org, Iterable<VDC>> allVDCsInOrg;
@Inject @Inject
protected OrgVDCSupplier(Supplier<Map<String, Org>> orgSupplier, protected OrgVDCSupplier(Supplier<Map<String, Org>> orgSupplier,
Function<Org, Iterable<org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) { Function<Org, Iterable<VDC>> allVDCsInOrg) {
this.orgSupplier = orgSupplier; this.orgSupplier = orgSupplier;
this.allVDCsInOrg = allVDCsInOrg; this.allVDCsInOrg = allVDCsInOrg;
} }
@Override @Override
public Map<String, Map<String, org.jclouds.vcloud.domain.VDC>> get() { public Map<String, Map<String, VDC>> get() {
return transformValues(transformValues(orgSupplier.get(), allVDCsInOrg), return transformValues(transformValues(orgSupplier.get(), allVDCsInOrg),
new Function<Iterable<org.jclouds.vcloud.domain.VDC>, Map<String, org.jclouds.vcloud.domain.VDC>>() { new Function<Iterable<? extends VDC>, Map<String, VDC>>() {
@Override @Override
public Map<String, org.jclouds.vcloud.domain.VDC> apply( public Map<String, VDC> apply(
Iterable<org.jclouds.vcloud.domain.VDC> from) { Iterable<? extends VDC> from) {
return uniqueIndex(from, name); return uniqueIndex(Lists.newArrayList(from), name);
} }
}); });
@ -492,33 +494,33 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Singleton @Singleton
public static class OrgCatalogItemSupplier implements public static class OrgCatalogItemSupplier implements
Supplier<Map<String, Map<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>>>> { Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> {
protected final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> catalogSupplier; protected final Supplier<Map<String, Map<String, Catalog>>> catalogSupplier;
protected final Function<org.jclouds.vcloud.domain.Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog; protected final Function<Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog;
@Inject @Inject
protected OrgCatalogItemSupplier( protected OrgCatalogItemSupplier(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> catalogSupplier, Supplier<Map<String, Map<String, Catalog>>> catalogSupplier,
Function<org.jclouds.vcloud.domain.Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog) { Function<Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog) {
this.catalogSupplier = catalogSupplier; this.catalogSupplier = catalogSupplier;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
} }
@Override @Override
public Map<String, Map<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>>> get() { public Map<String, Map<String, Map<String, CatalogItem>>> get() {
return transformValues( return transformValues(
catalogSupplier.get(), catalogSupplier.get(),
new Function<Map<String, org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>>>() { new Function<Map<String, Catalog>, Map<String, Map<String, CatalogItem>>>() {
@Override @Override
public Map<String, Map<String, CatalogItem>> apply( public Map<String, Map<String, CatalogItem>> apply(
Map<String, org.jclouds.vcloud.domain.Catalog> from) { Map<String, Catalog> from) {
return transformValues( return transformValues(
from, from,
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, org.jclouds.vcloud.domain.CatalogItem>>() { new Function<Catalog, Map<String, CatalogItem>>() {
@Override @Override
public Map<String, CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) { public Map<String, CatalogItem> apply(Catalog from) {
return uniqueIndex(filter(allCatalogItemsInCatalog.apply(from), notNull()), name); return uniqueIndex(filter(allCatalogItemsInCatalog.apply(from), notNull()), name);
} }
}); });
@ -530,10 +532,10 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<String, Map<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache( protected Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> provideOrgCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogItemSupplier supplier) { OrgCatalogItemSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>>>>( return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, CatalogItem>>>>(
authException, seconds, supplier); authException, seconds, supplier);
} }

View File

@ -31,6 +31,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Iterables2;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
@ -60,14 +61,14 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<Cata
@Override @Override
public Iterable<CatalogItem> apply(Catalog from) { public Iterable<CatalogItem> apply(Catalog from) {
Iterable<CatalogItem> catalogItems = transformParallel(filter(from.values(), new Predicate<ReferenceType>() { Iterable<? extends CatalogItem> catalogItems = transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
@Override @Override
public boolean apply(ReferenceType input) { public boolean apply(ReferenceType input) {
return input.getType().equals(VCloudMediaType.CATALOGITEM_XML); return input.getType().equals(VCloudMediaType.CATALOGITEM_XML);
} }
}), new Function<ReferenceType, Future<CatalogItem>>() { }), new Function<ReferenceType, Future<? extends CatalogItem>>() {
@Override @Override
public Future<CatalogItem> apply(ReferenceType from) { public Future<CatalogItem> apply(ReferenceType from) {
@ -75,7 +76,7 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<Cata
} }
}, executor, null, logger, "catalogItems in " + from.getHref()); }, executor, null, logger, "catalogItems in " + from.getHref());
return catalogItems; return Iterables2.concreteCopy(catalogItems);
} }
} }

View File

@ -48,9 +48,9 @@ public class AllCatalogItemsInOrg implements Function<Org, Iterable<CatalogItem>
@Override @Override
public Iterable<CatalogItem> apply(Org from) { public Iterable<CatalogItem> apply(Org from) {
return Iterables.concat(Iterables.transform(allCatalogsInOrg.apply(from), return Iterables.concat(Iterables.transform(allCatalogsInOrg.apply(from),
new Function<Catalog, Iterable<CatalogItem>>() { new Function<Catalog, Iterable<? extends CatalogItem>>() {
@Override @Override
public Iterable<CatalogItem> apply(Catalog from) { public Iterable<? extends CatalogItem> apply(Catalog from) {
return allCatalogItemsInCatalog.apply(from); return allCatalogItemsInCatalog.apply(from);
} }

View File

@ -30,6 +30,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Iterables2;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
@ -56,14 +57,14 @@ public class AllCatalogsInOrg implements Function<Org, Iterable<Catalog>> {
@Override @Override
public Iterable<Catalog> apply(final Org org) { public Iterable<Catalog> apply(final Org org) {
Iterable<Catalog> catalogs = transformParallel(org.getCatalogs().values(), Iterable<? extends Catalog> catalogs = transformParallel(org.getCatalogs().values(),
new Function<ReferenceType, Future<Catalog>>() { new Function<ReferenceType, Future<? extends Catalog>>() {
@Override @Override
public Future<Catalog> apply(ReferenceType from) { public Future<Catalog> apply(ReferenceType from) {
return (Future<Catalog>) aclient.getCatalogClient().getCatalog(from.getHref()); return aclient.getCatalogClient().getCatalog(from.getHref());
} }
}, executor, null, logger, "catalogs in " + org.getName()); }, executor, null, logger, "catalogs in " + org.getName());
return catalogs; return Iterables2.concreteCopy(catalogs);
} }
} }

View File

@ -30,6 +30,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Iterables2;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
@ -41,7 +42,7 @@ import com.google.common.base.Function;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class AllVDCsInOrg implements Function<Org, Iterable<org.jclouds.vcloud.domain.VDC>> { public class AllVDCsInOrg implements Function<Org, Iterable<VDC>> {
@Resource @Resource
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
@ -58,14 +59,14 @@ public class AllVDCsInOrg implements Function<Org, Iterable<org.jclouds.vcloud.d
public Iterable<VDC> apply(final Org org) { public Iterable<VDC> apply(final Org org) {
Iterable<VDC> catalogItems = transformParallel(org.getVDCs().values(), Iterable<VDC> catalogItems = transformParallel(org.getVDCs().values(),
new Function<ReferenceType, Future<org.jclouds.vcloud.domain.VDC>>() { new Function<ReferenceType, Future<? extends VDC>>() {
@Override @Override
public Future<VDC> apply(ReferenceType from) { public Future<? extends VDC> apply(ReferenceType from) {
return aclient.getVDCClient().getVDC(from.getHref()); return aclient.getVDCClient().getVDC(from.getHref());
} }
}, executor, null, logger, "vdcs in org " + org.getName()); }, executor, null, logger, "vdcs in org " + org.getName());
return catalogItems; return Iterables2.concreteCopy(catalogItems);
} }
} }

View File

@ -35,6 +35,7 @@ import org.jclouds.Constants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Iterables2;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
@ -65,7 +66,7 @@ public class OrgsForLocations implements Function<Iterable<Location>, Iterable<
@Override @Override
public Iterable<Org> apply(Iterable<Location> from) { public Iterable<Org> apply(Iterable<Location> from) {
return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() { return Iterables2.concreteCopy(transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() {
@Override @Override
public boolean apply(Location input) { public boolean apply(Location input) {
@ -79,14 +80,14 @@ public class OrgsForLocations implements Function<Iterable<Location>, Iterable<
return URI.create(from.getParent().getId()); return URI.create(from.getParent().getId());
} }
})), new Function<URI, Future<Org>>() { })), new Function<URI, Future<? extends Org>>() {
@Override @Override
public Future<Org> apply(URI from) { public Future<Org> apply(URI from) {
return aclient.getOrgClient().getOrg(from); return aclient.getOrgClient().getOrg(from);
} }
}, executor, null, logger, "organizations for uris"); }, executor, null, logger, "organizations for uris"));
} }
} }

View File

@ -30,6 +30,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Iterables2;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
@ -53,14 +54,14 @@ public class OrgsForNames implements Function<Iterable<String>, Iterable<Org>> {
@Override @Override
public Iterable<Org> apply(Iterable<String> from) { public Iterable<Org> apply(Iterable<String> from) {
return transformParallel(from, new Function<String, Future<Org>>() { return Iterables2.concreteCopy(transformParallel(from, new Function<String, Future<? extends Org>>() {
@Override @Override
public Future<Org> apply(String from) { public Future<Org> apply(String from) {
return aclient.getOrgClient().findOrgNamed(from); return aclient.getOrgClient().findOrgNamed(from);
} }
}, executor, null, logger, "organizations for names"); }, executor, null, logger, "organizations for names"));
} }
} }

View File

@ -36,6 +36,7 @@ import org.jclouds.concurrent.ExceptionParsingListenableFuture;
import org.jclouds.concurrent.Futures; import org.jclouds.concurrent.Futures;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.util.Iterables2;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.CatalogItem;
@ -78,14 +79,14 @@ public class VAppTemplatesForCatalogItems implements Function<Iterable<CatalogIt
@Override @Override
public Iterable<VAppTemplate> apply(Iterable<CatalogItem> from) { public Iterable<VAppTemplate> apply(Iterable<CatalogItem> from) {
return transformParallel(filter(from, new Predicate<CatalogItem>() { return Iterables2.concreteCopy(transformParallel(filter(from, new Predicate<CatalogItem>() {
@Override @Override
public boolean apply(CatalogItem input) { public boolean apply(CatalogItem input) {
return input.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML); return input.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML);
} }
}), new Function<CatalogItem, Future<VAppTemplate>>() { }), new Function<CatalogItem, Future<? extends VAppTemplate>>() {
@Override @Override
public Future<VAppTemplate> apply(CatalogItem from) { public Future<VAppTemplate> apply(CatalogItem from) {
@ -94,7 +95,7 @@ public class VAppTemplatesForCatalogItems implements Function<Iterable<CatalogIt
returnNullOnAuthorizationException); returnNullOnAuthorizationException);
} }
}, executor, null, logger, "vappTemplates in"); }, executor, null, logger, "vappTemplates in"));
} }
} }

View File

@ -25,6 +25,7 @@ import static com.google.common.collect.Iterables.filter;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.util.Iterables2;
import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
@ -53,7 +54,7 @@ public class VAppTemplatesInOrg implements Function<Org, Iterable<VAppTemplate>>
@Override @Override
public Iterable<VAppTemplate> apply(Org from) { public Iterable<VAppTemplate> apply(Org from) {
Iterable<CatalogItem> catalogs = allCatalogItemsInOrg.apply(from); Iterable<CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
Iterable<VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs); Iterable<VAppTemplate> vAppTemplates = Iterables2.concreteCopy(vAppTemplatesForCatalogItems.apply(catalogs));
return filter(vAppTemplates, and(notNull(), new Predicate<VAppTemplate>(){ return filter(vAppTemplates, and(notNull(), new Predicate<VAppTemplate>(){
//TODO: test this //TODO: test this

View File

@ -69,8 +69,8 @@ public class VAppTemplatesSupplier implements Supplier<Set<VAppTemplate>> {
@Override @Override
public Set<VAppTemplate> get() { public Set<VAppTemplate> get() {
Iterable<Org> orgs = checkNotNull(orgMap.get().values(), "orgs"); Iterable<Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<Iterable<VAppTemplate>> images = transformParallel(orgs, Iterable<? extends Iterable<VAppTemplate>> images = transformParallel(orgs,
new Function<Org, Future<Iterable<VAppTemplate>>>() { new Function<Org, Future<? extends Iterable<VAppTemplate>>>() {
@Override @Override
public Future<Iterable<VAppTemplate>> apply(final Org from) { public Future<Iterable<VAppTemplate>> apply(final Org from) {

View File

@ -43,6 +43,7 @@ import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudVersionsClient; import org.jclouds.vcloud.VCloudVersionsClient;
import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.domain.AllocationModel; import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
@ -257,11 +258,11 @@ public abstract class BaseVCloudAsyncClientTest<T> extends BaseAsyncClientTest<T
} }
@Override @Override
public Map<String, Map<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>>> get() { public Map<String, Map<String, Map<String, CatalogItem>>> get() {
return ImmutableMap.<String, Map<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>>> of( return ImmutableMap.<String, Map<String, Map<String, CatalogItem>>> of(
ORG_REF.getName(), ImmutableMap ORG_REF.getName(), ImmutableMap
.<String, Map<String, org.jclouds.vcloud.domain.CatalogItem>> of(CATALOG_REF .<String, Map<String, CatalogItem>> of(CATALOG_REF
.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of( .getName(), ImmutableMap.<String, CatalogItem> of(
"template", "template",
new CatalogItemImpl("template", URI new CatalogItemImpl("template", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description", .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description",

View File

@ -42,6 +42,7 @@ import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -83,21 +84,21 @@ public class FetchBlobMetadata implements Function<PageSet<? extends StorageMeta
public PageSet<? extends StorageMetadata> apply(PageSet<? extends StorageMetadata> in) { public PageSet<? extends StorageMetadata> apply(PageSet<? extends StorageMetadata> in) {
checkState(container != null, "container name should be initialized"); checkState(container != null, "container name should be initialized");
Iterable<BlobMetadata> returnv = transformParallel(Iterables.filter(in, new Predicate<StorageMetadata>() { Iterable<BlobMetadata> returnv = Lists.newArrayList(transformParallel(Iterables.filter(in, new Predicate<StorageMetadata>() {
@Override @Override
public boolean apply(StorageMetadata input) { public boolean apply(StorageMetadata input) {
return input.getType() == StorageType.BLOB; return input.getType() == StorageType.BLOB;
} }
}), new Function<StorageMetadata, Future<BlobMetadata>>() { }), new Function<StorageMetadata, Future<? extends BlobMetadata>>() {
@Override @Override
public Future<BlobMetadata> apply(StorageMetadata from) { public Future<BlobMetadata> apply(StorageMetadata from) {
return ablobstore.blobMetadata(container, from.getName()); return ablobstore.blobMetadata(container, from.getName());
} }
}, userExecutor, maxTime, logger, String.format("getting metadata from containerName: %s", container)); }, userExecutor, maxTime, logger, String.format("getting metadata from containerName: %s", container)));
return new PageSetImpl<BlobMetadata>(returnv, in.getNextMarker()); return new PageSetImpl<BlobMetadata>(returnv, in.getNextMarker());
} }

View File

@ -75,7 +75,7 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
public Iterable<Blob> execute(final String container, ListContainerOptions options) { public Iterable<Blob> execute(final String container, ListContainerOptions options) {
Iterable<? extends BlobMetadata> list = getAllBlobMetadata.execute(container, options); Iterable<? extends BlobMetadata> list = getAllBlobMetadata.execute(container, options);
return transformParallel(list, new Function<BlobMetadata, Future<Blob>>() { return transformParallel(list, new Function<BlobMetadata, Future<? extends Blob>>() {
@Override @Override
public Future<Blob> apply(BlobMetadata from) { public Future<Blob> apply(BlobMetadata from) {

View File

@ -69,8 +69,8 @@ public class VCloudHardwareSupplier implements Supplier<Set<? extends Hardware>>
@Override @Override
public Set<? extends Hardware> get() { public Set<? extends Hardware> get() {
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs"); Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<Iterable<? extends Hardware>> sizes = transformParallel(orgs, Iterable<? extends Iterable<? extends Hardware>> sizes = transformParallel(orgs,
new Function<Org, Future<Iterable<? extends Hardware>>>() { new Function<Org, Future<? extends Iterable<? extends Hardware>>>() {
@Override @Override
public Future<Iterable<? extends Hardware>> apply(final Org from) { public Future<Iterable<? extends Hardware>> apply(final Org from) {

View File

@ -69,8 +69,8 @@ public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
@Override @Override
public Set<? extends Image> get() { public Set<? extends Image> get() {
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs"); Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<Iterable<? extends Image>> images = transformParallel(orgs, Iterable<? extends Iterable<? extends Image>> images = transformParallel(orgs,
new Function<Org, Future<Iterable<? extends Image>>>() { new Function<Org, Future<? extends Iterable<? extends Image>>>() {
@Override @Override
public Future<Iterable<? extends Image>> apply(final Org from) { public Future<Iterable<? extends Image>> apply(final Org from) {

View File

@ -61,14 +61,14 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<? ex
@Override @Override
public Iterable<? extends CatalogItem> apply(Catalog from) { public Iterable<? extends CatalogItem> apply(Catalog from) {
Iterable<CatalogItem> catalogItems = transformParallel(filter(from.values(), new Predicate<ReferenceType>() { Iterable<? extends CatalogItem> catalogItems = transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
@Override @Override
public boolean apply(ReferenceType input) { public boolean apply(ReferenceType input) {
return input.getType().equals(TerremarkVCloudMediaType.CATALOGITEM_XML); return input.getType().equals(TerremarkVCloudMediaType.CATALOGITEM_XML);
} }
}), new Function<ReferenceType, Future<CatalogItem>>() { }), new Function<ReferenceType, Future<? extends CatalogItem>>() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override

View File

@ -56,8 +56,8 @@ public class AllCatalogsInOrg implements Function<Org, Iterable<? extends Catalo
@Override @Override
public Iterable<? extends Catalog> apply(final Org org) { public Iterable<? extends Catalog> apply(final Org org) {
Iterable<Catalog> catalogs = transformParallel(org.getCatalogs().values(), Iterable<? extends Catalog> catalogs = transformParallel(org.getCatalogs().values(),
new Function<ReferenceType, Future<Catalog>>() { new Function<ReferenceType, Future<? extends Catalog>>() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Future<Catalog> apply(ReferenceType from) { public Future<Catalog> apply(ReferenceType from) {

View File

@ -56,12 +56,11 @@ public class AllVDCsInOrg implements Function<Org, Iterable<? extends org.jcloud
@Override @Override
public Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(final Org org) { public Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(final Org org) {
Iterable<org.jclouds.trmk.vcloud_0_8.domain.VDC> catalogItems = transformParallel(org.getVDCs().values(), Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> catalogItems = transformParallel(org.getVDCs().values(),
new Function<ReferenceType, Future<org.jclouds.trmk.vcloud_0_8.domain.VDC>>() { new Function<ReferenceType, Future<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>() {
@SuppressWarnings("unchecked")
@Override @Override
public Future<org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(ReferenceType from) { public Future<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(ReferenceType from) {
return (Future<org.jclouds.trmk.vcloud_0_8.domain.VDC>) aclient.getVDC(from.getHref()); return aclient.getVDC(from.getHref());
} }
}, executor, null, logger, "vdcs in org " + org.getName()); }, executor, null, logger, "vdcs in org " + org.getName());

View File

@ -79,12 +79,10 @@ public class OrgsForLocations implements Function<Iterable<? extends Location>,
return URI.create(from.getParent().getId()); return URI.create(from.getParent().getId());
} }
})), new Function<URI, Future<Org>>() { })), new Function<URI, Future<? extends Org>>() {
@SuppressWarnings("unchecked")
@Override @Override
public Future<Org> apply(URI from) { public Future<? extends Org> apply(URI from) {
return (Future<Org>) aclient.getOrg(from); return aclient.getOrg(from);
} }
}, executor, null, logger, "organizations for uris"); }, executor, null, logger, "organizations for uris");

View File

@ -53,12 +53,10 @@ public class OrgsForNames implements Function<Iterable<String>, Iterable<? exten
@Override @Override
public Iterable<? extends Org> apply(Iterable<String> from) { public Iterable<? extends Org> apply(Iterable<String> from) {
return transformParallel(from, new Function<String, Future<Org>>() { return transformParallel(from, new Function<String, Future<? extends Org>>() {
@SuppressWarnings("unchecked")
@Override @Override
public Future<Org> apply(String from) { public Future<? extends Org> apply(String from) {
return (Future<Org>) aclient.findOrgNamed(from); return aclient.findOrgNamed(from);
} }
}, executor, null, logger, "organizations for names"); }, executor, null, logger, "organizations for names");

View File

@ -68,12 +68,10 @@ public class VAppTemplatesForCatalogItems implements
return input.getEntity().getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML); return input.getEntity().getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML);
} }
}), new Function<CatalogItem, Future<VAppTemplate>>() { }), new Function<CatalogItem, Future<? extends VAppTemplate>>() {
@SuppressWarnings("unchecked")
@Override @Override
public Future<VAppTemplate> apply(CatalogItem from) { public Future<? extends VAppTemplate> apply(CatalogItem from) {
return (Future<VAppTemplate>) aclient.getVAppTemplate(from.getEntity().getHref()); return aclient.getVAppTemplate(from.getEntity().getHref());
} }
}, executor, null, logger, "vappTemplates in"); }, executor, null, logger, "vappTemplates in");

View File

@ -69,12 +69,10 @@ public class VAppTemplatesForResourceEntities implements
return input.getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML); return input.getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML);
} }
}), new Function<ReferenceType, Future<VAppTemplate>>() { }), new Function<ReferenceType, Future<? extends VAppTemplate>>() {
@SuppressWarnings("unchecked")
@Override @Override
public Future<VAppTemplate> apply(ReferenceType from) { public Future<? extends VAppTemplate> apply(ReferenceType from) {
return (Future<VAppTemplate>) aclient.getVAppTemplate(from.getHref()); return aclient.getVAppTemplate(from.getHref());
} }
}, executor, null, logger, "vappTemplates in"); }, executor, null, logger, "vappTemplates in");

View File

@ -238,7 +238,7 @@ public class BaseComputeService implements ComputeService {
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) { public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> destroying nodes matching(%s)", filter); logger.debug(">> destroying nodes matching(%s)", filter);
Set<NodeMetadata> set = newLinkedHashSet(filter(transformParallel(nodesMatchingFilterAndNotTerminated(filter), Set<NodeMetadata> set = newLinkedHashSet(filter(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, Future<NodeMetadata>>() { new Function<NodeMetadata, Future<? extends NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping // TODO make an async interface instead of re-wrapping
@Override @Override
@ -403,7 +403,7 @@ public class BaseComputeService implements ComputeService {
public void rebootNodesMatching(Predicate<NodeMetadata> filter) { public void rebootNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> rebooting nodes matching(%s)", filter); logger.debug(">> rebooting nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<Void>>() { new Function<NodeMetadata, Future<? extends Void>>() {
// TODO use native async // TODO use native async
@Override @Override
public Future<Void> apply(NodeMetadata from) { public Future<Void> apply(NodeMetadata from) {
@ -434,7 +434,7 @@ public class BaseComputeService implements ComputeService {
public void resumeNodesMatching(Predicate<NodeMetadata> filter) { public void resumeNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> resuming nodes matching(%s)", filter); logger.debug(">> resuming nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<Void>>() { new Function<NodeMetadata, Future<? extends Void>>() {
// TODO use native async // TODO use native async
@Override @Override
public Future<Void> apply(NodeMetadata from) { public Future<Void> apply(NodeMetadata from) {
@ -465,7 +465,7 @@ public class BaseComputeService implements ComputeService {
public void suspendNodesMatching(Predicate<NodeMetadata> filter) { public void suspendNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> suspending nodes matching(%s)", filter); logger.debug(">> suspending nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<Void>>() { new Function<NodeMetadata, Future<? extends Void>>() {
// TODO use native async // TODO use native async
@Override @Override
public Future<Void> apply(NodeMetadata from) { public Future<Void> apply(NodeMetadata from) {
@ -649,7 +649,7 @@ public class BaseComputeService implements ComputeService {
} }
private final class TransformNodesIntoInitializedScriptRunners implements private final class TransformNodesIntoInitializedScriptRunners implements
Function<NodeMetadata, Future<RunScriptOnNode>> { Function<NodeMetadata, Future<? extends RunScriptOnNode>> {
private final Map<NodeMetadata, Exception> badNodes; private final Map<NodeMetadata, Exception> badNodes;
private final Statement script; private final Statement script;
private final RunScriptOptions options; private final RunScriptOptions options;

View File

@ -71,31 +71,32 @@ public class FutureIterables {
private static BackoffLimitedRetryHandler retryHandler = BackoffLimitedRetryHandler.INSTANCE; private static BackoffLimitedRetryHandler retryHandler = BackoffLimitedRetryHandler.INSTANCE;
public static <F, T> Iterable<T> transformParallel(final Iterable<F> fromIterable, public static <F, T> Iterable<T> transformParallel(final Iterable<F> fromIterable,
final Function<? super F, Future<T>> function) { final Function<? super F, Future<? extends T>> function) {
return transformParallel(fromIterable, function, org.jclouds.concurrent.MoreExecutors.sameThreadExecutor(), null); return transformParallel(fromIterable, function, org.jclouds.concurrent.MoreExecutors.sameThreadExecutor(), null);
} }
public static <F, T> Iterable<T> transformParallel(final Iterable<F> fromIterable, public static <F, T> Iterable<T> transformParallel(final Iterable<F> fromIterable,
final Function<? super F, Future<T>> function, ExecutorService exec, @Nullable Long maxTime) { final Function<? super F, Future<? extends T>> function, ExecutorService exec, @Nullable Long maxTime) {
return transformParallel(fromIterable, function, exec, maxTime, logger, "transforming"); return transformParallel(fromIterable, function, exec, maxTime, logger, "transforming");
} }
public static <F, T> Iterable<T> transformParallel(final Iterable<F> fromIterable, public static <F, T> Iterable<T> transformParallel(final Iterable<F> fromIterable,
final Function<? super F, Future<T>> function, ExecutorService exec, @Nullable Long maxTime, Logger logger, final Function<? super F, Future<? extends T>> function, ExecutorService exec, @Nullable Long maxTime, Logger logger,
String logPrefix) { String logPrefix) {
return transformParallel(fromIterable, function, exec, maxTime, logger, logPrefix, retryHandler, maxRetries); return transformParallel(fromIterable, function, exec, maxTime, logger, logPrefix, retryHandler, maxRetries);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <F, T> Iterable<T> transformParallel(Iterable<F> fromIterable, public static <F, T> Iterable<T> transformParallel(Iterable<F> fromIterable,
Function<? super F, Future<T>> function, ExecutorService exec, @Nullable Long maxTime, Logger logger, Function<? super F, Future<? extends T>> function, ExecutorService exec, @Nullable Long maxTime, Logger logger,
String logPrefix, BackoffLimitedRetryHandler retryHandler, int maxRetries) { String logPrefix, BackoffLimitedRetryHandler retryHandler, int maxRetries) {
Map<F, Exception> exceptions = newHashMap(); Map<F, Exception> exceptions = newHashMap();
Map<F, Future<T>> responses = newHashMap(); Map<F, Future<? extends T>> responses = newHashMap();
for (int i = 0; i < maxRetries; i++) { for (int i = 0; i < maxRetries; i++) {
for (F from : fromIterable) { for (F from : fromIterable) {
responses.put(from, function.apply(from)); Future<? extends T> to = function.apply(from);
responses.put(from, to);
} }
exceptions = awaitCompletion(responses, exec, maxTime, logger, logPrefix); exceptions = awaitCompletion(responses, exec, maxTime, logger, logPrefix);
if (exceptions.size() > 0 && !any(exceptions.values(), containsThrowable(AuthorizationException.class))) { if (exceptions.size() > 0 && !any(exceptions.values(), containsThrowable(AuthorizationException.class))) {
@ -169,10 +170,10 @@ public class FutureIterables {
return errorMap; return errorMap;
} }
public static <T> Iterable<T> unwrap(Iterable<Future<T>> values) { public static <T> Iterable<T> unwrap(Iterable<Future<? extends T>> values) {
return transform(values, new Function<Future<T>, T>() { return transform(values, new Function<Future<? extends T>, T>() {
@Override @Override
public T apply(Future<T> from) { public T apply(Future<? extends T> from) {
try { try {
return from.get(); return from.get();
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -0,0 +1,40 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.util;
import com.google.common.collect.ImmutableSortedSet;
/**
* General utilities used in jclouds code for {@link Iterable Iterables}.
*
* @author danikov
*/
public class Iterables2 {
/**
* Copies the contents of a wildcarded {@link Iterable} into a concrete {@link Iterable} of the left bound
*
* @param unboundedValues wildcarded source {@link Iterable}
* @return concrete-typed copy of the source
*/
public static <T> Iterable<T> concreteCopy(Iterable<? extends T> unboundedValues) {
return ImmutableSortedSet.copyOf(unboundedValues);
}
}

View File

@ -155,4 +155,14 @@ public class Maps2 {
return result; return result;
} }
/**
* Covariant compatible version
*
* @see {@link Maps#uniqueIndex(Iterable, Function)}
*/
public static <K, V> ImmutableMap<K, V> uniqueIndex(
Iterable<? extends V> values, Function<? super V, ? extends K> keyFunction) {
return uniqueIndex(values, keyFunction);
}
} }

View File

@ -43,7 +43,7 @@ public class FutureIterablesTest {
final AtomicInteger counter = new AtomicInteger(); final AtomicInteger counter = new AtomicInteger();
try { try {
transformParallel(ImmutableSet.of("hello", "goodbye"), new Function<String, Future<String>>() { transformParallel(ImmutableSet.of("hello", "goodbye"), new Function<String, Future<? extends String>>() {
@Override @Override
public Future<String> apply(String input) { public Future<String> apply(String input) {
@ -63,7 +63,7 @@ public class FutureIterablesTest {
final AtomicInteger counter = new AtomicInteger(); final AtomicInteger counter = new AtomicInteger();
try { try {
transformParallel(ImmutableSet.of("hello", "goodbye"), new Function<String, Future<String>>() { transformParallel(ImmutableSet.of("hello", "goodbye"), new Function<String, Future<? extends String>>() {
@Override @Override
public Future<String> apply(String input) { public Future<String> apply(String input) {

View File

@ -74,14 +74,14 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
} }
@Override @Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() { public Iterable<LoadBalancerMetadata> listLoadBalancers() {
Iterable<? extends LoadBalancer> loadBalancers; Iterable<? extends LoadBalancer> loadBalancers;
Set<String> regions = this.regions.get(); Set<String> regions = this.regions.get();
if (regions.size() > 0) if (regions.size() > 0)
loadBalancers = concat(transformParallel(regions, new Function<String, Future<Set<? extends LoadBalancer>>>() { loadBalancers = concat(transformParallel(regions, new Function<String, Future<? extends Set<? extends LoadBalancer>>>() {
@Override @Override
public ListenableFuture<Set<? extends LoadBalancer>> apply(String from) { public ListenableFuture<? extends Set<? extends LoadBalancer>> apply(String from) {
return aclient.describeLoadBalancersInRegion(from); return aclient.describeLoadBalancersInRegion(from);
} }

View File

@ -62,6 +62,7 @@ import org.jclouds.glesys.options.DestroyServerOptions;
import org.jclouds.location.predicates.LocationPredicates; import org.jclouds.location.predicates.LocationPredicates;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.util.Iterables2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -196,13 +197,13 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
@Override @Override
public Iterable<ServerDetails> listNodes() { public Iterable<ServerDetails> listNodes() {
return transformParallel(client.getServerClient().listServers(), new Function<Server, Future<ServerDetails>>() { return Iterables2.concreteCopy(transformParallel(client.getServerClient().listServers(), new Function<Server, Future<? extends ServerDetails>>() {
@Override @Override
public Future<ServerDetails> apply(Server from) { public Future<ServerDetails> apply(Server from) {
return aclient.getServerClient().getServerDetails(from.getId()); return aclient.getServerClient().getServerDetails(from.getId());
} }
}, userThreads, null, logger, "server details"); }, userThreads, null, logger, "server details"));
} }
@Override @Override

View File

@ -69,12 +69,10 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
@Override @Override
protected Iterable<? extends RunningInstance> pollRunningInstances() { protected Iterable<? extends RunningInstance> pollRunningInstances() {
Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transformParallel(regions.get(), Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transformParallel(regions.get(),
new Function<String, Future<Set<SpotInstanceRequest>>>() { new Function<String, Future<? extends Set<SpotInstanceRequest>>>() {
@SuppressWarnings("unchecked")
@Override @Override
public Future<Set<SpotInstanceRequest>> apply(String from) { public Future<? extends Set<SpotInstanceRequest>> apply(String from) {
return (Future<Set<SpotInstanceRequest>>) client.getSpotInstanceServices() return client.getSpotInstanceServices()
.describeSpotInstanceRequestsInRegion(from); .describeSpotInstanceRequestsInRegion(from);
} }