diff --git a/common/trmk/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayload.java b/common/trmk/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayload.java index 7037e4151b..5fffa298d8 100644 --- a/common/trmk/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayload.java +++ b/common/trmk/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayload.java @@ -63,9 +63,20 @@ public class BindAddInternetServiceToXmlPayload implements MapBinder { String payload = Strings2.replaceTokens(xmlTemplate, ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns)); payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("description"), description == null ? "" - : String.format("\n %s", description)); + : String.format("\n\t%s", description)); + payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("monitor"), getMonitorString(postParams)); return stringBinder.bindToRequest(request, payload); } + + private String getMonitorString(Map postParams) + { + // Sending no element to Terremark will result in default behavior, which is to create a monitor. + String monitor = postParams.get("monitor"); + if (monitor == null || "true".equalsIgnoreCase(monitor)) { + return ""; + } + return "\n\tDisabled"; + } @Override public R bindToRequest(R request, Object input) { diff --git a/common/trmk/src/main/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptions.java b/common/trmk/src/main/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptions.java index 814fa651a4..9c4b8c55f0 100644 --- a/common/trmk/src/main/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptions.java +++ b/common/trmk/src/main/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptions.java @@ -38,12 +38,17 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa String description = null; @VisibleForTesting String enabled = "true"; + @VisibleForTesting + Boolean monitorEnabled = null; @Override public R bindToRequest(R request, Map postParams) { Map copy = Maps.newHashMap(); copy.putAll(postParams); copy.put("description", description); copy.put("enabled", enabled); + if (monitorEnabled != null) { + copy.put("monitor", monitorEnabled.toString()); + } return super.bindToRequest(request, copy); } @@ -51,12 +56,15 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa this.enabled = "false"; return this; } - + public AddInternetServiceOptions monitorDisabled() { + this.monitorEnabled = false; + return this; + } public AddInternetServiceOptions withDescription(String description) { this.description = description; return this; } - + public static class Builder { /** @@ -67,6 +75,14 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa return options.withDescription(description); } + /** + * @see AddInternetServiceOptions#monitorDisabled() + */ + public static AddInternetServiceOptions monitorDisabled() { + AddInternetServiceOptions options = new AddInternetServiceOptions(); + return options.monitorDisabled(); + } + /** * @see AddInternetServiceOptions#disabled() */ diff --git a/common/trmk/src/main/resources/terremark/CreateInternetService.xml b/common/trmk/src/main/resources/terremark/CreateInternetService.xml index b5cdc9bf51..6dfff809d5 100644 --- a/common/trmk/src/main/resources/terremark/CreateInternetService.xml +++ b/common/trmk/src/main/resources/terremark/CreateInternetService.xml @@ -6,4 +6,5 @@ {port} {enabled} {description} + {monitor} diff --git a/common/trmk/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java b/common/trmk/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java index 5c58625632..a4a1d0fd35 100644 --- a/common/trmk/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java +++ b/common/trmk/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java @@ -33,8 +33,9 @@ import static org.testng.Assert.assertNotNull; import java.io.IOException; import java.net.URI; import java.util.List; -import java.util.Properties; import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -46,8 +47,8 @@ import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.SshClient; -import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshClient.Factory; +import org.jclouds.ssh.SshException; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.VCloudExpressClientLiveTest; import org.jclouds.vcloud.VCloudExpressMediaType; @@ -65,9 +66,11 @@ import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; +import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; +import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; @@ -103,6 +106,17 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes assertNotNull(tmClient.getNodes(service.getId())); } } + + @Test + public void testCreateInternetServiceMonitorDisabled() throws Exception { + VDC vdc = tmClient.findVDCInOrgNamed(null, null); + Set publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref()); + PublicIpAddress publicIp = publicIpAddresses.iterator().next(); + System.out.println("PublicIP: " + publicIp.getAddress()); + + tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX + "-no-monitoring", Protocol.TCP, 1234, + AddInternetServiceOptions.Builder.monitorDisabled()); + } @Test public void testGetPublicIpsAssociatedWithVDC() throws Exception { diff --git a/common/trmk/src/test/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayloadTest.java b/common/trmk/src/test/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayloadTest.java index 386ac9c1ca..4a25773082 100644 --- a/common/trmk/src/test/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayloadTest.java +++ b/common/trmk/src/test/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlPayloadTest.java @@ -21,6 +21,7 @@ package org.jclouds.vcloud.terremark.binders; import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; @@ -81,6 +82,41 @@ public class BindAddInternetServiceToXmlPayloadTest { map.put("description", "name TCP 22"); binder.bindToRequest(request, map); assertEquals(request.getPayload().getRawContent(), expected); - } + + public void testDisableMonitoringEnabled() throws IOException { + HttpRequest request = new HttpRequest("GET", URI.create("http://test")); + BindAddInternetServiceToXmlPayload binder = injector + .getInstance(BindAddInternetServiceToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("name", "name"); + map.put("protocol", "TCP"); + map.put("port", "22"); + map.put("enabled", "true"); + + map.put("monitor", "true"); + + binder.bindToRequest(request, map); + String rawContent = (String) request.getPayload().getRawContent(); + assertTrue(rawContent.indexOf("Disabled") == -1); + } + + public void testDisableMonitoringDisabled() throws IOException { + HttpRequest request = new HttpRequest("GET", URI.create("http://test")); + BindAddInternetServiceToXmlPayload binder = injector + .getInstance(BindAddInternetServiceToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("name", "name"); + map.put("protocol", "TCP"); + map.put("port", "22"); + map.put("enabled", "true"); + + map.put("monitor", "false"); + + binder.bindToRequest(request, map); + String rawContent = (String) request.getPayload().getRawContent(); + assertTrue(rawContent.indexOf("Disabled") != -1); + } } diff --git a/common/trmk/src/test/resources/terremark/CreateInternetService-options-test.xml b/common/trmk/src/test/resources/terremark/CreateInternetService-options-test.xml index 82730c8dfe..b4886c9e8f 100644 --- a/common/trmk/src/test/resources/terremark/CreateInternetService-options-test.xml +++ b/common/trmk/src/test/resources/terremark/CreateInternetService-options-test.xml @@ -5,6 +5,7 @@ TCP 22 false - - yahoo + + yahoo + Disabled diff --git a/common/trmk/src/test/resources/terremark/CreateInternetService-test.xml b/common/trmk/src/test/resources/terremark/CreateInternetService-test.xml index 6207dd6dd8..d6e082ad3b 100644 --- a/common/trmk/src/test/resources/terremark/CreateInternetService-test.xml +++ b/common/trmk/src/test/resources/terremark/CreateInternetService-test.xml @@ -5,6 +5,7 @@ TCP 22 true + + name TCP 22 - name TCP 22 diff --git a/common/trmk/src/test/resources/terremark/CreateInternetService-test2.xml b/common/trmk/src/test/resources/terremark/CreateInternetService-test2.xml index 301c21589d..c8aeff2552 100644 --- a/common/trmk/src/test/resources/terremark/CreateInternetService-test2.xml +++ b/common/trmk/src/test/resources/terremark/CreateInternetService-test2.xml @@ -6,4 +6,5 @@ 22 true + diff --git a/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java b/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java index da4e29bed0..bd4ccc6c05 100644 --- a/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java +++ b/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClient.java @@ -23,6 +23,7 @@ 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.IPADDRESS_LIST_XML; import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.KEYSLIST_XML; import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.PUBLICIP_XML; @@ -50,6 +51,7 @@ 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.IpAddress; import org.jclouds.vcloud.terremark.domain.KeyPair; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; @@ -61,6 +63,7 @@ import org.jclouds.vcloud.terremark.functions.VDCURIToPublicIPsEndpoint; 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.IpAddressesHandler; import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler; import org.jclouds.vcloud.terremark.xml.KeyPairHandler; import org.jclouds.vcloud.terremark.xml.KeyPairsHandler; @@ -239,4 +242,13 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient { @Consumes(APPLICATION_XML) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getTerremarkNetwork(@EndpointParam URI network); + + /** + * @see TerremarkECloudClient#getIpAddresses + */ + @GET + @Consumes(IPADDRESS_LIST_XML) + @XMLResponseParser(IpAddressesHandler.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> getIpAddresses(@EndpointParam URI network); } diff --git a/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java b/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java index f8e1bf97f1..2bfd7e1460 100644 --- a/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java +++ b/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudClient.java @@ -20,11 +20,13 @@ package org.jclouds.vcloud.terremark; import java.net.URI; +import java.util.Set; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.terremark.domain.IpAddress; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.TerremarkNetwork; import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork; @@ -54,5 +56,7 @@ public interface TerremarkECloudClient extends TerremarkVCloudClient { TerremarkOrgNetwork getNetwork(URI network); TerremarkNetwork getTerremarkNetwork(URI network); + + Set getIpAddresses(URI network); } diff --git a/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java b/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java index c357f47712..ddf82d61f5 100644 --- a/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java +++ b/providers/trmk-ecloud/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java @@ -67,4 +67,15 @@ public interface TerremarkECloudMediaType extends TerremarkVCloudMediaType { * "application/vnd.tmrk.ecloud.keysList+xml" */ public final static MediaType KEYSLIST_XML_TYPE = new MediaType("application", "vnd.tmrk.ecloud.keysList+xml"); + + + /** + * "application/vnd.tmrk.ecloud.ipAddressList+xml" + */ + public final static String IPADDRESS_LIST_XML = "application/vnd.tmrk.ecloud.ipAddressList+xml"; + + /** + * "application/vnd.tmrk.ecloud.ipAddressList+xml" + */ + public final static MediaType IPADDRESSES_LIST_XML_TYPE = new MediaType("application", "vnd.tmrk.ecloud.ipAddressList+xml"); } diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java index 72ced2e021..c67b23b92c 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java @@ -299,7 +299,7 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest