mirror of https://github.com/apache/jclouds.git
flattened vCloud classes now that vcloud 0.8 doesn't need to share hierarchy with 1.0
This commit is contained in:
parent
f42b550015
commit
560aa95e90
|
@ -1,212 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud;
|
||||
|
||||
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.
|
||||
* <p/>
|
||||
*
|
||||
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
public interface CommonVCloudAsyncClient {
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#getOrg
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(OrgHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(ORG_XML)
|
||||
ListenableFuture<? extends Org> getOrg(@EndpointParam URI orgId);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#getOrgNamed
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(OrgHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(ORG_XML)
|
||||
ListenableFuture<? extends Org> findOrgNamed(
|
||||
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#getCatalog
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(CatalogHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#findCatalogInOrgNamed
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(CatalogHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
ListenableFuture<? extends Catalog> 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<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#getCatalogItemInOrg
|
||||
*/
|
||||
@GET
|
||||
@Consumes(CATALOGITEM_XML)
|
||||
@XMLResponseParser(CatalogItemHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends CatalogItem> 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<? extends OrgNetwork> 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<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#getVDC(URI)
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
@Consumes(VDC_XML)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#findVDCInOrgNamed(String, String)
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
@Consumes(VDC_XML)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends VDC> 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<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#findTasksListInOrgNamed
|
||||
*/
|
||||
@GET
|
||||
@Consumes(TASKSLIST_XML)
|
||||
@XMLResponseParser(TasksListHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
|
||||
@Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#getTask
|
||||
*/
|
||||
@GET
|
||||
@Consumes(TASK_XML)
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
|
||||
|
||||
/**
|
||||
* @see CommonVCloudClient#cancelTask
|
||||
*/
|
||||
@POST
|
||||
@Path("/action/cancel")
|
||||
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
|
||||
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud;
|
||||
|
||||
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.
|
||||
* <p/>
|
||||
*
|
||||
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
|
||||
* @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);
|
||||
|
||||
}
|
|
@ -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<? extends Org> getOrg(@EndpointParam URI orgId);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getOrgNamed
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(OrgHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(ORG_XML)
|
||||
ListenableFuture<? extends Org> findOrgNamed(
|
||||
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getCatalog
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(CatalogHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#findCatalogInOrgNamed
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(CatalogHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
ListenableFuture<? extends Catalog> 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<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getCatalogItemInOrg
|
||||
*/
|
||||
@GET
|
||||
@Consumes(CATALOGITEM_XML)
|
||||
@XMLResponseParser(CatalogItemHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends CatalogItem> 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<? extends OrgNetwork> 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<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getVDC(URI)
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
@Consumes(VDC_XML)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#findVDCInOrgNamed(String, String)
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
@Consumes(VDC_XML)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends VDC> 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<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#findTasksListInOrgNamed
|
||||
*/
|
||||
@GET
|
||||
@Consumes(TASKSLIST_XML)
|
||||
@XMLResponseParser(TasksListHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
|
||||
@Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#getTask
|
||||
*/
|
||||
@GET
|
||||
@Consumes(TASK_XML)
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#cancelTask
|
||||
*/
|
||||
@POST
|
||||
@Path("/action/cancel")
|
||||
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to VApp Template features.
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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<String> getPrivateAddresses(URI vAppId);
|
||||
|
||||
/**
|
||||
* returns a set of addresses that are publically visible
|
||||
*/
|
||||
Set<String> getPublicAddresses(URI vAppId);
|
||||
|
||||
/**
|
||||
* reboots the vApp, blocking until the following state transition is complete:
|
||||
* <p/>
|
||||
* 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:
|
||||
* <p/>
|
||||
* current -> {@code VAppStatus#OFF} -> deleted
|
||||
*
|
||||
* @param vAppId
|
||||
* vApp to stop
|
||||
*/
|
||||
void stop(URI vAppId);
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
|
||||
return CreateNodesWithGroupEncodedIntoNameThenAddToSet.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||
return StaticHardwareSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||
return VCloudImageSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
return OrgAndVDCToLocationSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||
return DefaultVDC.class;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class DefaultVDC implements Supplier<Location> {
|
||||
@Singleton
|
||||
public static final class IsDefaultVDC implements Predicate<Location> {
|
||||
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<Set<? extends Location>> locationsSupplier;
|
||||
private final IsDefaultVDC isDefaultVDC;
|
||||
|
||||
@Inject
|
||||
DefaultVDC(@Memoized Supplier<Set<? extends Location>> locationsSupplier, IsDefaultVDC isDefaultVDC) {
|
||||
this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier");
|
||||
this.isDefaultVDC = checkNotNull(isDefaultVDC, "isDefaultVDC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location get() {
|
||||
return find(locationsSupplier.get(), isDefaultVDC);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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<Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap.<Status, NodeState> 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<Status, NodeState> provideVAppStatusToNodeState() {
|
||||
return VAPPSTATUS_TO_NODESTATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
install(defineComputeStrategyModule());
|
||||
install(defineComputeSupplierModule());
|
||||
}
|
||||
|
||||
public abstract BindComputeStrategiesByClass defineComputeStrategyModule();
|
||||
|
||||
public abstract BindComputeSuppliersByClass defineComputeSupplierModule();
|
||||
|
||||
}
|
|
@ -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<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
|
||||
return CreateNodesWithGroupEncodedIntoNameThenAddToSet.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
|
||||
return InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.class;
|
||||
|
|
|
@ -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<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||
return VCloudImageSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
return OrgAndVDCToLocationSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||
return DefaultVDC.class;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class DefaultVDC implements Supplier<Location> {
|
||||
@Singleton
|
||||
public static final class IsDefaultVDC implements Predicate<Location> {
|
||||
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<Set<? extends Location>> locationsSupplier;
|
||||
private final IsDefaultVDC isDefaultVDC;
|
||||
|
||||
@Inject
|
||||
DefaultVDC(@Memoized Supplier<Set<? extends Location>> 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<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||
|
|
|
@ -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<Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap.<Status, NodeState> 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<Status, NodeState> provideVAppStatusToNodeState() {
|
||||
return VAPPSTATUS_TO_NODESTATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
install(defineComputeStrategyModule());
|
||||
install(defineComputeSupplierModule());
|
||||
bind(new TypeLiteral<Function<VApp, NodeMetadata>>() {
|
||||
}).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();
|
||||
}
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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<T, A extends ReferenceType> implements CommonVCloudComputeClient {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final CommonVCloudClient client;
|
||||
protected final Predicate<URI> taskTester;
|
||||
|
||||
@Inject
|
||||
public CommonVCloudComputeClientImpl(CommonVCloudClient client, Predicate<URI> 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<String> getPrivateAddresses(URI id);
|
||||
|
||||
@Override
|
||||
public abstract Set<String> getPublicAddresses(URI id);
|
||||
|
||||
}
|
|
@ -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<Map<String, ? extends Org>> nameToOrg;
|
||||
protected final VCloudGetNodeMetadataStrategy getNodeMetadata;
|
||||
protected final CommonVCloudClient client;
|
||||
protected final FindLocationForResource findLocationForResourceInVDC;
|
||||
|
||||
Set<String> blackListVAppNames = ImmutableSet.<String> of();
|
||||
|
||||
@Inject(optional = true)
|
||||
|
@ -68,31 +71,28 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
|
|||
this.blackListVAppNames = ImmutableSet.copyOf(Splitter.on(',').split(blackListNodes));
|
||||
}
|
||||
|
||||
private final Supplier<Map<String, ReferenceType>> orgNameToEndpoint;
|
||||
|
||||
@Inject
|
||||
protected VCloudListNodesStrategy(CommonVCloudClient client,
|
||||
@Org Supplier<Map<String, ReferenceType>> orgNameToEndpoint, VCloudGetNodeMetadataStrategy getNodeMetadata,
|
||||
FindLocationForResource findLocationForResourceInVDC) {
|
||||
protected VCloudListNodesStrategy(VCloudClient client, Supplier<Map<String, ? extends Org>> nameToOrg,
|
||||
VCloudGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
|
||||
this.client = client;
|
||||
this.orgNameToEndpoint = orgNameToEndpoint;
|
||||
this.nameToOrg = nameToOrg;
|
||||
this.getNodeMetadata = getNodeMetadata;
|
||||
this.findLocationForResourceInVDC = findLocationForResourceInVDC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ComputeMetadata> listNodes() {
|
||||
Set<ComputeMetadata> 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<ComputeMetadata> nodes = ImmutableSet.<ComputeMetadata> 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<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
Set<NodeMetadata> 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<NodeMetadata> nodes = ImmutableSet.<NodeMetadata> 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<NodeMetadata> nodes, ReferenceType vdc, ReferenceType resource) {
|
||||
void addVAppToSetRetryingIfNotYetPresent(Builder<NodeMetadata> nodes, ReferenceType vdc, ReferenceType resource) {
|
||||
NodeMetadata node = null;
|
||||
int i = 0;
|
||||
while (node == null && i++ < 3) {
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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<S extends VCloudClient, A extends VCloudAsyncClient> extends
|
||||
CommonVCloudRestClientModule<S, A> {
|
||||
|
||||
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||
super(syncClientType, asyncClientType);
|
||||
}
|
||||
|
||||
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
|
||||
Map<Class<?>, Class<?>> delegateMap) {
|
||||
super(syncClientType, asyncClientType, delegateMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
|
||||
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
|
||||
});
|
||||
bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
|
||||
return factory.create(VCloudLoginAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, final VCloudLoginAsyncClient login) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
try {
|
||||
return login.login().get(10, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
propagate(e);
|
||||
assert false : e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,452 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
|
||||
RestClientModule<S, A> {
|
||||
|
||||
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||
super(syncClientType, asyncClientType);
|
||||
}
|
||||
|
||||
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
|
||||
Map<Class<?>, Class<?>> delegateMap) {
|
||||
super(syncClientType, asyncClientType, delegateMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
// Ensures we don't retry on authorization failures
|
||||
bind(new TypeLiteral<AtomicReference<AuthorizationException>>() {
|
||||
}).toInstance(new AtomicReference<AuthorizationException>());
|
||||
installDefaultVCloudEndpointsModule();
|
||||
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
|
||||
}).to(new TypeLiteral<FindLocationForResource>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Org, Iterable<? extends Catalog>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogsInOrg>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Org, Iterable<? extends VDC>>>() {
|
||||
}).to(new TypeLiteral<AllVDCsInOrg>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends Org>>>() {
|
||||
}).to(new TypeLiteral<OrgsForNames>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends Org>>>() {
|
||||
}).to(new TypeLiteral<OrgsForLocations>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Org, Iterable<? extends CatalogItem>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogItemsInOrg>() {
|
||||
});
|
||||
}
|
||||
|
||||
@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<Map<String, String>> provideVDCtoORG(Supplier<Map<String, ? extends Org>> orgNameToOrgSuppier) {
|
||||
return Suppliers.compose(new Function<Map<String, ? extends Org>, Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(Map<String, ? extends Org> arg0) {
|
||||
Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
|
||||
for (Entry<String, ? extends Org> orgr : arg0.entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
}
|
||||
return returnVal.build();
|
||||
}
|
||||
}, orgNameToOrgSuppier);
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@OrgList
|
||||
URI provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
VCloudSession session = sessionSupplier.get();
|
||||
return URI.create(getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org"));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
|
||||
protected final Supplier<VCloudSession> sessionSupplier;
|
||||
protected final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
|
||||
|
||||
@Inject
|
||||
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
|
||||
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
this.organizationsForNames = organizationsForNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Org> get() {
|
||||
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void installDefaultVCloudEndpointsModule() {
|
||||
install(new DefaultVCloudReferencesModule());
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
protected final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allCatalogsInOrg = allCatalogsInOrg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@VCloudToken
|
||||
@Provides
|
||||
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.Org
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
URItoVDC supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class URItoVDC implements Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> {
|
||||
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
|
||||
|
||||
@Inject
|
||||
URItoVDC(Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap) {
|
||||
this.orgVDCMap = orgVDCMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
|
||||
return uniqueIndex(
|
||||
concat(transform(
|
||||
orgVDCMap.get().values(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return from.values();
|
||||
}
|
||||
|
||||
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(org.jclouds.vcloud.domain.VDC from) {
|
||||
return from.getHref();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final static Function<ReferenceType, String> name = new Function<ReferenceType, String>() {
|
||||
|
||||
@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<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
|
||||
checkState(versions.size() > 0, "No versions present");
|
||||
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
|
||||
return versions.get(version);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
|
||||
private final Supplier<VCloudSession> sessionSupplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return sessionSupplier.get().getOrgs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
|
||||
return factory.create(VCloudVersionsAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
|
||||
return orgSupplier.get().get(defaultOrg.getName());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<URI> successTester(Injector injector,
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
return new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), completed);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgVDCSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgVDCSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allVDCsInOrg = allVDCsInOrg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allVDCsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogItemSupplier implements
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
|
||||
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
|
||||
protected final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogItemSupplier(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
|
||||
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
|
||||
this.catalogSupplier = catalogSupplier;
|
||||
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||
return transformValues(
|
||||
catalogSupplier.get(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends CatalogItem>> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return transformValues(
|
||||
from,
|
||||
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
|
||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogItemSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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<VCloudClient, VCloudAsyncClient> {
|
||||
public class VCloudRestClientModule extends RestClientModule<VCloudClient, VCloudAsyncClient> {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(VAppTemplateClient.class, VAppTemplateAsyncClient.class)//
|
||||
|
@ -67,4 +132,367 @@ public class VCloudRestClientModule extends BaseVCloudRestClientModule<VCloudCli
|
|||
super(VCloudClient.class, VCloudAsyncClient.class, DELEGATE_MAP);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
|
||||
return factory.create(VCloudLoginAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, final VCloudLoginAsyncClient login) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@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<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
|
||||
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
|
||||
});
|
||||
bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class);
|
||||
// Ensures we don't retry on authorization failures
|
||||
bind(new TypeLiteral<AtomicReference<AuthorizationException>>() {
|
||||
}).toInstance(new AtomicReference<AuthorizationException>());
|
||||
installDefaultVCloudEndpointsModule();
|
||||
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
|
||||
}).to(new TypeLiteral<FindLocationForResource>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Org, Iterable<? extends Catalog>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogsInOrg>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Org, Iterable<? extends VDC>>>() {
|
||||
}).to(new TypeLiteral<AllVDCsInOrg>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends Org>>>() {
|
||||
}).to(new TypeLiteral<OrgsForNames>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends Org>>>() {
|
||||
}).to(new TypeLiteral<OrgsForLocations>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Org, Iterable<? extends CatalogItem>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogItemsInOrg>() {
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, ? extends Org>> orgNameToOrgSuppier) {
|
||||
return Suppliers.compose(new Function<Map<String, ? extends Org>, Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(Map<String, ? extends Org> arg0) {
|
||||
Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
|
||||
for (Entry<String, ? extends Org> orgr : arg0.entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
}
|
||||
return returnVal.build();
|
||||
}
|
||||
}, orgNameToOrgSuppier);
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@OrgList
|
||||
URI provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
VCloudSession session = sessionSupplier.get();
|
||||
return URI.create(getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org"));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
|
||||
protected final Supplier<VCloudSession> sessionSupplier;
|
||||
protected final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
|
||||
|
||||
@Inject
|
||||
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
|
||||
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
this.organizationsForNames = organizationsForNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Org> get() {
|
||||
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void installDefaultVCloudEndpointsModule() {
|
||||
install(new DefaultVCloudReferencesModule());
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
protected final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allCatalogsInOrg = allCatalogsInOrg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@VCloudToken
|
||||
@Provides
|
||||
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.Org
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
URItoVDC supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class URItoVDC implements Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> {
|
||||
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
|
||||
|
||||
@Inject
|
||||
URItoVDC(Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap) {
|
||||
this.orgVDCMap = orgVDCMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
|
||||
return uniqueIndex(
|
||||
concat(transform(
|
||||
orgVDCMap.get().values(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return from.values();
|
||||
}
|
||||
|
||||
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(org.jclouds.vcloud.domain.VDC from) {
|
||||
return from.getHref();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final static Function<ReferenceType, String> name = new Function<ReferenceType, String>() {
|
||||
|
||||
@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<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
|
||||
checkState(versions.size() > 0, "No versions present");
|
||||
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
|
||||
return versions.get(version);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
|
||||
private final Supplier<VCloudSession> sessionSupplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return sessionSupplier.get().getOrgs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
|
||||
return factory.create(VCloudVersionsAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
|
||||
return orgSupplier.get().get(defaultOrg.getName());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<URI> successTester(Injector injector,
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
return new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), completed);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgVDCSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgVDCSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allVDCsInOrg = allVDCsInOrg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allVDCsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogItemSupplier implements
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
|
||||
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
|
||||
protected final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogItemSupplier(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
|
||||
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
|
||||
this.catalogSupplier = catalogSupplier;
|
||||
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||
return transformValues(
|
||||
catalogSupplier.get(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends CatalogItem>> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return transformValues(
|
||||
from,
|
||||
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
|
||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogItemSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Catalog, Iterable<? ex
|
|||
@Resource
|
||||
public Logger logger = Logger.NULL;
|
||||
|
||||
private final CommonVCloudAsyncClient aclient;
|
||||
private final VCloudAsyncClient aclient;
|
||||
private final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
AllCatalogItemsInCatalog(CommonVCloudAsyncClient aclient,
|
||||
AllCatalogItemsInCatalog(VCloudAsyncClient aclient,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.aclient = aclient;
|
||||
this.executor = executor;
|
||||
|
|
|
@ -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.Catalog;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
|
@ -45,11 +45,11 @@ public class AllCatalogsInOrg implements Function<Org, Iterable<? extends Catalo
|
|||
@Resource
|
||||
public Logger logger = Logger.NULL;
|
||||
|
||||
private final CommonVCloudAsyncClient aclient;
|
||||
private final VCloudAsyncClient aclient;
|
||||
private final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
AllCatalogsInOrg(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
AllCatalogsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.aclient = aclient;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
|
|
@ -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 org.jclouds.vcloud.domain.ReferenceType;
|
||||
|
||||
|
@ -44,11 +44,11 @@ public class AllVDCsInOrg implements Function<Org, Iterable<? extends org.jcloud
|
|||
@Resource
|
||||
public Logger logger = Logger.NULL;
|
||||
|
||||
private final CommonVCloudAsyncClient aclient;
|
||||
private final VCloudAsyncClient aclient;
|
||||
private final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
AllVDCsInOrg(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
AllVDCsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.aclient = aclient;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.jclouds.Constants;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
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;
|
||||
|
@ -49,11 +49,11 @@ import com.google.common.collect.Sets;
|
|||
public class OrgsForLocations implements Function<Iterable<? extends Location>, Iterable<? extends Org>> {
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -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<String>, Iterable<? extends Org>> {
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
@ -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<URI> {
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,329 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud;
|
||||
|
||||
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<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> {
|
||||
|
||||
protected S connection;
|
||||
protected RestContext<S, A> context;
|
||||
|
||||
protected abstract Iterable<Org> 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<S, A> 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<String, String> 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<S, A> 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<S, A> 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<S, A> 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<Org> 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<S, A> createContextWithProperties(Properties overrides) {
|
||||
return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
}
|
||||
|
||||
@AfterGroups(groups = { "live" })
|
||||
public void teardownClient() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<VCloudClient, VCloudAsyncClient> {
|
||||
public class DeprecatedVCloudClientLiveTest {
|
||||
|
||||
protected VCloudClient connection;
|
||||
protected RestContext<VCloudClient,VCloudAsyncClient> 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<VCloudClient, VCloudAsyncClient> 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<String, String> 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<VCloudClient, VCloudAsyncClient> 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<VCloudClient, VCloudAsyncClient> 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<VCloudClient, VCloudAsyncClient> 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<Org> 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<VCloudClient, VCloudAsyncClient> createContextWithProperties(Properties overrides) {
|
||||
return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
}
|
||||
|
||||
@AfterGroups(groups = { "live" })
|
||||
public void teardownClient() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<Org> listOrgs() {
|
||||
return Iterables.transform(connection.listOrgs().values(), new Function<ReferenceType, Org>(){
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.vcloud;
|
||||
|
||||
import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<Status, NodeState> provideVAppStatusToNodeState() {
|
||||
return CommonVCloudComputeServiceContextModule.VAPPSTATUS_TO_NODESTATE;
|
||||
return VCloudComputeServiceContextModule.VAPPSTATUS_TO_NODESTATE;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,152 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.functions;
|
||||
|
||||
import static 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.<String, String> 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.<String, String> 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.<String, String> 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.<String, String> 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.<String, String> 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.<String, String> 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.<String, String> 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"))));
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
Loading…
Reference in New Issue