Issue 280: converged vcloud express and vcloud org and vdc objects

This commit is contained in:
Adrian Cole 2010-08-21 21:06:52 -07:00
parent 2db03edb18
commit c0f454e7eb
105 changed files with 2576 additions and 5057 deletions

View File

@ -29,7 +29,7 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
@ -40,7 +40,7 @@ import com.google.common.base.Predicate;
* @author Adrian Cole
*/
@Singleton
public class BlueLockVCloudDirectorComputeClient extends BaseVCloudComputeClient {
public class BlueLockVCloudDirectorComputeClient extends VCloudComputeClientImpl {
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@Inject

View File

@ -29,7 +29,7 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
@ -40,7 +40,7 @@ import com.google.common.base.Predicate;
* @author Adrian Cole
*/
@Singleton
public class BlueLockVCloudExpressComputeClient extends BaseVCloudExpressComputeClient {
public class BlueLockVCloudExpressComputeClient extends VCloudExpressComputeClientImpl {
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@Inject

View File

@ -29,10 +29,10 @@ import javax.inject.Named;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@ -47,7 +47,7 @@ import com.google.common.collect.Iterables;
public class BlueLockVCloudExpressRestClientModule extends VCloudExpressRestClientModule {
@Override
protected URI provideDefaultNetwork(VCloudExpressClient client) {
protected URI provideDefaultNetwork(CommonVCloudClient client) {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
@ -62,7 +62,7 @@ public class BlueLockVCloudExpressRestClientModule extends VCloudExpressRestClie
}
@Override
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) final String user) {
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) final String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return Iterables.getOnlyElement(Iterables.filter(org.getCatalogs().values(), new Predicate<NamedResource>() {

View File

@ -0,0 +1,332 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
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.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Org;
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.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.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.NetworkHandler;
import org.jclouds.vcloud.xml.OrgHandler;
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 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 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#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNameds
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @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(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> 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#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @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);
/**
* @see VCloudClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
}

View File

@ -0,0 +1,184 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
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.Network;
import org.jclouds.vcloud.domain.Org;
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;
/**
* 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);
VAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* returns the vapp template corresponding to a 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
*/
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
Network findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
Network 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);
Task deployVApp(URI vAppId);
void deleteVApp(URI vAppId);
Task undeployVApp(URI vAppId);
/**
* This call powers on the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOnVApp(URI vAppId);
/**
* This call powers off the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOffVApp(URI vAppId);
/**
* This call shuts down the vApp.
*/
void shutdownVApp(URI vAppId);
/**
* This call resets the vApp.
*/
Task resetVApp(URI vAppId);
/**
* This call suspends the vApp.
*/
Task suspendVApp(URI vAppId);
Task getTask(URI taskId);
void cancelTask(URI taskId);
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
VApp getVApp(URI vApp);
}

View File

@ -19,66 +19,32 @@
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.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Org;
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.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.OrgNameVDCNameResourceEntityNameToEndpoint;
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.NetworkHandler;
import org.jclouds.vcloud.xml.OrgHandler;
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 com.google.common.util.concurrent.ListenableFuture;
@ -86,258 +52,11 @@ 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"
* />
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
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#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNameds
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @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(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> 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#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @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);
/**
* @see VCloudClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
/**
* @see VCloudClient#instantiateVAppTemplateInVDC

View File

@ -20,21 +20,11 @@
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.Network;
import org.jclouds.vcloud.domain.Org;
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.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -48,140 +38,8 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudClient {
public interface VCloudClient extends 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);
VAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* returns the vapp template corresponding to a 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
*/
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
Network findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
Network 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);
Task deployVApp(URI vAppId);
void deleteVApp(URI vAppId);
Task undeployVApp(URI vAppId);
/**
* This call powers on the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOnVApp(URI vAppId);
/**
* This call powers off the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOffVApp(URI vAppId);
/**
* This call shuts down the vApp.
*/
void shutdownVApp(URI vAppId);
/**
* This call resets the vApp.
*/
Task resetVApp(URI vAppId);
/**
* This call suspends the vApp.
*/
Task suspendVApp(URI vAppId);
Task getTask(URI taskId);
void cancelTask(URI taskId);
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
VApp getVApp(URI vApp);
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);

View File

@ -19,68 +19,32 @@
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Organization;
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.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrganizationNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrganizationNameAndTasksListNameToEndpoint;
import org.jclouds.vcloud.functions.OrganizationNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
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.NetworkHandler;
import org.jclouds.vcloud.xml.OrganizationHandler;
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 com.google.common.util.concurrent.ListenableFuture;
@ -88,298 +52,11 @@ 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"
* />
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudExpressAsyncClient {
/**
* @see VCloudExpressClient#getDefaultOrganization
*/
@Deprecated
@GET
@Endpoint(Org.class)
@Consumes(ORG_XML)
@XMLResponseParser(OrganizationHandler.class)
ListenableFuture<? extends Organization> getDefaultOrganization();
/**
* @see VCloudExpressClient#getOrganization
*/
@GET
@XMLResponseParser(OrganizationHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> getOrganization(@EndpointParam URI orgId);
/**
* @see VCloudExpressClient#getOrganizationNamed
*/
@GET
@XMLResponseParser(OrganizationHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> findOrganizationNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
* @see VCloudExpressClient#getDefaultCatalog
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML)
@XMLResponseParser(CatalogHandler.class)
ListenableFuture<? extends Catalog> getDefaultCatalog();
/**
* @see VCloudExpressClient#getCatalog
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see VCloudExpressClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrganizationNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrganizationNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see VCloudExpressClient#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudExpressClient#findVAppTemplateInOrgCatalogNameds
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VCloudExpressClient#getCatalogItem
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see VCloudExpressClient#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 VCloudExpressClient#findNetworkInOrgVDCNamed
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudExpressClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> getNetwork(@EndpointParam URI network);
/**
* @see VCloudExpressClient#getDefaultVDC
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
ListenableFuture<? extends VDC> getDefaultVDC();
/**
* @see VCloudExpressClient#getVDC(URI)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see VCloudExpressClient#findVDCInOrgNamed(String, String)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrganizationNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrganizationNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see VCloudExpressClient#getTasksList
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
/**
* @see VCloudExpressClient#getTasksListInOrg
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrganizationNameAndTasksListNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrganizationNameAndTasksListNameToEndpoint.class) String tasksListName);
/**
* @see VCloudExpressClient#getDefaultTasksList
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.TasksList.class)
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
ListenableFuture<? extends TasksList> getDefaultTasksList();
/**
* @see VCloudExpressClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#getTask
*/
@GET
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
/**
* @see VCloudExpressClient#cancelTask
*/
@POST
@Path("/action/cancel")
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
/**
* @see VCloudExpressClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudExpressClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
/**
* @see VCloudExpressClient#instantiateVAppTemplateInVDC

View File

@ -20,21 +20,11 @@
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.Network;
import org.jclouds.vcloud.domain.Organization;
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.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -42,169 +32,11 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
* 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"
* />
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudExpressClient {
/**
* Please use {@link #findOrganizationNamed(String)} passing null
*/
@Deprecated
Organization getDefaultOrganization();
Organization getOrganization(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
*/
Organization findOrganizationNamed(@Nullable String name);
/**
* Please use #findCatalogInOrgNamed(null, null)
*/
@Deprecated
Catalog getDefaultCatalog();
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);
VAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* returns the vapp template corresponding to a 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
*/
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
Network findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
Network 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);
/**
* Please use #findVDCInOrgNamed
*/
@Deprecated
VDC getDefaultVDC();
TasksList getTasksList(URI tasksListId);
TasksList findTasksListInOrgNamed(String orgName, String tasksListName);
/**
* Please use #getTasksListInOrg(null, null)
*/
@Deprecated
TasksList getDefaultTasksList();
Task deployVApp(URI vAppId);
void deleteVApp(URI vAppId);
Task undeployVApp(URI vAppId);
/**
* This call powers on the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOnVApp(URI vAppId);
/**
* This call powers off the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOffVApp(URI vAppId);
/**
* This call shuts down the vApp.
*/
void shutdownVApp(URI vAppId);
/**
* This call resets the vApp.
*/
Task resetVApp(URI vAppId);
/**
* This call suspends the vApp.
*/
Task suspendVApp(URI vAppId);
Task getTask(URI taskId);
void cancelTask(URI taskId);
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
VApp getVApp(URI vApp);
public interface VCloudExpressClient extends CommonVCloudClient {
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);

View File

@ -1,216 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public class BaseVCloudExpressComputeClient implements VCloudExpressComputeClient {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final VCloudExpressClient client;
protected final Predicate<URI> taskTester;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
public BaseVCloudExpressComputeClient(VCloudExpressClient client, Predicate<URI> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
this.client = client;
this.taskTester = successTester;
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = client.instantiateVAppTemplateInVDC(vdc.getId(), template.getId(), name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getId());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("deploy", vAppResponse, task);
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOn", vAppResponse, task);
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
}
protected Map<String, String> parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) {
Map<String, String> response = parseResponse(template, vAppResponse);
checkState(response.containsKey("id"), "bad configuration: [id] should be in response");
checkState(response.containsKey("username"), "bad configuration: [username] should be in response");
checkState(response.containsKey("password"), "bad configuration: [password] should be in response");
return response;
}
protected Map<String, String> parseResponse(VAppTemplate template, VApp vAppResponse) {
Map<String, String> config = Maps.newLinkedHashMap();// Allows nulls
config.put("id", vAppResponse.getId().toASCIIString());
config.put("username", null);
config.put("password", null);
return config;
}
@Override
public void reboot(URI id) {
VApp vApp = client.getVApp(id);
logger.debug(">> resetting vApp(%s)", vApp.getName());
Task task = client.resetVApp(vApp.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("resetVApp", vApp, task);
}
logger.debug("<< on vApp(%s)", vApp.getName());
}
@Override
public void stop(URI id) {
VApp vApp = client.getVApp(id);
vApp = powerOffVAppIfDeployed(vApp);
vApp = undeployVAppIfDeployed(vApp);
deleteVApp(vApp);
logger.debug("<< deleted vApp(%s)", vApp.getName());
}
private void deleteVApp(VApp vApp) {
logger.debug(">> deleting vApp(%s)", vApp.getName());
client.deleteVApp(vApp.getId());
}
private VApp undeployVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(VAppStatus.RESOLVED) > 0) {
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
Task task = client.undeployVApp(vApp.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("undeploy", vApp, task);
}
vApp = client.getVApp(vApp.getId());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
return vApp;
}
private VApp powerOffVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(VAppStatus.OFF) > 0) {
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
Task task = client.powerOffVApp(vApp.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOff", vApp, task);
}
vApp = client.getVApp(vApp.getId());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
return vApp;
}
public static class TaskException extends VAppException {
private final Task task;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public TaskException(String type, VApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type, vApp.getName(),
vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task;
}
public Task getTask() {
return task;
}
}
public static class VAppException extends RuntimeException {
private final VApp vApp;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, VApp vApp) {
super(message);
this.vApp = vApp;
}
public VApp getvApp() {
return vApp;
}
}
@Override
public Set<String> getPrivateAddresses(URI id) {
return ImmutableSet.of();
}
@Override
public Set<String> getPublicAddresses(URI id) {
VApp vApp = client.getVApp(id);
return Sets.newHashSet(vApp.getNetworkToAddresses().values());
}
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.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 reboot(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);
}

View File

@ -21,10 +21,10 @@ package org.jclouds.vcloud.compute;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.ImplementedBy;
@ -33,11 +33,11 @@ import com.google.inject.ImplementedBy;
*
* @author Adrian Cole
*/
@ImplementedBy(BaseVCloudComputeClient.class)
public interface VCloudComputeClient {
@ImplementedBy(VCloudComputeClientImpl.class)
public interface VCloudComputeClient extends CommonVCloudComputeClient {
/**
* Runs through all commands necessary to startup a vApp, opening at least
* one ip address to the public network. These are the steps:
* Runs through all commands necessary to startup a vApp, opening at least one ip address to the
* public network. These are the steps:
* <p/>
* instantiate -> deploy -> powerOn
* <p/>
@ -59,43 +59,11 @@ public interface VCloudComputeClient {
* opens the following ports on the public ip address
* @return map contains at least the following properties
* <ol>
* <li>id - vApp id</li> <li>username - console login user</li> <li>
* password - console login password</li>
* <li>id - vApp id</li> <li>username - console login user</li> <li> password - console
* login password</li>
* </ol>
*/
Map<String, String> start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
int... portsToOpen);
/**
* 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 reboot(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);
}

View File

@ -21,10 +21,10 @@ package org.jclouds.vcloud.compute;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.ImplementedBy;
@ -33,11 +33,11 @@ import com.google.inject.ImplementedBy;
*
* @author Adrian Cole
*/
@ImplementedBy(BaseVCloudExpressComputeClient.class)
public interface VCloudExpressComputeClient {
@ImplementedBy(VCloudExpressComputeClientImpl.class)
public interface VCloudExpressComputeClient extends CommonVCloudComputeClient {
/**
* Runs through all commands necessary to startup a vApp, opening at least
* one ip address to the public network. These are the steps:
* Runs through all commands necessary to startup a vApp, opening at least one ip address to the
* public network. These are the steps:
* <p/>
* instantiate -> deploy -> powerOn
* <p/>
@ -59,43 +59,11 @@ public interface VCloudExpressComputeClient {
* opens the following ports on the public ip address
* @return map contains at least the following properties
* <ol>
* <li>id - vApp id</li> <li>username - console login user</li> <li>
* password - console login password</li>
* <li>id - vApp id</li> <li>username - console login user</li> <li> password - console
* login password</li>
* </ol>
*/
Map<String, String> start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
int... portsToOpen);
/**
* 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 reboot(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);
}

View File

@ -27,10 +27,24 @@ import javax.inject.Singleton;
import org.jclouds.compute.LoadBalancerService;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Size;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
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.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.domain.Location;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
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.VCloudRebootNodeStrategy;
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.StaticSizeSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier;
import org.jclouds.vcloud.domain.VAppStatus;
import com.google.common.annotations.VisibleForTesting;
@ -41,7 +55,7 @@ import com.google.inject.Provides;
import com.google.inject.util.Providers;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*
* @author Adrian Cole
@ -63,6 +77,11 @@ public abstract class CommonVCloudComputeServiceContextModule extends BaseComput
@Override
protected void configure() {
install(new ComputeServiceTimeoutsModule());
bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
bindLoadBalancer();
}
@ -75,4 +94,14 @@ public abstract class CommonVCloudComputeServiceContextModule extends BaseComput
return injector.getInstance(StaticSizeSupplier.class);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(OrgAndVDCToLocationSupplier.class);
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(VCloudImageSupplier.class);
}
}

View File

@ -19,38 +19,25 @@
package org.jclouds.vcloud.compute.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
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.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.domain.Location;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy;
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.VCloudRebootNodeStrategy;
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*
* @author Adrian Cole
@ -67,21 +54,11 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic
}).to(new TypeLiteral<RestContextImpl<VCloudClient, VCloudClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class);
bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(OrgAndVDCToLocationSupplier.class);
@Provides
@Singleton
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudComputeClient in) {
return in;
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(VCloudImageSupplier.class);
}
}

View File

@ -19,39 +19,26 @@
package org.jclouds.vcloud.compute.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
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.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.domain.Location;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.compute.strategy.VCloudExpressAddNodeWithTagStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressRebootNodeStrategy;
import org.jclouds.vcloud.compute.suppliers.OrganizationAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudExpressImageSupplier;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link BaseVCloudExpressComputeClient} bound.
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/
@ -67,21 +54,11 @@ public class VCloudExpressComputeServiceContextModule extends CommonVCloudComput
}).to(new TypeLiteral<RestContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(VCloudExpressAddNodeWithTagStrategy.class);
bind(DestroyNodeStrategy.class).to(VCloudExpressDestroyNodeStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudExpressListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudExpressGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudExpressRebootNodeStrategy.class);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(OrganizationAndVDCToLocationSupplier.class);
@Provides
@Singleton
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudExpressComputeClient in) {
return in;
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(VCloudExpressImageSupplier.class);
}
}

View File

@ -31,7 +31,7 @@ import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
@ -40,7 +40,7 @@ import com.google.common.base.Function;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link BaseVCloudExpressComputeClient} bound.
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/

View File

@ -1,61 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.functions.AllCatalogItemsInOrganization;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class ImagesInOrganization implements Function<Organization, Iterable<? extends Image>> {
private final AllCatalogItemsInOrganization allCatalogItemsInOrganization;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<ImageForVAppTemplate> imageForVAppTemplateProvider;
@Inject
ImagesInOrganization(AllCatalogItemsInOrganization allCatalogItemsInOrganization,
Provider<ImageForVAppTemplate> imageForVAppTemplateProvider,
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) {
this.imageForVAppTemplateProvider = imageForVAppTemplateProvider;
this.allCatalogItemsInOrganization = allCatalogItemsInOrganization;
this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems;
}
@Override
public Iterable<? extends Image> apply(Organization from) {
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrganization.apply(from);
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.get().withParent(from));
}
}

View File

@ -17,30 +17,26 @@
* ====================================================================
*/
package org.jclouds.vcloud.compute;
package org.jclouds.vcloud.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
@ -52,52 +48,18 @@ import com.google.inject.Inject;
* @author Adrian Cole
*/
@Singleton
public class BaseVCloudComputeClient implements VCloudComputeClient {
public class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final VCloudClient client;
protected final CommonVCloudClient client;
protected final Predicate<URI> taskTester;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
public BaseVCloudComputeClient(VCloudClient client, Predicate<URI> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
public CommonVCloudComputeClientImpl(CommonVCloudClient client, Predicate<URI> successTester) {
this.client = client;
this.taskTester = successTester;
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = client.instantiateVAppTemplateInVDC(vdc.getId(), template.getId(), name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getId());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("deploy", vAppResponse, task);
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOn", vAppResponse, task);
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
}
protected Map<String, String> parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) {

View File

@ -0,0 +1,89 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudComputeClientImpl extends CommonVCloudComputeClientImpl implements VCloudComputeClient {
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
public VCloudComputeClientImpl(VCloudClient client, Predicate<URI> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
super(client, successTester);
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = VCloudClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getId(), template.getId(),
name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getId());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("deploy", vAppResponse, task);
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOn", vAppResponse, task);
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
}
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressComputeClientImpl extends CommonVCloudComputeClientImpl implements VCloudExpressComputeClient {
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
public VCloudExpressComputeClientImpl(VCloudExpressClient client, Predicate<URI> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
super(client, successTester);
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = VCloudExpressClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getId(),
template.getId(), name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getId());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("deploy", vAppResponse, task);
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOn", vAppResponse, task);
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
}
}

View File

@ -29,18 +29,18 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudDestroyNodeStrategy implements DestroyNodeStrategy {
protected final VCloudComputeClient computeClient;
protected final CommonVCloudComputeClient computeClient;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudDestroyNodeStrategy(VCloudComputeClient computeClient, GetNodeMetadataStrategy getNode) {
protected VCloudDestroyNodeStrategy(CommonVCloudComputeClient computeClient, GetNodeMetadataStrategy getNode) {
this.computeClient = computeClient;
this.getNode = getNode;

View File

@ -1,55 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressDestroyNodeStrategy implements DestroyNodeStrategy {
protected final VCloudExpressComputeClient computeClient;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudExpressDestroyNodeStrategy(VCloudExpressComputeClient computeClient, GetNodeMetadataStrategy getNode) {
this.computeClient = computeClient;
this.getNode = getNode;
}
@Override
public NodeMetadata execute(String id) {
computeClient.stop(URI.create(checkNotNull(id, "node.id")));
return getNode.execute(id);
}
}

View File

@ -1,95 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.os.CIMOperatingSystem;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.GetExtra;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudExpressClient client;
protected final VCloudExpressComputeClient computeClient;
protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC;
protected final GetExtra getExtra;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
protected VCloudExpressGetNodeMetadataStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.computeClient = checkNotNull(computeClient, "computeClient");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
}
public NodeMetadata execute(String in) {
URI id = URI.create(in);
VApp from = client.getVApp(id);
if (from == null)
return null;
String tag = parseTagFromName(from.getName());
Location location = findLocationForResourceInVDC.apply(from.getVDC());
return new NodeMetadataImpl(in, from.getName(), in, location, from.getId(), ImmutableMap.<String, String> of(),
tag, null, from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(from
.getOsType()), null, null, from.getOperatingSystemDescription()) : null, vAppStatusToNodeState
.get(from.getStatus()), computeClient.getPublicAddresses(id), computeClient
.getPrivateAddresses(id), getExtra.apply(from), null);
}
}

View File

@ -1,141 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.strategy;
import static org.jclouds.compute.reference.ComputeServiceConstants.COMPUTE_LOGGER;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_BLACKLIST_NODES;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.internal.ComputeMetadataImpl;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.domain.NamedResource;
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.ImmutableMap;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.internal.util.ImmutableSet;
/**
* @author Adrian Cole
*/
// TODO REFACTOR!!! needs to be parallel
@Singleton
public class VCloudExpressListNodesStrategy implements ListNodesStrategy {
@Resource
@Named(COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudExpressGetNodeMetadataStrategy getNodeMetadata;
protected final VCloudExpressClient client;
protected final FindLocationForResource findLocationForResourceInVDC;
Set<String> blackListVAppNames = ImmutableSet.<String> of();
@Inject(optional = true)
void setBlackList(@Named(PROPERTY_BLACKLIST_NODES) String blackListNodes) {
if (blackListNodes != null && !"".equals(blackListNodes))
this.blackListVAppNames = ImmutableSet.copyOf(Splitter.on(',').split(blackListNodes));
}
private final Supplier<Map<String, NamedResource>> orgNameToEndpoint;
@Inject
protected VCloudExpressListNodesStrategy(VCloudExpressClient client,
@Org Supplier<Map<String, NamedResource>> orgNameToEndpoint,
VCloudExpressGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
this.client = client;
this.orgNameToEndpoint = orgNameToEndpoint;
this.getNodeMetadata = getNodeMetadata;
this.findLocationForResourceInVDC = findLocationForResourceInVDC;
}
@Override
public Iterable<ComputeMetadata> list() {
Set<ComputeMetadata> nodes = Sets.newHashSet();
for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
if (validVApp(resource)) {
nodes.add(convertVAppToComputeMetadata(vdc, resource));
}
}
}
}
return nodes;
}
private boolean validVApp(NamedResource resource) {
return resource.getType().equals(VCloudExpressMediaType.VAPP_XML)
&& !blackListVAppNames.contains(resource.getName());
}
private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) {
Location location = findLocationForResourceInVDC.apply(vdc);
return new ComputeMetadataImpl(ComputeType.NODE, resource.getId().toASCIIString(), resource.getName(), resource
.getId().toASCIIString(), location, null, ImmutableMap.<String, String> of());
}
@Override
public Iterable<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
Set<NodeMetadata> nodes = Sets.newHashSet();
for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
}
}
}
}
return nodes;
}
@VisibleForTesting
void addVAppToSetRetryingIfNotYetPresent(Set<NodeMetadata> nodes, NamedResource vdc, NamedResource resource) {
NodeMetadata node = null;
int i = 0;
while (node == null && i++ < 3) {
try {
node = getNodeMetadata.execute(resource.getId().toASCIIString());
nodes.add(node);
} catch (NullPointerException e) {
logger.warn("vApp %s not yet present in vdc %s", resource.getName(), vdc.getName());
}
}
}
}

