mirror of https://github.com/apache/jclouds.git
JCLOUDS-304. Remove broken terremark providers
This commit is contained in:
parent
06b8cd7ac5
commit
ddfefd7ec7
|
@ -83,16 +83,6 @@
|
|||
<artifactId>cloudsigma</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds.provider</groupId>
|
||||
<artifactId>trmk-vcloudexpress</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds.provider</groupId>
|
||||
<artifactId>trmk-ecloud</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds.provider</groupId>
|
||||
<artifactId>bluelock-vcloud-zone01</artifactId>
|
||||
|
|
|
@ -32,6 +32,5 @@
|
|||
<modules>
|
||||
<module>azure</module>
|
||||
<module>openstack</module>
|
||||
<module>trmk</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You 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.
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.jclouds</groupId>
|
||||
<artifactId>jclouds-project</artifactId>
|
||||
<version>1.7.0-SNAPSHOT</version>
|
||||
<relativePath>../../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>org.apache.jclouds.common</groupId>
|
||||
<artifactId>trmk-common</artifactId>
|
||||
<name>common Terremark components</name>
|
||||
<description>common Terremark components</description>
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<properties>
|
||||
<jclouds.osgi.export>org.jclouds.trmk.vcloud_0_8*;version="${project.version}"</jclouds.osgi.export>
|
||||
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jamesmurty.utils</groupId>
|
||||
<artifactId>java-xmlbuilder</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-log4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-sshj</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -1,576 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8;
|
||||
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOGITEMCUSTOMIZATIONPARAMETERS_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOGITEM_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOG_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.INTERNETSERVICE_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.NETWORK_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.NODESERVICE_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.ORG_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.PUBLICIPSLIST_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.PUBLICIP_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.TASKSLIST_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.TASK_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.VAPPTEMPLATE_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.VAPP_XML;
|
||||
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.VDC_XML;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.jclouds.Fallbacks;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.predicates.validators.DnsNameValidator;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.ParamValidators;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.BindCloneVAppParamsToXmlPayload;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.BindNodeConfigurationToXmlPayload;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.BindVAppConfigurationToXmlPayload;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndCatalogNameToEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndTasksListNameToEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndVDCNameToEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameCatalogNameItemNameToEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameCatalogNameVAppTemplateNameToEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameVDCNameResourceEntityNameToEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.CustomizationParameters;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.InternetService;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.KeyPair;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Network;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Node;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Protocol;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.PublicIpAddress;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Task;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.TasksList;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
|
||||
import org.jclouds.trmk.vcloud_0_8.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameToEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.ParseTaskFromLocationHeader;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.VDCURIToInternetServicesEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.VDCURIToPublicIPsEndpoint;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.AddNodeOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.CatalogHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.CatalogItemHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.CustomizationParametersHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.InternetServiceHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.InternetServicesHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.NetworkHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.NodeHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.NodesHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.OrgHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.PublicIpAddressesHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.TaskHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.TasksListHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.VAppHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.VAppTemplateHandler;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.VDCHandler;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* 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 TerremarkVCloudApi extends Closeable {
|
||||
@GET
|
||||
@XMLResponseParser(CatalogHandler.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Catalog getCatalog(@EndpointParam 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
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(CatalogHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
@MapBinder(OrgNameAndCatalogNameToEndpoint.class)
|
||||
Catalog findCatalogInOrgNamed(@Nullable @PayloadParam("orgName") String orgName,
|
||||
@Nullable @PayloadParam("catalogName") String catalogName);
|
||||
|
||||
@GET
|
||||
@Consumes(CATALOGITEM_XML)
|
||||
@XMLResponseParser(CatalogItemHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
CatalogItem getCatalogItem(@EndpointParam 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
|
||||
*/
|
||||
@GET
|
||||
@Consumes(CATALOGITEM_XML)
|
||||
@XMLResponseParser(CatalogItemHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@MapBinder(OrgNameCatalogNameItemNameToEndpoint.class)
|
||||
CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable @PayloadParam("orgName") String orgName,
|
||||
@Nullable @PayloadParam("catalogName") String catalogName, @PayloadParam("itemName") String itemName);
|
||||
|
||||
@GET
|
||||
@Consumes(NETWORK_XML)
|
||||
@XMLResponseParser(NetworkHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@MapBinder(OrgNameVDCNameResourceEntityNameToEndpoint.class)
|
||||
Network findNetworkInOrgVDCNamed(@Nullable @PayloadParam("orgName") String orgName,
|
||||
@Nullable @PayloadParam("vdcName") String vdcName, @PayloadParam("resourceName") String networkName);
|
||||
|
||||
@GET
|
||||
@Consumes(NETWORK_XML)
|
||||
@XMLResponseParser(NetworkHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Network getNetwork(@EndpointParam URI network);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
@Consumes(VDC_XML)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@MapBinder(OrgNameAndVDCNameToEndpoint.class)
|
||||
VDC findVDCInOrgNamed(@Nullable @PayloadParam("orgName") String orgName,
|
||||
@Nullable @PayloadParam("vdcName") String vdcName);
|
||||
|
||||
@GET
|
||||
@Consumes(TASKSLIST_XML)
|
||||
@XMLResponseParser(TasksListHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
TasksList getTasksList(@EndpointParam URI tasksListId);
|
||||
|
||||
@GET
|
||||
@XMLResponseParser(TasksListHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@Consumes(TASKSLIST_XML)
|
||||
@MapBinder(OrgNameAndTasksListNameToEndpoint.class)
|
||||
TasksList findTasksListInOrgNamed(@Nullable @PayloadParam("orgName") String orgName,
|
||||
@Nullable @PayloadParam("tasksListName") String tasksListName);
|
||||
|
||||
/**
|
||||
* Whenever the result of a request cannot be returned immediately, the
|
||||
* server creates a Task object and includes it in the response, as a member
|
||||
* of the Tasks container in the response body. Each Task has an href value,
|
||||
* which is a URL that the client can use to retrieve the Task element alone,
|
||||
* without the rest of the response in which it was contained. All
|
||||
* information about the task is included in the Task element when it is
|
||||
* returned in the response's Tasks container, so a client does not need to
|
||||
* make an additional request to the Task URL unless it wants to follow the
|
||||
* progress of a task that was incomplete.
|
||||
*/
|
||||
@GET
|
||||
@Consumes(TASK_XML)
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Task getTask(@EndpointParam URI taskId);
|
||||
|
||||
@POST
|
||||
@Path("/action/cancel")
|
||||
void cancelTask(@EndpointParam URI taskId);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a listing of all orgs that the current user has access to.
|
||||
*/
|
||||
@Provides
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org
|
||||
Map<String, ReferenceType> listOrgs();
|
||||
|
||||
@POST
|
||||
@Path("/action/instantiateVAppTemplate")
|
||||
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
|
||||
@Consumes(VAPP_XML)
|
||||
@XMLResponseParser(VAppHandler.class)
|
||||
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
VApp instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
|
||||
@PayloadParam("template") URI template,
|
||||
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
@POST
|
||||
@Path("/action/cloneVApp")
|
||||
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
|
||||
@Consumes(TASK_XML)
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
|
||||
Task cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("vApp") URI toClone,
|
||||
@PayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, CloneVAppOptions... options);
|
||||
|
||||
@GET
|
||||
@Consumes(VAPPTEMPLATE_XML)
|
||||
@XMLResponseParser(VAppTemplateHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
VAppTemplate getVAppTemplate(@EndpointParam 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
|
||||
*/
|
||||
@GET
|
||||
@Consumes(VAPPTEMPLATE_XML)
|
||||
@XMLResponseParser(VAppTemplateHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@MapBinder(OrgNameCatalogNameVAppTemplateNameToEndpoint.class)
|
||||
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable @PayloadParam("orgName") String orgName,
|
||||
@Nullable @PayloadParam("catalogName") String catalogName, @PayloadParam("itemName") String itemName);
|
||||
|
||||
@GET
|
||||
@Consumes(VAPP_XML)
|
||||
@XMLResponseParser(VAppHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@MapBinder(OrgNameVDCNameResourceEntityNameToEndpoint.class)
|
||||
VApp findVAppInOrgVDCNamed(@Nullable @PayloadParam("orgName") String orgName,
|
||||
@Nullable @PayloadParam("vdcName") String vdcName, @PayloadParam("resourceName") String vAppName);
|
||||
|
||||
@GET
|
||||
@Consumes(VAPP_XML)
|
||||
@XMLResponseParser(VAppHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
VApp getVApp(@EndpointParam URI vApp);
|
||||
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/action/deploy")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Task deployVApp(@EndpointParam URI vAppId);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/action/undeploy")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Task undeployVApp(@EndpointParam URI vAppId);
|
||||
|
||||
/**
|
||||
* This call powers on the vApp, as specified in the vApp's ovf:Startup
|
||||
* element.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/powerOn")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Task powerOnVApp(@EndpointParam URI vAppId);
|
||||
|
||||
/**
|
||||
* This call powers off the vApp, as specified in the vApp's ovf:Startup
|
||||
* element.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/powerOff")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Task powerOffVApp(@EndpointParam URI vAppId);
|
||||
|
||||
/**
|
||||
* This call shuts down the vApp.
|
||||
*/
|
||||
@POST
|
||||
@Path("/power/action/shutdown")
|
||||
void shutdownVApp(@EndpointParam URI vAppId);
|
||||
|
||||
/**
|
||||
* This call resets the vApp.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/reset")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Task resetVApp(@EndpointParam URI vAppId);
|
||||
|
||||
/**
|
||||
* This call suspends the vApp.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/suspend")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Task suspendVApp(@EndpointParam URI vAppId);
|
||||
|
||||
@DELETE
|
||||
@ResponseParser(ParseTaskFromLocationHeader.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Task deleteVApp(@EndpointParam URI vAppId);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(VDCHandler.class)
|
||||
@Consumes(VDC_XML)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
VDC getVDC(@EndpointParam URI vdc);
|
||||
|
||||
@GET
|
||||
@XMLResponseParser(OrgHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@Consumes(ORG_XML)
|
||||
org.jclouds.trmk.vcloud_0_8.domain.Org getOrg(@EndpointParam URI orgId);
|
||||
|
||||
@GET
|
||||
@XMLResponseParser(OrgHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@Consumes(ORG_XML)
|
||||
org.jclouds.trmk.vcloud_0_8.domain.Org findOrgNamed(
|
||||
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
|
||||
|
||||
@GET
|
||||
@XMLResponseParser(CustomizationParametersHandler.class)
|
||||
@Consumes(CATALOGITEMCUSTOMIZATIONPARAMETERS_XML)
|
||||
CustomizationParameters getCustomizationOptions(@EndpointParam URI customization);
|
||||
|
||||
/**
|
||||
* This call returns a list of public IP addresses.
|
||||
*/
|
||||
@GET
|
||||
@Consumes(PUBLICIPSLIST_XML)
|
||||
@XMLResponseParser(PublicIpAddressesHandler.class)
|
||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
||||
Set<PublicIpAddress> getPublicIpsAssociatedWithVDC(
|
||||
@EndpointParam(parser = VDCURIToPublicIPsEndpoint.class) URI vDCId);
|
||||
|
||||
@DELETE
|
||||
@Fallback(TerremarkVCloudFallbacks.VoidOnDeleteDefaultIp.class)
|
||||
void deletePublicIp(@EndpointParam 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.
|
||||
*
|
||||
*/
|
||||
@POST
|
||||
@Path("/internetServices")
|
||||
@Produces(INTERNETSERVICE_XML)
|
||||
@Consumes(INTERNETSERVICE_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@MapBinder(AddInternetServiceOptions.class)
|
||||
InternetService addInternetServiceToExistingIp(@EndpointParam URI publicIpId,
|
||||
@PayloadParam("name") String serviceName, @PayloadParam("protocol") Protocol protocol,
|
||||
@PayloadParam("port") int port, AddInternetServiceOptions... options);
|
||||
|
||||
@DELETE
|
||||
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
|
||||
void deleteInternetService(@EndpointParam URI internetServiceId);
|
||||
|
||||
@GET
|
||||
@Consumes(INTERNETSERVICESLIST_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
InternetService getInternetService(@EndpointParam URI internetServiceId);
|
||||
|
||||
@GET
|
||||
@Consumes(INTERNETSERVICESLIST_XML)
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
||||
Set<InternetService> getAllInternetServicesInVDC(
|
||||
@EndpointParam(parser = VDCURIToInternetServicesEndpoint.class) URI vDCId);
|
||||
|
||||
/**
|
||||
* This call returns information about the internet service on a public IP.
|
||||
*/
|
||||
@GET
|
||||
@Path("/internetServices")
|
||||
@Consumes(INTERNETSERVICESLIST_XML)
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
||||
Set<InternetService> getInternetServicesOnPublicIp(@EndpointParam URI ipId);
|
||||
|
||||
@GET
|
||||
@Consumes(PUBLICIP_XML)
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
||||
Set<InternetService> getPublicIp(@EndpointParam URI ipId);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param internetServiceId
|
||||
* @param ipAddress
|
||||
* @param name
|
||||
* @param port
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Path("/nodeServices")
|
||||
@Produces(NODESERVICE_XML)
|
||||
@Consumes(NODESERVICE_XML)
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@MapBinder(AddNodeOptions.class)
|
||||
Node addNode(@EndpointParam URI internetServiceId,
|
||||
@PayloadParam("ipAddress") String ipAddress, @PayloadParam("name") String name,
|
||||
@PayloadParam("port") int port, AddNodeOptions... options);
|
||||
|
||||
@GET
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@Consumes(NODESERVICE_XML)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Node getNode(@EndpointParam URI nodeId);
|
||||
|
||||
@PUT
|
||||
@Produces(NODESERVICE_XML)
|
||||
@Consumes(NODESERVICE_XML)
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@MapBinder(BindNodeConfigurationToXmlPayload.class)
|
||||
Node configureNode(@EndpointParam URI nodeId, @PayloadParam("name") String name,
|
||||
@PayloadParam("enabled") boolean enabled, @Nullable @PayloadParam("description") String description);
|
||||
|
||||
@DELETE
|
||||
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
|
||||
void deleteNode(@EndpointParam URI nodeId);
|
||||
|
||||
@GET
|
||||
@Path("/nodeServices")
|
||||
@XMLResponseParser(NodesHandler.class)
|
||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
||||
@Consumes(NODESERVICE_XML)
|
||||
Set<Node> getNodes(@EndpointParam 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).
|
||||
* <p/>
|
||||
* You can change the following items for a vApp.
|
||||
* <ol>
|
||||
* <li>vApp name Number of virtual CPUs</li>
|
||||
* <li>Amount of virtual memory</li>
|
||||
* <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.
|
||||
*
|
||||
* @param VApp
|
||||
* vApp to change in power state off
|
||||
* @param configuration
|
||||
* (s) to change
|
||||
* @return task of configuration change
|
||||
*/
|
||||
@PUT
|
||||
@Produces(VAPP_XML)
|
||||
@Consumes(VAPP_XML)
|
||||
@MapBinder(BindVAppConfigurationToXmlPayload.class)
|
||||
@ResponseParser(ParseTaskFromLocationHeader.class)
|
||||
Task configureVApp(
|
||||
@EndpointParam(parser = BindVAppConfigurationToXmlPayload.class) VApp vApp, VAppConfiguration configuration);
|
||||
|
||||
/**
|
||||
*/
|
||||
Set<KeyPair> listKeyPairsInOrg(URI org);
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException
|
||||
* if a key of the same name already exists
|
||||
*/
|
||||
KeyPair generateKeyPairInOrg(URI org, String name, boolean makeDefault);
|
||||
|
||||
/**
|
||||
*/
|
||||
KeyPair findKeyPairInOrg(URI org, String keyPairName);
|
||||
|
||||
KeyPair getKeyPair(URI keyPair);
|
||||
|
||||
// TODO
|
||||
// KeyPair configureKeyPair(int keyPairId, KeyPairConfiguration
|
||||
// keyPairConfiguration);
|
||||
|
||||
void deleteKeyPair(URI keyPair);
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jclouds.Fallback;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
public final class TerremarkVCloudFallbacks {
|
||||
private TerremarkVCloudFallbacks() {
|
||||
}
|
||||
|
||||
/**
|
||||
* There's no current way to determine if an IP is the default outbound one. In this case, we may get errors on
|
||||
* deleting an IP, which are ok.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public static final class VoidOnDeleteDefaultIp implements Fallback<Void> {
|
||||
public static final Pattern MESSAGE_PATTERN = Pattern
|
||||
.compile(".*Cannot release this Public IP as it is default oubound IP.*");
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Void> create(Throwable t) throws Exception {
|
||||
return immediateFuture(createOrPropagate(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void createOrPropagate(Throwable t) throws Exception {
|
||||
if (checkNotNull(t, "throwable") instanceof HttpResponseException) {
|
||||
HttpResponseException hre = HttpResponseException.class.cast(t);
|
||||
if (hre.getResponse().getStatusCode() == 503 || hre.getResponse().getStatusCode() == 401
|
||||
|| MESSAGE_PATTERN.matcher(hre.getMessage()).matches())
|
||||
return null;
|
||||
} else if (t instanceof AuthorizationException) {
|
||||
return null;
|
||||
}
|
||||
throw propagate(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,277 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* Resource Types used in Terremark VCloud
|
||||
*
|
||||
* @see MediaType
|
||||
*/
|
||||
public interface TerremarkVCloudMediaType {
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.error+xml"
|
||||
*/
|
||||
public static final String ERROR_XML = "application/vnd.vmware.vcloud.error+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.error+xml"
|
||||
*/
|
||||
public static final MediaType ERROR_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.error+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vcloud+xml"
|
||||
*/
|
||||
public static final String VCLOUD_XML = "application/vnd.vmware.vcloud.vcloud+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vcloud+xml"
|
||||
*/
|
||||
public static final MediaType VCLOUD_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vcloud+xml");
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.org+xml"
|
||||
*/
|
||||
public static final String ORG_XML = "application/vnd.vmware.vcloud.org+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.org+xml"
|
||||
*/
|
||||
public static final MediaType ORG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.org+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vdc+xml"
|
||||
*/
|
||||
public static final String VDC_XML = "application/vnd.vmware.vcloud.vdc+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vdc+xml"
|
||||
*/
|
||||
public static final MediaType VDC_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vdc+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.catalog+xml"
|
||||
*/
|
||||
public static final String CATALOG_XML = "application/vnd.vmware.vcloud.catalog+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.catalog+xml"
|
||||
*/
|
||||
public static final MediaType CATALOG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.catalog+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.tasksList+xml"
|
||||
*/
|
||||
public static final String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.tasksList+xml"
|
||||
*/
|
||||
public static final MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.catalogItem+xml"
|
||||
*/
|
||||
public static final String CATALOGITEM_XML = "application/vnd.vmware.vcloud.catalogItem+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.catalogItem+xml"
|
||||
*/
|
||||
public static final MediaType CATALOGITEM_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.catalogItem+xml");
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.networkConnectionSection+xml"
|
||||
*/
|
||||
public static final String NETWORKCONNECTIONSECTION_XML = "application/vnd.vmware.vcloud.networkConnectionSection+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.networkConnectionSection+xml"
|
||||
*/
|
||||
public static final MediaType NETWORKCONNECTIONSECTION_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.networkConnectionSection+xml");
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
|
||||
*/
|
||||
public static final String VIRTUALHARDWARESECTION_XML = "application/vnd.vmware.vcloud.virtualHardwareSection+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
|
||||
*/
|
||||
public static final MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.virtualHardwareSection+xml");
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
|
||||
*/
|
||||
public static final String GUESTCUSTOMIZATIONSECTION_XML = "application/vnd.vmware.vcloud.guestCustomizationSection+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
|
||||
*/
|
||||
public static final MediaType GUESTCUSTOMIZATIONSECTION_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.guestCustomizationSection+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.networkSection+xml"
|
||||
*/
|
||||
public static final String NETWORKSECTION_XML = "application/vnd.vmware.vcloud.networkSection+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.networkSection+xml"
|
||||
*/
|
||||
public static final MediaType NETWORKSECTION_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.networkSection+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.task+xml"
|
||||
*/
|
||||
public static final String TASK_XML = "application/vnd.vmware.vcloud.task+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.task+xml"
|
||||
*/
|
||||
public static final MediaType TASK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.task+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.undeployVAppParams+xml"
|
||||
*/
|
||||
public static final String UNDEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.undeployVAppParams+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.undeployVAppParams+xml"
|
||||
*/
|
||||
public static final MediaType UNDEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.undeployVAppParams+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.deployVAppParams+xml"
|
||||
*/
|
||||
public static final String DEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.deployVAppParams+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.deployVAppParams+xml"
|
||||
*/
|
||||
public static final MediaType DEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.deployVAppParams+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vApp+xml"
|
||||
*/
|
||||
public static final String VAPP_XML = "application/vnd.vmware.vcloud.vApp+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vApp+xml"
|
||||
*/
|
||||
public static final MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vm+xml"
|
||||
*/
|
||||
public static final String VM_XML = "application/vnd.vmware.vcloud.vm+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vm+xml"
|
||||
*/
|
||||
public static final MediaType VM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vm+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
|
||||
*/
|
||||
public static final String VAPPTEMPLATE_XML = "application/vnd.vmware.vcloud.vAppTemplate+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
|
||||
*/
|
||||
public static final MediaType VAPPTEMPLATE_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.vAppTemplate+xml");
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.network+xml"
|
||||
*/
|
||||
public static final String NETWORK_XML = "application/vnd.vmware.vcloud.network+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.network+xml"
|
||||
*/
|
||||
public static final MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.rasdItem+xml"
|
||||
*/
|
||||
public static final String RASDITEM_XML = "application/vnd.vmware.vcloud.rasdItem+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.rasdItem+xml"
|
||||
*/
|
||||
public static final MediaType RASDITEM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.rasdItem+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.organizationList+xml"
|
||||
*/
|
||||
public static final String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.organizationList+xml"
|
||||
*/
|
||||
public static final MediaType ORGLIST_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.orgList+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.publicIp+xml"
|
||||
*/
|
||||
public static final String PUBLICIP_XML = "application/vnd.tmrk.vCloud.publicIp+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.publicIp+xml"
|
||||
*/
|
||||
public static final MediaType PUBLICIP_XML_TYPE = new MediaType("application", "vnd.tmrk.vCloud.publicIp+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.publicIpsList+xml"
|
||||
*/
|
||||
public static final String PUBLICIPSLIST_XML = "application/vnd.tmrk.vCloud.publicIpsList+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.publicIpsList+xml"
|
||||
*/
|
||||
public static final MediaType PUBLICIPSLIST_XML_TYPE = new MediaType("application",
|
||||
"vnd.tmrk.vCloud.publicIpsList+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.internetService+xml"
|
||||
*/
|
||||
public static final String INTERNETSERVICE_XML = "application/vnd.tmrk.vCloud.internetService+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.internetService+xml"
|
||||
*/
|
||||
public static final MediaType INTERNETSERVICE_XML_TYPE = new MediaType("application",
|
||||
"vnd.tmrk.vCloud.internetService+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.internetServicesList+xml"
|
||||
*/
|
||||
public static final String INTERNETSERVICESLIST_XML = "application/vnd.tmrk.vCloud.internetServicesList+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.internetServicesList+xml"
|
||||
*/
|
||||
public static final MediaType INTERNETSERVICESLIST_XML_TYPE = new MediaType("application",
|
||||
"vnd.tmrk.vCloud.internetServicesList+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.nodeService+xml"
|
||||
*/
|
||||
public static final String NODESERVICE_XML = "application/vnd.tmrk.vCloud.nodeService+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.nodeService+xml"
|
||||
*/
|
||||
public static final MediaType NODESERVICE_XML_TYPE = new MediaType("application", "vnd.tmrk.vCloud.nodeService+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml"
|
||||
*/
|
||||
public static final String CATALOGITEMCUSTOMIZATIONPARAMETERS_XML = "application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml";
|
||||
|
||||
/**
|
||||
* "application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml"
|
||||
*/
|
||||
public static final MediaType CATALOGITEMCUSTOMIZATIONPARAMETERS_XML_TYPE = new MediaType("application",
|
||||
"vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml");
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8;
|
||||
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VCloudError;
|
||||
|
||||
/**
|
||||
* Encapsulates an VCloud Error.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class VCloudResponseException extends HttpResponseException {
|
||||
|
||||
private org.jclouds.trmk.vcloud_0_8.domain.VCloudError error;
|
||||
|
||||
public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error) {
|
||||
super(String.format("request %s failed with code %s, error: %s", command.getCurrentRequest().getRequestLine(), response
|
||||
.getStatusCode(), error.toString()), command, response);
|
||||
this.setError(error);
|
||||
|
||||
}
|
||||
|
||||
public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error, Throwable cause) {
|
||||
super(String.format("request %1$s failed with error: %2$s", command.getCurrentRequest().getRequestLine(), error
|
||||
.toString()), command, response, cause);
|
||||
this.setError(error);
|
||||
|
||||
}
|
||||
|
||||
public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error) {
|
||||
super(message, command, response);
|
||||
this.setError(error);
|
||||
|
||||
}
|
||||
|
||||
public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error,
|
||||
Throwable cause) {
|
||||
super(message, command, response, cause);
|
||||
this.setError(error);
|
||||
|
||||
}
|
||||
|
||||
public void setError(VCloudError error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public VCloudError getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* A VCloud Session Token
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface VCloudToken {
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.util.Patterns;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindAddInternetServiceToXmlPayload implements MapBinder {
|
||||
@Inject
|
||||
@Named("CreateInternetService")
|
||||
private String xmlTemplate;
|
||||
@Inject
|
||||
private BindToStringPayload stringBinder;
|
||||
@Inject
|
||||
@Named(PROPERTY_TERREMARK_EXTENSION_NS)
|
||||
private String ns;
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
|
||||
String name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
|
||||
String protocol = checkNotNull(postParams.get("protocol"), "protocol parameter not present").toString();
|
||||
String port = checkNotNull(postParams.get("port"), "port parameter not present").toString();
|
||||
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString();
|
||||
String description = (String) postParams.get("description");
|
||||
String payload = Strings2.replaceTokens(xmlTemplate,
|
||||
ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns));
|
||||
try {
|
||||
payload = Patterns.TOKEN_TO_PATTERN.get("description").matcher(payload).replaceAll(description == null ? ""
|
||||
: String.format("\n\t<Description>%s</Description>", description));
|
||||
payload = Patterns.TOKEN_TO_PATTERN.get("monitor").matcher(payload).replaceAll(getMonitorString(postParams));
|
||||
} catch (ExecutionException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return stringBinder.bindToRequest(request, payload);
|
||||
}
|
||||
|
||||
private String getMonitorString(Map<String, Object> postParams)
|
||||
{
|
||||
// Sending no <Monitor> element to Terremark will result in default behavior, which is to create a monitor.
|
||||
String monitor = (String) postParams.get("monitor");
|
||||
if (monitor == null || "true".equalsIgnoreCase(monitor)) {
|
||||
return "";
|
||||
}
|
||||
return "\n\t<Monitor><MonitorType>Disabled</MonitorType></Monitor>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException("CreateInternetService needs parameters");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.util.Patterns;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindAddNodeServiceToXmlPayload implements MapBinder {
|
||||
|
||||
@Inject
|
||||
@Named("CreateNodeService")
|
||||
private String xmlTemplate;
|
||||
@Inject
|
||||
private BindToStringPayload stringBinder;
|
||||
@Inject
|
||||
@Named(PROPERTY_TERREMARK_EXTENSION_NS)
|
||||
private String ns;
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
String ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present").toString();
|
||||
String name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
|
||||
String port = checkNotNull(postParams.get("port"), "port parameter not present").toString();
|
||||
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString();
|
||||
String description = (String) postParams.get("description");
|
||||
|
||||
String payload = Strings2.replaceTokens(xmlTemplate,
|
||||
ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns));
|
||||
try {
|
||||
payload = Patterns.TOKEN_TO_PATTERN.get("description").matcher(payload).replaceAll(description == null ? ""
|
||||
: String.format("\n <Description>%s</Description>", description));
|
||||
} catch (ExecutionException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return stringBinder.bindToRequest(request, payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException("CreateNodeService needs parameters");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindCloneVAppParamsToXmlPayload implements MapBinder {
|
||||
|
||||
protected final String ns;
|
||||
protected final String schema;
|
||||
private final BindToStringPayload stringBinder;
|
||||
|
||||
@Inject
|
||||
public BindCloneVAppParamsToXmlPayload(BindToStringPayload stringBinder,
|
||||
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
|
||||
this.ns = ns;
|
||||
this.schema = schema;
|
||||
this.stringBinder = stringBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
|
||||
String newName = checkNotNull(postParams.remove("newName"), "newName").toString();
|
||||
String vApp = checkNotNull(postParams.remove("vApp"), "vApp").toString();
|
||||
|
||||
CloneVAppOptions options = findOptionsInArgsOrNull(gRequest);
|
||||
if (options == null) {
|
||||
options = new CloneVAppOptions();
|
||||
}
|
||||
try {
|
||||
return stringBinder.bindToRequest(request, generateXml(newName, vApp, options));
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FactoryConfigurationError e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (TransformerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRoot(String name, boolean deploy, boolean powerOn) throws ParserConfigurationException,
|
||||
FactoryConfigurationError {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("CloneVAppParams").a("name", name).a("deploy", deploy + "")
|
||||
.a("powerOn", powerOn + "").a("xmlns", ns).a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
|
||||
.a("xsi:schemaLocation", ns + " " + schema);
|
||||
return rootBuilder;
|
||||
}
|
||||
|
||||
protected String generateXml(String newName, String vApp, CloneVAppOptions options)
|
||||
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
|
||||
XMLBuilder rootBuilder = buildRoot(newName, options.isDeploy(), options.isPowerOn());
|
||||
if (options.getDescription() != null)
|
||||
rootBuilder.e("Description").text(options.getDescription());
|
||||
rootBuilder.e("VApp").a("xmlns", ns).a("href", vApp).a("type", TerremarkVCloudMediaType.VAPP_XML);
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
}
|
||||
|
||||
protected CloneVAppOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) {
|
||||
for (Object arg : gRequest.getInvocation().getArgs()) {
|
||||
if (arg instanceof CloneVAppOptions) {
|
||||
return (CloneVAppOptions) arg;
|
||||
} else if (arg instanceof CloneVAppOptions[]) {
|
||||
CloneVAppOptions[] options = (CloneVAppOptions[]) arg;
|
||||
return (options.length > 0) ? options[0] : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException("CloneVAppParams is needs parameters");
|
||||
}
|
||||
|
||||
protected String ifNullDefaultTo(String value, String defaultValue) {
|
||||
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindCreateKeyToXmlPayload implements MapBinder {
|
||||
|
||||
private final String xmlTemplate;
|
||||
private final BindToStringPayload stringBinder;
|
||||
private final String ns;
|
||||
|
||||
@Inject
|
||||
BindCreateKeyToXmlPayload(@Named(PROPERTY_TERREMARK_EXTENSION_NS) String ns, @Named("CreateKey") String xmlTemplate,
|
||||
BindToStringPayload stringBinder) {
|
||||
this.ns = ns;
|
||||
this.xmlTemplate = xmlTemplate;
|
||||
this.stringBinder = stringBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
String name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
|
||||
String isDefault = checkNotNull(postParams.get("isDefault"), "isDefault parameter not present").toString();
|
||||
|
||||
String payload = Strings2.replaceTokens(xmlTemplate,
|
||||
ImmutableMap.of("name", name, "isDefault", isDefault, "ns", ns));
|
||||
return stringBinder.bindToRequest(request, payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException("CreateKey needs parameters");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Network;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Inject;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder {
|
||||
|
||||
protected final String ns;
|
||||
protected final String schema;
|
||||
private final BindToStringPayload stringBinder;
|
||||
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1",
|
||||
ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
|
||||
private final Supplier<ReferenceType> defaultNetwork;
|
||||
private final String defaultFenceMode;
|
||||
|
||||
@Inject
|
||||
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
|
||||
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
|
||||
@Network Supplier<ReferenceType> network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
|
||||
this.ns = ns;
|
||||
this.schema = schema;
|
||||
this.stringBinder = stringBinder;
|
||||
this.defaultNetwork = network;
|
||||
this.defaultFenceMode = fenceMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
|
||||
String name = checkNotNull(postParams.remove("name"), "name").toString();
|
||||
String template = checkNotNull(postParams.remove("template"), "template").toString();
|
||||
|
||||
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
|
||||
|
||||
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
|
||||
String network = (defaultNetwork != null) ? defaultNetwork.get().getHref().toASCIIString() : null;
|
||||
String fenceMode = defaultFenceMode;
|
||||
String networkName = name;
|
||||
if (options != null) {
|
||||
if (options.getNetworkConfig().size() > 0) {
|
||||
NetworkConfig config = Iterables.get(options.getNetworkConfig(), 0);
|
||||
network = ifNullDefaultTo(config.getParentNetwork(), network);
|
||||
fenceMode = ifNullDefaultTo(config.getFenceMode(), defaultFenceMode);
|
||||
networkName = ifNullDefaultTo(config.getNetworkName(), networkName);
|
||||
}
|
||||
addQuantity(options, virtualHardwareQuantity);
|
||||
}
|
||||
try {
|
||||
return stringBinder.bindToRequest(request,
|
||||
generateXml(name, template, virtualHardwareQuantity, networkName, fenceMode, URI.create(network)));
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FactoryConfigurationError e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (TransformerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String generateXml(String name, String template, SortedMap<ResourceType, String> virtualHardwareQuantity,
|
||||
String networkName, @Nullable String fenceMode, URI network) throws ParserConfigurationException,
|
||||
FactoryConfigurationError, TransformerException {
|
||||
XMLBuilder rootBuilder = buildRoot(name);
|
||||
|
||||
rootBuilder.e("VAppTemplate").a("href", template);
|
||||
|
||||
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
|
||||
addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
|
||||
addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, network);
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
}
|
||||
|
||||
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, @Nullable String fenceMode,
|
||||
URI network) {
|
||||
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e("NetworkConfig")
|
||||
.a("name", name);
|
||||
if (fenceMode != null) {
|
||||
XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
|
||||
featuresBuilder.e("FenceMode").t(fenceMode);
|
||||
}
|
||||
networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns)
|
||||
.a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema)
|
||||
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
|
||||
return rootBuilder;
|
||||
}
|
||||
|
||||
private void addQuantity(InstantiateVAppTemplateOptions options, Map<ResourceType, String> virtualHardwareQuantity) {
|
||||
if (options.getCpuCount() != null) {
|
||||
virtualHardwareQuantity.put(ResourceType.PROCESSOR, options.getCpuCount());
|
||||
}
|
||||
if (options.getMemorySizeMegabytes() != null) {
|
||||
virtualHardwareQuantity.put(ResourceType.MEMORY, options.getMemorySizeMegabytes());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
|
||||
}
|
||||
|
||||
protected String ifNullDefaultTo(Object value, String defaultValue) {
|
||||
return value != null ? value.toString() : checkNotNull(defaultValue, "defaultValue");
|
||||
}
|
||||
|
||||
ThreadLocal<Map<String, String>> propLocal = new ThreadLocal<Map<String, String>>();
|
||||
|
||||
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) {
|
||||
InstantiateVAppTemplateOptions options = null;
|
||||
for (Object arg : gRequest.getInvocation().getArgs()) {
|
||||
if (arg instanceof InstantiateVAppTemplateOptions) {
|
||||
options = (InstantiateVAppTemplateOptions) arg;
|
||||
} else if (arg instanceof InstantiateVAppTemplateOptions[]) {
|
||||
InstantiateVAppTemplateOptions[] optionsA = (InstantiateVAppTemplateOptions[]) arg;
|
||||
options = (optionsA.length > 0) ? optionsA[0] : null;
|
||||
}
|
||||
}
|
||||
if (options != null)
|
||||
propLocal.set(options.getProperties());
|
||||
return options;
|
||||
}
|
||||
|
||||
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
|
||||
SortedMap<ResourceType, String> virtualHardwareQuantity) {
|
||||
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a("xmlns:q1", ns)
|
||||
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
|
||||
if (propLocal.get() != null) {
|
||||
for (Entry<String, String> entry : propLocal.get().entrySet()) {
|
||||
productSectionBuilder.e("Property").a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1")
|
||||
.a("ovf:key", entry.getKey()).a("ovf:value", entry.getValue());
|
||||
}
|
||||
propLocal.set(null);
|
||||
}
|
||||
if (virtualHardwareQuantity.size() > 0) {
|
||||
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e("VirtualHardwareSection").a(
|
||||
"xmlns:q1", ns);
|
||||
for (Entry<ResourceType, String> entry : virtualHardwareQuantity.entrySet()) {
|
||||
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns",
|
||||
"http://schemas.dmtf.org/ovf/envelope/1");
|
||||
itemBuilder.e("InstanceID")
|
||||
.a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
|
||||
.t(virtualHardwareToInstanceId.get(entry.getKey()));
|
||||
itemBuilder.e("ResourceType")
|
||||
.a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
|
||||
.t(entry.getKey().value());
|
||||
itemBuilder.e("VirtualQuantity")
|
||||
.a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
|
||||
.t(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindNodeConfigurationToXmlPayload implements MapBinder {
|
||||
|
||||
private final String ns;
|
||||
private final BindToStringPayload stringBinder;
|
||||
|
||||
@Inject
|
||||
BindNodeConfigurationToXmlPayload(@Named(PROPERTY_TERREMARK_EXTENSION_NS) String ns, BindToStringPayload stringBinder) {
|
||||
this.ns = ns;
|
||||
this.stringBinder = stringBinder;
|
||||
}
|
||||
|
||||
protected String generateXml(Map<String, Object> postParams) throws ParserConfigurationException,
|
||||
FactoryConfigurationError, TransformerException {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", ns).a("xmlns:xsi",
|
||||
"http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
|
||||
rootBuilder.e("Name").t(checkNotNull(postParams.get("name"), "name").toString());
|
||||
rootBuilder.e("Enabled").t(checkNotNull(postParams.get("enabled"), "enabled").toString());
|
||||
if (postParams.containsKey("description") && postParams.get("description") != null)
|
||||
rootBuilder.e("Description").t((String) postParams.get("description"));
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
try {
|
||||
return stringBinder.bindToRequest(request, generateXml(postParams));
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalArgumentException("this is a map binder");
|
||||
}
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.cim.CIMPredicates;
|
||||
import org.jclouds.cim.ResourceAllocationSettingData;
|
||||
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Status;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Inject;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Object, URI> {
|
||||
|
||||
private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
|
||||
|
||||
protected final String ns;
|
||||
protected final String schema;
|
||||
protected final BindToStringPayload stringBinder;
|
||||
protected final String apiVersion;
|
||||
|
||||
@Inject
|
||||
public BindVAppConfigurationToXmlPayload(@ApiVersion String apiVersion,
|
||||
BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
|
||||
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
|
||||
this.apiVersion = apiVersion;
|
||||
this.ns = ns;
|
||||
this.schema = schema;
|
||||
this.stringBinder = stringBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
|
||||
VApp vApp = checkNotNull(findVAppInArgsOrNull(gRequest), "vApp");
|
||||
checkArgument(vApp.getStatus() == Status.OFF, "vApp must be off!");
|
||||
VAppConfiguration configuration = checkNotNull(findConfigInArgsOrNull(gRequest), "config");
|
||||
|
||||
try {
|
||||
return stringBinder.bindToRequest(request, generateXml(vApp, configuration));
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FactoryConfigurationError e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (TransformerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String generateXml(VApp vApp, VAppConfiguration configuration)
|
||||
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
|
||||
String name = configuration.getName() != null ? configuration.getName() : vApp.getName();
|
||||
|
||||
XMLBuilder rootBuilder = buildRoot(vApp, name);
|
||||
|
||||
XMLBuilder sectionBuilder = rootBuilder.e("Section").a("xsi:type", "VirtualHardwareSection_Type").a("xmlns",
|
||||
"http://schemas.dmtf.org/ovf/envelope/1").a("xmlns:q2", "http://www.vmware.com/vcloud/v1");
|
||||
sectionBuilder.e("Info").t("Virtual Hardware");
|
||||
|
||||
addProcessorItem(sectionBuilder, vApp, configuration);
|
||||
addMemoryItem(sectionBuilder, vApp, configuration);
|
||||
addDiskItems(sectionBuilder, vApp, configuration);
|
||||
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
}
|
||||
|
||||
private void addProcessorItem(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
|
||||
ResourceAllocationSettingData cpu = find(vApp.getResourceAllocations(), CIMPredicates
|
||||
.resourceTypeIn(ResourceType.PROCESSOR));
|
||||
long quantity = configuration.getProcessorCount() != null ? configuration.getProcessorCount() : cpu
|
||||
.getVirtualQuantity();
|
||||
addResourceWithQuantity(sectionBuilder, cpu, quantity);
|
||||
}
|
||||
|
||||
private void addMemoryItem(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
|
||||
ResourceAllocationSettingData memory = find(vApp.getResourceAllocations(), CIMPredicates
|
||||
.resourceTypeIn(ResourceType.MEMORY));
|
||||
long quantity = configuration.getMemory() != null ? configuration.getMemory() : memory.getVirtualQuantity();
|
||||
addResourceWithQuantity(sectionBuilder, memory, quantity);
|
||||
}
|
||||
|
||||
private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
|
||||
for (ResourceAllocationSettingData disk : filter(vApp.getResourceAllocations(), CIMPredicates
|
||||
.resourceTypeIn(ResourceType.DISK_DRIVE))) {
|
||||
if (!configuration.getDisksToDelete().contains(Integer.valueOf(disk.getAddressOnParent()))) {
|
||||
addDiskWithQuantity(sectionBuilder, disk);
|
||||
}
|
||||
}
|
||||
for (Long quantity : configuration.getDisks()) {
|
||||
ResourceAllocationSettingData disk = ResourceAllocationSettingData.builder().instanceID("9").addressOnParent(
|
||||
"-1").elementName("").resourceType(ResourceType.DISK_DRIVE).virtualQuantity(quantity).build();
|
||||
addDiskWithQuantity(sectionBuilder, disk);
|
||||
}
|
||||
}
|
||||
|
||||
private XMLBuilder addResourceWithQuantity(XMLBuilder sectionBuilder, ResourceAllocationSettingData resource,
|
||||
long quantity) {
|
||||
XMLBuilder itemBuilder = sectionBuilder.e("Item");
|
||||
addCommonElements(itemBuilder, resource, quantity);
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
private void addCommonElements(XMLBuilder itemBuilder, ResourceAllocationSettingData resource, long quantity) {
|
||||
itemBuilder.e("InstanceID").a("xmlns", RESOURCE_ALLOCATION_NS).t(resource.getInstanceID() + "");
|
||||
itemBuilder.e("ResourceType").a("xmlns", RESOURCE_ALLOCATION_NS).t(resource.getResourceType().value());
|
||||
itemBuilder.e("VirtualQuantity").a("xmlns", RESOURCE_ALLOCATION_NS).t(quantity + "");
|
||||
}
|
||||
|
||||
private XMLBuilder addDiskWithQuantity(XMLBuilder sectionBuilder, ResourceAllocationSettingData disk) {
|
||||
XMLBuilder itemBuilder = sectionBuilder.e("Item");
|
||||
itemBuilder.e("AddressOnParent").a("xmlns", RESOURCE_ALLOCATION_NS).t(disk.getAddressOnParent() + "");
|
||||
for (String hostResource : disk.getHostResources())
|
||||
itemBuilder.e("HostResource").a("xmlns", RESOURCE_ALLOCATION_NS).t(hostResource);
|
||||
addCommonElements(itemBuilder, disk, disk.getVirtualQuantity());
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRoot(VApp vApp, String name) throws ParserConfigurationException,
|
||||
FactoryConfigurationError {
|
||||
String status = vApp.getStatus().value();
|
||||
if (apiVersion.indexOf("0.8") != -1 && "8".equals(status))
|
||||
status = "2";
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("VApp").a("type", vApp.getType()).a("name", name).a("status", status)
|
||||
.a("size", vApp.getSize() + "").a("xmlns", ns).a("xmlns:xsi",
|
||||
"http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
|
||||
return rootBuilder;
|
||||
}
|
||||
|
||||
protected VApp findVAppInArgsOrNull(GeneratedHttpRequest gRequest) {
|
||||
for (Object arg : gRequest.getInvocation().getArgs()) {
|
||||
if (arg instanceof VApp) {
|
||||
return (VApp) arg;
|
||||
} else if (arg instanceof VApp[]) {
|
||||
VApp[] vapps = (VApp[]) arg;
|
||||
return (vapps.length > 0) ? vapps[0] : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected VAppConfiguration findConfigInArgsOrNull(GeneratedHttpRequest gRequest) {
|
||||
for (Object arg : gRequest.getInvocation().getArgs()) {
|
||||
if (arg instanceof VAppConfiguration) {
|
||||
return (VAppConfiguration) arg;
|
||||
} else if (arg instanceof VAppConfiguration[]) {
|
||||
VAppConfiguration[] configuration = (VAppConfiguration[]) arg;
|
||||
return (configuration.length > 0) ? configuration[0] : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException("BindVAppConfigurationToXmlPayload needs parameters");
|
||||
}
|
||||
|
||||
protected String ifNullDefaultTo(String value, String defaultValue) {
|
||||
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI apply(Object from) {
|
||||
return VApp.class.cast(checkNotNull(from, "from")).getHref();
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
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.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Catalog;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameAndCatalogNameToEndpoint implements MapBinder {
|
||||
private final Supplier<Map<String, ? extends Org>> orgMap;
|
||||
private final Supplier<ReferenceType> defaultOrg;
|
||||
private final Supplier<ReferenceType> defaultCatalog;
|
||||
|
||||
@Inject
|
||||
public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg, @Catalog Supplier<ReferenceType> defaultCatalog) {
|
||||
this.orgMap = orgMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultCatalog = defaultCatalog;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
Object org = postParams.get("orgName");
|
||||
Object catalog = postParams.get("catalogName");
|
||||
if (org == null && catalog == null)
|
||||
return (R) request.toBuilder().endpoint(defaultCatalog.get().getHref()).build();
|
||||
else if (org == null)
|
||||
org = defaultOrg.get().getName();
|
||||
|
||||
try {
|
||||
Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
|
||||
URI endpoint = catalog == null ? Iterables.getLast(catalogs.values()).getHref() : catalogs.get(catalog).getHref();
|
||||
return (R) request.toBuilder().endpoint(endpoint).build();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException(getClass() + " needs parameters");
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
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.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.TasksList;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameAndTasksListNameToEndpoint implements MapBinder {
|
||||
private final Supplier<Map<String, ? extends Org>> orgMap;
|
||||
private final Supplier<ReferenceType> defaultOrg;
|
||||
private final Supplier<ReferenceType> defaultTasksList;
|
||||
|
||||
@Inject
|
||||
public OrgNameAndTasksListNameToEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg, @TasksList Supplier<ReferenceType> defaultTasksList) {
|
||||
this.orgMap = orgMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultTasksList = defaultTasksList;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
Object org = postParams.get("orgName");
|
||||
Object tasksList = postParams.get("tasksListName");
|
||||
if (org == null && tasksList == null)
|
||||
return (R) request.toBuilder().endpoint(defaultTasksList.get().getHref()).build();
|
||||
else if (org == null)
|
||||
org = defaultOrg.get().getName();
|
||||
|
||||
try {
|
||||
Map<String, ReferenceType> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists();
|
||||
URI endpoint = tasksList == null ? Iterables.getLast(tasksLists.values()).getHref() : tasksLists.get(tasksList).getHref();
|
||||
return (R) request.toBuilder().endpoint(endpoint).build();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSuchElementException(org + "/" + tasksList + " not found in " + orgMap.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException(getClass() + " needs parameters");
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
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.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.VDC;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameAndVDCNameToEndpoint implements MapBinder {
|
||||
private final Supplier<Map<String, ? extends Org>> orgNameToVDCEndpoint;
|
||||
private final Supplier<ReferenceType> defaultOrg;
|
||||
private final Supplier<ReferenceType> defaultVDC;
|
||||
|
||||
@Inject
|
||||
public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, ? extends Org>> orgNameToVDCEndpoint,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
|
||||
this.orgNameToVDCEndpoint = orgNameToVDCEndpoint;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultVDC = defaultVDC;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
Object org = postParams.get("orgName");
|
||||
Object vdc = postParams.get("vdcName");
|
||||
if (org == null && vdc == null)
|
||||
return (R) request.toBuilder().endpoint(defaultVDC.get().getHref()).build();
|
||||
else if (org == null)
|
||||
org = defaultOrg.get().getName();
|
||||
|
||||
try {
|
||||
Map<String, ReferenceType> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();
|
||||
URI endpoint = vdc == null ? Iterables.getLast(vdcs.values()).getHref() : vdcs.get(vdc).getHref();
|
||||
return (R) request.toBuilder().endpoint(endpoint).build();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVDCEndpoint.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException(getClass() + " needs parameters");
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameCatalogNameItemNameToEndpoint implements MapBinder {
|
||||
private final Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> orgCatalogMap;
|
||||
private final Supplier<ReferenceType> defaultOrg;
|
||||
private final Supplier<ReferenceType> defaultCatalog;
|
||||
|
||||
@Inject
|
||||
public OrgNameCatalogNameItemNameToEndpoint(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> orgCatalogMap,
|
||||
@Org Supplier<ReferenceType> defaultOrg, @Catalog Supplier<ReferenceType> defaultCatalog) {
|
||||
this.orgCatalogMap = orgCatalogMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultCatalog = defaultCatalog;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
Object org = postParams.get("orgName");
|
||||
Object catalog = postParams.get("catalogName");
|
||||
Object catalogItem = postParams.get("itemName");
|
||||
if (org == null)
|
||||
org = defaultOrg.get().getName();
|
||||
if (catalog == null)
|
||||
catalog = defaultCatalog.get().getName();
|
||||
try {
|
||||
Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
|
||||
return (R) request.toBuilder().endpoint(catalogs.get(catalog).get(catalogItem).getHref()).build();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in "
|
||||
+ orgCatalogMap.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException(getClass() + " needs parameters");
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
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.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements MapBinder {
|
||||
private final Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>> orgCatalogItemMap;
|
||||
private final Supplier<ReferenceType> defaultOrg;
|
||||
private final Supplier<ReferenceType> defaultCatalog;
|
||||
|
||||
@Inject
|
||||
public OrgNameCatalogNameVAppTemplateNameToEndpoint(
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>> orgCatalogItemMap,
|
||||
@Org Supplier<ReferenceType> defaultOrg, @Catalog Supplier<ReferenceType> defaultCatalog) {
|
||||
this.orgCatalogItemMap = orgCatalogItemMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultCatalog = defaultCatalog;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
Object org = postParams.get("orgName");
|
||||
Object catalog = postParams.get("catalogName");
|
||||
Object catalogItem = postParams.get("itemName");
|
||||
if (org == null)
|
||||
org = defaultOrg.get().getName();
|
||||
if (catalog == null)
|
||||
catalog = defaultCatalog.get().getName();
|
||||
Map<String, Map<String, Map<String, ? extends CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get();
|
||||
|
||||
if (!orgCatalogItemMap.containsKey(org))
|
||||
throw new NoSuchElementException("org: " + org + " not found in " + orgCatalogItemMap.keySet());
|
||||
Map<String, Map<String, ? extends CatalogItem>> catalogs = orgCatalogItemMap.get(org);
|
||||
|
||||
if (!catalogs.containsKey(catalog))
|
||||
throw new NoSuchElementException("catalog: " + org + "/" + catalog + " not found in " + catalogs.keySet());
|
||||
Map<String, ? extends CatalogItem> catalogMap = catalogs.get(catalog);
|
||||
|
||||
if (!catalogMap.containsKey(catalogItem))
|
||||
throw new NoSuchElementException("item: " + org + "/" + catalog + "/" + catalogItem + " not found in "
|
||||
+ catalogMap.keySet());
|
||||
CatalogItem item = catalogMap.get(catalogItem);
|
||||
|
||||
URI endpoint = checkNotNull(item.getEntity(),
|
||||
"item: " + org + "/" + catalog + "/" + catalogItem + " has no entity").getHref();
|
||||
return (R) request.toBuilder().endpoint(endpoint).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException(getClass() + " needs parameters");
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.VDC;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameVDCNameNetworkNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
|
||||
@Inject
|
||||
public OrgNameVDCNameNetworkNameToEndpoint(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap,
|
||||
@Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
|
||||
super(orgVDCMap, defaultOrg, defaultVDC);
|
||||
}
|
||||
|
||||
protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
|
||||
org.jclouds.trmk.vcloud_0_8.domain.VDC vDCObject) {
|
||||
ReferenceType resourceEntity = vDCObject.getAvailableNetworks().get(resource);
|
||||
if (resourceEntity == null)
|
||||
throw new NoSuchElementException("network " + resource + " in vdc " + vDC + ", org " + org + " not found in "
|
||||
+ vDCObject.getAvailableNetworks().keySet());
|
||||
return resourceEntity.getHref();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.VDC;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class OrgNameVDCNameResourceEntityNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
|
||||
@Inject
|
||||
public OrgNameVDCNameResourceEntityNameToEndpoint(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap,
|
||||
@Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
|
||||
super(orgVDCMap, defaultOrg, defaultVDC);
|
||||
}
|
||||
|
||||
protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
|
||||
org.jclouds.trmk.vcloud_0_8.domain.VDC vDCObject) {
|
||||
ReferenceType resourceEntity = vDCObject.getResourceEntities().get(resource);
|
||||
if (resourceEntity == null)
|
||||
throw new NoSuchElementException("entity " + resource + " in vdc " + vDC + ", org " + org + " not found in "
|
||||
+ vDCObject.getResourceEntities().keySet());
|
||||
return resourceEntity.getHref();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class OrgNameVDCNameResourceNameToEndpoint implements MapBinder {
|
||||
|
||||
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap;
|
||||
protected final Supplier<ReferenceType> defaultOrg;
|
||||
protected final Supplier<ReferenceType> defaultVDC;
|
||||
|
||||
@Inject
|
||||
public OrgNameVDCNameResourceNameToEndpoint(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap,
|
||||
@Org Supplier<ReferenceType> defaultOrg, @org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
|
||||
this.orgVDCMap = orgVDCMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultVDC = defaultVDC;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
Object org = postParams.get("orgName");
|
||||
Object vDC = postParams.get("vdcName");
|
||||
Object resource = postParams.get("resourceName");
|
||||
if (org == null)
|
||||
org = defaultOrg.get().getName();
|
||||
if (vDC == null)
|
||||
vDC = defaultVDC.get().getName();
|
||||
Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgToVDCs = orgVDCMap.get();
|
||||
checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
|
||||
Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> vDCs = orgToVDCs.get(org);
|
||||
if (vDCs == null)
|
||||
throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
|
||||
org.jclouds.trmk.vcloud_0_8.domain.VDC vDCObject = vDCs.get(vDC);
|
||||
if (vDCObject == null)
|
||||
throw new NoSuchElementException("vdc " + vDC + " in org " + org + " not found in " + vDCs.keySet());
|
||||
URI endpoint = getEndpointOfResourceInVDC(org, vDC, resource, vDCObject);
|
||||
return (R) request.toBuilder().endpoint(endpoint).build();
|
||||
}
|
||||
|
||||
protected abstract URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource, VDC vDCObject);
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
throw new IllegalStateException(getClass() + " needs parameters");
|
||||
}
|
||||
}
|
|
@ -1,393 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.getLast;
|
||||
import static org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions.Builder.withDescription;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.InternetService;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Node;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Protocol;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.PublicIpAddress;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Status;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Task;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.TaskStatus;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.TasksList;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.InternetServiceAndPublicIpAddressSupplier;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkVCloudComputeClient {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final TerremarkVCloudApi client;
|
||||
protected final Provider<String> passwordGenerator;
|
||||
protected final InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier;
|
||||
protected final Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus;
|
||||
protected final Predicate<URI> taskTester;
|
||||
|
||||
@Inject
|
||||
protected TerremarkVCloudComputeClient(TerremarkVCloudApi client,
|
||||
@Named("PASSWORD") Provider<String> passwordGenerator, Predicate<URI> successTester,
|
||||
Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus, Map<String, Credentials> credentialStore,
|
||||
InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier) {
|
||||
this.client = client;
|
||||
this.passwordGenerator = passwordGenerator;
|
||||
this.internetServiceAndPublicIpAddressSupplier = internetServiceAndPublicIpAddressSupplier;
|
||||
this.vAppStatusToNodeStatus = vAppStatusToNodeStatus;
|
||||
this.taskTester = successTester;
|
||||
}
|
||||
|
||||
protected Status getStatus(VApp vApp) {
|
||||
return vApp.getStatus();
|
||||
}
|
||||
|
||||
public ComputeServiceAdapter.NodeAndInitialCredentials<VApp> startAndReturnCredentials(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
|
||||
int... portsToOpen) {
|
||||
// we only get IP addresses after "deploy"
|
||||
if (portsToOpen.length > 0 && !options.shouldBlock())
|
||||
throw new IllegalArgumentException("We cannot open ports on terremark unless we can deploy the vapp");
|
||||
String password = null;
|
||||
VAppTemplate template = client.getVAppTemplate(templateId);
|
||||
if (template.getDescription().indexOf("Windows") != -1) {
|
||||
password = passwordGenerator.get();
|
||||
options.getProperties().put("password", password);
|
||||
}
|
||||
checkNotNull(options, "options");
|
||||
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
|
||||
|
||||
VApp vAppResponse = client.instantiateVAppTemplateInVDC(VDC, templateId, name, options);
|
||||
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
|
||||
if (options.shouldDeploy()) {
|
||||
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
|
||||
|
||||
Task task = client.deployVApp(vAppResponse.getHref());
|
||||
if (options.shouldBlock()) {
|
||||
if (!taskTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
|
||||
}
|
||||
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
|
||||
if (options.shouldPowerOn()) {
|
||||
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
|
||||
task = client.powerOnVApp(vAppResponse.getHref());
|
||||
if (!taskTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(),
|
||||
task));
|
||||
}
|
||||
logger.debug("<< on vApp(%s)", vAppResponse.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (portsToOpen.length > 0)
|
||||
createPublicAddressMappedToPorts(vAppResponse.getHref(), portsToOpen);
|
||||
return new ComputeServiceAdapter.NodeAndInitialCredentials<VApp>(vAppResponse, vAppResponse.getHref().toASCIIString(), password!= null?LoginCredentials.builder().password(password).build():null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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/>
|
||||
* This command blocks until the vApp is in state {@code VAppStatus#ON}
|
||||
*
|
||||
* @param VDC
|
||||
* id of the virtual datacenter {@code VCloudClient#getDefaultVDC}
|
||||
* @param templateId
|
||||
* id of the vAppTemplate you wish to instantiate
|
||||
* @param name
|
||||
* name of the vApp
|
||||
* @param cores
|
||||
* amount of virtual cpu cores
|
||||
* @param megs
|
||||
* amount of ram in megabytes
|
||||
* @param options
|
||||
* options for instantiating the vApp; null is ok
|
||||
* @param portsToOpen
|
||||
* 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>
|
||||
* </ol>
|
||||
*/
|
||||
public VApp start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
|
||||
int... portsToOpen) {
|
||||
return startAndReturnCredentials(VDC, templateId, name, options, portsToOpen).getNode();
|
||||
}
|
||||
|
||||
public String createPublicAddressMappedToPorts(URI vAppId, int... ports) {
|
||||
VApp vApp = client.getVApp(vAppId);
|
||||
PublicIpAddress ip = null;
|
||||
String privateAddress = getLast(vApp.getNetworkToAddresses().values());
|
||||
for (int port : ports) {
|
||||
InternetService is = null;
|
||||
Protocol protocol;
|
||||
switch (port) {
|
||||
case 22:
|
||||
protocol = Protocol.TCP;
|
||||
break;
|
||||
case 80:
|
||||
case 8080:
|
||||
protocol = Protocol.HTTP;
|
||||
break;
|
||||
case 443:
|
||||
protocol = Protocol.HTTPS;
|
||||
break;
|
||||
default:
|
||||
protocol = Protocol.HTTP;
|
||||
break;
|
||||
}
|
||||
if (ip == null) {
|
||||
|
||||
Entry<InternetService, PublicIpAddress> entry = internetServiceAndPublicIpAddressSupplier
|
||||
.getNewInternetServiceAndIp(vApp, port, protocol);
|
||||
is = entry.getKey();
|
||||
ip = entry.getValue();
|
||||
|
||||
} 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())));
|
||||
}
|
||||
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getName(), is.getPublicIpAddress().getAddress(),
|
||||
is.getProtocol(), is.getPort());
|
||||
logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress(), is.getPort(),
|
||||
privateAddress, port);
|
||||
Node node = client.addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port);
|
||||
logger.debug("<< added Node(%s)", node.getName());
|
||||
}
|
||||
return ip != null ? ip.getAddress() : null;
|
||||
}
|
||||
|
||||
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) {
|
||||
checkNotNull(vApp.getVDC(), "VDC reference missing for vApp(%s)", vApp.getName());
|
||||
Set<PublicIpAddress> ipAddresses = Sets.newHashSet();
|
||||
SERVICE: for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC().getHref())) {
|
||||
for (Node node : client.getNodes(service.getId())) {
|
||||
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
|
||||
ipAddresses.add(service.getPublicIpAddress());
|
||||
logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getName(), service.getPublicIpAddress()
|
||||
.getAddress(), service.getPort(), node.getIpAddress(), node.getPort());
|
||||
client.deleteNode(node.getId());
|
||||
logger.debug("<< deleted Node(%s)", node.getName());
|
||||
Set<Node> nodes = client.getNodes(service.getId());
|
||||
if (nodes.size() == 0) {
|
||||
logger.debug(">> deleting InternetService(%s) %s:%d", service.getName(), service.getPublicIpAddress()
|
||||
.getAddress(), service.getPort());
|
||||
client.deleteInternetService(service.getId());
|
||||
logger.debug("<< deleted InternetService(%s)", service.getName());
|
||||
continue SERVICE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ipAddresses;
|
||||
}
|
||||
|
||||
private void deletePublicIpAddressesWithNoServicesAttached(Set<PublicIpAddress> ipAddresses) {
|
||||
IPADDRESS: for (PublicIpAddress address : ipAddresses) {
|
||||
Set<InternetService> services = client.getInternetServicesOnPublicIp(address.getId());
|
||||
if (services.size() == 0) {
|
||||
logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address.getAddress());
|
||||
try {
|
||||
client.deletePublicIp(address.getId());
|
||||
logger.debug("<< deleted PublicIpAddress(%s)", address.getId());
|
||||
} catch (Exception e) {
|
||||
logger.trace("cannot delete PublicIpAddress(%s) as it is unsupported", address.getId());
|
||||
}
|
||||
continue IPADDRESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys dependent resources, powers off and deletes the vApp, blocking
|
||||
* until the following state transition is complete:
|
||||
* <p/>
|
||||
* current -> {@code VAppStatus#OFF} -> deleted
|
||||
* <p/>
|
||||
* * 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.
|
||||
*
|
||||
* @param vAppId
|
||||
* vApp to stop
|
||||
*/
|
||||
public void stop(URI id) {
|
||||
VApp vApp = client.getVApp(id);
|
||||
if (vApp == null)
|
||||
return;
|
||||
Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp);
|
||||
deletePublicIpAddressesWithNoServicesAttached(ipAddresses);
|
||||
if (vApp.getStatus() != Status.OFF) {
|
||||
try {
|
||||
powerOffAndWait(vApp);
|
||||
} catch (IllegalStateException e) {
|
||||
logger.warn("<< %s vApp(%s)", e.getMessage(), vApp.getName());
|
||||
blockOnLastTask(vApp);
|
||||
powerOffAndWait(vApp);
|
||||
}
|
||||
vApp = client.getVApp(id);
|
||||
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
|
||||
}
|
||||
logger.debug(">> deleting vApp(%s)", vApp.getName());
|
||||
client.deleteVApp(id);
|
||||
logger.debug("<< deleted vApp(%s))", vApp.getName());
|
||||
}
|
||||
|
||||
private void powerOffAndWait(VApp vApp) {
|
||||
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
|
||||
Task task = client.powerOffVApp(vApp.getHref());
|
||||
if (!taskTester.apply(task.getHref()))
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
|
||||
}
|
||||
|
||||
void blockOnLastTask(VApp vApp) {
|
||||
TasksList list = client.findTasksListInOrgNamed(null, null);
|
||||
try {
|
||||
Task lastTask = getLast(filter(list.getTasks(), new Predicate<Task>() {
|
||||
|
||||
public boolean apply(Task input) {
|
||||
return input.getStatus() == TaskStatus.QUEUED || input.getStatus() == TaskStatus.RUNNING;
|
||||
}
|
||||
|
||||
}));
|
||||
if (!taskTester.apply(lastTask.getHref()))
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), lastTask));
|
||||
} catch (NoSuchElementException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a set of addresses that are only visible to the private network.
|
||||
*
|
||||
* @returns empty set if the node is not found
|
||||
*/
|
||||
public Set<String> getPrivateAddresses(URI id) {
|
||||
VApp vApp = client.getVApp(id);
|
||||
if (vApp != null)
|
||||
return Sets.newHashSet(vApp.getNetworkToAddresses().values());
|
||||
else
|
||||
return ImmutableSet.<String> of();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a set of addresses that are publically visible
|
||||
*
|
||||
* @returns empty set if the node is not found
|
||||
*/
|
||||
public Set<String> getPublicAddresses(URI id) {
|
||||
VApp vApp = client.getVApp(id);
|
||||
if (vApp != null) {
|
||||
Set<String> ipAddresses = Sets.newHashSet();
|
||||
for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC().getHref())) {
|
||||
for (Node node : client.getNodes(service.getId())) {
|
||||
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
|
||||
ipAddresses.add(service.getPublicIpAddress().getAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ipAddresses;
|
||||
} else {
|
||||
return ImmutableSet.<String> of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reboots the vApp, blocking until the following state transition is
|
||||
* complete:
|
||||
* <p/>
|
||||
* current -> {@code VAppStatus#OFF} -> {@code VAppStatus#ON}
|
||||
*
|
||||
* @param vAppId
|
||||
* vApp to reboot
|
||||
*/
|
||||
public void reset(URI id) {
|
||||
VApp vApp = refreshVApp(id);
|
||||
logger.debug(">> resetting vApp(%s)", vApp.getName());
|
||||
Task task = reset(vApp);
|
||||
if (!taskTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "resetVApp", vApp.getName(), task));
|
||||
}
|
||||
logger.debug("<< on vApp(%s)", vApp.getName());
|
||||
}
|
||||
|
||||
protected void deleteVApp(VApp vApp) {
|
||||
logger.debug(">> deleting vApp(%s)", vApp.getName());
|
||||
Task task = client.deleteVApp(vApp.getHref());
|
||||
if (task != null)
|
||||
if (!taskTester.apply(task.getHref()))
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "delete", vApp.getName(), task));
|
||||
}
|
||||
|
||||
protected VApp refreshVApp(URI id) {
|
||||
return client.getVApp(id);
|
||||
}
|
||||
|
||||
protected Task powerOff(VApp vApp) {
|
||||
return client.powerOffVApp(vApp.getHref());
|
||||
}
|
||||
|
||||
protected Task reset(VApp vApp) {
|
||||
return client.resetVApp(vApp.getHref());
|
||||
}
|
||||
|
||||
protected Task undeploy(VApp vApp) {
|
||||
return client.undeployVApp(vApp.getHref());
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute;
|
||||
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.callables.RunScriptOnNode;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.extensions.ImageExtension;
|
||||
import org.jclouds.compute.extensions.SecurityGroupExtension;
|
||||
import org.jclouds.compute.internal.BaseComputeService;
|
||||
import org.jclouds.compute.internal.PersistNodeCredentials;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.scriptbuilder.functions.InitAdminAccess;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.CleanupOrphanKeys;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkVCloudComputeService extends BaseComputeService {
|
||||
private final CleanupOrphanKeys cleanupOrphanKeys;
|
||||
|
||||
@Inject
|
||||
protected TerremarkVCloudComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
|
||||
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||
@Named("DEFAULT") Provider<TemplateOptions> templateOptionsProvider,
|
||||
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
||||
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
||||
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
||||
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, CleanupOrphanKeys cleanupOrphanKeys,
|
||||
Optional<ImageExtension> imageExtension, Optional<SecurityGroupExtension> securityGroupExtension) {
|
||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
|
||||
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
||||
resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
|
||||
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
|
||||
persistNodeCredentials, timeouts, userExecutor, imageExtension, securityGroupExtension);
|
||||
this.cleanupOrphanKeys = cleanupOrphanKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans implicit keypairs.
|
||||
*/
|
||||
@Override
|
||||
protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) {
|
||||
cleanupOrphanKeys.execute(deadNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns template options, except of type
|
||||
* {@link TerremarkVCloudTemplateOptions}.
|
||||
*/
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions templateOptions() {
|
||||
return TerremarkVCloudTemplateOptions.class.cast(super.templateOptions());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.config;
|
||||
|
||||
import org.jclouds.compute.config.BindComputeStrategiesByClass;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.StartVAppWithGroupEncodedIntoName;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudDestroyNodeStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudGetImageStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudGetNodeMetadataStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudLifeCycleStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudListNodesStrategy;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
|
||||
|
||||
@Override
|
||||
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||
return TerremarkVCloudDestroyNodeStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||
return TerremarkVCloudGetNodeMetadataStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends GetImageStrategy> defineGetImageStrategy() {
|
||||
return TerremarkVCloudGetImageStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||
return TerremarkVCloudListNodesStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||
return TerremarkVCloudLifeCycleStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ResumeNodeStrategy> defineStartNodeStrategy() {
|
||||
return TerremarkVCloudLifeCycleStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends SuspendNodeStrategy> defineStopNodeStrategy() {
|
||||
return TerremarkVCloudLifeCycleStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
|
||||
return TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
|
||||
return StartVAppWithGroupEncodedIntoName.class;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.config;
|
||||
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.config.BindComputeSuppliersByClass;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.suppliers.StaticHardwareSupplier;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.suppliers.VAppTemplatesInOrgs;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkBindComputeSuppliersByClass extends BindComputeSuppliersByClass {
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||
return StaticHardwareSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||
return VAppTemplatesInOrgs.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.config;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeService;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.ImageForVCloudExpressVAppTemplate;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.ImagesInVCloudExpressOrg;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.NodeMetadataToOrgAndName;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.ParseOsFromVAppTemplateName;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.VAppToNodeMetadata;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Status;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Configures the {@link TerremarkVCloudComputeServiceContext}; requires
|
||||
* {@link TerremarkVCloudComputeClientImpl} bound.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkVCloudComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||
|
||||
@VisibleForTesting
|
||||
public static final Map<Status, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
|
||||
.<Status, NodeMetadata.Status> builder()
|
||||
.put(Status.OFF, NodeMetadata.Status.SUSPENDED)
|
||||
.put(Status.ON, NodeMetadata.Status.RUNNING)
|
||||
.put(Status.RESOLVED, NodeMetadata.Status.PENDING)
|
||||
.put(Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED)
|
||||
.put(Status.DEPLOYED, NodeMetadata.Status.PENDING)
|
||||
.put(Status.SUSPENDED, NodeMetadata.Status.SUSPENDED)
|
||||
.put(Status.UNRESOLVED, NodeMetadata.Status.PENDING).build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
protected Map<Status, NodeMetadata.Status> toPortableNodeStatus() {
|
||||
return toPortableNodeStatus;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static final Map<Status, Image.Status> toPortableImageStatus = ImmutableMap
|
||||
.<Status, Image.Status> builder()
|
||||
.put(Status.RESOLVED, Image.Status.AVAILABLE)
|
||||
.put(Status.OFF, Image.Status.AVAILABLE)
|
||||
.put(Status.UNRECOGNIZED, Image.Status.UNRECOGNIZED)
|
||||
.put(Status.DEPLOYED, Image.Status.PENDING)
|
||||
.put(Status.UNRESOLVED, Image.Status.PENDING).build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
protected Map<Status, Image.Status> toPortableImageStatus() {
|
||||
return toPortableImageStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<Function<NodeMetadata, OrgAndName>>() {
|
||||
}).to(new TypeLiteral<NodeMetadataToOrgAndName>() {
|
||||
});
|
||||
bind(TemplateOptions.class).to(TerremarkVCloudTemplateOptions.class);
|
||||
bind(ComputeService.class).to(TerremarkVCloudComputeService.class);
|
||||
bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(
|
||||
ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.class);
|
||||
bind(SecureRandom.class).toInstance(new SecureRandom());
|
||||
install(new TerremarkBindComputeStrategiesByClass());
|
||||
install(new TerremarkBindComputeSuppliersByClass());
|
||||
bind(new TypeLiteral<Function<VApp, NodeMetadata>>() {
|
||||
}).to(VAppToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<VAppTemplate, Image>>() {
|
||||
}).to(ImageForVCloudExpressVAppTemplate.class);
|
||||
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
|
||||
}).to(new TypeLiteral<ImagesInVCloudExpressOrg>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<String, OperatingSystem>>() {
|
||||
}).to(ParseOsFromVAppTemplateName.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Supplier<String> provideSuffix(final SecureRandom random) {
|
||||
return new Supplier<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
return random.nextInt(4096) + "";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Named("PASSWORD")
|
||||
@Provides
|
||||
String providePassword(SecureRandom random) {
|
||||
return random.nextLong() + "";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class OrgAndName {
|
||||
protected final URI org;
|
||||
protected final String name;
|
||||
|
||||
public OrgAndName(URI org, String name) {
|
||||
this.org = org;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((org == null) ? 0 : org.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.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;
|
||||
OrgAndName other = (OrgAndName) obj;
|
||||
if (org == null) {
|
||||
if (other.org != null)
|
||||
return false;
|
||||
} else if (!org.equals(other.org))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public URI getOrg() {
|
||||
return org;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OrgTag [org=" + org + ", name=" + name + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
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.http.HttpResponseException;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.KeyPair;
|
||||
import org.jclouds.util.Throwables2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class CreateUniqueKeyPair implements Function<OrgAndName, KeyPair> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
protected final TerremarkVCloudApi trmkClient;
|
||||
protected Supplier<String> randomSuffix;
|
||||
|
||||
@Inject
|
||||
CreateUniqueKeyPair(TerremarkVCloudApi trmkClient, Supplier<String> randomSuffix) {
|
||||
this.trmkClient = trmkClient;
|
||||
this.randomSuffix = randomSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyPair apply(OrgAndName from) {
|
||||
return createNewKeyPairInOrg(from.getOrg(), from.getName());
|
||||
}
|
||||
|
||||
private KeyPair createNewKeyPairInOrg(URI org, String keyPairName) {
|
||||
checkNotNull(org, "org");
|
||||
checkNotNull(keyPairName, "keyPairName");
|
||||
logger.debug(">> creating keyPair org(%s) name(%s)", org, keyPairName);
|
||||
KeyPair keyPair = null;
|
||||
while (keyPair == null) {
|
||||
try {
|
||||
keyPair = trmkClient.generateKeyPairInOrg(org, getNextName(keyPairName), false);
|
||||
logger.debug("<< created keyPair(%s)", keyPair.getName());
|
||||
} catch (RuntimeException e) {
|
||||
HttpResponseException ht = Throwables2.getFirstThrowableOfType(e, HttpResponseException.class);
|
||||
if (ht == null || ht.getContent() == null
|
||||
|| ht.getContent().indexOf("Security key with same name exists") == -1)
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return keyPair;
|
||||
}
|
||||
|
||||
private String getNextName(String keyPairName) {
|
||||
return "jclouds_" + keyPairName.replaceAll("-", "_") + "_" + randomSuffix.get();
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class FindLocationForResource implements Function<ReferenceType, Location> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
final Supplier<Set<? extends Location>> locations;
|
||||
|
||||
@Inject
|
||||
public FindLocationForResource(@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* searches for a location associated with this resource.
|
||||
*
|
||||
* @throws NoSuchElementException
|
||||
* if not found
|
||||
*/
|
||||
public Location apply(ReferenceType resource) {
|
||||
for (Location input : locations.get()) {
|
||||
do {
|
||||
// The "name" isn't always present, ex inside a vApp we have a rel
|
||||
// link that only includes href and type.
|
||||
if (URI.create(input.getId()).equals(resource.getHref()))
|
||||
return input;
|
||||
} while ((input = input.getParent()) != null);
|
||||
}
|
||||
throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource,
|
||||
locations.get()));
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.cim.functions.HardwareBuilderFromResourceAllocations;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.predicates.ImagePredicates;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class HardwareForVCloudExpressVApp implements Function<VApp, Hardware> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Function<ReferenceType, Location> findLocationForResource;
|
||||
private final HardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
|
||||
|
||||
@Inject
|
||||
protected HardwareForVCloudExpressVApp(Function<ReferenceType, Location> findLocationForResource,
|
||||
HardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
|
||||
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
|
||||
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hardware apply(VApp from) {
|
||||
checkNotNull(from, "VApp");
|
||||
try {
|
||||
HardwareBuilder builder = rasdToHardwareBuilder.apply(from.getResourceAllocations());
|
||||
builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
|
||||
builder.ids(from.getHref().toASCIIString()).name(from.getName())
|
||||
.supportsImage(ImagePredicates.idEquals(from.getHref().toASCIIString()));
|
||||
builder.hypervisor("VMware");
|
||||
return builder.build();
|
||||
} catch (NoSuchElementException e) {
|
||||
logger.debug("incomplete data to form vApp %s", from.getHref());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Status;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ImageForVCloudExpressVAppTemplate implements Function<VAppTemplate, Image> {
|
||||
private final Map<Status, org.jclouds.compute.domain.Image.Status> toPortableImageStatus;
|
||||
private final FindLocationForResource findLocationForResource;
|
||||
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
|
||||
private final Function<String, OperatingSystem> osParser;
|
||||
|
||||
private ReferenceType parent;
|
||||
|
||||
@Inject
|
||||
protected ImageForVCloudExpressVAppTemplate(Map<Status, Image.Status> toPortableImageStatus, FindLocationForResource findLocationForResource,
|
||||
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, Function<String, OperatingSystem> osParser) {
|
||||
this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus");
|
||||
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
|
||||
this.credentialsProvider = checkNotNull(credentialsProvider, "credentialsProvider");
|
||||
this.osParser = osParser;
|
||||
}
|
||||
|
||||
public ImageForVCloudExpressVAppTemplate withParent(ReferenceType parent) {
|
||||
this.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image apply(@Nullable VAppTemplate from) {
|
||||
if (from == null)
|
||||
return null;
|
||||
ImageBuilder builder = new ImageBuilder();
|
||||
builder.ids(from.getHref().toASCIIString());
|
||||
builder.uri(from.getHref());
|
||||
builder.name(from.getName());
|
||||
builder.location(findLocationForResource.apply(checkNotNull(parent, "parent")));
|
||||
builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
|
||||
builder.operatingSystem(osParser.apply(from.getName()));
|
||||
builder.status(toPortableImageStatus.get(from.getStatus()));
|
||||
builder.defaultCredentials(credentialsProvider.apply(from));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInOrg;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ImagesInVCloudExpressOrg implements Function<Org, Iterable<? extends Image>> {
|
||||
|
||||
private final AllCatalogItemsInOrg allCatalogItemsInOrg;
|
||||
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
|
||||
private final Provider<ImageForVCloudExpressVAppTemplate> imageForVAppTemplateProvider;
|
||||
|
||||
@Inject
|
||||
ImagesInVCloudExpressOrg(AllCatalogItemsInOrg allCatalogItemsInOrg,
|
||||
Provider<ImageForVCloudExpressVAppTemplate> imageForVAppTemplateProvider,
|
||||
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) {
|
||||
this.imageForVAppTemplateProvider = imageForVAppTemplateProvider;
|
||||
this.allCatalogItemsInOrg = allCatalogItemsInOrg;
|
||||
this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Image> apply(Org from) {
|
||||
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
|
||||
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
|
||||
return FluentIterable.from(vAppTemplates)
|
||||
.transform(imageForVAppTemplateProvider.get().withParent(from))
|
||||
.filter(notNull());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.VAppTemplatesForResourceEntities;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ImagesInVCloudExpressVDC implements Function<VDC, Iterable<? extends Image>> {
|
||||
private final VAppTemplatesForResourceEntities vAppTemplatesForResourceEntities;
|
||||
private final ImageForVCloudExpressVAppTemplate imageForVAppTemplateProvider;
|
||||
|
||||
@Inject
|
||||
public ImagesInVCloudExpressVDC(VAppTemplatesForResourceEntities vAppTemplatesForResourceEntities,
|
||||
ImageForVCloudExpressVAppTemplate imageForVAppTemplateProvider) {
|
||||
this.vAppTemplatesForResourceEntities = checkNotNull(vAppTemplatesForResourceEntities, "vAppTemplatesForResourceEntities");
|
||||
this.imageForVAppTemplateProvider = checkNotNull(imageForVAppTemplateProvider, "imageForVAppTemplateProvider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Image> apply(VDC from) {
|
||||
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForResourceEntities.apply(checkNotNull(from, "vdc")
|
||||
.getResourceEntities().values());
|
||||
return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.withParent(from));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.VDC;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class NodeMetadataToOrgAndName implements Function<NodeMetadata, OrgAndName> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
final Supplier<Map<String, String>> vdcToOrg;
|
||||
|
||||
private final TerremarkVCloudApi client;
|
||||
|
||||
@Inject
|
||||
NodeMetadataToOrgAndName(TerremarkVCloudApi client, @VDC Supplier<Map<String, String>> vdcToOrg) {
|
||||
this.vdcToOrg = vdcToOrg;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrgAndName apply(NodeMetadata from) {
|
||||
if (from.getGroup() != null) {
|
||||
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 {
|
||||
return new OrgAndName(org.getHref(), from.getGroup());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.util.ComputeServiceUtils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseOsFromVAppTemplateName implements Function<String, OperatingSystem> {
|
||||
protected static final Pattern OS_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
|
||||
|
||||
protected final Map<OsFamily, Map<String, String>> osVersionMap;
|
||||
|
||||
@Inject
|
||||
protected ParseOsFromVAppTemplateName(Map<OsFamily, Map<String, String>> osVersionMap) {
|
||||
this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperatingSystem apply(String from) {
|
||||
OperatingSystem.Builder builder = OperatingSystem.builder();
|
||||
OsFamily osFamily = parseOsFamilyOrUnrecognized(checkNotNull(from, "vapp template name"));
|
||||
builder.family(osFamily);
|
||||
builder.description(from);
|
||||
builder.is64Bit(from.indexOf("64") != -1);
|
||||
Matcher matcher = OS_PATTERN.matcher(from);
|
||||
if (matcher.find()) {
|
||||
builder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TemplateToInstantiateOptions implements Function<Template, InstantiateVAppTemplateOptions> {
|
||||
|
||||
@Override
|
||||
public InstantiateVAppTemplateOptions apply(Template from) {
|
||||
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(getCores(from.getHardware())).intValue())
|
||||
.memory(from.getHardware().getRam());
|
||||
if (!from.getOptions().shouldBlockUntilRunning())
|
||||
options.block(false);
|
||||
String sshKeyFingerprint = TerremarkVCloudTemplateOptions.class.cast(from.getOptions()).getSshKeyFingerprint();
|
||||
if (sshKeyFingerprint != null)
|
||||
options.sshKeyFingerprint(sshKeyFingerprint);
|
||||
return options;
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cim.OSType;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.CIMOperatingSystem;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.functions.GroupNamingConvention;
|
||||
import org.jclouds.compute.util.ComputeServiceUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Status;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
|
||||
|
||||
protected final TerremarkVCloudComputeClient computeClient;
|
||||
protected final Map<String, Credentials> credentialStore;
|
||||
protected final Supplier<Set<? extends Image>> images;
|
||||
protected final FindLocationForResource findLocationForResourceInVDC;
|
||||
protected final HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp;
|
||||
protected final Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus;
|
||||
protected final GroupNamingConvention nodeNamingConvention;
|
||||
|
||||
@Inject
|
||||
protected VAppToNodeMetadata(TerremarkVCloudComputeClient computeClient, Map<String, Credentials> credentialStore,
|
||||
Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus, HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
|
||||
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images,
|
||||
GroupNamingConvention.Factory namingConvention) {
|
||||
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
|
||||
this.images = checkNotNull(images, "images");
|
||||
this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
|
||||
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
this.computeClient = checkNotNull(computeClient, "computeClient");
|
||||
this.vAppStatusToNodeStatus = checkNotNull(vAppStatusToNodeStatus, "vAppStatusToNodeStatus");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(VApp from) {
|
||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.ids(from.getHref().toASCIIString());
|
||||
builder.uri(from.getHref());
|
||||
builder.name(from.getName());
|
||||
builder.hostname(from.getName());
|
||||
Location vdcLocation = findLocationForResourceInVDC.apply(from.getVDC());
|
||||
builder.location(vdcLocation);
|
||||
if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {
|
||||
builder.operatingSystem(new CIMOperatingSystem(OSType.fromValue(from.getOsType()), "", null, from
|
||||
.getOperatingSystemDescription()));
|
||||
} else if (from.getOperatingSystemDescription() != null) {
|
||||
OperatingSystem.Builder osBuilder = new OperatingSystem.Builder();
|
||||
if (from.getOsType() != null)
|
||||
osBuilder.name(from.getOsType() + "");
|
||||
osBuilder.family(ComputeServiceUtils.parseOsFamilyOrUnrecognized(from.getOperatingSystemDescription()));
|
||||
osBuilder.version("");
|
||||
osBuilder.is64Bit(from.getOperatingSystemDescription().indexOf("64") != -1);
|
||||
osBuilder.description(from.getOperatingSystemDescription());
|
||||
builder.operatingSystem(osBuilder.build());
|
||||
}
|
||||
builder.hardware(hardwareForVCloudExpressVApp.apply(from));
|
||||
builder.status(vAppStatusToNodeStatus.get(from.getStatus()));
|
||||
builder.publicAddresses(computeClient.getPublicAddresses(from.getHref()));
|
||||
builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref()));
|
||||
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
|
||||
builder.credentials(LoginCredentials.fromCredentials(credentialStore
|
||||
.get("node#" + from.getHref().toASCIIString())));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -1,270 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.options;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
|
||||
/**
|
||||
* Contains options supported in the {@code ComputeService#runNode} operation on
|
||||
* the "trmk-vcloudexpress" provider. <h2>
|
||||
* Usage</h2> The recommended way to instantiate a
|
||||
* TerremarkVCloudTemplateOptions object is to statically import
|
||||
* TerremarkVCloudTemplateOptions.* and invoke a static creation method followed
|
||||
* by an instance mutator (if needed):
|
||||
* <p/>
|
||||
* <code>
|
||||
* import static org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions.Builder.*;
|
||||
* <p/>
|
||||
* ComputeService client = // get connection
|
||||
* templateBuilder.options(inboundPorts(22, 80, 8080, 443));
|
||||
* Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build());
|
||||
* <code>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkVCloudTemplateOptions extends TemplateOptions implements Cloneable {
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions clone() {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
copyTo(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(TemplateOptions to) {
|
||||
super.copyTo(to);
|
||||
if (to instanceof TerremarkVCloudTemplateOptions) {
|
||||
TerremarkVCloudTemplateOptions eTo = TerremarkVCloudTemplateOptions.class.cast(to);
|
||||
if (noKeyPair)
|
||||
eTo.noKeyPair();
|
||||
if (keyPair != null)
|
||||
eTo.keyPair = keyPair;
|
||||
}
|
||||
}
|
||||
|
||||
private String keyPair = null;
|
||||
private boolean noKeyPair;
|
||||
|
||||
public static final TerremarkVCloudTemplateOptions NONE = new TerremarkVCloudTemplateOptions();
|
||||
|
||||
/**
|
||||
* Specifies the keypair used to run instances with
|
||||
*/
|
||||
public TerremarkVCloudTemplateOptions sshKeyFingerprint(String keyPair) {
|
||||
checkState(!noKeyPair, "you cannot specify both options keyPair and noKeyPair");
|
||||
this.keyPair = checkNotNull(emptyToNull(keyPair), "use noKeyPair option to request boot without a keypair");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use a keypair on instances
|
||||
*/
|
||||
public TerremarkVCloudTemplateOptions noKeyPair() {
|
||||
checkState(keyPair == null, "you cannot specify both options keyPair and noKeyPair");
|
||||
this.noKeyPair = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudTemplateOptions#sshKeyFingerprint
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions sshKeyFingerprint(String keyPair) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.sshKeyFingerprint(keyPair));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudTemplateOptions#noKeyPair
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions noKeyPair() {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.noKeyPair());
|
||||
}
|
||||
|
||||
// methods that only facilitate returning the correct object type
|
||||
/**
|
||||
* @see TemplateOptions#inboundPorts
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions inboundPorts(int... ports) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.inboundPorts(ports));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#port
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions blockOnPort(int port, int seconds) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.blockOnPort(port, seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#blockUntilRunning
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions blockUntilRunning(boolean blockUntilRunning) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.blockUntilRunning(blockUntilRunning));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#installPrivateKey
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions installPrivateKey(String rsaKey) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.installPrivateKey(rsaKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#authorizePublicKey
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions authorizePublicKey(String rsaKey) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.authorizePublicKey(rsaKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#userMetadata(Map)
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions userMetadata(Map<String, String> userMetadata) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#userMetadata(String, String)
|
||||
*/
|
||||
public static TerremarkVCloudTemplateOptions userMetadata(String key, String value) {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
return TerremarkVCloudTemplateOptions.class.cast(options.userMetadata(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
// methods that only facilitate returning the correct object type
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#blockOnPort
|
||||
*/
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions blockOnPort(int port, int seconds) {
|
||||
return TerremarkVCloudTemplateOptions.class.cast(super.blockOnPort(port, seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* special thing is that we do assume if you are passing groups that you have
|
||||
* everything you need already defined. for example, our option inboundPorts
|
||||
* normally creates ingress rules accordingly but if we notice you've
|
||||
* specified securityGroups, we do not mess with rules at all
|
||||
*
|
||||
* @see TemplateOptions#inboundPorts
|
||||
*/
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions inboundPorts(int... ports) {
|
||||
return TerremarkVCloudTemplateOptions.class.cast(super.inboundPorts(ports));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#authorizePublicKey(String)
|
||||
*/
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions authorizePublicKey(String publicKey) {
|
||||
return TerremarkVCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#installPrivateKey(String)
|
||||
*/
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions installPrivateKey(String privateKey) {
|
||||
return TerremarkVCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#userMetadata
|
||||
*/
|
||||
public TerremarkVCloudTemplateOptions userMetadata(Map<String, String> userMetadata) {
|
||||
return TerremarkVCloudTemplateOptions.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions userMetadata(String key, String value) {
|
||||
return TerremarkVCloudTemplateOptions.class.cast(super.userMetadata(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return keyPair to use when running the instance or null, to generate a
|
||||
* keypair.
|
||||
*/
|
||||
public String getSshKeyFingerprint() {
|
||||
return keyPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true (default) if we are supposed to use a keypair
|
||||
*/
|
||||
public boolean shouldAutomaticallyCreateKeyPair() {
|
||||
return !noKeyPair;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((keyPair == null) ? 0 : keyPair.hashCode());
|
||||
result = prime * result + (noKeyPair ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TerremarkVCloudTemplateOptions other = (TerremarkVCloudTemplateOptions) obj;
|
||||
if (keyPair == null) {
|
||||
if (other.keyPair != null)
|
||||
return false;
|
||||
} else if (!keyPair.equals(other.keyPair))
|
||||
return false;
|
||||
if (noKeyPair != other.noKeyPair)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TerremarkVCloudTemplateOptions [keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", inboundPorts="
|
||||
+ inboundPorts + ", privateKey=" + (privateKey != null) + ", publicKey="
|
||||
+ (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds
|
||||
+ ", userMetadata: " + userMetadata + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.collect.Iterables.all;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.size;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.inGroup;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.parentLocationId;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class CleanupOrphanKeys {
|
||||
final Function<NodeMetadata, OrgAndName> nodeToOrgAndName;
|
||||
final DeleteKeyPair deleteKeyPair;
|
||||
final ListNodesStrategy listNodes;
|
||||
final Map<String, Credentials> credentialStore;
|
||||
|
||||
@Inject
|
||||
CleanupOrphanKeys(Function<NodeMetadata, OrgAndName> nodeToOrgAndName, DeleteKeyPair deleteKeyPair,
|
||||
Map<String, Credentials> credentialStore, ListNodesStrategy listNodes) {
|
||||
this.nodeToOrgAndName = nodeToOrgAndName;
|
||||
this.deleteKeyPair = deleteKeyPair;
|
||||
this.listNodes = listNodes;
|
||||
this.credentialStore = credentialStore;
|
||||
}
|
||||
|
||||
public void execute(Iterable<? extends NodeMetadata> deadOnes) {
|
||||
for (NodeMetadata node : deadOnes){
|
||||
credentialStore.remove("node#" + node.getId());
|
||||
}
|
||||
Iterable<OrgAndName> orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull());
|
||||
for (OrgAndName orgGroup : orgGroups) {
|
||||
Iterable<? extends NodeMetadata> nodesInOrg = listNodes.listDetailsOnNodesMatching(parentLocationId(orgGroup
|
||||
.getOrg().toASCIIString()));
|
||||
Iterable<? extends NodeMetadata> nodesInGroup = filter(nodesInOrg, inGroup(orgGroup.getName()));
|
||||
if (size(nodesInGroup) == 0 || all(nodesInGroup, TERMINATED)){
|
||||
deleteKeyPair.execute(orgGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ssh.SshKeys;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.CreateUniqueKeyPair;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.KeyPair;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class CreateNewKeyPairUnlessUserSpecifiedOtherwise {
|
||||
final Map<String, Credentials> credentialStore;
|
||||
@VisibleForTesting
|
||||
final CreateUniqueKeyPair createUniqueKeyPair;
|
||||
|
||||
@Inject
|
||||
CreateNewKeyPairUnlessUserSpecifiedOtherwise(Map<String, Credentials> credentialStore,
|
||||
CreateUniqueKeyPair createUniqueKeyPair) {
|
||||
this.credentialStore = credentialStore;
|
||||
this.createUniqueKeyPair = createUniqueKeyPair;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void execute(URI org, String group, String identity, TerremarkVCloudTemplateOptions options) {
|
||||
String sshKeyFingerprint = options.getSshKeyFingerprint();
|
||||
boolean shouldAutomaticallyCreateKeyPair = options.shouldAutomaticallyCreateKeyPair();
|
||||
if (sshKeyFingerprint == null && shouldAutomaticallyCreateKeyPair) {
|
||||
|
||||
// make sure that we don't request multiple keys simultaneously
|
||||
synchronized (credentialStore) {
|
||||
// if there is already a keypair for the group specified, use it
|
||||
if (credentialStore.containsKey("group#" + group)) {
|
||||
LoginCredentials creds = LoginCredentials.fromCredentials(credentialStore.get("group#" + group));
|
||||
checkState(creds.getOptionalPrivateKey().isPresent(),
|
||||
"incorrect state: should have private key for: %s", creds);
|
||||
options.sshKeyFingerprint(SshKeys.fingerprintPrivateKey(creds.getPrivateKey()));
|
||||
} else {
|
||||
// otherwise create a new keypair and key it under the group
|
||||
KeyPair keyPair = createUniqueKeyPair.apply(new OrgAndName(org, group));
|
||||
credentialStore.put("group#" + group, LoginCredentials.builder().user(identity).privateKey(
|
||||
keyPair.getPrivateKey()).build());
|
||||
options.sshKeyFingerprint(keyPair.getFingerPrint());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
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.domain.Credentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.KeyPair;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class DeleteKeyPair {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
final TerremarkVCloudApi terremarkClient;
|
||||
final Map<String, Credentials> credentialStore;
|
||||
|
||||
@Inject
|
||||
DeleteKeyPair(TerremarkVCloudApi terremarkClient, Map<String, Credentials> credentialStore) {
|
||||
this.terremarkClient = terremarkClient;
|
||||
this.credentialStore = credentialStore;
|
||||
}
|
||||
|
||||
public void execute(OrgAndName orgTag) {
|
||||
for (KeyPair keyPair : terremarkClient.listKeyPairsInOrg(orgTag.getOrg())) {
|
||||
if (keyPair.getName().matches("jclouds_" + orgTag.getName().replaceAll("-", "_") + "_[0-9a-f]+")) {
|
||||
logger.debug(">> deleting keyPair(%s)", keyPair.getName());
|
||||
terremarkClient.deleteKeyPair(keyPair.getId());
|
||||
logger.debug("<< deleted keyPair(%s)", keyPair.getName());
|
||||
credentialStore.remove("group#" + orgTag.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.impl.ReturnCredentialsBoundToImage;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseVAppTemplateDescriptionToGetDefaultLoginCredentials extends ReturnCredentialsBoundToImage {
|
||||
@Inject
|
||||
public ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(@Nullable @Named("image") LoginCredentials creds,
|
||||
Map<String, Credentials> credentialStore, Map<OsFamily, LoginCredentials> osFamilyToCredentials) {
|
||||
super(creds, credentialStore, osFamilyToCredentials);
|
||||
}
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public static final Pattern USER_PASSWORD_PATTERN = Pattern
|
||||
.compile(".*[Uu]sername: ([a-z]+) ?.*\n[Pp]assword: ([^ \n\r]+) ?\r?\n.*");
|
||||
|
||||
@Override
|
||||
public LoginCredentials apply(Object resourceToAuthenticate) {
|
||||
if (creds != null)
|
||||
return creds;
|
||||
checkNotNull(resourceToAuthenticate);
|
||||
checkArgument(resourceToAuthenticate instanceof VAppTemplate, "Resource must be an VAppTemplate (for Terremark)");
|
||||
VAppTemplate template = (VAppTemplate) resourceToAuthenticate;
|
||||
String search = template.getDescription() != null ? template.getDescription() : template.getName();
|
||||
if (search.indexOf("Windows") >= 0) {
|
||||
return LoginCredentials.builder().user("Administrator").build();
|
||||
} else {
|
||||
Matcher matcher = USER_PASSWORD_PATTERN.matcher(search);
|
||||
if (matcher.find()) {
|
||||
return LoginCredentials.builder().user(matcher.group(1)).password(matcher.group(2)).authenticateSudo(true).build();
|
||||
} else {
|
||||
logger.warn("could not parse username/password for image: " + template.getHref() + "\n" + search);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.TemplateToInstantiateOptions;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class StartVAppWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
|
||||
protected final TerremarkVCloudComputeClient computeClient;
|
||||
protected final TemplateToInstantiateOptions getOptions;
|
||||
protected final Function<VApp, NodeMetadata> vAppToNodeMetadata;
|
||||
protected final Map<String, Credentials> credentialStore;
|
||||
protected final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
|
||||
|
||||
|
||||
@Inject
|
||||
protected StartVAppWithGroupEncodedIntoName(TerremarkVCloudComputeClient computeClient,
|
||||
Function<VApp, NodeMetadata> vAppToNodeMetadata, TemplateToInstantiateOptions getOptions,
|
||||
Map<String, Credentials> credentialStore, PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate) {
|
||||
this.computeClient = computeClient;
|
||||
this.vAppToNodeMetadata = vAppToNodeMetadata;
|
||||
this.getOptions = checkNotNull(getOptions, "getOptions");
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
this.prioritizeCredentialsFromTemplate = checkNotNull(prioritizeCredentialsFromTemplate, "prioritizeCredentialsFromTemplate");
|
||||
}
|
||||
@Override
|
||||
public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
|
||||
InstantiateVAppTemplateOptions options = getOptions.apply(template);
|
||||
NodeAndInitialCredentials<VApp> from = computeClient.startAndReturnCredentials(URI.create(template.getLocation().getId()), URI.create(template
|
||||
.getImage().getId()), name, options, template.getOptions().getInboundPorts());
|
||||
LoginCredentials fromNode = from.getCredentials();
|
||||
if (credentialStore.containsKey("group#" + group)) {
|
||||
fromNode = fromNode == null ? LoginCredentials.fromCredentials(credentialStore.get("group#" + group))
|
||||
: fromNode.toBuilder().privateKey(credentialStore.get("group#" + group).credential).build();
|
||||
}
|
||||
LoginCredentials creds = prioritizeCredentialsFromTemplate.apply(template, fromNode);
|
||||
if (creds != null)
|
||||
credentialStore.put("node#" + from.getNodeId(), creds);
|
||||
return vAppToNodeMetadata.apply(from.getNode());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.config.CustomizationResponse;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.functions.GroupNamingConvention;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
|
||||
/**
|
||||
* creates futures that correlate to
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends CreateNodesWithGroupEncodedIntoNameThenAddToSet {
|
||||
|
||||
private final CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise;
|
||||
|
||||
@Inject
|
||||
protected TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy(
|
||||
CreateNodeWithGroupEncodedIntoName addNodeWithTagStrategy,
|
||||
ListNodesStrategy listNodesStrategy,
|
||||
GroupNamingConvention.Factory namingConvention,
|
||||
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
|
||||
CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) {
|
||||
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
|
||||
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
|
||||
this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, ListenableFuture<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes,
|
||||
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
|
||||
assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: "
|
||||
+ template.getLocation();
|
||||
String orgId = template.getLocation().getParent().getId();
|
||||
assert orgId.startsWith("http") : "parent id should be a rest url: " + template.getLocation().getParent();
|
||||
createNewKeyPairUnlessUserSpecifiedOtherwise.execute(URI.create(orgId), tag, template.getImage()
|
||||
.getDefaultCredentials().identity, template.getOptions().as(TerremarkVCloudTemplateOptions.class));
|
||||
return super.execute(tag, count, template, goodNodes, badNodes, customizationResponses);
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.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.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkVCloudDestroyNodeStrategy implements DestroyNodeStrategy {
|
||||
protected final TerremarkVCloudComputeClient computeClient;
|
||||
protected final GetNodeMetadataStrategy getNode;
|
||||
|
||||
@Inject
|
||||
protected TerremarkVCloudDestroyNodeStrategy(TerremarkVCloudComputeClient computeClient, GetNodeMetadataStrategy getNode) {
|
||||
this.computeClient = computeClient;
|
||||
this.getNode = getNode;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata destroyNode(String id) {
|
||||
computeClient.stop(URI.create(checkNotNull(id, "node.id")));
|
||||
return getNode.getNode(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.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.Image;
|
||||
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkVCloudGetImageStrategy implements GetImageStrategy {
|
||||
|
||||
protected final TerremarkVCloudApi client;
|
||||
protected final Function<VAppTemplate, Image> vAppToImage;
|
||||
|
||||
@Inject
|
||||
protected TerremarkVCloudGetImageStrategy(TerremarkVCloudApi client, Function<VAppTemplate, Image> vAppToImage) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.vAppToImage = vAppToImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(String in) {
|
||||
URI id = URI.create(in);
|
||||
VAppTemplate from = client.getVAppTemplate(id);
|
||||
if (from == null)
|
||||
return null;
|
||||
return vAppToImage.apply(from);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.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.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkVCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
||||
|
||||
protected final TerremarkVCloudApi client;
|
||||
protected final Function<VApp, NodeMetadata> vAppToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected TerremarkVCloudGetNodeMetadataStrategy(TerremarkVCloudApi client,
|
||||
Function<VApp, NodeMetadata> vAppToNodeMetadata) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.vAppToNodeMetadata = vAppToNodeMetadata;
|
||||
}
|
||||
|
||||
public NodeMetadata getNode(String in) {
|
||||
URI id = URI.create(in);
|
||||
VApp from = client.getVApp(id);
|
||||
if (from == null)
|
||||
return null;
|
||||
return vAppToNodeMetadata.apply(from);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Task;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkVCloudLifeCycleStrategy implements RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final TerremarkVCloudApi client;
|
||||
protected final Predicate<URI> taskTester;
|
||||
protected final GetNodeMetadataStrategy getNode;
|
||||
|
||||
@Inject
|
||||
protected TerremarkVCloudLifeCycleStrategy(TerremarkVCloudApi client, Predicate<URI> taskTester,
|
||||
GetNodeMetadataStrategy getNode) {
|
||||
this.client = client;
|
||||
this.taskTester = taskTester;
|
||||
this.getNode = getNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata rebootNode(String in) {
|
||||
Task task = client.resetVApp(URI.create(checkNotNull(in, "node.id")));
|
||||
return returnWhenTaskCompletes(in, task);
|
||||
}
|
||||
|
||||
private NodeMetadata returnWhenTaskCompletes(String in, Task task) {
|
||||
taskTester.apply(task.getHref());
|
||||
return getNode.getNode(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata resumeNode(String in) {
|
||||
Task task = client.powerOnVApp(URI.create(checkNotNull(in, "node.id")));
|
||||
return returnWhenTaskCompletes(in, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata suspendNode(String in) {
|
||||
Task task = client.powerOffVApp(URI.create(checkNotNull(in, "node.id")));
|
||||
return returnWhenTaskCompletes(in, task);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.strategy;
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static org.jclouds.compute.config.ComputeServiceProperties.BLACKLIST_NODES;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.all;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.withIds;
|
||||
import static org.jclouds.compute.reference.ComputeServiceConstants.COMPUTE_LOGGER;
|
||||
|
||||
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.ComputeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.ComputeType;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.FindLocationForResource;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.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.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// TODO REFACTOR!!! needs to be parallel
|
||||
@Singleton
|
||||
public class TerremarkVCloudListNodesStrategy implements ListNodesStrategy {
|
||||
@Resource
|
||||
@Named(COMPUTE_LOGGER)
|
||||
public Logger logger = Logger.NULL;
|
||||
protected final TerremarkVCloudGetNodeMetadataStrategy getNodeMetadata;
|
||||
protected final TerremarkVCloudApi client;
|
||||
protected final FindLocationForResource findLocationForResourceInVDC;
|
||||
Set<String> blackListVAppNames = ImmutableSet.<String> of();
|
||||
|
||||
@Inject(optional = true)
|
||||
void setBlackList(@Named(BLACKLIST_NODES) String blackListNodes) {
|
||||
if (blackListNodes != null && !"".equals(blackListNodes))
|
||||
this.blackListVAppNames = ImmutableSet.copyOf(Splitter.on(',').split(blackListNodes));
|
||||
}
|
||||
|
||||
private final Supplier<Map<String, ReferenceType>> orgNameToEndpoint;
|
||||
|
||||
@Inject
|
||||
protected TerremarkVCloudListNodesStrategy(TerremarkVCloudApi client,
|
||||
@Org Supplier<Map<String, ReferenceType>> orgNameToEndpoint,
|
||||
TerremarkVCloudGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
|
||||
this.client = client;
|
||||
this.orgNameToEndpoint = orgNameToEndpoint;
|
||||
this.getNodeMetadata = getNodeMetadata;
|
||||
this.findLocationForResourceInVDC = findLocationForResourceInVDC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ComputeMetadata> listNodes() {
|
||||
Set<ComputeMetadata> nodes = Sets.newHashSet();
|
||||
for (String org : orgNameToEndpoint.get().keySet()) {
|
||||
for (ReferenceType vdc : client.findOrgNamed(org).getVDCs().values()) {
|
||||
for (ReferenceType resource : client.getVDC(vdc.getHref()).getResourceEntities().values()) {
|
||||
if (validVApp(resource)) {
|
||||
nodes.add(convertVAppToComputeMetadata(vdc, resource));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private boolean validVApp(ReferenceType resource) {
|
||||
return resource.getType().equals(TerremarkVCloudMediaType.VAPP_XML)
|
||||
&& !blackListVAppNames.contains(resource.getName());
|
||||
}
|
||||
|
||||
private ComputeMetadata convertVAppToComputeMetadata(ReferenceType vdc, ReferenceType resource) {
|
||||
ComputeMetadataBuilder builder = new ComputeMetadataBuilder(ComputeType.NODE);
|
||||
builder.providerId(resource.getHref().toASCIIString());
|
||||
builder.name(resource.getName());
|
||||
builder.id(resource.getHref().toASCIIString());
|
||||
builder.location(findLocationForResourceInVDC.apply(vdc));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listNodesByIds(Iterable<String> ids) {
|
||||
return FluentIterable.from(listDetailsOnNodesMatching(all())).filter(withIds(toArray(ids, String.class))).toSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
Set<NodeMetadata> nodes = Sets.newHashSet();
|
||||
for (String org : orgNameToEndpoint.get().keySet()) {
|
||||
for (ReferenceType vdc : client.findOrgNamed(org).getVDCs().values()) {
|
||||
for (ReferenceType resource : client.getVDC(vdc.getHref()).getResourceEntities().values()) {
|
||||
if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
|
||||
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addVAppToSetRetryingIfNotYetPresent(Set<NodeMetadata> nodes, ReferenceType vdc, ReferenceType resource) {
|
||||
NodeMetadata node = null;
|
||||
int i = 0;
|
||||
while (node == null && i++ < 3) {
|
||||
try {
|
||||
node = getNodeMetadata.getNode(resource.getHref().toASCIIString());
|
||||
nodes.add(node);
|
||||
} catch (NullPointerException e) {
|
||||
logger.warn("vApp %s not yet present in vdc %s", resource.getName(), vdc.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.suppliers;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Volume;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class StaticHardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
||||
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
Set<Hardware> hardware = Sets.newHashSet();
|
||||
for (int cpus : new int[] { 1, 2, 4, 8 })
|
||||
for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) {
|
||||
String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10);
|
||||
hardware.add(new HardwareBuilder().ids(id).ram(ram).processors(ImmutableList.of(new Processor(cpus, 1.0)))
|
||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(10f, true, true))).hypervisor("VMware").build());
|
||||
}
|
||||
return hardware;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.compute.suppliers;
|
||||
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Sets.newLinkedHashSet;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
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.trmk.vcloud_0_8.compute.functions.ImagesInVCloudExpressOrg;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class VAppTemplatesInOrgs implements Supplier<Set<? extends Image>> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
public Logger logger = Logger.NULL;
|
||||
|
||||
private final Supplier<Set<? extends Location>> locations;
|
||||
private final Function<Iterable<? extends Location>, Iterable<? extends Org>> organizationsForLocations;
|
||||
private final ImagesInVCloudExpressOrg imagesInOrg;
|
||||
|
||||
@Inject
|
||||
VAppTemplatesInOrgs(@Memoized Supplier<Set<? extends Location>> locations,
|
||||
Function<Iterable<? extends Location>, Iterable<? extends Org>> organizationsForLocations,
|
||||
ImagesInVCloudExpressOrg imagesInOrg) {
|
||||
this.locations = locations;
|
||||
this.organizationsForLocations = organizationsForLocations;
|
||||
this.imagesInOrg = imagesInOrg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Terremark does not provide vApp templates in the vDC resourceEntity list. Rather, you must
|
||||
* query the catalog.
|
||||
*/
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
logger.debug(">> providing vAppTemplates");
|
||||
return newLinkedHashSet(concat(transform(organizationsForLocations.apply(locations.get()), imagesInOrg)));
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.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 javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class VCloudHardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
public Logger logger = Logger.NULL;
|
||||
|
||||
private final Supplier<Map<String, ? extends Org>> orgMap;
|
||||
private final Function<Org, Iterable<? extends Hardware>> sizesInOrg;
|
||||
private final ListeningExecutorService userExecutor;
|
||||
|
||||
@Inject
|
||||
VCloudHardwareSupplier(Supplier<Map<String, ? extends Org>> orgMap,
|
||||
Function<Org, Iterable<? extends Hardware>> sizesInOrg,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
|
||||
this.orgMap = checkNotNull(orgMap, "orgMap");
|
||||
this.sizesInOrg = checkNotNull(sizesInOrg, "sizesInOrg");
|
||||
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
|
||||
Iterable<? extends Iterable<? extends Hardware>> sizes = transformParallel(orgs,
|
||||
new Function<Org, ListenableFuture<? extends Iterable<? extends Hardware>>>() {
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Iterable<? extends Hardware>> apply(final Org from) {
|
||||
checkNotNull(from, "org");
|
||||
return userExecutor.submit(new Callable<Iterable<? extends Hardware>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Hardware> call() throws Exception {
|
||||
return sizesInOrg.apply(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "sizesInOrg(" + from.getHref() + ")";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}, userExecutor, null, logger, "sizes in " + orgs);
|
||||
return newLinkedHashSet(concat(sizes));
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.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 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.trmk.vcloud_0_8.domain.Org;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
public Logger logger = Logger.NULL;
|
||||
|
||||
private final Supplier<Map<String, ? extends Org>> orgMap;
|
||||
private final Function<Org, Iterable<? extends Image>> imagesInOrg;
|
||||
private final ListeningExecutorService userExecutor;
|
||||
|
||||
@Inject
|
||||
VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap,
|
||||
Function<Org, Iterable<? extends Image>> imagesInOrg,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
|
||||
this.orgMap = checkNotNull(orgMap, "orgMap");
|
||||
this.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");
|
||||
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
|
||||
Iterable<? extends Iterable<? extends Image>> images = transformParallel(orgs,
|
||||
new Function<Org, ListenableFuture<? extends Iterable<? extends Image>>>() {
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Iterable<? extends Image>> apply(final Org from) {
|
||||
checkNotNull(from, "org");
|
||||
return userExecutor.submit(new Callable<Iterable<? extends Image>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Image> call() throws Exception {
|
||||
return imagesInOrg.apply(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "imagesInOrg(" + from.getHref() + ")";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}, userExecutor, null, logger, "images in " + orgs);
|
||||
return newLinkedHashSet(concat(images));
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class DefaultCatalogForOrg implements Function<ReferenceType, ReferenceType> {
|
||||
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
|
||||
private final Supplier<Map<String, ? extends Org>> nameToOrg;
|
||||
|
||||
@Inject
|
||||
public DefaultCatalogForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
|
||||
@Catalog Predicate<ReferenceType> defaultSelector, Supplier<Map<String, ? extends Org>> nameToOrg) {
|
||||
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
|
||||
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_CATALOG,
|
||||
checkNotNull(defaultSelector, "defaultSelector"));
|
||||
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(ReferenceType defaultOrg) {
|
||||
org.jclouds.trmk.vcloud_0_8.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
|
||||
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
|
||||
return selector.apply(org.getCatalogs().values());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Network;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class DefaultNetworkForVDC implements Function<ReferenceType, ReferenceType> {
|
||||
|
||||
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
|
||||
private final Supplier<Map<URI, ? extends VDC>> uriToVDC;
|
||||
|
||||
@Inject
|
||||
public DefaultNetworkForVDC(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
|
||||
@Network Predicate<ReferenceType> defaultSelector,
|
||||
Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> uriToVDC) {
|
||||
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
|
||||
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_NETWORK,
|
||||
checkNotNull(defaultSelector, "defaultSelector"));
|
||||
this.uriToVDC = checkNotNull(uriToVDC, "uriToVDC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(ReferenceType defaultVDC) {
|
||||
org.jclouds.trmk.vcloud_0_8.domain.VDC vDC = uriToVDC.get().get(defaultVDC.getHref());
|
||||
checkState(vDC != null, "could not retrieve VDC at %s", defaultVDC);
|
||||
return selector.apply(vDC.getAvailableNetworks().values());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class DefaultOrgForUser implements Supplier<ReferenceType> {
|
||||
|
||||
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
|
||||
private final Supplier<VCloudSession> session;
|
||||
|
||||
@Inject
|
||||
public DefaultOrgForUser(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
|
||||
@Org Predicate<ReferenceType> defaultSelector, Supplier<VCloudSession> session) {
|
||||
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
|
||||
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_ORG, checkNotNull(
|
||||
defaultSelector, "defaultSelector"));
|
||||
this.session = checkNotNull(session, "session");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType get() {
|
||||
return selector.apply(session.get().getOrgs().values());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_TASKSLIST;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.TasksList;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class DefaultTasksListForOrg implements Function<ReferenceType, ReferenceType> {
|
||||
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
|
||||
private final Supplier<Map<String, ? extends Org>> nameToOrg;
|
||||
|
||||
@Inject
|
||||
public DefaultTasksListForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
|
||||
@TasksList Predicate<ReferenceType> defaultSelector, Supplier<Map<String, ? extends Org>> nameToOrg) {
|
||||
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
|
||||
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_TASKSLIST,
|
||||
checkNotNull(defaultSelector, "defaultSelector"));
|
||||
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(ReferenceType defaultOrg) {
|
||||
org.jclouds.trmk.vcloud_0_8.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
|
||||
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
|
||||
return selector.apply(org.getTasksLists().values());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.config;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DefaultVCloudReferencesModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Supplier<ReferenceType>>() {
|
||||
}).annotatedWith(Org.class).to(DefaultOrgForUser.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org
|
||||
protected Predicate<ReferenceType> provideDefaultOrgSelector(Injector i) {
|
||||
return Predicates.alwaysTrue();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.TasksList
|
||||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.TasksList
|
||||
protected Predicate<ReferenceType> provideDefaultTasksListSelector(Injector i) {
|
||||
return Predicates.alwaysTrue();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Catalog
|
||||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Catalog
|
||||
protected Predicate<ReferenceType> provideDefaultCatalogSelector(Injector i) {
|
||||
return Predicates.alwaysTrue();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>> provideCatalogsById(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> supplier) {
|
||||
return Suppliers
|
||||
.compose(
|
||||
new Function<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>, Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>() {
|
||||
|
||||
@Override
|
||||
public Map<URI, ? extends Catalog> apply(Map<String, Map<String, ? extends Catalog>> arg0) {
|
||||
Builder<URI, Catalog> builder = ImmutableMap.builder();
|
||||
for (Map<String, ? extends Catalog> v1 : arg0.values()) {
|
||||
for (Catalog v2 : v1.values()) {
|
||||
builder.put(v2.getHref(), v2);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC
|
||||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC
|
||||
protected Predicate<ReferenceType> provideDefaultVDCSelector(Injector i) {
|
||||
return Predicates.alwaysTrue();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Network
|
||||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
|
||||
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Network
|
||||
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
|
||||
return Predicates.alwaysTrue();
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.VDC;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class DefaultVDCForOrg implements Function<ReferenceType, ReferenceType> {
|
||||
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
|
||||
private final Supplier<Map<String, ? extends Org>> nameToOrg;
|
||||
|
||||
@Inject
|
||||
public DefaultVDCForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
|
||||
@VDC Predicate<ReferenceType> defaultSelector, Supplier<Map<String, ? extends Org>> nameToOrg) {
|
||||
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
|
||||
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_VDC, checkNotNull(
|
||||
defaultSelector, "defaultSelector"));
|
||||
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(ReferenceType defaultOrg) {
|
||||
org.jclouds.trmk.vcloud_0_8.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
|
||||
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
|
||||
return selector.apply(org.getVDCs().values());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,558 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Iterables.getLast;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.collect.Maps.uniqueIndex;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
|
||||
import static org.jclouds.util.Predicates2.retry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
||||
import org.jclouds.location.suppliers.LocationsSupplier;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.rest.config.HttpApiModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.VCloudToken;
|
||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.FindLocationForResource;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Keys;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.OrgList;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.VCloudLogin;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInCatalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInOrg;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogsInOrg;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.AllVDCsInOrg;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.OrgsForLocations;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.OrgsForNames;
|
||||
import org.jclouds.trmk.vcloud_0_8.functions.VAppTemplatesForCatalogItems;
|
||||
import org.jclouds.trmk.vcloud_0_8.handlers.ParseTerremarkVCloudErrorFromHttpResponse;
|
||||
import org.jclouds.trmk.vcloud_0_8.internal.TerremarkVCloudLoginApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.internal.TerremarkVCloudVersionsApi;
|
||||
import org.jclouds.trmk.vcloud_0_8.location.DefaultVDC;
|
||||
import org.jclouds.trmk.vcloud_0_8.location.OrgAndVDCToLocationSupplier;
|
||||
import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
public class TerremarkVCloudHttpApiModule<S> extends HttpApiModule<S> {
|
||||
|
||||
public TerremarkVCloudHttpApiModule() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
|
||||
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
|
||||
});
|
||||
installDefaultVCloudEndpointsModule();
|
||||
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
|
||||
}).to(new TypeLiteral<FindLocationForResource>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends Catalog>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogsInOrg>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends VDC>>>() {
|
||||
}).to(new TypeLiteral<AllVDCsInOrg>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>>>() {
|
||||
}).to(new TypeLiteral<OrgsForNames>() {
|
||||
});
|
||||
bind(
|
||||
new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>>>() {
|
||||
}).to(new TypeLiteral<OrgsForLocations>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
|
||||
});
|
||||
bind(new TypeLiteral<Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends CatalogItem>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogItemsInOrg>() {
|
||||
});
|
||||
bindHttpApi(binder(), TerremarkVCloudVersionsApi.class);
|
||||
bindHttpApi(binder(), TerremarkVCloudLoginApi.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(
|
||||
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgNameToOrgSupplier) {
|
||||
return Suppliers.compose(
|
||||
new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>, Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org> arg0) {
|
||||
Builder<String, String> returnVal = ImmutableMap.builder();
|
||||
for (Entry<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org> orgr : arg0.entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
}
|
||||
return returnVal.build();
|
||||
}
|
||||
}, orgNameToOrgSupplier);
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> provideOrgMapCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgMapSupplier supplier) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@OrgList
|
||||
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
return Suppliers.compose(new Function<VCloudSession, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(VCloudSession arg0) {
|
||||
return URI.create(getLast(arg0.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "orgListURI()";
|
||||
}
|
||||
|
||||
}, sessionSupplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgMapSupplier implements
|
||||
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> {
|
||||
protected final Supplier<VCloudSession> sessionSupplier;
|
||||
protected final Function<Iterable<String>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> organizationsForNames;
|
||||
|
||||
@Inject
|
||||
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
|
||||
Function<Iterable<String>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> organizationsForNames) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
this.organizationsForNames = organizationsForNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org> get() {
|
||||
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void installDefaultVCloudEndpointsModule() {
|
||||
install(new DefaultVCloudReferencesModule());
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> {
|
||||
protected final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier;
|
||||
protected final Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>> allCatalogsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogSupplier(
|
||||
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
|
||||
Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>> allCatalogsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allCatalogsInOrg = allCatalogsInOrg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog> apply(
|
||||
Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@VCloudToken
|
||||
@Provides
|
||||
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> provideURIToVDC(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
URItoVDC supplier) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class URItoVDC implements Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> {
|
||||
private final Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap;
|
||||
|
||||
@Inject
|
||||
URItoVDC(Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap) {
|
||||
this.orgVDCMap = orgVDCMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> get() {
|
||||
return uniqueIndex(
|
||||
concat(transform(
|
||||
orgVDCMap.get().values(),
|
||||
new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(
|
||||
Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> from) {
|
||||
return from.values();
|
||||
}
|
||||
|
||||
})), new Function<org.jclouds.trmk.vcloud_0_8.domain.VDC, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(org.jclouds.trmk.vcloud_0_8.domain.VDC from) {
|
||||
return from.getHref();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final Function<ReferenceType, String> name = new Function<ReferenceType, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(ReferenceType from) {
|
||||
return from.getName();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@VCloudLogin
|
||||
protected Supplier<URI> provideAuthenticationURI(final TerremarkVCloudVersionsApi versionService,
|
||||
@ApiVersion final String version) {
|
||||
return new Supplier<URI>() {
|
||||
|
||||
@Override
|
||||
public URI get() {
|
||||
SortedMap<String, URI> versions = versionService.getSupportedVersions();
|
||||
checkState(versions.size() > 0, "No versions present");
|
||||
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
|
||||
return versions.get(version);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "login()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Singleton
|
||||
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
|
||||
private final Supplier<VCloudSession> sessionSupplier;
|
||||
|
||||
@Inject
|
||||
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return sessionSupplier.get().getOrgs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<org.jclouds.trmk.vcloud_0_8.domain.Org> provideOrg(
|
||||
final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() {
|
||||
|
||||
@Override
|
||||
public org.jclouds.trmk.vcloud_0_8.domain.Org apply(ReferenceType input) {
|
||||
return orgSupplier.get().get(input.getName());
|
||||
|
||||
}
|
||||
}, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<URI> successTester(Injector injector,
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
return retry(injector.getInstance(TaskSuccess.class), completed);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogSupplier supplier) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgVDCSupplier supplier) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgVDCSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> {
|
||||
protected final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier;
|
||||
private final Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> allVDCsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgVDCSupplier(
|
||||
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
|
||||
Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> allVDCsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allVDCsInOrg = allVDCsInOrg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allVDCsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(
|
||||
Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogItemSupplier implements
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>> {
|
||||
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> catalogSupplier;
|
||||
protected final Function<org.jclouds.trmk.vcloud_0_8.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogItemSupplier(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> catalogSupplier,
|
||||
Function<org.jclouds.trmk.vcloud_0_8.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
|
||||
this.catalogSupplier = catalogSupplier;
|
||||
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>> get() {
|
||||
return transformValues(
|
||||
catalogSupplier.get(),
|
||||
new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends CatalogItem>> apply(
|
||||
Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog> from) {
|
||||
return transformValues(
|
||||
from,
|
||||
new Function<org.jclouds.trmk.vcloud_0_8.domain.Catalog, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends CatalogItem> apply(
|
||||
org.jclouds.trmk.vcloud_0_8.domain.Catalog from) {
|
||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogItemSupplier supplier) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a listing of all orgs that the current user has access to.
|
||||
*/
|
||||
@Provides
|
||||
@Org
|
||||
Map<String, ReferenceType> listOrgs(Supplier<VCloudSession> sessionSupplier) {
|
||||
return sessionSupplier.get().getOrgs();
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, final TerremarkVCloudLoginApi login) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
return login.login();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(login).add("method", "login").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateInternetService")
|
||||
String provideCreateInternetService() throws IOException {
|
||||
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateInternetService.xml"));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateNodeService")
|
||||
String provideCreateNodeService() throws IOException {
|
||||
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateNodeService.xml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgNameToKeysListSupplier implements Supplier<Map<String, ReferenceType>> {
|
||||
protected final Supplier<VCloudSession> sessionSupplier;
|
||||
private final TerremarkVCloudApi client;
|
||||
|
||||
@Inject
|
||||
protected OrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier, TerremarkVCloudApi client) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(ReferenceType from) {
|
||||
return client.findOrgNamed(from.getName()).getKeys();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Keys
|
||||
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgNameToKeysListSupplier supplier) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateKey")
|
||||
String provideCreateKey() throws IOException {
|
||||
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateKey.xml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installLocations() {
|
||||
super.installLocations();
|
||||
bind(ImplicitLocationSupplier.class).to(DefaultVDC.class).in(Scopes.SINGLETON);
|
||||
bind(LocationsSupplier.class).to(OrgAndVDCToLocationSupplier.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
/**
|
||||
* reports storage resource consumption in a vDC.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Capacity {
|
||||
|
||||
private final String units;
|
||||
private final long allocated;
|
||||
private final long limit;
|
||||
private final int used;
|
||||
private final long overhead;
|
||||
|
||||
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 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 + (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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
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;
|
||||
} else if (!units.equals(other.units))
|
||||
return false;
|
||||
if (used != other.used)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[allocated=" + allocated + ", limit=" + limit + ", overhead=" + overhead + ", units=" + units + ", used="
|
||||
+ used + "]";
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.CatalogImpl;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Catalog
|
||||
@ImplementedBy(CatalogImpl.class)
|
||||
public interface Catalog extends ReferenceType, Map<String, ReferenceType> {
|
||||
|
||||
/**
|
||||
* optional description
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
@Nullable
|
||||
String getDescription();
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.CatalogItemImpl;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(CatalogItemImpl.class)
|
||||
public interface CatalogItem extends ReferenceType {
|
||||
|
||||
String getDescription();
|
||||
|
||||
ReferenceType getEntity();
|
||||
|
||||
Map<String, String> getProperties();
|
||||
|
||||
ReferenceType getComputeOptions();
|
||||
|
||||
ReferenceType getCustomizationOptions();
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ComputePoolReference implements Comparable<ComputePoolReference> {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromComputePoolReference(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private URI href;
|
||||
private String name;
|
||||
|
||||
public Builder href(URI href) {
|
||||
this.href = href;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ComputePoolReference build() {
|
||||
return new ComputePoolReference(href, name);
|
||||
}
|
||||
|
||||
public Builder fromComputePoolReference(ComputePoolReference in) {
|
||||
return href(in.getHref()).name(in.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final URI href;
|
||||
private final String name;
|
||||
|
||||
public ComputePoolReference(URI href, String name) {
|
||||
this.href = href;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int compareTo(ComputePoolReference that) {
|
||||
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||
}
|
||||
|
||||
public URI getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
ComputePoolReference that = ComputePoolReference.class.cast(o);
|
||||
return equal(this.href, that.href) && equal(this.name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(href, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("").add("href", href).add("name", name).toString();
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
/**
|
||||
* The response lists which customization options are supported for this
|
||||
* particular vApp. The possible customization options are Network and Password.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a
|
||||
* href="https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/6-using-the-vcloud-express-api.aspx"
|
||||
* >Terremark documentation</a>
|
||||
*/
|
||||
public class CustomizationParameters {
|
||||
private final boolean customizeNetwork;
|
||||
private final boolean customizePassword;
|
||||
private final boolean customizeSSH;
|
||||
|
||||
public CustomizationParameters(boolean customizeNetwork,
|
||||
boolean customizePassword, boolean customizeSSH) {
|
||||
this.customizeNetwork = customizeNetwork;
|
||||
this.customizePassword = customizePassword;
|
||||
this.customizeSSH = customizeSSH;
|
||||
}
|
||||
|
||||
public boolean canCustomizeNetwork() {
|
||||
return customizeNetwork;
|
||||
}
|
||||
|
||||
public boolean canCustomizePassword() {
|
||||
return customizePassword;
|
||||
}
|
||||
|
||||
public boolean canCustomizeSSH() {
|
||||
return customizeSSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (customizeNetwork ? 1231 : 1237);
|
||||
result = prime * result + (customizePassword ? 1231 : 1237);
|
||||
result = prime * result + (customizeSSH ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
CustomizationParameters other = (CustomizationParameters) obj;
|
||||
if (customizeNetwork != other.customizeNetwork)
|
||||
return false;
|
||||
if (customizePassword != other.customizePassword)
|
||||
return false;
|
||||
if (customizeSSH != other.customizeSSH)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomizationParameters [customizeNetwork=" + customizeNetwork
|
||||
+ ", customizePassword=" + customizePassword + ", customizeSSH="
|
||||
+ customizeSSH + "]";
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DataCenter {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String id;
|
||||
private String name;
|
||||
private String code;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder code(String code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataCenter build() {
|
||||
return new DataCenter(id, name, code);
|
||||
}
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final String code;
|
||||
|
||||
public DataCenter(String id, String name, String code) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return id of the data center
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return name of the data center
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return airport code of the data center
|
||||
*/
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((code == null) ? 0 : code.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.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;
|
||||
DataCenter other = (DataCenter) obj;
|
||||
if (code == null) {
|
||||
if (other.code != null)
|
||||
return false;
|
||||
} else if (!code.equals(other.code))
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", name=" + name + ", code=" + code + "]";
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* The FenceMode element contains one of the following strings that specify how
|
||||
* a network is connected to its parent network.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum FenceMode {
|
||||
/**
|
||||
* The two networks are bridged.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
ALLOW_IN_OUT,
|
||||
/**
|
||||
* The two networks are not connected.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
ISOLATED,
|
||||
/**
|
||||
* The two networks are connected as specified in their NatService elements.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
NAT_ROUTED, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static FenceMode fromValue(String fenceMode) {
|
||||
try {
|
||||
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(fenceMode, "fenceMode")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class InternetService implements Comparable<InternetService> {
|
||||
private final String name;
|
||||
private final URI id;
|
||||
private final PublicIpAddress publicIpAddress;
|
||||
private final int port;
|
||||
private final Protocol protocol;
|
||||
private final boolean enabled;
|
||||
private final int timeout;
|
||||
private final String description;
|
||||
|
||||
public InternetService(String name, URI id, PublicIpAddress publicIpAddress, int port, Protocol protocol,
|
||||
boolean enabled, int timeout, String description) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.publicIpAddress = publicIpAddress;
|
||||
this.port = port;
|
||||
this.protocol = protocol;
|
||||
this.enabled = enabled;
|
||||
this.timeout = timeout;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public PublicIpAddress getPublicIpAddress() {
|
||||
return publicIpAddress;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public Protocol getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public URI getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int compareTo(InternetService that) {
|
||||
return (this == that) ? 0 : getId().compareTo(that.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[description=" + description + ", enabled=" + enabled + ", id=" + id + ", name=" + name + ", port="
|
||||
+ port + ", protocol=" + protocol + ", publicIpAddress=" + publicIpAddress + ", timeout=" + timeout + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + (enabled ? 1231 : 1237);
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + port;
|
||||
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
|
||||
result = prime * result + ((publicIpAddress == null) ? 0 : publicIpAddress.hashCode());
|
||||
result = prime * result + timeout;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
InternetService other = (InternetService) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
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 (port != other.port)
|
||||
return false;
|
||||
if (protocol == null) {
|
||||
if (other.protocol != null)
|
||||
return false;
|
||||
} else if (!protocol.equals(other.protocol))
|
||||
return false;
|
||||
if (publicIpAddress == null) {
|
||||
if (other.publicIpAddress != null)
|
||||
return false;
|
||||
} else if (!publicIpAddress.equals(other.publicIpAddress))
|
||||
return false;
|
||||
if (timeout != other.timeout)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class IpAddress implements Comparable<IpAddress> {
|
||||
|
||||
public static enum Status {
|
||||
AVAILABLE, ASSIGNED, UNRECOGNIZED;
|
||||
public String value() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static Status fromValue(String status) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final String address;
|
||||
private final Status status;
|
||||
@Nullable
|
||||
private final String server;
|
||||
|
||||
public IpAddress(String address, Status status, String server) {
|
||||
this.address = address;
|
||||
this.status = status;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IpAddress [address=" + address + ", server=" + server + ", status=" + status + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IpAddress o) {
|
||||
return (this == o) ? 0 : getAddress().compareTo(o.getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((address == null) ? 0 : address.hashCode());
|
||||
result = prime * result + ((server == null) ? 0 : server.hashCode());
|
||||
result = prime * result + ((status == null) ? 0 : status.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;
|
||||
IpAddress other = (IpAddress) obj;
|
||||
if (address == null) {
|
||||
if (other.address != null)
|
||||
return false;
|
||||
} else if (!address.equals(other.address))
|
||||
return false;
|
||||
if (server == null) {
|
||||
if (other.server != null)
|
||||
return false;
|
||||
} else if (!server.equals(other.server))
|
||||
return false;
|
||||
if (status == null) {
|
||||
if (other.status != null)
|
||||
return false;
|
||||
} else if (!status.equals(other.status))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* an SSH keypair
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class KeyPair {
|
||||
private final URI id;
|
||||
private final String name;
|
||||
private final boolean isDefault;
|
||||
@Nullable
|
||||
private final String privateKey;
|
||||
private final String fingerPrint;
|
||||
|
||||
public KeyPair(URI id, String name, boolean isDefault, @Nullable String privateKey, String fingerPrint) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.isDefault = isDefault;
|
||||
this.privateKey = privateKey;
|
||||
this.fingerPrint = fingerPrint;
|
||||
}
|
||||
|
||||
public URI getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
public String getFingerPrint() {
|
||||
return fingerPrint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((fingerPrint == null) ? 0 : fingerPrint.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + (isDefault ? 1231 : 1237);
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((privateKey == null) ? 0 : privateKey.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;
|
||||
KeyPair other = (KeyPair) obj;
|
||||
if (fingerPrint == null) {
|
||||
if (other.fingerPrint != null)
|
||||
return false;
|
||||
} else if (!fingerPrint.equals(other.fingerPrint))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (isDefault != other.isDefault)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (privateKey == null) {
|
||||
if (other.privateKey != null)
|
||||
return false;
|
||||
} else if (!privateKey.equals(other.privateKey))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Key [fingerPrint=" + fingerPrint + ", id=" + id + ", isDefault=" + isDefault + ", name=" + name
|
||||
+ ", privateKey=" + (privateKey != null) + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* A network that is available in a vDC.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface Network extends ReferenceType {
|
||||
/**
|
||||
*
|
||||
* @return Description of the network
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return The IP address of the network primary gateway
|
||||
*/
|
||||
String getGateway();
|
||||
|
||||
/**
|
||||
* *
|
||||
*
|
||||
* @return the network subnet mask
|
||||
*/
|
||||
String getNetmask();
|
||||
|
||||
/**
|
||||
* return the network fence mode.
|
||||
*/
|
||||
FenceMode getFenceMode();
|
||||
|
||||
ReferenceType getNetworkExtension();
|
||||
|
||||
ReferenceType getIps();
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* @author Seshu Pasam
|
||||
*/
|
||||
public class NetworkAdapter implements Comparable<NetworkAdapter> {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromNetworkAdapter(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String macAddress;
|
||||
private String name;
|
||||
private Subnet subnet;
|
||||
|
||||
public Builder macAddress(String macAddress) {
|
||||
this.macAddress = macAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder subnet(Subnet subnet) {
|
||||
this.subnet = subnet;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NetworkAdapter build() {
|
||||
return new NetworkAdapter(macAddress, name, subnet);
|
||||
}
|
||||
|
||||
public Builder fromNetworkAdapter(NetworkAdapter in) {
|
||||
return macAddress(in.getMacAddress()).name(in.getName()).subnet(in.getSubnet());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final String macAddress;
|
||||
private final String name;
|
||||
private final Subnet subnet;
|
||||
|
||||
public NetworkAdapter(String macAddress, String name, Subnet subnet) {
|
||||
this.macAddress = macAddress;
|
||||
this.name = name;
|
||||
this.subnet = subnet;
|
||||
}
|
||||
|
||||
public int compareTo(NetworkAdapter that) {
|
||||
return (this == that) ? 0 : getMacAddress().compareTo(that.getMacAddress());
|
||||
}
|
||||
|
||||
public String getMacAddress() {
|
||||
return macAddress;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Subnet getSubnet() {
|
||||
return subnet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
NetworkAdapter that = NetworkAdapter.class.cast(o);
|
||||
return equal(this.macAddress, that.macAddress) && equal(this.name, that.name) && equal(this.subnet, that.subnet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(macAddress, name, subnet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("").add("macAddress", macAddress).add("name", name).add("subnet", subnet)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NetworkExtendedInfo implements Comparable<NetworkExtendedInfo> {
|
||||
public enum Type {
|
||||
INTERNAL, DMZ, UNRECOGNIZED;
|
||||
public static Type fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final URI href;
|
||||
private final String name;
|
||||
private final String rnatAddress;
|
||||
private final String address;
|
||||
private final String broadcastAddress;
|
||||
private final String gatewayAddress;
|
||||
private final Type networkType;
|
||||
private final String vlan;
|
||||
private final String friendlyName;
|
||||
|
||||
public NetworkExtendedInfo(String id, URI href, String name, String rnatAddress, String address,
|
||||
String broadcastAddress, String gatewayAddress, Type networkType, String vlan, String friendlyName) {
|
||||
this.id = id;
|
||||
this.href = href;
|
||||
this.name = name;
|
||||
this.rnatAddress = rnatAddress;
|
||||
this.address = address;
|
||||
this.broadcastAddress = broadcastAddress;
|
||||
this.gatewayAddress = gatewayAddress;
|
||||
this.networkType = networkType;
|
||||
this.vlan = vlan;
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public int compareTo(NetworkExtendedInfo that) {
|
||||
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public URI getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRnatAddress() {
|
||||
return rnatAddress;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getBroadcastAddress() {
|
||||
return broadcastAddress;
|
||||
}
|
||||
|
||||
public String getGatewayAddress() {
|
||||
return gatewayAddress;
|
||||
}
|
||||
|
||||
public Type getNetworkType() {
|
||||
return networkType;
|
||||
}
|
||||
|
||||
public String getVlan() {
|
||||
return vlan;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((address == null) ? 0 : address.hashCode());
|
||||
result = prime * result + ((broadcastAddress == null) ? 0 : broadcastAddress.hashCode());
|
||||
result = prime * result + ((friendlyName == null) ? 0 : friendlyName.hashCode());
|
||||
result = prime * result + ((gatewayAddress == null) ? 0 : gatewayAddress.hashCode());
|
||||
result = prime * result + ((href == null) ? 0 : href.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((networkType == null) ? 0 : networkType.hashCode());
|
||||
result = prime * result + ((rnatAddress == null) ? 0 : rnatAddress.hashCode());
|
||||
result = prime * result + ((vlan == null) ? 0 : vlan.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;
|
||||
NetworkExtendedInfo other = (NetworkExtendedInfo) obj;
|
||||
if (address == null) {
|
||||
if (other.address != null)
|
||||
return false;
|
||||
} else if (!address.equals(other.address))
|
||||
return false;
|
||||
if (broadcastAddress == null) {
|
||||
if (other.broadcastAddress != null)
|
||||
return false;
|
||||
} else if (!broadcastAddress.equals(other.broadcastAddress))
|
||||
return false;
|
||||
if (friendlyName == null) {
|
||||
if (other.friendlyName != null)
|
||||
return false;
|
||||
} else if (!friendlyName.equals(other.friendlyName))
|
||||
return false;
|
||||
if (gatewayAddress == null) {
|
||||
if (other.gatewayAddress != null)
|
||||
return false;
|
||||
} else if (!gatewayAddress.equals(other.gatewayAddress))
|
||||
return false;
|
||||
if (href == null) {
|
||||
if (other.href != null)
|
||||
return false;
|
||||
} else if (!href.equals(other.href))
|
||||
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 (networkType == null) {
|
||||
if (other.networkType != null)
|
||||
return false;
|
||||
} else if (!networkType.equals(other.networkType))
|
||||
return false;
|
||||
if (rnatAddress == null) {
|
||||
if (other.rnatAddress != null)
|
||||
return false;
|
||||
} else if (!rnatAddress.equals(other.rnatAddress))
|
||||
return false;
|
||||
if (vlan == null) {
|
||||
if (other.vlan != null)
|
||||
return false;
|
||||
} else if (!vlan.equals(other.vlan))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[address=" + address + ", broadcastAddress=" + broadcastAddress + ", friendlyName=" + friendlyName
|
||||
+ ", gatewayAddress=" + gatewayAddress + ", href=" + href + ", id=" + id + ", name=" + name
|
||||
+ ", networkType=" + networkType + ", rnatAddress=" + rnatAddress + ", vlan=" + vlan + "]";
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Node implements Comparable<Node> {
|
||||
private final String name;
|
||||
private final URI id;
|
||||
private final String ipAddress;
|
||||
private final int port;
|
||||
private final boolean enabled;
|
||||
private final String description;
|
||||
|
||||
public Node(String name, URI id, String ipAddress, int port, boolean enabled, String description) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.ipAddress = ipAddress;
|
||||
this.port = port;
|
||||
this.enabled = enabled;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public URI getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
public int compareTo(Node that) {
|
||||
return (this == that) ? 0 : getId().compareTo(that.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Node [id=" + id + ", name=" + name + ", description=" + description + ", ipAddress=" + ipAddress
|
||||
+ ", port=" + port + ", enabled=" + enabled + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + (enabled ? 1231 : 1237);
|
||||
result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + port;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Node other = (Node) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
return false;
|
||||
if (ipAddress == null) {
|
||||
if (other.ipAddress != null)
|
||||
return false;
|
||||
} else if (!ipAddress.equals(other.ipAddress))
|
||||
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 (port != other.port)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.OrgImpl;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Keys;
|
||||
|
||||
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
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(OrgImpl.class)
|
||||
public interface Org extends ReferenceType {
|
||||
/**
|
||||
* optional description
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
@Nullable
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
Map<String, ReferenceType> getCatalogs();
|
||||
|
||||
/**
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
Map<String, ReferenceType> getVDCs();
|
||||
|
||||
/**
|
||||
* If there are any queued, running, or recently completed tasks owned by a
|
||||
* member of the organization, it also contains a TasksList.
|
||||
*
|
||||
* there are multiple tasks lists in a terremark org
|
||||
*
|
||||
*/
|
||||
Map<String, ReferenceType> getTasksLists();
|
||||
|
||||
@Keys
|
||||
ReferenceType getKeys();
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
/**
|
||||
*
|
||||
* Protocol for an {@link InternetService}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public enum Protocol {
|
||||
|
||||
FTP, HTTP, HTTPS, TCP, UDP, PPTP, IPSEC;
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class PublicIpAddress implements Comparable<PublicIpAddress> {
|
||||
private final String address;
|
||||
private final URI id;
|
||||
|
||||
public PublicIpAddress(String address, URI id) {
|
||||
this.address = address;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public URI getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int compareTo(PublicIpAddress that) {
|
||||
return (this == that) ? 0 : getId().compareTo(that.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((address == null) ? 0 : address.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.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;
|
||||
PublicIpAddress other = (PublicIpAddress) obj;
|
||||
if (address == null) {
|
||||
if (other.address != null)
|
||||
return false;
|
||||
} else if (!address.equals(other.address))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PublicIpAddress [address=" + address + ", id=" + id + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* Many container elements are populated with references to contained objects. Each reference
|
||||
* consists of a hyperlink, an optional media type, and a name.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@ImplementedBy(ReferenceTypeImpl.class)
|
||||
public interface ReferenceType extends Comparable<ReferenceType> {
|
||||
/**
|
||||
* @return hyperlink to the referenced object
|
||||
*/
|
||||
URI getHref();
|
||||
|
||||
/**
|
||||
* @return name of the referenced object.
|
||||
*
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return object type, expressed as the media type of the XML representing of the object
|
||||
* @see VCloudMediaType
|
||||
*/
|
||||
String getType();
|
||||
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Objects such as vAppTemplate, vApp, and Vm have a status attribute whose
|
||||
* value indicates the state of the object. Status for an object, such as a
|
||||
* vAppTemplate or vApp, whose Children (Vm objects) each have a status of their
|
||||
* own, is computed from the status of the Children.
|
||||
*
|
||||
* <h2>NOTE</h2>
|
||||
* <p/>
|
||||
* The deployment status of an object is indicated by the value of its deployed
|
||||
* attribute.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum Status {
|
||||
|
||||
/**
|
||||
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is unresolved.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
UNRESOLVED,
|
||||
/**
|
||||
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is resolved.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
RESOLVED,
|
||||
|
||||
/**
|
||||
* The {@link VApp} or {@link Vm} is suspended.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
SUSPENDED,
|
||||
/**
|
||||
* The {@link VApp} or {@link Vm} is powered on
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
ON,
|
||||
/**
|
||||
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is off.
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
OFF, UNRECOGNIZED, DEPLOYED;
|
||||
public String value() {
|
||||
switch (this) {
|
||||
case UNRESOLVED:
|
||||
return "0";
|
||||
case RESOLVED:
|
||||
return "1";
|
||||
case OFF:
|
||||
return "2";
|
||||
case SUSPENDED:
|
||||
return "3";
|
||||
case ON:
|
||||
return "4";
|
||||
default:
|
||||
return "7";
|
||||
}
|
||||
}
|
||||
|
||||
public static Status fromValue(String status) {
|
||||
try {
|
||||
return fromValue(Integer.parseInt(checkNotNull(status, "status")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
public static Status fromValue(int v) {
|
||||
switch (v) {
|
||||
case 0:
|
||||
return UNRESOLVED;
|
||||
case 1:
|
||||
return RESOLVED;
|
||||
case 2:
|
||||
return OFF;
|
||||
case 3:
|
||||
return SUSPENDED;
|
||||
case 4:
|
||||
return ON;
|
||||
case 7:
|
||||
return UNRECOGNIZED;
|
||||
default:
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* @author Seshu Pasam
|
||||
*/
|
||||
public class Subnet implements Comparable<Subnet> {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromSubnet(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private URI href;
|
||||
private String name;
|
||||
|
||||
public Builder href(URI href) {
|
||||
this.href = href;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Subnet build() {
|
||||
return new Subnet(href, name);
|
||||
}
|
||||
|
||||
public Builder fromSubnet(Subnet in) {
|
||||
return href(in.getHref()).name(in.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final URI href;
|
||||
private final String name;
|
||||
|
||||
public Subnet(URI href, String name) {
|
||||
this.href = href;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int compareTo(Subnet that) {
|
||||
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||
}
|
||||
|
||||
public URI getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Subnet that = Subnet.class.cast(o);
|
||||
return equal(this.href, that.href) && equal(this.name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(href, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("").add("href", href).add("name", name).toString();
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.TaskImpl;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* Whenever the result of a request cannot be returned immediately, the server creates a Task
|
||||
* object. Tasks owned by an object such as a vApp or vDC are contained in the Tasks element of the
|
||||
* object's XML representation. This element is read-only.
|
||||
*/
|
||||
@ImplementedBy(TaskImpl.class)
|
||||
public interface Task extends ReferenceType {
|
||||
/**
|
||||
* The current status of the task.
|
||||
*/
|
||||
String getOperation();
|
||||
|
||||
/**
|
||||
* The current status of the task.
|
||||
*/
|
||||
TaskStatus getStatus();
|
||||
|
||||
/**
|
||||
* date and time when the task was started.
|
||||
*/
|
||||
Date getStartTime();
|
||||
|
||||
/**
|
||||
* date and time when the task completed. Does not appear for running tasks.
|
||||
*/
|
||||
Date getEndTime();
|
||||
|
||||
/**
|
||||
* date and time at which the task expires. By default, tasks expire 24 hours after their start
|
||||
* time. Expired tasks cannot be queried.
|
||||
*/
|
||||
Date getExpiryTime();
|
||||
|
||||
/**
|
||||
* A link to the object that owns the task. For copy operations, the owner is the copy that is
|
||||
* being created. For delete operations, the owner is the deleted object, so this element is not
|
||||
* included. For all other operations, the owner is the object to which the request was made.
|
||||
*/
|
||||
ReferenceType getOwner();
|
||||
|
||||
/**
|
||||
* error message or related information returned by the task
|
||||
*/
|
||||
@Nullable
|
||||
VCloudError getError();
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum TaskStatus {
|
||||
/**
|
||||
* The task has completed and returned a value indicating success.
|
||||
*/
|
||||
SUCCESS,
|
||||
/**
|
||||
* The task is running.
|
||||
*/
|
||||
RUNNING,
|
||||
|
||||
/**
|
||||
* The task has been queued for execution.
|
||||
*/
|
||||
QUEUED,
|
||||
/**
|
||||
* The task has completed and returned a value indicating an error.
|
||||
*/
|
||||
ERROR,
|
||||
/**
|
||||
* not an official status, temporarily in.
|
||||
*/
|
||||
CANCELLED, UNRECOGNIZED;
|
||||
public String value() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static TaskStatus fromValue(String status) {
|
||||
if ("CANCELED".equals(status.toUpperCase())) {
|
||||
// TODO: ecloud hack
|
||||
status = "CANCELLED";
|
||||
} else if ("FAILED".equals(status.toUpperCase())) {
|
||||
status = "ERROR";
|
||||
} else if ("COMPLETED".equals(status.toUpperCase())) {
|
||||
status = "SUCCESS";
|
||||
}
|
||||
try {
|
||||
return valueOf(checkNotNull(status, "status").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.TasksListImpl;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.TasksList
|
||||
@ImplementedBy(TasksListImpl.class)
|
||||
public interface TasksList {
|
||||
|
||||
URI getLocation();
|
||||
|
||||
SortedSet<Task> getTasks();
|
||||
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cim.ResourceAllocationSettingData;
|
||||
import org.jclouds.cim.VirtualSystemSettingData;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl;
|
||||
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* A virtual application (vApp) is a software solution, packaged in OVF containing one or more
|
||||
* virtual machines. A vApp can be authored by Developers at ISVs and VARs or by IT Administrators
|
||||
* in Enterprises and Service Providers.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(VAppImpl.class)
|
||||
public interface VApp extends ReferenceType {
|
||||
ReferenceType getVDC();
|
||||
|
||||
Set<ReferenceType> getExtendedInfo();
|
||||
|
||||
Status getStatus();
|
||||
|
||||
Long getSize();
|
||||
|
||||
ListMultimap<String, String> getNetworkToAddresses();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return CIM OSType of the image or null, if this information isn't available yet
|
||||
* @see <a href="http://dmtf.org/standards/cim/cim_schema_v2260">DMTF CIM model</a>
|
||||
*/
|
||||
@Nullable
|
||||
Integer getOsType();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return description or null, if this information isn't available yet
|
||||
*/
|
||||
@Nullable
|
||||
String getOperatingSystemDescription();
|
||||
|
||||
VirtualSystemSettingData getSystem();
|
||||
|
||||
Set<ResourceAllocationSettingData> getResourceAllocations();
|
||||
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class VAppConfiguration {
|
||||
private String name = null;
|
||||
private Integer processorCount = null;
|
||||
private Long memory = null;
|
||||
private List<Long> disks = Lists.newArrayList();
|
||||
private List<Integer> disksToDelete = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* The vApp name
|
||||
*
|
||||
*/
|
||||
public VAppConfiguration changeNameTo(String name) {
|
||||
this.name = checkNotNull(emptyToNull(name), "name must be defined");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* the number of virtual CPUs.
|
||||
*/
|
||||
public VAppConfiguration changeProcessorCountTo(int cpus) {
|
||||
checkArgument(cpus >= 1, "cpu count must be positive");
|
||||
this.processorCount = cpus;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* number of MB of memory.
|
||||
*/
|
||||
public VAppConfiguration changeMemoryTo(long megabytes) {
|
||||
checkArgument(megabytes >= 1, "megabytes must be positive");
|
||||
this.memory = megabytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To define a new disk, all you need to define is the size of the disk. The allowed values are a
|
||||
* multiple of 1048576.
|
||||
*/
|
||||
public VAppConfiguration addDisk(long kilobytes) {
|
||||
checkArgument(kilobytes > 0, "kilobytes must be positive");
|
||||
checkArgument(kilobytes % 1048576 == 0, "disk must be an interval of 1048576");
|
||||
this.disks.add(kilobytes);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To remove a disk, you specify its addressOnParent.
|
||||
*
|
||||
* Ex.
|
||||
*
|
||||
* <pre>
|
||||
* Set<ResourceAllocation> disks = Sets.newLinkedHashSet(vApp.getResourceAllocationByType().get(
|
||||
* ResourceType.DISK_DRIVE));
|
||||
* ResourceAllocation lastDisk = disks.last();
|
||||
* VAppConfiguration config = deleteDiskWithAddressOnParent(lastDisk.getAddressOnParent());
|
||||
* </pre>
|
||||
*/
|
||||
public VAppConfiguration deleteDiskWithAddressOnParent(int addressOnParent) {
|
||||
checkArgument(addressOnParent > 0, "you cannot delete the system disk");
|
||||
disksToDelete.add(addressOnParent);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see VAppConfiguration#changeNameTo(String)
|
||||
*/
|
||||
public static VAppConfiguration changeNameTo(String name) {
|
||||
VAppConfiguration options = new VAppConfiguration();
|
||||
return options.changeNameTo(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VAppConfiguration#changeProcessorCountTo(int)
|
||||
*/
|
||||
public static VAppConfiguration changeProcessorCountTo(int cpus) {
|
||||
VAppConfiguration options = new VAppConfiguration();
|
||||
return options.changeProcessorCountTo(cpus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VAppConfiguration#changeMemoryTo(long)
|
||||
*/
|
||||
public static VAppConfiguration changeMemoryTo(long megabytes) {
|
||||
VAppConfiguration options = new VAppConfiguration();
|
||||
return options.changeMemoryTo(megabytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VAppConfiguration#addDisk(long)
|
||||
*/
|
||||
public static VAppConfiguration addDisk(long kilobytes) {
|
||||
VAppConfiguration options = new VAppConfiguration();
|
||||
return options.addDisk(kilobytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VAppConfiguration#deleteDiskWithAddressOnParent(int)
|
||||
*/
|
||||
public static VAppConfiguration deleteDiskWithAddressOnParent(int addressOnParent) {
|
||||
VAppConfiguration options = new VAppConfiguration();
|
||||
return options.deleteDiskWithAddressOnParent(addressOnParent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Integer getProcessorCount() {
|
||||
return processorCount;
|
||||
}
|
||||
|
||||
public Long getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
public List<Long> getDisks() {
|
||||
return disks;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<Integer> getDisksToDelete() {
|
||||
return disksToDelete;
|
||||
}
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author Seshu Pasam, Adrian Cole
|
||||
*/
|
||||
public class VAppExtendedInfo implements Comparable<VAppExtendedInfo> {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromVAppExtendedInfo(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String id;
|
||||
private URI href;
|
||||
private String name;
|
||||
private String longName;
|
||||
private List<String> tags = Lists.newArrayList();
|
||||
private List<NetworkAdapter> networkAdapters = Lists.newArrayList();
|
||||
private ComputePoolReference computePoolReference;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder href(URI href) {
|
||||
this.href = href;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder longName(String longName) {
|
||||
this.longName = longName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder tags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder networkAdapters(List<NetworkAdapter> networkAdapters) {
|
||||
this.networkAdapters = networkAdapters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder networkAdapter(NetworkAdapter networkAdapter) {
|
||||
this.networkAdapters.add(networkAdapter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder computePoolReference(ComputePoolReference computePoolReference) {
|
||||
this.computePoolReference = computePoolReference;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VAppExtendedInfo build() {
|
||||
return new VAppExtendedInfo(id, href, name, tags, longName, networkAdapters, computePoolReference);
|
||||
}
|
||||
|
||||
public Builder fromVAppExtendedInfo(VAppExtendedInfo in) {
|
||||
return id(in.getId()).href(in.getHref()).name(in.getName()).longName(in.getLongName()).tags(in.getTags())
|
||||
.networkAdapters(in.getNetworkAdapters()).computePoolReference(in.getComputePoolReference());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final URI href;
|
||||
private final String name;
|
||||
private final String longName;
|
||||
private final List<String> tags;
|
||||
private final List<NetworkAdapter> networkAdapters;
|
||||
private final ComputePoolReference computePoolReference;
|
||||
|
||||
public VAppExtendedInfo(String id, URI href, String name, List<String> tags, String longName,
|
||||
List<NetworkAdapter> networkAdapters, ComputePoolReference computePoolReference) {
|
||||
this.id = id;
|
||||
this.href = href;
|
||||
this.name = name;
|
||||
this.tags = tags;
|
||||
this.longName = longName;
|
||||
this.networkAdapters = networkAdapters;
|
||||
this.computePoolReference = computePoolReference;
|
||||
}
|
||||
|
||||
public int compareTo(VAppExtendedInfo that) {
|
||||
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public URI getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getLongName() {
|
||||
return longName;
|
||||
}
|
||||
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public List<NetworkAdapter> getNetworkAdapters() {
|
||||
return networkAdapters;
|
||||
}
|
||||
|
||||
public ComputePoolReference getComputePoolReference() {
|
||||
return computePoolReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
VAppExtendedInfo that = VAppExtendedInfo.class.cast(o);
|
||||
return equal(this.id, that.id) && equal(this.href, that.href) && equal(this.name, that.name)
|
||||
&& equal(this.longName, that.longName) && equal(this.tags, that.tags)
|
||||
&& equal(this.networkAdapters, that.networkAdapters)
|
||||
&& equal(this.computePoolReference, that.computePoolReference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(id, href, name, longName, tags, networkAdapters, computePoolReference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("").add("id", id).add("href", href).add("name", name).add("longName", longName)
|
||||
.add("tags", tags).add("networkAdapters", networkAdapters).add("computePoolReference",
|
||||
computePoolReference).toString();
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface VAppTemplate extends ReferenceType {
|
||||
|
||||
Status getStatus();
|
||||
|
||||
String getDescription();
|
||||
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.ErrorImpl;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(ErrorImpl.class)
|
||||
public interface VCloudError {
|
||||
public static enum MinorCode {
|
||||
/**
|
||||
* The request was made by a user who had insufficient rights to the object or operation.
|
||||
*/
|
||||
ACCESS_TO_RESOURCE_IS_FORBIDDEN,
|
||||
/**
|
||||
* The request could not be validated or contained invalid XML.
|
||||
*/
|
||||
BAD_REQUEST,
|
||||
/**
|
||||
* A conflict was detected between sections of an OVF descriptor.
|
||||
*/
|
||||
CONFLICT,
|
||||
/**
|
||||
* The entity is busy
|
||||
*/
|
||||
BUSY_ENTITY,
|
||||
/**
|
||||
* An attempt to instantiate a vAppTemplate or use a vAppTemplate or a Vm in a composition did
|
||||
* not include an AllEULAsAccepted element with a value of true.
|
||||
*/
|
||||
EULA_NOT_ACCEPTED,
|
||||
/**
|
||||
* Returned for any failure that cannot be matched to another minor error code.
|
||||
*/
|
||||
INTERNAL_SERVER_ERROR,
|
||||
/**
|
||||
* One or more references (href attribute values) supplied in the request could not be
|
||||
* resolved to an object.
|
||||
*/
|
||||
INVALID_REFERENCE,
|
||||
/**
|
||||
* The HTTP method (GET, PUT, POST, DELETE) is not allowed for the request.
|
||||
*/
|
||||
METHOD_NOT_ALLOWED,
|
||||
/**
|
||||
* One or more references (href attribute values) supplied in the request could not be
|
||||
* resolved to an object, or the Content-type of the request was incorrect.
|
||||
*/
|
||||
RESOURCE_NOT_FOUND,
|
||||
/**
|
||||
* The request raised an exception that did not match any HTTP status code.
|
||||
*/
|
||||
UNKNOWN,
|
||||
/**
|
||||
* The wrong content type was specified for the request.
|
||||
*/
|
||||
UNSUPPORTED_MEDIA_TYPE, UNRECOGNIZED;
|
||||
|
||||
public static MinorCode fromValue(String minorCode) {
|
||||
try {
|
||||
return valueOf(checkNotNull(minorCode, "minorCode"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return message describing the error
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return matches the HTTP status code
|
||||
*/
|
||||
int getMajorErrorCode();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return error code specific to the failed operation or null if vcloud <0.9
|
||||
*/
|
||||
@Nullable
|
||||
MinorCode getMinorErrorCode();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return optional additional information about the source of the error
|
||||
*/
|
||||
@Nullable
|
||||
String getVendorSpecificErrorCode();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return stack trace of the error, if available. This attribute is returned only when a request
|
||||
* is made by the system administrator.
|
||||
*/
|
||||
String getStackTrace();
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface VCloudSession {
|
||||
String getVCloudToken();
|
||||
|
||||
Map<String, ReferenceType> getOrgs();
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.internal.VDCImpl;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.InternetServices;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.PublicIPs;
|
||||
|
||||
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.trmk.vcloud_0_8.endpoints.VDC
|
||||
@ImplementedBy(VDCImpl.class)
|
||||
public interface VDC extends ReferenceType {
|
||||
@Nullable
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* container for ResourceEntity elements
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
Map<String, ReferenceType> getResourceEntities();
|
||||
|
||||
/**
|
||||
* container for OrgNetwork elements that represent organization networks
|
||||
* contained by the vDC
|
||||
*
|
||||
* @since vcloud api 0.8
|
||||
*/
|
||||
Map<String, ReferenceType> getAvailableNetworks();
|
||||
|
||||
@Catalog
|
||||
ReferenceType getCatalog();
|
||||
|
||||
@PublicIPs
|
||||
ReferenceType getPublicIps();
|
||||
|
||||
@InternetServices
|
||||
ReferenceType getInternetServices();
|
||||
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
|
||||
/**
|
||||
* Locations of resources in vCloud
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements Catalog {
|
||||
|
||||
private final String name;
|
||||
private final String type;
|
||||
private final URI href;
|
||||
@Nullable
|
||||
private final String description;
|
||||
|
||||
public CatalogImpl(String name, String type, URI href, @Nullable String description,
|
||||
Map<String, ReferenceType> contents) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.type = checkNotNull(type, "type");
|
||||
this.description = description;
|
||||
this.href = checkNotNull(href, "href");
|
||||
putAll(checkNotNull(contents, "contents"));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public URI getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((href == null) ? 0 : href.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
CatalogImpl other = (CatalogImpl) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (href == null) {
|
||||
if (other.href != null)
|
||||
return false;
|
||||
} else if (!href.equals(other.href))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (type == null) {
|
||||
if (other.type != null)
|
||||
return false;
|
||||
} else if (!type.equals(other.type))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ReferenceType o) {
|
||||
return (this == o) ? 0 : getHref().compareTo(o.getHref());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
|
||||
|
||||
protected final String description;
|
||||
protected final ReferenceType entity;
|
||||
protected final Map<String, String> properties = Maps.newLinkedHashMap();
|
||||
private final ReferenceType computeOptions;
|
||||
private final ReferenceType customizationOptions;
|
||||
|
||||
public CatalogItemImpl(String name, URI id, String description, ReferenceType computeOptions,
|
||||
ReferenceType customizationOptions, ReferenceType entity, Map<String, String> properties) {
|
||||
super(name, TerremarkVCloudMediaType.CATALOGITEM_XML, id);
|
||||
this.description = description;
|
||||
this.entity = checkNotNull(entity, "entity");
|
||||
this.properties.putAll(checkNotNull(properties, "properties"));
|
||||
this.computeOptions = computeOptions;
|
||||
this.customizationOptions = customizationOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TerremarkVCloudMediaType.CATALOGITEM_XML;
|
||||
}
|
||||
|
||||
public ReferenceType getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType getComputeOptions() {
|
||||
return computeOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType getCustomizationOptions() {
|
||||
return customizationOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + getDescription()
|
||||
+ ", entity=" + entity + ", computeOptions=" + computeOptions + ", customizationOptions="
|
||||
+ customizationOptions + ", properties=" + properties + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((entity == null) ? 0 : entity.hashCode());
|
||||
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
|
||||
result = prime * result + ((computeOptions == null) ? 0 : computeOptions.hashCode());
|
||||
result = prime * result + ((customizationOptions == null) ? 0 : customizationOptions.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
CatalogItemImpl other = (CatalogItemImpl) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (entity == null) {
|
||||
if (other.entity != null)
|
||||
return false;
|
||||
} else if (!entity.equals(other.entity))
|
||||
return false;
|
||||
if (properties == null) {
|
||||
if (other.properties != null)
|
||||
return false;
|
||||
} else if (!properties.equals(other.properties))
|
||||
return false;
|
||||
if (computeOptions == null) {
|
||||
if (other.computeOptions != null)
|
||||
return false;
|
||||
} else if (!computeOptions.equals(other.computeOptions))
|
||||
return false;
|
||||
if (customizationOptions == null) {
|
||||
if (other.customizationOptions != null)
|
||||
return false;
|
||||
} else if (!customizationOptions.equals(other.customizationOptions))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VCloudError;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class ErrorImpl implements VCloudError {
|
||||
private final String message;
|
||||
private final int majorErrorCode;
|
||||
private final MinorCode minorErrorCode;
|
||||
@Nullable
|
||||
private final String vendorSpecificErrorCode;
|
||||
@Nullable
|
||||
private final String stackTrace;
|
||||
|
||||
public ErrorImpl(String message, int majorErrorCode, @Nullable MinorCode minorErrorCode,
|
||||
@Nullable String vendorSpecificErrorCode, @Nullable String stackTrace) {
|
||||
this.message = checkNotNull(message, "message");
|
||||
this.majorErrorCode = majorErrorCode;
|
||||
this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone
|
||||
this.vendorSpecificErrorCode = vendorSpecificErrorCode;
|
||||
this.stackTrace = stackTrace;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public int getMajorErrorCode() {
|
||||
return majorErrorCode;
|
||||
}
|
||||
|
||||
public MinorCode getMinorErrorCode() {
|
||||
return minorErrorCode;
|
||||
}
|
||||
|
||||
public String getVendorSpecificErrorCode() {
|
||||
return vendorSpecificErrorCode;
|
||||
}
|
||||
|
||||
public String getStackTrace() {
|
||||
return stackTrace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + majorErrorCode;
|
||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||
result = prime * result + ((minorErrorCode == null) ? 0 : minorErrorCode.hashCode());
|
||||
result = prime * result + ((stackTrace == null) ? 0 : stackTrace.hashCode());
|
||||
result = prime * result + ((vendorSpecificErrorCode == null) ? 0 : vendorSpecificErrorCode.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;
|
||||
ErrorImpl other = (ErrorImpl) obj;
|
||||
if (majorErrorCode != other.majorErrorCode)
|
||||
return false;
|
||||
if (message == null) {
|
||||
if (other.message != null)
|
||||
return false;
|
||||
} else if (!message.equals(other.message))
|
||||
return false;
|
||||
if (minorErrorCode == null) {
|
||||
if (other.minorErrorCode != null)
|
||||
return false;
|
||||
} else if (!minorErrorCode.equals(other.minorErrorCode))
|
||||
return false;
|
||||
if (stackTrace == null) {
|
||||
if (other.stackTrace != null)
|
||||
return false;
|
||||
} else if (!stackTrace.equals(other.stackTrace))
|
||||
return false;
|
||||
if (vendorSpecificErrorCode == null) {
|
||||
if (other.vendorSpecificErrorCode != null)
|
||||
return false;
|
||||
} else if (!vendorSpecificErrorCode.equals(other.vendorSpecificErrorCode))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[majorErrorCode=" + majorErrorCode + ", message=" + message + ", minorErrorCode=" + minorErrorCode
|
||||
+ ", stackTrace=" + stackTrace + ", vendorSpecificErrorCode=" + vendorSpecificErrorCode + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.FenceMode;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Network;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
|
||||
/**
|
||||
* Locations of resources in vCloud
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class NetworkImpl extends ReferenceTypeImpl implements Network {
|
||||
|
||||
protected final String description;
|
||||
protected final String gateway;
|
||||
protected final String netmask;
|
||||
protected final FenceMode fenceMode;
|
||||
protected final ReferenceType networkExtension;
|
||||
protected final ReferenceType ips;
|
||||
|
||||
public NetworkImpl(String name, String type, URI id, String description, String gateway, String netmask,
|
||||
FenceMode fenceMode, ReferenceType networkExtension, ReferenceType ips) {
|
||||
super(name, type, id);
|
||||
this.description = description;
|
||||
this.gateway = gateway;
|
||||
this.netmask = netmask;
|
||||
this.fenceMode = fenceMode;
|
||||
this.networkExtension = networkExtension;
|
||||
this.ips = ips;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public FenceMode getFenceMode() {
|
||||
return fenceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ReferenceType getIps() {
|
||||
return ips;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ReferenceType getNetworkExtension() {
|
||||
return networkExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(ReferenceType o) {
|
||||
return (this == o) ? 0 : getHref().compareTo(o.getHref());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Locations of resources in vCloud
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class OrgImpl extends ReferenceTypeImpl implements Org {
|
||||
@Nullable
|
||||
private final String description;
|
||||
private final Map<String, ReferenceType> catalogs;
|
||||
private final Map<String, ReferenceType> vdcs;
|
||||
private final ReferenceType keys;
|
||||
private final ImmutableMap<String, ReferenceType> tasksLists;
|
||||
|
||||
public OrgImpl(String name, String type, URI id, String description, Map<String, ReferenceType> catalogs,
|
||||
Map<String, ReferenceType> vdcs, Map<String, ReferenceType> tasksLists, ReferenceType keys) {
|
||||
super(name, type, id);
|
||||
this.description = description;
|
||||
this.catalogs = ImmutableMap.copyOf(checkNotNull(catalogs, "catalogs"));
|
||||
this.vdcs = ImmutableMap.copyOf(checkNotNull(vdcs, "vdcs"));
|
||||
this.tasksLists = ImmutableMap.copyOf(checkNotNull(tasksLists, "tasksLists"));
|
||||
this.keys = checkNotNull(keys, "keys");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> getCatalogs() {
|
||||
return catalogs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> getVDCs() {
|
||||
return vdcs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((keys == null) ? 0 : keys.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 (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
OrgImpl other = (OrgImpl) obj;
|
||||
if (catalogs == null) {
|
||||
if (other.catalogs != null)
|
||||
return false;
|
||||
} else if (!catalogs.equals(other.catalogs))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (keys == null) {
|
||||
if (other.keys != null)
|
||||
return false;
|
||||
} else if (!keys.equals(other.keys))
|
||||
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 int compareTo(ReferenceType o) {
|
||||
return (this == o) ? 0 : getHref().compareTo(o.getHref());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
|
||||
+ ", catalogs=" + catalogs + ", tasksLists=" + tasksLists + ", vdcs=" + vdcs + ", keys=" + keys + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> getTasksLists() {
|
||||
return tasksLists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
|
||||
/**
|
||||
* Location of a Rest resource
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class ReferenceTypeImpl implements ReferenceType {
|
||||
private final String name;
|
||||
private final String type;
|
||||
private final URI href;
|
||||
|
||||
public ReferenceTypeImpl(String name, String type, URI href) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ReferenceType that) {
|
||||
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((href == null) ? 0 : href.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.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;
|
||||
ReferenceTypeImpl other = (ReferenceTypeImpl) obj;
|
||||
if (href == null) {
|
||||
if (other.href != null)
|
||||
return false;
|
||||
} else if (!href.equals(other.href))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (type == null) {
|
||||
if (other.type != null)
|
||||
return false;
|
||||
} else if (!type.equals(other.type))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[href=" + href + ", name=" + name + ", type=" + type + "]";
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Task;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.TaskStatus;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.VCloudError;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class TaskImpl extends ReferenceTypeImpl implements Task {
|
||||
|
||||
private final String operation;
|
||||
private final TaskStatus status;
|
||||
private final Date startTime;
|
||||
@Nullable
|
||||
private final Date endTime;
|
||||
@Nullable
|
||||
private final Date expiryTime;
|
||||
private final ReferenceType owner;
|
||||
@Nullable
|
||||
private final VCloudError error;
|
||||
|
||||
public TaskImpl(URI id, String operation, TaskStatus status, Date startTime, @Nullable Date endTime,
|
||||
@Nullable Date expiryTime, ReferenceType owner, VCloudError error) {
|
||||
super(null, TerremarkVCloudMediaType.TASK_XML, id);
|
||||
this.operation = operation;
|
||||
this.status = checkNotNull(status, "status");
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.expiryTime = expiryTime;
|
||||
this.owner = owner;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VCloudError getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskImpl [endTime=" + endTime + ", error=" + error + ", expiryTime=" + expiryTime + ", operation="
|
||||
+ operation + ", owner=" + owner + ", startTime=" + startTime + ", status=" + status + ", getHref()="
|
||||
+ getHref() + ", getName()=" + getName() + ", getType()=" + getType() + ", toString()="
|
||||
+ super.toString() + ", getClass()=" + getClass() + "]";
|
||||
}
|
||||
|
||||
public Date getExpiryTime() {
|
||||
return expiryTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
|
||||
result = prime * result + ((error == null) ? 0 : error.hashCode());
|
||||
result = prime * result + ((expiryTime == null) ? 0 : expiryTime.hashCode());
|
||||
result = prime * result + ((operation == null) ? 0 : operation.hashCode());
|
||||
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
||||
result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
|
||||
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TaskImpl other = (TaskImpl) obj;
|
||||
if (endTime == null) {
|
||||
if (other.endTime != null)
|
||||
return false;
|
||||
} else if (!endTime.equals(other.endTime))
|
||||
return false;
|
||||
if (error == null) {
|
||||
if (other.error != null)
|
||||
return false;
|
||||
} else if (!error.equals(other.error))
|
||||
return false;
|
||||
if (expiryTime == null) {
|
||||
if (other.expiryTime != null)
|
||||
return false;
|
||||
} else if (!expiryTime.equals(other.expiryTime))
|
||||
return false;
|
||||
if (operation == null) {
|
||||
if (other.operation != null)
|
||||
return false;
|
||||
} else if (!operation.equals(other.operation))
|
||||
return false;
|
||||
if (owner == null) {
|
||||
if (other.owner != null)
|
||||
return false;
|
||||
} else if (!owner.equals(other.owner))
|
||||
return false;
|
||||
if (startTime == null) {
|
||||
if (other.startTime != null)
|
||||
return false;
|
||||
} else if (!startTime.equals(other.startTime))
|
||||
return false;
|
||||
if (status == null) {
|
||||
if (other.status != null)
|
||||
return false;
|
||||
} else if (!status.equals(other.status))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.trmk.vcloud_0_8.domain.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Task;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.TasksList;
|
||||
|
||||
/**
|
||||
* Locations of resources in vCloud
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class TasksListImpl implements TasksList {
|
||||
private final SortedSet<Task> tasks;
|
||||
private final URI id;
|
||||
|
||||
public TasksListImpl(URI id, SortedSet<Task> tasks) {
|
||||
this.id = id;
|
||||
this.tasks = tasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Task> getTasks() {
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getLocation() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((tasks == null) ? 0 : tasks.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;
|
||||
TasksListImpl other = (TasksListImpl) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (tasks == null) {
|
||||
if (other.tasks != null)
|
||||
return false;
|
||||
} else if (!tasks.equals(other.tasks))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue