revised terremark implementation to only include the minimum vCloud vocabulary it needs

This commit is contained in:
Adrian Cole 2011-07-24 21:39:23 +10:00
parent 560aa95e90
commit 6f6b11c45a
207 changed files with 3541 additions and 10499 deletions

View File

@ -0,0 +1,152 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.io.Payloads;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
/**
* Tests behavior of {@code ParseLoginResponseFromHeaders}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "ParseLoginResponseFromHeadersTest")
public class ParseLoginResponseFromHeadersTest extends BaseHandlerTest {
private ParseLoginResponseFromHeaders parser;
@BeforeTest
void setUp() {
parser = injector.getInstance(ParseLoginResponseFromHeaders.class);
}
@Test
public void testApply() {
HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass()
.getResourceAsStream("/orglist.xml")), ImmutableMultimap.<String, String> of("x-vcloud-authorization",
"vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/"));
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
VCloudSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2");
assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}
@Test
public void testApplyBlueLock() {
HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass()
.getResourceAsStream("/orglist.xml")), ImmutableMultimap.<String, String> of("x-vcloud-authorization",
"MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0="));
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
VCloudSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=");
assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}
@Test
public void testApplyTerremark() {
HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass()
.getResourceAsStream("/orglist.xml")), ImmutableMultimap.<String, String> of("Set-Cookie",
"vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/"));
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
VCloudSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d");
assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}
@Test
public void testApplyTerremarkMultipleCookies() {
HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass()
.getResourceAsStream("/orglist.xml")), ImmutableMultimap.<String, String> builder().put("Set-Cookie",
"NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly")
.put("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").build());
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
VCloudSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d");
assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}
@Test(expectedExceptions = HttpResponseException.class)
public void testUnmatchedCookieThrowsHttpResponseException() {
HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass()
.getResourceAsStream("/orglist.xml")), ImmutableMultimap.<String, String> builder().put("Set-Cookie",
"NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly")
.build());
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
parser.apply(response);
}
@Test(expectedExceptions = HttpResponseException.class)
public void testNoThrowsHttpResponseException() {
HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass()
.getResourceAsStream("/orglist.xml")), ImmutableMultimap.<String, String> of());
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
parser.apply(response);
}
@Test
public void testApplyVirtacore() {
HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass()
.getResourceAsStream("/orglist.xml")), ImmutableMultimap.<String, String> of("x-vcloud-authorization",
"vcloud-token=IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48="));
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
VCloudSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48=");
assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}
}

View File

@ -1,212 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.CATALOG_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.NETWORK_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.ORG_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.TASK_XML;
import static org.jclouds.trmk.vcloud_0_8.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.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.TasksList;
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
import org.jclouds.trmk.vcloud_0_8.domain.network.OrgNetwork;
import org.jclouds.trmk.vcloud_0_8.filters.SetVCloudTokenCookie;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameToTasksListEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameVDCNameNetworkNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.xml.CatalogHandler;
import org.jclouds.trmk.vcloud_0_8.xml.CatalogItemHandler;
import org.jclouds.trmk.vcloud_0_8.xml.OrgHandler;
import org.jclouds.trmk.vcloud_0_8.xml.OrgNetworkHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TaskHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TasksListHandler;
import org.jclouds.trmk.vcloud_0_8.xml.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

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

@ -19,18 +19,23 @@
package org.jclouds.trmk.vcloud_0_8;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOGITEMCUSTOMIZATIONPARAMETERS_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOG_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.INTERNETSERVICE_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.NETWORK_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.NODESERVICE_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.ORG_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.PUBLICIPSLIST_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.PUBLICIP_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.CATALOG_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.ORG_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.VAPP_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.VDC_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.TASKSLIST_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.TASK_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.VAPP_XML;
import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.VDC_XML;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
@ -54,157 +59,364 @@ import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.trmk.vcloud_0_8.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.binders.BindNodeConfigurationToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.binders.BindVAppConfigurationToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.binders.TerremarkBindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.CustomizationParameters;
import org.jclouds.trmk.vcloud_0_8.domain.InternetService;
import org.jclouds.trmk.vcloud_0_8.domain.Network;
import org.jclouds.trmk.vcloud_0_8.domain.Node;
import org.jclouds.trmk.vcloud_0_8.domain.Protocol;
import org.jclouds.trmk.vcloud_0_8.domain.PublicIpAddress;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkCatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkOrg;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkVDC;
import org.jclouds.trmk.vcloud_0_8.domain.TasksList;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
import org.jclouds.trmk.vcloud_0_8.filters.SetVCloudTokenCookie;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndTasksListNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.ParseTaskFromLocationHeader;
import org.jclouds.trmk.vcloud_0_8.functions.ReturnVoidOnDeleteDefaultIp;
import org.jclouds.trmk.vcloud_0_8.functions.VDCURIToInternetServicesEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.VDCURIToPublicIPsEndpoint;
import org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions;
import org.jclouds.trmk.vcloud_0_8.options.AddNodeOptions;
import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.xml.CatalogHandler;
import org.jclouds.trmk.vcloud_0_8.xml.CatalogItemHandler;
import org.jclouds.trmk.vcloud_0_8.xml.CustomizationParametersHandler;
import org.jclouds.trmk.vcloud_0_8.xml.InternetServiceHandler;
import org.jclouds.trmk.vcloud_0_8.xml.InternetServicesHandler;
import org.jclouds.trmk.vcloud_0_8.xml.NodeHandler;
import org.jclouds.trmk.vcloud_0_8.xml.NodesHandler;
import org.jclouds.trmk.vcloud_0_8.xml.OrgHandler;
import org.jclouds.trmk.vcloud_0_8.xml.PublicIpAddressesHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TerremarkCatalogItemHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TerremarkOrgHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TerremarkVDCHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VCloudExpressCatalogHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VCloudExpressVAppHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TaskHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TasksListHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VAppHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VAppTemplateHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VDCHandler;
import org.jclouds.trmk.vcloud_0_8.xml.NetworkHandler;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @see <a href=
* "https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx"
* />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
public interface TerremarkVCloudAsyncClient {
/**
* @see VCloudExpressClient#getCatalogItemInOrg
* @see TerremarkVCloudClient#getCatalogItemInOrg
*/
@Override
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(TerremarkCatalogItemHandler.class)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TerremarkCatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
ListenableFuture<? extends CatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
/**
* @see VCloudExpressClient#getCatalogItem
* @see TerremarkVCloudClient#getCatalogItem
*/
@Override
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(TerremarkCatalogItemHandler.class)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TerremarkCatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
@Override
@GET
@XMLResponseParser(TerremarkOrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends TerremarkOrg> getOrg(@EndpointParam URI orgId);
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see VCloudExpressClient#findOrgNamed
* @see TerremarkVCloudClient#getTasksList
*/
@Override
@GET
@XMLResponseParser(TerremarkOrgHandler.class)
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
/**
* @see TerremarkVCloudClient#findTasksListInOrgNamed
*/
@GET
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(TASKSLIST_XML)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName);
/**
* @see TerremarkVCloudClient#getTask
*/
@GET
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
/**
* @see TerremarkVCloudClient#cancelTask
*/
@POST
@Path("/action/cancel")
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Map<String, ReferenceType> listOrgs();
/**
* @see TerremarkVCloudClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see VCloudClient#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNamed
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#findNetworkInOrgVDCNamed
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> getNetwork(@EndpointParam URI network);
/**
* @see TerremarkVCloudClient#cloneVAppInVDC
*/
@POST
@Path("/action/cloneVApp")
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("vApp") URI toClone,
@PayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, CloneVAppOptions... options);
/**
* @see VCloudClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
/**
* @see TerremarkVCloudClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see TerremarkVCloudClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see TerremarkVCloudClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see TerremarkVCloudClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see TerremarkVCloudClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see TerremarkVCloudClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see TerremarkVCloudClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @see TerremarkVCloudClient#deleteVApp
*/
@DELETE
@ResponseParser(ParseTaskFromLocationHeader.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> deleteVApp(@EndpointParam URI vAppId);
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends TerremarkOrg> findOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
ListenableFuture<? extends org.jclouds.trmk.vcloud_0_8.domain.Org> getOrg(@EndpointParam URI orgId);
/**
* @see TerremarkVCloudClient#findOrgNamed
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends org.jclouds.trmk.vcloud_0_8.domain.Org> findOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
* Terremark does not have multiple catalogs, so we ignore this parameter.
*/
@GET
@Override
@XMLResponseParser(VCloudExpressCatalogHandler.class)
@XMLResponseParser(CatalogHandler.class)
@Consumes(CATALOG_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see TerremarkVCloudExpressClient#getVDC
* @see TerremarkTerremarkVCloudClient#getVDC
*/
@Override
@GET
@XMLResponseParser(TerremarkVDCHandler.class)
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TerremarkVDC> getVDC(@EndpointParam URI vdc);
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see VCloudExpressClient#findVDCInOrgNamed
* @see TerremarkVCloudClient#findVDCInOrgNamed
*/
@GET
@Override
@XMLResponseParser(TerremarkVDCHandler.class)
@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);
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see VCloudExpressClient#instantiateVAppTemplateInVDC
* @see TerremarkVCloudClient#instantiateVAppTemplateInVDC
*/
@Override
@POST
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VCloudExpressVAppHandler.class)
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VCloudExpressVApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@PayloadParam("template") URI template,
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@PayloadParam("template") URI template,
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
/**
* @see TerremarkVCloudExpressClient#getAllInternetServicesInVDC
* @see TerremarkTerremarkVCloudClient#getAllInternetServicesInVDC
*/
@GET
@Consumes(INTERNETSERVICESLIST_XML)
@XMLResponseParser(InternetServicesHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<? extends Set<InternetService>> getAllInternetServicesInVDC(
@EndpointParam(parser = VDCURIToInternetServicesEndpoint.class) URI vDCId);
@EndpointParam(parser = VDCURIToInternetServicesEndpoint.class) URI vDCId);
/**
* @see TerremarkVCloudExpressClient#addInternetServiceToExistingIp
* @see TerremarkTerremarkVCloudClient#addInternetServiceToExistingIp
*/
@POST
@Path("/internetServices")
@ -213,18 +425,18 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
@XMLResponseParser(InternetServiceHandler.class)
@MapBinder(AddInternetServiceOptions.class)
ListenableFuture<? extends InternetService> addInternetServiceToExistingIp(@EndpointParam URI publicIpId,
@PayloadParam("name") String serviceName, @PayloadParam("protocol") Protocol protocol,
@PayloadParam("port") int port, AddInternetServiceOptions... options);
@PayloadParam("name") String serviceName, @PayloadParam("protocol") Protocol protocol,
@PayloadParam("port") int port, AddInternetServiceOptions... options);
/**
* @see TerremarkVCloudExpressClient#deletePublicIp
* @see TerremarkTerremarkVCloudClient#deletePublicIp
*/
@DELETE
@ExceptionParser(ReturnVoidOnDeleteDefaultIp.class)
ListenableFuture<Void> deletePublicIp(@EndpointParam URI ipId);
/**
* @see TerremarkVCloudExpressClient#getInternetServicesOnPublicIP
* @see TerremarkTerremarkVCloudClient#getInternetServicesOnPublicIP
*/
@GET
@Path("/internetServices")
@ -234,7 +446,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
ListenableFuture<? extends Set<InternetService>> getInternetServicesOnPublicIp(@EndpointParam URI ipId);
/**
* @see TerremarkVCloudExpressClient#getPublicIp
* @see TerremarkTerremarkVCloudClient#getPublicIp
*/
@GET
@Consumes(PUBLICIP_XML)
@ -243,24 +455,24 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
ListenableFuture<? extends Set<InternetService>> getPublicIp(@EndpointParam URI ipId);
/**
* @see TerremarkVCloudExpressClient#getPublicIpsAssociatedWithVDC
* @see TerremarkTerremarkVCloudClient#getPublicIpsAssociatedWithVDC
*/
@GET
@Consumes(PUBLICIPSLIST_XML)
@XMLResponseParser(PublicIpAddressesHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<? extends Set<PublicIpAddress>> getPublicIpsAssociatedWithVDC(
@EndpointParam(parser = VDCURIToPublicIPsEndpoint.class) URI vDCId);
@EndpointParam(parser = VDCURIToPublicIPsEndpoint.class) URI vDCId);
/**
* @see TerremarkVCloudExpressClient#deleteInternetService
* @see TerremarkTerremarkVCloudClient#deleteInternetService
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteInternetService(@EndpointParam URI internetServiceId);
/**
* @see TerremarkVCloudExpressClient#getInternetService
* @see TerremarkTerremarkVCloudClient#getInternetService
*/
@GET
@Consumes(INTERNETSERVICESLIST_XML)
@ -269,7 +481,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
ListenableFuture<? extends InternetService> getInternetService(@EndpointParam URI internetServiceId);
/**
* @see TerremarkVCloudExpressClient#addNode
* @see TerremarkTerremarkVCloudClient#addNode
*/
@POST
@Path("/nodeServices")
@ -278,11 +490,11 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
@XMLResponseParser(NodeHandler.class)
@MapBinder(AddNodeOptions.class)
ListenableFuture<? extends Node> addNode(@EndpointParam URI internetServiceId,
@PayloadParam("ipAddress") String ipAddress, @PayloadParam("name") String name,
@PayloadParam("port") int port, AddNodeOptions... options);
@PayloadParam("ipAddress") String ipAddress, @PayloadParam("name") String name,
@PayloadParam("port") int port, AddNodeOptions... options);
/**
* @see TerremarkVCloudExpressClient#getNodes
* @see TerremarkTerremarkVCloudClient#getNodes
*/
@GET
@Path("/nodeServices")
@ -292,7 +504,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
ListenableFuture<? extends Set<Node>> getNodes(@EndpointParam URI internetServiceId);
/**
* @see TerremarkVCloudExpressClient#getNode
* @see TerremarkTerremarkVCloudClient#getNode
*/
@GET
@XMLResponseParser(NodeHandler.class)
@ -301,7 +513,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
ListenableFuture<? extends Node> getNode(@EndpointParam URI nodeId);
/**
* @see TerremarkVCloudExpressClient#configureNode
* @see TerremarkTerremarkVCloudClient#configureNode
*/
@PUT
@Produces(NODESERVICE_XML)
@ -309,17 +521,17 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
@XMLResponseParser(NodeHandler.class)
@MapBinder(BindNodeConfigurationToXmlPayload.class)
ListenableFuture<? extends Node> configureNode(@EndpointParam URI nodeId, @PayloadParam("name") String name,
@PayloadParam("enabled") boolean enabled, @Nullable @PayloadParam("description") String description);
@PayloadParam("enabled") boolean enabled, @Nullable @PayloadParam("description") String description);
/**
* @see TerremarkVCloudExpressClient#deleteNode
* @see TerremarkTerremarkVCloudClient#deleteNode
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteNode(@EndpointParam URI nodeId);
/**
* @see TerremarkVCloudExpressClient#configureVApp
* @see TerremarkTerremarkVCloudClient#configureVApp
*/
@PUT
@Produces(VAPP_XML)
@ -327,8 +539,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
@MapBinder(BindVAppConfigurationToXmlPayload.class)
@ResponseParser(ParseTaskFromLocationHeader.class)
ListenableFuture<? extends Task> configureVApp(
@EndpointParam(parser = BindVAppConfigurationToXmlPayload.class) VCloudExpressVApp vApp,
VAppConfiguration configuration);
@EndpointParam(parser = BindVAppConfigurationToXmlPayload.class) VApp vApp, VAppConfiguration configuration);
/**
* @see TerremarkVCloudClient#getCustomizationOptions

View File

@ -19,66 +19,197 @@
package org.jclouds.trmk.vcloud_0_8;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.CustomizationParameters;
import org.jclouds.trmk.vcloud_0_8.domain.InternetService;
import org.jclouds.trmk.vcloud_0_8.domain.KeyPair;
import org.jclouds.trmk.vcloud_0_8.domain.Network;
import org.jclouds.trmk.vcloud_0_8.domain.Node;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.Protocol;
import org.jclouds.trmk.vcloud_0_8.domain.PublicIpAddress;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkCatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkOrg;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkVDC;
import org.jclouds.trmk.vcloud_0_8.domain.TasksList;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
import org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions;
import org.jclouds.trmk.vcloud_0_8.options.AddNodeOptions;
import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @see <a href=
* "https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx"
* />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudClient extends VCloudExpressClient {
public interface TerremarkVCloudClient {
Catalog getCatalog(URI catalogId);
/**
* {@inheritDoc}
* 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
*/
@Override
TerremarkCatalogItem getCatalogItem(URI catalogItem);
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);
Network findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
Network getNetwork(URI network);
/**
* returns the VDC in the organization associated with the specified name.
* Note that both parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param vdcName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or vdc name that isn't present
*/
VDC findVDCInOrgNamed(String orgName, String vdcName);
TasksList getTasksList(URI tasksListId);
TasksList findTasksListInOrgNamed(String orgName, String tasksListName);
/**
* Whenever the result of a request cannot be returned immediately, the
* server creates a Task object and includes it in the response, as a member
* of the Tasks container in the response body. Each Task has an href value,
* which is a URL that the client can use to retrieve the Task element alone,
* without the rest of the response in which it was contained. All
* information about the task is included in the Task element when it is
* returned in the response's Tasks container, so a client does not need to
* make an additional request to the Task URL unless it wants to follow the
* progress of a task that was incomplete.
*/
Task getTask(URI taskId);
void cancelTask(URI taskId);
/**
*
* @return a listing of all orgs that the current user has access to.
*/
Map<String, ReferenceType> listOrgs();
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);
Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options);
VAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* returns the vapp template corresponding to a catalog item in the catalog
* associated with the specified name. Note that the org and catalog
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that
* isn't present
*/
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
VApp getVApp(URI vApp);
Task deployVApp(URI vAppId);
/**
*
*/
Task undeployVApp(URI vAppId);
/**
* This call powers on the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOnVApp(URI vAppId);
/**
* This call powers off the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOffVApp(URI vAppId);
/**
* This call shuts down the vApp.
*/
void shutdownVApp(URI vAppId);
/**
* This call resets the vApp.
*/
Task resetVApp(URI vAppId);
/**
* This call suspends the vApp.
*/
Task suspendVApp(URI vAppId);
Task deleteVApp(URI vAppId);
/**
* {@inheritDoc}
*/
@Override
TerremarkVDC getVDC(URI catalogItem);
VDC getVDC(URI catalogItem);
/**
* {@inheritDoc}
*/
@Override
TerremarkCatalogItem findCatalogItemInOrgCatalogNamed(String orgName, String catalogName, String itemName);
Org getOrg(URI orgId);
/**
* {@inheritDoc}
*/
@Override
TerremarkOrg getOrg(URI orgId);
/**
* {@inheritDoc}
*/
@Override
TerremarkOrg findOrgNamed(String orgName);
Org findOrgNamed(String orgName);
CustomizationParameters getCustomizationOptions(URI customizationOptions);
@ -90,8 +221,9 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
void deletePublicIp(URI ipId);
/**
* This call adds an internet service to a known, existing public IP. This call is identical to
* Add Internet Service except you specify the public IP in the request.
* This call adds an internet service to a known, existing public IP. This
* call is identical to Add Internet Service except you specify the public IP
* in the request.
*
*/
InternetService addInternetServiceToExistingIp(URI existingIpId, String serviceName, Protocol protocol, int port,
@ -113,9 +245,10 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
/**
* This call adds a node to an existing internet service.
* <p/>
* Every vDC is assigned a network of 60 IP addresses that can be used as nodes. Each node can
* associated with multiple internet service. You can get a list of the available IP addresses by
* calling Get IP Addresses for a Network.
* Every vDC is assigned a network of 60 IP addresses that can be used as
* nodes. Each node can associated with multiple internet service. You can
* get a list of the available IP addresses by calling Get IP Addresses for a
* Network.
*
* @param internetServiceId
* @param ipAddress
@ -135,8 +268,9 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
Set<Node> getNodes(URI internetServiceId);
/**
* This call configures the settings of an existing vApp by passing the new configuration. The
* existing vApp must be in a powered off state (status = 2).
* This call configures the settings of an existing vApp by passing the new
* configuration. The existing vApp must be in a powered off state (status =
* 2).
* <p/>
* You can change the following items for a vApp.
* <ol>
@ -145,16 +279,17 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
* <li>Add a virtual disk</li>
* <li>Delete a virtual disk</li>
* </ol>
* You can make more than one change in a single request. For example, you can increase the
* number of virtual CPUs and the amount of virtual memory in the same request.
* You can make more than one change in a single request. For example, you
* can increase the number of virtual CPUs and the amount of virtual memory
* in the same request.
*
* @param VCloudExpressVApp
* @param VApp
* vApp to change in power state off
* @param configuration
* (s) to change
* @return task of configuration change
*/
Task configureVApp(VCloudExpressVApp vApp, VAppConfiguration configuration);
Task configureVApp(VApp vApp, VAppConfiguration configuration);
/**
*/

View File

@ -26,8 +26,8 @@ import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.trmk.vcloud_0_8.compute.config.VCloudExpressComputeServiceContextModule;
import org.jclouds.trmk.vcloud_0_8.config.VCloudExpressRestClientModule;
import org.jclouds.trmk.vcloud_0_8.compute.config.TerremarkVCloudComputeServiceContextModule;
import org.jclouds.trmk.vcloud_0_8.config.TerremarkVCloudRestClientModule;
import com.google.inject.Injector;
import com.google.inject.Key;
@ -35,39 +35,43 @@ import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Creates {@link VCloudComputeServiceContext} or {@link Injector} instances based on the most
* commonly requested arguments.
* Creates {@link VCloudComputeServiceContext} or {@link Injector} instances
* based on the most commonly requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* Note that Threadsafe objects will be bound as singletons to the Injector or
* Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
* If no <code>Module</code>s are specified, the default
* {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be
* installed.
*
* @author Adrian Cole
* @see VCloudComputeServiceContext
*/
public class VCloudExpressContextBuilder extends ComputeServiceContextBuilder<VCloudExpressClient, VCloudExpressAsyncClient> {
public class TerremarkVCloudContextBuilder<S extends TerremarkVCloudClient, A extends TerremarkVCloudAsyncClient>
extends ComputeServiceContextBuilder<S, A> {
public VCloudExpressContextBuilder(Properties props) {
super(VCloudExpressClient.class, VCloudExpressAsyncClient.class, props);
public TerremarkVCloudContextBuilder(Class<S> syncClientType, Class<A> asyncClientType, Properties props) {
super(syncClientType, asyncClientType, props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new VCloudExpressComputeServiceContextModule());
modules.add(new TerremarkVCloudComputeServiceContextModule());
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new VCloudExpressRestClientModule());
modules.add(new TerremarkVCloudRestClientModule<S, A>(syncClientType, asyncClientType));
}
@Override
public ComputeServiceContext buildComputeServiceContext() {
// need the generic type information
return (ComputeServiceContext) this.buildInjector().getInstance(
Key.get(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressAsyncClient>>() {
}));
Key.get(new TypeLiteral<ComputeServiceContextImpl<S, A>>() {
}));
}
}

View File

@ -20,14 +20,198 @@ package org.jclouds.trmk.vcloud_0_8;
import javax.ws.rs.core.MediaType;
/**
* Resource Types used in Terremark VCloud
*
* @see MediaType
*/
public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
public interface TerremarkVCloudMediaType {
/**
* "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.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");
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
*/
public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml";
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
*/
public final static MediaType ORGLIST_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.orgList+xml");
/**
* "application/vnd.tmrk.vCloud.publicIp+xml"
@ -37,8 +221,7 @@ public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
/**
* "application/vnd.tmrk.vCloud.publicIp+xml"
*/
public final static MediaType PUBLICIP_XML_TYPE = new MediaType("application",
"vnd.tmrk.vCloud.publicIp+xml");
public final static MediaType PUBLICIP_XML_TYPE = new MediaType("application", "vnd.tmrk.vCloud.publicIp+xml");
/**
* "application/vnd.tmrk.vCloud.publicIpsList+xml"
@ -49,7 +232,7 @@ public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
* "application/vnd.tmrk.vCloud.publicIpsList+xml"
*/
public final static MediaType PUBLICIPSLIST_XML_TYPE = new MediaType("application",
"vnd.tmrk.vCloud.publicIpsList+xml");
"vnd.tmrk.vCloud.publicIpsList+xml");
/**
* "application/vnd.tmrk.vCloud.internetService+xml"
@ -60,7 +243,7 @@ public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
* "application/vnd.tmrk.vCloud.internetService+xml"
*/
public final static MediaType INTERNETSERVICE_XML_TYPE = new MediaType("application",
"vnd.tmrk.vCloud.internetService+xml");
"vnd.tmrk.vCloud.internetService+xml");
/**
* "application/vnd.tmrk.vCloud.internetServicesList+xml"
@ -71,7 +254,7 @@ public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
* "application/vnd.tmrk.vCloud.internetServicesList+xml"
*/
public final static MediaType INTERNETSERVICESLIST_XML_TYPE = new MediaType("application",
"vnd.tmrk.vCloud.internetServicesList+xml");
"vnd.tmrk.vCloud.internetServicesList+xml");
/**
* "application/vnd.tmrk.vCloud.nodeService+xml"
@ -81,8 +264,7 @@ public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
/**
* "application/vnd.tmrk.vCloud.nodeService+xml"
*/
public final static MediaType NODESERVICE_XML_TYPE = new MediaType("application",
"vnd.tmrk.vCloud.nodeService+xml");
public final static MediaType NODESERVICE_XML_TYPE = new MediaType("application", "vnd.tmrk.vCloud.nodeService+xml");
/**
* "application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml"
@ -92,6 +274,6 @@ public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
/**
* "application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml"
*/
public final static MediaType CATALOGITEMCUSTOMIZATIONPARAMETERS_XML_TYPE = new MediaType(
"application", "vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml");
public final static MediaType CATALOGITEMCUSTOMIZATIONPARAMETERS_XML_TYPE = new MediaType("application",
"vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml");
}

