Issue 484:Add ability to disable the monitor on Terremark eCloud Internet Service

This commit is contained in:
Adrian Cole 2011-02-18 21:01:19 -08:00
parent c83eb2e395
commit 63b6f21044
6 changed files with 48 additions and 34 deletions

View File

@ -25,7 +25,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.vcloud.terremark.binders.BindAddInternetServiceToXmlPayload; import org.jclouds.vcloud.terremark.binders.BindAddInternetServiceToXmlPayload;
import com.google.common.annotations.VisibleForTesting; 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"; String enabled = "true";
@VisibleForTesting @VisibleForTesting
Boolean monitorEnabled = null; Boolean monitorEnabled = null;
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
Map<String, String> copy = Maps.newHashMap(); ImmutableMap.Builder<String, String> copy = ImmutableMap.<String, String> builder();
copy.putAll(postParams); copy.putAll(postParams);
copy.put("description", description); if (description != null)
copy.put("description", description);
copy.put("enabled", enabled); copy.put("enabled", enabled);
if (monitorEnabled != null) { if (monitorEnabled != null)
copy.put("monitor", monitorEnabled.toString()); copy.put("monitor", monitorEnabled.toString());
} return super.bindToRequest(request, copy.build());
return super.bindToRequest(request, copy);
} }
public AddInternetServiceOptions disabled() { public AddInternetServiceOptions disabled() {
this.enabled = "false"; this.enabled = "false";
return this; return this;
} }
public AddInternetServiceOptions monitorDisabled() { public AddInternetServiceOptions monitorDisabled() {
this.monitorEnabled = false; this.monitorEnabled = false;
return this; return this;
} }
public AddInternetServiceOptions withDescription(String description) { public AddInternetServiceOptions withDescription(String description) {
this.description = description; this.description = description;
return this; return this;
} }
public static class Builder { public static class Builder {
/** /**
@ -82,7 +85,7 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa
AddInternetServiceOptions options = new AddInternetServiceOptions(); AddInternetServiceOptions options = new AddInternetServiceOptions();
return options.monitorDisabled(); return options.monitorDisabled();
} }
/** /**
* @see AddInternetServiceOptions#disabled() * @see AddInternetServiceOptions#disabled()
*/ */

View File

@ -102,26 +102,26 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
@Test @Test
public void testGetAllInternetServices() throws Exception { public void testGetAllInternetServices() throws Exception {
for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null) for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null)
.getHref())) { .getHref())) {
assertNotNull(tmClient.getNodes(service.getId())); assertNotNull(tmClient.getNodes(service.getId()));
} }
} }
@Test @Test
public void testCreateInternetServiceMonitorDisabled() throws Exception { public void testCreateInternetServiceMonitorDisabled() throws Exception {
VDC vdc = tmClient.findVDCInOrgNamed(null, null); VDC vdc = tmClient.findVDCInOrgNamed(null, null);
Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref()); Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref());
PublicIpAddress publicIp = publicIpAddresses.iterator().next(); PublicIpAddress publicIp = publicIpAddresses.iterator().next();
System.out.println("PublicIP: " + publicIp.getAddress());
InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX + "-no-monitoring",
tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX + "-no-monitoring", Protocol.TCP, 1234, Protocol.TCP, 1234, AddInternetServiceOptions.Builder.monitorDisabled());
AddInternetServiceOptions.Builder.monitorDisabled()); tmClient.deleteInternetService(service.getId());
} }
@Test @Test
public void testGetPublicIpsAssociatedWithVDC() throws Exception { public void testGetPublicIpsAssociatedWithVDC() throws Exception {
for (PublicIpAddress ip : tmClient for (PublicIpAddress ip : tmClient
.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) { .getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) {
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId())); assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
assertNotNull(tmClient.getPublicIp(ip.getId())); assertNotNull(tmClient.getPublicIp(ip.getId()));
} }
@ -150,7 +150,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
@Test(enabled = true) @Test(enabled = true)
public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException, public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException { IOException {
prepare(); prepare();
StringBuffer name = new StringBuffer(); StringBuffer name = new StringBuffer();
for (int i = 0; i < 15; i++) 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 // if this template supports setting the root password, let's add it to
// our options // our options
CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions() CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions()
.getHref()); .getHref());
if (customizationOptions.canCustomizePassword()) if (customizationOptions.canCustomizePassword())
instantiateOptions.withPassword("robotsarefun"); instantiateOptions.withPassword("robotsarefun");
@ -186,7 +186,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
// instantiate, noting vApp returned has minimal details // instantiate, noting vApp returned has minimal details
vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName, vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName,
instantiateOptions); instantiateOptions);
assertEquals(vApp.getStatus(), Status.RESOLVED); assertEquals(vApp.getStatus(), Status.RESOLVED);
@ -278,7 +278,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
@Test(enabled = true, dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" }) @Test(enabled = true, dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" })
public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException, IOException { public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException, IOException {
node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName() node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName()
+ "-SSH", 22); + "-SSH", 22);
loopAndCheckPass(); loopAndCheckPass();
} }
@ -341,7 +341,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
vApp = tmClient.getVApp(vApp.getHref()); vApp = tmClient.getVApp(vApp.getHref());
Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1) 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()); assert successTester.apply(task.getHref());
@ -359,7 +359,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
// extract the disks on the vApp sorted by addressOnParent // extract the disks on the vApp sorted by addressOnParent
List<ResourceAllocation> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(), List<ResourceAllocation> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(),
resourceType(ResourceType.DISK_DRIVE))); resourceType(ResourceType.DISK_DRIVE)));
// delete the second disk // delete the second disk
task = tmClient.configureVApp(vApp, deleteDiskWithAddressOnParent(disks.get(1).getAddressOnParent())); 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, 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.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(), assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(),
processorCount); processorCount);
assertEquals( 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.MEMORY)).getVirtualQuantity(), memory);
assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity(), assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity(),
hardDisk); hardDisk);
assertEquals(vApp.getSize().longValue(), find(vApp.getResourceAllocations(), assertEquals(vApp.getSize().longValue(),
resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity()); find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity());
} }
private void doCheckPass(String address) throws IOException { private void doCheckPass(String address) throws IOException {
@ -465,8 +465,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
Properties overrides = setupProperties(); Properties overrides = setupProperties();
Injector injector = new RestContextFactory().createContextBuilder(provider, Injector injector = new RestContextFactory().createContextBuilder(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides) ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector();
.buildInjector();
connection = tmClient = injector.getInstance(TerremarkVCloudClient.class); connection = tmClient = injector.getInstance(TerremarkVCloudClient.class);

View File

@ -5,7 +5,7 @@
<Protocol>TCP</Protocol> <Protocol>TCP</Protocol>
<Port>22</Port> <Port>22</Port>
<Enabled>false</Enabled> <Enabled>false</Enabled>
<Description>yahoo</Description> <Description>yahoo</Description>
<Monitor><MonitorType>Disabled</MonitorType></Monitor>
</CreateInternetServiceRequest> </CreateInternetServiceRequest>

View File

@ -5,7 +5,7 @@
<Protocol>TCP</Protocol> <Protocol>TCP</Protocol>
<Port>22</Port> <Port>22</Port>
<Enabled>true</Enabled> <Enabled>true</Enabled>
<Description>name TCP 22</Description> <Description>name TCP 22</Description>
</CreateInternetServiceRequest> </CreateInternetServiceRequest>

View File

@ -299,12 +299,12 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
Method method = TerremarkECloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", URI.class, Method method = TerremarkECloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class); String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/publicIp/12"), HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/publicIp/12"),
"name", Protocol.TCP, 22, disabled().withDescription("yahoo"), AddInternetServiceOptions.Builder.monitorDisabled()); "name", Protocol.TCP, 22, disabled().withDescription("yahoo").monitorDisabled());
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1"); assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose( assertPayloadEquals(request, Strings2.toStringAndClose(
getClass().getResourceAsStream("/terremark/CreateInternetService-options-test.xml")).replace( getClass().getResourceAsStream("/CreateInternetService-options-test.xml")).replace(
"vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"), "vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"),
"application/vnd.tmrk.ecloud.internetService+xml", false); "application/vnd.tmrk.ecloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);

View File

@ -0,0 +1,12 @@
<CreateInternetServiceRequest
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:tmrk:vCloudExpressExtensions-1.6">
<Name>name</Name>
<Protocol>TCP</Protocol>
<Port>22</Port>
<Enabled>false</Enabled>
<Description>yahoo</Description>
<Monitor><MonitorType>Disabled</MonitorType></Monitor>
</CreateInternetServiceRequest>