From d908600e8ac8c4c04e50a878ed7f079625251861 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 1 Nov 2010 01:24:27 -0700 Subject: [PATCH] Issue 383: added new network features needed for terremark ecloud, so that default vdc will operate --- .../internal/VCloudExpressNetworkImpl.java | 23 +- .../xml/VCloudExpressNetworkHandler.java | 34 +-- .../jclouds/vcloud/VCloudAsyncClientTest.java | 28 ++- .../VCloudExpressOrgNetworkAdapterTest.java | 6 +- .../xml/VCloudExpressNetworkHandlerTest.java | 13 +- .../resources/express/network-terremark.xml | 12 +- .../terremark/TerremarkECloudAsyncClient.java | 50 ++++- .../terremark/TerremarkECloudClient.java | 15 +- .../compute/TerremarkVCloudComputeClient.java | 8 +- .../TerremarkECloudRestClientModule.java | 16 +- .../terremark/domain/TerremarkNetwork.java | 196 ++++++++++++++++++ .../terremark/domain/TerremarkOrgNetwork.java | 46 ++++ .../TerremarkVCloudExpressNetwork.java | 95 +++++++++ ...eTerremarkVCloudErrorFromHttpResponse.java | 3 + .../xml/TerremarkNetworkHandler.java | 91 ++++++++ ...mTerremarkVCloudExpressNetworkHandler.java | 59 ++++++ .../TerremarkVCloudExpressNetworkHandler.java | 66 ++++++ .../TerremarkECloudAsyncClientTest.java | 33 +++ .../xml/TerremarkNetworkHandlerTest.java | 49 +++++ ...remarkVCloudExpressNetworkHandlerTest.java | 87 ++++++++ .../resources/terremark/TerremarkNetwork.xml | 12 ++ 21 files changed, 881 insertions(+), 61 deletions(-) create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkNetwork.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkOrgNetwork.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVCloudExpressNetwork.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandler.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandler.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandlerTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandlerTest.java create mode 100644 vcloud/terremark/src/test/resources/terremark/TerremarkNetwork.xml diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressNetworkImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressNetworkImpl.java index b817802261..17f2023439 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressNetworkImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressNetworkImpl.java @@ -42,15 +42,15 @@ public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VClou /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - private final String description; - private final Set dnsServers = Sets.newHashSet(); - private final String gateway; - private final String netmask; - private final Set fenceModes = Sets.newHashSet(); + protected final String description; + protected final Set dnsServers = Sets.newHashSet(); + protected final String gateway; + protected final String netmask; + protected final Set fenceModes = Sets.newHashSet(); @Nullable - private final Boolean dhcp; - private final Set natRules = Sets.newHashSet(); - private final Set firewallRules = Sets.newHashSet(); + protected final Boolean dhcp; + protected final Set natRules = Sets.newHashSet(); + protected final Set firewallRules = Sets.newHashSet(); public VCloudExpressNetworkImpl(String name, String type, URI id, String description, Set dnsServers, String gateway, String netmask, Set fenceModes, Boolean dhcp, Set natRules, @@ -196,10 +196,9 @@ public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VClou @Override public String toString() { - return "NetworkImpl [id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" - + description + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes - + ", firewallRules=" + firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" - + netmask + "]"; + return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description + + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules=" + + firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" + netmask + "]"; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandler.java index 45d58c39ca..6515a97d54 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandler.java @@ -50,28 +50,28 @@ public class VCloudExpressNetworkHandler extends ParseSax.HandlerWithResult dnsServers = Sets.newLinkedHashSet(); - private String gateway; - private String netmask; - private Set fenceModes = Sets.newLinkedHashSet(); - private Boolean dhcp; - private Set natRules = Sets.newLinkedHashSet(); - private Set firewallRules = Sets.newLinkedHashSet(); + protected Set dnsServers = Sets.newLinkedHashSet(); + protected String gateway; + protected String netmask; + protected Set fenceModes = Sets.newLinkedHashSet(); + protected Boolean dhcp; + protected Set natRules = Sets.newLinkedHashSet(); + protected Set firewallRules = Sets.newLinkedHashSet(); - private String externalIP; - private Integer externalPort; - private String internalIP; - private Integer internalPort; + protected String externalIP; + protected Integer externalPort; + protected String internalIP; + protected Integer internalPort; - private FirewallPolicy policy; - private String sourceIP; - private int sourcePort; + protected FirewallPolicy policy; + protected String sourceIP; + protected int sourcePort; public VCloudExpressNetwork getResult() { return new VCloudExpressNetworkImpl(network.getName(), network.getType(), network.getHref(), description, diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index 15b8d7deeb..3700215533 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -52,11 +52,13 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.jclouds.vcloud.config.VCloudRestClientModule; +import org.jclouds.vcloud.domain.AllocationModel; import org.jclouds.vcloud.domain.GuestCustomizationSection; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VCloudSession; +import org.jclouds.vcloud.domain.VDCStatus; import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogItemImpl; import org.jclouds.vcloud.domain.internal.OrgImpl; @@ -86,6 +88,7 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.TypeLiteral; @@ -350,6 +353,22 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } + public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, "org", "vdc", "network"); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgNetworkHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class); HttpRequest request = processor.createRequest(method, URI @@ -908,11 +927,11 @@ public class VCloudAsyncClientTest extends RestClientTest { null, URI .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), - null, + VDCStatus.READY, null, "description", - null, - null, + ImmutableSet. of(), + AllocationModel.ALLOCATION_POOL, null, null, null, @@ -930,7 +949,8 @@ public class VCloudAsyncClientTest extends RestClientTest { "application/vnd.vmware.vcloud.vAppTemplate+xml", URI .create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), - null, 0, 0, 0, false)))); + ImmutableMap. of(), 0, 0, 0, + false)))); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressOrgNetworkAdapterTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressOrgNetworkAdapterTest.java index a46207f92f..a6e4d6ffc9 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressOrgNetworkAdapterTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/domain/network/internal/VCloudExpressOrgNetworkAdapterTest.java @@ -54,15 +54,15 @@ public class VCloudExpressOrgNetworkAdapterTest { Factory factory = injector.getInstance(ParseSax.Factory.class); VCloudExpressNetwork in = factory.create(injector.getInstance(VCloudExpressNetworkHandler.class)).parse(is); OrgNetwork result = new VCloudExpressOrgNetworkAdapter(in); - assertEquals(result.getName(), "10.114.34.128/26"); - assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708")); + assertEquals(result.getName(), "10.122.209.128/28"); + assertEquals(result.getHref(), URI.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/network/40031")); assertEquals(result.getType(), "application/vnd.vmware.vcloud.network+xml"); assertEquals(result.getOrg(), null); assertEquals(result.getDescription(), null); assertEquals(result.getTasks(), ImmutableList.of()); assert result.getConfiguration() != null; - assertEquals(result.getConfiguration().getIpScope(), new IpScope(true, "10.114.34.129", "255.255.255.192", null, + assertEquals(result.getConfiguration().getIpScope(), new IpScope(true, "10.122.209.129", "255.255.255.240", null, null, null, ImmutableSet. of(), ImmutableSet. of())); assertEquals(result.getConfiguration().getParentNetwork(), null); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandlerTest.java index 19ee37b9e3..a0f89fec7f 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressNetworkHandlerTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; -import java.net.UnknownHostException; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; @@ -51,20 +50,20 @@ public class VCloudExpressNetworkHandlerTest { private Factory factory; - public void testTerremark() throws UnknownHostException { + public void testTerremark() { InputStream is = getClass().getResourceAsStream("/express/network-terremark.xml"); injector = Guice.createInjector(new SaxParserModule()); factory = injector.getInstance(ParseSax.Factory.class); VCloudExpressNetwork result = factory.create(injector.getInstance(VCloudExpressNetworkHandler.class)).parse(is); - assertEquals(result, new VCloudExpressNetworkImpl("10.114.34.128/26", + assertEquals(result, new VCloudExpressNetworkImpl("10.122.209.128/28", "application/vnd.vmware.vcloud.network+xml", URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"), null, - ImmutableSet. of(), "10.114.34.129", "255.255.255.192", ImmutableSet + .create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/network/40031"), null, + ImmutableSet. of(), "10.122.209.129", "255.255.255.240", ImmutableSet . of(FenceMode.ISOLATED), null, ImmutableSet. of(), ImmutableSet . of())); } - public void testHosting() throws UnknownHostException { + public void testHosting() { InputStream is = getClass().getResourceAsStream("/express/network-hosting.xml"); injector = Guice.createInjector(new SaxParserModule()); factory = injector.getInstance(ParseSax.Factory.class); @@ -76,7 +75,7 @@ public class VCloudExpressNetworkHandlerTest { . of(), null, ImmutableSet. of(), ImmutableSet. of())); } - public void testBluelock() throws UnknownHostException { + public void testBluelock() { InputStream is = getClass().getResourceAsStream("/express/network-bluelock.xml"); injector = Guice.createInjector(new SaxParserModule()); factory = injector.getInstance(ParseSax.Factory.class); diff --git a/vcloud/core/src/test/resources/express/network-terremark.xml b/vcloud/core/src/test/resources/express/network-terremark.xml index df465f2943..66f6524988 100644 --- a/vcloud/core/src/test/resources/express/network-terremark.xml +++ b/vcloud/core/src/test/resources/express/network-terremark.xml @@ -1,10 +1,12 @@ - - + + + - 10.114.34.129 - 255.255.255.192 + 10.122.209.129 + 255.255.255.240 isolated - \ No newline at end of file + diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java index a555ba2931..b7f70e3b8e 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java @@ -20,6 +20,7 @@ package org.jclouds.vcloud.terremark; import static javax.ws.rs.core.MediaType.APPLICATION_XML; +import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; 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.KEYSLIST_XML; @@ -45,12 +46,16 @@ 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.VCloudClient; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint; 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.domain.PublicIpAddress; +import org.jclouds.vcloud.terremark.domain.TerremarkNetwork; +import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork; import org.jclouds.vcloud.terremark.functions.OrgURIToKeysListEndpoint; import org.jclouds.vcloud.terremark.functions.VDCURIToInternetServicesEndpoint; import org.jclouds.vcloud.terremark.functions.VDCURIToPublicIPsEndpoint; @@ -61,6 +66,8 @@ import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler; import org.jclouds.vcloud.terremark.xml.KeyPairHandler; import org.jclouds.vcloud.terremark.xml.KeyPairsHandler; import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler; +import org.jclouds.vcloud.terremark.xml.TerremarkNetworkHandler; +import org.jclouds.vcloud.terremark.xml.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler; import com.google.common.util.concurrent.ListenableFuture; @@ -156,7 +163,7 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient { @Nullable @EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org); /** - * @see TerremarkVCloudExpressClient#listKeyPairs + * @see TerremarkECloudClient#listKeyPairs */ @GET @Path("") @@ -166,7 +173,7 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient { ListenableFuture> listKeyPairs(@EndpointParam URI keysList); /** - * @see TerremarkVCloudExpressClient#generateKeyPairInOrg + * @see TerremarkECloudClient#generateKeyPairInOrg */ @POST @Path("") @@ -179,7 +186,7 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient { @MapPayloadParam("isDefault") boolean makeDefault); /** - * @see TerremarkVCloudExpressClient#getKeyPair + * @see TerremarkECloudClient#getKeyPair */ @GET @Path("") @@ -204,10 +211,45 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient { // KeyPairConfiguration keyConfiguration); /** - * @see TerremarkVCloudExpressClient#deleteKeyPair + * @see TerremarkECloudClient#deleteKeyPair */ @DELETE @Path("") @ExceptionParser(ReturnVoidOnNotFoundOr404.class) ListenableFuture deleteKeyPair(@EndpointParam URI keyId); + + /** + * @see TerremarkECloudClient#findNetworkInOrgVDCNamed + */ + @Override + @GET + @Path("") + @Consumes(NETWORK_XML) + @XMLResponseParser(TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findNetworkInOrgVDCNamed( + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName); + + /** + * @see TerremarkECloudClient#getNetwork + */ + @Override + @GET + @Path("") + @Consumes(NETWORK_XML) + @XMLResponseParser(TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getNetwork(@EndpointParam URI network); + + /** + * @see TerremarkECloudClient#getTerremarkNetwork + */ + @GET + @Path("") + @XMLResponseParser(TerremarkNetworkHandler.class) + @Consumes(APPLICATION_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTerremarkNetwork(@EndpointParam URI network); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java index 19fdc6bb0f..a317c1921a 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java @@ -22,16 +22,18 @@ package org.jclouds.vcloud.terremark; import java.net.URI; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; +import org.jclouds.vcloud.terremark.domain.TerremarkNetwork; +import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork; /** * Provides access to VCloud resources via their REST API. *

* - * @see + * @see * @author Adrian Cole */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) @@ -44,4 +46,11 @@ public interface TerremarkECloudClient extends TerremarkVCloudClient { * @return */ PublicIpAddress activatePublicIpInVDC(URI vDCId); + + TerremarkOrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String vdc, String networkName); + + TerremarkOrgNetwork getNetwork(URI network); + + TerremarkNetwork getTerremarkNetwork(URI network); + } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index 27f4e7c007..a812be12d8 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -214,8 +214,12 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl Set services = client.getInternetServicesOnPublicIp(address.getId()); if (services.size() == 0) { logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address.getAddress()); - client.deletePublicIp(address.getId()); - logger.debug("<< deleted PublicIpAddress(%s)", address.getId()); + try { + client.deletePublicIp(address.getId()); + logger.debug("<< deleted PublicIpAddress(%s)", address.getId()); + } catch (UnsupportedOperationException e) { + logger.trace("cannot delete PublicIpAddress(%s) as it is unsupported", address.getId()); + } continue IPADDRESS; } } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java index c13caa7e8c..a666f643ec 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java @@ -19,6 +19,8 @@ package org.jclouds.vcloud.terremark.config; +import static com.google.common.base.Preconditions.checkNotNull; + import java.net.URI; import java.util.Map; import java.util.NoSuchElementException; @@ -31,11 +33,12 @@ import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.network.OrgNetwork; import org.jclouds.vcloud.terremark.TerremarkECloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkECloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; +import org.jclouds.vcloud.terremark.domain.TerremarkNetwork; +import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; @@ -97,9 +100,14 @@ public class TerremarkECloudRestClientModule extends @Override public boolean apply(ReferenceType input) { - OrgNetwork network = injector.getInstance(TerremarkECloudClient.class).getNetwork(input.getHref()); - // TODO: get extension data on this network and check NetworkType == DMZ - return network.getDescription() != null &&network.getDescription().toLowerCase().contains("dmz"); + TerremarkOrgNetwork network = injector.getInstance(TerremarkECloudClient.class).getNetwork( + input.getHref()); + TerremarkNetwork terremarkNetwork = injector.getInstance(TerremarkECloudClient.class) + .getTerremarkNetwork( + checkNotNull(checkNotNull(network, "network at: " + input).getNetworkExtension(), + "network extension for: " + input).getHref()); + return checkNotNull(terremarkNetwork, "terremark network extension at: " + network.getNetworkExtension()) + .getNetworkType() == TerremarkNetwork.Type.DMZ; } }).getHref(); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkNetwork.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkNetwork.java new file mode 100644 index 0000000000..03ce516ea3 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkNetwork.java @@ -0,0 +1,196 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +/** + * @author Adrian Cole + */ +public class TerremarkNetwork implements Comparable { + public enum Type { + INTERNAL, DMZ, UNRECOGNIZED; + public static Type fromValue(String type) { + try { + return valueOf(checkNotNull(type, "type").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + + } + + private final String id; + private final URI href; + private final String name; + private final String rnatAddress; + private final String address; + private final String broadcastAddress; + private final String gatewayAddress; + private final Type networkType; + private final String vlan; + private final String friendlyName; + + public TerremarkNetwork(String id, URI href, String name, String rnatAddress, String address, + String broadcastAddress, String gatewayAddress, Type networkType, String vlan, String friendlyName) { + this.id = id; + this.href = href; + this.name = name; + this.rnatAddress = rnatAddress; + this.address = address; + this.broadcastAddress = broadcastAddress; + this.gatewayAddress = gatewayAddress; + this.networkType = networkType; + this.vlan = vlan; + this.friendlyName = friendlyName; + } + + public int compareTo(TerremarkNetwork that) { + return (this == that) ? 0 : getHref().compareTo(that.getHref()); + } + + public String getId() { + return id; + } + + public URI getHref() { + return href; + } + + public String getName() { + return name; + } + + public String getRnatAddress() { + return rnatAddress; + } + + public String getAddress() { + return address; + } + + public String getBroadcastAddress() { + return broadcastAddress; + } + + public String getGatewayAddress() { + return gatewayAddress; + } + + public Type getNetworkType() { + return networkType; + } + + public String getVlan() { + return vlan; + } + + public String getFriendlyName() { + return friendlyName; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((address == null) ? 0 : address.hashCode()); + result = prime * result + ((broadcastAddress == null) ? 0 : broadcastAddress.hashCode()); + result = prime * result + ((friendlyName == null) ? 0 : friendlyName.hashCode()); + result = prime * result + ((gatewayAddress == null) ? 0 : gatewayAddress.hashCode()); + result = prime * result + ((href == null) ? 0 : href.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((networkType == null) ? 0 : networkType.hashCode()); + result = prime * result + ((rnatAddress == null) ? 0 : rnatAddress.hashCode()); + result = prime * result + ((vlan == null) ? 0 : vlan.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TerremarkNetwork other = (TerremarkNetwork) obj; + if (address == null) { + if (other.address != null) + return false; + } else if (!address.equals(other.address)) + return false; + if (broadcastAddress == null) { + if (other.broadcastAddress != null) + return false; + } else if (!broadcastAddress.equals(other.broadcastAddress)) + return false; + if (friendlyName == null) { + if (other.friendlyName != null) + return false; + } else if (!friendlyName.equals(other.friendlyName)) + return false; + if (gatewayAddress == null) { + if (other.gatewayAddress != null) + return false; + } else if (!gatewayAddress.equals(other.gatewayAddress)) + return false; + if (href == null) { + if (other.href != null) + return false; + } else if (!href.equals(other.href)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (networkType == null) { + if (other.networkType != null) + return false; + } else if (!networkType.equals(other.networkType)) + return false; + if (rnatAddress == null) { + if (other.rnatAddress != null) + return false; + } else if (!rnatAddress.equals(other.rnatAddress)) + return false; + if (vlan == null) { + if (other.vlan != null) + return false; + } else if (!vlan.equals(other.vlan)) + return false; + return true; + } + + @Override + public String toString() { + return "[address=" + address + ", broadcastAddress=" + broadcastAddress + ", friendlyName=" + friendlyName + + ", gatewayAddress=" + gatewayAddress + ", href=" + href + ", id=" + id + ", name=" + name + + ", networkType=" + networkType + ", rnatAddress=" + rnatAddress + ", vlan=" + vlan + "]"; + } +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkOrgNetwork.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkOrgNetwork.java new file mode 100644 index 0000000000..af3a4a3cd6 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkOrgNetwork.java @@ -0,0 +1,46 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.domain; + +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.network.internal.VCloudExpressOrgNetworkAdapter; +import org.jclouds.vcloud.terremark.domain.internal.TerremarkVCloudExpressNetwork; + +/** + * + * @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(); + } +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVCloudExpressNetwork.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVCloudExpressNetwork.java new file mode 100644 index 0000000000..8db3b15942 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVCloudExpressNetwork.java @@ -0,0 +1,95 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.domain.internal; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.firewall.FirewallRule; +import org.jclouds.vcloud.domain.network.internal.VCloudExpressNetworkImpl; +import org.jclouds.vcloud.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 dnsServers, + String gateway, String netmask, Set fenceModes, Boolean dhcp, Set natRules, + Set 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 + "]"; + } +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java index 5a2b6e54e6..40017c27b8 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java @@ -81,6 +81,9 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl } exception = new ResourceNotFoundException(message, exception); break; + case 405: + exception = new UnsupportedOperationException(response.getMessage(), exception); + break; case 501: if (response.getMessage() != null && (response.getMessage().indexOf("NotImplemented") != -1)) exception = new UnsupportedOperationException(response.getMessage(), exception); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandler.java new file mode 100644 index 0000000000..c19bfe954c --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandler.java @@ -0,0 +1,91 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.xml; + +import java.net.URI; + +import javax.annotation.Resource; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.terremark.domain.TerremarkNetwork; +import org.jclouds.vcloud.terremark.domain.TerremarkNetwork.Type; + +/** + * @author Adrian Cole + */ +public class TerremarkNetworkHandler extends HandlerWithResult { + + @Resource + protected Logger logger = Logger.NULL; + private StringBuilder currentText = new StringBuilder(); + + private String id; + private URI href; + private String name; + private String rnatAddress; + private String address; + private String broadcastAddress; + private String gatewayAddress; + private Type networkType; + private String vlan; + private String friendlyName; + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } + + @Override + public TerremarkNetwork getResult() { + return new TerremarkNetwork(id, href, name, rnatAddress, address, broadcastAddress, gatewayAddress, networkType, + vlan, friendlyName); + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("Href") && currentOrNull() != null) { + href = URI.create(currentOrNull()); + } else if (qName.equals("Id")) { + id = currentOrNull(); + } else if (qName.equals("Name")) { + this.name = currentOrNull(); + } else if (qName.equals("RnatAddress")) { + rnatAddress = currentOrNull(); + } else if (qName.equals("Address")) { + address = currentOrNull(); + } else if (qName.equals("BroadcastAddress")) { + broadcastAddress = currentOrNull(); + } else if (qName.equals("GatewayAddress")) { + gatewayAddress = currentOrNull(); + } else if (qName.equals("NetworkType")) { + networkType = TerremarkNetwork.Type.fromValue(currentOrNull()); + } else if (qName.equals("Vlan")) { + vlan = currentOrNull(); + } else if (qName.equals("FriendlyName")) { + friendlyName = currentOrNull(); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.java new file mode 100644 index 0000000000..5849adfebc --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.xml; + +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler extends + ParseSax.HandlerWithResult { + + protected final TerremarkVCloudExpressNetworkHandler vcxHandler; + + @Inject + public TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler(TerremarkVCloudExpressNetworkHandler vcxHandler) { + this.vcxHandler = vcxHandler; + } + + public TerremarkOrgNetwork getResult() { + return new TerremarkOrgNetwork(vcxHandler.getResult()); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + vcxHandler.startElement(uri, localName, qName, attributes); + } + + public void endElement(String uri, String name, String qName) { + vcxHandler.endElement(uri, name, qName); + } + + public void characters(char ch[], int start, int length) { + vcxHandler.characters(ch, start, length); + } + +} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandler.java new file mode 100644 index 0000000000..1bce0bef27 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandler.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.xml; + +import static org.jclouds.vcloud.util.Utils.cleanseAttributes; +import static org.jclouds.vcloud.util.Utils.newReferenceType; + +import java.util.Map; + +import javax.annotation.Resource; + +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.terremark.domain.internal.TerremarkVCloudExpressNetwork; +import org.jclouds.vcloud.xml.VCloudExpressNetworkHandler; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class TerremarkVCloudExpressNetworkHandler extends VCloudExpressNetworkHandler { + + @Resource + protected Logger logger = Logger.NULL; + + private ReferenceType ips; + private ReferenceType extension; + + public TerremarkVCloudExpressNetwork getResult() { + return new TerremarkVCloudExpressNetwork(network.getName(), network.getType(), network.getHref(), description, + dnsServers, gateway, netmask, fenceModes, dhcp, natRules, firewallRules, extension, ips); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + if (qName.equals("Network")) { + network = newReferenceType(attributes); + } else if (qName.equals("Link")) { + if ("IP Addresses".equals(attributes.get("name"))) { + ips = newReferenceType(attributes); + } else if ("down".equals(attributes.get("rel"))) { + extension = newReferenceType(attributes); + } + } + } + +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java index ae1f723d9d..17736e8255 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java @@ -74,6 +74,7 @@ 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.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; @@ -96,6 +97,38 @@ import domain.VCloudVersionsAsyncClient; */ @Test(groups = "unit", sequential = true, testName = "TerremarkECloudAsyncClientTest") public class TerremarkECloudAsyncClientTest extends RestClientTest { + public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkECloudAsyncClient.class.getMethod("getNetwork", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkECloudAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class, + String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "vdc", "network"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + /** * ignore parameter of catalog id since this doesn't work */ diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandlerTest.java new file mode 100644 index 0000000000..2f2019529f --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkNetworkHandlerTest.java @@ -0,0 +1,49 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.net.UnknownHostException; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.TerremarkNetwork; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code TerremarkNetworkHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "terremark.TerremarkNetworkHandlerTest") +public class TerremarkNetworkHandlerTest extends BaseHandlerTest { + + public void test1() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/TerremarkNetwork.xml"); + + TerremarkNetwork result = factory.create(injector.getInstance(TerremarkNetworkHandler.class)).parse(is); + assertEquals(result, new TerremarkNetwork("XXXXX", URI + .create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/XXXXX"), + "10.X.X.0/27", "209.X.X.X", "10.X.X.0", "10.X.X.X", "10.X.X.1", TerremarkNetwork.Type.DMZ, "279", + "10.X.X.0/27 (DMZ_279)")); + } +} \ No newline at end of file diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandlerTest.java new file mode 100644 index 0000000000..ab550c1768 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVCloudExpressNetworkHandlerTest.java @@ -0,0 +1,87 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; +import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.VCloudExpressNetwork; +import org.jclouds.vcloud.domain.network.firewall.FirewallRule; +import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule; +import org.jclouds.vcloud.terremark.domain.internal.TerremarkVCloudExpressNetwork; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code TerremarkVCloudExpressNetworkHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "terremark.TerremarkVCloudExpressNetworkHandlerTest") +public class TerremarkVCloudExpressNetworkHandlerTest { + + private Injector injector; + + private Factory factory; + + public void testTerremark() { + InputStream is = getClass().getResourceAsStream("/express/network-terremark.xml"); + injector = Guice.createInjector(new SaxParserModule()); + factory = injector.getInstance(ParseSax.Factory.class); + VCloudExpressNetwork result = factory.create(injector.getInstance(TerremarkVCloudExpressNetworkHandler.class)) + .parse(is); + assertEquals( + result, + new TerremarkVCloudExpressNetwork( + "10.122.209.128/28", + "application/vnd.vmware.vcloud.network+xml", + URI.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/network/40031"), + null, + ImmutableSet. of(), + "10.122.209.129", + "255.255.255.240", + ImmutableSet. of(FenceMode.ISOLATED), + null, + ImmutableSet. of(), + ImmutableSet. of(), + + new ReferenceTypeImpl( + "10.122.209.128/28", + "application/xml", + URI + .create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/40031")), + new ReferenceTypeImpl( + "IP Addresses", + "application/xml", + URI + .create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/40031/ips")))); + + } +} diff --git a/vcloud/terremark/src/test/resources/terremark/TerremarkNetwork.xml b/vcloud/terremark/src/test/resources/terremark/TerremarkNetwork.xml new file mode 100644 index 0000000000..0241427e6c --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/TerremarkNetwork.xml @@ -0,0 +1,12 @@ + + XXXXX + https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/XXXXX + 10.X.X.0/27 + 209.X.X.X +

10.X.X.0
+ 10.X.X.X + 10.X.X.1 + DMZ + 279 + 10.X.X.0/27 (DMZ_279) +