corrected the disableStaticNAT functions, and added code to properly clean up on destroy node

This commit is contained in:
Adrian Cole 2011-11-27 18:15:58 -05:00
parent 1dbb34c2aa
commit 9dc71cec3a
8 changed files with 129 additions and 20 deletions

View File

@ -214,11 +214,35 @@ public class CloudStackComputeServiceAdapter implements
public void destroyNode(String id) {
long guestId = Long.parseLong(id);
Long job = client.getVirtualMachineClient().destroyVirtualMachine(guestId);
if (job != null) {
logger.debug(">> destroying virtualMachine(%s)", guestId);
boolean completed = jobComplete.apply(job);
logger.trace("<< virtualMachine(%s) destroyed(%s)", guestId, completed);
Set<IPForwardingRule> forwardingRules = client.getNATClient().getIPForwardingRulesForVirtualMachine(guestId);
for (IPForwardingRule rule : forwardingRules) {
job = client.getNATClient().deleteIPForwardingRule(rule.getId());
jobComplete.apply(job);
deleteIPForwardingRuleAndDisableStaticNAT(rule);
}
} else {
logger.trace("<< virtualMachine(%s) not found", guestId);
}
}
public void deleteIPForwardingRuleAndDisableStaticNAT(IPForwardingRule rule) {
boolean completed;
Long job = client.getNATClient().deleteIPForwardingRule(rule.getId());
if (job != null) {
logger.debug(">> deleting IPForwardingRule(%s)", rule.getId());
completed = jobComplete.apply(job);
logger.trace("<< IPForwardingRule(%s) deleted(%s)", rule.getId(), completed);
disableStaticNATOnPublicIP(rule.getIPAddressId());
}
}
public void disableStaticNATOnPublicIP(Long IPAddressId) {
Long job = client.getNATClient().disableStaticNATOnPublicIP(IPAddressId);
if (job != null) {
logger.debug(">> disabling static nat IPAddress(%s)", IPAddressId);
logger.trace("<< IPAddress(%s) static nat disabled", IPAddressId);
}
}

View File

@ -38,7 +38,6 @@ import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -123,18 +122,19 @@ public interface NATAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "deleteIpForwardingRule")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Long> deleteIPForwardingRule(@QueryParam("id") long id);
/**
* @see NATClient#disableStaticNat
* @see NATClient#disableStaticNATOnPublicIP
*/
@GET
@QueryParams(keys = "command", values = "disableStaticNat")
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> disableStaticNat(@QueryParam("ipaddressid") long IPAddressId);
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Long> disableStaticNATOnPublicIP(@QueryParam("ipaddressid") long IPAddressId);
}

View File

@ -106,7 +106,7 @@ public interface NATClient {
*
* @param IPAddressId
* the public IP address id for which static nat feature is being
* disableed
* disabled
*/
void disableStaticNat(long IPAddressId);
Long disableStaticNATOnPublicIP(long IPAddressId);
}

View File

@ -25,13 +25,10 @@ import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
@ -155,8 +152,8 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
}
public void testDisableStaticNAT() throws SecurityException, NoSuchMethodException, IOException {
Method method = NATAsyncClient.class.getMethod("disableStaticNat", long.class);
public void testDisableStaticNATOnPublicIP() throws SecurityException, NoSuchMethodException, IOException {
Method method = NATAsyncClient.class.getMethod("disableStaticNATOnPublicIP", long.class);
HttpRequest httpRequest = processor.createRequest(method, 5);
assertRequestLineEquals(httpRequest,
@ -164,9 +161,9 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
@ -181,7 +178,7 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);

View File

@ -0,0 +1,43 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.parse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "DeleteIPForwardingRuleResponseTest")
public class DeleteIPForwardingRuleResponseTest extends BaseItemParserTest<Long> {
@Override
public String resource() {
return "/deleteipforwardingruleresponse.json";
}
@Override
@SelectJson("jobid")
public Long expected() {
return 50005l;
}
}

View File

@ -0,0 +1,43 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.parse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "DisableStaticNATResponseTest")
public class DisableStaticNATResponseTest extends BaseItemParserTest<Long> {
@Override
public String resource() {
return "/disablestaticnatresponse.json";
}
@Override
@SelectJson("jobid")
public Long expected() {
return 50006l;
}
}

View File

@ -0,0 +1 @@
{ "deleteipforwardingruleresponse" : {"jobid":50005} }

View File

@ -0,0 +1 @@
{ "disablestaticnatresponse" : {"jobid":50006} }