View File

@ -1,60 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.Task;
import com.google.common.base.Predicate;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressRebootNodeStrategy implements RebootNodeStrategy {
private final VCloudExpressClient client;
protected final Predicate<URI> taskTester;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudExpressRebootNodeStrategy(VCloudExpressClient client, Predicate<URI> taskTester, GetNodeMetadataStrategy getNode) {
this.client = client;
this.taskTester = taskTester;
this.getNode = getNode;
}
@Override
public NodeMetadata execute(String in) {
URI id = URI.create(checkNotNull(in, "node.id"));
Task task = client.resetVApp(id);
taskTester.apply(task.getLocation());
return getNode.execute(in);
}
}

View File

@ -40,8 +40,8 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.GetExtra;
import org.jclouds.vcloud.domain.VApp;
@ -58,15 +58,15 @@ public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudClient client;
protected final VCloudComputeClient computeClient;
protected final CommonVCloudClient client;
protected final CommonVCloudComputeClient computeClient;
protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC;
protected final GetExtra getExtra;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
VCloudGetNodeMetadataStrategy(VCloudClient client, VCloudComputeClient computeClient,
protected VCloudGetNodeMetadataStrategy(CommonVCloudClient client, CommonVCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");

View File

@ -36,7 +36,7 @@ import org.jclouds.compute.domain.internal.ComputeMetadataImpl;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.domain.NamedResource;
@ -61,7 +61,7 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
@Named(COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudGetNodeMetadataStrategy getNodeMetadata;
protected final VCloudClient client;
protected final CommonVCloudClient client;
protected final FindLocationForResource findLocationForResourceInVDC;
Set<String> blackListVAppNames = ImmutableSet.<String> of();
@ -74,8 +74,9 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
private final Supplier<Map<String, NamedResource>> orgNameToEndpoint;
@Inject
protected VCloudListNodesStrategy(VCloudClient client, @Org Supplier<Map<String, NamedResource>> orgNameToEndpoint,
VCloudGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
protected VCloudListNodesStrategy(CommonVCloudClient client,
@Org Supplier<Map<String, NamedResource>> orgNameToEndpoint, VCloudGetNodeMetadataStrategy getNodeMetadata,
FindLocationForResource findLocationForResourceInVDC) {
this.client = client;
this.orgNameToEndpoint = orgNameToEndpoint;
this.getNodeMetadata = getNodeMetadata;

View File

@ -29,7 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.domain.Task;
import com.google.common.base.Predicate;
@ -39,12 +39,13 @@ import com.google.common.base.Predicate;
*/
@Singleton
public class VCloudRebootNodeStrategy implements RebootNodeStrategy {
private final VCloudClient client;
private final CommonVCloudClient client;
protected final Predicate<URI> taskTester;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudRebootNodeStrategy(VCloudClient client, Predicate<URI> taskTester, GetNodeMetadataStrategy getNode) {
protected VCloudRebootNodeStrategy(CommonVCloudClient client, Predicate<URI> taskTester,
GetNodeMetadataStrategy getNode) {
this.client = client;
this.taskTester = taskTester;
this.getNode = getNode;

View File

@ -1,70 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.suppliers;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
@Singleton
public class OrganizationAndVDCToLocationSupplier implements Supplier<Set<? extends Location>> {
private final String providerName;
private final Supplier<Map<String, NamedResource>> orgNameToResource;
private final Supplier<Map<String, ? extends Organization>> orgNameToVDCResource;
@Inject
OrganizationAndVDCToLocationSupplier(@org.jclouds.rest.annotations.Provider String providerName,
@Org Supplier<Map<String, NamedResource>> orgNameToResource,
Supplier<Map<String, ? extends Organization>> orgNameToVDCResource) {
this.providerName = providerName;
this.orgNameToResource = orgNameToResource;
this.orgNameToVDCResource = orgNameToVDCResource;
}
@Override
public Set<? extends Location> get() {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Set<Location> locations = Sets.newLinkedHashSet();
for (NamedResource org : orgNameToResource.get().values()) {
Location orgL = new VCloudLocation(org, provider);
for (NamedResource vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) {
locations.add(new VCloudLocation(vdc, orgL));
}
}
return locations;
}
}

View File

@ -1,92 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Sets.newLinkedHashSet;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.functions.ImagesInOrganization;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressImageSupplier implements Supplier<Set<? extends Image>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final ImagesInOrganization imagesInOrganization;
private final ExecutorService executor;
@Inject
VCloudExpressImageSupplier(Supplier<Map<String, ? extends Organization>> orgMap, ImagesInOrganization imagesInOrganization,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.orgMap = checkNotNull(orgMap, "orgMap");
this.imagesInOrganization = checkNotNull(imagesInOrganization, "imagesInOrganization");
this.executor = checkNotNull(executor, "executor");
}
@Override
public Set<? extends Image> get() {
Iterable<? extends Organization> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<Iterable<? extends Image>> images = transformParallel(orgs,
new Function<Organization, Future<Iterable<? extends Image>>>() {
@Override
public Future<Iterable<? extends Image>> apply(final Organization from) {
checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Image>>() {
@Override
public Iterable<? extends Image> call() throws Exception {
return imagesInOrganization.apply(from);
}
});
}
}, executor, null, logger, "images in " + orgs);
return newLinkedHashSet(concat(images));
}
}

View File

@ -39,7 +39,6 @@ import org.jclouds.Constants;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.functions.ImagesInOrg;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function;
@ -56,11 +55,12 @@ public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
public Logger logger = Logger.NULL;
private final Supplier<Map<String, ? extends Org>> orgMap;
private final ImagesInOrg imagesInOrg;
private final Function<Org, Iterable<? extends Image>> imagesInOrg;
private final ExecutorService executor;
@Inject
VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap, ImagesInOrg imagesInOrg,
VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap,
Function<Org, Iterable<? extends Image>> imagesInOrg,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.orgMap = checkNotNull(orgMap, "orgMap");
this.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");

View File

@ -19,56 +19,24 @@
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
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.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.http.RequiresHttp;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.functions.VCloudExpressAllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.VCloudExpressAllCatalogsInOrganization;
import org.jclouds.vcloud.functions.VCloudExpressAllVDCsInOrganization;
import org.jclouds.vcloud.functions.VCloudExpressOrganizationsForNames;
import org.jclouds.vcloud.functions.VCloudExpressOrganizatonsForLocations;
import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForCatalogItems;
import org.jclouds.vcloud.predicates.VCloudExpressTaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import domain.VCloudExpressLoginAsyncClient;
@ -86,273 +54,6 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
super(syncClientType, asyncClientType);
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<VCloudExpressAllCatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Organization, Iterable<? extends Catalog>>>() {
}).to(new TypeLiteral<VCloudExpressAllCatalogsInOrganization>() {
});
bind(new TypeLiteral<Function<Organization, Iterable<? extends VDC>>>() {
}).to(new TypeLiteral<VCloudExpressAllVDCsInOrganization>() {
});
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends Organization>>>() {
}).to(new TypeLiteral<VCloudExpressOrganizationsForNames>() {
});
bind(new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends Organization>>>() {
}).to(new TypeLiteral<VCloudExpressOrganizatonsForLocations>() {
});
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VCloudExpressVAppTemplatesForCatalogItems>() {
});
}
@Provides
@Singleton
protected Organization provideOrganization(VCloudExpressClient discovery) {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrganizationNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Override
protected URI provideDefaultNetwork(VCloudExpressClient client) {
if (authException.get() != null)
throw authException.get();
try {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return get(networks.values(), 0).getId();
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Override
protected Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<URI>(injector.getInstance(VCloudExpressTaskSuccess.class), completed);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Map<String, ? extends Organization>> orgToVDCSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Organization> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal;
}
});
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected URI provideDefaultVDC(Organization org) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
return get(org.getVDCs().values(), 0).getId();
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return get(org.getCatalogs().values(), 0).getId();
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Organization>> provideOrgMapCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationMapSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Organization>>(
authException, seconds, new Supplier<Map<String, ? extends Organization>>() {
@Override
public Map<String, ? extends Organization> get() {
return supplier.get();
}
});
}
@Singleton
public static class OrganizationMapSupplier implements Supplier<Map<String, ? extends Organization>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final Function<Iterable<String>, Iterable<? extends Organization>> organizationsForNames;
@Inject
protected OrganizationMapSupplier(Supplier<VCloudSession> sessionSupplier,
Function<Iterable<String>, Iterable<? extends Organization>> organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@Override
public Map<String, ? extends Organization> get() {
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
}
}
@Singleton
public static class OrganizationCatalogSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
protected final Supplier<Map<String, ? extends Organization>> orgSupplier;
private final Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrganization;
@Inject
protected OrganizationCatalogSupplier(Supplier<Map<String, ? extends Organization>> orgSupplier,
Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrganization) {
this.orgSupplier = orgSupplier;
this.allCatalogsInOrganization = allCatalogsInOrganization;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return transformValues(
transformValues(orgSupplier.get(), allCatalogsInOrganization),
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);
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrganizationCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrganizationVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get();
}
});
}
@Singleton
public static class OrganizationVDCSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
protected final Supplier<Map<String, ? extends Organization>> orgSupplier;
private final Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrganization;
@Inject
protected OrganizationVDCSupplier(Supplier<Map<String, ? extends Organization>> orgSupplier,
Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrganization) {
this.orgSupplier = orgSupplier;
this.allVDCsInOrganization = allVDCsInOrganization;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return transformValues(
transformValues(orgSupplier.get(), allVDCsInOrganization),
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 OrganizationCatalogItemSupplier 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;
private final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrganizationCatalogItemSupplier(
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>>>> provideOrganizationCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogItemSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected VCloudExpressLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
@ -380,11 +81,4 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
});
}
@Provides
@TasksList
@Singleton
protected URI provideDefaultTasksList(Organization org) {
checkState(org.getTasksLists().size() > 0, "No tasks lists present in org: " + org.getName());
return get(org.getTasksLists().values(), 0).getId();
}
}

View File

@ -19,56 +19,24 @@
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
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.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.http.RequiresHttp;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
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.predicates.TaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import domain.VCloudLoginAsyncClient;
@ -86,280 +54,6 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
super(syncClientType, asyncClientType);
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
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<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
});
}
@Override
protected URI provideDefaultNetwork(VCloudClient client) {
if (authException.get() != null)
throw authException.get();
try {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return get(networks.values(), 0).getId();
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Provides
@Singleton
protected Org provideOrg(VCloudClient discovery) {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrgNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Override
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
@org.jclouds.vcloud.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal;
}
});
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected URI provideDefaultVDC(Org org) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
return get(org.getVDCs().values(), 0).getId();
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return get(org.getCatalogs().values(), 0).getId();
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgMapSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(authException,
seconds, new Supplier<Map<String, ? extends Org>>() {
@Override
public Map<String, ? extends Org> get() {
return supplier.get();
}
});
}
@Singleton
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
protected final Supplier<VCloudSession> sessionSupplier;
private 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);
}
}
@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;
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
@Inject
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
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);
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get();
}
});
}
@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;
private final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrgCatalogItemSupplier(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
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, final OrgCatalogItemSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
}
@Provides
@TasksList
@Singleton
protected URI provideDefaultTasksList(Org org) {
return org.getTasksList().getId();
}
@Provides
@Singleton
protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {

View File

@ -22,8 +22,11 @@ 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.get;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.newLinkedHashMap;
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_IDENTITY;
@ -34,6 +37,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEO
import java.net.URI;
import java.util.Map;
import java.util.SortedMap;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -44,30 +48,48 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
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.logging.Logger;
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.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.compute.functions.ImagesInOrg;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
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.predicates.TaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import domain.VCloudVersionsAsyncClient;
@ -78,7 +100,8 @@ import domain.VCloudVersionsAsyncClient;
*/
@RequiresHttp
@ConfiguresRestClient
public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModule<S, A> {
public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
RestClientModule<S, A> {
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
@ -88,16 +111,142 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
protected void configure() {
requestInjection(this);
super.configure();
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<Org, Iterable<? extends Image>>>() {
}).to(new TypeLiteral<ImagesInOrg>() {
});
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
});
}
@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(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal;
}
});
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected URI provideDefaultVDC(Org org) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
return get(org.getVDCs().values(), 0).getId();
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return get(org.getCatalogs().values(), 0).getId();
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgMapSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(authException,
seconds, new Supplier<Map<String, ? extends Org>>() {
@Override
public Map<String, ? extends Org> get() {
return supplier.get();
}
});
}
@Singleton
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
protected final Supplier<VCloudSession> sessionSupplier;
private 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);
}
}
@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;
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
@Inject
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
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);
}
});
}
}
@Resource
protected Logger logger = Logger.NULL;
@Provides
@Singleton
protected abstract Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed);
@VCloudToken
@Provides
String provideVCloudToken(Supplier<VCloudSession> cache) {
@ -105,21 +254,21 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return getLast(orgs).getId();
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected String provideOrgName(@Org Iterable<NamedResource> orgs) {
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return getLast(orgs).getName();
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Supplier<Map<String, NamedResource>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgNameToOrgSupplier supplier) {
@ -180,7 +329,7 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Iterable<NamedResource> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
VCloudSession discovery = cache.get();
@ -235,18 +384,13 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
}
@Provides
@Catalog
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected String provideCatalogName(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
return getLast(getLast(catalogs.get().values()).keySet());
}
@Provides
@Network
@Singleton
protected abstract URI provideDefaultNetwork(S client);
@Provides
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK)
@Singleton
@ -254,6 +398,162 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
return network.toASCIIString();
}
@Provides
@Network
@Singleton
protected URI provideDefaultNetwork(CommonVCloudClient client) {
if (authException.get() != null)
throw authException.get();
try {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return get(networks.values(), 0).getId();
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Provides
@Singleton
protected Org provideOrg(CommonVCloudClient discovery) {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrgNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@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, final OrgCatalogSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get();
}
});
}
@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;
private final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrgCatalogItemSupplier(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
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, final OrgCatalogItemSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
}
@Provides
@TasksList
@Singleton
protected URI provideDefaultTasksList(Org org) {
return org.getTasksList().getId();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class);

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* The AllocationModel element defines how resources are allocated in a vDC.
*/
public enum AllocationModel {
/**
* Resources are committed to a vDC only when vApps are created in it
*/
ALLOCATION_VAPP,
/**
* Only a percentage of the resources you allocate are committed to the organization vDC.
*/
ALLOCATION_POOL,
/**
* All the resources you allocate are committed as a pool to the organization vDC. vApps in vDCs
* that support this allocation model can specify values for resource and limit.
*/
RESERVATION_POOL,
/**
* The VCloud API returned a model unsupported in the version 1.0 spec.
*/
UNRECOGNIZED_MODEL;
public String value() {
switch (this) {
case ALLOCATION_VAPP:
return "AllocationVApp";
case ALLOCATION_POOL:
return "AllocationPool";
case RESERVATION_POOL:
return "ReservationPool";
default:
return "UnrecognizedModel";
}
}
@Override
public String toString() {
return value();
}
public static AllocationModel fromValue(String model) {
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(model, "model")));
}
}

View File