View File

@ -18,23 +18,35 @@
*/
package org.jclouds.trmk.vcloud_0_8;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME;
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.trmk.vcloud_0_8.domain.FenceMode;
/**
* Builds properties used in Terremark VCloud Clients
*
* @author Adrian Cole
*/
public class TerremarkVCloudPropertiesBuilder extends VCloudExpressPropertiesBuilder {
public class TerremarkVCloudPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty("jclouds.dns_name_length_min", "1");
properties.setProperty("jclouds.dns_name_length_max", "15");
// with ssh key injection comes another reboot. allowing more time
@ -46,17 +58,45 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudExpressPropertiesBui
super(properties);
}
void setExtensions() {
if (properties.getProperty(PROPERTY_TERREMARK_EXTENSION_NS) == null) {
properties.setProperty(
PROPERTY_TERREMARK_EXTENSION_NS,
String.format("urn:tmrk:%s-%s", properties.getProperty(PROPERTY_TERREMARK_EXTENSION_NAME),
properties.getProperty(PROPERTY_TERREMARK_EXTENSION_VERSION)));
}
}
protected void setNs() {
if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null)
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE,
"http://www.vmware.com/vcloud/v" + properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
}
protected void setFenceMode() {
if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) {
if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8"))
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut");
else
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString());
}
}
public TerremarkVCloudPropertiesBuilder withApiVersion(String version) {
properties.setProperty(PROPERTY_API_VERSION, "0.8");
return this;
}
public TerremarkVCloudPropertiesBuilder withSchemaVersion(String version) {
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
return this;
}
@Override
public Properties build() {
setNs();
setFenceMode();
setExtensions();
return super.build();
}
void setExtensions() {
if (properties.getProperty(PROPERTY_TERREMARK_EXTENSION_NS) == null) {
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NS, String.format("urn:tmrk:%s-%s",
properties.getProperty(PROPERTY_TERREMARK_EXTENSION_NAME), properties
.getProperty(PROPERTY_TERREMARK_EXTENSION_VERSION)));
}
}
}

View File

@ -1,271 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.CATALOG_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.NETWORK_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.TASK_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.trmk.vcloud_0_8.VCloudMediaType.VAPP_XML;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.trmk.vcloud_0_8.binders.BindCloneVCloudExpressVAppParamsToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.network.OrgNetwork;
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
import org.jclouds.trmk.vcloud_0_8.filters.SetVCloudTokenCookie;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.ParseTaskFromLocationHeader;
import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.xml.OrgNetworkFromVCloudExpressNetworkHandler;
import org.jclouds.trmk.vcloud_0_8.xml.TaskHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VCloudExpressCatalogHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VCloudExpressVAppHandler;
import org.jclouds.trmk.vcloud_0_8.xml.VCloudExpressVAppTemplateHandler;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Map<String, ReferenceType> listOrgs();
/**
* @see CommonVCloudClient#getCatalog
*/
@Override
@GET
@XMLResponseParser(VCloudExpressCatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see CommonVCloudClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(VCloudExpressCatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see VCloudClient#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VCloudExpressVAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VCloudExpressVAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNamed
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VCloudExpressVAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VCloudExpressVAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#findNetworkInOrgVDCNamed
*/
@Override
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkFromVCloudExpressNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudClient#getNetwork
*/
@Override
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkFromVCloudExpressNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
/**
* @see VCloudExpressClient#instantiateVAppTemplateInVDC
*/
@POST
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VCloudExpressVAppHandler.class)
@MapBinder(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VCloudExpressVApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@PayloadParam("template") URI template,
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
/**
* @see VCloudExpressClient#cloneVAppInVDC
*/
@POST
@Path("/action/cloneVApp")
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVCloudExpressVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("vApp") URI toClone,
@PayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);
/**
* @see VCloudClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VCloudExpressVAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VCloudExpressVApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VCloudExpressVAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VCloudExpressVApp> getVApp(@EndpointParam URI vApp);
/**
* @see VCloudExpressClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#deleteVApp
*/
@DELETE
@ResponseParser(ParseTaskFromLocationHeader.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> deleteVApp(@EndpointParam URI vAppId);
}

View File

@ -1,113 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudExpressClient extends CommonVCloudClient {
/**
*
* @return a listing of all orgs that the current user has access to.
*/
Map<String, ReferenceType> listOrgs();
VCloudExpressVApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName,
InstantiateVAppTemplateOptions... options);
Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options);
VCloudExpressVAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* returns the vapp template corresponding to a catalog item in the catalog associated with the
* specified name. Note that the org and catalog parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that isn't present
*/
VCloudExpressVAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
VCloudExpressVApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
VCloudExpressVApp getVApp(URI vApp);
Task deployVApp(URI vAppId);
/**
*
*/
Task undeployVApp(URI vAppId);
/**
* This call powers on the vApp, as specified in the vApp's ovf:Startup element.
*/
Task powerOnVApp(URI vAppId);
/**
* This call powers off the vApp, as specified in the vApp's ovf:Startup element.
*/
Task powerOffVApp(URI vAppId);
/**
* This call shuts down the vApp.
*/
void shutdownVApp(URI vAppId);
/**
* This call resets the vApp.
*/
Task resetVApp(URI vAppId);
/**
* This call suspends the vApp.
*/
Task suspendVApp(URI vAppId);
Task deleteVApp(URI vAppId);
}

View File

@ -1,41 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8;
import javax.ws.rs.core.MediaType;
/**
* Resource Types used in VCloud express
*
* @see MediaType
*/
public interface VCloudExpressMediaType extends VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
*/
public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.organizationList+xml";
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
*/
public final static MediaType ORGLIST_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.organizationList+xml");
}

View File

@ -1,89 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.trmk.vcloud_0_8.domain.network.FenceMode;
/**
* Builds properties used in VCloud Clients
*
* @author Adrian Cole
*/
public class VCloudExpressPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA,
"http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty("jclouds.dns_name_length_min", "1");
properties.setProperty("jclouds.dns_name_length_max", "80");
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 180l * 1000l + "");
return properties;
}
public VCloudExpressPropertiesBuilder(Properties properties) {
super(properties);
}
protected void setNs() {
if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null)
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v"
+ properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
}
protected void setFenceMode() {
if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) {
if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8"))
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut");
else
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
}
}
public VCloudExpressPropertiesBuilder withApiVersion(String version) {
properties.setProperty(PROPERTY_API_VERSION, "0.8");
return this;
}
public VCloudExpressPropertiesBuilder withSchemaVersion(String version) {
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
return this;
}
@Override
public Properties build() {
setNs();
setFenceMode();
return super.build();
}
}

View File

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

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

