Issue 217: call undeploy before deleting a vapp

This commit is contained in:
Adrian Cole 2010-03-29 10:43:42 -07:00
parent 6ea95932ff
commit b6e063bf51
2 changed files with 40 additions and 9 deletions

View File

@ -145,7 +145,19 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
if (!taskTester.apply(task.getId())) { if (!taskTester.apply(task.getId())) {
throw new TaskException("powerOff", vApp, task); throw new TaskException("powerOff", vApp, task);
} }
logger.debug("<< off vApp(%s)", vApp.getId()); vApp = client.getVApp(id);
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getId());
}
if (vApp.getStatus() != VAppStatus.UNRESOLVED) {
logger
.debug(">> undeploying vApp(%s), current status: %s", vApp.getId(), vApp
.getStatus());
Task task = client.undeployVApp(vApp.getId());
if (!taskTester.apply(task.getId())) {
throw new TaskException("undeploy", vApp, task);
}
vApp = client.getVApp(id);
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getId());
} }
logger.debug(">> deleting vApp(%s)", vApp.getId()); logger.debug(">> deleting vApp(%s)", vApp.getId());
client.deleteVApp(id); client.deleteVApp(id);

View File

@ -31,6 +31,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
@ -125,14 +126,6 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
return ip != null ? ip.getAddress() : null; return ip != null ? ip.getAddress() : null;
} }
@Override
public void stop(String id) {
VApp vApp = client.getVApp(id);
Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp);
deletePublicIpAddressesWithNoServicesAttached(ipAddresses);
super.stop(id);
}
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) { private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) {
Set<PublicIpAddress> ipAddresses = Sets.newHashSet(); Set<PublicIpAddress> ipAddresses = Sets.newHashSet();
SERVICE: for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC() SERVICE: for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC()
@ -173,6 +166,32 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
} }
} }
/**
* deletes the internet service and nodes associated with the vapp. Deletes the IP address, if
* there are no others using it. Finally, it powers off and deletes the vapp. Note that we do not
* call undeploy, as terremark does not support the command.
*/
@Override
public void stop(String id) {
VApp vApp = client.getVApp(id);
Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp);
deletePublicIpAddressesWithNoServicesAttached(ipAddresses);
if (vApp.getStatus() != VAppStatus.OFF) {
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp
.getStatus());
Task task = client.powerOffVApp(vApp.getId());
if (!taskTester.apply(task.getId())) {
throw new TaskException("powerOff", vApp, task);
}
vApp = client.getVApp(id);
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getId());
}
logger.debug(">> deleting vApp(%s)", vApp.getId());
client.deleteVApp(id);
boolean successful = notFoundTester.apply(vApp);
logger.debug("<< deleted vApp(%s) completed(%s)", vApp.getId(), successful);
}
@Override @Override
public Set<InetAddress> getPrivateAddresses(String id) { public Set<InetAddress> getPrivateAddresses(String id) {
VApp vApp = client.getVApp(id); VApp vApp = client.getVApp(id);