revised terremark impl as certain methods related to public ips are only in the ecloud impl

This commit is contained in:
Adrian Cole 2010-08-10 15:54:06 -07:00
parent 25bc2c0691
commit de4183e579
14 changed files with 664 additions and 93 deletions

View File

@ -25,7 +25,6 @@ import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.rest.annotations.Provider;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.endpoints.Org;
@ -42,7 +41,7 @@ public class OrgNameToEndpoint implements Function<Object, URI> {
private final URI defaultUri;
@Inject
public OrgNameToEndpoint(@Org Supplier<Map<String, NamedResource>> orgNameToEndpoint, @Provider URI defaultUri) {
public OrgNameToEndpoint(@Org Supplier<Map<String, NamedResource>> orgNameToEndpoint, @Org URI defaultUri) {
this.orgNameToEndpoint = orgNameToEndpoint;
this.defaultUri = defaultUri;
}

View File

@ -20,6 +20,7 @@ package org.jclouds.vcloud.terremark;
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.INTERNETSERVICESLIST_XML;
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.INTERNETSERVICE_XML;
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.PUBLICIP_XML;
import java.util.Set;
@ -38,12 +39,15 @@ import org.jclouds.rest.annotations.RequestFilters;
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.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -51,27 +55,14 @@ import com.google.common.util.concurrent.ListenableFuture;
* Provides access to eCloud resources via their REST API.
* <p/>
*
* @see <a href="http://support.theenterprisecloud.com/kb/default.asp?id=645&Lang=1&SID=" />
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=645&Lang=1&SID="
* />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
/**
* @see TerremarkVCloudExpressClient#addInternetService
*/
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/extensions/vdc/{vDCId}/internetServices")
@Produces(INTERNETSERVICE_XML)
@Consumes(INTERNETSERVICE_XML)
@XMLResponseParser(InternetServiceHandler.class)
@MapBinder(AddInternetServiceOptions.class)
@Override
ListenableFuture<? extends InternetService> addInternetServiceToVDC(@PathParam("vDCId") String vDCId,
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
/**
* @see TerremarkVCloudExpressClient#getAllInternetServices
*/
@ -80,9 +71,21 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
@Path("/extensions/vdc/{vDCId}/internetServices")
@Consumes(INTERNETSERVICESLIST_XML)
@XMLResponseParser(InternetServicesHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
@Override
ListenableFuture<? extends Set<InternetService>> getAllInternetServicesInVDC(@PathParam("vDCId") String vDCId);
/**
* @see TerremarkVCloudExpressClient#activatePublicIpInVDC
*/
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/extensions/vdc/{vDCId}/publicIps")
@Consumes(PUBLICIP_XML)
@XMLResponseParser(PublicIpAddressesHandler.class)
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<PublicIpAddress> activatePublicIpInVDC(@PathParam("vDCId") String vDCId);
/**
* @see TerremarkVCloudExpressClient#addInternetServiceToExistingIp
*/
@ -95,8 +98,8 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
@MapBinder(AddInternetServiceOptions.class)
@Override
ListenableFuture<? extends InternetService> addInternetServiceToExistingIp(@PathParam("ipId") int existingIpId,
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
/**
* @see TerremarkVCloudExpressClient#getInternetServicesOnPublicIP

View File

@ -21,16 +21,25 @@ package org.jclouds.vcloud.terremark;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="http://support.theenterprisecloud.com/kb/default.asp?id=645&Lang=1&SID=" />
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=645&Lang=1&SID="
* />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface TerremarkECloudClient extends TerremarkVCloudClient {
//TODO
/**
* Allocate a new public IP
*
* @param vDCId
* @return
*/
PublicIpAddress activatePublicIpInVDC(String vDCId);
}

View File

@ -8,6 +8,16 @@ import javax.ws.rs.core.MediaType;
* @see MediaType
*/
public interface TerremarkECloudMediaType extends TerremarkVCloudMediaType {
/**
* "application/vnd.tmrk.ecloud.publicIp+xml"
*/
public final static String PUBLICIP_XML = "application/vnd.tmrk.ecloud.publicIp+xml";
/**
* "application/vnd.tmrk.ecloud.publicIp+xml"
*/
public final static MediaType PUBLICIP_XML_TYPE = new MediaType("application", "vnd.tmrk.ecloud.publicIp+xml");
/**
* "application/vnd.tmrk.ecloud.internetService+xml"
*/
@ -17,7 +27,7 @@ public interface TerremarkECloudMediaType extends TerremarkVCloudMediaType {
* "application/vnd.tmrk.ecloud.internetService+xml"
*/
public final static MediaType INTERNETSERVICE_XML_TYPE = new MediaType("application",
"vnd.tmrk.ecloud.internetService+xml");
"vnd.tmrk.ecloud.internetService+xml");
/**
* "application/vnd.tmrk.ecloud.internetServicesList+xml"
*/
@ -27,6 +37,6 @@ public interface TerremarkECloudMediaType extends TerremarkVCloudMediaType {
* "application/vnd.tmrk.ecloud.internetServicesList+xml"
*/
public final static MediaType INTERNETSERVICESLIST_XML_TYPE = new MediaType("application",
"vnd.tmrk.ecloud.internetServicesList+xml");
"vnd.tmrk.ecloud.internetServicesList+xml");
}

View File

@ -198,20 +198,6 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
/**
* @see TerremarkVCloudExpressClient#addInternetService
*/
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/extensions/vdc/{vDCId}/internetServices")
@Produces(INTERNETSERVICE_XML)
@Consumes(INTERNETSERVICE_XML)
@XMLResponseParser(InternetServiceHandler.class)
@MapBinder(AddInternetServiceOptions.class)
ListenableFuture<? extends InternetService> addInternetServiceToVDC(@PathParam("vDCId") String vDCId,
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
/**
* @see TerremarkVCloudExpressClient#getAllInternetServices
*/
@ -279,16 +265,6 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<? extends Set<PublicIpAddress>> getPublicIpsAssociatedWithVDC(@PathParam("vDCId") String vDCId);
/**
* @see TerremarkVCloudExpressClient#activatePublicIpInVDC
*/
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/extensions/{vDCId}/publicIps")
@XMLResponseParser(PublicIpAddressesHandler.class)
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<PublicIpAddress> activatePublicIpInVDC(@PathParam("vDCId") String vDCId);
/**
* @see TerremarkVCloudExpressClient#deleteInternetService
*/

View File

@ -66,21 +66,6 @@ public interface TerremarkVCloudClient extends VCloudClient {
void deletePublicIp(int ipId);
/**
* Allocate a new public IP
*
* @param vDCId
* @return
*/
PublicIpAddress activatePublicIpInVDC(String vDCId);
/**
* The call creates a new internet server, including protocol and port
* information. The public IP is dynamically allocated.
*
*/
InternetService addInternetServiceToVDC(String vDCId, String serviceName, Protocol protocol, int port,
AddInternetServiceOptions... options);
/**
* This call adds an internet service to a known, existing public IP. This

View File

@ -20,6 +20,7 @@ package org.jclouds.vcloud.terremark;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType.KEYSLIST_XML;
import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.INTERNETSERVICE_XML;
import java.net.URI;
import java.util.Set;
@ -29,8 +30,11 @@ 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.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
@ -42,8 +46,12 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.terremark.binders.BindCreateKeyToXmlPayload;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.KeyPair;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.functions.OrgNameToKeysListEndpoint;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
@ -60,6 +68,19 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface TerremarkVCloudExpressAsyncClient extends TerremarkVCloudAsyncClient {
/**
* @see TerremarkVCloudExpressClient#addInternetServiceToVDC
*/
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/extensions/vdc/{vDCId}/internetServices")
@Produces(INTERNETSERVICE_XML)
@Consumes(INTERNETSERVICE_XML)
@XMLResponseParser(InternetServiceHandler.class)
@MapBinder(AddInternetServiceOptions.class)
ListenableFuture<? extends InternetService> addInternetServiceToVDC(@PathParam("vDCId") String vDCId,
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
/**
* @see TerremarkVCloudExpressClient#listKeyPairsInOrg

View File

@ -26,7 +26,10 @@ import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.KeyPair;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
/**
* Provides access to VCloud resources via their REST API.
@ -52,6 +55,8 @@ public interface TerremarkVCloudExpressClient extends TerremarkVCloudClient {
* null if use the default org
* @throws ResourceNotFoundException
* if the orgName is not a valid organization
* @throws IllegalStateException
* if a key of the same name already exists
*/
KeyPair generateKeyPairInOrg(@Nullable String orgName, String name, boolean makeDefault);
@ -70,4 +75,7 @@ public interface TerremarkVCloudExpressClient extends TerremarkVCloudClient {
// keyPairConfiguration);
void deleteKeyPair(URI keyPair);
InternetService addInternetServiceToVDC(String vDCId, String serviceName, Protocol protocol, int port,
AddInternetServiceOptions... options);
}

View File

@ -42,6 +42,7 @@ import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.TerremarkECloudClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
@ -129,11 +130,22 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
break;
}
if (ip == null) {
logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getId(), protocol, port);
is = client.addInternetServiceToVDC(vApp.getVDC().getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getId(), vApp
.getName())));
ip = is.getPublicIpAddress();
if (client instanceof TerremarkVCloudExpressClient) {
is = TerremarkVCloudExpressClient.class.cast(client).addInternetServiceToVDC(
vApp.getVDC().getId(),
vApp.getName() + "-" + port,
protocol,
port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getId(), vApp
.getName())));
ip = is.getPublicIpAddress();
} else {
logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getName(), protocol, port);
ip = TerremarkECloudClient.class.cast(client).activatePublicIpInVDC(vApp.getVDC().getId());
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getId(), vApp
.getName())));
}
} else {
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress(), protocol, port);
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,

