From 560aa95e90dea608c8d976a0f9b672e2fb6e28f7 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 24 Jul 2011 13:37:03 +1000 Subject: [PATCH] flattened vCloud classes now that vcloud 0.8 doesn't need to share hierarchy with 1.0 --- .../vcloud/CommonVCloudAsyncClient.java | 212 -------- .../jclouds/vcloud/CommonVCloudClient.java | 128 ----- .../org/jclouds/vcloud/VCloudAsyncClient.java | 161 ++++++- .../java/org/jclouds/vcloud/VCloudClient.java | 17 +- .../compute/CommonVCloudComputeClient.java | 61 --- ...monVCloudBindComputeStrategiesByClass.java | 35 -- ...mmonVCloudBindComputeSuppliersByClass.java | 105 ---- ...mmonVCloudComputeServiceContextModule.java | 69 --- .../VCloudBindComputeStrategiesByClass.java | 13 +- .../VCloudBindComputeSuppliersByClass.java | 75 ++- .../VCloudComputeServiceContextModule.java | 31 +- .../CommonVCloudComputeClientImpl.java | 123 ----- .../strategy/VCloudListNodesStrategy.java | 42 +- .../config/BaseVCloudRestClientModule.java | 106 ---- .../config/CommonVCloudRestClientModule.java | 452 ------------------ .../vcloud/config/VCloudRestClientModule.java | 434 ++++++++++++++++- .../functions/AllCatalogItemsInCatalog.java | 6 +- .../vcloud/functions/AllCatalogsInOrg.java | 6 +- .../vcloud/functions/AllVDCsInOrg.java | 6 +- .../vcloud/functions/OrgsForLocations.java | 6 +- .../vcloud/functions/OrgsForNames.java | 6 +- .../VAppTemplatesForCatalogItems.java | 5 +- .../VCloudLoginAsyncClient.java | 3 +- .../vcloud/predicates/TaskSuccess.java | 8 +- .../vcloud/CommonVCloudClientLiveTest.java | 329 ------------- .../DeprecatedVCloudClientLiveTest.java | 289 ++++++++++- .../jclouds/vcloud/VCloudAsyncClientTest.java | 1 + .../vcloud/VCloudSessionRefreshLiveTest.java | 1 + .../functions/VAppToNodeMetadataTest.java | 4 +- .../features/CatalogAsyncClientTest.java | 2 +- .../features/CatalogClientLiveTest.java | 2 +- .../features/NetworkAsyncClientTest.java | 2 +- .../features/NetworkClientLiveTest.java | 2 +- .../vcloud/features/OrgAsyncClientTest.java | 2 +- .../vcloud/features/OrgClientLiveTest.java | 2 +- .../vcloud/features/TaskAsyncClientTest.java | 2 +- .../vcloud/features/TaskClientLiveTest.java | 2 +- .../vcloud/features/VAppAsyncClientTest.java | 2 +- .../vcloud/features/VAppClientLiveTest.java | 2 +- .../features/VAppTemplateAsyncClientTest.java | 2 +- .../features/VAppTemplateClientLiveTest.java | 2 +- .../vcloud/features/VDCAsyncClientTest.java | 2 +- .../vcloud/features/VDCClientLiveTest.java | 2 +- .../vcloud/features/VmAsyncClientTest.java | 2 +- .../vcloud/features/VmClientLiveTest.java | 2 +- .../test/java/org/jclouds/vcloud/functions | 152 ------ .../BaseVCloudAsyncClientTest.java | 4 +- .../BaseVCloudClientLiveTest.java | 3 +- .../VCloudLoginAsyncClientTest.java | 2 +- 49 files changed, 1060 insertions(+), 1867 deletions(-) delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/compute/CommonVCloudComputeClient.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeStrategiesByClass.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeSuppliersByClass.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java delete mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java rename apis/vcloud/src/main/java/org/jclouds/vcloud/{ => internal}/VCloudLoginAsyncClient.java (95%) delete mode 100644 apis/vcloud/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java delete mode 100644 apis/vcloud/src/test/java/org/jclouds/vcloud/functions rename apis/vcloud/src/test/java/org/jclouds/vcloud/{ => internal}/BaseVCloudAsyncClientTest.java (98%) rename apis/vcloud/src/test/java/org/jclouds/vcloud/{ => internal}/BaseVCloudClientLiveTest.java (98%) rename apis/vcloud/src/test/java/org/jclouds/vcloud/{ => internal}/VCloudLoginAsyncClientTest.java (99%) diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java deleted file mode 100644 index e2fa7b8951..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java +++ /dev/null @@ -1,212 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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; - -import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; -import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; -import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; -import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; -import static org.jclouds.vcloud.VCloudMediaType.TASK_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.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import org.jclouds.rest.annotations.EndpointParam; -import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.TasksList; -import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.domain.network.OrgNetwork; -import org.jclouds.vcloud.filters.SetVCloudTokenCookie; -import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint; -import org.jclouds.vcloud.functions.OrgNameVDCNameNetworkNameToEndpoint; -import org.jclouds.vcloud.xml.CatalogHandler; -import org.jclouds.vcloud.xml.CatalogItemHandler; -import org.jclouds.vcloud.xml.OrgHandler; -import org.jclouds.vcloud.xml.OrgNetworkHandler; -import org.jclouds.vcloud.xml.TaskHandler; -import org.jclouds.vcloud.xml.TasksListHandler; -import org.jclouds.vcloud.xml.VDCHandler; - -import com.google.common.util.concurrent.ListenableFuture; - -/** - * Provides access to VCloud resources via their REST API. - *

- * - * @see - * @author Adrian Cole - */ -@RequestFilters(SetVCloudTokenCookie.class) -public interface CommonVCloudAsyncClient { - - /** - * @see CommonVCloudClient#getOrg - */ - @GET - @XMLResponseParser(OrgHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Consumes(ORG_XML) - ListenableFuture getOrg(@EndpointParam URI orgId); - - /** - * @see CommonVCloudClient#getOrgNamed - */ - @GET - @XMLResponseParser(OrgHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Consumes(ORG_XML) - ListenableFuture findOrgNamed( - @Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName); - - /** - * @see CommonVCloudClient#getCatalog - */ - @GET - @XMLResponseParser(CatalogHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Consumes(CATALOG_XML) - ListenableFuture getCatalog(@EndpointParam URI catalogId); - - /** - * @see CommonVCloudClient#findCatalogInOrgNamed - */ - @GET - @XMLResponseParser(CatalogHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Consumes(CATALOG_XML) - ListenableFuture findCatalogInOrgNamed( - @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName); - - /** - * @see CommonVCloudClient#getCatalogItem - */ - @GET - @Consumes(CATALOGITEM_XML) - @XMLResponseParser(CatalogItemHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getCatalogItem(@EndpointParam URI catalogItem); - - /** - * @see CommonVCloudClient#getCatalogItemInOrg - */ - @GET - @Consumes(CATALOGITEM_XML) - @XMLResponseParser(CatalogItemHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture findCatalogItemInOrgCatalogNamed( - @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName, - @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); - - /** - * @see CommonVCloudClient#findNetworkInOrgVDCNamed - */ - @GET - @Consumes(NETWORK_XML) - @XMLResponseParser(OrgNetworkHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture findNetworkInOrgVDCNamed( - @Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String catalogName, - @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String networkName); - - /** - * @see CommonVCloudClient#getNetwork - */ - @GET - @Consumes(NETWORK_XML) - @XMLResponseParser(OrgNetworkHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getNetwork(@EndpointParam URI network); - - /** - * @see CommonVCloudClient#getVDC(URI) - */ - @GET - @XMLResponseParser(VDCHandler.class) - @Consumes(VDC_XML) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVDC(@EndpointParam URI vdc); - - /** - * @see CommonVCloudClient#findVDCInOrgNamed(String, String) - */ - @GET - @XMLResponseParser(VDCHandler.class) - @Consumes(VDC_XML) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture findVDCInOrgNamed( - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); - - /** - * @see CommonVCloudClient#getTasksList - */ - @GET - @Consumes(TASKSLIST_XML) - @XMLResponseParser(TasksListHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getTasksList(@EndpointParam URI tasksListId); - - /** - * @see CommonVCloudClient#findTasksListInOrgNamed - */ - @GET - @Consumes(TASKSLIST_XML) - @XMLResponseParser(TasksListHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture findTasksListInOrgNamed( - @Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName); - - /** - * @see CommonVCloudClient#getTask - */ - @GET - @Consumes(TASK_XML) - @XMLResponseParser(TaskHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getTask(@EndpointParam URI taskId); - - /** - * @see CommonVCloudClient#cancelTask - */ - @POST - @Path("/action/cancel") - ListenableFuture cancelTask(@EndpointParam URI taskId); - -} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java deleted file mode 100644 index 7d8d232ad1..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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; - -import java.net.URI; -import java.util.NoSuchElementException; -import java.util.concurrent.TimeUnit; - -import javax.annotation.Nullable; - -import org.jclouds.concurrent.Timeout; -import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.TasksList; -import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.domain.network.OrgNetwork; - -/** - * Provides access to VCloud resources via their REST API. - *

- * - * @see - * @author Adrian Cole - */ -@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) -public interface CommonVCloudClient { - - Org getOrg(URI orgId); - - /** - * This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within - * the organization. - * - * @param name - * organization name, or null for the default - * @throws NoSuchElementException - * if you specified an org name that isn't present - */ - Org findOrgNamed(@Nullable String name); - - Catalog getCatalog(URI catalogId); - - /** - * returns the catalog in the organization associated with the specified name. Note that both - * parameters can be null to choose default. - * - * @param orgName - * organization name, or null for the default - * @param catalogName - * catalog name, or null for the default - * @throws NoSuchElementException - * if you specified an org or catalog name that isn't present - */ - Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName); - - CatalogItem getCatalogItem(URI catalogItem); - - /** - * returns the catalog item in the catalog associated with the specified name. Note that the org - * and catalog parameters can be null to choose default. - * - * @param orgName - * organization name, or null for the default - * @param catalogName - * catalog name, or null for the default - * @param itemName - * item you wish to lookup - * - * @throws NoSuchElementException - * if you specified an org, catalog, or catalog item name that isn't present - */ - CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName); - - OrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName); - - OrgNetwork getNetwork(URI network); - - VDC getVDC(URI vdc); - - /** - * returns the VDC in the organization associated with the specified name. Note that both - * parameters can be null to choose default. - * - * @param orgName - * organization name, or null for the default - * @param vdcName - * catalog name, or null for the default - * @throws NoSuchElementException - * if you specified an org or vdc name that isn't present - */ - VDC findVDCInOrgNamed(String orgName, String vdcName); - - TasksList getTasksList(URI tasksListId); - - TasksList findTasksListInOrgNamed(String orgName); - - /** - * Whenever the result of a request cannot be returned immediately, the server creates a Task - * object and includes it in the response, as a member of the Tasks container in the response - * body. Each Task has an href value, which is a URL that the client can use to retrieve the Task - * element alone, without the rest of the response in which it was contained. All information - * about the task is included in the Task element when it is returned in the response’s Tasks - * container, so a client does not need to make an additional request to the Task URL unless it - * wants to follow the progress of a task that was incomplete. - */ - Task getTask(URI taskId); - - void cancelTask(URI taskId); - -} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index 6e507456ed..b4036e172a 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -18,13 +18,19 @@ */ package org.jclouds.vcloud; +import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; +import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML; import static org.jclouds.vcloud.VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML; import static org.jclouds.vcloud.VCloudMediaType.NETWORKCONNECTIONSECTION_XML; +import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; +import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; +import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML; 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 static org.jclouds.vcloud.VCloudMediaType.VM_XML; import java.io.InputStream; @@ -64,13 +70,19 @@ import org.jclouds.vcloud.binders.BindGuestCustomizationSectionToXmlPayload; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.binders.BindNetworkConnectionSectionToXmlPayload; import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.GuestCustomizationSection; import org.jclouds.vcloud.domain.NetworkConnectionSection; +import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.Vm; +import org.jclouds.vcloud.domain.network.OrgNetwork; import org.jclouds.vcloud.endpoints.OrgList; import org.jclouds.vcloud.features.CatalogAsyncClient; import org.jclouds.vcloud.features.NetworkAsyncClient; @@ -82,15 +94,27 @@ import org.jclouds.vcloud.features.VAppTemplateClient; import org.jclouds.vcloud.features.VDCAsyncClient; import org.jclouds.vcloud.features.VmAsyncClient; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint; +import org.jclouds.vcloud.functions.OrgNameVDCNameNetworkNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint; import org.jclouds.vcloud.options.CaptureVAppOptions; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.xml.CatalogHandler; +import org.jclouds.vcloud.xml.CatalogItemHandler; +import org.jclouds.vcloud.xml.OrgHandler; import org.jclouds.vcloud.xml.OrgListHandler; +import org.jclouds.vcloud.xml.OrgNetworkHandler; import org.jclouds.vcloud.xml.TaskHandler; +import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VAppTemplateHandler; +import org.jclouds.vcloud.xml.VDCHandler; import org.jclouds.vcloud.xml.VmHandler; import com.google.common.util.concurrent.ListenableFuture; @@ -104,8 +128,143 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) -public interface VCloudAsyncClient extends CommonVCloudAsyncClient { +public interface VCloudAsyncClient { + /** + * @see VCloudClient#getOrg + */ + @GET + @XMLResponseParser(OrgHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(ORG_XML) + ListenableFuture getOrg(@EndpointParam URI orgId); + /** + * @see VCloudClient#getOrgNamed + */ + @GET + @XMLResponseParser(OrgHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(ORG_XML) + ListenableFuture findOrgNamed( + @Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName); + + /** + * @see VCloudClient#getCatalog + */ + @GET + @XMLResponseParser(CatalogHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(CATALOG_XML) + ListenableFuture getCatalog(@EndpointParam URI catalogId); + + /** + * @see VCloudClient#findCatalogInOrgNamed + */ + @GET + @XMLResponseParser(CatalogHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(CATALOG_XML) + ListenableFuture findCatalogInOrgNamed( + @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName); + + /** + * @see VCloudClient#getCatalogItem + */ + @GET + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(CatalogItemHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getCatalogItem(@EndpointParam URI catalogItem); + + /** + * @see VCloudClient#getCatalogItemInOrg + */ + @GET + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(CatalogItemHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findCatalogItemInOrgCatalogNamed( + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); + + /** + * @see VCloudClient#findNetworkInOrgVDCNamed + */ + @GET + @Consumes(NETWORK_XML) + @XMLResponseParser(OrgNetworkHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findNetworkInOrgVDCNamed( + @Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String networkName); + + /** + * @see VCloudClient#getNetwork + */ + @GET + @Consumes(NETWORK_XML) + @XMLResponseParser(OrgNetworkHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getNetwork(@EndpointParam URI network); + + /** + * @see VCloudClient#getVDC(URI) + */ + @GET + @XMLResponseParser(VDCHandler.class) + @Consumes(VDC_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVDC(@EndpointParam URI vdc); + + /** + * @see VCloudClient#findVDCInOrgNamed(String, String) + */ + @GET + @XMLResponseParser(VDCHandler.class) + @Consumes(VDC_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findVDCInOrgNamed( + @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); + + /** + * @see VCloudClient#getTasksList + */ + @GET + @Consumes(TASKSLIST_XML) + @XMLResponseParser(TasksListHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTasksList(@EndpointParam URI tasksListId); + + /** + * @see VCloudClient#findTasksListInOrgNamed + */ + @GET + @Consumes(TASKSLIST_XML) + @XMLResponseParser(TasksListHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findTasksListInOrgNamed( + @Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName); + + /** + * @see VCloudClient#getTask + */ + @GET + @Consumes(TASK_XML) + @XMLResponseParser(TaskHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTask(@EndpointParam URI taskId); + + /** + * @see VCloudClient#cancelTask + */ + @POST + @Path("/action/cancel") + ListenableFuture cancelTask(@EndpointParam URI taskId); + /** * Provides asynchronous access to VApp Template features. * diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java index 4355c40232..fce97d29b3 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -61,7 +61,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; * @author Adrian Cole */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) -public interface VCloudClient extends CommonVCloudClient { +public interface VCloudClient { /** * Provides asynchronous access to VApp Template features. * @@ -281,7 +281,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see CatalogClient#getCatalog */ - @Override @Deprecated Catalog getCatalog(URI catalogId); @@ -289,7 +288,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see CatalogClient#getCatalogItem */ - @Override @Deprecated Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName); @@ -297,7 +295,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see CatalogClient#getCatalogItem */ - @Override @Deprecated CatalogItem getCatalogItem(URI catalogItem); @@ -305,7 +302,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see CatalogClient#findCatalogItemInOrgCatalogNamed */ - @Override @Deprecated CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName); @@ -313,7 +309,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see TaskClient#getTasksList */ - @Override @Deprecated TasksList getTasksList(URI tasksListId); @@ -321,7 +316,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see TaskClient#findTasksListInOrgNamed */ - @Override @Deprecated TasksList findTasksListInOrgNamed(String orgName); @@ -329,7 +323,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see TaskClient#getTask */ - @Override @Deprecated Task getTask(URI taskId); @@ -337,7 +330,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see TaskClient#cancelTask */ - @Override @Deprecated void cancelTask(URI taskId); @@ -345,7 +337,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see VDCClient#getVDC */ - @Override @Deprecated VDC getVDC(URI vdc); @@ -353,7 +344,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see VDCClient#findVDCInOrgNamed */ - @Override @Deprecated VDC findVDCInOrgNamed(String orgName, String vdcName); @@ -361,7 +351,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see NetworkClient#findNetworkInOrgVDCNamed */ - @Override @Deprecated OrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName); @@ -369,7 +358,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see NetworkClient#getNetwork */ - @Override @Deprecated OrgNetwork getNetwork(URI network); @@ -377,7 +365,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see OrgClient#getOrg */ - @Override @Deprecated Org getOrg(URI orgId); @@ -385,8 +372,6 @@ public interface VCloudClient extends CommonVCloudClient { * * @see OrgClient#findOrgNamed */ - @Override @Deprecated Org findOrgNamed(@Nullable String name); - } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/CommonVCloudComputeClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/CommonVCloudComputeClient.java deleted file mode 100644 index ba71d950da..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/CommonVCloudComputeClient.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.compute; - -import java.net.URI; -import java.util.Set; - -/** - * - * @author Adrian Cole - */ -public interface CommonVCloudComputeClient { - - /** - * returns a set of addresses that are only visible to the private network. - */ - Set getPrivateAddresses(URI vAppId); - - /** - * returns a set of addresses that are publically visible - */ - Set getPublicAddresses(URI vAppId); - - /** - * reboots the vApp, blocking until the following state transition is complete: - *

- * current -> {@code VAppStatus#OFF} -> {@code VAppStatus#ON} - * - * @param vAppId - * vApp to reboot - */ - void reset(URI vAppId); - - /** - * Destroys dependent resources, powers off and deletes the vApp, blocking until the following - * state transition is complete: - *

- * current -> {@code VAppStatus#OFF} -> deleted - * - * @param vAppId - * vApp to stop - */ - void stop(URI vAppId); - -} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeStrategiesByClass.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeStrategiesByClass.java deleted file mode 100644 index 6def15cbe2..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeStrategiesByClass.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.compute.config; - -import org.jclouds.compute.config.BindComputeStrategiesByClass; -import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet; -import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet; - -/** - * @author Adrian Cole - */ -public abstract class CommonVCloudBindComputeStrategiesByClass extends BindComputeStrategiesByClass { - - @Override - protected Class defineRunNodesAndAddToSetStrategy() { - return CreateNodesWithGroupEncodedIntoNameThenAddToSet.class; - } - -} \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeSuppliersByClass.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeSuppliersByClass.java deleted file mode 100644 index b65746e016..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudBindComputeSuppliersByClass.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.compute.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.find; - -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.collect.Memoized; -import org.jclouds.compute.config.BindComputeSuppliersByClass; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; -import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier; -import org.jclouds.vcloud.compute.suppliers.StaticHardwareSupplier; -import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.endpoints.VDC; - -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; - -/** - * @author Adrian Cole - */ -public class CommonVCloudBindComputeSuppliersByClass extends BindComputeSuppliersByClass { - @Override - protected Class>> defineHardwareSupplier() { - return StaticHardwareSupplier.class; - } - - @Override - protected Class>> defineImageSupplier() { - return VCloudImageSupplier.class; - } - - @Override - protected Class>> defineLocationSupplier() { - return OrgAndVDCToLocationSupplier.class; - } - - @Override - protected Class> defineDefaultLocationSupplier() { - return DefaultVDC.class; - } - - @Singleton - public static class DefaultVDC implements Supplier { - @Singleton - public static final class IsDefaultVDC implements Predicate { - private final ReferenceType defaultVDC; - - @Inject - IsDefaultVDC(@VDC ReferenceType defaultVDC) { - this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC"); - } - - @Override - public boolean apply(Location input) { - return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString()); - } - - @Override - public String toString() { - return "isDefaultVDC()"; - } - } - - private final Supplier> locationsSupplier; - private final IsDefaultVDC isDefaultVDC; - - @Inject - DefaultVDC(@Memoized Supplier> locationsSupplier, IsDefaultVDC isDefaultVDC) { - this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier"); - this.isDefaultVDC = checkNotNull(isDefaultVDC, "isDefaultVDC"); - } - - @Override - public Location get() { - return find(locationsSupplier.get(), isDefaultVDC); - } - - } -} \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java deleted file mode 100644 index e34f28dc62..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.compute.config; - -import java.util.Map; - -import javax.inject.Singleton; - -import org.jclouds.compute.config.BaseComputeServiceContextModule; -import org.jclouds.compute.config.BindComputeStrategiesByClass; -import org.jclouds.compute.config.BindComputeSuppliersByClass; -import org.jclouds.compute.domain.NodeState; -import org.jclouds.vcloud.domain.Status; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; -import com.google.inject.Provides; - -/** - * Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl} - * bound. - * - * @author Adrian Cole - */ -public abstract class CommonVCloudComputeServiceContextModule extends BaseComputeServiceContextModule { - - @VisibleForTesting - public static final Map VAPPSTATUS_TO_NODESTATE = ImmutableMap. builder() - .put(Status.OFF, NodeState.SUSPENDED).put(Status.ON, NodeState.RUNNING) - .put(Status.RESOLVED, NodeState.PENDING).put(Status.ERROR, NodeState.ERROR) - .put(Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(Status.DEPLOYED, NodeState.PENDING) - .put(Status.INCONSISTENT, NodeState.PENDING).put(Status.UNKNOWN, NodeState.UNRECOGNIZED) - .put(Status.MIXED, NodeState.PENDING).put(Status.WAITING_FOR_INPUT, NodeState.PENDING) - .put(Status.SUSPENDED, NodeState.SUSPENDED).put(Status.UNRESOLVED, NodeState.PENDING).build(); - - @Singleton - @Provides - protected Map provideVAppStatusToNodeState() { - return VAPPSTATUS_TO_NODESTATE; - } - - @Override - protected void configure() { - super.configure(); - install(defineComputeStrategyModule()); - install(defineComputeSupplierModule()); - } - - public abstract BindComputeStrategiesByClass defineComputeStrategyModule(); - - public abstract BindComputeSuppliersByClass defineComputeSupplierModule(); - -} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java index 58c01f30a1..4dba542bf4 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java @@ -18,22 +18,31 @@ */ package org.jclouds.vcloud.compute.config; +import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName; +import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet; 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.SuspendNodeStrategy; +import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet; import org.jclouds.vcloud.compute.strategy.InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn; import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy; -import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudLifeCycleStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; /** * @author Adrian Cole */ -public class VCloudBindComputeStrategiesByClass extends CommonVCloudBindComputeStrategiesByClass { +public class VCloudBindComputeStrategiesByClass extends BindComputeStrategiesByClass { + + @Override + protected Class defineRunNodesAndAddToSetStrategy() { + return CreateNodesWithGroupEncodedIntoNameThenAddToSet.class; + } + @Override protected Class defineAddNodeWithTagStrategy() { return InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.class; diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeSuppliersByClass.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeSuppliersByClass.java index 70b0c00a5c..259bf9e8e6 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeSuppliersByClass.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeSuppliersByClass.java @@ -18,16 +18,85 @@ */ package org.jclouds.vcloud.compute.config; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.find; + import java.util.Set; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.vcloud.compute.suppliers.VCloudHardwareSupplier; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.config.BindComputeSuppliersByClass; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier; +import org.jclouds.vcloud.compute.suppliers.VCloudHardwareSupplier; +import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.endpoints.VDC; + +import com.google.common.base.Predicate; import com.google.common.base.Supplier; /** * @author Adrian Cole */ -public class VCloudBindComputeSuppliersByClass extends CommonVCloudBindComputeSuppliersByClass { +public class VCloudBindComputeSuppliersByClass extends BindComputeSuppliersByClass { + + @Override + protected Class>> defineImageSupplier() { + return VCloudImageSupplier.class; + } + + @Override + protected Class>> defineLocationSupplier() { + return OrgAndVDCToLocationSupplier.class; + } + + @Override + protected Class> defineDefaultLocationSupplier() { + return DefaultVDC.class; + } + + @Singleton + public static class DefaultVDC implements Supplier { + @Singleton + public static final class IsDefaultVDC implements Predicate { + private final ReferenceType defaultVDC; + + @Inject + IsDefaultVDC(@VDC ReferenceType defaultVDC) { + this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC"); + } + + @Override + public boolean apply(Location input) { + return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString()); + } + + @Override + public String toString() { + return "isDefaultVDC()"; + } + } + + private final Supplier> locationsSupplier; + private final IsDefaultVDC isDefaultVDC; + + @Inject + DefaultVDC(@Memoized Supplier> locationsSupplier, IsDefaultVDC isDefaultVDC) { + this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier"); + this.isDefaultVDC = checkNotNull(isDefaultVDC, "isDefaultVDC"); + } + + @Override + public Location get() { + return find(locationsSupplier.get(), isDefaultVDC); + } + + } @Override protected Class>> defineHardwareSupplier() { diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index a7d0a46bb5..a1f076d029 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -21,12 +21,18 @@ package org.jclouds.vcloud.compute.config; import static org.jclouds.compute.domain.OsFamily.UBUNTU; +import java.util.Map; + +import javax.inject.Singleton; + import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeSuppliersByClass; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.options.TemplateOptions; @@ -42,10 +48,14 @@ import org.jclouds.vcloud.compute.internal.VCloudTemplateBuilderImpl; import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; import org.jclouds.vcloud.compute.strategy.GetLoginCredentialsFromGuestConfiguration; import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VApp; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; import com.google.inject.Injector; +import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -55,11 +65,28 @@ import com.google.inject.TypeLiteral; * * @author Adrian Cole */ -public class VCloudComputeServiceContextModule extends CommonVCloudComputeServiceContextModule { +public class VCloudComputeServiceContextModule extends BaseComputeServiceContextModule { + + @VisibleForTesting + public static final Map VAPPSTATUS_TO_NODESTATE = ImmutableMap. builder() + .put(Status.OFF, NodeState.SUSPENDED).put(Status.ON, NodeState.RUNNING) + .put(Status.RESOLVED, NodeState.PENDING).put(Status.ERROR, NodeState.ERROR) + .put(Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(Status.DEPLOYED, NodeState.PENDING) + .put(Status.INCONSISTENT, NodeState.PENDING).put(Status.UNKNOWN, NodeState.UNRECOGNIZED) + .put(Status.MIXED, NodeState.PENDING).put(Status.WAITING_FOR_INPUT, NodeState.PENDING) + .put(Status.SUSPENDED, NodeState.SUSPENDED).put(Status.UNRESOLVED, NodeState.PENDING).build(); + + @Singleton + @Provides + protected Map provideVAppStatusToNodeState() { + return VAPPSTATUS_TO_NODESTATE; + } @Override protected void configure() { super.configure(); + install(defineComputeStrategyModule()); + install(defineComputeSupplierModule()); bind(new TypeLiteral>() { }).to(VAppToNodeMetadata.class); bind(TemplateOptions.class).to(VCloudTemplateOptions.class); @@ -88,12 +115,10 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic return template.osFamily(UBUNTU).os64Bit(true); } - @Override public BindComputeStrategiesByClass defineComputeStrategyModule() { return new VCloudBindComputeStrategiesByClass(); } - @Override public BindComputeSuppliersByClass defineComputeSupplierModule() { return new VCloudBindComputeSuppliersByClass(); } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java deleted file mode 100644 index 7f48fcd0e9..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.compute.internal; - -import java.net.URI; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; -import org.jclouds.vcloud.CommonVCloudClient; -import org.jclouds.vcloud.compute.CommonVCloudComputeClient; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.Task; - -import com.google.common.base.Predicate; -import com.google.inject.Inject; - -/** - * @author Adrian Cole - */ -@Singleton -public abstract class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - protected final CommonVCloudClient client; - protected final Predicate taskTester; - - @Inject - public CommonVCloudComputeClientImpl(CommonVCloudClient client, Predicate successTester) { - this.client = client; - this.taskTester = successTester; - } - - @Override - public void reset(URI id) { - A vApp = refreshVApp(id); - logger.debug(">> resetting vApp(%s)", vApp.getName()); - Task task = reset(vApp); - if (!taskTester.apply(task.getHref())) { - throw new RuntimeException(String.format("failed to %s %s: %s", "resetVApp", vApp.getName(), task)); - } - logger.debug("<< on vApp(%s)", vApp.getName()); - } - - protected abstract Task reset(A vApp); - - protected abstract A refreshVApp(URI id); - - @Override - public void stop(URI id) { - A vApp = refreshVApp(id); - vApp = powerOffVAppIfDeployed(vApp); - vApp = undeployVAppIfDeployed(vApp); - deleteVApp(vApp); - logger.debug("<< deleted vApp(%s)", vApp.getName()); - } - - protected abstract void deleteVApp(A vApp); - - private A undeployVAppIfDeployed(A vApp) { - if (getStatus(vApp).compareTo(Status.RESOLVED) > 0) { - logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), getStatus(vApp)); - Task task = undeploy(vApp); - if (!taskTester.apply(task.getHref())) { - // TODO timeout - throw new RuntimeException(String.format("failed to %s %s: %s", "undeploy", vApp.getName(), task)); - } - vApp = refreshVApp(vApp.getHref()); - logger.debug("<< %s vApp(%s)", getStatus(vApp), vApp.getName()); - } - return vApp; - } - - protected abstract Task undeploy(A vApp); - - private A powerOffVAppIfDeployed(A vApp) { - if (getStatus(vApp).compareTo(Status.OFF) > 0) { - logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), getStatus(vApp)); - Task task = powerOff(vApp); - if (!taskTester.apply(task.getHref())) { - // TODO timeout - throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task)); - } - vApp = refreshVApp(vApp.getHref()); - logger.debug("<< %s vApp(%s)", getStatus(vApp), vApp.getName()); - } - return vApp; - } - - protected abstract Task powerOff(A vApp); - - protected abstract Status getStatus(A vApp); - - @Override - public abstract Set getPrivateAddresses(URI id); - - @Override - public abstract Set getPublicAddresses(URI id); - -} \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java index 8c44e5b8b6..ff6b41662f 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java @@ -34,18 +34,18 @@ import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.CommonVCloudClient; +import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.compute.functions.FindLocationForResource; +import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.endpoints.Org; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableSet.Builder; import com.google.inject.Inject; /** @@ -57,9 +57,12 @@ public class VCloudListNodesStrategy implements ListNodesStrategy { @Resource @Named(COMPUTE_LOGGER) public Logger logger = Logger.NULL; + + protected final VCloudClient client; + protected final Supplier> nameToOrg; protected final VCloudGetNodeMetadataStrategy getNodeMetadata; - protected final CommonVCloudClient client; protected final FindLocationForResource findLocationForResourceInVDC; + Set blackListVAppNames = ImmutableSet. of(); @Inject(optional = true) @@ -68,31 +71,28 @@ public class VCloudListNodesStrategy implements ListNodesStrategy { this.blackListVAppNames = ImmutableSet.copyOf(Splitter.on(',').split(blackListNodes)); } - private final Supplier> orgNameToEndpoint; - @Inject - protected VCloudListNodesStrategy(CommonVCloudClient client, - @Org Supplier> orgNameToEndpoint, VCloudGetNodeMetadataStrategy getNodeMetadata, - FindLocationForResource findLocationForResourceInVDC) { + protected VCloudListNodesStrategy(VCloudClient client, Supplier> nameToOrg, + VCloudGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) { this.client = client; - this.orgNameToEndpoint = orgNameToEndpoint; + this.nameToOrg = nameToOrg; this.getNodeMetadata = getNodeMetadata; this.findLocationForResourceInVDC = findLocationForResourceInVDC; } @Override public Iterable listNodes() { - Set nodes = Sets.newHashSet(); - for (String org : orgNameToEndpoint.get().keySet()) { - for (ReferenceType vdc : client.findOrgNamed(org).getVDCs().values()) { - for (ReferenceType resource : client.getVDC(vdc.getHref()).getResourceEntities().values()) { + Builder nodes = ImmutableSet. builder(); + for (Org org : nameToOrg.get().values()) { + for (ReferenceType vdc : org.getVDCs().values()) { + for (ReferenceType resource : client.getVDCClient().getVDC(vdc.getHref()).getResourceEntities().values()) { if (validVApp(resource)) { nodes.add(convertVAppToComputeMetadata(vdc, resource)); } } } } - return nodes; + return nodes.build(); } private boolean validVApp(ReferenceType resource) { @@ -110,21 +110,21 @@ public class VCloudListNodesStrategy implements ListNodesStrategy { @Override public Iterable listDetailsOnNodesMatching(Predicate filter) { - Set nodes = Sets.newHashSet(); - for (String org : orgNameToEndpoint.get().keySet()) { - for (ReferenceType vdc : client.findOrgNamed(org).getVDCs().values()) { - for (ReferenceType resource : client.getVDC(vdc.getHref()).getResourceEntities().values()) { + Builder nodes = ImmutableSet. builder(); + for (Org org : nameToOrg.get().values()) { + for (ReferenceType vdc : org.getVDCs().values()) { + for (ReferenceType resource : client.getVDCClient().getVDC(vdc.getHref()).getResourceEntities().values()) { if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) { addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource); } } } } - return nodes; + return nodes.build(); } @VisibleForTesting - void addVAppToSetRetryingIfNotYetPresent(Set nodes, ReferenceType vdc, ReferenceType resource) { + void addVAppToSetRetryingIfNotYetPresent(Builder nodes, ReferenceType vdc, ReferenceType resource) { NodeMetadata node = null; int i = 0; while (node == null && i++ < 3) { diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java deleted file mode 100644 index 0a8d53f7fa..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.config; - -import static com.google.common.base.Throwables.propagate; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; - -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler; -import org.jclouds.http.RequiresHttp; -import org.jclouds.rest.AsyncClientFactory; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; -import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.VCloudLoginAsyncClient; -import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.VAppTemplate; -import org.jclouds.vcloud.domain.VCloudSession; -import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; -import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; - -/** - * Configures the VCloud authentication service connection, including logging - * and http transport. - * - * @author Adrian Cole - */ -@RequiresHttp -@ConfiguresRestClient -public abstract class BaseVCloudRestClientModule extends - CommonVCloudRestClientModule { - - public BaseVCloudRestClientModule(Class syncClientType, Class asyncClientType) { - super(syncClientType, asyncClientType); - } - - public BaseVCloudRestClientModule(Class syncClientType, Class asyncClientType, - Map, Class> delegateMap) { - super(syncClientType, asyncClientType, delegateMap); - } - - @Override - protected void configure() { - bind(new TypeLiteral, Iterable>>() { - }).to(new TypeLiteral() { - }); - bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class); - super.configure(); - } - - @Provides - @Singleton - protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) { - return factory.create(VCloudLoginAsyncClient.class); - } - - @Provides - @Singleton - protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - AtomicReference authException, final VCloudLoginAsyncClient login) { - return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(authException, seconds, - new Supplier() { - - @Override - public VCloudSession get() { - try { - return login.login().get(10, TimeUnit.SECONDS); - } catch (Exception e) { - propagate(e); - assert false : e; - return null; - } - } - - }); - } -} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java deleted file mode 100644 index 95dcf06a98..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java +++ /dev/null @@ -1,452 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.getLast; -import static com.google.common.collect.Iterables.transform; -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_SESSION_INTERVAL; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; - -import java.net.URI; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicReference; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.domain.Location; -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.RequiresHttp; -import org.jclouds.http.annotation.ClientError; -import org.jclouds.http.annotation.Redirection; -import org.jclouds.http.annotation.ServerError; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.AsyncClientFactory; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.config.RestClientModule; -import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; -import org.jclouds.vcloud.CommonVCloudAsyncClient; -import org.jclouds.vcloud.CommonVCloudClient; -import org.jclouds.vcloud.VCloudToken; -import org.jclouds.vcloud.VCloudVersionsAsyncClient; -import org.jclouds.vcloud.compute.functions.FindLocationForResource; -import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.VCloudSession; -import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.endpoints.OrgList; -import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog; -import org.jclouds.vcloud.functions.AllCatalogItemsInOrg; -import org.jclouds.vcloud.functions.AllCatalogsInOrg; -import org.jclouds.vcloud.functions.AllVDCsInOrg; -import org.jclouds.vcloud.functions.OrgsForLocations; -import org.jclouds.vcloud.functions.OrgsForNames; -import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse; -import org.jclouds.vcloud.predicates.TaskSuccess; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.inject.Injector; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; - -/** - * Configures the VCloud authentication service connection, including logging - * and http transport. - * - * @author Adrian Cole - */ -@RequiresHttp -@ConfiguresRestClient -public class CommonVCloudRestClientModule extends - RestClientModule { - - public CommonVCloudRestClientModule(Class syncClientType, Class asyncClientType) { - super(syncClientType, asyncClientType); - } - - public CommonVCloudRestClientModule(Class syncClientType, Class asyncClientType, - Map, Class> delegateMap) { - super(syncClientType, asyncClientType, delegateMap); - } - - @Override - protected void configure() { - super.configure(); - // Ensures we don't retry on authorization failures - bind(new TypeLiteral>() { - }).toInstance(new AtomicReference()); - installDefaultVCloudEndpointsModule(); - bind(new TypeLiteral>() { - }).to(new TypeLiteral() { - }); - bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { - }); - bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { - }); - bind(new TypeLiteral, Iterable>>() { - }).to(new TypeLiteral() { - }); - bind(new TypeLiteral, Iterable>>() { - }).to(new TypeLiteral() { - }); - bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { - }); - bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { - }); - } - - @Singleton - @Provides - CommonVCloudAsyncClient provideCommonVCloudAsyncClient(A in) { - return in; - } - - @Singleton - @Provides - CommonVCloudClient provideCommonVCloudClient(S in) { - return in; - } - - @Provides - @Singleton - @org.jclouds.vcloud.endpoints.VDC - protected Supplier> provideVDCtoORG(Supplier> orgNameToOrgSuppier) { - return Suppliers.compose(new Function, Map>() { - - @Override - public Map apply(Map arg0) { - Builder returnVal = ImmutableMap. builder(); - for (Entry orgr : arg0.entrySet()) { - for (String vdc : orgr.getValue().getVDCs().keySet()) { - returnVal.put(vdc, orgr.getKey()); - } - } - return returnVal.build(); - } - }, orgNameToOrgSuppier); - - } - - @Provides - @Singleton - protected Supplier> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - AtomicReference authException, OrgMapSupplier supplier) { - return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( - authException, seconds, supplier); - } - - @Provides - @Singleton - @OrgList - URI provideOrgListURI(Supplier sessionSupplier) { - VCloudSession session = sessionSupplier.get(); - return URI.create(getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org")); - } - - @Singleton - public static class OrgMapSupplier implements Supplier> { - protected final Supplier sessionSupplier; - protected final Function, Iterable> organizationsForNames; - - @Inject - protected OrgMapSupplier(Supplier sessionSupplier, - Function, Iterable> organizationsForNames) { - this.sessionSupplier = sessionSupplier; - this.organizationsForNames = organizationsForNames; - } - - @Override - public Map get() { - return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name); - } - } - - protected void installDefaultVCloudEndpointsModule() { - install(new DefaultVCloudReferencesModule()); - } - - @Singleton - public static class OrgCatalogSupplier implements - Supplier>> { - protected final Supplier> orgSupplier; - protected final Function> allCatalogsInOrg; - - @Inject - protected OrgCatalogSupplier(Supplier> orgSupplier, - Function> allCatalogsInOrg) { - this.orgSupplier = orgSupplier; - this.allCatalogsInOrg = allCatalogsInOrg; - } - - @Override - public Map> get() { - return transformValues( - transformValues(orgSupplier.get(), allCatalogsInOrg), - new Function, Map>() { - - @Override - public Map apply( - Iterable from) { - return uniqueIndex(from, name); - } - - }); - } - } - - @VCloudToken - @Provides - String provideVCloudToken(Supplier cache) { - return checkNotNull(cache.get().getVCloudToken(), "No token present in session"); - } - - @Provides - @org.jclouds.vcloud.endpoints.Org - @Singleton - protected Supplier> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - AtomicReference authException, OrgNameToOrgSupplier supplier) { - return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( - authException, seconds, supplier); - } - - @Provides - @Singleton - protected Supplier> provideURIToVDC( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, - URItoVDC supplier) { - return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( - authException, seconds, supplier); - } - - @Singleton - public static class URItoVDC implements Supplier> { - private final Supplier>> orgVDCMap; - - @Inject - URItoVDC(Supplier>> orgVDCMap) { - this.orgVDCMap = orgVDCMap; - } - - @Override - public Map get() { - return uniqueIndex( - concat(transform( - orgVDCMap.get().values(), - new Function, Iterable>() { - - @Override - public Iterable apply( - Map from) { - return from.values(); - } - - })), new Function() { - - @Override - public URI apply(org.jclouds.vcloud.domain.VDC from) { - return from.getHref(); - } - - }); - } - - } - - final static Function name = new Function() { - - @Override - public String apply(ReferenceType from) { - return from.getName(); - } - - }; - - @Provides - @Singleton - @org.jclouds.vcloud.endpoints.VCloudLogin - protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, - @Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException { - SortedMap versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS); - checkState(versions.size() > 0, "No versions present"); - checkState(versions.containsKey(version), "version " + version + " not present in: " + versions); - return versions.get(version); - } - - @Singleton - private static class OrgNameToOrgSupplier implements Supplier> { - private final Supplier sessionSupplier; - - @SuppressWarnings("unused") - @Inject - OrgNameToOrgSupplier(Supplier sessionSupplier) { - this.sessionSupplier = sessionSupplier; - } - - @Override - public Map get() { - return sessionSupplier.get().getOrgs(); - } - - } - - @Provides - @Singleton - protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) { - return factory.create(VCloudVersionsAsyncClient.class); - } - - @Provides - @Singleton - protected Org provideOrg(Supplier> orgSupplier, - @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) { - return orgSupplier.get().get(defaultOrg.getName()); - } - - @Provides - @Singleton - protected Predicate successTester(Injector injector, - @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { - return new RetryablePredicate(injector.getInstance(TaskSuccess.class), completed); - } - - @Provides - @Singleton - protected Supplier>> provideOrgCatalogItemMapSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, - OrgCatalogSupplier supplier) { - return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( - authException, seconds, supplier); - } - - @Provides - @Singleton - protected Supplier>> provideOrgVDCSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, - OrgVDCSupplier supplier) { - return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( - authException, seconds, supplier); - } - - @Singleton - public static class OrgVDCSupplier implements - Supplier>> { - protected final Supplier> orgSupplier; - private final Function> allVDCsInOrg; - - @Inject - protected OrgVDCSupplier(Supplier> orgSupplier, - Function> allVDCsInOrg) { - this.orgSupplier = orgSupplier; - this.allVDCsInOrg = allVDCsInOrg; - } - - @Override - public Map> get() { - return transformValues( - transformValues(orgSupplier.get(), allVDCsInOrg), - new Function, Map>() { - - @Override - public Map apply( - Iterable from) { - return uniqueIndex(from, name); - } - - }); - } - } - - @Singleton - public static class OrgCatalogItemSupplier implements - Supplier>>> { - protected final Supplier>> catalogSupplier; - protected final Function> allCatalogItemsInCatalog; - - @Inject - protected OrgCatalogItemSupplier( - Supplier>> catalogSupplier, - Function> allCatalogItemsInCatalog) { - this.catalogSupplier = catalogSupplier; - this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; - } - - @Override - public Map>> get() { - return transformValues( - catalogSupplier.get(), - new Function, Map>>() { - - @Override - public Map> apply( - Map from) { - return transformValues( - from, - new Function>() { - - @Override - public Map apply(org.jclouds.vcloud.domain.Catalog from) { - return uniqueIndex(allCatalogItemsInCatalog.apply(from), name); - } - }); - - } - }); - } - } - - @Provides - @Singleton - protected Supplier>>> provideOrgCatalogItemSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, - OrgCatalogItemSupplier supplier) { - return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>>( - authException, seconds, supplier); - } - - @Override - protected void bindErrorHandlers() { - bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class); - bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class); - bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class); - } -} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index bb7249e3b9..20e6139621 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -18,12 +18,57 @@ */ package org.jclouds.vcloud.config; -import java.util.Map; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Throwables.propagate; +import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Iterables.getLast; +import static com.google.common.collect.Iterables.transform; +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_SESSION_INTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; +import java.net.URI; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicReference; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler; +import org.jclouds.domain.Location; +import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.RequiresHttp; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.rest.AsyncClientFactory; +import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudToken; +import org.jclouds.vcloud.VCloudVersionsAsyncClient; +import org.jclouds.vcloud.compute.functions.FindLocationForResource; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudSession; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.endpoints.OrgList; import org.jclouds.vcloud.features.CatalogAsyncClient; import org.jclouds.vcloud.features.CatalogClient; import org.jclouds.vcloud.features.NetworkAsyncClient; @@ -40,17 +85,37 @@ import org.jclouds.vcloud.features.VDCAsyncClient; import org.jclouds.vcloud.features.VDCClient; import org.jclouds.vcloud.features.VmAsyncClient; import org.jclouds.vcloud.features.VmClient; +import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog; +import org.jclouds.vcloud.functions.AllCatalogItemsInOrg; +import org.jclouds.vcloud.functions.AllCatalogsInOrg; +import org.jclouds.vcloud.functions.AllVDCsInOrg; +import org.jclouds.vcloud.functions.OrgsForLocations; +import org.jclouds.vcloud.functions.OrgsForNames; +import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; +import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse; +import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; +import org.jclouds.vcloud.predicates.TaskSuccess; +import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; +import com.google.inject.Injector; +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 class VCloudRestClientModule extends BaseVCloudRestClientModule { +public class VCloudRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// .put(VAppTemplateClient.class, VAppTemplateAsyncClient.class)// @@ -67,4 +132,367 @@ public class VCloudRestClientModule extends BaseVCloudRestClientModule provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + AtomicReference authException, final VCloudLoginAsyncClient login) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(authException, seconds, + new Supplier() { + + @Override + public VCloudSession get() { + try { + return login.login().get(10, TimeUnit.SECONDS); + } catch (Exception e) { + propagate(e); + assert false : e; + return null; + } + } + + }); + } + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class); + // Ensures we don't retry on authorization failures + bind(new TypeLiteral>() { + }).toInstance(new AtomicReference()); + installDefaultVCloudEndpointsModule(); + bind(new TypeLiteral>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + } + + @Provides + @Singleton + @org.jclouds.vcloud.endpoints.VDC + protected Supplier> provideVDCtoORG(Supplier> orgNameToOrgSuppier) { + return Suppliers.compose(new Function, Map>() { + + @Override + public Map apply(Map arg0) { + Builder returnVal = ImmutableMap. builder(); + for (Entry orgr : arg0.entrySet()) { + for (String vdc : orgr.getValue().getVDCs().keySet()) { + returnVal.put(vdc, orgr.getKey()); + } + } + return returnVal.build(); + } + }, orgNameToOrgSuppier); + + } + + @Provides + @Singleton + protected Supplier> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + AtomicReference authException, OrgMapSupplier supplier) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + authException, seconds, supplier); + } + + @Provides + @Singleton + @OrgList + URI provideOrgListURI(Supplier sessionSupplier) { + VCloudSession session = sessionSupplier.get(); + return URI.create(getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org")); + } + + @Singleton + public static class OrgMapSupplier implements Supplier> { + protected final Supplier sessionSupplier; + protected final Function, Iterable> organizationsForNames; + + @Inject + protected OrgMapSupplier(Supplier sessionSupplier, + Function, Iterable> organizationsForNames) { + this.sessionSupplier = sessionSupplier; + this.organizationsForNames = organizationsForNames; + } + + @Override + public Map get() { + return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name); + } + } + + protected void installDefaultVCloudEndpointsModule() { + install(new DefaultVCloudReferencesModule()); + } + + @Singleton + public static class OrgCatalogSupplier implements + Supplier>> { + protected final Supplier> orgSupplier; + protected final Function> allCatalogsInOrg; + + @Inject + protected OrgCatalogSupplier(Supplier> orgSupplier, + Function> allCatalogsInOrg) { + this.orgSupplier = orgSupplier; + this.allCatalogsInOrg = allCatalogsInOrg; + } + + @Override + public Map> get() { + return transformValues( + transformValues(orgSupplier.get(), allCatalogsInOrg), + new Function, Map>() { + + @Override + public Map apply( + Iterable from) { + return uniqueIndex(from, name); + } + + }); + } + } + + @VCloudToken + @Provides + String provideVCloudToken(Supplier cache) { + return checkNotNull(cache.get().getVCloudToken(), "No token present in session"); + } + + @Provides + @org.jclouds.vcloud.endpoints.Org + @Singleton + protected Supplier> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + AtomicReference authException, OrgNameToOrgSupplier supplier) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + authException, seconds, supplier); + } + + @Provides + @Singleton + protected Supplier> provideURIToVDC( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, + URItoVDC supplier) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + authException, seconds, supplier); + } + + @Singleton + public static class URItoVDC implements Supplier> { + private final Supplier>> orgVDCMap; + + @Inject + URItoVDC(Supplier>> orgVDCMap) { + this.orgVDCMap = orgVDCMap; + } + + @Override + public Map get() { + return uniqueIndex( + concat(transform( + orgVDCMap.get().values(), + new Function, Iterable>() { + + @Override + public Iterable apply( + Map from) { + return from.values(); + } + + })), new Function() { + + @Override + public URI apply(org.jclouds.vcloud.domain.VDC from) { + return from.getHref(); + } + + }); + } + + } + + final static Function name = new Function() { + + @Override + public String apply(ReferenceType from) { + return from.getName(); + } + + }; + + @Provides + @Singleton + @org.jclouds.vcloud.endpoints.VCloudLogin + protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, + @Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException { + SortedMap versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS); + checkState(versions.size() > 0, "No versions present"); + checkState(versions.containsKey(version), "version " + version + " not present in: " + versions); + return versions.get(version); + } + + @Singleton + private static class OrgNameToOrgSupplier implements Supplier> { + private final Supplier sessionSupplier; + + @SuppressWarnings("unused") + @Inject + OrgNameToOrgSupplier(Supplier sessionSupplier) { + this.sessionSupplier = sessionSupplier; + } + + @Override + public Map get() { + return sessionSupplier.get().getOrgs(); + } + + } + + @Provides + @Singleton + protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) { + return factory.create(VCloudVersionsAsyncClient.class); + } + + @Provides + @Singleton + protected Org provideOrg(Supplier> orgSupplier, + @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) { + return orgSupplier.get().get(defaultOrg.getName()); + } + + @Provides + @Singleton + protected Predicate successTester(Injector injector, + @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { + return new RetryablePredicate(injector.getInstance(TaskSuccess.class), completed); + } + + @Provides + @Singleton + protected Supplier>> provideOrgCatalogItemMapSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, + OrgCatalogSupplier supplier) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( + authException, seconds, supplier); + } + + @Provides + @Singleton + protected Supplier>> provideOrgVDCSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, + OrgVDCSupplier supplier) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( + authException, seconds, supplier); + } + + @Singleton + public static class OrgVDCSupplier implements + Supplier>> { + protected final Supplier> orgSupplier; + private final Function> allVDCsInOrg; + + @Inject + protected OrgVDCSupplier(Supplier> orgSupplier, + Function> allVDCsInOrg) { + this.orgSupplier = orgSupplier; + this.allVDCsInOrg = allVDCsInOrg; + } + + @Override + public Map> get() { + return transformValues( + transformValues(orgSupplier.get(), allVDCsInOrg), + new Function, Map>() { + + @Override + public Map apply( + Iterable from) { + return uniqueIndex(from, name); + } + + }); + } + } + + @Singleton + public static class OrgCatalogItemSupplier implements + Supplier>>> { + protected final Supplier>> catalogSupplier; + protected final Function> allCatalogItemsInCatalog; + + @Inject + protected OrgCatalogItemSupplier( + Supplier>> catalogSupplier, + Function> allCatalogItemsInCatalog) { + this.catalogSupplier = catalogSupplier; + this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; + } + + @Override + public Map>> get() { + return transformValues( + catalogSupplier.get(), + new Function, Map>>() { + + @Override + public Map> apply( + Map from) { + return transformValues( + from, + new Function>() { + + @Override + public Map apply(org.jclouds.vcloud.domain.Catalog from) { + return uniqueIndex(allCatalogItemsInCatalog.apply(from), name); + } + }); + + } + }); + } + } + + @Provides + @Singleton + protected Supplier>>> provideOrgCatalogItemSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference authException, + OrgCatalogItemSupplier supplier) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>>( + authException, seconds, supplier); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class); + } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java index ec8c4158ce..58728dde9e 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java @@ -31,7 +31,7 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.CommonVCloudAsyncClient; +import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.CatalogItem; @@ -48,11 +48,11 @@ public class AllCatalogItemsInCatalog implements Function, Iterable> { @Resource public Logger logger = Logger.NULL; - private final CommonVCloudAsyncClient aclient; + private final VCloudAsyncClient aclient; private final ExecutorService executor; @Inject - OrgsForLocations(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + OrgsForLocations(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java index edaa2d0dc4..57bcad90ce 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java @@ -30,7 +30,7 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.CommonVCloudAsyncClient; +import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.domain.Org; import com.google.common.base.Function; @@ -42,11 +42,11 @@ import com.google.common.base.Function; public class OrgsForNames implements Function, Iterable> { @Resource public Logger logger = Logger.NULL; - private final CommonVCloudAsyncClient aclient; + private final VCloudAsyncClient aclient; private final ExecutorService executor; @Inject - OrgsForNames(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + OrgsForNames(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java index 718fa03489..900f128546 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java @@ -36,7 +36,6 @@ import org.jclouds.concurrent.ExceptionParsingListenableFuture; import org.jclouds.concurrent.Futures; import org.jclouds.logging.Logger; import org.jclouds.rest.AuthorizationException; -import org.jclouds.vcloud.CommonVCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.CatalogItem; @@ -54,7 +53,7 @@ public class VAppTemplatesForCatalogItems implements @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; - private final CommonVCloudAsyncClient aclient; + private final VCloudAsyncClient aclient; private final ExecutorService executor; private final ReturnNullOnAuthorizationException returnNullOnAuthorizationException; @@ -70,7 +69,7 @@ public class VAppTemplatesForCatalogItems implements } @Inject - VAppTemplatesForCatalogItems(CommonVCloudAsyncClient aclient, + VAppTemplatesForCatalogItems(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, ReturnNullOnAuthorizationException returnNullOnAuthorizationException) { this.aclient = aclient; diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudLoginAsyncClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClient.java similarity index 95% rename from apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudLoginAsyncClient.java rename to apis/vcloud/src/main/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClient.java index b998d8ceb1..0bf6f887ef 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudLoginAsyncClient.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClient.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.vcloud; +package org.jclouds.vcloud.internal; import javax.ws.rs.Consumes; import javax.ws.rs.POST; @@ -25,6 +25,7 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java index 2dcb16a881..154f14ce2a 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java @@ -24,7 +24,7 @@ import javax.annotation.Resource; import javax.inject.Singleton; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.CommonVCloudClient; +import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TaskStatus; @@ -40,20 +40,20 @@ import com.google.inject.Inject; @Singleton public class TaskSuccess implements Predicate { - private final CommonVCloudClient client; + private final VCloudClient client; @Resource protected Logger logger = Logger.NULL; @Inject - public TaskSuccess(CommonVCloudClient client) { + public TaskSuccess(VCloudClient client) { this.client = client; } public boolean apply(URI taskId) { logger.trace("looking for status on task %s", taskId); - Task task = client.getTask(taskId); + Task task = client.getTaskClient().getTask(taskId); // perhaps task isn't available, yet if (task == null) return false; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java deleted file mode 100644 index 794c6a215a..0000000000 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java +++ /dev/null @@ -1,329 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.Map; -import java.util.Properties; - -import org.jclouds.Constants; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.domain.network.OrgNetwork; -import org.jclouds.vcloud.reference.VCloudConstants; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Tests behavior of {@code VCloudClient} - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true) -public abstract class CommonVCloudClientLiveTest { - - protected S connection; - protected RestContext context; - - protected abstract Iterable listOrgs(); - - @Test - public void testOrg() throws Exception { - for (Org org : orgs) { - assertNotNull(org); - assertNotNull(org.getName()); - assert org.getCatalogs().size() >= 1; - assert org.getTasksList() != null; - assert org.getVDCs().size() >= 1; - assertEquals(connection.findOrgNamed(org.getName()), org); - } - } - - @Test - public void testPropertiesCanOverrideDefaultOrg() throws Exception { - for (Org org : orgs) { - RestContext newContext = null; - try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName()))); - assertEquals(newContext.getApi().findOrgNamed(null), org); - } finally { - newContext.close(); - } - } - } - - public Properties overrideDefaults(Map overrides) { - Properties properties = setupProperties(); - properties.putAll(overrides); - return properties; - } - - @Test - public void testCatalog() throws Exception { - for (Org org : orgs) { - for (ReferenceType cat : org.getCatalogs().values()) { - Catalog response = connection.getCatalog(cat.getHref()); - assertNotNull(response); - assertNotNull(response.getName()); - assertNotNull(response.getHref()); - assertEquals(connection.findCatalogInOrgNamed(org.getName(), response.getName()), response); - } - } - } - - @Test - public void testPropertiesCanOverrideDefaultCatalog() throws Exception { - for (Org org : orgs) { - for (ReferenceType cat : org.getCatalogs().values()) { - RestContext newContext = null; - try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG, cat.getName()))); - assertEquals(newContext.getApi().findCatalogInOrgNamed(null, null), connection.getCatalog(cat.getHref())); - } finally { - newContext.close(); - } - } - } - } - - @Test - public void testGetOrgNetwork() throws Exception { - for (Org org : orgs) { - for (ReferenceType resource : org.getNetworks().values()) { - if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { - OrgNetwork item = connection.getNetwork(resource.getHref()); - assertNotNull(item); - } - } - } - } - - @Test - public void testGetVDCNetwork() throws Exception { - for (Org org : orgs) { - for (ReferenceType vdc : org.getVDCs().values()) { - VDC response = connection.getVDC(vdc.getHref()); - for (ReferenceType resource : response.getAvailableNetworks().values()) { - if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { - try { - OrgNetwork net = connection.getNetwork(resource.getHref()); - assertNotNull(net); - assertNotNull(net.getName()); - assertNotNull(net.getHref()); - assertEquals( - connection.findNetworkInOrgVDCNamed(org.getName(), response.getName(), net.getName()), net); - } catch (AuthorizationException e) { - - } - } - } - } - } - } - - @Test - public void testPropertiesCanOverrideDefaultNetwork() throws Exception { - for (Org org : orgs) { - for (ReferenceType vdc : org.getVDCs().values()) { - VDC response = connection.getVDC(vdc.getHref()); - for (ReferenceType net : response.getAvailableNetworks().values()) { - RestContext newContext = null; - try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, net.getName()))); - assertEquals(newContext.getApi().findNetworkInOrgVDCNamed(null, null, net.getName()), - connection.getNetwork(net.getHref())); - } finally { - newContext.close(); - } - } - } - } - } - - @Test - public void testGetCatalogItem() throws Exception { - for (Org org : orgs) { - for (ReferenceType cat : org.getCatalogs().values()) { - Catalog response = connection.getCatalog(cat.getHref()); - for (ReferenceType resource : response.values()) { - if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { - CatalogItem item = connection.getCatalogItem(resource.getHref()); - verifyCatalogItem(item); - } - } - } - } - } - - protected void verifyCatalogItem(CatalogItem item) { - assertNotNull(item); - assertNotNull(item); - assertNotNull(item.getEntity()); - assertNotNull(item.getHref()); - assertNotNull(item.getProperties()); - assertNotNull(item.getType()); - } - - @Test - public void testFindCatalogItem() throws Exception { - for (Org org : orgs) { - for (ReferenceType cat : org.getCatalogs().values()) { - Catalog response = connection.getCatalog(cat.getHref()); - for (ReferenceType resource : response.values()) { - if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { - CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(org.getName(), response.getName(), - resource.getName()); - verifyCatalogItem(item); - } - } - } - } - } - - @Test - public void testDefaultVDC() throws Exception { - for (Org org : orgs) { - for (ReferenceType vdc : org.getVDCs().values()) { - VDC response = connection.getVDC(vdc.getHref()); - assertNotNull(response); - assertNotNull(response.getName()); - assertNotNull(response.getHref()); - assertNotNull(response.getResourceEntities()); - assertNotNull(response.getAvailableNetworks()); - assertEquals(connection.getVDC(response.getHref()), response); - } - } - } - - @Test - public void testPropertiesCanOverrideDefaultVDC() throws Exception { - for (Org org : orgs) { - for (ReferenceType vdc : org.getVDCs().values()) { - RestContext newContext = null; - try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName()))); - assertEquals(newContext.getApi().findVDCInOrgNamed(null, null), connection.getVDC(vdc.getHref())); - } finally { - newContext.close(); - } - } - } - } - - @Test - public void testDefaultTasksList() throws Exception { - for (Org org : orgs) { - org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName()); - assertNotNull(response); - assertNotNull(response.getLocation()); - assertNotNull(response.getTasks()); - assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation()); - } - } - - @Test - public void testGetTask() throws Exception { - for (Org org : orgs) { - org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName()); - assertNotNull(response); - assertNotNull(response.getLocation()); - assertNotNull(response.getTasks()); - if (response.getTasks().size() > 0) { - Task task = response.getTasks().last(); - assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref()); - } - } - } - - protected String provider = "vcloud"; - protected String identity; - protected String credential; - protected String endpoint; - protected String apiversion; - protected Iterable orgs; - - protected void setupCredentials() { - identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".identity"); - endpoint = System.getProperty("test." + provider + ".endpoint"); - apiversion = System.getProperty("test." + provider + ".apiversion"); - } - - protected Properties setupProperties() { - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - if (endpoint != null) - overrides.setProperty(provider + ".endpoint", endpoint); - if (apiversion != null) - overrides.setProperty(provider + ".apiversion", apiversion); - return overrides; - } - - protected Properties setupRestProperties() { - return RestContextFactory.getPropertiesFromResource("/rest.properties"); - } - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - context = createContextWithProperties(setupProperties()); - connection = context.getApi(); - orgs = listOrgs(); - } - - public RestContext createContextWithProperties(Properties overrides) { - return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - } - - @AfterGroups(groups = { "live" }) - public void teardownClient() { - context.close(); - } - -} diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/DeprecatedVCloudClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/DeprecatedVCloudClientLiveTest.java index 244142dfed..da11de46a6 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/DeprecatedVCloudClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/DeprecatedVCloudClientLiveTest.java @@ -18,21 +18,38 @@ */ package org.jclouds.vcloud; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import java.util.Map; +import java.util.Properties; + +import org.jclouds.Constants; +import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextFactory; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.Vm; +import org.jclouds.vcloud.domain.network.OrgNetwork; +import org.jclouds.vcloud.reference.VCloudConstants; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.inject.Module; /** * Tests behavior of deprecated {@code VCloudClient} features @@ -41,9 +58,277 @@ import com.google.common.collect.Iterables; */ @Deprecated @Test(groups = "live", singleThreaded = true) -public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest { +public class DeprecatedVCloudClientLiveTest { + + protected VCloudClient connection; + protected RestContext context; + + @Test + public void testOrg() throws Exception { + for (Org org : orgs) { + assertNotNull(org); + assertNotNull(org.getName()); + assert org.getCatalogs().size() >= 1; + assert org.getTasksList() != null; + assert org.getVDCs().size() >= 1; + assertEquals(connection.findOrgNamed(org.getName()), org); + } + } + + @Test + public void testPropertiesCanOverrideDefaultOrg() throws Exception { + for (Org org : orgs) { + RestContext newContext = null; + try { + newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName()))); + assertEquals(newContext.getApi().findOrgNamed(null), org); + } finally { + newContext.close(); + } + } + } + + public Properties overrideDefaults(Map overrides) { + Properties properties = setupProperties(); + properties.putAll(overrides); + return properties; + } + + @Test + public void testCatalog() throws Exception { + for (Org org : orgs) { + for (ReferenceType cat : org.getCatalogs().values()) { + Catalog response = connection.getCatalog(cat.getHref()); + assertNotNull(response); + assertNotNull(response.getName()); + assertNotNull(response.getHref()); + assertEquals(connection.findCatalogInOrgNamed(org.getName(), response.getName()), response); + } + } + } + + @Test + public void testPropertiesCanOverrideDefaultCatalog() throws Exception { + for (Org org : orgs) { + for (ReferenceType cat : org.getCatalogs().values()) { + RestContext newContext = null; + try { + newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG, cat.getName()))); + assertEquals(newContext.getApi().findCatalogInOrgNamed(null, null), connection.getCatalog(cat.getHref())); + } finally { + newContext.close(); + } + } + } + } + + @Test + public void testGetOrgNetwork() throws Exception { + for (Org org : orgs) { + for (ReferenceType resource : org.getNetworks().values()) { + if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { + OrgNetwork item = connection.getNetwork(resource.getHref()); + assertNotNull(item); + } + } + } + } + + @Test + public void testGetVDCNetwork() throws Exception { + for (Org org : orgs) { + for (ReferenceType vdc : org.getVDCs().values()) { + VDC response = connection.getVDC(vdc.getHref()); + for (ReferenceType resource : response.getAvailableNetworks().values()) { + if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { + try { + OrgNetwork net = connection.getNetwork(resource.getHref()); + assertNotNull(net); + assertNotNull(net.getName()); + assertNotNull(net.getHref()); + assertEquals( + connection.findNetworkInOrgVDCNamed(org.getName(), response.getName(), net.getName()), net); + } catch (AuthorizationException e) { + + } + } + } + } + } + } + + @Test + public void testPropertiesCanOverrideDefaultNetwork() throws Exception { + for (Org org : orgs) { + for (ReferenceType vdc : org.getVDCs().values()) { + VDC response = connection.getVDC(vdc.getHref()); + for (ReferenceType net : response.getAvailableNetworks().values()) { + RestContext newContext = null; + try { + newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, net.getName()))); + assertEquals(newContext.getApi().findNetworkInOrgVDCNamed(null, null, net.getName()), + connection.getNetwork(net.getHref())); + } finally { + newContext.close(); + } + } + } + } + } + + @Test + public void testGetCatalogItem() throws Exception { + for (Org org : orgs) { + for (ReferenceType cat : org.getCatalogs().values()) { + Catalog response = connection.getCatalog(cat.getHref()); + for (ReferenceType resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + CatalogItem item = connection.getCatalogItem(resource.getHref()); + verifyCatalogItem(item); + } + } + } + } + } + + protected void verifyCatalogItem(CatalogItem item) { + assertNotNull(item); + assertNotNull(item); + assertNotNull(item.getEntity()); + assertNotNull(item.getHref()); + assertNotNull(item.getProperties()); + assertNotNull(item.getType()); + } + + @Test + public void testFindCatalogItem() throws Exception { + for (Org org : orgs) { + for (ReferenceType cat : org.getCatalogs().values()) { + Catalog response = connection.getCatalog(cat.getHref()); + for (ReferenceType resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(org.getName(), response.getName(), + resource.getName()); + verifyCatalogItem(item); + } + } + } + } + } + + @Test + public void testDefaultVDC() throws Exception { + for (Org org : orgs) { + for (ReferenceType vdc : org.getVDCs().values()) { + VDC response = connection.getVDC(vdc.getHref()); + assertNotNull(response); + assertNotNull(response.getName()); + assertNotNull(response.getHref()); + assertNotNull(response.getResourceEntities()); + assertNotNull(response.getAvailableNetworks()); + assertEquals(connection.getVDC(response.getHref()), response); + } + } + } + + @Test + public void testPropertiesCanOverrideDefaultVDC() throws Exception { + for (Org org : orgs) { + for (ReferenceType vdc : org.getVDCs().values()) { + RestContext newContext = null; + try { + newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName()))); + assertEquals(newContext.getApi().findVDCInOrgNamed(null, null), connection.getVDC(vdc.getHref())); + } finally { + newContext.close(); + } + } + } + } + + @Test + public void testDefaultTasksList() throws Exception { + for (Org org : orgs) { + org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName()); + assertNotNull(response); + assertNotNull(response.getLocation()); + assertNotNull(response.getTasks()); + assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation()); + } + } + + @Test + public void testGetTask() throws Exception { + for (Org org : orgs) { + org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName()); + assertNotNull(response); + assertNotNull(response.getLocation()); + assertNotNull(response.getTasks()); + if (response.getTasks().size() > 0) { + Task task = response.getTasks().last(); + assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref()); + } + } + } + + protected String provider = "vcloud"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + protected Iterable orgs; + + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider + + ".identity"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); + } + + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + overrides.setProperty(provider + ".identity", identity); + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); + return overrides; + } + + protected Properties setupRestProperties() { + return RestContextFactory.getPropertiesFromResource("/rest.properties"); + } + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + setupCredentials(); + context = createContextWithProperties(setupProperties()); + connection = context.getApi(); + orgs = listOrgs(); + } + + public RestContext createContextWithProperties(Properties overrides) { + return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, + ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); + } + + @AfterGroups(groups = { "live" }) + public void teardownClient() { + context.close(); + } - @Override protected Iterable listOrgs() { return Iterables.transform(connection.listOrgs().values(), new Function(){ diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index afbf7b3b7d..0e8ab2510e 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -39,6 +39,7 @@ import org.jclouds.util.Strings2; import org.jclouds.vcloud.domain.GuestCustomizationSection; import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.NetworkConfig; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.options.CaptureVAppOptions; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudSessionRefreshLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudSessionRefreshLiveTest.java index 5a2308e84d..34af3f964e 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudSessionRefreshLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudSessionRefreshLiveTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.vcloud; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java index d433e7f3af..a49d75a1fb 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java @@ -42,7 +42,7 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.SaxParserModule; import org.jclouds.vcloud.VCloudPropertiesBuilder; -import org.jclouds.vcloud.compute.config.CommonVCloudComputeServiceContextModule; +import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VApp; @@ -105,7 +105,7 @@ public class VAppToNodeMetadataTest { @Singleton @Provides protected Map provideVAppStatusToNodeState() { - return CommonVCloudComputeServiceContextModule.VAPPSTATUS_TO_NODESTATE; + return VCloudComputeServiceContextModule.VAPPSTATUS_TO_NODESTATE; } }); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogAsyncClientTest.java index 33de6247a7..8b60f93945 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogAsyncClientTest.java @@ -26,7 +26,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.options.CatalogItemOptions; import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogItemHandler; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java index b63af13266..9d8bffdbdd 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java @@ -21,10 +21,10 @@ package org.jclouds.vcloud.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkAsyncClientTest.java index 568091afd9..fee9802d53 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkAsyncClientTest.java @@ -26,7 +26,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.xml.OrgNetworkHandler; import org.testng.annotations.Test; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkClientLiveTest.java index 3781b4ddd0..c652c1bedc 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/NetworkClientLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.vcloud.features; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgAsyncClientTest.java index 3d1f55aeed..0b2483d014 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgAsyncClientTest.java @@ -27,7 +27,7 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.xml.OrgHandler; import org.jclouds.vcloud.xml.OrgListHandler; import org.testng.annotations.Test; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgClientLiveTest.java index 9bcc670542..2b12245f7d 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/OrgClientLiveTest.java @@ -21,8 +21,8 @@ package org.jclouds.vcloud.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskAsyncClientTest.java index 07fc94042c..e84a087166 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskAsyncClientTest.java @@ -27,7 +27,7 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TasksListHandler; import org.testng.annotations.Test; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskClientLiveTest.java index 2377ff9484..f01d725b53 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/TaskClientLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.vcloud.features; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppAsyncClientTest.java index 462c407756..5996190f95 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppAsyncClientTest.java @@ -29,7 +29,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Strings2; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.VAppHandler; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppClientLiveTest.java index f5aca341f3..d2032301c5 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppClientLiveTest.java @@ -20,12 +20,12 @@ package org.jclouds.vcloud.features; import static org.testng.Assert.assertNotNull; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateAsyncClientTest.java index 100c8d7040..ab346114ac 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateAsyncClientTest.java @@ -30,9 +30,9 @@ import org.jclouds.ovf.xml.EnvelopeHandler; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Strings2; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.NetworkConfig; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.options.CaptureVAppOptions; import org.jclouds.vcloud.options.CloneVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateClientLiveTest.java index 14f9fed1c9..1d3c09cfec 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VAppTemplateClientLiveTest.java @@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.AuthorizationException; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.CatalogItem; @@ -38,6 +37,7 @@ import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.jclouds.vcloud.options.CatalogItemOptions; import org.jclouds.vcloud.predicates.TaskSuccess; import org.testng.annotations.Test; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCAsyncClientTest.java index 525064695f..7fd5074378 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCAsyncClientTest.java @@ -27,7 +27,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.xml.VDCHandler; import org.testng.annotations.Test; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCClientLiveTest.java index 08ce12379f..5c69734059 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VDCClientLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.vcloud.features; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmAsyncClientTest.java index e84a1b4ca4..51d6c181f2 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmAsyncClientTest.java @@ -29,8 +29,8 @@ import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Strings2; -import org.jclouds.vcloud.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.domain.GuestCustomizationSection; +import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.VmHandler; import org.testng.annotations.Test; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java index 4c52b8b9b0..205c55b87b 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java @@ -29,7 +29,6 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; -import org.jclouds.vcloud.BaseVCloudClientLiveTest; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; @@ -38,6 +37,7 @@ import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.Vm; +import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; import com.google.common.collect.Iterables; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/functions b/apis/vcloud/src/test/java/org/jclouds/vcloud/functions deleted file mode 100644 index fdfeadc1ea..0000000000 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/functions +++ /dev/null @@ -1,152 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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 org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.io.Payloads; -import org.jclouds.vcloud.VCloudMediaType; -import org.jclouds.vcloud.domain.VCloudSession; -import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; - -/** - * Tests behavior of {@code ParseLoginResponseFromHeaders} - * - * @author Adrian Cole - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during -// surefire -@Test(groups = "unit", testName = "ParseLoginResponseFromHeadersTest") -public class ParseLoginResponseFromHeadersTest extends BaseHandlerTest { - - private ParseLoginResponseFromHeaders parser; - - @BeforeTest - void setUp() { - parser = injector.getInstance(ParseLoginResponseFromHeaders.class); - } - - @Test - public void testApply() { - HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", - "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/")); - response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); - response.getPayload().getContentMetadata().setContentLength(307l); - - VCloudSession reply = parser.apply(response); - assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2"); - assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); - - } - - @Test - public void testApplyBlueLock() { - HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", - "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=")); - response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); - response.getPayload().getContentMetadata().setContentLength(307l); - - VCloudSession reply = parser.apply(response); - assertEquals(reply.getVCloudToken(), "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0="); - assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); - - } - - @Test - public void testApplyTerremark() { - HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("Set-Cookie", - "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/")); - response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); - response.getPayload().getContentMetadata().setContentLength(307l); - - VCloudSession reply = parser.apply(response); - assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); - assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); - - } - - @Test - public void testApplyTerremarkMultipleCookies() { - HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. builder().put("Set-Cookie", - "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly") - .put("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").build()); - response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); - response.getPayload().getContentMetadata().setContentLength(307l); - - VCloudSession reply = parser.apply(response); - assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); - assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); - - } - - @Test(expectedExceptions = HttpResponseException.class) - public void testUnmatchedCookieThrowsHttpResponseException() { - HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. builder().put("Set-Cookie", - "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly") - .build()); - response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); - response.getPayload().getContentMetadata().setContentLength(307l); - - parser.apply(response); - } - - @Test(expectedExceptions = HttpResponseException.class) - public void testNoThrowsHttpResponseException() { - HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of()); - response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); - response.getPayload().getContentMetadata().setContentLength(307l); - - parser.apply(response); - } - - @Test - public void testApplyVirtacore() { - HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", - "vcloud-token=IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48=")); - response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); - response.getPayload().getContentMetadata().setContentLength(307l); - - VCloudSession reply = parser.apply(response); - assertEquals(reply.getVCloudToken(), "IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48="); - assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); - - } -} diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/BaseVCloudAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudAsyncClientTest.java similarity index 98% rename from apis/vcloud/src/test/java/org/jclouds/vcloud/BaseVCloudAsyncClientTest.java rename to apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudAsyncClientTest.java index 2ccc14f322..e9c4b72eb0 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/BaseVCloudAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudAsyncClientTest.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.vcloud; +package org.jclouds.vcloud.internal; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.testng.Assert.assertEquals; @@ -37,6 +37,8 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextSpec; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudVersionsAsyncClient; import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.domain.AllocationModel; import org.jclouds.vcloud.domain.Org; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/BaseVCloudClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudClientLiveTest.java similarity index 98% rename from apis/vcloud/src/test/java/org/jclouds/vcloud/BaseVCloudClientLiveTest.java rename to apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudClientLiveTest.java index 7250540b1a..e21cb2a86d 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/BaseVCloudClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudClientLiveTest.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.vcloud; +package org.jclouds.vcloud.internal; import static com.google.common.base.Preconditions.checkNotNull; @@ -35,6 +35,7 @@ import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.SshClient.Factory; import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.jclouds.vcloud.VCloudClient; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudLoginAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClientTest.java similarity index 99% rename from apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudLoginAsyncClientTest.java rename to apis/vcloud/src/test/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClientTest.java index 95ed71bce3..ecc5ea8f3f 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudLoginAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClientTest.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.vcloud; +package org.jclouds.vcloud.internal; import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.testng.Assert.assertEquals;