@ -37,7 +37,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.trmk.vcloud_0_8.VCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
import com.google.inject.Inject;
@ -49,14 +49,14 @@ import com.jamesmurty.utils.XMLBuilder;
*
*/
@Singleton
public class BindCloneVCloudExpressVAppParamsToXmlPayload implements MapBinder {
public class BindCloneVAppParamsToXmlPayload implements MapBinder {
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
@Inject
public BindCloneVCloudExpressVAppParamsToXmlPayload(BindToStringPayload stringBinder,
public BindCloneVAppParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
@ -88,17 +88,6 @@ public class BindCloneVCloudExpressVAppParamsToXmlPayload implements MapBinder {
}
protected String generateXml(String newName, String vApp, CloneVAppOptions options)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(newName, options.isDeploy(), options.isPowerOn());
if (options.getDescription() != null)
rootBuilder.e("Description").text(options.getDescription());
rootBuilder.e("VApp").a("xmlns", ns).a("href", vApp).a("type", VCloudMediaType.VAPP_XML);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected XMLBuilder buildRoot(String name, boolean deploy, boolean powerOn) throws ParserConfigurationException,
FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("CloneVAppParams").a("name", name).a("deploy", deploy + "")
@ -107,6 +96,17 @@ public class BindCloneVCloudExpressVAppParamsToXmlPayload implements MapBinder {
return rootBuilder;
}
protected String generateXml(String newName, String vApp, CloneVAppOptions options)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(newName, options.isDeploy(), options.isPowerOn());
if (options.getDescription() != null)
rootBuilder.e("Description").text(options.getDescription());
rootBuilder.e("VApp").a("xmlns", ns).a("href", vApp).a("type", TerremarkVCloudMediaType.VAPP_XML);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected CloneVAppOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof CloneVAppOptions) {

View File

@ -21,16 +21,15 @@ package org.jclouds.trmk.vcloud_0_8.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.SortedMap;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.inject.Named;
@ -45,9 +44,9 @@ import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.network.NetworkConfig;
import org.jclouds.trmk.vcloud_0_8.endpoints.Network;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
@ -61,24 +60,21 @@ import com.jamesmurty.utils.XMLBuilder;
*
*/
@Singleton
public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implements MapBinder {
public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder {
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1",
ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
private final ReferenceType defaultNetwork;
private final String defaultFenceMode;
private final String apiVersion;
@Inject
public BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network ReferenceType network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Network ReferenceType network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
this.ns = ns;
this.apiVersion = apiVersion;
this.schema = schema;
this.stringBinder = stringBinder;
this.defaultNetwork = network;
@ -88,7 +84,7 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.remove("name"), "name");
@ -105,15 +101,13 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
NetworkConfig config = Iterables.get(options.getNetworkConfig(), 0);
network = ifNullDefaultTo(config.getParentNetwork(), network);
fenceMode = ifNullDefaultTo(config.getFenceMode(), defaultFenceMode);
if (apiVersion.indexOf("0.8") != -1 && fenceMode.equals("bridged"))
fenceMode = "allowInOut";
networkName = ifNullDefaultTo(config.getNetworkName(), networkName);
}
addQuantity(options, virtualHardwareQuantity);
}
try {
return stringBinder.bindToRequest(request, generateXml(name, template, virtualHardwareQuantity, networkName,
fenceMode, URI.create(network)));
return stringBinder.bindToRequest(request,
generateXml(name, template, virtualHardwareQuantity, networkName, fenceMode, URI.create(network)));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
@ -125,8 +119,8 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
}
protected String generateXml(String name, String template, SortedMap<ResourceType, String> virtualHardwareQuantity,
String networkName, @Nullable String fenceMode, URI network) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
String networkName, @Nullable String fenceMode, URI network) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(name);
rootBuilder.e("VAppTemplate").a("href", template);
@ -140,9 +134,9 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
}
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, @Nullable String fenceMode,
URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e("NetworkConfig").a(
"name", name);
URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e("NetworkConfig")
.a("name", name);
if (fenceMode != null) {
XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
featuresBuilder.e("FenceMode").t(fenceMode);
@ -150,46 +144,13 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
}
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
if (virtualHardwareQuantity.size() > 0) {
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e("VirtualHardwareSection").a(
"xmlns:q1", ns);
for (Entry<ResourceType, String> entry : virtualHardwareQuantity.entrySet()) {
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns",
"http://schemas.dmtf.org/ovf/envelope/1");
itemBuilder.e("InstanceID").a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData").t(
virtualHardwareToInstanceId.get(entry.getKey()));
itemBuilder.e("ResourceType").a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData").t(
entry.getKey().value());
itemBuilder.e("VirtualQuantity").a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData").t(
entry.getValue());
}
}
}
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns).a(
"xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema).a(
"xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns)
.a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema)
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
return rootBuilder;
}
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof InstantiateVAppTemplateOptions) {
return (InstantiateVAppTemplateOptions) arg;
} else if (arg instanceof InstantiateVAppTemplateOptions[]) {
InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg;
return (options.length > 0) ? options[0] : null;
}
}
return null;
}
private void addQuantity(InstantiateVAppTemplateOptions options, Map<ResourceType, String> virtualHardwareQuantity) {
if (options.getCpuCount() != null) {
virtualHardwareQuantity.put(ResourceType.PROCESSOR, options.getCpuCount());
@ -197,10 +158,8 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
if (options.getMemorySizeMegabytes() != null) {
virtualHardwareQuantity.put(ResourceType.MEMORY, options.getMemorySizeMegabytes());
}
if (options.getDiskSizeKilobytes() != null) {
virtualHardwareQuantity.put(ResourceType.DISK_DRIVE, options.getDiskSizeKilobytes());
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
@ -209,4 +168,51 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
protected String ifNullDefaultTo(Object value, String defaultValue) {
return value != null ? value.toString() : checkNotNull(defaultValue, "defaultValue");
}
ThreadLocal<Map<String, String>> propLocal = new ThreadLocal<Map<String, String>>();
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
InstantiateVAppTemplateOptions options = null;
for (Object arg : gRequest.getArgs()) {
if (arg instanceof InstantiateVAppTemplateOptions) {
options = (InstantiateVAppTemplateOptions) arg;
} else if (arg instanceof InstantiateVAppTemplateOptions[]) {
InstantiateVAppTemplateOptions[] optionsA = (InstantiateVAppTemplateOptions[]) arg;
options = (optionsA.length > 0) ? optionsA[0] : null;
}
}
if (options != null)
propLocal.set(options.getProperties());
return options;
}
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a("xmlns:q1", ns)
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
if (propLocal.get() != null) {
for (Entry<String, String> entry : propLocal.get().entrySet()) {
productSectionBuilder.e("Property").a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1")
.a("ovf:key", entry.getKey()).a("ovf:value", entry.getValue());
}
propLocal.set(null);
}
if (virtualHardwareQuantity.size() > 0) {
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e("VirtualHardwareSection").a(
"xmlns:q1", ns);
for (Entry<ResourceType, String> entry : virtualHardwareQuantity.entrySet()) {
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns",
"http://schemas.dmtf.org/ovf/envelope/1");
itemBuilder.e("InstanceID")
.a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(virtualHardwareToInstanceId.get(entry.getKey()));
itemBuilder.e("ResourceType")
.a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getKey().value());
itemBuilder.e("VirtualQuantity")
.a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getValue());
}
}
}
}

View File

@ -46,7 +46,7 @@ import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import com.google.common.base.Function;
import com.google.inject.Inject;
@ -84,7 +84,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
VCloudExpressVApp vApp = checkNotNull(findVAppInArgsOrNull(gRequest), "vApp");
VApp vApp = checkNotNull(findVAppInArgsOrNull(gRequest), "vApp");
checkArgument(vApp.getStatus() == Status.OFF, "vApp must be off!");
VAppConfiguration configuration = checkNotNull(findConfigInArgsOrNull(gRequest), "config");
@ -100,7 +100,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
}
protected String generateXml(VCloudExpressVApp vApp, VAppConfiguration configuration)
protected String generateXml(VApp vApp, VAppConfiguration configuration)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
String name = configuration.getName() != null ? configuration.getName() : vApp.getName();
@ -119,7 +119,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
return rootBuilder.asString(outputProperties);
}
private void addProcessorItem(XMLBuilder sectionBuilder, VCloudExpressVApp vApp, VAppConfiguration configuration) {
private void addProcessorItem(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
ResourceAllocationSettingData cpu = find(vApp.getResourceAllocations(), CIMPredicates
.resourceTypeIn(ResourceType.PROCESSOR));
long quantity = configuration.getProcessorCount() != null ? configuration.getProcessorCount() : cpu
@ -127,14 +127,14 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
addResourceWithQuantity(sectionBuilder, cpu, quantity);
}
private void addMemoryItem(XMLBuilder sectionBuilder, VCloudExpressVApp vApp, VAppConfiguration configuration) {
private void addMemoryItem(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
ResourceAllocationSettingData memory = find(vApp.getResourceAllocations(), CIMPredicates
.resourceTypeIn(ResourceType.MEMORY));
long quantity = configuration.getMemory() != null ? configuration.getMemory() : memory.getVirtualQuantity();
addResourceWithQuantity(sectionBuilder, memory, quantity);
}
private void addDiskItems(XMLBuilder sectionBuilder, VCloudExpressVApp vApp, VAppConfiguration configuration) {
private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
for (ResourceAllocationSettingData disk : filter(vApp.getResourceAllocations(), CIMPredicates
.resourceTypeIn(ResourceType.DISK_DRIVE))) {
if (!configuration.getDisksToDelete().contains(new Integer(disk.getAddressOnParent()))) {
@ -170,7 +170,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
return itemBuilder;
}
protected XMLBuilder buildRoot(VCloudExpressVApp vApp, String name) throws ParserConfigurationException,
protected XMLBuilder buildRoot(VApp vApp, String name) throws ParserConfigurationException,
FactoryConfigurationError {
String status = vApp.getStatus().value();
if (apiVersion.indexOf("0.8") != -1 && "8".equals(status))
@ -181,12 +181,12 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
return rootBuilder;
}
protected VCloudExpressVApp findVAppInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
protected VApp findVAppInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof VCloudExpressVApp) {
return (VCloudExpressVApp) arg;
} else if (arg instanceof VCloudExpressVApp[]) {
VCloudExpressVApp[] vapps = (VCloudExpressVApp[]) arg;
if (arg instanceof VApp) {
return (VApp) arg;
} else if (arg instanceof VApp[]) {
VApp[] vapps = (VApp[]) arg;
return (vapps.length > 0) ? vapps[0] : null;
}
}
@ -216,6 +216,6 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
@Override
public URI apply(Object from) {
return VCloudExpressVApp.class.cast(checkNotNull(from, "from")).getHref();
return VApp.class.cast(checkNotNull(from, "from")).getHref();
}
}

View File

@ -1,59 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.binders;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class TerremarkBindCloneVAppParamsToXmlPayload extends BindCloneVCloudExpressVAppParamsToXmlPayload {
@Inject
public TerremarkBindCloneVAppParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
super(stringBinder, ns,schema);
}
@Override
protected XMLBuilder buildRoot(String name, boolean deploy, boolean powerOn)
throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("CloneVAppParamsType").a("name", name).a("deploy",
deploy+"").a("powerOn", powerOn+"").a("xmlns", ns).a("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation",
ns + " " + schema);
return rootBuilder;
}
}

View File

@ -1,87 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.binders;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.endpoints.Network;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.options.TerremarkInstantiateVAppTemplateOptions;
import com.jamesmurty.utils.XMLBuilder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends
BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload {
@Inject
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Nullable @Network ReferenceType network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
super(stringBinder, apiVersion, ns, schema, network, fenceMode);
}
ThreadLocal<Map<String, String>> propLocal = new ThreadLocal<Map<String, String>>();
@Override
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
InstantiateVAppTemplateOptions options = super.findOptionsInArgsOrNull(gRequest);
if (options != null && options instanceof TerremarkInstantiateVAppTemplateOptions)
propLocal.set(TerremarkInstantiateVAppTemplateOptions.class.cast(options).getProperties());
return options;
}
@Override
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a("xmlns:q1", ns).a(
"xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
if (propLocal.get() != null) {
for (Entry<String, String> entry : propLocal.get().entrySet()) {
productSectionBuilder.e("Property").a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key",
entry.getKey()).a("ovf:value", entry.getValue());
}
propLocal.set(null);
}
super.addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
}
}

View File

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

