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,26 +40,29 @@ 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);
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;

View File

@ -112,10 +112,10 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
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
@ -381,8 +381,8 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
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());
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

@ -7,5 +7,5 @@
<Enabled>false</Enabled>
<Description>yahoo</Description>
<Monitor><MonitorType>Disabled</MonitorType></Monitor>
</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>