View File

@ -40,7 +40,7 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
exception = new AuthorizationException(command.getRequest(), content);
break;
case 403: // TODO temporary as terremark mistakenly uses this for vApp
// not found.
// not found.
case 404:
if (!command.getRequest().getMethod().equals("DELETE")) {
String path = command.getRequest().getEndpoint().getPath();
@ -55,9 +55,10 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
}
break;
case 500:
if (response.getMessage().indexOf("because there is a pending task running") != -1)
exception = new IllegalStateException(response.getMessage(), exception);
else if (response.getMessage().indexOf("because it is already powered off") != -1)
if ((response.getMessage().indexOf("because there is a pending task running") != -1)
|| (response.getMessage().indexOf("because it is already powered off") != -1)
|| (response.getMessage().indexOf("already exists") != -1)
|| (response.getMessage().indexOf("same name exists") != -1))
exception = new IllegalStateException(response.getMessage(), exception);
break;
default:

View File

@ -32,6 +32,7 @@ import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@ -79,6 +80,13 @@ import com.google.inject.Module;
public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
// Terremark service call 695,490
@Override
@Test(expectedExceptions = NoSuchElementException.class)
public void testCatalog() throws Exception {
super.testCatalog();
}
protected String provider = "trmk-vcloudexpress";
protected String expectedOs = "Ubuntu Linux (32-bit)";
protected String itemName = "Ubuntu JeOS 9.10 (32-bit)";
@ -222,8 +230,17 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
@Test
public void testAddInternetService() throws InterruptedException, ExecutionException, TimeoutException, IOException {
is = tmClient.addInternetServiceToVDC(tmClient.getDefaultVDC().getId(), "SSH", Protocol.TCP, 22);
publicIp = is.getPublicIpAddress().getAddress();
PublicIpAddress ip;
if (tmClient instanceof TerremarkVCloudExpressClient) {
is = TerremarkVCloudExpressClient.class.cast(tmClient).addInternetServiceToVDC(
tmClient.getVDCInOrg(null, null).getId(), "SSH", Protocol.TCP, 22);
ip = is.getPublicIpAddress();
} else {
ip = TerremarkECloudClient.class.cast(tmClient)
.activatePublicIpInVDC(tmClient.getVDCInOrg(null, null).getId());
is = tmClient.addInternetServiceToExistingIp(ip.getId(), "SSH", Protocol.TCP, 22);
}
publicIp = ip.getAddress();
}
@Test(enabled = true, dependsOnMethods = "testInstantiateAndPowerOn")

