jclouds/jclouds — pull request #348 by aledsage (2012-02-04 16:47:24+00:00)
Title: Issue 445: cleaning up incidental resources

Fixes for issues #364, #365 and #445.

Don (polyrock@hotmail.com) and I had previously worked on this, so much of the code was already done from October - just not quite finished!

Notes:

* As suggested by Adrian in #445, we do `deleteSecurityGroup; deleteKeyPair`. We rely on the first throwing an exception if there are still nodes using these.
We rely on the securityGroup+keyPair having been created as a pair for a given group of nodes.

* There is (probably) a race if someone concurrently creates an instance at the same time as deleting old instances - we may delete the key-pair just when the node-being-created was about to rely on its existance.
But I'm pretty sure we can live with that.

* I've refactored everywhere that overrides deleteNode and deleteNodesMatching, to instead override cleanUpIncidentalResourcesOfDeadNodes (as called by BaseComputeService.deleteNode).
However, I don't have all of standbox in my workspace so may have missed some there.

Other observations:

* EC2ComputeService.deleteSecurityGroup and deleteKeyPair are marked as @VisibleForTesting, but appear not to be called from anything but this class.
I think they could safely be marked as private if desired.

---
When running AWSEC2ComputeServiceLiveTest, the testExtendedOptionsAndLogin failed. I'm pretty sure that's not related to these changes though...

java.lang.AssertionError: [region=us-west-2, availabilityZone=us-west-2b, instanceId=i-38d39408, instanceState=running, instanceType=t1.micro, virtualizationType=paravirtual, imageId=ami-30fe7300, ipAddress=50.112.43.130, dnsName=ec2-50-112-43-130.us-west-2.compute.amazonaws.com, privateIpAddress=10.248.6.144, privateDnsName=ip-10-248-6-144.us-west-2.compute.internal, keyName=ec2-o, platform=null, launchTime=Sat Feb 04 16:02:15 GMT 2012, rootDeviceName=/dev/sda1, rootDeviceType=ebs, ebsBlockDevices={/dev/sda1=[volumeId=vol-69f77702, attachmentStatus=attached, attachTime=Sat Feb 04 16:02:38 GMT 2012, deleteOnTermination=true]}, monitoringState=enabled, placementGroup=null, productCodes=[], spotInstanceRequestId=sir-ecb12219, subnetId=null, hypervisor=xen, vpcId=null, tags={Name=ec2-o}]
at org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceLiveTest.testExtendedOptionsAndLogin(AWSEC2ComputeServiceLiveTest.java:176)