@ -25,21 +25,23 @@ import static org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions.Buil
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.trmk.vcloud_0_8.domain.InternetService;
import org.jclouds.trmk.vcloud_0_8.domain.Node;
import org.jclouds.trmk.vcloud_0_8.domain.Protocol;
@ -48,10 +50,9 @@ import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.TaskStatus;
import org.jclouds.trmk.vcloud_0_8.domain.TasksList;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.suppliers.InternetServiceAndPublicIpAddressSupplier;
import com.google.common.base.Predicate;
@ -62,50 +63,106 @@ import com.google.common.collect.Sets;
* @author Adrian Cole
*/
@Singleton
public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl {
public class TerremarkVCloudComputeClient {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final TerremarkVCloudClient client;
protected final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
protected final Provider<String> passwordGenerator;
protected final Map<String, Credentials> credentialStore;
protected final InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier;
protected final Map<Status, NodeState> vAppStatusToNodeState;
protected final Predicate<URI> taskTester;
@Inject
protected TerremarkVCloudComputeClient(TerremarkVCloudClient client,
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
@Named("PASSWORD") Provider<String> passwordGenerator, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier) {
super(client, successTester, vAppStatusToNodeState);
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
@Named("PASSWORD") Provider<String> passwordGenerator, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier) {
this.client = client;
this.credentialsProvider = credentialsProvider;
this.passwordGenerator = passwordGenerator;
this.credentialStore = credentialStore;
this.internetServiceAndPublicIpAddressSupplier = internetServiceAndPublicIpAddressSupplier;
this.vAppStatusToNodeState = vAppStatusToNodeState;
this.taskTester = successTester;
}
@Override
public VCloudExpressVApp start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
if (options.getDiskSizeKilobytes() != null) {
logger.warn("trmk does not support resizing the primary disk; unsetting disk size");
}
protected Status getStatus(VApp vApp) {
return vApp.getStatus();
}
/**
* Runs through all commands necessary to startup a vApp, opening at least
* one ip address to the public network. These are the steps:
* <p/>
* instantiate -> deploy -> powerOn
* <p/>
* This command blocks until the vApp is in state {@code VAppStatus#ON}
*
* @param VDC
* id of the virtual datacenter {@code VCloudClient#getDefaultVDC}
* @param templateId
* id of the vAppTemplate you wish to instantiate
* @param name
* name of the vApp
* @param cores
* amount of virtual cpu cores
* @param megs
* amount of ram in megabytes
* @param options
* options for instantiating the vApp; null is ok
* @param portsToOpen
* opens the following ports on the public ip address
* @return map contains at least the following properties
* <ol>
* <li>id - vApp id</li> <li>username - console login user</li> <li>
* password - console login password</li>
* </ol>
*/
public VApp start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
int... portsToOpen) {
// we only get IP addresses after "deploy"
if (portsToOpen.length > 0 && !options.shouldBlock())
throw new IllegalArgumentException("We cannot open ports on terremark unless we can deploy the vapp");
String password = null;
VCloudExpressVAppTemplate template = client.getVAppTemplate(templateId);
if (template.getDescription().indexOf("Windows") != -1
&& options instanceof TerremarkInstantiateVAppTemplateOptions) {
VAppTemplate template = client.getVAppTemplate(templateId);
if (template.getDescription().indexOf("Windows") != -1) {
password = passwordGenerator.get();
TerremarkInstantiateVAppTemplateOptions.class.cast(options).getProperties().put("password", password);
options.getProperties().put("password", password);
}
Credentials defaultCredentials = credentialsProvider.execute(template);
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VCloudExpressVApp vAppResponse = super.start(VDC, templateId, name, options, portsToOpen);
VApp vAppResponse = client.instantiateVAppTemplateInVDC(VDC, templateId, name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
if (options.shouldDeploy()) {
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getHref());
if (options.shouldBlock()) {
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
if (options.shouldPowerOn()) {
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getHref());
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(),
task));
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
}
}
if (password != null) {
credentialStore.put("node#" + vAppResponse.getHref().toASCIIString(), new Credentials(
defaultCredentials.identity, password));
defaultCredentials.identity, password));
}
if (portsToOpen.length > 0)
createPublicAddressMappedToPorts(vAppResponse.getHref(), portsToOpen);
@ -113,51 +170,55 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
}
public String createPublicAddressMappedToPorts(URI vAppId, int... ports) {
VCloudExpressVApp vApp = client.getVApp(vAppId);
VApp vApp = client.getVApp(vAppId);
PublicIpAddress ip = null;
String privateAddress = getLast(vApp.getNetworkToAddresses().values());
for (int port : ports) {
InternetService is = null;
Protocol protocol;
switch (port) {
case 22:
protocol = Protocol.TCP;
break;
case 80:
case 8080:
protocol = Protocol.HTTP;
break;
case 443:
protocol = Protocol.HTTPS;
break;
default:
protocol = Protocol.HTTP;
break;
case 22:
protocol = Protocol.TCP;
break;
case 80:
case 8080:
protocol = Protocol.HTTP;
break;
case 443:
protocol = Protocol.HTTPS;
break;
default:
protocol = Protocol.HTTP;
break;
}
if (ip == null) {
Entry<InternetService, PublicIpAddress> entry = internetServiceAndPublicIpAddressSupplier
.getNewInternetServiceAndIp(vApp, port, protocol);
.getNewInternetServiceAndIp(vApp, port, protocol);
is = entry.getKey();
ip = entry.getValue();
} else {
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress(), protocol, port);
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
is = client.addInternetServiceToExistingIp(
ip.getId(),
vApp.getName() + "-" + port,
protocol,
port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
}
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getName(), is.getPublicIpAddress().getAddress(), is
.getProtocol(), is.getPort());
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getName(), is.getPublicIpAddress().getAddress(),
is.getProtocol(), is.getPort());
logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress(), is.getPort(),
privateAddress, port);
privateAddress, port);
Node node = client.addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port);
logger.debug("<< added Node(%s)", node.getName());
}
return ip != null ? ip.getAddress() : null;
}
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VCloudExpressVApp vApp) {
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) {
checkNotNull(vApp.getVDC(), "VDC reference missing for vApp(%s)", vApp.getName());
Set<PublicIpAddress> ipAddresses = Sets.newHashSet();
SERVICE: for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC().getHref())) {
@ -165,13 +226,13 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
ipAddresses.add(service.getPublicIpAddress());
logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getName(), service.getPublicIpAddress()
.getAddress(), service.getPort(), node.getIpAddress(), node.getPort());
.getAddress(), service.getPort(), node.getIpAddress(), node.getPort());
client.deleteNode(node.getId());
logger.debug("<< deleted Node(%s)", node.getName());
Set<Node> nodes = client.getNodes(service.getId());
if (nodes.size() == 0) {
logger.debug(">> deleting InternetService(%s) %s:%d", service.getName(), service.getPublicIpAddress()
.getAddress(), service.getPort());
.getAddress(), service.getPort());
client.deleteInternetService(service.getId());
logger.debug("<< deleted InternetService(%s)", service.getName());
continue SERVICE;
@ -199,13 +260,21 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
}
/**
* deletes the internet service and nodes associated with the vapp. Deletes the IP address, if
* there are no others using it. Finally, it powers off and deletes the vapp. Note that we do not
* call undeploy, as terremark does not support the command.
* Destroys dependent resources, powers off and deletes the vApp, blocking
* until the following state transition is complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> deleted
* <p/>
* * deletes the internet service and nodes associated with the vapp. Deletes
* the IP address, if there are no others using it. Finally, it powers off
* and deletes the vapp. Note that we do not call undeploy, as terremark does
* not support the command.
*
* @param vAppId
* vApp to stop
*/
@Override
public void stop(URI id) {
VCloudExpressVApp vApp = client.getVApp(id);
VApp vApp = client.getVApp(id);
Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp);
deletePublicIpAddressesWithNoServicesAttached(ipAddresses);
if (vApp.getStatus() != Status.OFF) {
@ -224,19 +293,18 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
logger.debug("<< deleted vApp(%s))", vApp.getName());
}
private void powerOffAndWait(VCloudExpressVApp vApp) {
private void powerOffAndWait(VApp vApp) {
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
Task task = client.powerOffVApp(vApp.getHref());
if (!taskTester.apply(task.getHref()))
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
}
void blockOnLastTask(VCloudExpressVApp vApp) {
TasksList list = client.findTasksListInOrgNamed(null);
void blockOnLastTask(VApp vApp) {
TasksList list = client.findTasksListInOrgNamed(null, null);
try {
Task lastTask = getLast(filter(list.getTasks(), new Predicate<Task>() {
@Override
public boolean apply(Task input) {
return input.getStatus() == TaskStatus.QUEUED || input.getStatus() == TaskStatus.RUNNING;
}
@ -250,11 +318,12 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
}
/**
* returns a set of addresses that are only visible to the private network.
*
* @returns empty set if the node is not found
*/
@Override
public Set<String> getPrivateAddresses(URI id) {
VCloudExpressVApp vApp = client.getVApp(id);
VApp vApp = client.getVApp(id);
if (vApp != null)
return Sets.newHashSet(vApp.getNetworkToAddresses().values());
else
@ -262,11 +331,12 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
}
/**
* returns a set of addresses that are publically visible
*
* @returns empty set if the node is not found
*/
@Override
public Set<String> getPublicAddresses(URI id) {
VCloudExpressVApp vApp = client.getVApp(id);
VApp vApp = client.getVApp(id);
if (vApp != null) {
Set<String> ipAddresses = Sets.newHashSet();
for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC().getHref())) {
@ -281,4 +351,47 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
return ImmutableSet.<String> of();
}
}
/**
* reboots the vApp, blocking until the following state transition is
* complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> {@code VAppStatus#ON}
*
* @param vAppId
* vApp to reboot
*/
public void reset(URI id) {
VApp vApp = refreshVApp(id);
logger.debug(">> resetting vApp(%s)", vApp.getName());
Task task = reset(vApp);
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "resetVApp", vApp.getName(), task));
}
logger.debug("<< on vApp(%s)", vApp.getName());
}
protected void deleteVApp(VApp vApp) {
logger.debug(">> deleting vApp(%s)", vApp.getName());
Task task = client.deleteVApp(vApp.getHref());
if (task != null)
if (!taskTester.apply(task.getHref()))
throw new RuntimeException(String.format("failed to %s %s: %s", "delete", vApp.getName(), task));
}
protected VApp refreshVApp(URI id) {
return client.getVApp(id);
}
protected Task powerOff(VApp vApp) {
return client.powerOffVApp(vApp.getHref());
}
protected Task reset(VApp vApp) {
return client.resetVApp(vApp.getHref());
}
protected Task undeploy(VApp vApp) {
return client.undeployVApp(vApp.getHref());
}
}

View File

@ -1,68 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.compute;
import java.net.URI;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import com.google.inject.ImplementedBy;
/**
*
* @author Adrian Cole
*/
@ImplementedBy(VCloudExpressComputeClientImpl.class)
public interface VCloudExpressComputeClient extends CommonVCloudComputeClient {
/**
* Runs through all commands necessary to startup a vApp, opening at least one ip address to the
* public network. These are the steps:
* <p/>
* instantiate -> deploy -> powerOn
* <p/>
* This command blocks until the vApp is in state {@code VAppStatus#ON}
*
* @param VDC
* id of the virtual datacenter {@code VCloudClient#getDefaultVDC}
* @param templateId
* id of the vAppTemplate you wish to instantiate
* @param name
* name of the vApp
* @param cores
* amount of virtual cpu cores
* @param megs
* amount of ram in megabytes
* @param options
* options for instantiating the vApp; null is ok
* @param portsToOpen
* opens the following ports on the public ip address
* @return map contains at least the following properties
* <ol>
* <li>id - vApp id</li> <li>username - console login user</li> <li> password - console
* login password</li>
* </ol>
*/
VCloudExpressVApp start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
int... portsToOpen);
}

View File

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

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

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

@ -18,15 +18,57 @@
*/
package org.jclouds.trmk.vcloud_0_8.compute.config;
import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.StartVAppWithGroupEncodedIntoName;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudDestroyNodeStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudGetNodeMetadataStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudLifeCycleStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudListNodesStrategy;
/**
* @author Adrian Cole
*/
public class TerremarkBindComputeStrategiesByClass extends VCloudExpressBindComputeStrategiesByClass {
public class TerremarkBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
return TerremarkVCloudDestroyNodeStrategy.class;
}
@Override
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
return TerremarkVCloudGetNodeMetadataStrategy.class;
}
@Override
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
return TerremarkVCloudListNodesStrategy.class;
}
@Override
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
return TerremarkVCloudLifeCycleStrategy.class;
}
@Override
protected Class<? extends ResumeNodeStrategy> defineStartNodeStrategy() {
return TerremarkVCloudLifeCycleStrategy.class;
}
@Override
protected Class<? extends SuspendNodeStrategy> defineStopNodeStrategy() {
return TerremarkVCloudLifeCycleStrategy.class;
}
@Override
protected Class<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
return TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class;

View File

@ -18,17 +18,86 @@
*/
package org.jclouds.trmk.vcloud_0_8.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.find;
import java.util.Set;
import org.jclouds.compute.domain.Image;
import org.jclouds.trmk.vcloud_0_8.compute.suppliers.VAppTemplatesInOrgs;
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.trmk.vcloud_0_8.compute.suppliers.OrgAndVDCToLocationSupplier;
import org.jclouds.trmk.vcloud_0_8.compute.suppliers.StaticHardwareSupplier;
import org.jclouds.trmk.vcloud_0_8.compute.suppliers.VAppTemplatesInOrgs;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.endpoints.VDC;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
public class TerremarkBindComputeSuppliersByClass extends CommonVCloudBindComputeSuppliersByClass {
public class TerremarkBindComputeSuppliersByClass extends BindComputeSuppliersByClass {
@Override
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
return StaticHardwareSupplier.class;
}
@Override
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return OrgAndVDCToLocationSupplier.class;
}
@Override
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
return DefaultVDC.class;
}
@Singleton
public static class DefaultVDC implements Supplier<Location> {
@Singleton
public static final class IsDefaultVDC implements Predicate<Location> {
private final ReferenceType defaultVDC;
@Inject
IsDefaultVDC(@VDC ReferenceType defaultVDC) {
this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC");
}
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString());
}
@Override
public String toString() {
return "isDefaultVDC()";
}
}
private final Supplier<Set<? extends Location>> locationsSupplier;
private final IsDefaultVDC isDefaultVDC;
@Inject
DefaultVDC(@Memoized Supplier<Set<? extends Location>> locationsSupplier, IsDefaultVDC isDefaultVDC) {
this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier");
this.isDefaultVDC = checkNotNull(isDefaultVDC, "isDefaultVDC");
}
@Override
public Location get() {
return find(locationsSupplier.get(), isDefaultVDC);
}
}
@Override
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
return VAppTemplatesInOrgs.class;

View File

@ -19,6 +19,7 @@
package org.jclouds.trmk.vcloud_0_8.compute.config;
import java.security.SecureRandom;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@ -26,25 +27,38 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudAsyncClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeService;
import org.jclouds.trmk.vcloud_0_8.compute.VCloudExpressComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.domain.KeyPairCredentials;
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
import org.jclouds.trmk.vcloud_0_8.compute.functions.ImagesInVCloudExpressOrg;
import org.jclouds.trmk.vcloud_0_8.compute.functions.NodeMetadataToOrgAndName;
import org.jclouds.trmk.vcloud_0_8.compute.functions.TerremarkVCloudExpressVAppToNodeMetadata;
import org.jclouds.trmk.vcloud_0_8.compute.functions.ParseOsFromVAppTemplateName;
import org.jclouds.trmk.vcloud_0_8.compute.functions.VAppToNodeMetadata;
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
@ -53,7 +67,52 @@ import com.google.inject.TypeLiteral;
*
* @author Adrian Cole
*/
public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressComputeServiceContextModule {
public class TerremarkVCloudComputeServiceContextModule 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.UNRECOGNIZED, NodeState.UNRECOGNIZED)
.put(Status.DEPLOYED, 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();
bind(new TypeLiteral<Function<NodeMetadata, OrgAndName>>() {
}).to(new TypeLiteral<NodeMetadataToOrgAndName>() {
});
bind(TemplateOptions.class).to(TerremarkVCloudTemplateOptions.class);
bind(ComputeService.class).to(TerremarkVCloudComputeService.class);
bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(
ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.class);
bind(SecureRandom.class).toInstance(new SecureRandom());
install(new TerremarkBindComputeStrategiesByClass());
install(new TerremarkBindComputeSuppliersByClass());
bindVAppConverter();
bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<TerremarkVCloudClient, TerremarkVCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<RestContext<TerremarkVCloudClient, TerremarkVCloudAsyncClient>>() {
}).to(new TypeLiteral<RestContextImpl<TerremarkVCloudClient, TerremarkVCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
}).to(new TypeLiteral<ImagesInVCloudExpressOrg>() {
});
bind(new TypeLiteral<Function<String, OperatingSystem>>() {
}).to(ParseOsFromVAppTemplateName.class);
}
protected void bindVAppConverter() {
bind(new TypeLiteral<Function<VApp, NodeMetadata>>() {
}).to(VAppToNodeMetadata.class);
}
@Provides
@Singleton
@ -67,36 +126,6 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressCom
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<NodeMetadata, OrgAndName>>() {
}).to(new TypeLiteral<NodeMetadataToOrgAndName>() {
});
bind(TemplateOptions.class).to(TerremarkVCloudTemplateOptions.class);
bind(ComputeService.class).to(TerremarkVCloudComputeService.class);
bind(VCloudExpressComputeClient.class).to(TerremarkVCloudComputeClient.class);
bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(
ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.class);
bind(SecureRandom.class).toInstance(new SecureRandom());
}
@Override
protected void bindVAppConverter() {
bind(new TypeLiteral<Function<VCloudExpressVApp, NodeMetadata>>() {
}).to(TerremarkVCloudExpressVAppToNodeMetadata.class);
}
@Override
public BindComputeStrategiesByClass defineComputeStrategyModule() {
return new TerremarkBindComputeStrategiesByClass();
}
@Override
public BindComputeSuppliersByClass defineComputeSupplierModule() {
return new TerremarkBindComputeSuppliersByClass();
}
@Provides
@Singleton
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap() {

View File

@ -1,73 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.compute.config;
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.StartVAppWithGroupEncodedIntoName;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.VCloudExpressDestroyNodeStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.VCloudExpressGetNodeMetadataStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.VCloudExpressLifeCycleStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.VCloudExpressListNodesStrategy;
/**
* @author Adrian Cole
*/
public class VCloudExpressBindComputeStrategiesByClass extends CommonVCloudBindComputeStrategiesByClass {
@Override
protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return StartVAppWithGroupEncodedIntoName.class;
}
@Override
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
return VCloudExpressDestroyNodeStrategy.class;
}
@Override
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
return VCloudExpressGetNodeMetadataStrategy.class;
}
@Override
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
return VCloudExpressListNodesStrategy.class;
}
@Override
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
return VCloudExpressLifeCycleStrategy.class;
}
@Override
protected Class<? extends ResumeNodeStrategy> defineStartNodeStrategy() {
return VCloudExpressLifeCycleStrategy.class;
}
@Override
protected Class<? extends SuspendNodeStrategy> defineStopNodeStrategy() {
return VCloudExpressLifeCycleStrategy.class;
}
}

View File

@ -1,92 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.compute.config;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressClient;
import org.jclouds.trmk.vcloud_0_8.compute.CommonVCloudComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.VCloudExpressComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.functions.ImagesInVCloudExpressOrg;
import org.jclouds.trmk.vcloud_0_8.compute.functions.ParseOsFromVAppTemplateName;
import org.jclouds.trmk.vcloud_0_8.compute.functions.VCloudExpressVAppToNodeMetadata;
import org.jclouds.trmk.vcloud_0_8.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import com.google.common.base.Function;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/
public class VCloudExpressComputeServiceContextModule extends CommonVCloudComputeServiceContextModule {
@Override
protected void configure() {
super.configure();
bindVAppConverter();
bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<RestContext<VCloudExpressClient, VCloudExpressClient>>() {
}).to(new TypeLiteral<RestContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
}).to(new TypeLiteral<ImagesInVCloudExpressOrg>() {
});
bind(new TypeLiteral<Function<String, OperatingSystem>>() {
}).to(ParseOsFromVAppTemplateName.class);
}
protected void bindVAppConverter() {
bind(new TypeLiteral<Function<VCloudExpressVApp, NodeMetadata>>() {
}).to(VCloudExpressVAppToNodeMetadata.class);
}
@Provides
@Singleton
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudExpressComputeClient in) {
return in;
}
@Override
public BindComputeStrategiesByClass defineComputeStrategyModule() {
return new VCloudExpressBindComputeStrategiesByClass();
}
@Override
public BindComputeSuppliersByClass defineComputeSupplierModule() {
return new CommonVCloudBindComputeSuppliersByClass();
}
}

View File

@ -32,14 +32,14 @@ import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp, Hardware> {
public class HardwareForVCloudExpressVApp implements Function<VApp, Hardware> {
@Resource
protected Logger logger = Logger.NULL;
@ -55,7 +55,7 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
}
@Override
public Hardware apply(VCloudExpressVApp from) {
public Hardware apply(VApp from) {
checkNotNull(from, "VApp");
try {
HardwareBuilder builder = rasdToHardwareBuilder.apply(from.getResourceAllocations());

View File

@ -28,14 +28,14 @@ import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
public class ImageForVCloudExpressVAppTemplate implements Function<VCloudExpressVAppTemplate, Image> {
public class ImageForVCloudExpressVAppTemplate implements Function<VAppTemplate, Image> {
private final FindLocationForResource findLocationForResource;
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
private final Function<String, OperatingSystem> osParser;
@ -56,7 +56,7 @@ public class ImageForVCloudExpressVAppTemplate implements Function<VCloudExpress
}
@Override
public Image apply(VCloudExpressVAppTemplate from) {
public Image apply(VAppTemplate from) {
ImageBuilder builder = new ImageBuilder();
builder.ids(from.getHref().toASCIIString());
builder.uri(from.getHref());

View File

@ -25,7 +25,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInOrg;
import com.google.common.base.Function;
@ -38,13 +38,13 @@ import com.google.common.collect.Iterables;
public class ImagesInVCloudExpressOrg implements Function<Org, Iterable<? extends Image>> {
private final AllCatalogItemsInOrg allCatalogItemsInOrg;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VCloudExpressVAppTemplate>> vAppTemplatesForCatalogItems;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<ImageForVCloudExpressVAppTemplate> imageForVAppTemplateProvider;
@Inject
ImagesInVCloudExpressOrg(AllCatalogItemsInOrg allCatalogItemsInOrg,
Provider<ImageForVCloudExpressVAppTemplate> imageForVAppTemplateProvider,
Function<Iterable<? extends CatalogItem>, Iterable<? extends VCloudExpressVAppTemplate>> vAppTemplatesForCatalogItems) {
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) {
this.imageForVAppTemplateProvider = imageForVAppTemplateProvider;
this.allCatalogItemsInOrg = allCatalogItemsInOrg;
this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems;
@ -53,7 +53,7 @@ public class ImagesInVCloudExpressOrg implements Function<Org, Iterable<? extend
@Override
public Iterable<? extends Image> apply(Org from) {
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
Iterable<? extends VCloudExpressVAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.get().withParent(from));
}

View File

@ -24,9 +24,9 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
import org.jclouds.trmk.vcloud_0_8.functions.VCloudExpressVAppTemplatesForResourceEntities;
import org.jclouds.trmk.vcloud_0_8.functions.VAppTemplatesForResourceEntities;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@ -36,11 +36,11 @@ import com.google.common.collect.Iterables;
*/
@Singleton
public class ImagesInVCloudExpressVDC implements Function<VDC, Iterable<? extends Image>> {
private final VCloudExpressVAppTemplatesForResourceEntities vAppTemplatesForResourceEntities;
private final VAppTemplatesForResourceEntities vAppTemplatesForResourceEntities;
private final ImageForVCloudExpressVAppTemplate imageForVAppTemplateProvider;
@Inject
public ImagesInVCloudExpressVDC(VCloudExpressVAppTemplatesForResourceEntities vAppTemplatesForResourceEntities,
public ImagesInVCloudExpressVDC(VAppTemplatesForResourceEntities vAppTemplatesForResourceEntities,
ImageForVCloudExpressVAppTemplate imageForVAppTemplateProvider) {
this.vAppTemplatesForResourceEntities = checkNotNull(vAppTemplatesForResourceEntities, "vAppTemplatesForResourceEntities");
this.imageForVAppTemplateProvider = checkNotNull(imageForVAppTemplateProvider, "imageForVAppTemplateProvider");
@ -48,7 +48,7 @@ public class ImagesInVCloudExpressVDC implements Function<VDC, Iterable<? extend
@Override
public Iterable<? extends Image> apply(VDC from) {
Iterable<? extends VCloudExpressVAppTemplate> vAppTemplates = vAppTemplatesForResourceEntities.apply(checkNotNull(from, "vdc")
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForResourceEntities.apply(checkNotNull(from, "vdc")
.getResourceEntities().values());
return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.withParent(from));
}

View File

@ -28,7 +28,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.endpoints.VDC;
@ -50,10 +50,10 @@ public class NodeMetadataToOrgAndName implements Function<NodeMetadata, OrgAndNa
final Supplier<Map<String, String>> vdcToOrg;
private final VCloudExpressClient client;
private final TerremarkVCloudClient client;
@Inject
NodeMetadataToOrgAndName(VCloudExpressClient client, @VDC Supplier<Map<String, String>> vdcToOrg) {
NodeMetadataToOrgAndName(TerremarkVCloudClient client, @VDC Supplier<Map<String, String>> vdcToOrg) {
this.vdcToOrg = vdcToOrg;
this.client = client;
}

View File

@ -19,13 +19,13 @@
package org.jclouds.trmk.vcloud_0_8.compute.functions;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.trmk.vcloud_0_8.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
import static org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Template;
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Function;
@ -33,12 +33,12 @@ import com.google.common.base.Function;
* @author Adrian Cole
*/
@Singleton
public class TemplateToInstantiateOptions implements Function<Template, TerremarkInstantiateVAppTemplateOptions> {
public class TemplateToInstantiateOptions implements Function<Template, InstantiateVAppTemplateOptions> {
@Override
public TerremarkInstantiateVAppTemplateOptions apply(Template from) {
TerremarkInstantiateVAppTemplateOptions options = processorCount(
Double.valueOf(getCores(from.getHardware())).intValue()).memory(from.getHardware().getRam());
public InstantiateVAppTemplateOptions apply(Template from) {
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(getCores(from.getHardware())).intValue())
.memory(from.getHardware().getRam());
if (!from.getOptions().shouldBlockUntilRunning())
options.block(false);
String sshKeyFingerprint = TerremarkVCloudTemplateOptions.class.cast(from.getOptions()).getSshKeyFingerprint();

View File

@ -1,97 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Credentials;
import org.jclouds.trmk.vcloud_0_8.compute.VCloudExpressComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.domain.KeyPairCredentials;
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
@Singleton
public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppToNodeMetadata {
private final ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap;
@Inject
public TerremarkVCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images,
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
super(computeClient, credentialStore, vAppStatusToNodeState, hardwareForVCloudExpressVApp,
findLocationForResourceInVDC, images);
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
}
@Override
public NodeMetadata apply(VCloudExpressVApp from) {
NodeMetadata node = super.apply(from);
if (node == null)
return null;
if (node.getGroup() != null) {
node = installCredentialsFromCache(node);
}
return node;
}
NodeMetadata installCredentialsFromCache(NodeMetadata node) {
OrgAndName orgAndName = getOrgAndNameFromNode(node);
if (credentialsMap.containsKey(orgAndName)) {
Credentials creds = credentialsMap.get(orgAndName);
node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(creds).build();
credentialStore.put("node#" + node.getId(), creds);
}
// this is going to need refactoring.. we really need a credential list in the store per
// node.
String adminPasswordKey = "node#" + node.getId() + "#adminPassword";
if (credentialStore.containsKey(adminPasswordKey)) {
node = NodeMetadataBuilder.fromNodeMetadata(node).adminPassword(
credentialStore.get(adminPasswordKey).credential).build();
}
return node;
}
OrgAndName getOrgAndNameFromNode(NodeMetadata node) {
URI orgId = URI.create(node.getLocation().getParent().getId());
OrgAndName orgAndName = new OrgAndName(orgId, node.getGroup());
return orgAndName;
}
}

View File

@ -21,8 +21,10 @@ package org.jclouds.trmk.vcloud_0_8.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -37,9 +39,12 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Credentials;
import org.jclouds.trmk.vcloud_0_8.compute.VCloudExpressComputeClient;
import org.jclouds.domain.Location;
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.domain.KeyPairCredentials;
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@ -48,38 +53,40 @@ import com.google.common.base.Supplier;
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVApp, NodeMetadata> {
public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
protected final VCloudExpressComputeClient computeClient;
protected final TerremarkVCloudComputeClient computeClient;
protected final Map<String, Credentials> credentialStore;
protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC;
protected final HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp;
protected final Map<Status, NodeState> vAppStatusToNodeState;
protected final ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap;
@Inject
protected VCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
protected VAppToNodeMetadata(TerremarkVCloudComputeClient computeClient,
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images) {
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images,
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
this.images = checkNotNull(images, "images");
this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.computeClient = checkNotNull(computeClient, "computeClient");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
}
@Override
public NodeMetadata apply(VCloudExpressVApp from) {
public NodeMetadata apply(VApp from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getHref().toASCIIString());
builder.uri(from.getHref());
builder.name(from.getName());
//terremark
builder.hostname(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
builder.group(parseGroupFromName(from.getName()));
Location vdcLocation = findLocationForResourceInVDC.apply(from.getVDC());
builder.location(vdcLocation);
if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {
builder.operatingSystem(new CIMOperatingSystem(OSType.fromValue(from.getOsType()), "", null, from
.getOperatingSystemDescription()));
@ -97,7 +104,29 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
builder.state(vAppStatusToNodeState.get(from.getStatus()));
builder.publicAddresses(computeClient.getPublicAddresses(from.getHref()));
builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref()));
builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString()));
String group = parseGroupFromName(from.getName());
if (group != null) {
builder.group(group);
installCredentialsFromCache(from.getHref(), URI.create(vdcLocation.getParent().getId()), group, builder);
} else {
builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString()));
}
return builder.build();
}
protected void installCredentialsFromCache(URI nodeId, URI orgId, String group, NodeMetadataBuilder builder) {
OrgAndName orgAndName = new OrgAndName(orgId, group);
if (credentialsMap.containsKey(orgAndName)) {
Credentials creds = credentialsMap.get(orgAndName);
builder.credentials(creds);
credentialStore.put("node#" + nodeId, creds);
}
// this is going to need refactoring.. we really need a credential list in
// the store per
// node.
String adminPasswordKey = "node#" + nodeId + "#adminPassword";
if (credentialStore.containsKey(adminPasswordKey)) {
builder.adminPassword(credentialStore.get(adminPasswordKey).credential);
}
}
}

View File

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

@ -1,136 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressClient;
import org.jclouds.trmk.vcloud_0_8.compute.VCloudExpressComputeClient;
import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressComputeClientImpl extends
CommonVCloudComputeClientImpl<VCloudExpressVAppTemplate, VCloudExpressVApp> implements VCloudExpressComputeClient {
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
public VCloudExpressComputeClientImpl(VCloudExpressClient client, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState) {
super(client, successTester);
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
protected void deleteVApp(VCloudExpressVApp vApp) {
logger.debug(">> deleting vApp(%s)", vApp.getName());
Task task = VCloudExpressClient.class.cast(client).deleteVApp(vApp.getHref());
if (task != null)
if (!taskTester.apply(task.getHref()))
throw new RuntimeException(String.format("failed to %s %s: %s", "delete", vApp.getName(), task));
}
@Override
public VCloudExpressVApp start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VCloudExpressVApp vAppResponse = VCloudExpressClient.class.cast(client).instantiateVAppTemplateInVDC(VDC,
templateId, name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
if (options.shouldDeploy()) {
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = VCloudExpressClient.class.cast(client).deployVApp(vAppResponse.getHref());
if (options.shouldBlock()) {
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
if (options.shouldPowerOn()) {
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = VCloudExpressClient.class.cast(client).powerOnVApp(vAppResponse.getHref());
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(),
task));
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
}
}
return vAppResponse;
}
@Override
public Set<String> getPrivateAddresses(URI id) {
return ImmutableSet.of();
}
@Override
public Set<String> getPublicAddresses(URI id) {
VCloudExpressVApp vApp = refreshVApp(id);
return Sets.newHashSet(vApp.getNetworkToAddresses().values());
}
@Override
protected Status getStatus(VCloudExpressVApp vApp) {
return vApp.getStatus();
}
@Override
protected VCloudExpressVApp refreshVApp(URI id) {
return VCloudExpressClient.class.cast(client).getVApp(id);
}
@Override
protected Task powerOff(VCloudExpressVApp vApp) {
return VCloudExpressClient.class.cast(client).powerOffVApp(vApp.getHref());
}
@Override
protected Task reset(VCloudExpressVApp vApp) {
return VCloudExpressClient.class.cast(client).resetVApp(vApp.getHref());
}
@Override
protected Task undeploy(VCloudExpressVApp vApp) {
return VCloudExpressClient.class.cast(client).undeployVApp(vApp.getHref());
}
}

View File

@ -32,7 +32,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
/**
* @author Adrian Cole
@ -51,9 +51,9 @@ public class ParseVAppTemplateDescriptionToGetDefaultLoginCredentials implements
@Override
public Credentials execute(Object resourceToAuthenticate) {
checkNotNull(resourceToAuthenticate);
checkArgument(resourceToAuthenticate instanceof VCloudExpressVAppTemplate,
checkArgument(resourceToAuthenticate instanceof VAppTemplate,
"Resource must be an VAppTemplate (for Terremark)");
VCloudExpressVAppTemplate template = (VCloudExpressVAppTemplate) resourceToAuthenticate;
VAppTemplate template = (VAppTemplate) resourceToAuthenticate;
String search = template.getDescription() != null ? template.getDescription() : template.getName();
if (search.indexOf("Windows") >= 0) {
return new Credentials("Administrator", null);

View File

@ -33,8 +33,8 @@ import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.domain.Credentials;
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.functions.TemplateToInstantiateOptions;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Function;
@ -45,12 +45,12 @@ import com.google.common.base.Function;
public class StartVAppWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
protected final TerremarkVCloudComputeClient computeClient;
protected final TemplateToInstantiateOptions getOptions;
protected final Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata;
protected final Function<VApp, NodeMetadata> vAppToNodeMetadata;
private final Map<String, Credentials> credentialStore;
@Inject
protected StartVAppWithGroupEncodedIntoName(TerremarkVCloudComputeClient computeClient,
Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata, TemplateToInstantiateOptions getOptions,
Function<VApp, NodeMetadata> vAppToNodeMetadata, TemplateToInstantiateOptions getOptions,
Map<String, Credentials> credentialStore) {
this.computeClient = computeClient;
this.vAppToNodeMetadata = vAppToNodeMetadata;
@ -60,8 +60,8 @@ public class StartVAppWithGroupEncodedIntoName implements CreateNodeWithGroupEnc
@Override
public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
TerremarkInstantiateVAppTemplateOptions options = getOptions.apply(template);
VCloudExpressVApp vApp = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template
InstantiateVAppTemplateOptions options = getOptions.apply(template);
VApp vApp = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template
.getImage().getId()), name, options, template.getOptions().getInboundPorts());
NodeMetadata node = vAppToNodeMetadata.apply(vApp);
NodeMetadataBuilder builder = NodeMetadataBuilder.fromNodeMetadata(node);

View File

@ -28,18 +28,18 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.trmk.vcloud_0_8.compute.CommonVCloudComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressDestroyNodeStrategy implements DestroyNodeStrategy {
protected final CommonVCloudComputeClient computeClient;
public class TerremarkVCloudDestroyNodeStrategy implements DestroyNodeStrategy {
protected final TerremarkVCloudComputeClient computeClient;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudExpressDestroyNodeStrategy(CommonVCloudComputeClient computeClient, GetNodeMetadataStrategy getNode) {
protected TerremarkVCloudDestroyNodeStrategy(TerremarkVCloudComputeClient computeClient, GetNodeMetadataStrategy getNode) {
this.computeClient = computeClient;
this.getNode = getNode;

View File

@ -27,8 +27,8 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressClient;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import com.google.common.base.Function;
@ -36,21 +36,21 @@ import com.google.common.base.Function;
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
public class TerremarkVCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
protected final VCloudExpressClient client;
protected final Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata;
protected final TerremarkVCloudClient client;
protected final Function<VApp, NodeMetadata> vAppToNodeMetadata;
@Inject
protected VCloudExpressGetNodeMetadataStrategy(VCloudExpressClient client,
Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata) {
protected TerremarkVCloudGetNodeMetadataStrategy(TerremarkVCloudClient client,
Function<VApp, NodeMetadata> vAppToNodeMetadata) {
this.client = checkNotNull(client, "client");
this.vAppToNodeMetadata = vAppToNodeMetadata;
}
public NodeMetadata getNode(String in) {
URI id = URI.create(in);
VCloudExpressVApp from = client.getVApp(id);
VApp from = client.getVApp(id);
if (from == null)
return null;
return vAppToNodeMetadata.apply(from);

View File

@ -34,7 +34,7 @@ import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.logging.Logger;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import com.google.common.base.Predicate;
@ -43,17 +43,17 @@ import com.google.common.base.Predicate;
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressLifeCycleStrategy implements RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy {
public class TerremarkVCloudLifeCycleStrategy implements RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final VCloudExpressClient client;
private final TerremarkVCloudClient client;
protected final Predicate<URI> taskTester;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudExpressLifeCycleStrategy(VCloudExpressClient client, Predicate<URI> taskTester,
protected TerremarkVCloudLifeCycleStrategy(TerremarkVCloudClient client, Predicate<URI> taskTester,
GetNodeMetadataStrategy getNode) {
this.client = client;
this.taskTester = taskTester;

View File

@ -34,8 +34,8 @@ import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.logging.Logger;
import org.jclouds.trmk.vcloud_0_8.CommonVCloudClient;
import org.jclouds.trmk.vcloud_0_8.VCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.compute.functions.FindLocationForResource;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
@ -53,12 +53,12 @@ import com.google.inject.Inject;
*/
// TODO REFACTOR!!! needs to be parallel
@Singleton
public class VCloudExpressListNodesStrategy implements ListNodesStrategy {
public class TerremarkVCloudListNodesStrategy implements ListNodesStrategy {
@Resource
@Named(COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudExpressGetNodeMetadataStrategy getNodeMetadata;
protected final CommonVCloudClient client;
protected final TerremarkVCloudGetNodeMetadataStrategy getNodeMetadata;
protected final TerremarkVCloudClient client;
protected final FindLocationForResource findLocationForResourceInVDC;
Set<String> blackListVAppNames = ImmutableSet.<String> of();
@ -71,9 +71,9 @@ public class VCloudExpressListNodesStrategy implements ListNodesStrategy {
private final Supplier<Map<String, ReferenceType>> orgNameToEndpoint;
@Inject
protected VCloudExpressListNodesStrategy(CommonVCloudClient client,
protected TerremarkVCloudListNodesStrategy(TerremarkVCloudClient client,
@Org Supplier<Map<String, ReferenceType>> orgNameToEndpoint,
VCloudExpressGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
TerremarkVCloudGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
this.client = client;
this.orgNameToEndpoint = orgNameToEndpoint;
this.getNodeMetadata = getNodeMetadata;
@ -96,7 +96,8 @@ public class VCloudExpressListNodesStrategy implements ListNodesStrategy {
}
private boolean validVApp(ReferenceType resource) {
return resource.getType().equals(VCloudMediaType.VAPP_XML) && !blackListVAppNames.contains(resource.getName());
return resource.getType().equals(TerremarkVCloudMediaType.VAPP_XML)
&& !blackListVAppNames.contains(resource.getName());
}
private ComputeMetadata convertVAppToComputeMetadata(ReferenceType vdc, ReferenceType resource) {

View File

@ -1,116 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.config;
import static com.google.common.base.Throwables.propagate;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressAsyncClient;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressClient;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressLoginAsyncClient;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
import org.jclouds.trmk.vcloud_0_8.functions.VCloudExpressVAppTemplatesForCatalogItems;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Configures the VCloud authentication service connection, including logging
* and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressClient, A extends VCloudExpressAsyncClient>
extends CommonVCloudRestClientModule<S, A> {
public BaseVCloudExpressRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Map<String, ReferenceType> listOrgs(Supplier<VCloudSession> sessionSupplier) {
return sessionSupplier.get().getOrgs();
}
public BaseVCloudExpressRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap);
}
@Override
protected void configure() {
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VCloudExpressVAppTemplate>>>() {
}).to(new TypeLiteral<VCloudExpressVAppTemplatesForCatalogItems>() {
});
super.configure();
}
@Provides
@Singleton
protected VCloudExpressLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
return factory.create(VCloudExpressLoginAsyncClient.class);
}
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, final VCloudExpressLoginAsyncClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() {
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
}
});
}
}

View File

@ -20,16 +20,21 @@ package org.jclouds.trmk.vcloud_0_8.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_TASKSLIST;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.endpoints.TasksList;
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
/**
@ -38,10 +43,15 @@ import com.google.common.base.Supplier;
*/
@Singleton
public class DefaultTasksListForOrg implements Function<ReferenceType, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<Map<String, ? extends Org>> nameToOrg;
@Inject
public DefaultTasksListForOrg(Supplier<Map<String, ? extends Org>> nameToOrg) {
public DefaultTasksListForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@TasksList Predicate<ReferenceType> defaultSelector, Supplier<Map<String, ? extends Org>> nameToOrg) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_TASKSLIST,
checkNotNull(defaultSelector, "defaultSelector"));
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@ -49,7 +59,7 @@ public class DefaultTasksListForOrg implements Function<ReferenceType, Reference
public ReferenceType apply(ReferenceType defaultOrg) {
org.jclouds.trmk.vcloud_0_8.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return org.getTasksList();
return selector.apply(org.getTasksLists().values());
}
}

View File

@ -23,12 +23,9 @@ 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.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
@ -89,7 +86,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton
@org.jclouds.trmk.vcloud_0_8.endpoints.Catalog
protected Predicate<ReferenceType> provideDefaultCatalogSelector(Injector i) {
return i.getInstance(WriteableCatalog.class);
return Predicates.alwaysTrue();
}
@Provides
@ -114,35 +111,6 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
}, supplier);
}
@Singleton
public static class WriteableCatalog implements Predicate<ReferenceType> {
@Resource
protected Logger logger = Logger.NULL;
private final Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>> catalogsByIdSupplier;
@Inject
public WriteableCatalog(Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.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.trmk.vcloud_0_8.endpoints.VDC
@Singleton

View File

@ -1,123 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.config;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudAsyncClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
import org.jclouds.trmk.vcloud_0_8.endpoints.Keys;
import org.jclouds.trmk.vcloud_0_8.handlers.ParseTerremarkVCloudErrorFromHttpResponse;
import org.jclouds.util.Strings2;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient, A extends TerremarkVCloudAsyncClient>
extends BaseVCloudExpressRestClientModule<S, A> {
public TerremarkRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
public TerremarkRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap);
}
@Singleton
@Provides
@Named("CreateInternetService")
String provideCreateInternetService() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateInternetService.xml"));
}
@Singleton
@Provides
@Named("CreateNodeService")
String provideCreateNodeService() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateNodeService.xml"));
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
}
@Singleton
public static class OrgNameToKeysListSupplier implements Supplier<Map<String, ReferenceType>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final TerremarkVCloudClient client;
@Inject
protected OrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier, TerremarkVCloudClient client) {
this.sessionSupplier = sessionSupplier;
this.client = client;
}
@Override
public Map<String, ReferenceType> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
@Override
public ReferenceType apply(ReferenceType from) {
return client.findOrgNamed(from.getName()).getKeys();
}
});
}
}
@Provides
@Singleton
@Keys
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgNameToKeysListSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
authException, seconds, supplier);
}
@Singleton
@Provides
@Named("CreateKey")
String provideCreateKey() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateKey.xml"));
}
}

View File

@ -20,6 +20,7 @@ package org.jclouds.trmk.vcloud_0_8.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform;
@ -29,6 +30,7 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
@ -44,27 +46,26 @@ 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.trmk.vcloud_0_8.CommonVCloudAsyncClient;
import org.jclouds.trmk.vcloud_0_8.CommonVCloudClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudAsyncClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
import org.jclouds.trmk.vcloud_0_8.VCloudToken;
import org.jclouds.trmk.vcloud_0_8.VCloudVersionsAsyncClient;
import org.jclouds.trmk.vcloud_0_8.compute.functions.FindLocationForResource;
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
import org.jclouds.trmk.vcloud_0_8.endpoints.Keys;
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
import org.jclouds.trmk.vcloud_0_8.endpoints.OrgList;
import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInCatalog;
import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInOrg;
@ -72,8 +73,12 @@ import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogsInOrg;
import org.jclouds.trmk.vcloud_0_8.functions.AllVDCsInOrg;
import org.jclouds.trmk.vcloud_0_8.functions.OrgsForLocations;
import org.jclouds.trmk.vcloud_0_8.functions.OrgsForNames;
import org.jclouds.trmk.vcloud_0_8.handlers.ParseVCloudErrorFromHttpResponse;
import org.jclouds.trmk.vcloud_0_8.functions.VAppTemplatesForCatalogItems;
import org.jclouds.trmk.vcloud_0_8.handlers.ParseTerremarkVCloudErrorFromHttpResponse;
import org.jclouds.trmk.vcloud_0_8.internal.TerremarkVCloudLoginAsyncClient;
import org.jclouds.trmk.vcloud_0_8.internal.TerremarkVCloudVersionsAsyncClient;
import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess;
import org.jclouds.util.Strings2;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
@ -81,26 +86,19 @@ import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Maps;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.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 class TerremarkVCloudRestClientModule<S extends TerremarkVCloudClient, A extends TerremarkVCloudAsyncClient>
extends RestClientModule<S, A> {
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
public TerremarkVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
public TerremarkVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap);
}
@ -108,6 +106,9 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
});
// Ensures we don't retry on authorization failures
bind(new TypeLiteral<AtomicReference<AuthorizationException>>() {
}).toInstance(new AtomicReference<AuthorizationException>());
@ -115,63 +116,55 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
}).to(new TypeLiteral<FindLocationForResource>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends Catalog>>>() {
bind(new TypeLiteral<Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends Catalog>>>() {
}).to(new TypeLiteral<AllCatalogsInOrg>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends VDC>>>() {
bind(new TypeLiteral<Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends VDC>>>() {
}).to(new TypeLiteral<AllVDCsInOrg>() {
});
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends Org>>>() {
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>>>() {
}).to(new TypeLiteral<OrgsForNames>() {
});
bind(new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends Org>>>() {
}).to(new TypeLiteral<OrgsForLocations>() {
bind(
new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>>>() {
}).to(new TypeLiteral<OrgsForLocations>() {
});
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends CatalogItem>>>() {
bind(new TypeLiteral<Function<org.jclouds.trmk.vcloud_0_8.domain.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.trmk.vcloud_0_8.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>>() {
protected Supplier<Map<String, String>> provideVDCtoORG(
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgNameToOrgSuppier) {
return Suppliers.compose(
new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>, Map<String, String>>() {
@Override
public Map<String, String> apply(Map<String, ? extends Org> 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());
@Override
public Map<String, String> apply(Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org> arg0) {
Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
for (Entry<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org> orgr : arg0.entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal.build();
}
}
return returnVal.build();
}
}, orgNameToOrgSuppier);
}, 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>>(
protected Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> provideOrgMapCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgMapSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>>(
authException, seconds, supplier);
}
@ -184,19 +177,20 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
}
@Singleton
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
public static class OrgMapSupplier implements
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> {
protected final Supplier<VCloudSession> sessionSupplier;
protected final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
protected final Function<Iterable<String>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> organizationsForNames;
@Inject
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
Function<Iterable<String>, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@Override
public Map<String, ? extends Org> get() {
public Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org> get() {
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
}
}
@ -304,7 +298,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Provides
@Singleton
@org.jclouds.trmk.vcloud_0_8.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
protected URI provideAuthenticationURI(TerremarkVCloudVersionsAsyncClient 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");
@ -331,13 +325,14 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Provides
@Singleton
protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
return factory.create(VCloudVersionsAsyncClient.class);
protected TerremarkVCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
return factory.create(TerremarkVCloudVersionsAsyncClient.class);
}
@Provides
@Singleton
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
protected org.jclouds.trmk.vcloud_0_8.domain.Org provideOrg(
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultOrg) {
return orgSupplier.get().get(defaultOrg.getName());
}
@ -357,7 +352,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>>(
authException, seconds, supplier);
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> provideOrgVDCSupplierCache(
@ -370,12 +365,13 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Singleton
public static class OrgVDCSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> {
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
private final Function<Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> allVDCsInOrg;
protected final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier;
private final Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> allVDCsInOrg;
@Inject
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> allVDCsInOrg) {
protected OrgVDCSupplier(
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> allVDCsInOrg) {
this.orgSupplier = orgSupplier;
this.allVDCsInOrg = allVDCsInOrg;
}
@ -424,7 +420,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
new Function<org.jclouds.trmk.vcloud_0_8.domain.Catalog, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>() {
@Override
public Map<String, ? extends CatalogItem> apply(org.jclouds.trmk.vcloud_0_8.domain.Catalog from) {
public Map<String, ? extends CatalogItem> apply(
org.jclouds.trmk.vcloud_0_8.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
}
});
@ -443,10 +440,102 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
authException, seconds, supplier);
}
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Map<String, ReferenceType> listOrgs(Supplier<VCloudSession> sessionSupplier) {
return sessionSupplier.get().getOrgs();
}
@Provides
@Singleton
protected TerremarkVCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
return factory.create(TerremarkVCloudLoginAsyncClient.class);
}
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, final TerremarkVCloudLoginAsyncClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() {
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
}
});
}
@Singleton
@Provides
@Named("CreateInternetService")
String provideCreateInternetService() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateInternetService.xml"));
}
@Singleton
@Provides
@Named("CreateNodeService")
String provideCreateNodeService() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateNodeService.xml"));
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
}
}
@Singleton
public static class OrgNameToKeysListSupplier implements Supplier<Map<String, ReferenceType>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final TerremarkVCloudClient client;
@Inject
protected OrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier, TerremarkVCloudClient client) {
this.sessionSupplier = sessionSupplier;
this.client = client;
}
@Override
public Map<String, ReferenceType> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
@Override
public ReferenceType apply(ReferenceType from) {
return client.findOrgNamed(from.getName()).getKeys();
}
});
}
}
@Provides
@Singleton
@Keys
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgNameToKeysListSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
authException, seconds, supplier);
}
@Singleton
@Provides
@Named("CreateKey")
String provideCreateKey() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateKey.xml"));
}
}

View File

@ -1,41 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.config;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressAsyncClient;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressClient;
/**
* Configures the VCloud authentication service connection, including logging
* and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class VCloudExpressRestClientModule extends
BaseVCloudExpressRestClientModule<VCloudExpressClient, VCloudExpressAsyncClient> {
public VCloudExpressRestClientModule() {
super(VCloudExpressClient.class, VCloudExpressAsyncClient.class);
}
}

View File

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

@ -18,7 +18,6 @@
*/
package org.jclouds.trmk.vcloud_0_8.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
@ -33,13 +32,6 @@ import com.google.inject.ImplementedBy;
@org.jclouds.trmk.vcloud_0_8.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
@ -49,24 +41,4 @@ public interface Catalog extends ReferenceType, Map<String, ReferenceType> {
@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

@ -36,4 +36,7 @@ public interface CatalogItem extends ReferenceType {
Map<String, String> getProperties();
ReferenceType getComputeOptions();
ReferenceType getCustomizationOptions();
}

View File

@ -16,7 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.network;
package org.jclouds.trmk.vcloud_0_8.domain;
import static com.google.common.base.Preconditions.checkNotNull;
@ -24,21 +24,18 @@ 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.
* 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
* @since vcloud api 0.8
*/
BRIDGED,
ALLOW_IN_OUT,
/**
* The two networks are not connected.
*

View File

@ -16,39 +16,42 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.network;
package org.jclouds.trmk.vcloud_0_8.domain;
/**
*
* The IpAddressAllocationMode element specifies how an IP address is allocated to this connection.
* A network that is available in a vDC.
*
* @author Adrian Cole
*/
public enum IpAddressAllocationMode {
public interface Network extends ReferenceType {
/**
* no IP addressing mode specified
*
* @since vcloud api 1.0
* @return Description of the network
*/
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;
String getDescription();
/**
*
*
* @return The IP address of the network primary gateway
*/
String getGateway();
/**
* *
*
* @return the network subnet mask
*/
String getNetmask();
/**
* return the network fence mode.
*/
FenceMode getFenceMode();
ReferenceType getNetworkExtension();
ReferenceType getIps();
}

View File

@ -25,7 +25,7 @@ import java.net.URI;
/**
* @author Adrian Cole
*/
public class TerremarkNetwork implements Comparable<TerremarkNetwork> {
public class NetworkExtendedInfo implements Comparable<NetworkExtendedInfo> {
public enum Type {
INTERNAL, DMZ, UNRECOGNIZED;
public static Type fromValue(String type) {
@ -49,7 +49,7 @@ public class TerremarkNetwork implements Comparable<TerremarkNetwork> {
private final String vlan;
private final String friendlyName;
public TerremarkNetwork(String id, URI href, String name, String rnatAddress, String address,
public NetworkExtendedInfo(String id, URI href, String name, String rnatAddress, String address,
String broadcastAddress, String gatewayAddress, Type networkType, String vlan, String friendlyName) {
this.id = id;
this.href = href;
@ -63,7 +63,7 @@ public class TerremarkNetwork implements Comparable<TerremarkNetwork> {
this.friendlyName = friendlyName;
}
public int compareTo(TerremarkNetwork that) {
public int compareTo(NetworkExtendedInfo that) {
return (this == that) ? 0 : getHref().compareTo(that.getHref());
}
@ -132,7 +132,7 @@ public class TerremarkNetwork implements Comparable<TerremarkNetwork> {
return false;
if (getClass() != obj.getClass())
return false;
TerremarkNetwork other = (TerremarkNetwork) obj;
NetworkExtendedInfo other = (NetworkExtendedInfo) obj;
if (address == null) {
if (other.address != null)
return false;

View File

@ -18,21 +18,23 @@
*/
package org.jclouds.trmk.vcloud_0_8.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.domain.internal.OrgImpl;
import org.jclouds.trmk.vcloud_0_8.endpoints.Keys;
import com.google.inject.ImplementedBy;
/**
* A vCloud organization is a high-level abstraction that provides a unit of administration for
* objects and resources. As viewed by a user, an organization (represented by an Org element) can
* contain Catalog, Network, and vDC elements. If there are any queued, running, or recently
* completed tasks owned by a member of the organization, it also contains a TasksList element. As
* viewed by an administrator, an organization also contains users, groups, and other information
* 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
*/
@ -46,14 +48,6 @@ public interface Org extends ReferenceType {
@Nullable
String getDescription();
/**
* full name of the organization
*
* @since vcloud api 1.0
*/
@Nullable
String getFullName();
/**
* @since vcloud api 0.8
*/
@ -65,25 +59,15 @@ public interface Org extends ReferenceType {
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.
* 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.
* there are multiple tasks lists in a terremark org
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
Map<String, ReferenceType> getTasksLists();
@Keys
ReferenceType getKeys();
}

View File

@ -20,7 +20,6 @@ package org.jclouds.trmk.vcloud_0_8.domain;
import java.net.URI;
import org.jclouds.trmk.vcloud_0_8.VCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
import com.google.inject.ImplementedBy;

View File

@ -21,25 +21,22 @@ package org.jclouds.trmk.vcloud_0_8.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Objects such as vAppTemplate, vApp, and Vm have a status attribute whose value indicates the
* state of the object. Status for an object, such as a vAppTemplate or vApp, whose Children (Vm
* objects) each have a status of their own, is computed from the status of the Children.
* 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.
* 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.
*
@ -52,14 +49,7 @@ public enum Status {
* @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.
*
@ -72,109 +62,26 @@ public enum Status {
* @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;
OFF, UNRECOGNIZED, DEPLOYED;
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";
case UNRESOLVED:
return "0";
case RESOLVED:
return "1";
case OFF:
return "2";
case SUSPENDED:
return "3";
case ON:
return "4";
default:
return "7";
}
}
@ -188,40 +95,20 @@ public enum Status {
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;
case 0:
return UNRESOLVED;
case 1:
return RESOLVED;
case 2:
return OFF;
case 3:
return SUSPENDED;
case 4:
return ON;
case 7:
return UNRECOGNIZED;
default:
return UNRECOGNIZED;
}
}

View File

@ -29,7 +29,7 @@ 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.
* object's XML representation. This element is read-only.
*/
@ImplementedBy(TaskImpl.class)
public interface Task extends ReferenceType {

View File

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

View File

@ -1,56 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain;
import java.util.Map;
import org.jclouds.trmk.vcloud_0_8.domain.internal.TerremarkOrgImpl;
import org.jclouds.trmk.vcloud_0_8.endpoints.Keys;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@org.jclouds.trmk.vcloud_0_8.endpoints.Org
@ImplementedBy(TerremarkOrgImpl.class)
public interface TerremarkOrg extends Org {
/**
*
* @see #getKeys
*/
@Deprecated
ReferenceType getKeysList();
@Keys
ReferenceType getKeys();
/**
* there are multiple tasks lists in a terremark org
*
* @see #getTasksLists
*/
@Deprecated
ReferenceType getTasksList();
/**
*/
Map<String, ReferenceType> getTasksLists();
}

View File

@ -1,44 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain;
import org.jclouds.trmk.vcloud_0_8.domain.internal.TerremarkVCloudExpressNetwork;
import org.jclouds.trmk.vcloud_0_8.domain.network.internal.VCloudExpressOrgNetworkAdapter;
/**
*
* @author Adrian Cole
*/
public class TerremarkOrgNetwork extends VCloudExpressOrgNetworkAdapter {
private final TerremarkVCloudExpressNetwork delegate;
public TerremarkOrgNetwork(TerremarkVCloudExpressNetwork in) {
super(in);
this.delegate = in;
}
public ReferenceType getNetworkExtension() {
return delegate.getNetworkExtension();
}
public ReferenceType getIps() {
return delegate.getIps();
}
}

View File

@ -1,45 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain;
import org.jclouds.trmk.vcloud_0_8.domain.internal.TerremarkVDCImpl;
import org.jclouds.trmk.vcloud_0_8.endpoints.Catalog;
import org.jclouds.trmk.vcloud_0_8.endpoints.InternetServices;
import org.jclouds.trmk.vcloud_0_8.endpoints.PublicIPs;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC
@ImplementedBy(TerremarkVDCImpl.class)
public interface TerremarkVDC extends VDC {
@Catalog
ReferenceType getCatalog();
@PublicIPs
ReferenceType getPublicIps();
@InternetServices
ReferenceType getInternetServices();
// TODO getDescription() // what is the type?
}

View File

@ -24,7 +24,7 @@ import javax.annotation.Nullable;
import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.VirtualSystemSettingData;
import org.jclouds.trmk.vcloud_0_8.domain.internal.VCloudExpressVAppImpl;
import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl;
import com.google.common.collect.ListMultimap;
import com.google.inject.ImplementedBy;
@ -36,8 +36,8 @@ import com.google.inject.ImplementedBy;
*
* @author Adrian Cole
*/
@ImplementedBy(VCloudExpressVAppImpl.class)
public interface VCloudExpressVApp extends ReferenceType {
@ImplementedBy(VAppImpl.class)
public interface VApp extends ReferenceType {
ReferenceType getVDC();
Set<ReferenceType> getExtendedInfo();

View File

@ -22,7 +22,7 @@ package org.jclouds.trmk.vcloud_0_8.domain;
*
* @author Adrian Cole
*/
public interface VCloudExpressVAppTemplate extends ReferenceType {
public interface VAppTemplate extends ReferenceType {
Status getStatus();

View File

@ -70,7 +70,7 @@ public interface VCloudError {
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.
* resolved to an object, or the Content-type of the request was incorrect.
*/
RESOURCE_NOT_FOUND,
/**

View File

@ -18,89 +18,29 @@
*/
package org.jclouds.trmk.vcloud_0_8.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.domain.internal.VDCImpl;
import org.jclouds.trmk.vcloud_0_8.endpoints.Catalog;
import org.jclouds.trmk.vcloud_0_8.endpoints.InternetServices;
import org.jclouds.trmk.vcloud_0_8.endpoints.PublicIPs;
import com.google.inject.ImplementedBy;
/**
* A vDC is a deployment environment for vApps. A Vdc element provides a user view of a vDC.
* A vDC is a deployment environment for vApps. A Vdc element provides a user
* view of a vDC.
*
* @author Adrian Cole
*/
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC
@ImplementedBy(VDCImpl.class)
public interface VDC extends ReferenceType {
/**
* 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
*
@ -109,41 +49,20 @@ public interface VDC extends ReferenceType {
Map<String, ReferenceType> getResourceEntities();
/**
* container for OrgNetwork elements that represent organization networks contained by the vDC
* 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();
@Catalog
ReferenceType getCatalog();
/**
* 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();
@PublicIPs
ReferenceType getPublicIps();
/**
* 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();
@InternetServices
ReferenceType getInternetServices();
}

View File

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

@ -22,17 +22,12 @@ 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.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* Locations of resources in vCloud
@ -47,24 +42,16 @@ public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements
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) {
public CatalogImpl(String name, String type, URI href, @Nullable String description,
Map<String, ReferenceType> contents) {
this.name = checkNotNull(name, "name");
this.type = checkNotNull(type, "type");
this.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;
}
/**
@ -83,14 +70,6 @@ public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements
return name;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@ -106,30 +85,6 @@ public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements
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;
@ -137,8 +92,6 @@ public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements
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;
}
@ -167,16 +120,6 @@ public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements
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;

View File

@ -23,9 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.VCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
@ -41,18 +39,22 @@ public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
protected final String description;
protected final ReferenceType entity;
protected 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);
private final ReferenceType computeOptions;
private final ReferenceType customizationOptions;
public CatalogItemImpl(String name, URI id, String description, ReferenceType computeOptions,
ReferenceType customizationOptions, ReferenceType entity, Map<String, String> properties) {
super(name, TerremarkVCloudMediaType.CATALOGITEM_XML, id);
this.description = description;
this.entity = checkNotNull(entity, "entity");
this.properties.putAll(checkNotNull(properties, "properties"));
this.computeOptions = computeOptions;
this.customizationOptions = customizationOptions;
}
@Override
public String getType() {
return VCloudMediaType.CATALOGITEM_XML;
return TerremarkVCloudMediaType.CATALOGITEM_XML;
}
public ReferenceType getEntity() {
@ -68,10 +70,21 @@ public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
return properties;
}
@Override
public ReferenceType getComputeOptions() {
return computeOptions;
}
@Override
public ReferenceType getCustomizationOptions() {
return customizationOptions;
}
@Override
public String toString() {
return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + getDescription()
+ ", entity=" + entity + ", properties=" + properties + "]";
+ ", entity=" + entity + ", computeOptions=" + computeOptions + ", customizationOptions="
+ customizationOptions + ", properties=" + properties + "]";
}
@Override
@ -81,6 +94,8 @@ public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((entity == null) ? 0 : entity.hashCode());
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
result = prime * result + ((computeOptions == null) ? 0 : computeOptions.hashCode());
result = prime * result + ((customizationOptions == null) ? 0 : customizationOptions.hashCode());
return result;
}
@ -108,6 +123,16 @@ public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
return false;
} else if (!properties.equals(other.properties))
return false;
if (computeOptions == null) {
if (other.computeOptions != null)
return false;
} else if (!computeOptions.equals(other.computeOptions))
return false;
if (customizationOptions == null) {
if (other.customizationOptions != null)
return false;
} else if (!customizationOptions.equals(other.customizationOptions))
return false;
return true;
}

View File

@ -0,0 +1,109 @@
/**
*
* 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.trmk.vcloud_0_8.domain.internal;
import java.net.URI;
import org.jclouds.trmk.vcloud_0_8.domain.FenceMode;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Network;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class NetworkImpl extends ReferenceTypeImpl implements Network {
protected final String description;
protected final String gateway;
protected final String netmask;
protected final FenceMode fenceMode;
protected final ReferenceType networkExtension;
protected final ReferenceType ips;
public NetworkImpl(String name, String type, URI id, String description, String gateway, String netmask,
FenceMode fenceMode, ReferenceType networkExtension, ReferenceType ips) {
super(name, type, id);
this.description = description;
this.gateway = gateway;
this.netmask = netmask;
this.fenceMode = fenceMode;
this.networkExtension = networkExtension;
this.ips = ips;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public String getGateway() {
return gateway;
}
/**
* {@inheritDoc}
*/
@Override
public String getNetmask() {
return netmask;
}
/**
* {@inheritDoc}
*/
@Override
public FenceMode getFenceMode() {
return fenceMode;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getIps() {
return ips;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getNetworkExtension() {
return networkExtension;
}
/**
* {@inheritDoc}
*/
@Override
public int compareTo(ReferenceType o) {
return (this == o) ? 0 : getHref().compareTo(o.getHref());
}
}

View File

@ -21,18 +21,14 @@ package org.jclouds.trmk.vcloud_0_8.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.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
/**
* Locations of resources in vCloud
@ -41,31 +37,21 @@ import com.google.common.collect.Maps;
*
*/
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();
private final Map<String, ReferenceType> catalogs;
private final Map<String, ReferenceType> vdcs;
private final ReferenceType keys;
private final ImmutableMap<String, ReferenceType> tasksLists;
public OrgImpl(String name, String type, URI id, String fullName, String description,
Map<String, ReferenceType> catalogs, Map<String, ReferenceType> vdcs, Map<String, ReferenceType> networks,
@Nullable ReferenceType tasksList, Iterable<Task> tasks) {
public OrgImpl(String name, String type, URI id, String description, Map<String, ReferenceType> catalogs,
Map<String, ReferenceType> vdcs, Map<String, ReferenceType> tasksLists, ReferenceType keys) {
super(name, type, id);
this.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;
this.catalogs = ImmutableMap.copyOf(checkNotNull(catalogs, "catalogs"));
this.vdcs = ImmutableMap.copyOf(checkNotNull(vdcs, "vdcs"));
this.tasksLists = ImmutableMap.copyOf(checkNotNull(tasksLists, "tasksLists"));
this.keys = checkNotNull(keys, "keys");
}
@Override
@ -83,31 +69,14 @@ public class OrgImpl extends ReferenceTypeImpl implements Org {
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 + ((keys == null) ? 0 : keys.hashCode());
result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode());
result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode());
return result;
}
@ -131,25 +100,15 @@ public class OrgImpl extends ReferenceTypeImpl implements Org {
return false;
} else if (!description.equals(other.description))
return false;
if (fullName == null) {
if (other.fullName != null)
if (keys == null) {
if (other.keys != null)
return false;
} else if (!fullName.equals(other.fullName))
} else if (!keys.equals(other.keys))
return false;
if (networks == null) {
if (other.networks != null)
if (tasksLists == null) {
if (other.tasksLists != 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))
} else if (!tasksLists.equals(other.tasksLists))
return false;
if (vdcs == null) {
if (other.vdcs != null)
@ -166,9 +125,18 @@ public class OrgImpl extends ReferenceTypeImpl implements Org {
@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 + "]";
return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
+ ", catalogs=" + catalogs + ", tasksLists=" + tasksLists + ", vdcs=" + vdcs + ", keys=" + keys + "]";
}
@Override
public Map<String, ReferenceType> getTasksLists() {
return tasksLists;
}
@Override
public ReferenceType getKeys() {
return keys;
}
}

View File

@ -25,7 +25,7 @@ import java.util.Date;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.VCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.TaskStatus;
@ -51,7 +51,7 @@ public class TaskImpl extends ReferenceTypeImpl implements Task {
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);
super(null, TerremarkVCloudMediaType.TASK_XML, id);
this.operation = operation;
this.status = checkNotNull(status, "status");
this.startTime = startTime;

View File

@ -1,92 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.internal;
import java.net.URI;
import java.util.Map;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkCatalogItem;
/**
*
* @author Adrian Cole
*
*/
public class TerremarkCatalogItemImpl extends CatalogItemImpl implements TerremarkCatalogItem {
private final ReferenceType computeOptions;
private final ReferenceType customizationOptions;
public TerremarkCatalogItemImpl(String name, URI id, String description, ReferenceType computeOptions,
ReferenceType customizationOptions, ReferenceType entity, Map<String, String> properties) {
super(name, id, description, entity, properties);
this.computeOptions = computeOptions;
this.customizationOptions = customizationOptions;
}
@Override
public ReferenceType getComputeOptions() {
return computeOptions;
}
@Override
public ReferenceType getCustomizationOptions() {
return customizationOptions;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((computeOptions == null) ? 0 : computeOptions.hashCode());
result = prime * result + ((customizationOptions == null) ? 0 : customizationOptions.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
TerremarkCatalogItemImpl other = (TerremarkCatalogItemImpl) obj;
if (computeOptions == null) {
if (other.computeOptions != null)
return false;
} else if (!computeOptions.equals(other.computeOptions))
return false;
if (customizationOptions == null) {
if (other.customizationOptions != null)
return false;
} else if (!customizationOptions.equals(other.customizationOptions))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + getDescription()
+ ", entity=" + entity + ", computeOptions=" + computeOptions + ", customizationOptions="
+ customizationOptions + ", properties=" + properties + "]";
}
}

View File

@ -1,69 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkOrg;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/**
* Locations of resources in a Terremark vCloud
*
* @author Adrian Cole
*
*/
public class TerremarkOrgImpl extends OrgImpl implements TerremarkOrg {
private final ReferenceType keysList;
private final ImmutableMap<String, ReferenceType> tasksLists;
public TerremarkOrgImpl(String name, String type, URI id, String description, Map<String, ReferenceType> catalogs,
Map<String, ReferenceType> vdcs, Map<String, ReferenceType> networks, Map<String, ReferenceType> tasksLists,
ReferenceType keysList) {
super(name, type, id, name, description, catalogs, vdcs, networks, Iterables.get(tasksLists.values(), 0),
ImmutableList.<Task> of());
this.tasksLists = ImmutableMap.copyOf(checkNotNull(tasksLists, "tasksLists"));
this.keysList = checkNotNull(keysList, "keysList");
}
@Override
public ReferenceType getKeysList() {
return keysList;
}
@Override
public Map<String, ReferenceType> getTasksLists() {
return tasksLists;
}
@Override
public ReferenceType getKeys() {
return keysList;
}
}

View File

@ -1,94 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.internal;
import java.net.URI;
import java.util.Set;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.network.FenceMode;
import org.jclouds.trmk.vcloud_0_8.domain.network.firewall.FirewallRule;
import org.jclouds.trmk.vcloud_0_8.domain.network.internal.VCloudExpressNetworkImpl;
import org.jclouds.trmk.vcloud_0_8.domain.network.nat.rules.PortForwardingRule;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class TerremarkVCloudExpressNetwork extends VCloudExpressNetworkImpl {
private final ReferenceType networkExtension;
private final ReferenceType ips;
public TerremarkVCloudExpressNetwork(String name, String type, URI id, String description, Set<String> dnsServers,
String gateway, String netmask, Set<FenceMode> fenceModes, Boolean dhcp, Set<PortForwardingRule> natRules,
Set<FirewallRule> firewallRules, ReferenceType networkExtension, ReferenceType ips) {
super(name, type, id, description, dnsServers, gateway, netmask, fenceModes, dhcp, natRules, firewallRules);
this.networkExtension = networkExtension;
this.ips = ips;
}
public ReferenceType getNetworkExtension() {
return networkExtension;
}
public ReferenceType getIps() {
return ips;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((ips == null) ? 0 : ips.hashCode());
result = prime * result + ((networkExtension == null) ? 0 : networkExtension.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;
TerremarkVCloudExpressNetwork other = (TerremarkVCloudExpressNetwork) obj;
if (ips == null) {
if (other.ips != null)
return false;
} else if (!ips.equals(other.ips))
return false;
if (networkExtension == null) {
if (other.networkExtension != null)
return false;
} else if (!networkExtension.equals(other.networkExtension))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
+ ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules="
+ firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" + netmask + ",ips="
+ ips + ", networkExtension=" + networkExtension + "]";
}
}

View File

@ -1,109 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.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.trmk.vcloud_0_8.domain.AllocationModel;
import org.jclouds.trmk.vcloud_0_8.domain.Capacity;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.TerremarkVDC;
import org.jclouds.trmk.vcloud_0_8.domain.VDCStatus;
/**
* Locations of resources in Terremark vDC
*
* @author Adrian Cole
*
*/
public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC {
private final ReferenceType catalog;
private final ReferenceType publicIps;
private final ReferenceType internetServices;
public TerremarkVDCImpl(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, ReferenceType catalog, ReferenceType publicIps,
ReferenceType internetServices) {
super(name, type, id, status, org, description, tasks, allocationModel, storageCapacity, cpuCapacity,
memoryCapacity, resourceEntities, availableNetworks, nicQuota, networkQuota, vmQuota, isEnabled);
this.catalog = checkNotNull(catalog, "catalog");
this.publicIps = checkNotNull(publicIps, "publicIps");
this.internetServices = checkNotNull(internetServices, "internetServices");
}
public ReferenceType getCatalog() {
return catalog;
}
public ReferenceType getPublicIps() {
return publicIps;
}
public ReferenceType getInternetServices() {
return internetServices;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
result = prime * result + ((internetServices == null) ? 0 : internetServices.hashCode());
result = prime * result + ((publicIps == null) ? 0 : publicIps.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;
TerremarkVDCImpl other = (TerremarkVDCImpl) obj;
if (catalog == null) {
if (other.catalog != null)
return false;
} else if (!catalog.equals(other.catalog))
return false;
if (internetServices == null) {
if (other.internetServices != null)
return false;
} else if (!internetServices.equals(other.internetServices))
return false;
if (publicIps == null) {
if (other.publicIps != null)
return false;
} else if (!publicIps.equals(other.publicIps))
return false;
return true;
}
}

View File

@ -26,10 +26,10 @@ import java.util.Set;
import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.VirtualSystemSettingData;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressMediaType;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVApp;
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import com.google.common.collect.ListMultimap;
@ -38,7 +38,7 @@ import com.google.common.collect.ListMultimap;
* @author Adrian Cole
*
*/
public class VCloudExpressVAppImpl implements VCloudExpressVApp {
public class VAppImpl implements VApp {
private final String name;
private final URI href;
private final ReferenceType vDC;
@ -51,14 +51,14 @@ public class VCloudExpressVAppImpl implements VCloudExpressVApp {
private final Set<ResourceAllocationSettingData> resourceAllocations;
private final Integer osType;
public VCloudExpressVAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC,
public VAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC,
ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription,
VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations) {
this(name, href, status, size, vDC, networkToAddresses, osType, operatingSystemDescription, system,
resourceAllocations, new HashSet<ReferenceType>());
}
public VCloudExpressVAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC,
public VAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC,
ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription,
VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations,
Set<ReferenceType> extendedInfo) {
@ -141,7 +141,7 @@ public class VCloudExpressVAppImpl implements VCloudExpressVApp {
return false;
if (getClass() != obj.getClass())
return false;
VCloudExpressVAppImpl other = (VCloudExpressVAppImpl) obj;
VAppImpl other = (VAppImpl) obj;
if (href == null) {
if (other.href != null)
return false;
@ -225,7 +225,7 @@ public class VCloudExpressVAppImpl implements VCloudExpressVApp {
@Override
public String getType() {
return VCloudExpressMediaType.VAPP_XML;
return TerremarkVCloudMediaType.VAPP_XML;
}
@Override

View File

@ -22,22 +22,22 @@ import java.net.URI;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.VCloudExpressMediaType;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudExpressVAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
/**
*
* @author Adrian Cole
*
*/
public class VCloudExpressVAppTemplateImpl extends ReferenceTypeImpl implements VCloudExpressVAppTemplate {
public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate {
private final String description;
private final Status status;
public VCloudExpressVAppTemplateImpl(String name, URI id, @Nullable String description, @Nullable Status status) {
super(name, VCloudExpressMediaType.VAPPTEMPLATE_XML, id);
public VAppTemplateImpl(String name, URI id, @Nullable String description, @Nullable Status status) {
super(name, TerremarkVCloudMediaType.VAPPTEMPLATE_XML, id);
this.description = description;
this.status = status;
}
@ -68,7 +68,7 @@ public class VCloudExpressVAppTemplateImpl extends ReferenceTypeImpl implements
return false;
if (getClass() != obj.getClass())
return false;
VCloudExpressVAppTemplateImpl other = (VCloudExpressVAppTemplateImpl) obj;
VAppTemplateImpl other = (VAppTemplateImpl) obj;
if (description == null) {
if (other.description != null)
return false;

View File

@ -21,21 +21,14 @@ package org.jclouds.trmk.vcloud_0_8.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.trmk.vcloud_0_8.domain.AllocationModel;
import org.jclouds.trmk.vcloud_0_8.domain.Capacity;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.VDC;
import org.jclouds.trmk.vcloud_0_8.domain.VDCStatus;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
/**
* Locations of resources in vCloud
@ -45,62 +38,28 @@ import com.google.common.collect.Maps;
*/
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;
private final ReferenceType catalog;
private final ReferenceType publicIps;
private final ReferenceType internetServices;
private final Map<String, ReferenceType> resourceEntities;
private final Map<String, ReferenceType> availableNetworks;
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
public VDCImpl(String name, String type, URI href, @Nullable String description, ReferenceType catalog,
ReferenceType publicIps, ReferenceType internetServices, Map<String, ReferenceType> resourceEntities,
Map<String, ReferenceType> availableNetworks) {
super(name, type, href);
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;
this.catalog = checkNotNull(catalog, "catalog");
this.publicIps = checkNotNull(publicIps, "publicIps");
this.internetServices = checkNotNull(internetServices, "internetServices");
this.resourceEntities = ImmutableMap.copyOf(checkNotNull(resourceEntities, "resourceEntities"));
this.availableNetworks = ImmutableMap.copyOf(checkNotNull(availableNetworks, "availableNetworks"));
}
/**
* {@inheritDoc}
*/
@Override
public VDCStatus getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getOrg() {
return org;
}
/**
* {@inheritDoc}
* @InheritDoc
*/
@Override
public String getDescription() {
@ -108,47 +67,31 @@ public class VDCImpl extends ReferenceTypeImpl implements VDC {
}
/**
* {@inheritDoc}
* @InheritDoc
*/
@Override
public List<Task> getTasks() {
return tasks;
public ReferenceType getCatalog() {
return catalog;
}
/**
* {@inheritDoc}
* @InheritDoc
*/
@Override
public AllocationModel getAllocationModel() {
return allocationModel;
public ReferenceType getPublicIps() {
return publicIps;
}
/**
* {@inheritDoc}
* @InheritDoc
*/
@Override
public Capacity getStorageCapacity() {
return storageCapacity;
public ReferenceType getInternetServices() {
return internetServices;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getCpuCapacity() {
return cpuCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getMemoryCapacity() {
return memoryCapacity;
}
/**
* {@inheritDoc}
* @InheritDoc
*/
@Override
public Map<String, ReferenceType> getResourceEntities() {
@ -156,63 +99,23 @@ public class VDCImpl extends ReferenceTypeImpl implements VDC {
}
/**
* {@inheritDoc}
* @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 + ((catalog == null) ? 0 : catalog.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 + ((internetServices == null) ? 0 : internetServices.hashCode());
result = prime * result + ((publicIps == null) ? 0 : publicIps.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;
}
@ -225,71 +128,44 @@ public class VDCImpl extends ReferenceTypeImpl implements VDC {
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)
if (catalog == null) {
if (other.catalog != null)
return false;
} else if (!cpuCapacity.equals(other.cpuCapacity))
} else if (!catalog.equals(other.catalog))
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)
if (internetServices == null) {
if (other.internetServices != null)
return false;
} else if (!memoryCapacity.equals(other.memoryCapacity))
} else if (!internetServices.equals(other.internetServices))
return false;
if (networkQuota != other.networkQuota)
return false;
if (nicQuota != other.nicQuota)
return false;
if (org == null) {
if (other.org != null)
if (publicIps == null) {
if (other.publicIps != null)
return false;
} else if (!org.equals(other.org))
} else if (!publicIps.equals(other.publicIps))
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 + "]";
return "[name=" + getName() + ", href=" + getHref() + ", description=" + description + ", catalog=" + catalog
+ ", publicIps=" + publicIps + ", internetServices=" + internetServices + ", resourceEntities="
+ resourceEntities + ", availableNetworks=" + availableNetworks + "]";
}
}

View File

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

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

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

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

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

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

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

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

@ -1,83 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.network;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.network.firewall.FirewallRule;
import org.jclouds.trmk.vcloud_0_8.domain.network.nat.rules.PortForwardingRule;
/**
*
* A network that is available in a vDC.
*
* @author Adrian Cole
*/
public interface VCloudExpressNetwork extends ReferenceType {
/**
*
* @return Description of the network
*/
String getDescription();
/**
* @return IP addresses of the networks DNS servers.
*/
Set<String> getDnsServers();
/**
*
*
* @return The IP address of the networks primary gateway
*/
String getGateway();
/**
* *
*
* @return the networks subnet mask
*/
String getNetmask();
/**
* return the networks fence modes.
*/
Set<FenceMode> getFenceModes();
/**
* return True if the network provides DHCP services
*/
@Nullable
Boolean isDhcp();
/**
*
* @return Network Address Translation rules for the network
*/
Set<PortForwardingRule> getNatRules();
/**
* @return Firewall rules for the network
*/
Set<FirewallRule> getFirewallRules();
}

View File

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

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

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

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

@ -1,202 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.network.internal;
import java.net.URI;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
import org.jclouds.trmk.vcloud_0_8.domain.network.FenceMode;
import org.jclouds.trmk.vcloud_0_8.domain.network.VCloudExpressNetwork;
import org.jclouds.trmk.vcloud_0_8.domain.network.firewall.FirewallRule;
import org.jclouds.trmk.vcloud_0_8.domain.network.nat.rules.PortForwardingRule;
import com.google.common.collect.Sets;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VCloudExpressNetwork {
protected final String description;
protected final Set<String> dnsServers = Sets.newHashSet();
protected final String gateway;
protected final String netmask;
protected final Set<FenceMode> fenceModes = Sets.newHashSet();
@Nullable
protected final Boolean dhcp;
protected final Set<PortForwardingRule> natRules = Sets.newHashSet();
protected final Set<FirewallRule> firewallRules = Sets.newHashSet();
public VCloudExpressNetworkImpl(String name, String type, URI id, String description, Set<String> dnsServers,
String gateway, String netmask, Set<FenceMode> fenceModes, Boolean dhcp, Set<PortForwardingRule> natRules,
Set<FirewallRule> firewallRules) {
super(name, type, id);
this.description = description;
this.dnsServers.addAll(dnsServers);
this.gateway = gateway;
this.netmask = netmask;
this.fenceModes.addAll(fenceModes);
this.dhcp = dhcp;
this.natRules.addAll(natRules);
this.firewallRules.addAll(firewallRules);
}
/**
* {@inheritDoc}
*/
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
public Set<String> getDnsServers() {
return dnsServers;
}
/**
* {@inheritDoc}
*/
public String getGateway() {
return gateway;
}
/**
* {@inheritDoc}
*/
public String getNetmask() {
return netmask;
}
/**
* {@inheritDoc}
*/
public Set<FenceMode> getFenceModes() {
return fenceModes;
}
/**
* {@inheritDoc}
*/
public Boolean isDhcp() {
return dhcp;
}
/**
* {@inheritDoc}
*/
public Set<PortForwardingRule> getNatRules() {
return natRules;
}
/**
* {@inheritDoc}
*/
public Set<FirewallRule> getFirewallRules() {
return firewallRules;
}
@Override
public int compareTo(ReferenceType o) {
return (this == o) ? 0 : getHref().compareTo(o.getHref());
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((dhcp == null) ? 0 : dhcp.hashCode());
result = prime * result + ((dnsServers == null) ? 0 : dnsServers.hashCode());
result = prime * result + ((fenceModes == null) ? 0 : fenceModes.hashCode());
result = prime * result + ((firewallRules == null) ? 0 : firewallRules.hashCode());
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
result = prime * result + ((natRules == null) ? 0 : natRules.hashCode());
result = prime * result + ((netmask == null) ? 0 : netmask.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;
VCloudExpressNetworkImpl other = (VCloudExpressNetworkImpl) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (dhcp == null) {
if (other.dhcp != null)
return false;
} else if (!dhcp.equals(other.dhcp))
return false;
if (dnsServers == null) {
if (other.dnsServers != null)
return false;
} else if (!dnsServers.equals(other.dnsServers))
return false;
if (fenceModes == null) {
if (other.fenceModes != null)
return false;
} else if (!fenceModes.equals(other.fenceModes))
return false;
if (firewallRules == null) {
if (other.firewallRules != null)
return false;
} else if (!firewallRules.equals(other.firewallRules))
return false;
if (gateway == null) {
if (other.gateway != null)
return false;
} else if (!gateway.equals(other.gateway))
return false;
if (natRules == null) {
if (other.natRules != null)
return false;
} else if (!natRules.equals(other.natRules))
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 "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
+ ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules="
+ firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" + netmask + "]";
}
}

View File

@ -1,65 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.trmk.vcloud_0_8.domain.network.internal;
import org.jclouds.trmk.vcloud_0_8.domain.Task;
import org.jclouds.trmk.vcloud_0_8.domain.network.DhcpService;
import org.jclouds.trmk.vcloud_0_8.domain.network.Features;
import org.jclouds.trmk.vcloud_0_8.domain.network.FenceMode;
import org.jclouds.trmk.vcloud_0_8.domain.network.FirewallService;
import org.jclouds.trmk.vcloud_0_8.domain.network.IpRange;
import org.jclouds.trmk.vcloud_0_8.domain.network.IpScope;
import org.jclouds.trmk.vcloud_0_8.domain.network.NatService;
import org.jclouds.trmk.vcloud_0_8.domain.network.VCloudExpressNetwork;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public class VCloudExpressOrgNetworkAdapter extends OrgNetworkImpl {
public VCloudExpressOrgNetworkAdapter(VCloudExpressNetwork in) {
super(in.getName(), in.getType(), in.getHref(), null, in.getDescription(), ImmutableSet.<Task> of(),
parseConfiguration(in), null, ImmutableSet.<String> of());
}
static Configuration parseConfiguration(VCloudExpressNetwork in) {
String dns1 = (in.getDnsServers().size() > 0) ? Iterables.get(in.getDnsServers(), 0) : null;
String dns2 = (in.getDnsServers().size() > 1) ? Iterables.get(in.getDnsServers(), 1) : null;
String gateway = in.getGateway();
String netmask = in.getNetmask();
FenceMode mode = in.getFenceModes().size() > 0 ? Iterables.get(in.getFenceModes(), 0) : FenceMode.BRIDGED;
DhcpService dhcp = in.isDhcp() != null && in.isDhcp() ? new DhcpService(true, null, null, null) : null;
NatService nat = in.getNatRules().size() > 0 ? new NatService(true, null, null, in.getNatRules()) : null;
FirewallService firewall = in.getFirewallRules().size() > 0 ? new FirewallService(true, in.getFirewallRules())
: null;
return new OrgNetworkImpl.ConfigurationImpl(new IpScope(true, gateway, netmask, dns1, dns2, null, ImmutableSet
.<IpRange> of(), ImmutableSet.<String> of()), null, mode, new Features(dhcp, firewall, nat));
}
}

View File

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

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

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