mirror of https://github.com/apache/jclouds.git
Issue 386: fixed find method in vcloud
This commit is contained in:
parent
a45532f05c
commit
ad61d6e071
|
@ -95,15 +95,14 @@ import com.google.inject.name.Names;
|
|||
import domain.VCloudVersionsAsyncClient;
|
||||
|
||||
/**
|
||||
* Configures the VCloud authentication service connection, including logging
|
||||
* and http transport.
|
||||
* Configures the VCloud authentication service connection, including logging and http transport.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
|
||||
RestClientModule<S, A> {
|
||||
RestClientModule<S, A> {
|
||||
|
||||
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||
super(syncClientType, asyncClientType);
|
||||
|
@ -146,29 +145,39 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
|
||||
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
|
||||
new Supplier<Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> get() {
|
||||
Map<String, String> returnVal = newLinkedHashMap();
|
||||
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
new Supplier<Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> get() {
|
||||
Map<String, String> returnVal = newLinkedHashMap();
|
||||
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
@Singleton
|
||||
protected URI provideDefaultVDC(Org org) {
|
||||
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
|
||||
return get(org.getVDCs().values(), 0).getHref();
|
||||
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
|
||||
checkState(org.getVDCs().size() > 0, "No vdcs present in org %s", org.getName());
|
||||
return checkNotNull(org.getVDCs().get(defaultVDC), "vdc %s not present in org %s", defaultVDC, org.getName())
|
||||
.getHref();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
@Singleton
|
||||
protected String provideDefaultVDCName(@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
|
||||
Map<String, String> vDCtoOrg = vDCtoOrgSupplier.get();
|
||||
checkState(vDCtoOrg.keySet().size() > 0, "No vdcs present!");
|
||||
return get(vDCtoOrg.keySet(), 0);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -182,15 +191,15 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final OrgMapSupplier supplier) {
|
||||
final OrgMapSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(authException,
|
||||
seconds, new Supplier<Map<String, ? extends Org>>() {
|
||||
@Override
|
||||
public Map<String, ? extends Org> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
seconds, new Supplier<Map<String, ? extends Org>>() {
|
||||
@Override
|
||||
public Map<String, ? extends Org> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -199,7 +208,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
URI provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
VCloudSession session = sessionSupplier.get();
|
||||
return URI.create(Iterables.getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*",
|
||||
"org"));
|
||||
"org"));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -209,7 +218,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
|
||||
@Inject
|
||||
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
|
||||
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
|
||||
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
this.organizationsForNames = organizationsForNames;
|
||||
}
|
||||
|
@ -222,13 +231,13 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
|
||||
@Singleton
|
||||
public static class OrgCatalogSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allCatalogsInOrg = allCatalogsInOrg;
|
||||
}
|
||||
|
@ -236,16 +245,16 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,27 +285,27 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@org.jclouds.vcloud.endpoints.Org
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final OrgNameToOrgSupplier supplier) {
|
||||
final OrgNameToOrgSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(authException,
|
||||
seconds, new Supplier<Map<String, ReferenceType>>() {
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
seconds, new Supplier<Map<String, ReferenceType>>() {
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
|
||||
authException, seconds, new Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
@Override
|
||||
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
authException, seconds, new Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
@Override
|
||||
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -311,24 +320,24 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
|
||||
return uniqueIndex(
|
||||
concat(transform(
|
||||
orgVDCMap.get().values(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
concat(transform(
|
||||
orgVDCMap.get().values(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return from.values();
|
||||
}
|
||||
@Override
|
||||
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return from.values();
|
||||
}
|
||||
|
||||
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
|
||||
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(org.jclouds.vcloud.domain.VDC from) {
|
||||
return from.getHref();
|
||||
}
|
||||
@Override
|
||||
public URI apply(org.jclouds.vcloud.domain.VDC from) {
|
||||
return from.getHref();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -357,7 +366,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VCloudLogin
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
||||
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
|
||||
checkState(versions.size() > 0, "No versions present");
|
||||
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
|
||||
|
@ -391,7 +401,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@org.jclouds.vcloud.endpoints.Catalog
|
||||
@Singleton
|
||||
protected String provideCatalogName(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
|
||||
return getLast(getLast(catalogs.get().values()).keySet());
|
||||
}
|
||||
|
||||
|
@ -399,7 +409,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Network
|
||||
@Singleton
|
||||
protected URI provideDefaultNetwork(@org.jclouds.vcloud.endpoints.VDC URI defaultVDC, CommonVCloudClient client,
|
||||
Injector injector) {
|
||||
Injector injector) {
|
||||
if (authException.get() != null)
|
||||
throw authException.get();
|
||||
try {
|
||||
|
@ -410,18 +420,23 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
return Iterables.getLast(networks.values()).getHref();
|
||||
try {
|
||||
String networkName = injector.getInstance(Key.get(String.class, Names
|
||||
.named(PROPERTY_VCLOUD_DEFAULT_NETWORK)));
|
||||
.named(PROPERTY_VCLOUD_DEFAULT_NETWORK)));
|
||||
ReferenceType network = networks.get(networkName);
|
||||
checkState(network != null, String.format("network named %s not in %s", networkName, networks.keySet()));
|
||||
return network.getHref();
|
||||
} catch (ConfigurationException e) {
|
||||
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not work well.
|
||||
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's networks will
|
||||
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If this property
|
||||
// is not set, they are expected to add NetworkConfig to the options when launching a server.
|
||||
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not
|
||||
// work well.
|
||||
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's
|
||||
// networks will
|
||||
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If
|
||||
// this property
|
||||
// is not set, they are expected to add NetworkConfig to the options when launching a
|
||||
// server.
|
||||
return null;
|
||||
//throw new IllegalStateException(String.format("you must specify the property %s as one of %s",
|
||||
// PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e);
|
||||
// throw new
|
||||
// IllegalStateException(String.format("you must specify the property %s as one of %s",
|
||||
// PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e);
|
||||
}
|
||||
} catch (AuthorizationException e) {
|
||||
authException.set(e);
|
||||
|
@ -445,48 +460,49 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<URI> successTester(Injector injector,
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
return new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), completed);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogSupplier supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
|
||||
authException, seconds, new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgVDCSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allVDCsInOrg = allVDCsInOrg;
|
||||
}
|
||||
|
@ -494,29 +510,29 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allVDCsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
transformValues(orgSupplier.get(), allVDCsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogItemSupplier implements
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
|
||||
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
|
||||
private final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogItemSupplier(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
|
||||
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
|
||||
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
|
||||
this.catalogSupplier = catalogSupplier;
|
||||
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
|
||||
}
|
||||
|
@ -524,39 +540,40 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||
return transformValues(
|
||||
catalogSupplier.get(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
|
||||
catalogSupplier.get(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends CatalogItem>> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return transformValues(
|
||||
from,
|
||||
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends CatalogItem>> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return transformValues(
|
||||
from,
|
||||
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
|
||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Map<String, ? extends CatalogItem> apply(
|
||||
org.jclouds.vcloud.domain.Catalog from) {
|
||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogItemSupplier supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogItemSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -852,10 +852,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultVDC(Org org) {
|
||||
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
|
||||
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideDefaultVDCName(@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
|
||||
return "vdc";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
|
||||
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
|
||||
|
|
|
@ -120,12 +120,10 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
String.class, InstantiateVAppTemplateOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp",
|
||||
processorCount(1).memory(512).disk(1024)
|
||||
.addNetworkConfig(
|
||||
new NetworkConfig(null, URI
|
||||
.create("https://vcloud.safesecureweb.com/network/1990"),
|
||||
FenceMode.BRIDGED)));
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1)
|
||||
.memory(512).disk(1024).addNetworkConfig(
|
||||
new NetworkConfig(null, URI.create("https://vcloud.safesecureweb.com/network/1990"),
|
||||
FenceMode.BRIDGED)));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
|
||||
|
@ -685,10 +683,16 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultVDC(Org org) {
|
||||
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideDefaultVDCName(
|
||||
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
|
||||
return "vdc";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -63,6 +64,11 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
assertEquals(node.getType(), ComputeType.NODE);
|
||||
NodeMetadata allData = client.getNodeMetadata(node.getId());
|
||||
System.out.println(allData.getHardware());
|
||||
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory().createContext(
|
||||
provider, identity, credential).getProviderSpecificContext();
|
||||
VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName());
|
||||
assertEquals(vApp.getName(), allData.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -43,7 +43,9 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
|||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
@ -69,14 +71,17 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
|
|||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
|
||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
||||
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
|
||||
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils, Timeouts timeouts,
|
||||
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
|
||||
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended, ComputeUtils utils, Timeouts timeouts,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys,
|
||||
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap, NodeMetadataToOrgAndName nodeToOrgAndName) {
|
||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, templateBuilderProvider,
|
||||
templateOptionsProvider, nodeRunning, nodeTerminated, utils, timeouts, executor);
|
||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
|
||||
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
||||
nodeSuspended, utils, timeouts, executor);
|
||||
this.cleanupOrphanKeys = cleanupOrphanKeys;
|
||||
}
|
||||
|
||||
|
|
|
@ -309,20 +309,20 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
|
|||
}
|
||||
|
||||
public void testGetKeyPairInOrg() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("findKeyPairInOrg", URI.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), "keyPair");
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("findKeyPairInOrg", URI.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), "keyPair");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/keysList/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.keysList+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/keysList/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.keysList+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, KeyPairByNameHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, KeyPairByNameHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testConfigureNodeWithDescription() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", URI.class, String.class,
|
||||
|
@ -409,56 +409,56 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
|
|||
}
|
||||
|
||||
public void testListKeyPairsInOrg() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("listKeyPairsInOrg", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("listKeyPairsInOrg", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/keysList/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.keysList+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/keysList/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.keysList+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, KeyPairsHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, KeyPairsHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testListKeyPairsInOrgNotFound() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("listKeyPairsInOrg", URI.class);
|
||||
processor.createRequest(method, URI.create("d"));
|
||||
}
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testListKeyPairsInOrgNotFound() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("listKeyPairsInOrg", URI.class);
|
||||
processor.createRequest(method, URI.create("d"));
|
||||
}
|
||||
|
||||
public void testGetKeyPair() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("getKeyPair", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/key/12"));
|
||||
public void testGetKeyPair() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("getKeyPair", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/key/12"));
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud/extensions/key/12 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
assertRequestLineEquals(request, "GET https://vcloud/extensions/key/12 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, KeyPairHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, KeyPairHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("deleteKeyPair", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/key/12"));
|
||||
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("deleteKeyPair", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/key/12"));
|
||||
|
||||
assertRequestLineEquals(request, "DELETE https://vcloud/extensions/key/12 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
assertRequestLineEquals(request, "DELETE https://vcloud/extensions/key/12 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("getNode", URI.class);
|
||||
|
@ -530,8 +530,9 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
|
|||
|
||||
@Override
|
||||
public ReferenceType apply(ReferenceType from) {
|
||||
return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI
|
||||
.create(from.getHref().toASCIIString() + "/keysList"));
|
||||
return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI.create(from
|
||||
.getHref().toASCIIString()
|
||||
+ "/keysList"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -549,13 +550,12 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
|
|||
return ImmutableMap.<String, Org> of("org", new TerremarkOrgImpl("org", null, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), null, ImmutableMap
|
||||
.<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog",
|
||||
TerremarkECloudMediaType.CATALOG_XML, URI
|
||||
TerremarkECloudMediaType.CATALOG_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
|
||||
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc",
|
||||
TerremarkECloudMediaType.VDC_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
|
||||
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", TerremarkECloudMediaType.VDC_XML,
|
||||
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
|
||||
.<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList",
|
||||
TerremarkECloudMediaType.TASKSLIST_XML, URI
|
||||
TerremarkECloudMediaType.TASKSLIST_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), new ReferenceTypeImpl(
|
||||
"keysList", TerremarkECloudMediaType.KEYSLIST_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1"))));
|
||||
|
@ -593,10 +593,16 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
|
|||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultVDC(Org org) {
|
||||
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
|
||||
return URI.create("https://vdc/1");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideDefaultVDCName(
|
||||
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
|
||||
return "vdc";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
||||
|
|
|
@ -729,10 +729,16 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
|
|||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultVDC(Org org) {
|
||||
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
|
||||
return URI.create("https://vdc/1");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideDefaultVDCName(
|
||||
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
|
||||
return "vdc";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideCatalogName(Supplier<Map<String, Map<String, ? extends Catalog>>> catalogs) {
|
||||
return "catalog";
|
||||
|
|
Loading…
Reference in New Issue