diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java index 8e6fc7ad20..23bf9d0893 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java @@ -214,11 +214,35 @@ public class CloudStackComputeServiceAdapter implements public void destroyNode(String id) { long guestId = Long.parseLong(id); Long job = client.getVirtualMachineClient().destroyVirtualMachine(guestId); - boolean completed = jobComplete.apply(job); - Set forwardingRules = client.getNATClient().getIPForwardingRulesForVirtualMachine(guestId); - for(IPForwardingRule rule : forwardingRules) { - job = client.getNATClient().deleteIPForwardingRule(rule.getId()); - jobComplete.apply(job); + if (job != null) { + logger.debug(">> destroying virtualMachine(%s)", guestId); + boolean completed = jobComplete.apply(job); + logger.trace("<< virtualMachine(%s) destroyed(%s)", guestId, completed); + Set forwardingRules = client.getNATClient().getIPForwardingRulesForVirtualMachine(guestId); + for (IPForwardingRule rule : forwardingRules) { + 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); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java index 352d387b9b..bba24d819d 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java @@ -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 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 disableStaticNat(@QueryParam("ipaddressid") long IPAddressId); + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture disableStaticNATOnPublicIP(@QueryParam("ipaddressid") long IPAddressId); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java index 9fafec7909..105e1188ea 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java @@ -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); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATAsyncClientTest.java index 900c706ff2..33a27675d8 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATAsyncClientTest.java @@ -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 { + + @Override + public String resource() { + return "/deleteipforwardingruleresponse.json"; + } + + @Override + @SelectJson("jobid") + public Long expected() { + return 50005l; + } + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DisableStaticNATResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DisableStaticNATResponseTest.java new file mode 100644 index 0000000000..32307544b5 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DisableStaticNATResponseTest.java @@ -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 { + + @Override + public String resource() { + return "/disablestaticnatresponse.json"; + } + + @Override + @SelectJson("jobid") + public Long expected() { + return 50006l; + } + +} diff --git a/apis/cloudstack/src/test/resources/deleteipforwardingruleresponse.json b/apis/cloudstack/src/test/resources/deleteipforwardingruleresponse.json new file mode 100644 index 0000000000..ae9e7c8088 --- /dev/null +++ b/apis/cloudstack/src/test/resources/deleteipforwardingruleresponse.json @@ -0,0 +1 @@ +{ "deleteipforwardingruleresponse" : {"jobid":50005} } \ No newline at end of file diff --git a/apis/cloudstack/src/test/resources/disablestaticnatresponse.json b/apis/cloudstack/src/test/resources/disablestaticnatresponse.json new file mode 100644 index 0000000000..5bfd5a06a4 --- /dev/null +++ b/apis/cloudstack/src/test/resources/disablestaticnatresponse.json @@ -0,0 +1 @@ +{ "disablestaticnatresponse" : {"jobid":50006} } \ No newline at end of file