@ -19,39 +19,60 @@
package org.jclouds.vcloud.domain;
/**
* reports storage resource consumption in a vDC.
*
* @author Adrian Cole
*/
public class Capacity {
private final String units;
private final int allocated;
private final long allocated;
private final long limit;
private final int used;
private final long overhead;
public Capacity(String units, int allocated, int used) {
public Capacity(String units, long allocated, long limit, int used, long overhead) {
this.units = units;
this.limit = limit;
this.allocated = allocated;
this.used = used;
this.overhead = overhead;
}
public String getUnits() {
return units;
}
public int getAllocated() {
public long getAllocated() {
return allocated;
}
public long getLimit() {
return limit;
}
/**
* percentage of the allocation in use.
*/
public int getUsed() {
return used;
}
/**
* number of Units allocated to vShield Manager virtual machines provisioned from this vDC.
*/
public long getOverhead() {
return overhead;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + allocated;
result = prime * result + (int) (allocated ^ (allocated >>> 32));
result = prime * result + (int) (limit ^ (limit >>> 32));
result = prime * result + (int) (overhead ^ (overhead >>> 32));
result = prime * result + ((units == null) ? 0 : units.hashCode());
result = prime * result + used;
return result;
@ -68,6 +89,10 @@ public class Capacity {
Capacity other = (Capacity) obj;
if (allocated != other.allocated)
return false;
if (limit != other.limit)
return false;
if (overhead != other.overhead)
return false;
if (units == null) {
if (other.units != null)
return false;
@ -77,4 +102,10 @@ public class Capacity {
return false;
return true;
}
@Override
public String toString() {
return "[allocated=" + allocated + ", limit=" + limit + ", overhead=" + overhead + ", units=" + units + ", used="
+ used + "]";
}
}

View File

@ -21,36 +21,53 @@ package org.jclouds.vcloud.domain;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import com.google.inject.ImplementedBy;
/**
* A vCloud organization is a high-level abstraction that provides a unit of
* administration for objects and resources. As viewed by a user, an
* organization (represented by an Org element) can contain Catalog, Network,
* and vDC elements. If there are any queued, running, or recently completed
* tasks owned by a member of the organization, it also contains a TasksList
* element. As viewed by an administrator, an organization also contains users,
* groups, and other information
* A vCloud organization is a high-level abstraction that provides a unit of administration for
* objects and resources. As viewed by a user, an organization (represented by an Org element) can
* contain Catalog, Network, and vDC elements. If there are any queued, running, or recently
* completed tasks owned by a member of the organization, it also contains a TasksList element. As
* viewed by an administrator, an organization also contains users, groups, and other information
*
* @author Adrian Cole
*/
@ImplementedBy(OrgImpl.class)
public interface Org extends NamedResource {
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* @since vcloud api 0.8
*/
Map<String, NamedResource> getCatalogs();
/**
* @since vcloud api 0.8
*/
Map<String, NamedResource> getVDCs();
/**
* If there are any queued, running, or recently completed tasks owned by a
* member of the organization, it also contains a TasksList.
* If there are any queued, running, or recently completed tasks owned by a member of the
* organization, it also contains a TasksList.
*
* @since vcloud api 0.8
*/
@Nullable
NamedResource getTasksList();
/**
* @since vcloud api 1.0
*/
Map<String, NamedResource> getNetworks();
}

View File

@ -1,67 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* @author Adrian Cole
*/
public class Quota {
private final int limit;
private final int used;
public Quota(int limit, int used) {
this.limit = limit;
this.used = used;
}
public int getLimit() {
return limit;
}
public int getUsed() {
return used;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + limit;
result = prime * result + used;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Quota other = (Quota) obj;
if (limit != other.limit)
return false;
if (used != other.used)
return false;
return true;
}
}

View File

@ -19,33 +19,132 @@
package org.jclouds.vcloud.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import com.google.inject.ImplementedBy;
/**
* A vDC is a deployment environment for vApps. A Vdc element provides a user view of a vDC.
*
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.VDC
@ImplementedBy(VDCImpl.class)
public interface VDC extends NamedResource {
/**
* Reference to the org containing this vDC.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the org isn't present
*/
NamedResource getOrg();
/**
* The creation status of the vDC
*
* @since vcloud api 1.0
*/
VDCStatus getStatus();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
/**
* defines how resources are allocated by the vDC. The value of this element is set by the
* administrator who created the vDC. It is readonly to users.
*
* @since vcloud api 1.0
*/
AllocationModel getAllocationModel();
/**
* defines the storage capacity available in the vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support storage capacity
*/
@Nullable
Capacity getStorageCapacity();
/**
* reports CPU resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support cpu capacity
*/
@Nullable
Capacity getCpuCapacity();
/**
* reports memory resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support memory capacity
*/
@Nullable
Capacity getMemoryCapacity();
Quota getInstantiatedVmsQuota();
Quota getDeployedVmsQuota();
Map<String, NamedResource> getAvailableNetworks();
/**
* container for ResourceEntity elements
*
* @since vcloud api 0.8
*/
Map<String, NamedResource> getResourceEntities();
/**
* container for OrgNetwork elements that represent organization networks contained by the vDC
*
* @since vcloud api 0.8
*/
Map<String, NamedResource> getAvailableNetworks();
/**
* maximum number of virtual NICs allowed in this vDC. Defaults to 0, which specifies an
* unlimited number.
*
* @since vcloud api 1.0
*/
int getNicQuota();
/**
* maximum number of OrgNetwork objects that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 1.0
*/
int getNetworkQuota();
/**
* maximum number of virtual machines that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 0.8
*/
int getVmQuota();
/**
* true if this vDC is enabled
*
* @since vcloud api 1.0
*/
boolean isEnabled();
}

View File

@ -19,22 +19,42 @@
package org.jclouds.vcloud.domain;
import java.util.Map;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
* The creation status of the vDC
*
* @see VDC#getStatus
*/
@ImplementedBy(OrganizationImpl.class)
public interface Organization extends NamedResource {
public enum VDCStatus {
Map<String, NamedResource> getCatalogs();
CREATION_FAILED, NOT_READY, READY, UNKNOWN, UNRECOGNIZED_STATUS;
Map<String, NamedResource> getVDCs();
Map<String, NamedResource> getTasksLists();
public int value() {
switch (this) {
case CREATION_FAILED:
return -1;
case NOT_READY:
return 0;
case READY:
return 1;
case UNKNOWN:
return 2;
default:
return 3;
}
}
public static VDCStatus fromValue(int status) {
switch (status) {
case -1:
return CREATION_FAILED;
case 0:
return NOT_READY;
case 1:
return READY;
case 2:
return UNKNOWN;
default:
return UNRECOGNIZED_STATUS;
}
}
}

View File

@ -24,7 +24,6 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Org;
@ -34,19 +33,17 @@ import org.jclouds.vcloud.domain.Org;
* @author Adrian Cole
*
*/
public class OrgImpl implements Org {
private final String name;
private final URI id;
public class OrgImpl extends NamedResourceImpl implements Org {
private final String description;
private final Map<String, NamedResource> catalogs;
private final Map<String, NamedResource> vdcs;
private final Map<String, NamedResource> networks;
private final NamedResource tasksList;
public OrgImpl(String name, URI id, String description, Map<String, NamedResource> catalogs,
public OrgImpl(String name, String type, URI id, String description, Map<String, NamedResource> catalogs,
Map<String, NamedResource> vdcs, Map<String, NamedResource> networks, @Nullable NamedResource tasksList) {
this.name = name;
this.id = id;
super(name, type, id);
this.description = description;
this.catalogs = catalogs;
this.vdcs = vdcs;
@ -54,16 +51,6 @@ public class OrgImpl implements Org {
this.tasksList = tasksList;
}
@Override
public String getName() {
return name;
}
@Override
public URI getId() {
return id;
}
@Override
public Map<String, NamedResource> getCatalogs() {
return catalogs;
@ -82,11 +69,9 @@ public class OrgImpl implements Org {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int result = super.hashCode();
result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((networks == null) ? 0 : networks.hashCode());
result = prime * result + ((tasksList == null) ? 0 : tasksList.hashCode());
result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode());
@ -97,7 +82,7 @@ public class OrgImpl implements Org {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
@ -112,16 +97,6 @@ public class OrgImpl implements Org {
return false;
} else if (!description.equals(other.description))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (networks == null) {
if (other.networks != null)
return false;
@ -140,11 +115,6 @@ public class OrgImpl implements Org {
return true;
}
@Override
public String getType() {
return VCloudMediaType.ORG_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
@ -152,7 +122,7 @@ public class OrgImpl implements Org {
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", type=" + getType() + "]";
return "[id=" + getId() + ", name=" + getName() + ", type=" + getType() + "]";
}
@Override

View File

@ -1,139 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
import java.net.URI;
import java.util.Map;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class OrganizationImpl implements Organization {
private final String name;
private final URI id;
private final Map<String, NamedResource> catalogs;
private final Map<String, NamedResource> vdcs;
private final Map<String, NamedResource> tasksLists;
public OrganizationImpl(String name, URI id, Map<String, NamedResource> catalogs, Map<String, NamedResource> vdcs,
Map<String, NamedResource> tasksLists) {
this.name = name;
this.id = id;
this.catalogs = catalogs;
this.vdcs = vdcs;
this.tasksLists = tasksLists;
}
@Override
public String getName() {
return name;
}
@Override
public URI getId() {
return id;
}
@Override
public Map<String, NamedResource> getCatalogs() {
return catalogs;
}
@Override
public Map<String, NamedResource> getVDCs() {
return vdcs;
}
@Override
public Map<String, NamedResource> getTasksLists() {
return tasksLists;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode());
result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OrganizationImpl other = (OrganizationImpl) obj;
if (catalogs == null) {
if (other.catalogs != null)
return false;
} else if (!catalogs.equals(other.catalogs))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (tasksLists == null) {
if (other.tasksLists != null)
return false;
} else if (!tasksLists.equals(other.tasksLists))
return false;
if (vdcs == null) {
if (other.vdcs != null)
return false;
} else if (!vdcs.equals(other.vdcs))
return false;
return true;
}
@Override
public String getType() {
return VCloudExpressMediaType.ORG_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", type=" + getType() + "]";
}
}

View File

@ -22,13 +22,21 @@ package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.jclouds.vcloud.VCloudExpressMediaType;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Locations of resources in vCloud
@ -36,71 +44,176 @@ import org.jclouds.vcloud.domain.VDC;
* @author Adrian Cole
*
*/
public class VDCImpl implements VDC {
public class VDCImpl extends NamedResourceImpl implements VDC {
private final String name;
private final URI id;
private final VDCStatus status;
private final NamedResource org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final AllocationModel allocationModel;
private final Capacity storageCapacity;
private final Capacity cpuCapacity;
private final Capacity memoryCapacity;
private final Quota instantiatedVmsQuota;
private final Quota deployedVmsQuota;
private final Map<String, NamedResource> availableNetworks;
private final Map<String, NamedResource> resourceEntities;
private final Map<String, NamedResource> resourceEntities = Maps.newLinkedHashMap();
private final Map<String, NamedResource> availableNetworks = Maps.newLinkedHashMap();
private final int nicQuota;
private final int networkQuota;
private final int vmQuota;
private final boolean isEnabled;
public VDCImpl(String name, URI id, String description, Capacity storageCapacity, Capacity cpuCapacity,
Capacity memoryCapacity, Quota instantiatedVmsQuota, Quota deployedVmsQuota,
Map<String, NamedResource> resourceEntities, Map<String, NamedResource> availableNetworks) {
this.name = checkNotNull(name, "name");
this.id = checkNotNull(id, "id");
public VDCImpl(String name, String type, URI id, VDCStatus status, NamedResource org, @Nullable String description,
Iterable<Task> tasks, AllocationModel allocationModel, @Nullable Capacity storageCapacity,
@Nullable Capacity cpuCapacity, @Nullable Capacity memoryCapacity,
Map<String, NamedResource> resourceEntities, Map<String, NamedResource> availableNetworks, int nicQuota,
int networkQuota, int vmQuota, boolean isEnabled) {
super(name, type, id);
this.status = checkNotNull(status, "status");
this.org = org;// TODO: once <1.0 is killed check not null
this.description = description;
this.storageCapacity = storageCapacity;
this.cpuCapacity = cpuCapacity;
this.memoryCapacity = memoryCapacity;
this.instantiatedVmsQuota = instantiatedVmsQuota;
this.deployedVmsQuota = deployedVmsQuota;
this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks");
this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities");
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.allocationModel = checkNotNull(allocationModel, "allocationModel");
this.storageCapacity = storageCapacity;// TODO: once <1.0 is killed check not null
this.cpuCapacity = cpuCapacity;// TODO: once <1.0 is killed check not null
this.memoryCapacity = memoryCapacity;// TODO: once <1.0 is killed check not null
this.resourceEntities.putAll(checkNotNull(resourceEntities, "resourceEntities"));
this.availableNetworks.putAll(checkNotNull(availableNetworks, "availableNetworks"));
this.nicQuota = nicQuota;
this.networkQuota = networkQuota;
this.vmQuota = vmQuota;
this.isEnabled = isEnabled;
}
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
public VDCStatus getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public URI getId() {
return id;
public NamedResource getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, NamedResource> getAvailableNetworks() {
return availableNetworks;
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public AllocationModel getAllocationModel() {
return allocationModel;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getStorageCapacity() {
return storageCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getCpuCapacity() {
return cpuCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getMemoryCapacity() {
return memoryCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, NamedResource> getResourceEntities() {
return resourceEntities;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, NamedResource> getAvailableNetworks() {
return availableNetworks;
}
/**
* {@inheritDoc}
*/
@Override
public int getNicQuota() {
return nicQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getNetworkQuota() {
return networkQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getVmQuota() {
return vmQuota;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEnabled() {
return isEnabled;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int result = super.hashCode();
result = prime * result + ((allocationModel == null) ? 0 : allocationModel.hashCode());
result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode());
result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode());
result = prime * result + ((deployedVmsQuota == null) ? 0 : deployedVmsQuota.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((instantiatedVmsQuota == null) ? 0 : instantiatedVmsQuota.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + (isEnabled ? 1231 : 1237);
result = prime * result + ((memoryCapacity == null) ? 0 : memoryCapacity.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + networkQuota;
result = prime * result + nicQuota;
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((storageCapacity == null) ? 0 : storageCapacity.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + vmQuota;
return result;
}
@ -108,11 +221,16 @@ public class VDCImpl implements VDC {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VDCImpl other = (VDCImpl) obj;
if (allocationModel == null) {
if (other.allocationModel != null)
return false;
} else if (!allocationModel.equals(other.allocationModel))
return false;
if (availableNetworks == null) {
if (other.availableNetworks != null)
return false;
@ -123,91 +241,56 @@ public class VDCImpl implements VDC {
return false;
} else if (!cpuCapacity.equals(other.cpuCapacity))
return false;
if (deployedVmsQuota == null) {
if (other.deployedVmsQuota != null)
return false;
} else if (!deployedVmsQuota.equals(other.deployedVmsQuota))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (instantiatedVmsQuota == null) {
if (other.instantiatedVmsQuota != null)
return false;
} else if (!instantiatedVmsQuota.equals(other.instantiatedVmsQuota))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
if (isEnabled != other.isEnabled)
return false;
if (memoryCapacity == null) {
if (other.memoryCapacity != null)
return false;
} else if (!memoryCapacity.equals(other.memoryCapacity))
return false;
if (name == null) {
if (other.name != null)
if (networkQuota != other.networkQuota)
return false;
} else if (!name.equals(other.name))
if (nicQuota != other.nicQuota)
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (resourceEntities == null) {
if (other.resourceEntities != null)
return false;
} else if (!resourceEntities.equals(other.resourceEntities))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (storageCapacity == null) {
if (other.storageCapacity != null)
return false;
} else if (!storageCapacity.equals(other.storageCapacity))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (vmQuota != other.vmQuota)
return false;
return true;
}
@Override
public String getDescription() {
return description;
}
@Override
public Capacity getStorageCapacity() {
return storageCapacity;
}
@Override
public Capacity getCpuCapacity() {
return cpuCapacity;
}
@Override
public Capacity getMemoryCapacity() {
return memoryCapacity;
}
@Override
public Quota getInstantiatedVmsQuota() {
return instantiatedVmsQuota;
}
@Override
public Quota getDeployedVmsQuota() {
return deployedVmsQuota;
}
@Override
public String getType() {
return VCloudExpressMediaType.VDC_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", description=" + description + "]";
return "[id=" + getId() + ", name=" + getName() + ", org=" + org + ", description=" + description + ", status="
+ status + ", isEnabled=" + isEnabled + "]";
}
}

View File

@ -33,7 +33,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
@ -51,11 +51,11 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<? ex
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final CommonVCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
AllCatalogItemsInCatalog(VCloudAsyncClient aclient,
AllCatalogItemsInCatalog(CommonVCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;

View File

@ -1,68 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class AllCatalogItemsInOrganization implements Function<Organization, Iterable<? extends CatalogItem>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final Function<Organization, Iterable<? extends Catalog>> allCatalogsInOrganization;
private final Function<Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
AllCatalogItemsInOrganization(Function<Organization, Iterable<? extends Catalog>> allCatalogsInOrganization,
Function<Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
this.allCatalogsInOrganization = allCatalogsInOrganization;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@Override
public Iterable<? extends CatalogItem> apply(Organization from) {
return Iterables.concat(Iterables.transform(allCatalogsInOrganization.apply(from),
new Function<Catalog, Iterable<? extends CatalogItem>>() {
@Override
public Iterable<? extends CatalogItem> apply(Catalog from) {
return allCatalogItemsInCatalog.apply(from);
}
}));
}
}

View File

@ -32,7 +32,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Org;
@ -48,11 +48,11 @@ public class AllCatalogsInOrg implements Function<Org, Iterable<? extends Catalo
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final CommonVCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
AllCatalogsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
AllCatalogsInOrg(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}

View File

@ -1,74 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class AllCatalogsInOrganization implements Function<Organization, Iterable<? extends Catalog>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
AllCatalogsInOrganization(VCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@Override
public Iterable<? extends Catalog> apply(final Organization org) {
Iterable<Catalog> catalogs = transformParallel(org.getCatalogs().values(),
new Function<NamedResource, Future<Catalog>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Catalog> apply(NamedResource from) {
return (Future<Catalog>) aclient.getCatalog(from.getId());
}
}, executor, null, logger, "catalogs in " + org.getName());
return catalogs;
}
}

View File

@ -32,7 +32,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VDC;
@ -48,11 +48,11 @@ public class AllVDCsInOrg implements Function<Org, Iterable<? extends VDC>> {
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final CommonVCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
AllVDCsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
AllVDCsInOrg(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}

View File

@ -1,76 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.VDC;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class AllVDCsInOrganization implements Function<Organization, Iterable<? extends VDC>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
AllVDCsInOrganization(VCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@Override
public Iterable<? extends VDC> apply(final Organization org) {
Iterable<VDC> catalogItems = transformParallel(org.getVDCs().values(),
new Function<NamedResource, Future<VDC>>() {
@SuppressWarnings("unchecked")
@Override
public Future<VDC> apply(NamedResource from) {
return (Future<VDC>) aclient.getVDC(from.getId());
}
}, executor, null, logger, "vdcs in org " + org.getName());
return catalogItems;
}
}

View File

@ -1,76 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class OrganizationNameAndCatalogNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final String defaultOrg;
private final URI defaultUri;
@Inject
public OrganizationNameAndCatalogNameToEndpoint(Supplier<Map<String, ? extends Organization>> orgMap, @Org String defaultOrg,
@Catalog URI defaultUri) {
this.orgMap = orgMap;
this.defaultOrg = defaultOrg;
this.defaultUri = defaultUri;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1);
if (org == null && catalog == null)
return defaultUri;
else if (org == null)
org = defaultOrg;
try {
Map<String, NamedResource> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
return catalog == null ? Iterables.getLast(catalogs.values()).getId() : catalogs.get(catalog).getId();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
}
}
}

View File

@ -1,76 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.TasksList;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class OrganizationNameAndTasksListNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final String defaultOrg;
private final URI defaultUri;
@Inject
public OrganizationNameAndTasksListNameToEndpoint(Supplier<Map<String, ? extends Organization>> orgMap,
@Org String defaultOrg, @TasksList URI defaultUri) {
this.orgMap = orgMap;
this.defaultOrg = defaultOrg;
this.defaultUri = defaultUri;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgTasksList = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgTasksList, 0);
Object tasksList = Iterables.get(orgTasksList, 1);
if (org == null && tasksList == null)
return defaultUri;
else if (org == null)
org = defaultOrg;
try {
Map<String, NamedResource> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists();
return tasksList == null ? Iterables.getLast(tasksLists.values()).getId() : tasksLists.get(tasksList).getId();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + tasksList + " not found in " + orgMap.get());
}
}
}

View File

@ -1,76 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class OrganizationNameAndVDCNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Organization>> orgNameToVDCEndpoint;
private final String defaultOrg;
private final URI defaultUri;
@Inject
public OrganizationNameAndVDCNameToEndpoint(Supplier<Map<String, ? extends Organization>> orgNameToVDCEndpoint,
@Org String defaultOrg, @VDC URI defaultUri) {
this.orgNameToVDCEndpoint = orgNameToVDCEndpoint;
this.defaultOrg = defaultOrg;
this.defaultUri = defaultUri;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgVdc = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgVdc, 0);
Object vdc = Iterables.get(orgVdc, 1);
if (org == null && vdc == null)
return defaultUri;
else if (org == null)
org = defaultOrg;
try {
Map<String, NamedResource> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();
return vdc == null ? Iterables.getLast(vdcs.values()).getId() : vdcs.get(vdc).getId();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVDCEndpoint.get());
}
}
}

View File

@ -37,7 +37,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.domain.Org;
@ -53,11 +53,11 @@ public class OrgsForLocations implements Function<Iterable<? extends Location>,
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final CommonVCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
OrgsForLocations(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
OrgsForLocations(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}

View File

@ -32,7 +32,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function;
@ -45,11 +45,11 @@ public class OrgsForNames implements Function<Iterable<String>, Iterable<? exten
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final CommonVCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
OrgsForNames(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
OrgsForNames(CommonVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}

View File

@ -33,7 +33,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.VAppTemplate;
@ -50,11 +50,11 @@ public class VAppTemplatesForCatalogItems implements
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final CommonVCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
VAppTemplatesForCatalogItems(VCloudAsyncClient aclient,
VAppTemplatesForCatalogItems(CommonVCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;

View File

@ -1,73 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressAllCatalogsInOrganization implements Function<Organization, Iterable<? extends Catalog>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudExpressAsyncClient aclient;
private final ExecutorService executor;
@Inject
VCloudExpressAllCatalogsInOrganization(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@Override
public Iterable<? extends Catalog> apply(final Organization org) {
Iterable<Catalog> catalogs = transformParallel(org.getCatalogs().values(),
new Function<NamedResource, Future<Catalog>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Catalog> apply(NamedResource from) {
return (Future<Catalog>) aclient.getCatalog(from.getId());
}
}, executor, null, logger, "catalogs in " + org.getName());
return catalogs;
}
}

View File

@ -1,75 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.VDC;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressAllVDCsInOrganization implements Function<Organization, Iterable<? extends VDC>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudExpressAsyncClient aclient;
private final ExecutorService executor;
@Inject
VCloudExpressAllVDCsInOrganization(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@Override
public Iterable<? extends VDC> apply(final Organization org) {
Iterable<VDC> catalogItems = transformParallel(org.getVDCs().values(),
new Function<NamedResource, Future<VDC>>() {
@SuppressWarnings("unchecked")
@Override
public Future<VDC> apply(NamedResource from) {
return (Future<VDC>) aclient.getVDC(from.getId());
}
}, executor, null, logger, "vdcs in org " + org.getName());
return catalogItems;
}
}

View File

@ -1,70 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressOrganizationsForNames implements Function<Iterable<String>, Iterable<? extends Organization>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudExpressAsyncClient aclient;
private final ExecutorService executor;
@Inject
VCloudExpressOrganizationsForNames(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@Override
public Iterable<? extends Organization> apply(Iterable<String> from) {
return transformParallel(from, new Function<String, Future<Organization>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Organization> apply(String from) {
return (Future<Organization>) aclient.findOrganizationNamed(from);
}
}, executor, null, logger, "organizations for names");
}
}

View File

@ -1,98 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressOrganizatonsForLocations implements
Function<Iterable<? extends Location>, Iterable<? extends Organization>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudExpressAsyncClient aclient;
private final ExecutorService executor;
@Inject
VCloudExpressOrganizatonsForLocations(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
/**
* Zones are assignable, but we want regions. so we look for zones, whose
* parent is region. then, we use a set to extract the unique set.
*/
@Override
public Iterable<? extends Organization> apply(Iterable<? extends Location> from) {
return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE;
}
}), new Function<Location, URI>() {
@Override
public URI apply(Location from) {
return VCloudLocation.class.cast(from.getParent()).getResource().getId();
}
})), new Function<URI, Future<Organization>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Organization> apply(URI from) {
return (Future<Organization>) aclient.getOrganization(from);
}
}, executor, null, logger, "organizations for uris");
}
}

View File

@ -1,55 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class VDCNameToEndpoint implements Function<Object, URI> {
private final URI defaultVDC;
private final Organization org;
@Inject
public VDCNameToEndpoint(Organization org, @VDC URI defaultVDC) {
this.org = org;
this.defaultVDC = defaultVDC;
}
public URI apply(Object from) {
try {
return from == null ? defaultVDC : org.getVDCs().get(from).getId();
} catch (NullPointerException e) {
throw new IllegalArgumentException("vdc name: " + from + " not in " + org.getVDCs());
}
}
}

View File

@ -25,7 +25,7 @@ import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus;
@ -41,13 +41,13 @@ import com.google.inject.Inject;
@Singleton
public class TaskSuccess implements Predicate<URI> {
private final VCloudClient client;
private final CommonVCloudClient client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public TaskSuccess(VCloudClient client) {
public TaskSuccess(CommonVCloudClient client) {
this.client = client;
}

View File

@ -1,65 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.predicates;
import java.net.URI;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
*
* Tests to see if a task succeeds.
*
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressTaskSuccess implements Predicate<URI> {
private final VCloudExpressClient client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public VCloudExpressTaskSuccess(VCloudExpressClient client) {
this.client = client;
}
public boolean apply(URI taskId) {
logger.trace("looking for status on task %s", taskId);
Task task = client.getTask(taskId);
logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task
.getStatus());
if (task.getStatus() == TaskStatus.ERROR)
throw new RuntimeException("error on task: " + task.getLocation() + " error: " + task.getError());
return task.getStatus() == TaskStatus.SUCCESS;
}
}

View File

@ -45,7 +45,7 @@ public class Utils {
attributes, "minorErrorCode"));
}
private static String attrOrNull(Attributes attributes, String attr) {
public static String attrOrNull(Attributes attributes, String attr) {
return attributes.getIndex(attr) >= 0 ? attributes.getValue(attributes.getIndex(attr)) : null;
}

View File

@ -19,10 +19,6 @@
package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import static org.jclouds.vcloud.util.Utils.newNamedResource;
import static org.jclouds.vcloud.util.Utils.putNamedResource;
@ -49,10 +45,10 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
protected Map<String, NamedResource> catalogs = Maps.newLinkedHashMap();
protected Map<String, NamedResource> networks = Maps.newLinkedHashMap();
private String description;
protected String description;
public Org getResult() {
return new OrgImpl(org.getName(), org.getId(), description, catalogs, vdcs, networks, tasksList);
return new OrgImpl(org.getName(), org.getType(), org.getId(), description, catalogs, vdcs, networks, tasksList);
}
@Override
@ -62,13 +58,13 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
} else if (qName.equals("Link")) {
int typeIndex = attributes.getIndex("type");
if (typeIndex != -1) {
if (attributes.getValue(typeIndex).equals(VDC_XML)) {
if (attributes.getValue(typeIndex).indexOf("vdc+xml") != -1) {
putNamedResource(vdcs, attributes);
} else if (attributes.getValue(typeIndex).equals(CATALOG_XML)) {
} else if (attributes.getValue(typeIndex).indexOf("catalog+xml") != -1) {
putNamedResource(catalogs, attributes);
} else if (attributes.getValue(typeIndex).equals(TASKSLIST_XML)) {
} else if (attributes.getValue(typeIndex).indexOf("tasksList+xml") != -1) {
tasksList = newNamedResource(attributes);
} else if (attributes.getValue(typeIndex).equals(NETWORK_XML)) {
} else if (attributes.getValue(typeIndex).indexOf("network+xml") != -1) {
putNamedResource(networks, attributes);
}
}

View File

@ -1,69 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML;
import static org.jclouds.vcloud.util.Utils.newNamedResource;
import static org.jclouds.vcloud.util.Utils.putNamedResource;
import java.util.Map;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Maps;
/**
* @author Adrian Cole
*/
public class OrganizationHandler extends ParseSax.HandlerWithResult<Organization> {
protected NamedResource org;
protected Map<String, NamedResource> vdcs = Maps.newLinkedHashMap();
protected Map<String, NamedResource> tasksLists = Maps.newLinkedHashMap();
protected Map<String, NamedResource> catalogs = Maps.newLinkedHashMap();
public Organization getResult() {
return new OrganizationImpl(org.getName(), org.getId(), catalogs, vdcs, tasksLists);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equals("Org")) {
org = newNamedResource(attributes);
} else if (qName.equals("Link")) {
int typeIndex = attributes.getIndex("type");
if (typeIndex != -1) {
if (attributes.getValue(typeIndex).equals(VDC_XML)) {
putNamedResource(vdcs, attributes);
} else if (attributes.getValue(typeIndex).equals(CATALOG_XML)) {
putNamedResource(catalogs, attributes);
} else if (attributes.getValue(typeIndex).equals(TASKSLIST_XML)) {
putNamedResource(tasksLists, attributes);
}
}
}
}
}

View File

@ -111,7 +111,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
public void endElement(String uri, String localName, String qName) {
if (qName.equalsIgnoreCase("Task")) {
this.task = new TaskImpl(taskLink.getId(), status, startTime, endTime, expiryTime, owner, result, error);
taskLink = null;

View File

@ -22,68 +22,106 @@ package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.util.Utils.newNamedResource;
import static org.jclouds.vcloud.util.Utils.putNamedResource;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* @author Adrian Cole
*/
public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
private StringBuilder currentText = new StringBuilder();
private NamedResource vDC;
private Map<String, NamedResource> resourceEntities = Maps.newHashMap();
private Map<String, NamedResource> availableNetworks = Maps.newHashMap();
protected final TaskHandler taskHandler;
private String description;
@Inject
public VDCHandler(TaskHandler taskHandler) {
this.taskHandler = taskHandler;
}
private Quota instantiatedVmsQuota;
protected StringBuilder currentText = new StringBuilder();
private Capacity memoryCapacity;
protected NamedResource vDC;
protected VDCStatus status = VDCStatus.READY;
protected NamedResource org;
protected String description;
protected List<Task> tasks = Lists.newArrayList();
protected AllocationModel allocationModel = AllocationModel.UNRECOGNIZED_MODEL;
private Capacity cpuCapacity;
protected Capacity storageCapacity;
protected Capacity cpuCapacity;
protected Capacity memoryCapacity;
private Capacity storageCapacity;
protected String units;
protected long allocated = 0;
protected long limit = 0;
protected int used = 0;
protected long overhead = 0;
private Quota deployedVmsQuota;
protected Map<String, NamedResource> resourceEntities = Maps.newLinkedHashMap();
protected Map<String, NamedResource> availableNetworks = Maps.newLinkedHashMap();
private String units;
private int allocated;
private int used;
private int limit;
protected int nicQuota;
protected int networkQuota;
protected int vmQuota;
protected boolean isEnabled = true;
public VDC getResult() {
return new VDCImpl(vDC.getName(), vDC.getId(), description, storageCapacity, cpuCapacity, memoryCapacity,
instantiatedVmsQuota, deployedVmsQuota, resourceEntities, availableNetworks);
return new VDCImpl(vDC.getName(), vDC.getType(), vDC.getId(), status, org, description, tasks, allocationModel,
storageCapacity, cpuCapacity, memoryCapacity, resourceEntities, availableNetworks, nicQuota,
networkQuota, vmQuota, isEnabled);
}
void resetCapacity() {
units = null;
allocated = 0;
limit = 0;
used = 0;
overhead = 0;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equals("Vdc")) {
vDC = newNamedResource(attributes);
String status = Utils.attrOrNull(attributes, "status");
if (status != null)
this.status = VDCStatus.fromValue(Integer.parseInt(status));
} else if (qName.equals("Network")) {
putNamedResource(availableNetworks, attributes);
} else if (qName.equals("ResourceEntity")) {
putNamedResource(resourceEntities, attributes);
} else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) {
org = newNamedResource(attributes);
} else {
taskHandler.startElement(uri, localName, qName, attributes);
}
}
public void endElement(String uri, String name, String qName) {
if (qName.equals("Description")) {
taskHandler.endElement(uri, name, qName);
if (qName.equals("Task")) {
this.tasks.add(taskHandler.getResult());
} else if (qName.equals("Description")) {
description = currentOrNull();
} else if (qName.equals("AllocationModel")) {
allocationModel = AllocationModel.fromValue(currentOrNull());
} else if (qName.equals("Units")) {
units = currentOrNull();
} else if (qName.equals("Allocated")) {
@ -92,16 +130,30 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
used = Integer.parseInt(currentOrNull());
} else if (qName.equals("Limit")) {
limit = Integer.parseInt(currentOrNull());
} else if (qName.equals("Overhead")) {
overhead = Integer.parseInt(currentOrNull());
} else if (qName.equals("StorageCapacity")) {
storageCapacity = new Capacity(units, allocated, used);
storageCapacity = new Capacity(units, allocated, limit, used, overhead);
resetCapacity();
} else if (qName.equals("Cpu")) {
cpuCapacity = new Capacity(units, allocated, used);
cpuCapacity = new Capacity(units, allocated, limit, used, overhead);
resetCapacity();
} else if (qName.equals("Memory")) {
memoryCapacity = new Capacity(units, allocated, used);
} else if (qName.equals("InstantiatedVmsQuota")) {
instantiatedVmsQuota = new Quota(limit, used);
memoryCapacity = new Capacity(units, allocated, limit, used, overhead);
resetCapacity();
} else if (qName.equals("DeployedVmsQuota")) {
deployedVmsQuota = new Quota(limit, used);
vmQuota = (int) limit;
// vcloud express doesn't have the zero is unlimited rule
if (vmQuota == -1)
vmQuota = 0;
} else if (qName.equals("VmQuota")) {
vmQuota = Integer.parseInt(currentOrNull());
} else if (qName.equals("NicQuota")) {
nicQuota = Integer.parseInt(currentOrNull());
} else if (qName.equals("NetworkQuota")) {
networkQuota = Integer.parseInt(currentOrNull());
} else if (qName.equals("IsEnabled")) {
isEnabled = Boolean.parseBoolean(currentOrNull());
}
currentText = new StringBuilder();
}

View File

@ -0,0 +1,171 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code VCloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest")
public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> {
protected S connection;
protected String provider;
protected String identity;
protected RestContext<S, A> context;
protected String credential;
@Test
public void testOrg() throws Exception {
Org response = connection.findOrgNamed(null);
assertNotNull(response);
assertNotNull(response.getName());
assert response.getCatalogs().size() >= 1;
assert response.getTasksList() != null;
assert response.getVDCs().size() >= 1;
assertEquals(connection.findOrgNamed(response.getName()), response);
}
@Test
public void testCatalog() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getName());
assertNotNull(response.getId());
assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response);
}
@Test
public void testGetNetwork() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource resource : response.getAvailableNetworks().values()) {
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
Network item = connection.getNetwork(resource.getId());
assertNotNull(item);
}
}
}
@Test
public void testGetCatalogItem() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(null, null, resource.getName());
assertNotNull(item);
assertNotNull(item.getEntity());
assertNotNull(item.getId());
assertNotNull(item.getProperties());
assertNotNull(item.getType());
}
}
}
@Test
public void testGetVAppTemplate() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(null, null, item.getEntity().getName()));
}
}
}
}
@Test
public void testDefaultVDC() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getName());
assertNotNull(response.getId());
assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks());
assertEquals(connection.getVDC(response.getId()), response);
}
@Test
public void testDefaultTasksList() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null);
assertNotNull(response);
assertNotNull(response.getLocation());
assertNotNull(response.getTasks());
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation());
}
@Test
public void testGetTask() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null);
assertNotNull(response);
assertNotNull(response.getLocation());
assertNotNull(response.getTasks());
if (response.getTasks().size() > 0) {
Task task = response.getTasks().last();
assertEquals(connection.getTask(task.getLocation()).getLocation(), task.getLocation());
}
}
@Test
public void testGetVApp() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
VApp app = connection.getVApp(item.getId());
assertNotNull(app);
}
}
}
protected abstract void setupCredentials();
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties props = new Properties();
context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule()), props).getProviderSpecificContext();
connection = context.getApi();
}
}

View File

@ -661,7 +661,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@Override
protected Org provideOrg(VCloudClient discovery) {
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@ -676,7 +676,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@Override
protected URI provideDefaultNetwork(VCloudClient client) {
protected URI provideDefaultNetwork(CommonVCloudClient client) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
}
@ -721,9 +721,9 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
"vdc",
new VDCImpl(
"vdc",
URI
null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
"description",
null, null, "description",
null,
null,
null,
@ -743,7 +743,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
"application/vnd.vmware.vcloud.vAppTemplate+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))),
null))));
null, 0, 0, 0, false))));
}
@ -756,7 +756,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Override
public Map<String, Org> get() {
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", URI
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "description", ImmutableMap
.<String, NamedResource> of("catalog", new NamedResourceImpl("catalog",
VCloudMediaType.CATALOG_XML, URI

View File

@ -20,155 +20,21 @@
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.Properties;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code VCloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest")
public class VCloudClientLiveTest {
protected VCloudClient connection;
protected String identity;
protected RestContext<VCloudClient, VCloudAsyncClient> context;
private String credential;
@Test
public void testOrg() throws Exception {
Org response = connection.findOrgNamed(null);
assertNotNull(response);
assertNotNull(response.getName());
assert response.getCatalogs().size() >= 1;
assert response.getTasksList() != null;
assert response.getVDCs().size() >= 1;
assertEquals(connection.findOrgNamed(response.getName()), response);
}
@Test
public void testCatalog() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getName());
assertNotNull(response.getId());
assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response);
}
@Test
public void testGetNetwork() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource resource : response.getAvailableNetworks().values()) {
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
Network item = connection.getNetwork(resource.getId());
assertNotNull(item);
}
}
}
@Test
public void testGetCatalogItem() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(null, null, resource.getName());
assertNotNull(item);
assertNotNull(item.getEntity());
assertNotNull(item.getId());
assertNotNull(item.getProperties());
assertNotNull(item.getType());
}
}
}
@Test
public void testGetVAppTemplate() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(null, null, item.getEntity().getName()));
}
}
}
}
@Test
public void testDefaultVDC() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getName());
assertNotNull(response.getId());
assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks());
assertEquals(connection.getVDC(response.getId()), response);
}
@Test
public void testDefaultTasksList() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null);
assertNotNull(response);
assertNotNull(response.getLocation());
assertNotNull(response.getTasks());
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation());
}
@Test
public void testGetTask() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null);
assertNotNull(response);
assertNotNull(response.getLocation());
assertNotNull(response.getTasks());
if (response.getTasks().size() > 0) {
Task task = response.getTasks().last();
assertEquals(connection.getTask(task.getLocation()).getLocation(), task.getLocation());
}
}
@Test
public void testGetVApp() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
VApp app = connection.getVApp(item.getId());
assertNotNull(app);
}
}
}
public class VCloudClientLiveTest extends CommonVCloudClientLiveTest<VCloudClient, VCloudAsyncClient> {
protected void setupCredentials() {
provider = "vcloud";
identity = checkNotNull(System.getProperty("vcloud.identity"), "vcloud.identity");
credential = checkNotNull(System.getProperty("vcloud.credential"), "vcloud.credential");
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties props = new Properties();
context = new ComputeServiceContextFactory().createContext("vcloud", identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule()), props).getProviderSpecificContext();
connection = context.getApi();
}
}

View File

@ -50,21 +50,20 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
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.NetworkHandler;
import org.jclouds.vcloud.xml.OrganizationHandler;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VAppHandler;
@ -183,23 +182,8 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
checkFilters(request);
}
public void testDefaultOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultOrganization");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrganizationHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getOrganization", URI.class);
public void testOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getOrg", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
@ -208,14 +192,14 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrganizationHandler.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindOrganizationNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("findOrganizationNamed", String.class);
public void testFindOrgNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("findOrgNamed", String.class);
HttpRequest request = processor.createRequest(method, "org");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1");
@ -223,27 +207,12 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrganizationHandler.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testDefaultCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultCatalog");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getCatalog", URI.class);
HttpRequest request = processor.createRequest(method, URI
@ -355,21 +324,6 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
checkFilters(request);
}
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultVDC");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VDCHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testFindVDCInOrgNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "vdc");
@ -443,21 +397,6 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
checkFilters(request);
}
public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultTasksList");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/taskslist HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TasksListHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getTasksList", URI.class);
HttpRequest request = processor.createRequest(method, URI
@ -475,8 +414,8 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
}
public void testFindTasksListInOrgNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "tasksList");
Method method = VCloudAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class);
HttpRequest request = processor.createRequest(method, "org");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
@ -704,24 +643,24 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
}
@Override
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org");
}
@Override
protected String provideOrgName(@Org Iterable<NamedResource> orgs) {
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return "org";
}
@Override
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) {
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog");
}
@Override
protected Organization provideOrganization(VCloudExpressClient discovery) {
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@ -731,17 +670,17 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
}
@Override
protected URI provideDefaultTasksList(Organization org) {
protected URI provideDefaultTasksList(Org org) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/taskslist");
}
@Override
protected URI provideDefaultVDC(Organization org) {
protected URI provideDefaultVDC(Org org) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1");
}
@Override
protected URI provideDefaultNetwork(VCloudExpressClient client) {
protected URI provideDefaultNetwork(CommonVCloudClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
@ -768,55 +707,54 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
@Override
protected void configure() {
super.configure();
bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class);
bind(OrganizationCatalogSupplier.class).to(TestOrganizationCatalogSupplier.class);
bind(OrganizationCatalogItemSupplier.class).to(TestOrganizationCatalogItemSupplier.class);
bind(OrgMapSupplier.class).to(TestOrgMapSupplier.class);
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
}
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrganizationVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) {
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of("vdc", new VDCImpl("vdc", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "description", null, null, null,
null, null, ImmutableMap.<String, NamedResource> of("vapp", new NamedResourceImpl("vapp",
"application/vnd.vmware.vcloud.vApp+xml", URI
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of("vdc", new VDCImpl("vdc", null, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), null, null, "description", null,
null, null, null, null, ImmutableMap.<String, NamedResource> of("vapp",
new NamedResourceImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network", new NamedResourceImpl("network",
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))),
null))));
null, 0, 0, 0, false))));
}
@Singleton
public static class TestOrganizationMapSupplier extends OrganizationMapSupplier {
public static class TestOrgMapSupplier extends OrgMapSupplier {
@Inject
protected TestOrganizationMapSupplier() {
protected TestOrgMapSupplier() {
super(null, null);
}
@Override
public Map<String, Organization> get() {
return ImmutableMap.<String, Organization> of("org", new OrganizationImpl("org", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), ImmutableMap
public Map<String, Org> get() {
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), null, ImmutableMap
.<String, NamedResource> of("catalog", new NamedResourceImpl("catalog",
VCloudExpressMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, NamedResource> of("vdc", new NamedResourceImpl("vdc", VCloudExpressMediaType.VDC_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, NamedResource> of("tasksList", new NamedResourceImpl("tasksList",
VCloudExpressMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")))));
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), null,
new NamedResourceImpl("tasksList", VCloudExpressMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"))));
}
}
@Singleton
public static class TestOrganizationCatalogSupplier extends OrganizationCatalogSupplier {
public static class TestOrgCatalogSupplier extends OrgCatalogSupplier {
@Inject
protected TestOrganizationCatalogSupplier() {
protected TestOrgCatalogSupplier() {
super(null, null);
}
@ -835,8 +773,8 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
}
@Singleton
public static class TestOrganizationCatalogItemSupplier extends OrganizationCatalogItemSupplier {
protected TestOrganizationCatalogItemSupplier() {
public static class TestOrgCatalogItemSupplier extends OrgCatalogItemSupplier {
protected TestOrgCatalogItemSupplier() {
super(null, null);
}

View File

@ -20,156 +20,22 @@
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.Properties;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code VCloudClient}
* Tests behavior of {@code VCloudExpressClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest")
public class VCloudExpressClientLiveTest {
protected VCloudExpressClient connection;
protected String identity;
protected RestContext<VCloudExpressClient, VCloudExpressAsyncClient> context;
private String credential;
@Test
public void testOrganization() throws Exception {
Organization response = connection.findOrganizationNamed(null);
assertNotNull(response);
assertNotNull(response.getName());
assert response.getCatalogs().size() >= 1;
assert response.getTasksLists().size() >= 1;
assert response.getVDCs().size() >= 1;
assertEquals(connection.findOrganizationNamed(response.getName()), response);
}
@Test
public void testCatalog() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getName());
assertNotNull(response.getId());
assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response);
}
@Test
public void testGetNetwork() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource resource : response.getAvailableNetworks().values()) {
if (resource.getType().equals(VCloudExpressMediaType.NETWORK_XML)) {
Network item = connection.getNetwork(resource.getId());
assertNotNull(item);
}
}
}
@Test
public void testGetCatalogItem() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(null, null, resource.getName());
assertNotNull(item);
assertNotNull(item.getEntity());
assertNotNull(item.getId());
assertNotNull(item.getProperties());
assertNotNull(item.getType());
}
}
}
@Test
public void testGetVAppTemplate() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId());
if (item.getEntity().getType().equals(VCloudExpressMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(null, null, item.getEntity().getName()));
}
}
}
}
@Test
public void testDefaultVDC() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getName());
assertNotNull(response.getId());
assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks());
assertEquals(connection.getVDC(response.getId()), response);
}
@Test
public void testDefaultTasksList() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getLocation());
assertNotNull(response.getTasks());
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation());
}
@Test
public void testGetTask() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getLocation());
assertNotNull(response.getTasks());
if (response.getTasks().size() > 0) {
Task task = response.getTasks().last();
assertEquals(connection.getTask(task.getLocation()).getLocation(), task.getLocation());
}
}
@Test
public void testGetVApp() throws Exception {
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudExpressMediaType.VAPP_XML)) {
VApp app = connection.getVApp(item.getId());
assertNotNull(app);
}
}
}
public class VCloudExpressClientLiveTest extends
CommonVCloudClientLiveTest<VCloudExpressClient, VCloudExpressAsyncClient> {
protected void setupCredentials() {
provider = "vcloudexpress";
identity = checkNotNull(System.getProperty("vcloudexpress.identity"), "vcloudexpress.identity");
credential = checkNotNull(System.getProperty("vcloudexpress.credential"), "vcloudexpress.credential");
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties props = new Properties();
context = new ComputeServiceContextFactory().createContext("vcloudexpress", identity, credential, ImmutableSet
.<Module> of(new Log4JLoggingModule()), props).getProviderSpecificContext();
connection = context.getApi();
}
}

View File

@ -29,6 +29,7 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
@ -70,4 +71,38 @@ public class OrgHandlerTest {
.create("http://vcloud.example.com/api/v1.0/tasksList/5")));
}
public void testTerremark() {
InputStream is = getClass().getResourceAsStream("/express/org.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
assertEquals(result.getName(), "adrian@jclouds.org");
assertEquals(result.getId(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
assertEquals(result.getCatalogs(), ImmutableMap.of("Miami Environment 1 Catalog", new NamedResourceImpl(
"Miami Environment 1 Catalog", CATALOG_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))));
assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new NamedResourceImpl(
"Miami Environment 1", VCloudExpressMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))));
assertEquals(result.getTasksList(), new NamedResourceImpl("Miami Environment 1 Tasks List", TASKSLIST_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32")));
}
public void testHosting() {
InputStream is = getClass().getResourceAsStream("/express/org-hosting.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
assertEquals(result.getName(), "Customer 188849");
assertEquals(result.getId(), URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/188849"));
assertEquals(result.getCatalogs(), ImmutableMap.of("HMS Shared Catalog", new NamedResourceImpl(
"HMS Shared Catalog", CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))));
assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter", new NamedResourceImpl(
"188849 Virtual DataCenter", VCloudExpressMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"))));
assertEquals(result.getTasksList(), new NamedResourceImpl("188849 Task List", TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849")));
}
}

View File

@ -1,85 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code OrgHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.OrgHandlerTest")
public class OrganizationHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/express/org.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
Organization result = (Organization) factory.create(injector.getInstance(OrganizationHandler.class)).parse(is);
assertEquals(result.getName(), "adrian@jclouds.org");
assertEquals(result.getId(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
assertEquals(result.getCatalogs(), ImmutableMap.of("Miami Environment 1 Catalog", new NamedResourceImpl(
"Miami Environment 1 Catalog", CATALOG_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))));
assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new NamedResourceImpl(
"Miami Environment 1", VCloudExpressMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))));
assertEquals(result.getTasksLists(), ImmutableMap.of("Miami Environment 1 Tasks List", new NamedResourceImpl(
"Miami Environment 1 Tasks List", TASKSLIST_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32"))));
}
public void testHosting() {
InputStream is = getClass().getResourceAsStream("/express/org-hosting.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
Organization result = (Organization) factory.create(injector.getInstance(OrganizationHandler.class)).parse(is);
assertEquals(result.getName(), "Customer 188849");
assertEquals(result.getId(), URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/188849"));
assertEquals(result.getCatalogs(), ImmutableMap.of("HMS Shared Catalog", new NamedResourceImpl(
"HMS Shared Catalog", CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))));
assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter", new NamedResourceImpl(
"188849 Virtual DataCenter", VCloudExpressMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"))));
assertEquals(result.getTasksLists(), ImmutableMap.of("188849 Task List",
new NamedResourceImpl("188849 Task List", TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849"))));
}
}

View File

@ -27,10 +27,13 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.testng.annotations.Test;
@ -45,39 +48,68 @@ import com.google.inject.Injector;
*/
@Test(groups = "unit", testName = "vcloud.VDCHandlerTest")
public class VDCHandlerTest {
public void testApplyInputStream() {
public void testVCloud1_0() {
InputStream is = getClass().getResourceAsStream("/vdc.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
assertEquals(result.getName(), "Jclouds-Commit-compG1xstorA01");
assertEquals(result.getId(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vdc+xml");
assertEquals(result.getStatus(), VDCStatus.READY);
assertEquals(result.getOrg(), new NamedResourceImpl(null, VCloudMediaType.ORG_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/org/9566014")));
assertEquals(result.getDescription(), null);
assertEquals(result.getAllocationModel(), AllocationModel.ALLOCATION_POOL);
assertEquals(result.getStorageCapacity(), new Capacity("MB", 1024000, 1024000, 0, 0));
assertEquals(result.getCpuCapacity(), new Capacity("MHz", 20000, 20000, 0, 0));
assertEquals(result.getMemoryCapacity(), new Capacity("MB", 30720, 30720, 0, 0));
assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedResource> of());
assertEquals(result.getAvailableNetworks(), ImmutableMap.of("isolation01", new NamedResourceImpl("isolation01",
"application/vnd.vmware.vcloud.network+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/990419644")), "internet01",
new NamedResourceImpl("internet01", "application/vnd.vmware.vcloud.network+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/758634723"))));
assertEquals(result.getNicQuota(), 0);
assertEquals(result.getNetworkQuota(), 100);
assertEquals(result.getVmQuota(), 50);
assert result.isEnabled();
}
public void testTerremark() {
InputStream is = getClass().getResourceAsStream("/express/vdc.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
assertEquals(result.getName(), "Miami Environment 1");
assertEquals(result.getId(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
assertEquals(result.getDescription(), null);
assertEquals(result.getStorageCapacity(), null);
assertEquals(result.getCpuCapacity(), null);
assertEquals(result.getMemoryCapacity(), null);
assertEquals(result.getInstantiatedVmsQuota(), null);
assertEquals(result.getDeployedVmsQuota(), null);
assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedResource> of());
assertEquals(result.getStorageCapacity(), new Capacity("bytes * 10^9", 100, 0, 8, 0));
assertEquals(result.getCpuCapacity(), new Capacity("hz * 10^6", 5000, 0, 0, 0));
assertEquals(result.getMemoryCapacity(), new Capacity("bytes * 2^20", 10240, 0, 0, 0));
assertEquals(result.getVmQuota(), 0);
assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedResource> of("adriantest",
new NamedResourceImpl("adriantest", VCloudExpressMediaType.VAPP_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15124")), "centos-53",
new NamedResourceImpl("centos-53", VCloudExpressMediaType.VAPP_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15120"))));
assertEquals(result.getAvailableNetworks(), ImmutableMap.of("10.114.34.128/26", new NamedResourceImpl(
"10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
}
public void testApplyHosting() {
InputStream is = getClass().getResourceAsStream("/vdc-hosting.xml");
public void testHostingDotCom() {
InputStream is = getClass().getResourceAsStream("/express/vdc-hosting.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
assertEquals(result.getName(), "vDC Name");
assertEquals(result.getId(), URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"));
assertEquals(result.getDescription(), "vDC Name");
assertEquals(result.getStorageCapacity(), new Capacity("bytes * 10^9", 0, 40960));
assertEquals(result.getCpuCapacity(), new Capacity("hz * 10^6", 0, 2400));
assertEquals(result.getMemoryCapacity(), new Capacity("bytes * 10^9", 0, 2));
assertEquals(result.getInstantiatedVmsQuota(), new Quota(0, 2));
assertEquals(result.getDeployedVmsQuota(), new Quota(0, 2));
assertEquals(result.getStorageCapacity(), new Capacity("bytes * 10^9", 0, 0, 40960, 0));
assertEquals(result.getCpuCapacity(), new Capacity("hz * 10^6", 0, 0, 2400, 0));
assertEquals(result.getMemoryCapacity(), new Capacity("bytes * 10^9", 0, 0, 2, 0));
assertEquals(result.getVmQuota(), 0);
assertEquals(result.getResourceEntities(), new ImmutableMap.Builder<String, NamedResource>().put(
"Plesk (Linux) 64-bit Template",
new NamedResourceImpl("Plesk (Linux) 64-bit Template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
@ -91,8 +123,9 @@ public class VDCHandlerTest {
new NamedResourceImpl("Cent OS 64 Bit Template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"))).put(
"cPanel (Linux) 64 Bit Template",
new NamedResourceImpl("cPanel (Linux) 64 Bit Template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4"))).put(
new NamedResourceImpl("cPanel (Linux) 64 Bit Template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4"))).put(
"188849-1",
new NamedResourceImpl("188849-1", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1"))).put(

View File

@ -0,0 +1,36 @@
<Vdc href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog" type="application/vnd.vmware.vcloud.catalog+xml" name="Miami Environment 1"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps" type="application/xml" name="Public IPs"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices" type="application/xml" name="Internet Services"/>
<Description/>
<StorageCapacity>
<Units>bytes * 10^9</Units>
<Allocated>100</Allocated>
<Used>8</Used>
</StorageCapacity>
<ComputeCapacity>
<Cpu>
<Units>hz * 10^6</Units>
<Allocated>5000</Allocated>
</Cpu>
<Memory>
<Units>bytes * 2^20</Units>
<Allocated>10240</Allocated>
</Memory>
<InstantiatedVmsQuota>
<Limit>-1</Limit>
<Used>-1</Used>
</InstantiatedVmsQuota>
<DeployedVmsQuota>
<Limit>-1</Limit>
<Used>-1</Used>
</DeployedVmsQuota>
</ComputeCapacity>
<ResourceEntities>
<ResourceEntity href="https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15124" type="application/vnd.vmware.vcloud.vApp+xml" name="adriantest"/>
<ResourceEntity href="https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15120" type="application/vnd.vmware.vcloud.vApp+xml" name="centos-53"/>
</ResourceEntities>
<AvailableNetworks>
<Network href="https://services.vcloudexpress.terremark.com/api/v0.8/network/1708" type="application/vnd.vmware.vcloud.network+xml" name="10.114.34.128/26"/>
</AvailableNetworks>
</Vdc>

View File

@ -1,6 +1,49 @@
<Vdc href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<?xml version="1.0" encoding="UTF-8"?>
<Vdc xmlns="http://www.vmware.com/vcloud/v1" status="1" name="Jclouds-Commit-compG1xstorA01" type="application/vnd.vmware.vcloud.vdc+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://
vcenterprise.bluelock.com/api/v1.0/schema/master.xsd">
<Link rel="up" type="application/vnd.vmware.vcloud.org+xml" href="https://vcenterprise.bluelock.com/api/v1.0/org/9566014"/>
<Link rel="add" type="application/vnd.vmware.vcloud.uploadVAppTemplateParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/uploadVAppTemplate"/>
<Link rel="add" type="application/vnd.vmware.vcloud.media+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/media"/>
<Link rel="add" type="application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/instantiateVAppTemplate"/>
<Link rel="add" type="application/vnd.vmware.vcloud.cloneVAppParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/cloneVApp"/>
<Link rel="add" type="application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/cloneVAppTemplate"/>
<Link rel="add" type="application/vnd.vmware.vcloud.cloneMediaParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/cloneMedia"/>
<Link rel="add" type="application/vnd.vmware.vcloud.captureVAppParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/captureVApp"/>
<Link rel="add" type="application/vnd.vmware.vcloud.composeVAppParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/composeVApp"/>
<Link rel="move" type="application/vnd.vmware.vcloud.moveMediaParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/moveMedia"/>
<Link rel="move" type="application/vnd.vmware.vcloud.moveVAppParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/moveVApp"/>
<Link rel="move" type="application/vnd.vmware.vcloud.moveVAppTemplateParams+xml" href="https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439/action/moveVAppTemplate"/>
<AllocationModel>AllocationPool</AllocationModel>
<StorageCapacity>
<Units>MB</Units>
<Allocated>1024000</Allocated>
<Limit>1024000</Limit>
<Used>0</Used>
<Overhead>0</Overhead>
</StorageCapacity>
<ComputeCapacity>
<Cpu>
<Units>MHz</Units>
<Allocated>20000</Allocated>
<Limit>20000</Limit>
<Used>0</Used>
<Overhead>0</Overhead>
</Cpu>
<Memory>
<Units>MB</Units>
<Allocated>30720</Allocated>
<Limit>30720</Limit>
<Used>0</Used>
<Overhead>0</Overhead>
</Memory>
</ComputeCapacity>
<ResourceEntities/>
<AvailableNetworks>
<Network href="https://services.vcloudexpress.terremark.com/api/v0.8/network/1708" type="application/vnd.vmware.vcloud.network+xml" name="10.114.34.128/26"/>
<Network type="application/vnd.vmware.vcloud.network+xml" name="isolation01" href="https://vcenterprise.bluelock.com/api/v1.0/network/990419644"/>
<Network type="application/vnd.vmware.vcloud.network+xml" name="internet01" href="https://vcenterprise.bluelock.com/api/v1.0/network/758634723"/>
</AvailableNetworks>
<NicQuota>0</NicQuota>
<NetworkQuota>100</NetworkQuota>
<VmQuota>50</VmQuota>
<IsEnabled>true</IsEnabled>
</Vdc>

View File

@ -19,8 +19,7 @@
package org.jclouds.vcloud.hostingdotcom;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import java.net.URI;
@ -31,7 +30,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
@ -42,12 +40,10 @@ import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.hostingdotcom.xml.HostingDotComVAppHandler;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -55,22 +51,12 @@ 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"
* />
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface HostingDotComVCloudAsyncClient extends VCloudExpressAsyncClient {
@GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML)
@Produces(CATALOG_XML)
// produces is incorrect, but required for hosting.com to operate
@XMLResponseParser(CatalogHandler.class)
@Override
ListenableFuture<? extends Catalog> getDefaultCatalog();
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(HostingDotComVAppHandler.class)

View File

@ -27,7 +27,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
@ -40,7 +40,7 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole
*/
@Singleton
public class HostingDotComVCloudComputeClient extends BaseVCloudExpressComputeClient {
public class HostingDotComVCloudComputeClient extends VCloudExpressComputeClientImpl {
@Inject
protected HostingDotComVCloudComputeClient(VCloudExpressClient client, Predicate<URI> successTester,

View File

@ -25,6 +25,7 @@ import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule;
@ -34,26 +35,22 @@ import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient;
import com.google.inject.Provides;
/**
* 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 HostingDotComVCloudRestClientModule
extends
public class HostingDotComVCloudRestClientModule extends
BaseVCloudExpressRestClientModule<HostingDotComVCloudClient, HostingDotComVCloudAsyncClient> {
public HostingDotComVCloudRestClientModule() {
super(HostingDotComVCloudClient.class,
HostingDotComVCloudAsyncClient.class);
super(HostingDotComVCloudClient.class, HostingDotComVCloudAsyncClient.class);
}
@Provides
@Singleton
protected VCloudExpressAsyncClient provideVCloudAsyncClient(
HostingDotComVCloudAsyncClient in) {
protected VCloudExpressAsyncClient provideVCloudAsyncClient(HostingDotComVCloudAsyncClient in) {
return in;
}
@ -64,7 +61,7 @@ public class HostingDotComVCloudRestClientModule
}
@Override
protected URI provideDefaultNetwork(VCloudExpressClient client) {
protected URI provideDefaultNetwork(CommonVCloudClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}

View File

@ -1,148 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import javax.inject.Named;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import domain.VCloudVersionsAsyncClient;
/**
* Tests behavior of {@code HostingDotComVCloudAsyncClient}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "vcloud.HostingDotComVCloudAsyncClientTest")
public class HostingDotComVCloudAsyncClientTest extends RestClientTest<HostingDotComVCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = HostingDotComVCloudAsyncClient.class.getMethod("getDefaultCatalog");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://catalog HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(request, null, "application/vnd.vmware.vcloud.catalog+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<HostingDotComVCloudAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<HostingDotComVCloudAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new HostingDotComVCloudRestClientModuleExtension();
}
@Override
public ContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("hostingdotcom", "identity", "credential", new Properties());
}
@RequiresHttp
@ConfiguresRestClient
protected static class HostingDotComVCloudRestClientModuleExtension extends HostingDotComVCloudRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcloud/login");
}
@Override
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
return URI.create("https://org");
}
@Override
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) {
return URI.create("https://catalog");
}
@Override
protected Organization provideOrganization(VCloudExpressClient discovery) {
return null;
}
@Override
protected Iterable<NamedResource> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
return null;
}
@Override
protected URI provideDefaultTasksList(Organization org) {
return URI.create("https://taskslist");
}
@Override
protected URI provideDefaultVDC(Organization org) {
return URI.create("https://vdc/1");
}
@Override
protected URI provideDefaultNetwork(VCloudExpressClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
}
}

View File

@ -19,11 +19,11 @@
package org.jclouds.vcloud.terremark;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.CATALOGITEMCUSTOMIZATIONPARAMETERS_XML;
import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML;
import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.INTERNETSERVICE_XML;
@ -44,7 +44,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
@ -62,9 +61,8 @@ import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrganizationNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -77,7 +75,7 @@ import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.functions.ParseTaskFromLocationHeader;
@ -104,8 +102,7 @@ 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"
* />
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
@ -133,42 +130,24 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TerremarkCatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
@Override
@GET
@Deprecated
@Endpoint(Org.class)
@Consumes(ORG_XML)
@XMLResponseParser(TerremarkOrgHandler.class)
ListenableFuture<? extends TerremarkOrganization> getDefaultOrganization();
@Override
@GET
@XMLResponseParser(TerremarkOrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends TerremarkOrganization> getOrganization(@EndpointParam URI orgId);
ListenableFuture<? extends TerremarkOrg> getOrg(@EndpointParam URI orgId);
/**
* @see VCloudExpressClient#findOrganizationNamed
* @see VCloudExpressClient#findOrgNamed
*/
@Override
@GET
@XMLResponseParser(TerremarkOrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends TerremarkOrganization> findOrganizationNamed(
ListenableFuture<? extends TerremarkOrg> findOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
* @see TerremarkVCloudExpressClient#getDefaultVDC
*/
@Override
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@XMLResponseParser(TerremarkVDCHandler.class)
@Consumes(VDC_XML)
ListenableFuture<? extends VDC> getDefaultVDC();
/**
* Terremark does not have multiple catalogs, so we ignore this parameter.
*/
@ -198,8 +177,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrganizationNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrganizationNameAndVDCNameToEndpoint.class) String vdcName);
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see VCloudExpressClient#instantiateVAppTemplateInVDC

View File

@ -35,7 +35,7 @@ import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
@ -45,8 +45,7 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
* 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"
* />
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
@ -61,15 +60,11 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
@Override
TerremarkCatalogItem findCatalogItemInOrgCatalogNamed(String orgName, String catalogName, String itemName);
@Deprecated
@Override
TerremarkOrganization getDefaultOrganization();
TerremarkOrg getOrg(URI orgId);
@Override
TerremarkOrganization getOrganization(URI orgId);
@Override
TerremarkOrganization findOrganizationNamed(String orgName);
TerremarkOrg findOrgNamed(String orgName);
CustomizationParameters getCustomizationOptions(URI customizationOptions);
@ -81,9 +76,8 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
void deletePublicIp(URI ipId);
/**
* This call adds an internet service to a known, existing public IP. This
* call is identical to Add Internet Service except you specify the public IP
* in the request.
* This call adds an internet service to a known, existing public IP. This call is identical to
* Add Internet Service except you specify the public IP in the request.
*
*/
InternetService addInternetServiceToExistingIp(URI existingIpId, String serviceName, Protocol protocol, int port,
@ -105,10 +99,9 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
/**
* This call adds a node to an existing internet service.
* <p/>
* Every vDC is assigned a network of 60 IP addresses that can be used as
* nodes. Each node can associated with multiple internet service. You can
* get a list of the available IP addresses by calling Get IP Addresses for a
* Network.
* Every vDC is assigned a network of 60 IP addresses that can be used as nodes. Each node can
* associated with multiple internet service. You can get a list of the available IP addresses by
* calling Get IP Addresses for a Network.
*
* @param internetServiceId
* @param ipAddress
@ -128,9 +121,8 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
Set<Node> getNodes(URI internetServiceId);
/**
* This call configures the settings of an existing vApp by passing the new
* configuration. The existing vApp must be in a powered off state (status =
* 2).
* This call configures the settings of an existing vApp by passing the new configuration. The
* existing vApp must be in a powered off state (status = 2).
* <p/>
* You can change the following items for a vApp.
* <ol>
@ -139,9 +131,8 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
* <li>Add a virtual disk</li>
* <li>Delete a virtual disk</li>
* </ol>
* You can make more than one change in a single request. For example, you
* can increase the number of virtual CPUs and the amount of virtual memory
* in the same request.
* You can make more than one change in a single request. For example, you can increase the
* number of virtual CPUs and the amount of virtual memory in the same request.
*
* @param VApp
* vApp to change in power state off

View File

@ -38,7 +38,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.domain.TasksList;
@ -61,7 +61,7 @@ import com.google.common.collect.Sets;
* @author Adrian Cole
*/
@Singleton
public class TerremarkVCloudComputeClient extends BaseVCloudExpressComputeClient {
public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl {
private final TerremarkVCloudExpressClient client;
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@ -147,15 +147,15 @@ public class TerremarkVCloudComputeClient extends BaseVCloudExpressComputeClient
} else {
logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getName(), protocol, port);
ip = TerremarkECloudClient.class.cast(client).activatePublicIpInVDC(vApp.getVDC().getId());
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol,
port, withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp
.getName(), vApp.getName())));
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
}
} else {
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress(), protocol, port);
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(), vApp
.getName())));
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
}
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getName(), is.getPublicIpAddress().getAddress(), is
.getProtocol(), is.getPort());
@ -204,10 +204,9 @@ public class TerremarkVCloudComputeClient extends BaseVCloudExpressComputeClient
}
/**
* deletes the internet service and nodes associated with the vapp. Deletes
* the IP address, if there are no others using it. Finally, it powers off
* and deletes the vapp. Note that we do not call undeploy, as terremark does
* not support the command.
* deletes the internet service and nodes associated with the vapp. Deletes the IP address, if
* there are no others using it. Finally, it powers off and deletes the vapp. Note that we do not
* call undeploy, as terremark does not support the command.
*/
@Override
public void stop(URI id) {
@ -238,7 +237,7 @@ public class TerremarkVCloudComputeClient extends BaseVCloudExpressComputeClient
}
void blockOnLastTask(VApp vApp) {
TasksList list = client.findTasksListInOrgNamed(null, null);
TasksList list = client.findTasksListInOrgNamed(null);
try {
Task lastTask = getLast(filter(list.getTasks(), new Predicate<Task>() {

View File

@ -19,7 +19,6 @@
package org.jclouds.vcloud.terremark.compute.config;
import java.security.SecureRandom;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -46,9 +45,9 @@ import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule;
import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressRebootNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy;
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient;
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeService;
import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials;
@ -98,11 +97,11 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressCom
}).in(Scopes.SINGLETON);
// NOTE
bind(RunNodesAndAddToSetStrategy.class).to(TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudExpressListNodesStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
// NOTE
bind(GetNodeMetadataStrategy.class).to(TerremarkVCloudGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudExpressRebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(VCloudExpressDestroyNodeStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class);
bindLoadBalancer();
// MORE specifics...
bind(new TypeLiteral<Function<NodeMetadata, OrgAndName>>() {

View File

@ -30,7 +30,7 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.terremark.compute.domain.OrgAndName;
@ -62,7 +62,7 @@ public class NodeMetadataToOrgAndName implements Function<NodeMetadata, OrgAndNa
@Override
public OrgAndName apply(NodeMetadata from) {
if (from.getTag() != null) {
Organization org = client.findOrganizationNamed(vdcToOrg.get().get(from.getLocation().getId()));
Org org = client.findOrgNamed(vdcToOrg.get().get(from.getLocation().getId()));
if (org == null) {
logger.warn("did not find an association for vdc %s in %s", from.getLocation().getId(), vdcToOrg);
} else {

View File

@ -38,12 +38,12 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.GetExtra;
import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials;
import org.jclouds.vcloud.terremark.compute.domain.OrgAndName;
@ -54,7 +54,7 @@ import com.google.common.base.Supplier;
* @author Adrian Cole
*/
@Singleton
public class TerremarkVCloudGetNodeMetadataStrategy extends VCloudExpressGetNodeMetadataStrategy {
public class TerremarkVCloudGetNodeMetadataStrategy extends VCloudGetNodeMetadataStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@ -62,10 +62,10 @@ public class TerremarkVCloudGetNodeMetadataStrategy extends VCloudExpressGetNode
private final ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap;
@Inject
protected TerremarkVCloudGetNodeMetadataStrategy(VCloudExpressClient client,
VCloudExpressComputeClient computeClient, Map<VAppStatus, NodeState> vAppStatusToNodeState,
GetExtra getExtra, FindLocationForResource findLocationForResourceInVDC,
Supplier<Set<? extends Image>> images, ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
protected TerremarkVCloudGetNodeMetadataStrategy(CommonVCloudClient client, CommonVCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images,
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
super(client, computeClient, vAppStatusToNodeState, getExtra, findLocationForResourceInVDC, images);
this.credentialsMap = credentialsMap;
}

View File

@ -32,8 +32,8 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.functions.ImagesInOrganization;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.compute.functions.ImagesInOrg;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@ -50,16 +50,16 @@ public class VAppTemplatesInOrgs implements Supplier<Set<? extends Image>> {
public Logger logger = Logger.NULL;
private final Supplier<Set<? extends Location>> locations;
private final Function<Iterable<? extends Location>, Iterable<? extends Organization>> organizatonsForLocations;
private final ImagesInOrganization imagesInOrganization;
private final Function<Iterable<? extends Location>, Iterable<? extends Org>> organizatonsForLocations;
private final ImagesInOrg imagesInOrg;
@Inject
VAppTemplatesInOrgs(Supplier<Set<? extends Location>> locations,
Function<Iterable<? extends Location>, Iterable<? extends Organization>> organizatonsForLocations,
ImagesInOrganization imagesInOrganization) {
Function<Iterable<? extends Location>, Iterable<? extends Org>> organizatonsForLocations,
ImagesInOrg imagesInOrg) {
this.locations = locations;
this.organizatonsForLocations = organizatonsForLocations;
this.imagesInOrganization = imagesInOrganization;
this.imagesInOrg = imagesInOrg;
}
/**
@ -70,6 +70,6 @@ public class VAppTemplatesInOrgs implements Supplier<Set<? extends Image>> {
public Set<? extends Image> get() {
logger.debug(">> providing vAppTemplates");
return newLinkedHashSet(Iterables.concat(Iterables.transform(organizatonsForLocations.apply(locations.get()),
imagesInOrganization)));
imagesInOrg)));
}
}

View File

@ -102,7 +102,7 @@ public class TerremarkVCloudExpressRestClientModule extends
@Override
public NamedResource apply(NamedResource from) {
return client.findOrganizationNamed(from.getName()).getKeysList();
return client.findOrgNamed(from.getName()).getKeysList();
}
});

View File

@ -20,9 +20,8 @@
package org.jclouds.vcloud.terremark.domain;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrganizationImpl;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrgImpl;
import org.jclouds.vcloud.terremark.endpoints.KeysList;
import com.google.inject.ImplementedBy;
@ -30,9 +29,9 @@ import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@Org
@ImplementedBy(TerremarkOrganizationImpl.class)
public interface TerremarkOrganization extends Organization {
@org.jclouds.vcloud.endpoints.Org
@ImplementedBy(TerremarkOrgImpl.class)
public interface TerremarkOrg extends Org {
@KeysList
NamedResource getKeysList();

View File

@ -22,9 +22,11 @@ package org.jclouds.vcloud.terremark.domain.internal;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
/**
* Locations of resources in a Terremark vCloud
@ -32,13 +34,14 @@ import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
* @author Adrian Cole
*
*/
public class TerremarkOrganizationImpl extends OrganizationImpl implements TerremarkOrganization {
public class TerremarkOrgImpl extends OrgImpl implements TerremarkOrg {
private final NamedResource keysList;
public TerremarkOrganizationImpl(String name, URI id, Map<String, NamedResource> catalogs,
Map<String, NamedResource> vdcs, Map<String, NamedResource> tasksLists, NamedResource keysList) {
super(name, id, catalogs, vdcs, tasksLists);
public TerremarkOrgImpl(String name, String type, URI id, String description, Map<String, NamedResource> catalogs,
Map<String, NamedResource> vdcs, Map<String, NamedResource> networks, @Nullable NamedResource tasksList,
NamedResource keysList) {
super(name, type, id, description, catalogs, vdcs, networks, tasksList);
this.keysList = keysList;
}

View File

@ -24,9 +24,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
@ -45,12 +49,14 @@ public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public TerremarkVDCImpl(String name, URI id, String description, Capacity storageCapacity,
Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, Quota deployedVmsQuota,
Map<String, NamedResource> availableNetworks, Map<String, NamedResource> resourceEntities,
NamedResource catalog, NamedResource publicIps, NamedResource internetServices) {
super(name, id, description, storageCapacity, cpuCapacity, memoryCapacity, instantiatedVmsQuota,
deployedVmsQuota, availableNetworks, resourceEntities);
public TerremarkVDCImpl(String name, String type, URI id, VDCStatus status, NamedResource org,
@Nullable String description, Iterable<Task> tasks, AllocationModel allocationModel,
@Nullable Capacity storageCapacity, @Nullable Capacity cpuCapacity, @Nullable Capacity memoryCapacity,
Map<String, NamedResource> resourceEntities, Map<String, NamedResource> availableNetworks, int nicQuota,
int networkQuota, int vmQuota, boolean isEnabled, NamedResource catalog, NamedResource publicIps,
NamedResource internetServices) {
super(name, type, id, status, org, description, tasks, allocationModel, storageCapacity, cpuCapacity,
memoryCapacity, resourceEntities, availableNetworks, nicQuota, networkQuota, vmQuota, isEnabled);
this.catalog = checkNotNull(catalog, "catalog");
this.publicIps = checkNotNull(publicIps, "publicIps");
this.internetServices = checkNotNull(internetServices, "internetServices");

View File

@ -26,9 +26,8 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@ -40,28 +39,27 @@ import com.google.common.collect.Maps;
*/
@Singleton
public class OrgURIToKeysListEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final Supplier<Map<String, ? extends Org>> orgMap;
private final URI defaultOrg;
@Inject
public OrgURIToKeysListEndpoint(Supplier<Map<String, ? extends Organization>> orgMap, @Org URI defaultUri) {
public OrgURIToKeysListEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.vcloud.endpoints.Org URI defaultUri) {
this.orgMap = orgMap;
this.defaultOrg = defaultUri;
}
public URI apply(Object from) {
Map<URI, ? extends Organization> uriToOrg = Maps.uniqueIndex(orgMap.get().values(),
new Function<Organization, URI>() {
Map<URI, ? extends Org> uriToOrg = Maps.uniqueIndex(orgMap.get().values(), new Function<Org, URI>() {
@Override
public URI apply(Organization from) {
public URI apply(Org from) {
return from.getId();
}
});
try {
return TerremarkOrganization.class.cast(uriToOrg.get(from == null ? defaultOrg : from)).getKeysList()
.getId();
return TerremarkOrg.class.cast(uriToOrg.get(from == null ? defaultOrg : from)).getKeysList().getId();
} catch (NullPointerException e) {
throw new ResourceNotFoundException("org " + from + " not found in " + uriToOrg);
}

View File

@ -23,21 +23,22 @@ import static org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType.KEYSL
import static org.jclouds.vcloud.util.Utils.newNamedResource;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrganizationImpl;
import org.jclouds.vcloud.xml.OrganizationHandler;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrgImpl;
import org.jclouds.vcloud.xml.OrgHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class TerremarkOrgHandler extends OrganizationHandler {
public class TerremarkOrgHandler extends OrgHandler {
private NamedResource keysList;
public TerremarkOrganization getResult() {
return new TerremarkOrganizationImpl(org.getName(), org.getId(), catalogs, vdcs, tasksLists, keysList);
public TerremarkOrg getResult() {
return new TerremarkOrgImpl(org.getName(), org.getType(), org.getId(), description, catalogs, vdcs, networks,
tasksList, keysList);
}
@Override

View File

@ -19,12 +19,15 @@
package org.jclouds.vcloud.terremark.xml;
import javax.inject.Inject;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVDCImpl;
import org.jclouds.vcloud.util.Utils;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VDCHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@ -34,15 +37,20 @@ import org.xml.sax.SAXException;
*/
public class TerremarkVDCHandler extends VDCHandler {
@Inject
public TerremarkVDCHandler(TaskHandler taskHandler) {
super(taskHandler);
}
private NamedResource catalog;
private NamedResource publicIps;
private NamedResource internetServices;
public TerremarkVDC getResult() {
VDC vDC = super.getResult();
return new TerremarkVDCImpl(vDC.getName(), vDC.getId(), vDC.getDescription(), vDC.getStorageCapacity(), vDC
.getCpuCapacity(), vDC.getMemoryCapacity(), vDC.getInstantiatedVmsQuota(), vDC.getDeployedVmsQuota(), vDC
.getResourceEntities(), vDC.getAvailableNetworks(), catalog, publicIps, internetServices);
return new TerremarkVDCImpl(vDC.getName(), vDC.getType(), vDC.getId(), status, org, description, tasks,
allocationModel, storageCapacity, cpuCapacity, memoryCapacity, resourceEntities, availableNetworks,
nicQuota, networkQuota, vmQuota, isEnabled, catalog, publicIps, internetServices);
}
@Override

View File

@ -59,7 +59,7 @@ import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.predicates.VCloudExpressTaskSuccess;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
@ -444,7 +444,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
// then
// default internet
// service timeout
successTester = new RetryablePredicate<URI>(injector.getInstance(VCloudExpressTaskSuccess.class), 650, 10, TimeUnit.SECONDS);
successTester = new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS);
}
protected abstract void setupCredentials();

View File

@ -44,18 +44,17 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrganizationCatalogItemSupplier;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrganizationCatalogSupplier;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogItemSupplier;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogSupplier;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestOrgNameToKeysListSupplier;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrganizationMapSupplier;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrganizationVDCSupplier;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrgMapSupplier;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrgVDCSupplier;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
@ -103,21 +102,6 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
checkFilters(request);
}
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getDefaultVDC");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/vdc/1"));
@ -160,8 +144,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row").inGroup(
"group").withPassword("password").inNetwork(URI.create("http://network")));
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row")
.inGroup("group").withPassword("password").inNetwork(URI.create("http://network")));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -266,8 +250,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml")), "application/vnd.tmrk.ecloud.internetService+xml",
false);
"/terremark/CreateInternetService-options-test.xml")),
"application/vnd.tmrk.ecloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null);
@ -446,29 +430,29 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
protected void configure() {
super.configure();
bind(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class);
bind(OrganizationMapSupplier.class).to(TestTerremarkOrganizationMapSupplier.class);
bind(OrganizationCatalogSupplier.class).to(TestOrganizationCatalogSupplier.class);
bind(OrganizationCatalogItemSupplier.class).to(TestOrganizationCatalogItemSupplier.class);
bind(OrganizationVDCSupplier.class).to(TestTerremarkOrganizationVDCSupplier.class);
bind(OrgMapSupplier.class).to(TestTerremarkOrgMapSupplier.class);
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
bind(OrgVDCSupplier.class).to(TestTerremarkOrgVDCSupplier.class);
}
@Override
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return URI.create("https://org");
}
@Override
protected String provideOrgName(@Org Iterable<NamedResource> orgs) {
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return "org";
}
@Override
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) {
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) {
return URI.create("https://catalog");
}
@Override
protected Organization provideOrganization(VCloudExpressClient discovery) {
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@ -478,17 +462,17 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
}
@Override
protected URI provideDefaultTasksList(Organization org) {
protected URI provideDefaultTasksList(Org org) {
return URI.create("https://taskslist");
}
@Override
protected URI provideDefaultVDC(Organization org) {
protected URI provideDefaultVDC(Org org) {
return URI.create("https://vdc/1");
}
@Override
protected URI provideDefaultNetwork(VCloudExpressClient client) {
protected URI provideDefaultNetwork(CommonVCloudClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
}

Some files were not shown because too many files have changed in this diff Show More