From 63b6f2104432d131d9e0a8e4578879d4f8bfc1e2 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 18 Feb 2011 21:01:19 -0800 Subject: [PATCH] Issue 484:Add ability to disable the monitor on Terremark eCloud Internet Service --- .../options/AddInternetServiceOptions.java | 19 +++++---- .../terremark/TerremarkClientLiveTest.java | 41 +++++++++---------- .../CreateInternetService-options-test.xml | 4 +- .../terremark/CreateInternetService-test.xml | 2 +- .../TerremarkECloudAsyncClientTest.java | 4 +- .../CreateInternetService-options-test.xml | 12 ++++++ 6 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 providers/trmk-ecloud/src/test/resources/CreateInternetService-options-test.xml 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 9c4b8c55f0..bb5788cb47 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 @@ -25,7 +25,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.vcloud.terremark.binders.BindAddInternetServiceToXmlPayload; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; +import com.google.common.collect.ImmutableMap; /** * @@ -40,31 +40,34 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa String enabled = "true"; @VisibleForTesting Boolean monitorEnabled = null; + @Override public R bindToRequest(R request, Map postParams) { - Map copy = Maps.newHashMap(); + ImmutableMap.Builder copy = ImmutableMap. builder(); copy.putAll(postParams); - copy.put("description", description); + if (description != null) + copy.put("description", description); copy.put("enabled", enabled); - if (monitorEnabled != null) { + if (monitorEnabled != null) copy.put("monitor", monitorEnabled.toString()); - } - return super.bindToRequest(request, copy); + return super.bindToRequest(request, copy.build()); } public AddInternetServiceOptions disabled() { 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 { /** @@ -82,7 +85,7 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa AddInternetServiceOptions options = new AddInternetServiceOptions(); return options.monitorDisabled(); } - + /** * @see AddInternetServiceOptions#disabled() */ 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 a4a1d0fd35..a08e019741 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 @@ -102,26 +102,26 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes @Test public void testGetAllInternetServices() throws Exception { for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null) - .getHref())) { + .getHref())) { 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()); + + InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX + "-no-monitoring", + Protocol.TCP, 1234, AddInternetServiceOptions.Builder.monitorDisabled()); + tmClient.deleteInternetService(service.getId()); } @Test public void testGetPublicIpsAssociatedWithVDC() throws Exception { for (PublicIpAddress ip : tmClient - .getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) { + .getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) { assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId())); assertNotNull(tmClient.getPublicIp(ip.getId())); } @@ -150,7 +150,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes @Test(enabled = true) public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException, - IOException { + IOException { prepare(); StringBuffer name = new StringBuffer(); for (int i = 0; i < 15; i++) @@ -176,7 +176,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes // if this template supports setting the root password, let's add it to // our options CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions() - .getHref()); + .getHref()); if (customizationOptions.canCustomizePassword()) instantiateOptions.withPassword("robotsarefun"); @@ -186,7 +186,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes // instantiate, noting vApp returned has minimal details vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName, - instantiateOptions); + instantiateOptions); assertEquals(vApp.getStatus(), Status.RESOLVED); @@ -278,7 +278,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes @Test(enabled = true, dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" }) public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException, IOException { node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName() - + "-SSH", 22); + + "-SSH", 22); loopAndCheckPass(); } @@ -341,7 +341,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes vApp = tmClient.getVApp(vApp.getHref()); Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1) - .addDisk(25 * 1048576).addDisk(25 * 1048576)); + .addDisk(25 * 1048576).addDisk(25 * 1048576)); assert successTester.apply(task.getHref()); @@ -359,7 +359,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes // extract the disks on the vApp sorted by addressOnParent List disks = Lists.newArrayList(filter(vApp.getResourceAllocations(), - resourceType(ResourceType.DISK_DRIVE))); + resourceType(ResourceType.DISK_DRIVE))); // delete the second disk task = tmClient.configureVApp(vApp, deleteDiskWithAddressOnParent(disks.get(1).getAddressOnParent())); @@ -371,18 +371,18 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes } private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs, - int processorCount, long memory, long hardDisk) { + int processorCount, long memory, long hardDisk) { assertEquals(vApp.getName(), serverName); assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(), - processorCount); + processorCount); assertEquals( - find(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER)).getVirtualQuantity(), 1); + find(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER)).getVirtualQuantity(), 1); assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(), memory); assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity(), - hardDisk); - assertEquals(vApp.getSize().longValue(), find(vApp.getResourceAllocations(), - resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity()); + hardDisk); + assertEquals(vApp.getSize().longValue(), + find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity()); } private void doCheckPass(String address) throws IOException { @@ -465,8 +465,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes Properties overrides = setupProperties(); Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides) - .buildInjector(); + ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector(); connection = tmClient = injector.getInstance(TerremarkVCloudClient.class); 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 b4886c9e8f..ed05341d39 100644 --- a/common/trmk/src/test/resources/terremark/CreateInternetService-options-test.xml +++ b/common/trmk/src/test/resources/terremark/CreateInternetService-options-test.xml @@ -5,7 +5,7 @@ TCP 22 false - + 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 d6e082ad3b..a91635ef77 100644 --- a/common/trmk/src/test/resources/terremark/CreateInternetService-test.xml +++ b/common/trmk/src/test/resources/terremark/CreateInternetService-test.xml @@ -5,7 +5,7 @@ TCP 22 true - + name TCP 22 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 c67b23b92c..d239c52c1e 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,12 +299,12 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest + name + TCP + 22 + false + + yahoo + + Disabled +