mirror of https://github.com/apache/jclouds.git
Issue 306: tasks list and catalog by name
This commit is contained in:
parent
00d661740a
commit
b0050eeeeb
|
@ -28,8 +28,6 @@ import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
|
|||
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
|
@ -64,6 +62,8 @@ import org.jclouds.vcloud.domain.VAppTemplate;
|
|||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
|
||||
import org.jclouds.vcloud.functions.OrgNameAndTasksListNameToEndpoint;
|
||||
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
|
||||
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
|
||||
import org.jclouds.vcloud.functions.VAppIdToUri;
|
||||
|
@ -127,6 +127,7 @@ public interface VCloudAsyncClient {
|
|||
/**
|
||||
* @see VCloudClient#getDefaultCatalog
|
||||
*/
|
||||
@Deprecated
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
|
@ -136,6 +137,7 @@ public interface VCloudAsyncClient {
|
|||
/**
|
||||
* @see VCloudClient#getCatalog
|
||||
*/
|
||||
@Deprecated
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/catalog/{catalogId}")
|
||||
|
@ -144,6 +146,17 @@ public interface VCloudAsyncClient {
|
|||
@Consumes(CATALOG_XML)
|
||||
ListenableFuture<? extends Catalog> getCatalog(@PathParam("catalogId") String catalogId);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getCatalogInOrg
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(CatalogHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
ListenableFuture<? extends Catalog> getCatalogInOrg(
|
||||
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
|
||||
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getVAppTemplate
|
||||
*/
|
||||
|
@ -180,6 +193,7 @@ public interface VCloudAsyncClient {
|
|||
/**
|
||||
* @see VCloudClient#getDefaultVDC
|
||||
*/
|
||||
@Deprecated
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
|
@ -209,18 +223,10 @@ public interface VCloudAsyncClient {
|
|||
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
|
||||
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getVDC(URI)
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
@Consumes(VDC_XML)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vDCId);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getTasksList
|
||||
*/
|
||||
@Deprecated
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/tasksList/{tasksListId}")
|
||||
|
@ -229,9 +235,21 @@ public interface VCloudAsyncClient {
|
|||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends TasksList> getTasksList(@PathParam("tasksListId") String tasksListId);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getTasksListInOrg
|
||||
*/
|
||||
@GET
|
||||
@Consumes(TASKSLIST_XML)
|
||||
@XMLResponseParser(TasksListHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends TasksList> getTasksListInOrg(
|
||||
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String orgName,
|
||||
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getDefaultTasksList
|
||||
*/
|
||||
@Deprecated
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.TasksList.class)
|
||||
@Consumes(TASKSLIST_XML)
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
@ -51,7 +50,7 @@ public interface VCloudClient {
|
|||
Organization getDefaultOrganization();
|
||||
|
||||
/**
|
||||
* Please use #getOrganizationByName
|
||||
* Please use #getOrganizationNamed
|
||||
*/
|
||||
@Deprecated
|
||||
Organization getOrganization(String orgId);
|
||||
|
@ -65,10 +64,20 @@ public interface VCloudClient {
|
|||
*/
|
||||
Organization getOrganizationNamed(String name);
|
||||
|
||||
/**
|
||||
* Please use #getCatalogInOrg(null, null)
|
||||
*/
|
||||
@Deprecated
|
||||
Catalog getDefaultCatalog();
|
||||
|
||||
/**
|
||||
* Please use #getCatalogInOrg
|
||||
*/
|
||||
@Deprecated
|
||||
Catalog getCatalog(String catalogId);
|
||||
|
||||
Catalog getCatalogInOrg(String orgName, String catalogName);
|
||||
|
||||
CatalogItem getCatalogItem(String catalogItemId);
|
||||
|
||||
VAppTemplate getVAppTemplate(String vAppTemplateId);
|
||||
|
@ -76,19 +85,31 @@ public interface VCloudClient {
|
|||
Network getNetwork(String networkId);
|
||||
|
||||
/**
|
||||
* please use {@link #getVDC(URI)}
|
||||
* please use {@link #getVDCInOrg}
|
||||
*/
|
||||
@Deprecated
|
||||
VDC getVDC(String vDCId);
|
||||
|
||||
VDC getVDCInOrg(String orgName, String vdcName);
|
||||
|
||||
VDC getVDC(URI vdc);
|
||||
|
||||
/**
|
||||
* Please use #getVDCInOrg(null, null)
|
||||
*/
|
||||
@Deprecated
|
||||
VDC getDefaultVDC();
|
||||
|
||||
/**
|
||||
* Please use #getTasksListInOrg
|
||||
*/
|
||||
@Deprecated
|
||||
TasksList getTasksList(String tasksListId);
|
||||
|
||||
TasksList getTasksListInOrg(String orgName, String tasksListName);
|
||||
|
||||
/**
|
||||
* Please use #getTasksListInOrg(null, null)
|
||||
*/
|
||||
@Deprecated
|
||||
TasksList getDefaultTasksList();
|
||||
|
||||
Task deployVApp(String vAppId);
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.jclouds.domain.LocationScope;
|
|||
import org.jclouds.domain.internal.LocationImpl;
|
||||
import org.jclouds.vcloud.compute.domain.VCloudLocation;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -43,12 +43,12 @@ import com.google.common.collect.Sets;
|
|||
public class OrgAndVDCToLocationProvider implements Provider<Set<? extends Location>> {
|
||||
private final String providerName;
|
||||
private final Supplier<Map<String, NamedResource>> orgNameToResource;
|
||||
private final Supplier<Map<String, Map<String, NamedResource>>> orgNameToVDCResource;
|
||||
private final Supplier<Map<String, Organization>> orgNameToVDCResource;
|
||||
|
||||
@Inject
|
||||
OrgAndVDCToLocationProvider(@org.jclouds.rest.annotations.Provider String providerName,
|
||||
@Org Supplier<Map<String, NamedResource>> orgNameToResource,
|
||||
@VDC Supplier<Map<String, Map<String, NamedResource>>> orgNameToVDCResource) {
|
||||
Supplier<Map<String, Organization>> orgNameToVDCResource) {
|
||||
this.providerName = providerName;
|
||||
this.orgNameToResource = orgNameToResource;
|
||||
this.orgNameToVDCResource = orgNameToVDCResource;
|
||||
|
@ -61,7 +61,7 @@ public class OrgAndVDCToLocationProvider implements Provider<Set<? extends Locat
|
|||
|
||||
for (NamedResource org : orgNameToResource.get().values()) {
|
||||
Location orgL = new VCloudLocation(org, provider);
|
||||
for (NamedResource vdc : orgNameToVDCResource.get().get(org.getName()).values()) {
|
||||
for (NamedResource vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) {
|
||||
locations.add(new VCloudLocation(vdc, orgL));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,14 +82,15 @@ import com.google.inject.Provides;
|
|||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* 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 abstract class BaseVCloudRestClientModule<S extends VCloudClient, A extends VCloudAsyncClient> extends
|
||||
RestClientModule<S, A> {
|
||||
RestClientModule<S, A> {
|
||||
|
||||
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||
super(syncClientType, asyncClientType);
|
||||
|
@ -110,7 +111,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<String> successTester(TaskSuccess success,
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
return new RetryablePredicate<String>(success, completed);
|
||||
}
|
||||
|
||||
|
@ -138,20 +139,20 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
|||
@Singleton
|
||||
@VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final @VDC Supplier<Map<String, Map<String, NamedResource>>> orgToVDCSupplier) {
|
||||
final Supplier<Map<String, Organization>> orgToVDCSupplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
|
||||
new Supplier<Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> get() {
|
||||
Map<String, String> returnVal = Maps.newLinkedHashMap();
|
||||
for (Entry<String, Map<String, NamedResource>> orgr : orgToVDCSupplier.get().entrySet()) {
|
||||
for (String vdc : orgr.getValue().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
new Supplier<Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> get() {
|
||||
Map<String, String> returnVal = Maps.newLinkedHashMap();
|
||||
for (Entry<String, Organization> orgr : orgToVDCSupplier.get().entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@ -176,55 +177,54 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final VCloudLoginAsyncClient login) {
|
||||
final VCloudLoginAsyncClient login) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
|
||||
new Supplier<VCloudSession>() {
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
try {
|
||||
return login.login().get(10, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
assert false : e;
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
try {
|
||||
return login.login().get(10, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
assert false : e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@VDC
|
||||
protected Supplier<Map<String, Map<String, NamedResource>>> provideOrgToVDCCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgNameToVDCSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, NamedResource>>>(
|
||||
authException, seconds, new Supplier<Map<String, Map<String, NamedResource>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, NamedResource>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
protected Supplier<Map<String, Organization>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final OrganizationMapSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Organization>>(authException,
|
||||
seconds, new Supplier<Map<String, Organization>>() {
|
||||
@Override
|
||||
public Map<String, Organization> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgNameToVDCSupplier implements Supplier<Map<String, Map<String, NamedResource>>> {
|
||||
public static class OrganizationMapSupplier implements Supplier<Map<String, Organization>> {
|
||||
protected final Supplier<VCloudSession> sessionSupplier;
|
||||
private final VCloudClient client;
|
||||
|
||||
@Inject
|
||||
protected OrgNameToVDCSupplier(Supplier<VCloudSession> sessionSupplier, VCloudClient client) {
|
||||
protected OrganizationMapSupplier(Supplier<VCloudSession> sessionSupplier, VCloudClient client) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, NamedResource>> get() {
|
||||
Map<String, Map<String, NamedResource>> returnVal = Maps.newLinkedHashMap();
|
||||
public Map<String, Organization> get() {
|
||||
Map<String, Organization> returnVal = Maps.newLinkedHashMap();
|
||||
for (String orgName : sessionSupplier.get().getOrgs().keySet()) {
|
||||
returnVal.put(orgName, client.getOrganizationNamed(orgName).getVDCs());
|
||||
returnVal.put(orgName, client.getOrganizationNamed(orgName));
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -235,8 +235,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
|||
@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);
|
||||
|
@ -296,7 +295,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException, TimeoutException,
|
||||
InterruptedException {
|
||||
InterruptedException {
|
||||
if (authException.get() != null)
|
||||
throw authException.get();
|
||||
try {
|
||||
|
@ -327,7 +326,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
|||
@Network
|
||||
@Singleton
|
||||
protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
TimeoutException {
|
||||
if (authException.get() != null)
|
||||
throw authException.get();
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.vcloud.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, Organization>> orgMap;
|
||||
private final String defaultOrg;
|
||||
private final URI defaultUri;
|
||||
|
||||
@Inject
|
||||
public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, Organization>> orgMap, @Org String defaultOrg,
|
||||
@Catalog URI defaultUri) {
|
||||
this.orgMap = orgMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultUri = defaultUri;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public URI apply(Object from) {
|
||||
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
|
||||
Object org = Iterables.get(orgCatalog, 0);
|
||||
Object catalog = Iterables.get(orgCatalog, 1);
|
||||
if (org == null && catalog == null)
|
||||
return defaultUri;
|
||||
else if (org == null)
|
||||
org = defaultOrg;
|
||||
|
||||
try {
|
||||
Map<String, NamedResource> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
|
||||
|
||||
return catalog == null ? Iterables.getLast(catalogs.values()).getLocation() : catalogs.get(catalog)
|
||||
.getLocation();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.vcloud.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.endpoints.TasksList;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameAndTasksListNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, Organization>> orgMap;
|
||||
private final String defaultOrg;
|
||||
private final URI defaultUri;
|
||||
|
||||
@Inject
|
||||
public OrgNameAndTasksListNameToEndpoint(Supplier<Map<String, Organization>> orgMap, @Org String defaultOrg,
|
||||
@TasksList URI defaultUri) {
|
||||
this.orgMap = orgMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultUri = defaultUri;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public URI apply(Object from) {
|
||||
Iterable<Object> orgTasksList = (Iterable<Object>) checkNotNull(from, "args");
|
||||
Object org = Iterables.get(orgTasksList, 0);
|
||||
Object tasksList = Iterables.get(orgTasksList, 1);
|
||||
if (org == null && tasksList == null)
|
||||
return defaultUri;
|
||||
else if (org == null)
|
||||
org = defaultOrg;
|
||||
|
||||
try {
|
||||
Map<String, NamedResource> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists();
|
||||
return tasksList == null ? Iterables.getLast(tasksLists.values()).getLocation() : tasksLists.get(tasksList)
|
||||
.getLocation();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSuchElementException(org + "/" + tasksList + " not found in " + orgMap.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
|
||||
|
@ -41,13 +42,13 @@ import com.google.common.collect.Iterables;
|
|||
*/
|
||||
@Singleton
|
||||
public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, Map<String, NamedResource>>> orgNameToVDCEndpoint;
|
||||
private final Supplier<Map<String, Organization>> orgNameToVDCEndpoint;
|
||||
private final String defaultOrg;
|
||||
private final URI defaultUri;
|
||||
|
||||
@Inject
|
||||
public OrgNameAndVDCNameToEndpoint(@VDC Supplier<Map<String, Map<String, NamedResource>>> orgNameToVDCEndpoint,
|
||||
@Org String defaultOrg, @VDC URI defaultUri) {
|
||||
public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, Organization>> orgNameToVDCEndpoint, @Org String defaultOrg,
|
||||
@VDC URI defaultUri) {
|
||||
this.orgNameToVDCEndpoint = orgNameToVDCEndpoint;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultUri = defaultUri;
|
||||
|
@ -64,7 +65,7 @@ public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> {
|
|||
org = defaultOrg;
|
||||
|
||||
try {
|
||||
Map<String, NamedResource> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org));
|
||||
Map<String, NamedResource> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();
|
||||
|
||||
return vdc == null ? Iterables.getLast(vdcs.values()).getLocation() : vdcs.get(vdc).getLocation();
|
||||
} catch (NullPointerException e) {
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.jclouds.vcloud.config.VCloudRestClientModule;
|
|||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
|
||||
|
@ -331,6 +332,21 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCatalogInOrg() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getCatalogInOrg", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, "org", "catalog");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "2");
|
||||
|
@ -463,22 +479,6 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetVDCURI() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, VDCHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getDefaultTasksList");
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
@ -509,6 +509,21 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetTasksListInOrg() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getTasksListInOrg", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, "org", "tasksList");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TasksListHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class);
|
||||
HttpRequest request = processor.createRequest(method, 1);
|
||||
|
@ -715,7 +730,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(OrgNameToVDCSupplier.class).to(TestOrgNameToVDCSupplier.class);
|
||||
bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -781,17 +796,23 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
}
|
||||
|
||||
@Singleton
|
||||
public static class TestOrgNameToVDCSupplier extends OrgNameToVDCSupplier {
|
||||
public static class TestOrganizationMapSupplier extends OrganizationMapSupplier {
|
||||
@Inject
|
||||
protected TestOrgNameToVDCSupplier() {
|
||||
protected TestOrganizationMapSupplier() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, NamedResource>> get() {
|
||||
return ImmutableMap.<String, Map<String, NamedResource>> of("org", ImmutableMap.<String, NamedResource> of(
|
||||
"vdc", new NamedResourceImpl("1", "vdc", VCloudMediaType.VDC_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))));
|
||||
public Map<String, Organization> get() {
|
||||
return ImmutableMap.<String, Organization> of("org", new OrganizationImpl("1", "org", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), ImmutableMap.<String, NamedResource> of(
|
||||
"catalog", new NamedResourceImpl("1", "catalog", VCloudMediaType.CATALOG_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
|
||||
.<String, NamedResource> of("vdc", new NamedResourceImpl("1", "vdc", VCloudMediaType.VDC_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
|
||||
.<String, NamedResource> of("tasksList", new NamedResourceImpl("1", "tasksList",
|
||||
VCloudMediaType.TASKSLIST_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testOrganization() throws Exception {
|
||||
Organization response = connection.getDefaultOrganization();
|
||||
Organization response = connection.getOrganizationNamed(null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
assert response.getCatalogs().size() >= 1;
|
||||
|
@ -66,17 +66,17 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testCatalog() throws Exception {
|
||||
Catalog response = connection.getDefaultCatalog();
|
||||
Catalog response = connection.getCatalogInOrg(null, null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getId());
|
||||
assertNotNull(response.getName());
|
||||
assertNotNull(response.getLocation());
|
||||
assertEquals(connection.getCatalog(response.getId()), response);
|
||||
assertEquals(connection.getCatalogInOrg(null, response.getName()), response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNetwork() throws Exception {
|
||||
VDC response = connection.getDefaultVDC();
|
||||
VDC response = connection.getVDCInOrg(null, null);
|
||||
for (NamedResource resource : response.getAvailableNetworks().values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
|
||||
Network item = connection.getNetwork(resource.getId());
|
||||
|
@ -87,7 +87,7 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetCatalogItem() throws Exception {
|
||||
Catalog response = connection.getDefaultCatalog();
|
||||
Catalog response = connection.getCatalogInOrg(null, null);
|
||||
for (NamedResource resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getId());
|
||||
|
@ -103,7 +103,7 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetVAppTemplate() throws Exception {
|
||||
Catalog response = connection.getDefaultCatalog();
|
||||
Catalog response = connection.getCatalogInOrg(null, null);
|
||||
for (NamedResource resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getId());
|
||||
|
@ -116,7 +116,7 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testDefaultVDC() throws Exception {
|
||||
VDC response = connection.getDefaultVDC();
|
||||
VDC response = connection.getVDCInOrg(null, null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getId());
|
||||
assertNotNull(response.getName());
|
||||
|
@ -128,7 +128,7 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testDefaultTasksList() throws Exception {
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.getDefaultTasksList();
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.getTasksListInOrg(null, null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getId());
|
||||
assertNotNull(response.getLocation());
|
||||
|
@ -138,7 +138,7 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetTask() throws Exception {
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.getDefaultTasksList();
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.getTasksListInOrg(null, null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getLocation());
|
||||
assertNotNull(response.getTasks());
|
||||
|
@ -150,7 +150,7 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetVApp() throws Exception {
|
||||
VDC response = connection.getDefaultVDC();
|
||||
VDC response = connection.getVDCInOrg(null, null);
|
||||
for (NamedResource item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
VApp app = connection.getVApp(item.getId());
|
||||
|
|
|
@ -109,12 +109,14 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
||||
|
||||
@GET
|
||||
@Deprecated
|
||||
@Endpoint(Org.class)
|
||||
@Consumes(ORG_XML)
|
||||
@XMLResponseParser(TerremarkOrgHandler.class)
|
||||
ListenableFuture<? extends TerremarkOrganization> getDefaultOrganization();
|
||||
|
||||
@GET
|
||||
@Deprecated
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/org/{orgId}")
|
||||
@XMLResponseParser(TerremarkOrgHandler.class)
|
||||
|
|
|
@ -46,9 +46,11 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
|||
*/
|
||||
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
|
||||
public interface TerremarkVCloudClient extends VCloudClient {
|
||||
@Deprecated
|
||||
@Override
|
||||
TerremarkOrganization getDefaultOrganization();
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
TerremarkOrganization getOrganization(String orgId);
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.jclouds.vcloud.VCloudMediaType;
|
|||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
|
||||
|
@ -571,7 +572,7 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
|
|||
protected void configure() {
|
||||
super.configure();
|
||||
bind(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class);
|
||||
bind(OrgNameToVDCSupplier.class).to(TestOrgNameToVDCSupplier.class);
|
||||
bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -646,17 +647,23 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
|
|||
}
|
||||
|
||||
@Singleton
|
||||
public static class TestOrgNameToVDCSupplier extends OrgNameToVDCSupplier {
|
||||
public static class TestOrganizationMapSupplier extends OrganizationMapSupplier {
|
||||
@Inject
|
||||
protected TestOrgNameToVDCSupplier() {
|
||||
protected TestOrganizationMapSupplier() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, NamedResource>> get() {
|
||||
return ImmutableMap.<String, Map<String, NamedResource>> of("org", ImmutableMap.<String, NamedResource> of(
|
||||
"vdc", new NamedResourceImpl("1", "vdc", VCloudMediaType.VDC_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))));
|
||||
public Map<String, Organization> get() {
|
||||
return ImmutableMap.<String, Organization> of("org", new OrganizationImpl("1", "org", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), ImmutableMap.<String, NamedResource> of(
|
||||
"catalog", new NamedResourceImpl("1", "catalog", VCloudMediaType.CATALOG_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
|
||||
.<String, NamedResource> of("vdc", new NamedResourceImpl("1", "vdc", VCloudMediaType.VDC_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
|
||||
.<String, NamedResource> of("tasksList", new NamedResourceImpl("1", "tasksList",
|
||||
VCloudMediaType.TASKSLIST_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue