Issue 634: unhook trmk from vcloud 1.0 implementation

This commit is contained in:
Adrian Cole 2011-07-23 11:17:38 +10:00
parent a365e7de2c
commit fcc9e30832
154 changed files with 12893 additions and 9 deletions

View File

@ -37,10 +37,15 @@
<dependencies>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>vcloud-common</artifactId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId>
<version>0.3</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
@ -55,13 +60,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>vcloud-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>

View File

@ -0,0 +1,212 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameNetworkNameToEndpoint;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.OrgNetworkHandler;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VDCHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface CommonVCloudAsyncClient {
/**
* @see CommonVCloudClient#getOrg
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Org> getOrg(@EndpointParam URI orgId);
/**
* @see CommonVCloudClient#getOrgNamed
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Org> findOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
* @see CommonVCloudClient#getCatalog
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see CommonVCloudClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see CommonVCloudClient#getCatalogItem
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see CommonVCloudClient#getCatalogItemInOrg
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
/**
* @see CommonVCloudClient#findNetworkInOrgVDCNamed
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String networkName);
/**
* @see CommonVCloudClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
/**
* @see CommonVCloudClient#getVDC(URI)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see CommonVCloudClient#findVDCInOrgNamed(String, String)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see CommonVCloudClient#getTasksList
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
/**
* @see CommonVCloudClient#findTasksListInOrgNamed
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName);
/**
* @see CommonVCloudClient#getTask
*/
@GET
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
/**
* @see CommonVCloudClient#cancelTask
*/
@POST
@Path("/action/cancel")
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
}

View File

@ -0,0 +1,128 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.network.OrgNetwork;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface CommonVCloudClient {
Org getOrg(URI orgId);
/**
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within
* the organization.
*
* @param name
* organization name, or null for the default
* @throws NoSuchElementException
* if you specified an org name that isn't present
*/
Org findOrgNamed(@Nullable String name);
Catalog getCatalog(URI catalogId);
/**
* returns the catalog in the organization associated with the specified name. Note that both
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or catalog name that isn't present
*/
Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName);
CatalogItem getCatalogItem(URI catalogItem);
/**
* returns the catalog item in the catalog associated with the specified name. Note that the org
* and catalog parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that isn't present
*/
CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName);
OrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
OrgNetwork getNetwork(URI network);
VDC getVDC(URI vdc);
/**
* returns the VDC in the organization associated with the specified name. Note that both
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param vdcName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or vdc name that isn't present
*/
VDC findVDCInOrgNamed(String orgName, String vdcName);
TasksList getTasksList(URI tasksListId);
TasksList findTasksListInOrgNamed(String orgName);
/**
* Whenever the result of a request cannot be returned immediately, the server creates a Task
* object and includes it in the response, as a member of the Tasks container in the response
* body. Each Task has an href value, which is a URL that the client can use to retrieve the Task
* element alone, without the rest of the response in which it was contained. All information
* about the task is included in the Task element when it is returned in the responses Tasks
* container, so a client does not need to make an additional request to the Task URL unless it
* wants to follow the progress of a task that was incomplete.
*/
Task getTask(URI taskId);
void cancelTask(URI taskId);
}

View File

@ -0,0 +1,52 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Establishes a context with a VCloud endpoint.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Endpoint(org.jclouds.vcloud.endpoints.VCloudLogin.class)
@RequestFilters(BasicAuthentication.class)
public interface VCloudLoginAsyncClient {
/**
* This request returns a token to use in subsequent requests. After 30 minutes of inactivity,
* the token expires and you have to request a new token with this call.
*/
@POST
@ResponseParser(ParseLoginResponseFromHeaders.class)
@Consumes(VCloudMediaType.ORGLIST_XML)
ListenableFuture<VCloudSession> login();
}

View File

@ -0,0 +1,214 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import javax.ws.rs.core.MediaType;
/**
* Resource Types used in VCloud
*
* @see MediaType
*/
public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.error+xml"
*/
public final static String ERROR_XML = "application/vnd.vmware.vcloud.error+xml";
/**
* "application/vnd.vmware.vcloud.error+xml"
*/
public final static MediaType ERROR_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.error+xml");
/**
* "application/vnd.vmware.vcloud.vcloud+xml"
*/
public final static String VCLOUD_XML = "application/vnd.vmware.vcloud.vcloud+xml";
/**
* "application/vnd.vmware.vcloud.vcloud+xml"
*/
public final static MediaType VCLOUD_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vcloud+xml");
/**
* "application/vnd.vmware.vcloud.orgList+xml"
*/
public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml";
/**
* "application/vnd.vmware.vcloud.orgList+xml"
*/
public final static MediaType ORGLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.orgList+xml");
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
public final static String ORG_XML = "application/vnd.vmware.vcloud.org+xml";
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
public final static MediaType ORG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.org+xml");
/**
* "application/vnd.vmware.vcloud.vdc+xml"
*/
public final static String VDC_XML = "application/vnd.vmware.vcloud.vdc+xml";
/**
* "application/vnd.vmware.vcloud.vdc+xml"
*/
public final static MediaType VDC_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vdc+xml");
/**
* "application/vnd.vmware.vcloud.catalog+xml"
*/
public final static String CATALOG_XML = "application/vnd.vmware.vcloud.catalog+xml";
/**
* "application/vnd.vmware.vcloud.catalog+xml"
*/
public final static MediaType CATALOG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.catalog+xml");
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
*/
public final static String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml";
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
*/
public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml");
/**
* "application/vnd.vmware.vcloud.catalogItem+xml"
*/
public final static String CATALOGITEM_XML = "application/vnd.vmware.vcloud.catalogItem+xml";
/**
* "application/vnd.vmware.vcloud.catalogItem+xml"
*/
public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.catalogItem+xml");
/**
* "application/vnd.vmware.vcloud.networkConnectionSection+xml"
*/
public final static String NETWORKCONNECTIONSECTION_XML = "application/vnd.vmware.vcloud.networkConnectionSection+xml";
/**
* "application/vnd.vmware.vcloud.networkConnectionSection+xml"
*/
public final static MediaType NETWORKCONNECTIONSECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.networkConnectionSection+xml");
/**
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
*/
public final static String VIRTUALHARDWARESECTION_XML = "application/vnd.vmware.vcloud.virtualHardwareSection+xml";
/**
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
*/
public final static MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.virtualHardwareSection+xml");
/**
* "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
*/
public final static String GUESTCUSTOMIZATIONSECTION_XML = "application/vnd.vmware.vcloud.guestCustomizationSection+xml";
/**
* "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
*/
public final static MediaType GUESTCUSTOMIZATIONSECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.guestCustomizationSection+xml");
/**
* "application/vnd.vmware.vcloud.networkSection+xml"
*/
public final static String NETWORKSECTION_XML = "application/vnd.vmware.vcloud.networkSection+xml";
/**
* "application/vnd.vmware.vcloud.networkSection+xml"
*/
public final static MediaType NETWORKSECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.networkSection+xml");
/**
* "application/vnd.vmware.vcloud.task+xml"
*/
public final static String TASK_XML = "application/vnd.vmware.vcloud.task+xml";
/**
* "application/vnd.vmware.vcloud.task+xml"
*/
public final static MediaType TASK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.task+xml");
/**
* "application/vnd.vmware.vcloud.undeployVAppParams+xml"
*/
public final static String UNDEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.undeployVAppParams+xml";
/**
* "application/vnd.vmware.vcloud.undeployVAppParams+xml"
*/
public final static MediaType UNDEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.undeployVAppParams+xml");
/**
* "application/vnd.vmware.vcloud.deployVAppParams+xml"
*/
public final static String DEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.deployVAppParams+xml";
/**
* "application/vnd.vmware.vcloud.deployVAppParams+xml"
*/
public final static MediaType DEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.deployVAppParams+xml");
/**
* "application/vnd.vmware.vcloud.vApp+xml"
*/
public final static String VAPP_XML = "application/vnd.vmware.vcloud.vApp+xml";
/**
* "application/vnd.vmware.vcloud.vApp+xml"
*/
public final static MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml");
/**
* "application/vnd.vmware.vcloud.vm+xml"
*/
public final static String VM_XML = "application/vnd.vmware.vcloud.vm+xml";
/**
* "application/vnd.vmware.vcloud.vm+xml"
*/
public final static MediaType VM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vm+xml");
/**
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
*/
public final static String VAPPTEMPLATE_XML = "application/vnd.vmware.vcloud.vAppTemplate+xml";
/**
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
*/
public final static MediaType VAPPTEMPLATE_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.vAppTemplate+xml");
/**
* "application/vnd.vmware.vcloud.network+xml"
*/
public final static String NETWORK_XML = "application/vnd.vmware.vcloud.network+xml";
/**
* "application/vnd.vmware.vcloud.network+xml"
*/
public final static MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml");
/**
* "application/vnd.vmware.vcloud.rasdItem+xml"
*/
public final static String RASDITEM_XML = "application/vnd.vmware.vcloud.rasdItem+xml";
/**
* "application/vnd.vmware.vcloud.rasdItem+xml"
*/
public final static MediaType RASDITEM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.rasdItem+xml");
}

View File

@ -0,0 +1,73 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.vcloud.domain.VCloudError;
/**
* Encapsulates an VCloud Error.
*
* @author Adrian Cole
*
*/
public class VCloudResponseException extends HttpResponseException {
private static final long serialVersionUID = 1L;
private org.jclouds.vcloud.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;
}
}

View File

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

View File

@ -0,0 +1,48 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import java.net.URI;
import java.util.SortedMap;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Establishes a context with a VCloud endpoint.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
public interface VCloudVersionsAsyncClient {
/**
* Retrieve information for supported versions
*/
@GET
@XMLResponseParser(SupportedVersionsHandler.class)
@Path("/versions")
ListenableFuture<SortedMap<String, URI>> getSupportedVersions();
}

View File

@ -0,0 +1,61 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute;
import java.net.URI;
import java.util.Set;
/**
*
* @author Adrian Cole
*/
public interface CommonVCloudComputeClient {
/**
* returns a set of addresses that are only visible to the private network.
*/
Set<String> getPrivateAddresses(URI vAppId);
/**
* returns a set of addresses that are publically visible
*/
Set<String> getPublicAddresses(URI vAppId);
/**
* reboots the vApp, blocking until the following state transition is complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> {@code VAppStatus#ON}
*
* @param vAppId
* vApp to reboot
*/
void reset(URI vAppId);
/**
* Destroys dependent resources, powers off and deletes the vApp, blocking until the following
* state transition is complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> deleted
*
* @param vAppId
* vApp to stop
*/
void stop(URI vAppId);
}

View File

@ -0,0 +1,35 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.config;
import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
/**
* @author Adrian Cole
*/
public abstract class CommonVCloudBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override
protected Class<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
return CreateNodesWithGroupEncodedIntoNameThenAddToSet.class;
}
}

View File

@ -0,0 +1,105 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.find;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.StaticHardwareSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
public class CommonVCloudBindComputeSuppliersByClass extends BindComputeSuppliersByClass {
@Override
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
return StaticHardwareSupplier.class;
}
@Override
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
return VCloudImageSupplier.class;
}
@Override
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return OrgAndVDCToLocationSupplier.class;
}
@Override
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
return DefaultVDC.class;
}
@Singleton
public static class DefaultVDC implements Supplier<Location> {
@Singleton
public static final class IsDefaultVDC implements Predicate<Location> {
private final ReferenceType defaultVDC;
@Inject
IsDefaultVDC(@VDC ReferenceType defaultVDC) {
this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC");
}
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString());
}
@Override
public String toString() {
return "isDefaultVDC()";
}
}
private final Supplier<Set<? extends Location>> locationsSupplier;
private final IsDefaultVDC isDefaultVDC;
@Inject
DefaultVDC(@Memoized Supplier<Set<? extends Location>> locationsSupplier, IsDefaultVDC isDefaultVDC) {
this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier");
this.isDefaultVDC = checkNotNull(isDefaultVDC, "isDefaultVDC");
}
@Override
public Location get() {
return find(locationsSupplier.get(), isDefaultVDC);
}
}
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.config;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.domain.Status;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*
* @author Adrian Cole
*/
public abstract class CommonVCloudComputeServiceContextModule extends BaseComputeServiceContextModule {
@VisibleForTesting
public static final Map<Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap.<Status, NodeState> builder()
.put(Status.OFF, NodeState.SUSPENDED).put(Status.ON, NodeState.RUNNING)
.put(Status.RESOLVED, NodeState.PENDING).put(Status.ERROR, NodeState.ERROR)
.put(Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(Status.DEPLOYED, NodeState.PENDING)
.put(Status.INCONSISTENT, NodeState.PENDING).put(Status.UNKNOWN, NodeState.UNRECOGNIZED)
.put(Status.MIXED, NodeState.PENDING).put(Status.WAITING_FOR_INPUT, NodeState.PENDING)
.put(Status.SUSPENDED, NodeState.SUSPENDED).put(Status.UNRESOLVED, NodeState.PENDING).build();
@Singleton
@Provides
protected Map<Status, NodeState> provideVAppStatusToNodeState() {
return VAPPSTATUS_TO_NODESTATE;
}
@Override
protected void configure() {
super.configure();
install(defineComputeStrategyModule());
install(defineComputeSupplierModule());
}
public abstract BindComputeStrategiesByClass defineComputeStrategyModule();
public abstract BindComputeSuppliersByClass defineComputeSupplierModule();
}

View File

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

View File

@ -0,0 +1,123 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.internal;
import java.net.URI;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public abstract class CommonVCloudComputeClientImpl<T, A extends ReferenceType> implements CommonVCloudComputeClient {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final CommonVCloudClient client;
protected final Predicate<URI> taskTester;
@Inject
public CommonVCloudComputeClientImpl(CommonVCloudClient client, Predicate<URI> successTester) {
this.client = client;
this.taskTester = successTester;
}
@Override
public void reset(URI id) {
A vApp = refreshVApp(id);
logger.debug(">> resetting vApp(%s)", vApp.getName());
Task task = reset(vApp);
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "resetVApp", vApp.getName(), task));
}
logger.debug("<< on vApp(%s)", vApp.getName());
}
protected abstract Task reset(A vApp);
protected abstract A refreshVApp(URI id);
@Override
public void stop(URI id) {
A vApp = refreshVApp(id);
vApp = powerOffVAppIfDeployed(vApp);
vApp = undeployVAppIfDeployed(vApp);
deleteVApp(vApp);
logger.debug("<< deleted vApp(%s)", vApp.getName());
}
protected abstract void deleteVApp(A vApp);
private A undeployVAppIfDeployed(A vApp) {
if (getStatus(vApp).compareTo(Status.RESOLVED) > 0) {
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), getStatus(vApp));
Task task = undeploy(vApp);
if (!taskTester.apply(task.getHref())) {
// TODO timeout
throw new RuntimeException(String.format("failed to %s %s: %s", "undeploy", vApp.getName(), task));
}
vApp = refreshVApp(vApp.getHref());
logger.debug("<< %s vApp(%s)", getStatus(vApp), vApp.getName());
}
return vApp;
}
protected abstract Task undeploy(A vApp);
private A powerOffVAppIfDeployed(A vApp) {
if (getStatus(vApp).compareTo(Status.OFF) > 0) {
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), getStatus(vApp));
Task task = powerOff(vApp);
if (!taskTester.apply(task.getHref())) {
// TODO timeout
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
}
vApp = refreshVApp(vApp.getHref());
logger.debug("<< %s vApp(%s)", getStatus(vApp), vApp.getName());
}
return vApp;
}
protected abstract Task powerOff(A vApp);
protected abstract Status getStatus(A vApp);
@Override
public abstract Set<String> getPrivateAddresses(URI id);
@Override
public abstract Set<String> getPublicAddresses(URI id);
}

View File

@ -0,0 +1,92 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableSet.Builder;
/**
* @author Adrian Cole
*/
@Singleton
public class OrgAndVDCToLocationSupplier extends JustProvider {
private final Supplier<Map<String, ReferenceType>> orgNameToResource;
private final Supplier<Map<String, ? extends Org>> orgNameToVDCResource;
private final Map<String, Set<String>> isoCodesById;
@Inject
OrgAndVDCToLocationSupplier(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider URI endpoint,
@org.jclouds.vcloud.endpoints.Org Supplier<Map<String, ReferenceType>> orgNameToResource,
Supplier<Map<String, ? extends Org>> orgNameToVDCResource, @Iso3166 Map<String, Set<String>> isoCodesById) {
super(isoCodes, providerName, endpoint);
this.orgNameToResource = checkNotNull(orgNameToResource, "orgNameToResource");
this.orgNameToVDCResource = checkNotNull(orgNameToVDCResource, "orgNameToVDCResource");
this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
}
@Override
public Set<? extends Location> get() {
return buildJustProviderOrVDCs().build();
}
protected Builder<Location> buildJustProviderOrVDCs() {
Builder<Location> locations = ImmutableSet.builder();
Location provider = Iterables.getOnlyElement(super.get());
if (orgNameToResource.get().size() == 0)
return locations.add(provider);
else
for (ReferenceType org : orgNameToResource.get().values()) {
LocationBuilder builder = new LocationBuilder().scope(LocationScope.REGION).id(
org.getHref().toASCIIString()).description((org.getName())).parent(provider);
if (isoCodesById.containsKey(org.getHref().toASCIIString()))
builder.iso3166Codes(isoCodesById.get(org.getHref().toASCIIString()));
Location orgL = builder.build();
for (ReferenceType vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) {
builder = new LocationBuilder().scope(LocationScope.ZONE).id(vdc.getHref().toASCIIString()).description(
(vdc.getName())).parent(orgL);
if (isoCodesById.containsKey(vdc.getHref().toASCIIString()))
builder.iso3166Codes(isoCodesById.get(vdc.getHref().toASCIIString()));
locations.add(builder.build());
}
}
return locations;
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,452 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.OrgList;
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.AllCatalogItemsInOrg;
import org.jclouds.vcloud.functions.AllCatalogsInOrg;
import org.jclouds.vcloud.functions.AllVDCsInOrg;
import org.jclouds.vcloud.functions.OrgsForLocations;
import org.jclouds.vcloud.functions.OrgsForNames;
import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse;
import org.jclouds.vcloud.predicates.TaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Configures the VCloud authentication service connection, including logging
* and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
RestClientModule<S, A> {
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap);
}
@Override
protected void configure() {
super.configure();
// Ensures we don't retry on authorization failures
bind(new TypeLiteral<AtomicReference<AuthorizationException>>() {
}).toInstance(new AtomicReference<AuthorizationException>());
installDefaultVCloudEndpointsModule();
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
}).to(new TypeLiteral<FindLocationForResource>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends Catalog>>>() {
}).to(new TypeLiteral<AllCatalogsInOrg>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends VDC>>>() {
}).to(new TypeLiteral<AllVDCsInOrg>() {
});
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends Org>>>() {
}).to(new TypeLiteral<OrgsForNames>() {
});
bind(new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends Org>>>() {
}).to(new TypeLiteral<OrgsForLocations>() {
});
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInOrg>() {
});
}
@Singleton
@Provides
CommonVCloudAsyncClient provideCommonVCloudAsyncClient(A in) {
return in;
}
@Singleton
@Provides
CommonVCloudClient provideCommonVCloudClient(S in) {
return in;
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, ? extends Org>> orgNameToOrgSuppier) {
return Suppliers.compose(new Function<Map<String, ? extends Org>, Map<String, String>>() {
@Override
public Map<String, String> apply(Map<String, ? extends Org> arg0) {
Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
for (Entry<String, ? extends Org> orgr : arg0.entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal.build();
}
}, orgNameToOrgSuppier);
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(
authException, seconds, supplier);
}
@Provides
@Singleton
@OrgList
URI provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
VCloudSession session = sessionSupplier.get();
return URI.create(getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org"));
}
@Singleton
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
protected final Supplier<VCloudSession> sessionSupplier;
protected final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
@Inject
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@Override
public Map<String, ? extends Org> get() {
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
}
}
protected void installDefaultVCloudEndpointsModule() {
install(new DefaultVCloudReferencesModule());
}
@Singleton
public static class OrgCatalogSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
protected final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
@Inject
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
this.orgSupplier = orgSupplier;
this.allCatalogsInOrg = allCatalogsInOrg;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return transformValues(
transformValues(orgSupplier.get(), allCatalogsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
return uniqueIndex(from, name);
}
});
}
}
@VCloudToken
@Provides
String provideVCloudToken(Supplier<VCloudSession> cache) {
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
authException, seconds, supplier);
}
@Provides
@Singleton
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
URItoVDC supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
authException, seconds, supplier);
}
@Singleton
public static class URItoVDC implements Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> {
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
@Inject
URItoVDC(Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap) {
this.orgVDCMap = orgVDCMap;
}
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return uniqueIndex(
concat(transform(
orgVDCMap.get().values(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
return from.values();
}
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
@Override
public URI apply(org.jclouds.vcloud.domain.VDC from) {
return from.getHref();
}
});
}
}
final static Function<ReferenceType, String> name = new Function<ReferenceType, String>() {
@Override
public String apply(ReferenceType from) {
return from.getName();
}
};
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException {
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
checkState(versions.size() > 0, "No versions present");
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
return versions.get(version);
}
@Singleton
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
private final Supplier<VCloudSession> sessionSupplier;
@SuppressWarnings("unused")
@Inject
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
this.sessionSupplier = sessionSupplier;
}
@Override
public Map<String, ReferenceType> get() {
return sessionSupplier.get().getOrgs();
}
}
@Provides
@Singleton
protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
return factory.create(VCloudVersionsAsyncClient.class);
}
@Provides
@Singleton
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return orgSupplier.get().get(defaultOrg.getName());
}
@Provides
@Singleton
protected Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), completed);
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds, supplier);
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgVDCSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds, supplier);
}
@Singleton
public static class OrgVDCSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg;
@Inject
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
this.orgSupplier = orgSupplier;
this.allVDCsInOrg = allVDCsInOrg;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return transformValues(
transformValues(orgSupplier.get(), allVDCsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
return uniqueIndex(from, name);
}
});
}
}
@Singleton
public static class OrgCatalogItemSupplier implements
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
protected final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrgCatalogItemSupplier(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
this.catalogSupplier = catalogSupplier;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return transformValues(
catalogSupplier.get(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
@Override
public Map<String, Map<String, ? extends CatalogItem>> apply(
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
return transformValues(
from,
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
@Override
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
}
});
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogItemSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds, supplier);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class);
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.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.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.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.vcloud.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return selector.apply(org.getCatalogs().values());
}
}

View File

@ -0,0 +1,68 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.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.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.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.vcloud.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.vcloud.domain.VDC vDC = uriToVDC.get().get(defaultVDC.getHref());
checkState(vDC != null, "could not retrieve VDC at %s", defaultVDC);
return selector.apply(vDC.getAvailableNetworks().values());
}
}

View File

@ -0,0 +1,64 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.session/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.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 DefaultOrgForUser implements Function<String, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<VCloudSession> sessionSupplier;
@Inject
public DefaultOrgForUser(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@Org Predicate<ReferenceType> defaultSelector, Supplier<VCloudSession> sessionSupplier) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_ORG, checkNotNull(
defaultSelector, "defaultSelector"));
this.sessionSupplier = checkNotNull(sessionSupplier, "sessionSupplier");
}
@Override
public ReferenceType apply(String user) {
VCloudSession session = sessionSupplier.get();
checkState(session != null, "could not retrieve Session at %s", user);
return selector.apply(session.getOrgs().values());
}
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
@Singleton
public class DefaultTasksListForOrg implements Function<ReferenceType, ReferenceType> {
private final Supplier<Map<String, ? extends Org>> nameToOrg;
@Inject
public DefaultTasksListForOrg(Supplier<Map<String, ? extends Org>> nameToOrg) {
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@Override
public ReferenceType apply(ReferenceType defaultOrg) {
org.jclouds.vcloud.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return org.getTasksList();
}
}

View File

@ -0,0 +1,175 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import java.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
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;
/**
*
* @author Adrian Cole
*/
public class DefaultVCloudReferencesModule extends AbstractModule {
@Override
protected void configure() {
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected ReferenceType provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser,
@Named(PROPERTY_IDENTITY) String user) {
return defaultOrgURIForUser.apply(user);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Org
protected Predicate<ReferenceType> provideDefaultOrgSelector(Injector i) {
return Predicates.alwaysTrue();
}
@Provides
@org.jclouds.vcloud.endpoints.TasksList
@Singleton
protected ReferenceType provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return defaultTasksListURIForOrg.apply(defaultOrg);
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected ReferenceType provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return defaultCatalogURIForOrg.apply(defaultOrg);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Catalog
protected Predicate<ReferenceType> provideDefaultCatalogSelector(Injector i) {
return i.getInstance(WriteableCatalog.class);
}
@Provides
@Singleton
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>> provideCatalogsById(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> supplier) {
return Suppliers
.compose(
new Function<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>, Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<URI, ? extends Catalog> apply(Map<String, Map<String, ? extends Catalog>> arg0) {
Builder<URI, Catalog> builder = ImmutableMap.<URI, Catalog> builder();
for (Map<String, ? extends Catalog> v1 : arg0.values()) {
for (Catalog v2 : v1.values()) {
builder.put(v2.getHref(), v2);
}
}
return builder.build();
}
}, supplier);
}
@Singleton
public static class WriteableCatalog implements Predicate<ReferenceType> {
@Resource
protected Logger logger = Logger.NULL;
private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>> catalogsByIdSupplier;
@Inject
public WriteableCatalog(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>> catalogsByIdSupplier) {
this.catalogsByIdSupplier = catalogsByIdSupplier;
}
@Override
public boolean apply(ReferenceType arg0) {
// TODO: this is inefficient, calculating the index each time, but
// shouldn't be added to constructor as the supplier is an expensive
// call
Map<URI, ? extends Catalog> index = catalogsByIdSupplier.get();
Catalog catalog = index.get(arg0.getHref());
if (catalog == null) {
if (logger.isTraceEnabled())
logger.trace("didn't find catalog %s", arg0);
return false;
} else
return !catalog.isReadOnly();
}
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected ReferenceType provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return defaultVDCURIForOrg.apply(defaultOrg);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Predicate<ReferenceType> provideDefaultVDCSelector(Injector i) {
return Predicates.alwaysTrue();
}
@Provides
@org.jclouds.vcloud.endpoints.Network
@Singleton
protected ReferenceType provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
@org.jclouds.vcloud.endpoints.VDC ReferenceType defaultVDC) {
return defaultNetworkURIForVDC.apply(defaultVDC);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Network
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
return Predicates.alwaysTrue();
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.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.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.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.vcloud.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return selector.apply(org.getVDCs().values());
}
}

View File

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

View File

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

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.Catalog
@ImplementedBy(CatalogImpl.class)
public interface Catalog extends ReferenceType, Map<String, ReferenceType> {
/**
* Reference to the org containing this vDC.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the org isn't present
*/
ReferenceType getOrg();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly element, true if the catalog is published
*
* @since vcloud api 1.0
*/
boolean isPublished();
/**
* @return true, if the current user cannot modify the catalog
* @since vcloud api 1.0
*/
boolean isReadOnly();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
}

View File

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

View File

@ -0,0 +1,89 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import com.google.inject.ImplementedBy;
/**
* A vCloud organization is a high-level abstraction that provides a unit of administration for
* objects and resources. As viewed by a user, an organization (represented by an Org element) can
* contain Catalog, Network, and vDC elements. If there are any queued, running, or recently
* completed tasks owned by a member of the organization, it also contains a TasksList element. As
* viewed by an administrator, an organization also contains users, groups, and other information
*
* @author Adrian Cole
*/
@ImplementedBy(OrgImpl.class)
public interface Org extends ReferenceType {
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* full name of the organization
*
* @since vcloud api 1.0
*/
@Nullable
String getFullName();
/**
* @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.
*
* @since vcloud api 0.8
*/
@Nullable
ReferenceType getTasksList();
/**
* @since vcloud api 1.0
*/
Map<String, ReferenceType> getNetworks();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
}

View File

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

View File

@ -0,0 +1,228 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.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} could not be created.
*
* @since vcloud api 1.0
*/
ERROR,
/**
* 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 object is deployed.
* <p/>
* note that the documentation does not reference use of this.
*
* @since vcloud api 1.0
*/
DEPLOYED,
/**
* 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 VApp} or {@link Vm} waiting for user input.
*
* @since vcloud api 1.0
*/
WAITING_FOR_INPUT,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is in an unknown state.
*
* @since vcloud api 1.0
*/
UNKNOWN,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is in an unrecognized state.
*
* @since vcloud api 1.0
*/
UNRECOGNIZED,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is off.
*
* @since vcloud api 0.8
*/
OFF,
/**
* The {@link VApp} or {@link Vm} is in an inconsistent state.
*
* @since vcloud api 1.0
*/
INCONSISTENT,
/**
* The {@link VAppTemplate} or {@link VApp} have children do not all have the same status.
*
* @since vcloud api 1.0
*/
MIXED,
/**
* The {@link VAppTemplate} Upload initiated, OVF descriptor pending
*
* @since vcloud api 1.0
*/
PENDING_DESCRIPTOR,
/**
* The {@link VAppTemplate} Upload initiated, copying contents
*
* @since vcloud api 1.0
*/
COPYING,
/**
* The {@link VAppTemplate} Upload initiated, disk contents pending
*
* @since vcloud api 1.0
*/
PENDING_CONTENTS,
/**
* The {@link VAppTemplate} Upload has been quarantined
*
* @since vcloud api 1.0
*/
QUARANTINED,
/**
* The {@link VAppTemplate} Upload quarantine period has expired
*
* @since vcloud api 1.0
*/
QUARANTINE_EXPIRED;
public String value() {
switch (this) {
case UNRESOLVED:
return "0";
case RESOLVED:
return "1";
case DEPLOYED:
return "2";
case SUSPENDED:
return "3";
case ON:
return "4";
case WAITING_FOR_INPUT:
return "5";
case UNKNOWN:
return "6";
case UNRECOGNIZED:
return "7";
case OFF:
return "8";
case INCONSISTENT:
return "9";
case MIXED:
return "10";
case PENDING_DESCRIPTOR:
return "11";
case COPYING:
return "12";
case PENDING_CONTENTS:
return "13";
case QUARANTINED:
return "14";
case QUARANTINE_EXPIRED:
return "15";
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 DEPLOYED;
case 3:
return SUSPENDED;
case 4:
return ON;
case 5:
return WAITING_FOR_INPUT;
case 6:
return UNKNOWN;
case 7:
return UNRECOGNIZED;
case 8:
return OFF;
case 9:
return INCONSISTENT;
case 10:
return MIXED;
case 11:
return PENDING_DESCRIPTOR;
case 12:
return COPYING;
case 13:
return PENDING_CONTENTS;
case 14:
return QUARANTINED;
case 15:
return QUARANTINE_EXPIRED;
default:
return UNRECOGNIZED;
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import java.net.URI;
import java.util.SortedSet;
import org.jclouds.vcloud.domain.internal.TasksListImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.TasksList
@ImplementedBy(TasksListImpl.class)
public interface TasksList {
URI getLocation();
SortedSet<Task> getTasks();
}

View File

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

View File

@ -0,0 +1,31 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import java.util.Map;
/**
*
* @author Adrian Cole
*/
public interface VCloudSession {
String getVCloudToken();
Map<String, ReferenceType> getOrgs();
}

View File

@ -0,0 +1,149 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import com.google.inject.ImplementedBy;
/**
* A vDC is a deployment environment for vApps. A Vdc element provides a user view of a vDC.
*
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.VDC
@ImplementedBy(VDCImpl.class)
public interface VDC extends ReferenceType {
/**
* Reference to the org containing this vDC.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the org isn't present
*/
ReferenceType getOrg();
/**
* The creation status of the vDC
*
* @since vcloud api 1.0
*/
VDCStatus getStatus();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
/**
* defines how resources are allocated by the vDC. The value of this element is set by the
* administrator who created the vDC. It is readonly to users.
*
* @since vcloud api 1.0
*/
AllocationModel getAllocationModel();
/**
* defines the storage capacity available in the vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support storage capacity
*/
@Nullable
Capacity getStorageCapacity();
/**
* reports CPU resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support cpu capacity
*/
@Nullable
Capacity getCpuCapacity();
/**
* reports memory resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support memory capacity
*/
@Nullable
Capacity getMemoryCapacity();
/**
* 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();
/**
* maximum number of virtual NICs allowed in this vDC. Defaults to 0, which specifies an
* unlimited number.
*
* @since vcloud api 1.0
*/
int getNicQuota();
/**
* maximum number of OrgNetwork objects that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 1.0
*/
int getNetworkQuota();
/**
* maximum number of virtual machines that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 0.8
*/
int getVmQuota();
/**
* true if this vDC is enabled
*
* @since vcloud api 1.0
*/
boolean isEnabled();
}

View File

@ -0,0 +1,59 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* The creation status of the vDC
*
* @see VDC#getStatus
*/
public enum VDCStatus {
CREATION_FAILED, NOT_READY, READY, UNKNOWN, UNRECOGNIZED;
public int value() {
switch (this) {
case CREATION_FAILED:
return -1;
case NOT_READY:
return 0;
case READY:
return 1;
case UNKNOWN:
return 2;
default:
return 3;
}
}
public static VDCStatus fromValue(int status) {
switch (status) {
case -1:
return CREATION_FAILED;
case 0:
return NOT_READY;
case 1:
return READY;
case 2:
return UNKNOWN;
default:
return UNRECOGNIZED;
}
}
}

View File

@ -0,0 +1,193 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements Catalog {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
private final String name;
private final String type;
private final URI href;
private final ReferenceType org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final boolean published;
private final boolean readOnly;
public CatalogImpl(String name, String type, URI href, ReferenceType org, @Nullable String description,
Map<String, ReferenceType> contents, Iterable<Task> tasks, boolean published, boolean readOnly) {
this.name = checkNotNull(name, "name");
this.type = checkNotNull(type, "type");
this.org = org;// TODO: once <1.0 is killed check not null
this.description = description;
this.href = checkNotNull(href, "href");
putAll(checkNotNull(contents, "contents"));
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.published = published;
this.readOnly = readOnly;
}
/**
* {@inheritDoc}
*/
@Override
public URI getHref() {
return href;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
return type;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isPublished() {
return published;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isReadOnly() {
return readOnly;
}
@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 + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.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 (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
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());
}
}

View File

@ -0,0 +1,114 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
*
*/
public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
private final String description;
private final ReferenceType entity;
private final Map<String, String> properties = Maps.newLinkedHashMap();
public CatalogItemImpl(String name, URI id, @Nullable String description, ReferenceType entity,
Map<String, String> properties) {
super(name, VCloudMediaType.CATALOGITEM_XML, id);
this.description = description;
this.entity = checkNotNull(entity, "entity");
this.properties.putAll(checkNotNull(properties, "properties"));
}
@Override
public String getType() {
return VCloudMediaType.CATALOGITEM_XML;
}
public ReferenceType getEntity() {
return entity;
}
@Override
public String getDescription() {
return description;
}
public Map<String, String> getProperties() {
return properties;
}
@Override
public String toString() {
return "CatalogItemImpl [id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description="
+ getDescription() + ", entity=" + entity + ", 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());
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;
return true;
}
}

View File

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

View File

@ -0,0 +1,174 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class OrgImpl extends ReferenceTypeImpl implements Org {
private final String fullName;
@Nullable
private final String description;
private final Map<String, ReferenceType> catalogs = Maps.newLinkedHashMap();
private final Map<String, ReferenceType> vdcs = Maps.newLinkedHashMap();
private final Map<String, ReferenceType> networks = Maps.newLinkedHashMap();
private final ReferenceType tasksList;
private final List<Task> tasks = Lists.newArrayList();
public OrgImpl(String name, String type, URI id, String fullName, String description,
Map<String, ReferenceType> catalogs, Map<String, ReferenceType> vdcs, Map<String, ReferenceType> networks,
@Nullable ReferenceType tasksList, Iterable<Task> tasks) {
super(name, type, id);
this.fullName = checkNotNull(fullName, "fullName");
this.description = description;
this.catalogs.putAll(checkNotNull(catalogs, "catalogs"));
this.vdcs.putAll(checkNotNull(vdcs, "vdcs"));
this.networks.putAll(checkNotNull(networks, "networks"));
this.tasksList = tasksList;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
}
@Override
public String getFullName() {
return fullName;
}
@Override
public String getDescription() {
return description;
}
@Override
public Map<String, ReferenceType> getCatalogs() {
return catalogs;
}
@Override
public Map<String, ReferenceType> getVDCs() {
return vdcs;
}
@Override
public Map<String, ReferenceType> getNetworks() {
return networks;
}
@Override
public ReferenceType getTasksList() {
return tasksList;
}
@Override
public List<Task> getTasks() {
return tasks;
}
@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 + ((fullName == null) ? 0 : fullName.hashCode());
result = prime * result + ((networks == null) ? 0 : networks.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((tasksList == null) ? 0 : tasksList.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 (fullName == null) {
if (other.fullName != null)
return false;
} else if (!fullName.equals(other.fullName))
return false;
if (networks == null) {
if (other.networks != null)
return false;
} else if (!networks.equals(other.networks))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (tasksList == null) {
if (other.tasksList != null)
return false;
} else if (!tasksList.equals(other.tasksList))
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() + ", fullName=" + fullName
+ ", description=" + description + ", catalogs=" + catalogs + ", networks=" + networks + ", tasksList="
+ tasksList + ", vdcs=" + vdcs + ", tasks=" + tasks + "]";
}
}

View File

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

View File

@ -0,0 +1,167 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Date;
import javax.annotation.Nullable;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.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, VCloudMediaType.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;
}
}

View File

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

View File

@ -0,0 +1,295 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class VDCImpl extends ReferenceTypeImpl implements VDC {
private final VDCStatus status;
private final ReferenceType org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final AllocationModel allocationModel;
private final Capacity storageCapacity;
private final Capacity cpuCapacity;
private final Capacity memoryCapacity;
private final Map<String, ReferenceType> resourceEntities = Maps.newLinkedHashMap();
private final Map<String, ReferenceType> availableNetworks = Maps.newLinkedHashMap();
private final int nicQuota;
private final int networkQuota;
private final int vmQuota;
private final boolean isEnabled;
public VDCImpl(String name, String type, URI id, VDCStatus status, ReferenceType org, @Nullable String description,
Iterable<Task> tasks, AllocationModel allocationModel, @Nullable Capacity storageCapacity,
@Nullable Capacity cpuCapacity, @Nullable Capacity memoryCapacity,
Map<String, ReferenceType> resourceEntities, Map<String, ReferenceType> availableNetworks, int nicQuota,
int networkQuota, int vmQuota, boolean isEnabled) {
super(name, type, id);
this.status = checkNotNull(status, "status");
this.org = org;// TODO: once <1.0 is killed check not null
this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.allocationModel = checkNotNull(allocationModel, "allocationModel");
this.storageCapacity = storageCapacity;// TODO: once <1.0 is killed check not null
this.cpuCapacity = cpuCapacity;// TODO: once <1.0 is killed check not null
this.memoryCapacity = memoryCapacity;// TODO: once <1.0 is killed check not null
this.resourceEntities.putAll(checkNotNull(resourceEntities, "resourceEntities"));
this.availableNetworks.putAll(checkNotNull(availableNetworks, "availableNetworks"));
this.nicQuota = nicQuota;
this.networkQuota = networkQuota;
this.vmQuota = vmQuota;
this.isEnabled = isEnabled;
}
/**
* {@inheritDoc}
*/
@Override
public VDCStatus getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public AllocationModel getAllocationModel() {
return allocationModel;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getStorageCapacity() {
return storageCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getCpuCapacity() {
return cpuCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getMemoryCapacity() {
return memoryCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, ReferenceType> getResourceEntities() {
return resourceEntities;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, ReferenceType> getAvailableNetworks() {
return availableNetworks;
}
/**
* {@inheritDoc}
*/
@Override
public int getNicQuota() {
return nicQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getNetworkQuota() {
return networkQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getVmQuota() {
return vmQuota;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEnabled() {
return isEnabled;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((allocationModel == null) ? 0 : allocationModel.hashCode());
result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode());
result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + (isEnabled ? 1231 : 1237);
result = prime * result + ((memoryCapacity == null) ? 0 : memoryCapacity.hashCode());
result = prime * result + networkQuota;
result = prime * result + nicQuota;
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((storageCapacity == null) ? 0 : storageCapacity.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + vmQuota;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VDCImpl other = (VDCImpl) obj;
if (allocationModel == null) {
if (other.allocationModel != null)
return false;
} else if (!allocationModel.equals(other.allocationModel))
return false;
if (availableNetworks == null) {
if (other.availableNetworks != null)
return false;
} else if (!availableNetworks.equals(other.availableNetworks))
return false;
if (cpuCapacity == null) {
if (other.cpuCapacity != null)
return false;
} else if (!cpuCapacity.equals(other.cpuCapacity))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (isEnabled != other.isEnabled)
return false;
if (memoryCapacity == null) {
if (other.memoryCapacity != null)
return false;
} else if (!memoryCapacity.equals(other.memoryCapacity))
return false;
if (networkQuota != other.networkQuota)
return false;
if (nicQuota != other.nicQuota)
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (resourceEntities == null) {
if (other.resourceEntities != null)
return false;
} else if (!resourceEntities.equals(other.resourceEntities))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (storageCapacity == null) {
if (other.storageCapacity != null)
return false;
} else if (!storageCapacity.equals(other.storageCapacity))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (vmQuota != other.vmQuota)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getHref() + ", name=" + getName() + ", org=" + org + ", description=" + description + ", status="
+ status + ", isEnabled=" + isEnabled + "]";
}
}

View File

@ -0,0 +1,127 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import javax.annotation.Nullable;
/**
* specifies the properties of the networks DHCP service
*/
public class DhcpService {
private final boolean enabled;
@Nullable
private final Integer defaultLeaseTime;
@Nullable
private final Integer maxLeaseTime;
@Nullable
private final IpRange ipRange;
public DhcpService(boolean enabled, @Nullable Integer defaultLeaseTime, @Nullable Integer maxLeaseTime,
@Nullable IpRange ipRange) {
this.enabled = enabled;
this.defaultLeaseTime = defaultLeaseTime;
this.maxLeaseTime = maxLeaseTime;
this.ipRange = ipRange;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.8
*/
public boolean isEnabled() {
return enabled;
}
/**
* default duration of a DCHP address lease
*
* @since vcloud api 0.9
*/
@Nullable
public Integer getDefaultLeaseTime() {
return defaultLeaseTime;
}
/**
* maximum duration of a DCHP address lease.
*
* @since vcloud api 0.9
*/
@Nullable
public Integer getMaxLeaseTime() {
return maxLeaseTime;
}
/**
* @return range of IP addresses available to DHCP clients
*
* @since vcloud api 0.9
*/
@Nullable
public IpRange getIpRange() {
return ipRange;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((defaultLeaseTime == null) ? 0 : defaultLeaseTime.hashCode());
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((ipRange == null) ? 0 : ipRange.hashCode());
result = prime * result + ((maxLeaseTime == null) ? 0 : maxLeaseTime.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;
DhcpService other = (DhcpService) obj;
if (defaultLeaseTime == null) {
if (other.defaultLeaseTime != null)
return false;
} else if (!defaultLeaseTime.equals(other.defaultLeaseTime))
return false;
if (enabled != other.enabled)
return false;
if (ipRange == null) {
if (other.ipRange != null)
return false;
} else if (!ipRange.equals(other.ipRange))
return false;
if (maxLeaseTime == null) {
if (other.maxLeaseTime != null)
return false;
} else if (!maxLeaseTime.equals(other.maxLeaseTime))
return false;
return true;
}
@Override
public String toString() {
return "[defaultLeaseTime=" + defaultLeaseTime + ", enabled=" + enabled + ", ipRange=" + ipRange
+ ", maxLeaseTime=" + maxLeaseTime + "]";
}
}

View File

@ -0,0 +1,114 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import javax.annotation.Nullable;
/**
* The Features element defines the DHCP and firewall features of a network.
*/
public class Features {
@Nullable
private final DhcpService dhcpService;
@Nullable
private final FirewallService firewallService;
@Nullable
private final NatService natService;
public Features(@Nullable DhcpService dhcpService, @Nullable FirewallService firewallService,
@Nullable NatService natService) {
this.dhcpService = dhcpService;
this.firewallService = firewallService;
this.natService = natService;
}
/**
* specifies the properties of the networks DHCP service
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable
public DhcpService getDhcpService() {
return dhcpService;
}
/**
* defines the firewall service capabilities of the network
*
* @since vcloud api 0.8
*/
@Nullable
public FirewallService getFirewallService() {
return firewallService;
}
/**
* defines the NAT service capabilities of the network
*
* @since vcloud api 0.8
*/
@Nullable
public NatService getNatService() {
return natService;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dhcpService == null) ? 0 : dhcpService.hashCode());
result = prime * result + ((firewallService == null) ? 0 : firewallService.hashCode());
result = prime * result + ((natService == null) ? 0 : natService.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;
Features other = (Features) obj;
if (dhcpService == null) {
if (other.dhcpService != null)
return false;
} else if (!dhcpService.equals(other.dhcpService))
return false;
if (firewallService == null) {
if (other.firewallService != null)
return false;
} else if (!firewallService.equals(other.firewallService))
return false;
if (natService == null) {
if (other.natService != null)
return false;
} else if (!natService.equals(other.natService))
return false;
return true;
}
@Override
public String toString() {
return "[dhcpService=" + dhcpService + ", firewallService=" + firewallService + ", natService=" + natService
+ "]";
}
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
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.
* <p/>
* Note that in vcloud 0.8 this was called ALLOW_IN_OUT, and so our implementation automatically
* converts this for you. Use bridged instead of allowInOut.
*
* @since vcloud api 0.9
*/
BRIDGED,
/**
* 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;
}
}
}

View File

@ -0,0 +1,97 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* The FirewallService element defines the firewall service capabilities of a network.
*/
public class FirewallService {
private final boolean enabled;
List<FirewallRule> firewallRules = Lists.newArrayList();
public FirewallService(boolean enabled, Iterable<? extends FirewallRule> firewallRules) {
this.enabled = enabled;
Iterables.addAll(this.firewallRules, checkNotNull(firewallRules, "firewallRules"));
}
/**
* @return Firewall rules for the network
*
* @since vcloud api 0.8
*/
public List<? extends FirewallRule> getFirewallRules() {
return firewallRules;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.9
*/
@Nullable
public boolean isEnabled() {
return enabled;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((firewallRules == null) ? 0 : firewallRules.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;
FirewallService other = (FirewallService) obj;
if (enabled != other.enabled)
return false;
if (firewallRules == null) {
if (other.firewallRules != null)
return false;
} else if (!firewallRules.equals(other.firewallRules))
return false;
return true;
}
@Override
public String toString() {
return "[enabled=" + enabled + ", firewallRules=" + firewallRules + "]";
}
}

View File

@ -0,0 +1,54 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
/**
*
* The IpAddressAllocationMode element specifies how an IP address is allocated to this connection.
*
* @author Adrian Cole
*/
public enum IpAddressAllocationMode {
/**
* no IP addressing mode specified
*
* @since vcloud api 1.0
*/
NONE,
/**
* static IP address assigned manually
*
* @since vcloud api 1.0
*/
MANUAL,
/**
* static IP address allocated from a pool
*
* @since vcloud api 1.0
*/
POOL,
/**
* IP address assigned by DHCP
*
* @since vcloud api 1.0
*/
DHCP;
}

View File

@ -0,0 +1,89 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The IpRange element defines a range of IP addresses available on a network.
*
*/
public class IpRange {
private final String startAddress;
private final String endAddress;
public IpRange(String startAddress, String endAddress) {
this.startAddress = checkNotNull(startAddress, "startAddress");
this.endAddress = checkNotNull(endAddress, "endAddress");
}
/**
* @return lowest IP address in the range
*
* @since vcloud api 0.9
*/
public String getStartAddress() {
return startAddress;
}
/**
* @return highest IP address in the range
*
* @since vcloud api 0.9
*/
public String getEndAddress() {
return endAddress;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((endAddress == null) ? 0 : endAddress.hashCode());
result = prime * result + ((startAddress == null) ? 0 : startAddress.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;
IpRange other = (IpRange) obj;
if (endAddress == null) {
if (other.endAddress != null)
return false;
} else if (!endAddress.equals(other.endAddress))
return false;
if (startAddress == null) {
if (other.startAddress != null)
return false;
} else if (!startAddress.equals(other.startAddress))
return false;
return true;
}
@Override
public String toString() {
return "[startAddress=" + startAddress + ", endAddress=" + endAddress + "]";
}
}

View File

@ -0,0 +1,210 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import javax.annotation.Nullable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* The IpScope element defines the address range, gateway, netmask, and other properties of the
* network.
*
*/
public class IpScope {
private final boolean inherited;
@Nullable
private final String gateway;
@Nullable
private final String netmask;
@Nullable
private final String dns1;
@Nullable
private final String dns2;
@Nullable
private final String dnsSuffix;
private final Set<IpRange> ipRanges = Sets.newLinkedHashSet();
private final Set<String> allocatedIpAddresses = Sets.newLinkedHashSet();
public IpScope(boolean inherited, @Nullable String gateway, @Nullable String netmask, @Nullable String dns1,
@Nullable String dns2, @Nullable String dnsSuffix, Iterable<IpRange> ipRanges,
Iterable<String> allocatedIpAddresses) {
this.inherited = inherited;
this.gateway = gateway;
this.netmask = netmask;
this.dns1 = dns1;
this.dns2 = dns2;
this.dnsSuffix = dnsSuffix;
Iterables.addAll(this.ipRanges, checkNotNull(ipRanges, "ipRanges"));
Iterables.addAll(this.allocatedIpAddresses, checkNotNull(allocatedIpAddresses, "allocatedIpAddresses"));
}
/**
* @return true of the values in this IpScope element are inherited from the ParentNetwork of the
* containing Configuration
* @since vcloud api 0.9
*/
public boolean isInherited() {
return inherited;
}
/**
* @return IP address of the network gateway
*
* @since vcloud api 0.8
*/
@Nullable
public String getGateway() {
return gateway;
}
/**
* @return netmask to apply to addresses on the network
*
* @since vcloud api 0.8
*/
@Nullable
public String getNetmask() {
return netmask;
}
/**
* @return IP address of the primary DNS server for this network
*
* @since vcloud api 0.9
*/
@Nullable
public String getDns1() {
return dns1;
}
/**
* @return IP address of the secondary DNS server for this network
*
* @since vcloud api 0.9
*/
@Nullable
public String getDns2() {
return dns2;
}
/**
* @return suffix to be applied when resolving hostnames that are not fullyqualified.
*
* @since vcloud api 0.9
*/
@Nullable
public String getDnsSuffix() {
return dnsSuffix;
}
/**
* @return A container for IpRange elements.
*
* @since vcloud api 0.9
*/
public Set<IpRange> getIpRanges() {
return ipRanges;
}
/**
* @return A list of addresses allocated from any of the specified IpRanges
*
* @since vcloud api 0.9
*/
public Set<String> getAllocatedIpAddresses() {
return allocatedIpAddresses;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((allocatedIpAddresses == null) ? 0 : allocatedIpAddresses.hashCode());
result = prime * result + ((dns1 == null) ? 0 : dns1.hashCode());
result = prime * result + ((dns2 == null) ? 0 : dns2.hashCode());
result = prime * result + ((dnsSuffix == null) ? 0 : dnsSuffix.hashCode());
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
result = prime * result + (inherited ? 1231 : 1237);
result = prime * result + ((ipRanges == null) ? 0 : ipRanges.hashCode());
result = prime * result + ((netmask == null) ? 0 : netmask.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;
IpScope other = (IpScope) obj;
if (allocatedIpAddresses == null) {
if (other.allocatedIpAddresses != null)
return false;
} else if (!allocatedIpAddresses.equals(other.allocatedIpAddresses))
return false;
if (dns1 == null) {
if (other.dns1 != null)
return false;
} else if (!dns1.equals(other.dns1))
return false;
if (dns2 == null) {
if (other.dns2 != null)
return false;
} else if (!dns2.equals(other.dns2))
return false;
if (dnsSuffix == null) {
if (other.dnsSuffix != null)
return false;
} else if (!dnsSuffix.equals(other.dnsSuffix))
return false;
if (gateway == null) {
if (other.gateway != null)
return false;
} else if (!gateway.equals(other.gateway))
return false;
if (inherited != other.inherited)
return false;
if (ipRanges == null) {
if (other.ipRanges != null)
return false;
} else if (!ipRanges.equals(other.ipRanges))
return false;
if (netmask == null) {
if (other.netmask != null)
return false;
} else if (!netmask.equals(other.netmask))
return false;
return true;
}
@Override
public String toString() {
return "[allocatedIpAddresses=" + allocatedIpAddresses + ", dns1=" + dns1 + ", dns2=" + dns2 + ", dnsSuffix="
+ dnsSuffix + ", gateway=" + gateway + ", inherited=" + inherited + ", ipRanges=" + ipRanges
+ ", netmask=" + netmask + "]";
}
}

View File

@ -0,0 +1,136 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.nat.NatPolicy;
import org.jclouds.vcloud.domain.network.nat.NatRule;
import org.jclouds.vcloud.domain.network.nat.NatType;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* The NatService element defines the network address translation capabilities of a network.
*/
public class NatService {
private final boolean enabled;
@Nullable
private final NatType type;
@Nullable
private final NatPolicy policy;
private final List<NatRule> natRules = Lists.newArrayList();
public NatService(boolean enabled, @Nullable NatType type, @Nullable NatPolicy policy,
Iterable<? extends NatRule> natRules) {
this.enabled = enabled;
this.type = type;
this.policy = policy;
Iterables.addAll(this.natRules, checkNotNull(natRules, "natRules"));
}
/**
* @return Nat rules for the network
*
* @since vcloud api 0.8
*/
public List<? extends NatRule> getNatRules() {
return natRules;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.9
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return specifies how Network Address Translation is implemented by the NAT service
*
* @since vcloud api 0.9
*/
@Nullable
public NatType getType() {
return type;
}
/**
* @return specifies how packets are handled by the NAT service.
*
* @since vcloud api 0.9
*/
@Nullable
public NatPolicy getPolicy() {
return policy;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((natRules == null) ? 0 : natRules.hashCode());
result = prime * result + ((policy == null) ? 0 : policy.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;
NatService other = (NatService) obj;
if (enabled != other.enabled)
return false;
if (natRules == null) {
if (other.natRules != null)
return false;
} else if (!natRules.equals(other.natRules))
return false;
if (policy == null) {
if (other.policy != null)
return false;
} else if (!policy.equals(other.policy))
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 "[enabled=" + enabled + ", natRules=" + natRules + ", policy=" + policy + ", type=" + type + "]";
}
}

View File

@ -0,0 +1,132 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.annotation.Nullable;
/**
*
* @author Adrian Cole
*/
public class NetworkConfig {
@Nullable
private final String networkName;
private final URI parentNetwork;
@Nullable
private final FenceMode fenceMode;
/**
*
* Create a new NetworkConfig.
*
* @param networkName
* a valid {@networkConfig
* org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection network in the vapp
* template}, or null to have us choose default
* @param parentNetwork
* a valid {@networkConfig org.jclouds.vcloud.domain.Org#getNetworks in
* the Org}
* @param fenceMode
* how to manage the relationship between the two networks
*/
public NetworkConfig(String networkName, URI parentNetwork, FenceMode fenceMode) {
this.networkName = networkName;
this.parentNetwork = checkNotNull(parentNetwork, "parentNetwork");
this.fenceMode = fenceMode;
}
public NetworkConfig(URI parentNetwork) {
this(null, parentNetwork, null);
}
/**
* A name for the network. If the
* {@link org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection} includes a
* {@link NetworkSection.Network} network element, the name you specify for the vApp network must
* match the name specified in that elements name attribute.
*
* @return
*/
public String getNetworkName() {
return networkName;
}
/**
*
* @return A reference to the organization network to which this network connects.
*/
public URI getParentNetwork() {
return parentNetwork;
}
/**
* A value of bridged indicates that this vApp network is connected directly to the organization
* network.
*/
public FenceMode getFenceMode() {
return fenceMode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode());
result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.hashCode());
result = prime * result + ((networkName == null) ? 0 : networkName.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;
NetworkConfig other = (NetworkConfig) obj;
if (fenceMode == null) {
if (other.fenceMode != null)
return false;
} else if (!fenceMode.equals(other.fenceMode))
return false;
if (parentNetwork == null) {
if (other.parentNetwork != null)
return false;
} else if (!parentNetwork.equals(other.parentNetwork))
return false;
if (networkName == null) {
if (other.networkName != null)
return false;
} else if (!networkName.equals(other.networkName))
return false;
return true;
}
@Override
public String toString() {
return "[networkName=" + networkName + ", parentNetwork=" + parentNetwork + ", fenceMode=" + fenceMode + "]";
}
}

View File

@ -0,0 +1,124 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import com.google.inject.ImplementedBy;
/**
* A vDC is a deployment environment for vApps. A Vdc element provides a user view of a vDC.
*
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.Network
@ImplementedBy(VDCImpl.class)
public interface OrgNetwork extends ReferenceType {
/**
* The org this network belongs to.
*
* @since vcloud api 0.9
*/
@Nullable
ReferenceType getOrg();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 0.9
*/
List<Task> getTasks();
/**
*
* @return properties of the network
*
* @since vcloud api 0.9, but emulated for 0.8
*/
Configuration getConfiguration();
/**
* A reference the network pool from which this network is provisioned. This element, which is
* required when creating a NatRouted or Isolated network, is returned in response to a creation
* request but not shown in subsequent GET requests.
*
* @since vcloud api 0.9
*/
@Nullable
ReferenceType getNetworkPool();
/**
* list of external IP addresses that this network can use for NAT.
*
* @since vcloud api 0.9
*/
Set<String> getAllowedExternalIpAddresses();
/**
* The Configuration element specifies properties of a network.
*/
interface Configuration {
/**
* defines the address range, gateway, netmask, and other properties of the network.
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable
IpScope getIpScope();
/**
* reference to a network to which this network connects
*
* @since vcloud api 0.9
*/
@Nullable
ReferenceType getParentNetwork();
/**
* defines how this network is connected to its ParentNetwork
*
* @since vcloud api 0.8
*/
FenceMode getFenceMode();
/**
* defines a set of network features.
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable Features getFeatures();
}
}

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.firewall;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* specifies how packets are handled by the firewall
*
*/
public enum FirewallPolicy {
/**
* drop packets of this type
*/
DROP,
/**
* allow packets of this type to pass through the firewall
*/
ALLOW, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static FirewallPolicy fromValue(String policy) {
try {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(policy, "policy")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -0,0 +1,81 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.firewall;
/**
* The Protocols element specifies the protocols to which firewall rules apply.
*
* @since vcloud api 0.9 emulated for 0.8
*
*
*/
public class FirewallProtocols {
private final boolean tcp;
private final boolean udp;
public FirewallProtocols(boolean tcp, boolean udp) {
this.tcp = tcp;
this.udp = udp;
}
/**
* @return true if the firewall rules apply to the TCP protocol
*/
public boolean isTcp() {
return tcp;
}
/**
* @return true if the firewall rules apply to the UDP protocol
*/
public boolean isUdp() {
return udp;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (tcp ? 1231 : 1237);
result = prime * result + (udp ? 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;
FirewallProtocols other = (FirewallProtocols) obj;
if (tcp != other.tcp)
return false;
if (udp != other.udp)
return false;
return true;
}
@Override
public String toString() {
return "Protocols [tcp=" + tcp + ", udp=" + udp + "]";
}
}

View File

@ -0,0 +1,155 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.firewall;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* The FirewallRule element defines a single firewall rule.
*
* @author Adrian Cole
* @since vcloud api 0.8
*/
public class FirewallRule {
private final boolean enabled;
@Nullable
private final String description;
@Nullable
private final FirewallPolicy policy;
@Nullable
private final FirewallProtocols protocols;
private final int port;
private final String destinationIp;
public FirewallRule(boolean enabled, @Nullable String description, @Nullable FirewallPolicy policy,
@Nullable FirewallProtocols protocols, int port, String destinationIp) {
this.enabled = enabled;
this.description = description;
this.policy = policy;
this.protocols = protocols;
this.port = port;
this.destinationIp = checkNotNull(destinationIp, "destinationIp");
}
/**
* @return true if the rule is enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return description of the rule
*/
@Nullable
public String getDescription() {
return description;
}
/**
* @return specifies how packets are handled by the firewall
*/
@Nullable
public FirewallPolicy getPolicy() {
return policy;
}
/**
* @return specifies the protocols to which this firewall rule applies
*/
@Nullable
public FirewallProtocols getProtocols() {
return protocols;
}
/**
* @return specifies the network port to which this firewall rule applies. A value of 1 matches
* any port.
*/
public int getPort() {
return port;
}
/**
* @return specifies the destination IP address, inside the firewall, to which this firewall rule
* applies
*/
public String getDestinationIp() {
return destinationIp;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((destinationIp == null) ? 0 : destinationIp.hashCode());
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((policy == null) ? 0 : policy.hashCode());
result = prime * result + port;
result = prime * result + ((protocols == null) ? 0 : protocols.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;
FirewallRule other = (FirewallRule) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (destinationIp == null) {
if (other.destinationIp != null)
return false;
} else if (!destinationIp.equals(other.destinationIp))
return false;
if (enabled != other.enabled)
return false;
if (policy == null) {
if (other.policy != null)
return false;
} else if (!policy.equals(other.policy))
return false;
if (port != other.port)
return false;
if (protocols == null) {
if (other.protocols != null)
return false;
} else if (!protocols.equals(other.protocols))
return false;
return true;
}
@Override
public String toString() {
return "[description=" + description + ", destinationIp=" + destinationIp + ", enabled=" + enabled + ", policy="
+ policy + ", port=" + port + ", protocols=" + protocols + "]";
}
}

View File

@ -0,0 +1,280 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.Features;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.IpScope;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
*
* @author Adrian Cole
*/
public class OrgNetworkImpl extends ReferenceTypeImpl implements OrgNetwork {
@Nullable
private final ReferenceType org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final Configuration configuration;
@Nullable
private final ReferenceType networkPool;
private final Set<String> allowedExternalIpAddresses = Sets.newLinkedHashSet();
public OrgNetworkImpl(String name, String type, URI id, @Nullable ReferenceType org, @Nullable String description,
Iterable<Task> tasks, Configuration configuration, @Nullable ReferenceType networkPool,
Iterable<String> allowedExternalIpAddresses) {
super(name, type, id);
this.org = org;
this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.configuration = checkNotNull(configuration, "configuration");
this.networkPool = networkPool;
Iterables.addAll(this.allowedExternalIpAddresses, checkNotNull(allowedExternalIpAddresses,
"allowedExternalIpAddresses"));
}
public static class ConfigurationImpl implements Configuration {
@Nullable
private final IpScope ipScope;
@Nullable
private final ReferenceType parentNetwork;
private final FenceMode fenceMode;
private final Features features;
public ConfigurationImpl(@Nullable IpScope ipScope, @Nullable ReferenceType parentNetwork, FenceMode fenceMode,
@Nullable Features features) {
this.ipScope = ipScope;
this.parentNetwork = parentNetwork;
this.fenceMode = checkNotNull(fenceMode, "fenceMode");
this.features = features;
}
/**
* {@inheritDoc}
*/
@Override
public IpScope getIpScope() {
return ipScope;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getParentNetwork() {
return parentNetwork;
}
/**
* {@inheritDoc}
*/
@Override
public FenceMode getFenceMode() {
return fenceMode;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public Features getFeatures() {
return features;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((features == null) ? 0 : features.hashCode());
result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode());
result = prime * result + ((ipScope == null) ? 0 : ipScope.hashCode());
result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.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;
ConfigurationImpl other = (ConfigurationImpl) obj;
if (features == null) {
if (other.features != null)
return false;
} else if (!features.equals(other.features))
return false;
if (fenceMode == null) {
if (other.fenceMode != null)
return false;
} else if (!fenceMode.equals(other.fenceMode))
return false;
if (ipScope == null) {
if (other.ipScope != null)
return false;
} else if (!ipScope.equals(other.ipScope))
return false;
if (parentNetwork == null) {
if (other.parentNetwork != null)
return false;
} else if (!parentNetwork.equals(other.parentNetwork))
return false;
return true;
}
@Override
public String toString() {
return "[features=" + features + ", fenceMode=" + fenceMode + ", ipScope=" + ipScope + ", parentNetwork="
+ parentNetwork + "]";
}
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public Configuration getConfiguration() {
return configuration;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getNetworkPool() {
return networkPool;
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getAllowedExternalIpAddresses() {
return allowedExternalIpAddresses;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((allowedExternalIpAddresses == null) ? 0 : allowedExternalIpAddresses.hashCode());
result = prime * result + ((configuration == null) ? 0 : configuration.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((networkPool == null) ? 0 : networkPool.hashCode());
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.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;
OrgNetworkImpl other = (OrgNetworkImpl) obj;
if (allowedExternalIpAddresses == null) {
if (other.allowedExternalIpAddresses != null)
return false;
} else if (!allowedExternalIpAddresses.equals(other.allowedExternalIpAddresses))
return false;
if (configuration == null) {
if (other.configuration != null)
return false;
} else if (!configuration.equals(other.configuration))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (networkPool == null) {
if (other.networkPool != null)
return false;
} else if (!networkPool.equals(other.networkPool))
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
return true;
}
@Override
public String toString() {
return "[allowedExternalIpAddresses=" + allowedExternalIpAddresses + ", configuration=" + configuration
+ ", description=" + description + ", networkPool=" + networkPool + ", org=" + org + ", tasks=" + tasks
+ "]";
}
}

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* The Policy element of a NatService element specifies how packets are handled by the NAT service.
*
*/
public enum NatPolicy {
/**
* packets of this type pass through the firewall in both directions
*/
ALLOW_TRAFFIC,
/**
* only inbound packets of this type pass through the firewall
*/
ALLOW_TRAFFIC_IN, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static NatPolicy fromValue(String policy) {
try {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(policy, "policy")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -0,0 +1,50 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat;
/**
*
* The Protocol specifies the network protocol to which this rule applies
*
* @since vcloud api 0.9
*
* @author Adrian Cole
*/
public enum NatProtocol {
/**
* the rule applies to the TCP protocol
*
* @since vcloud api 0.9
*/
TCP,
/**
* the rule applies to the UDP protocol
*
* @since vcloud api 0.9
*/
UDP,
/**
* the rule applies to the TCP and UDP protocols.
*
* @since vcloud api 0.9
*/
TCP_UDP;
}

View File

@ -0,0 +1,37 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat;
import javax.annotation.Nullable;
/**
*
* Defines a rule associated with Nat
*
* @since vcloud api 0.9
*
* @author Adrian Cole
*/
public interface NatRule {
/**
* IP address to which this NAT rule maps the IP address specified in the InternalIp element.
*/
@Nullable
String getExternalIP();
}

View File

@ -0,0 +1,63 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
*
* The NatType element specifies how network address translation is implemented by the NAT service.
*
* @since vcloud api 0.9
*
* @author Adrian Cole
*/
public enum NatType {
/**
* NAT service implemented by IP address translation
*
* @since vcloud api 0.9
*/
IP_TRANSLATION,
/**
* NAT service implemented by network port forwarding
*
* @since vcloud api 0.9
*/
PORT_FORWARDING, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static NatType fromValue(String natType) {
try {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(natType, "natType")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat.rules;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* The MappingMode element specifies how IP address mapping is implemented by the NAT service.
*
*/
public enum MappingMode {
/**
* the external IP address is specified in the ExternalIP element
*/
MANUAL,
/**
* the external IP address is assigned automatically
*/
AUTOMATIC, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static MappingMode fromValue(String mode) {
try {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(mode, "mode")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -0,0 +1,88 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat.rules;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.nat.NatRule;
/**
* The OneToOneVmRule element describes a NAT rule that specifies network address translation
* details for a single virtual machine. The external IP address can be specified manually or
* assigned automatically at deployment time. The internal IP address is discovered by looking up
* the specified VmReference and NIC ID.
*
* @since vcloud 0.9
* @author Adrian Cole
*/
public class OneToOneVmRule implements NatRule {
private final MappingMode mappingMode;
@Nullable
private final String externalIP;
@Nullable
private final String vAppScopedVmId;
private final int vmNicId;
public OneToOneVmRule(MappingMode mappingMode, @Nullable String externalIp, @Nullable String vAppScopedVmId,
int vmNicId) {
this.mappingMode = checkNotNull(mappingMode, "mappingMode");
this.externalIP = externalIp;
this.vAppScopedVmId = vAppScopedVmId;
this.vmNicId = vmNicId;
}
/**
* @return how IP address mapping is implemented by the NAT service
* @since vcloud 0.9
*/
public MappingMode getMappingMode() {
return mappingMode;
}
/**
* @return if MappingMode is manual, specifies the external IP address of this Vm, otherwise
* null.
* @since vcloud 0.9
*/
@Nullable
@Override
public String getExternalIP() {
return externalIP;
}
/**
* @return readonly identifier created on import
* @since vcloud 0.9
*/
@Nullable
public String getVAppScopedVmId() {
return vAppScopedVmId;
}
/**
* @return device number of the NIC on the referenced virtual machine
* @since vcloud 0.9
*/
public int getVmNicId() {
return vmNicId;
}
}

View File

@ -0,0 +1,136 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat.rules;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.domain.network.nat.NatProtocol;
import org.jclouds.vcloud.domain.network.nat.NatRule;
/**
* The PortForwardingRule element describes a NAT rule that maps an IP address and port in an
* organization network to an external IP address and port.
*
* @since vcloud 0.8
* @author Adrian Cole
*/
public class PortForwardingRule implements NatRule {
private final String externalIP;
private final int externalPort;
private final String internalIP;
private final int internalPort;
private final NatProtocol protocol;
public PortForwardingRule(String externalIP, int externalPort, String internalIP, int internalPort,
NatProtocol protocol) {
this.externalIP = checkNotNull(externalIP, "externalIP");
this.externalPort = externalPort;
this.internalIP = checkNotNull(internalIP, "internalIP");
this.internalPort = internalPort;
this.protocol = checkNotNull(protocol, "protocol");
}
/**
* IP address to which this NAT rule maps the IP address specified in the InternalIp element.
*/
@Override
public String getExternalIP() {
return externalIP;
}
/**
* network port to which this NAT rule maps the port number specified in the InternalPort element
*/
public int getExternalPort() {
return externalPort;
}
/**
* IP address to which this NAT rule maps the IP address specified in the ExternalIp element.
*/
public String getInternalIP() {
return internalIP;
}
/**
* network port to which this NAT rule maps the port number specified in the ExternalPort
* element.
*/
public int getInternalPort() {
return internalPort;
}
/**
* specifies the network protocol to which this rule applies
*/
public NatProtocol getProtocol() {
return protocol;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode());
result = prime * result + externalPort;
result = prime * result + ((internalIP == null) ? 0 : internalIP.hashCode());
result = prime * result + internalPort;
result = prime * result + ((protocol == null) ? 0 : protocol.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;
PortForwardingRule other = (PortForwardingRule) obj;
if (externalIP == null) {
if (other.externalIP != null)
return false;
} else if (!externalIP.equals(other.externalIP))
return false;
if (externalPort != other.externalPort)
return false;
if (internalIP == null) {
if (other.internalIP != null)
return false;
} else if (!internalIP.equals(other.internalIP))
return false;
if (internalPort != other.internalPort)
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
return true;
}
@Override
public String toString() {
return "[externalIP=" + externalIP + ", externalPort=" + externalPort + ", internalIP=" + internalIP
+ ", internalPort=" + internalPort + ", protocol=" + protocol + "]";
}
}

View File

@ -0,0 +1,156 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.network.nat.rules;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.nat.NatProtocol;
import org.jclouds.vcloud.domain.network.nat.NatRule;
/**
* The VmRule element describes a NAT rule that maps an IP address and port in a vApp network to an
* external IP address and port. The external IP address, external port, and internal port are
* specified in the element. The internal IP address is discovered by looking up the specified
* VmReference and VmNicId.
*
* @since vcloud 0.9
* @author Adrian Cole
*/
public class VmRule implements NatRule {
@Nullable
private final String externalIP;
private final int externalPort;
@Nullable
private final String vAppScopedLocalId;
private final int vmNicId;
private final int internalPort;
private final NatProtocol protocol;
public VmRule(@Nullable String externalIP, int externalPort, @Nullable String vAppScopedLocalId, int vmNicId,
int internalPort, NatProtocol protocol) {
this.externalIP = externalIP;
this.externalPort = externalPort;
this.vAppScopedLocalId = vAppScopedLocalId;
this.vmNicId = vmNicId;
this.internalPort = internalPort;
this.protocol = checkNotNull(protocol, "protocol");
}
/**
* IP address to which this NAT rule maps the IP address specified in the InternalIp element.
*/
@Nullable
public String getExternalIP() {
return externalIP;
}
/**
* network port to which this NAT rule maps the port number specified in the InternalPort element
*/
public Integer getExternalPort() {
return externalPort;
}
/**
* @return readonly identifier created on import
* @since vcloud 0.9
*/
@Nullable
public String getVAppScopedLocalId() {
return vAppScopedLocalId;
}
/**
* @return device number of the NIC on the referenced virtual machine
* @since vcloud 0.9
*/
public int getVmNicId() {
return vmNicId;
}
/**
* network port to which this NAT rule maps the port number specified in the ExternalPort
* element.
*/
public Integer getInternalPort() {
return internalPort;
}
/**
* specifies the network protocol to which this rule applies
*/
public NatProtocol getProtocol() {
return protocol;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode());
result = prime * result + externalPort;
result = prime * result + internalPort;
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode());
result = prime * result + vmNicId;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VmRule other = (VmRule) obj;
if (externalIP == null) {
if (other.externalIP != null)
return false;
} else if (!externalIP.equals(other.externalIP))
return false;
if (externalPort != other.externalPort)
return false;
if (internalPort != other.internalPort)
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
if (vAppScopedLocalId == null) {
if (other.vAppScopedLocalId != null)
return false;
} else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId))
return false;
if (vmNicId != other.vmNicId)
return false;
return true;
}
@Override
public String toString() {
return "[externalIP=" + externalIP + ", externalPort=" + externalPort + ", internalPort=" + internalPort
+ ", protocol=" + protocol + ", vAppScopedLocalId=" + vAppScopedLocalId + ", vmNicId=" + vmNicId + "]";
}
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud Catalog.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Catalog {
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud Network.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Network {
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express Org.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Org {
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express Org List.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface OrgList {
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express Task List.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface TasksList {
}

View File

@ -0,0 +1,40 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Represents a component related to vCloud.
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface VCloudLogin {
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express Catalog.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface VDC {
}

View File

@ -0,0 +1,52 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.filters;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.utils.ModifyRequest;
import org.jclouds.vcloud.VCloudToken;
/**
* Adds the VCloud Token to the request as a cookie
*
* @author Adrian Cole
*
*/
@Singleton
public class SetVCloudTokenCookie implements HttpRequestFilter {
private Provider<String> vcloudTokenProvider;
@Inject
public SetVCloudTokenCookie(@VCloudToken Provider<String> authTokenProvider) {
this.vcloudTokenProvider = authTokenProvider;
}
@Override
public HttpRequest filter(HttpRequest request) throws HttpException {
return ModifyRequest.replaceHeader(request, HttpHeaders.COOKIE, "vcloud-token=" + vcloudTokenProvider.get());
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,87 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap;
private final ReferenceType defaultOrg;
private final ReferenceType defaultCatalog;
@Inject
public OrgNameCatalogNameVAppTemplateNameToEndpoint(
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap,
@Org ReferenceType defaultOrg, @Catalog ReferenceType defaultCatalog) {
this.orgCatalogItemMap = orgCatalogItemMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1);
Object catalogItem = Iterables.get(orgCatalog, 2);
if (org == null)
org = defaultOrg.getName();
if (catalog == null)
catalog = defaultCatalog.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);
return checkNotNull(item.getEntity(), "item: " + org + "/" + catalog + "/" + catalogItem + " has no entity")
.getHref();
}
}

View File

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

View File

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

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.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.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC);
}
protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
org.jclouds.vcloud.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();
}
}

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.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.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC);
}
protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
org.jclouds.vcloud.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();
}
}

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<Object, URI>{
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
protected final ReferenceType defaultOrg;
protected final ReferenceType defaultVDC;
@Inject
public OrgNameVDCNameResourceNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @org.jclouds.vcloud.endpoints.VDC ReferenceType defaultVDC) {
this.orgVDCMap = orgVDCMap;
this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgVDC = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgVDC, 0);
Object vDC = Iterables.get(orgVDC, 1);
Object resource = Iterables.get(orgVDC, 2);
if (org == null)
org = defaultOrg.getName();
if (vDC == null)
vDC = defaultVDC.getName();
Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get();
checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org);
if (vDCs == null)
throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
org.jclouds.vcloud.domain.VDC vDCObject = vDCs.get(vDC);
if (vDCObject == null)
throw new NoSuchElementException("vdc " + vDC + " in org " + org + " not found in " + vDCs.keySet());
return getEndpointOfResourceInVDC(org, vDC, resource, vDCObject);
}
protected abstract URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource, VDC vDCObject);
}

View File

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

View File

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

View File

@ -0,0 +1,107 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.releasePayload;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.xml.OrgListHandler;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
/**
* This parses {@link VCloudSession} from HTTP headers.
*
* @author Adrian Cole
*/
@Singleton
public class ParseLoginResponseFromHeaders implements Function<HttpResponse, VCloudSession> {
static final Pattern pattern = Pattern.compile("(vcloud-token)=?([^;]+)(;.*)?");
private final ParseSax.Factory factory;
private final Provider<OrgListHandler> orgHandlerProvider;
@Inject
private ParseLoginResponseFromHeaders(Factory factory, Provider<OrgListHandler> orgHandlerProvider) {
this.factory = factory;
this.orgHandlerProvider = orgHandlerProvider;
}
/**
* parses the http response headers to create a new {@link VCloudSession} object.
*/
public VCloudSession apply(HttpResponse from) {
try {
final String token = parseTokenFromHeaders(from);
final Map<String, ReferenceType> org = factory.create(orgHandlerProvider.get()).parse(
checkNotNull(from.getPayload().getInput(), "no payload in http response to login request %s", from));
return new VCloudSession() {
@VCloudToken
public String getVCloudToken() {
return token;
}
@Org
public Map<String, ReferenceType> getOrgs() {
return org;
}
};
} finally {
releasePayload(from);
}
}
public String parseTokenFromHeaders(HttpResponse from) {
String cookieHeader = from.getFirstHeaderOrNull("x-vcloud-authorization");
if (cookieHeader != null) {
Matcher matcher = pattern.matcher(cookieHeader);
return matcher.find() ? matcher.group(2) : cookieHeader;
} else {
try {
cookieHeader = Iterables.find(from.getHeaders().get(HttpHeaders.SET_COOKIE), Predicates.contains(pattern));
Matcher matcher = pattern.matcher(cookieHeader);
matcher.find();
return matcher.group(2);
} catch (NoSuchElementException e) {
throw new HttpResponseException(String.format("Header %s or %s must be present", "x-vcloud-authorization",
HttpHeaders.SET_COOKIE), null, from);
}
}
}
}

View File

@ -0,0 +1,120 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.handlers;
import static org.jclouds.http.HttpUtils.releasePayload;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.Logger;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudResponseException;
import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.domain.VCloudError.MinorCode;
import org.jclouds.vcloud.util.VCloudUtils;
/**
* This will parse and set an appropriate exception on the command object.
*
* @author Adrian Cole
*
*/
@Singleton
public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
@Resource
protected Logger logger = Logger.NULL;
public static final Pattern RESOURCE_PATTERN = Pattern.compile(".*/v[^/]+/([^/]+)/([0-9]+)");
private final VCloudUtils utils;
@Inject
public ParseVCloudErrorFromHttpResponse(VCloudUtils utils) {
this.utils = utils;
}
public void handleError(HttpCommand command, HttpResponse response) {
HttpRequest request = command.getCurrentRequest();
Exception exception = new HttpResponseException(command, response);
try {
VCloudError error = null;
String message = null;
if (response.getPayload() != null) {
String contentType = response.getPayload().getContentMetadata().getContentType();
if (VCloudMediaType.ERROR_XML.equals(contentType)) {
error = utils.parseErrorFromContent(request, response);
if (error != null) {
message = error.getMessage();
exception = new VCloudResponseException(command, response, error);
}
} else {
try {
message = Strings2.toStringAndClose(response.getPayload().getInput());
exception = message != null ? new HttpResponseException(command, response, message) : exception;
} catch (IOException e) {
}
}
}
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
.getStatusLine());
switch (response.getStatusCode()) {
case 400:
if (error != null
&& (error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.BUSY_ENTITY)
|| (error.getMessage() != null && error.getMessage().indexOf("is not running") != -1))
exception = new IllegalStateException(message, exception);
else
exception = new IllegalArgumentException(message, exception);
break;
case 401:
case 403:
exception = new AuthorizationException(exception.getMessage(), exception);
break;
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
String path = command.getCurrentRequest().getEndpoint().getPath();
Matcher matcher = RESOURCE_PATTERN.matcher(path);
if (matcher.find()) {
message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
} else {
message = path;
}
exception = new ResourceNotFoundException(message);
}
break;
}
} finally {
releasePayload(response);
command.setException(exception);
}
}
}

View File

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

View File

@ -0,0 +1,53 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.reference;
/**
* Configuration properties and constants used in VCloud connections.
*
* @author Adrian Cole
*/
public interface VCloudConstants {
public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema";
/**
* name of the default org that your vApp will join, if an org isn't
* explicitly specified.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_ORG = "jclouds.vcloud.defaults.org";
/**
* name of the default catalog to query, if it isn't explicitly specified.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_CATALOG = "jclouds.vcloud.defaults.catalog";
/**
* name of the VDC that your vApp will join, if a vDC isn't explicitly
* specified.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_VDC = "jclouds.vcloud.defaults.vdc";
/**
* name of the default network, in the default VDC that your vApp will join.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network";
public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode";
public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns";
public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema";
public static final String PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud.timeout.task-complete";
}

View File

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

View File

@ -0,0 +1,101 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.suppliers;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.NoSuchElementException;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public class OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault implements
Function<Iterable<ReferenceType>, ReferenceType> {
protected final ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull;
protected final String configurationKey;
protected final Predicate<ReferenceType> defaultSelector;
public OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(
ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull, String configurationKey,
Predicate<ReferenceType> defaultSelector) {
this.configurationKey = checkNotNull(configurationKey, "configurationKey");
this.valueOfConfigurationKeyOrNull = checkNotNull(valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull");
this.defaultSelector = checkNotNull(defaultSelector, "defaultSelector");
}
@Override
public ReferenceType apply(Iterable<ReferenceType> referenceTypes) {
checkNotNull(referenceTypes, "referenceTypes");
checkArgument(Iterables.size(referenceTypes) > 0,
"No referenceTypes corresponding to configuration key %s present", configurationKey);
if (Iterables.size(referenceTypes) == 1)
return Iterables.getLast(referenceTypes);
String namingPattern = valueOfConfigurationKeyOrNull.apply(configurationKey);
if (namingPattern != null) {
return findReferenceTypeWithNameMatchingPattern(referenceTypes, namingPattern);
} else {
return defaultReferenceType(referenceTypes);
}
}
public ReferenceType defaultReferenceType(Iterable<ReferenceType> referenceTypes) {
return Iterables.find(referenceTypes, defaultSelector);
}
public ReferenceType findReferenceTypeWithNameMatchingPattern(Iterable<ReferenceType> referenceTypes,
String namingPattern) {
try {
return Iterables.find(referenceTypes, new ReferenceTypeNameMatchesPattern(namingPattern));
} catch (NoSuchElementException e) {
throw new NoSuchElementException(String.format(
"referenceType matching pattern [%s], corresponding to configuration key %s, not in %s", namingPattern,
configurationKey, referenceTypes));
}
}
static class ReferenceTypeNameMatchesPattern implements Predicate<ReferenceType> {
private final String namingPattern;
public ReferenceTypeNameMatchesPattern(String namingPattern) {
this.namingPattern = checkNotNull(namingPattern, "namingPattern");
}
@Override
public boolean apply(ReferenceType arg0) {
return arg0.getName().matches(namingPattern);
}
@Override
public String toString() {
return "nameMatchesPattern(" + namingPattern + ")";
}
}
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.util;
import java.net.URI;
import java.util.Map;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.domain.VCloudError.MinorCode;
import org.jclouds.vcloud.domain.internal.ErrorImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
/**
*
* @author Adrian Cole
*/
public class Utils {
public static ReferenceType newReferenceType(Map<String, String> attributes, String defaultType) {
String uri = attributes.get("href");
String type = attributes.get("type");
// savvis org has null href
URI href = (uri != null) ? URI.create(uri) : null;
return new ReferenceTypeImpl(attributes.get("name"), type != null ? type : defaultType, href);
}
public static ReferenceType newReferenceType(Map<String, String> attributes) {
return newReferenceType(attributes, null);
}
public static VCloudError newError(Map<String, String> attributes) {
String vendorSpecificErrorCode = attributes.get("vendorSpecificErrorCode");
int errorCode;
// remove this logic when vcloud 0.8 is gone
try {
errorCode = Integer.parseInt(attributes.get("majorErrorCode"));
} catch (NumberFormatException e) {
errorCode = 500;
vendorSpecificErrorCode = attributes.get("majorErrorCode");
}
MinorCode minorErrorCode = attributes.containsKey("minorErrorCode") ? MinorCode.fromValue(attributes
.get("minorErrorCode")) : null;
if (minorErrorCode == null || minorErrorCode == MinorCode.UNRECOGNIZED) {
vendorSpecificErrorCode = attributes.get("minorErrorCode");
}
return new ErrorImpl(attributes.get("message"), errorCode, minorErrorCode, vendorSpecificErrorCode, attributes
.get("stackTrace"));
}
public static void putReferenceType(Map<String, ReferenceType> map, Map<String, String> attributes) {
map.put(attributes.get("name"), newReferenceType(attributes));
}
}

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.util;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.xml.ErrorHandler;
/**
* Needed to sign and verify requests and responses.
*
* @author Adrian Cole
*/
@Singleton
public class VCloudUtils {
private final ParseSax.Factory factory;
private final Provider<ErrorHandler> errorHandlerProvider;
@Resource
protected Logger logger = Logger.NULL;
@Inject
VCloudUtils(Factory factory, Provider<ErrorHandler> errorHandlerProvider) {
this.factory = factory;
this.errorHandlerProvider = errorHandlerProvider;
}
public VCloudError parseErrorFromContent(HttpRequest request, HttpResponse response) {
// HEAD has no content
if (response.getPayload() == null)
return null;
if (VCloudMediaType.ERROR_XML.equals(response.getPayload().getContentMetadata().getContentType())) {
try {
return (VCloudError) factory.create(errorHandlerProvider.get()).setContext(request).apply(response);
} catch (RuntimeException e) {
logger.warn(e, "error parsing error");
}
}
return null;
}
}

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