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 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 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.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()
*/

View File

@ -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<PublicIpAddress> 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<ResourceAllocation> 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.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides)
.buildInjector();
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector();
connection = tmClient = injector.getInstance(TerremarkVCloudClient.class);

View File

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

View File

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

View File

@ -299,12 +299,12 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
Method method = TerremarkECloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
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");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n");
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"),
"application/vnd.tmrk.ecloud.internetService+xml", false);
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>