View File

@ -0,0 +1,540 @@
/**
*
* Copyright (C) 2009 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.terremark;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.xml.CustomizationParametersHandler;
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code TerremarkECloudAsyncClient}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "TerremarkECloudAsyncClientTest")
public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkECloudAsyncClient> {
/**
* ignore parameter of catalog id since this doesn't work
*/
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getCatalog", String.class);
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(request, "GET https://catalog HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getDefaultVDC");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getVDC", String.class);
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(request, "GET https://vcloud/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class,
String.class, String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0)
.getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "name", 3 + "");
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testInstantiateVAppTemplateOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class,
String.class, String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0)
.getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "name", 3 + "",
TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row").inGroup("group")
.withPassword("password").inNetwork(URI.create("http://network")));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-options-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testActivatePublicIpInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("activatePublicIpInVDC", String.class);
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(request, "POST https://vcloud/extensions/vdc/1/publicIps HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.publicIp+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, PublicIpAddressesHandler.class);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getAllInternetServicesInVDC", String.class);
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(request, "GET https://vcloud/extensions/vdc/1/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetServicesList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServicesHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetInternetService() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getInternetService", int.class);
HttpRequest request = processor.createRequest(method, 12);
assertRequestLineEquals(request, "GET https://vcloud/extensions/internetService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetServicesList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testDeleteInternetService() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("deleteInternetService", int.class);
HttpRequest request = processor.createRequest(method, 12);
assertRequestLineEquals(request, "DELETE https://vcloud/extensions/internetService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testAddInternetServiceToExistingIp() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", int.class,
String.class, Protocol.class, int.class, Array.newInstance(AddInternetServiceOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, 12, "name", Protocol.TCP, 22);
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-test2.xml")), "application/vnd.tmrk.ecloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testAddInternetServiceToExistingIpOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", int.class,
String.class, Protocol.class, int.class, Array.newInstance(AddInternetServiceOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, 12, "name", Protocol.TCP, 22, disabled().withDescription(
"yahoo"));
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml")), "application/vnd.tmrk.ecloud.internetService+xml",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addNode", int.class, String.class, String.class,
int.class, Array.newInstance(AddNodeOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, 12, "10.2.2.2", "name", 22);
assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateNodeService-test2.xml")), "application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addNode", int.class, String.class, String.class,
int.class, Array.newInstance(AddNodeOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, 12, "10.2.2.2", "name", 22, AddNodeOptions.Builder
.disabled().withDescription("yahoo"));
assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateNodeService-options-test.xml")), "application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testConfigureNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", int.class, NodeConfiguration.class);
HttpRequest request = processor.createRequest(method, 12, new NodeConfiguration().changeDescriptionTo("eggs"));
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getNodes", int.class);
HttpRequest request = processor.createRequest(method, 12);
assertRequestLineEquals(request, "GET https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodesHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("deleteNode", int.class);
HttpRequest request = processor.createRequest(method, 12);
assertRequestLineEquals(request, "DELETE https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetCustomizationOptionsOfCatalogItem() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getCustomizationOptionsOfCatalogItem", String.class);
HttpRequest request = processor.createRequest(method, 12);
assertRequestLineEquals(request, "GET https://vcloud/extensions/template/12/options/customization HTTP/1.1");
assertNonPayloadHeadersEqual(request,
"Accept: application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CustomizationParametersHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getNode", int.class);
HttpRequest request = processor.createRequest(method, 12);
assertRequestLineEquals(request, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new TerremarkVCloudRestClientModuleExtension();
}
@Override
public ContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("trmk-vcloudexpress", "identity", "credential",
new Properties());
}
@RequiresHttp
@ConfiguresRestClient
protected static class TerremarkVCloudRestClientModuleExtension extends TerremarkVCloudExpressRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcloud/login");
}
@Override
protected void configure() {
super.configure();
bind(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class);
bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class);
}
@Override
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
return URI.create("https://org");
}
@Override
protected String provideOrgName(@Org Iterable<NamedResource> orgs) {
return "org";
}
@Override
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) {
return URI.create("https://catalog");
}
@Override
protected Organization provideOrganization(VCloudClient discovery) {
return null;
}
@Override
protected Iterable<NamedResource> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
return null;
}
@Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override
public Map<String, NamedResource> getOrgs() {
return ImmutableMap.<String, NamedResource> of("org", new NamedResourceImpl("1", "org",
VCloudMediaType.ORG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1")));
}
@Override
public String getVCloudToken() {
return "token";
}
});
}
@Singleton
public static class TestOrgNameToKeysListSupplier extends OrgNameToKeysListSupplier {
@Inject
protected TestOrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier) {
super(sessionSupplier, null);
}
@Override
public Map<String, NamedResource> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<NamedResource, NamedResource>() {
@SuppressWarnings("deprecation")
@Override
public NamedResource apply(NamedResource from) {
return new NamedResourceImpl(from.getId(), from.getName(),
TerremarkVCloudExpressMediaType.KEYSLIST_XML, URI.create(from.getLocation().toASCIIString()
+ "/keysList"));
}
});
}
}
@Singleton
public static class TestOrganizationMapSupplier extends OrganizationMapSupplier {
@Inject
protected TestOrganizationMapSupplier() {
super(null, null);
}
@Override
public Map<String, Organization> get() {
return ImmutableMap.<String, Organization> of("org", new OrganizationImpl("1", "org", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), ImmutableMap.<String, NamedResource> of(
"catalog", new NamedResourceImpl("1", "catalog", VCloudMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, NamedResource> of("vdc", new NamedResourceImpl("1", "vdc", VCloudMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, NamedResource> of("tasksList", new NamedResourceImpl("1", "tasksList",
VCloudMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")))));
}
}
@Override
protected URI provideDefaultTasksList(Organization org) {
return URI.create("https://taskslist");
}
@Override
protected URI provideDefaultVDC(Organization org) {
return URI.create("https://vdc/1");
}
@Override
protected URI provideDefaultNetwork(VCloudClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
}
}

View File

@ -47,7 +47,7 @@ public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest {
@Test
public void testKeysList() throws Exception {
TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient);
TerremarkOrganization org = vCloudExpressClient.getDefaultOrganization();
TerremarkOrganization org = vCloudExpressClient.getOrganizationNamed(null);
Set<KeyPair> response = vCloudExpressClient.listKeyPairsInOrg(null);
assertNotNull(response);
System.err.println(response);
@ -58,8 +58,14 @@ public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest {
protected void prepare() {
TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient);
TerremarkOrganization org = vCloudExpressClient.getDefaultOrganization();
key = vCloudExpressClient.generateKeyPairInOrg(org.getName(), "livetest", false);
TerremarkOrganization org = vCloudExpressClient.getOrganizationNamed(null);
try {
key = vCloudExpressClient.generateKeyPairInOrg(org.getName(), "livetest", false);
} catch (IllegalStateException e) {
key = vCloudExpressClient.getKeyPairInOrg(org.getName(), "livetest");
vCloudExpressClient.deleteKeyPair(key.getLocation());
key = vCloudExpressClient.generateKeyPairInOrg(org.getName(), "livetest", false);
}
assertNotNull(key);
System.err.println(key);
assertEquals(key.getName(), "livetest");

View File

@ -75,7 +75,6 @@ import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VAppHandler;
@ -186,21 +185,6 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
checkFilters(request);
}
public void testActivatePublicIpInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("activatePublicIpInVDC", String.class);
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(request, "POST https://vcloud/extensions/1/publicIps HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, PublicIpAddressesHandler.class);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testAddInternetService() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("addInternetServiceToVDC", String.class,
String.class, Protocol.class, int.class, Array.newInstance(AddInternetServiceOptions.class, 0).getClass());