mirror of https://github.com/apache/jclouds.git
corrected the disableStaticNAT functions, and added code to properly clean up on destroy node
This commit is contained in:
parent
1dbb34c2aa
commit
9dc71cec3a
|
@ -214,11 +214,35 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
long guestId = Long.parseLong(id);
|
long guestId = Long.parseLong(id);
|
||||||
Long job = client.getVirtualMachineClient().destroyVirtualMachine(guestId);
|
Long job = client.getVirtualMachineClient().destroyVirtualMachine(guestId);
|
||||||
|
if (job != null) {
|
||||||
|
logger.debug(">> destroying virtualMachine(%s)", guestId);
|
||||||
boolean completed = jobComplete.apply(job);
|
boolean completed = jobComplete.apply(job);
|
||||||
|
logger.trace("<< virtualMachine(%s) destroyed(%s)", guestId, completed);
|
||||||
Set<IPForwardingRule> forwardingRules = client.getNATClient().getIPForwardingRulesForVirtualMachine(guestId);
|
Set<IPForwardingRule> forwardingRules = client.getNATClient().getIPForwardingRulesForVirtualMachine(guestId);
|
||||||
for (IPForwardingRule rule : forwardingRules) {
|
for (IPForwardingRule rule : forwardingRules) {
|
||||||
job = client.getNATClient().deleteIPForwardingRule(rule.getId());
|
deleteIPForwardingRuleAndDisableStaticNAT(rule);
|
||||||
jobComplete.apply(job);
|
}
|
||||||
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ import org.jclouds.rest.annotations.SelectJson;
|
||||||
import org.jclouds.rest.annotations.Unwrap;
|
import org.jclouds.rest.annotations.Unwrap;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -123,18 +122,19 @@ public interface NATAsyncClient {
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@QueryParams(keys = "command", values = "deleteIpForwardingRule")
|
@QueryParams(keys = "command", values = "deleteIpForwardingRule")
|
||||||
@Unwrap(depth = 2)
|
@SelectJson("jobid")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Long> deleteIPForwardingRule(@QueryParam("id") long id);
|
ListenableFuture<Long> deleteIPForwardingRule(@QueryParam("id") long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NATClient#disableStaticNat
|
* @see NATClient#disableStaticNATOnPublicIP
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@QueryParams(keys = "command", values = "disableStaticNat")
|
@QueryParams(keys = "command", values = "disableStaticNat")
|
||||||
|
@SelectJson("jobid")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Void> disableStaticNat(@QueryParam("ipaddressid") long IPAddressId);
|
ListenableFuture<Long> disableStaticNATOnPublicIP(@QueryParam("ipaddressid") long IPAddressId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ public interface NATClient {
|
||||||
*
|
*
|
||||||
* @param IPAddressId
|
* @param IPAddressId
|
||||||
* the public IP address id for which static nat feature is being
|
* the public IP address id for which static nat feature is being
|
||||||
* disableed
|
* disabled
|
||||||
*/
|
*/
|
||||||
void disableStaticNat(long IPAddressId);
|
Long disableStaticNATOnPublicIP(long IPAddressId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,10 @@ import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
|
||||||
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
|
||||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -155,8 +152,8 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDisableStaticNAT() throws SecurityException, NoSuchMethodException, IOException {
|
public void testDisableStaticNATOnPublicIP() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = NATAsyncClient.class.getMethod("disableStaticNat", long.class);
|
Method method = NATAsyncClient.class.getMethod("disableStaticNATOnPublicIP", long.class);
|
||||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
|
@ -164,9 +161,9 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
|
|
||||||
|
@ -181,7 +178,7 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{ "deleteipforwardingruleresponse" : {"jobid":50005} }
|
|
@ -0,0 +1 @@
|
||||||
|
{ "disablestaticnatresponse" : {"jobid":50006} }
|
Loading…
Reference in New Issue