});
}
@Override
public void destroyNode(final String name) {
SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(name);
String diskName = null;
try {
Instance instance = api.getInstanceApiForProject(userProject.get()).getInZone(slashEncodedIds.getFirstId(),
slashEncodedIds.getSecondId());
if (instance.getMetadata().getItems().get(GCE_DELETE_BOOT_DISK_METADATA_KEY).equals("true")) {
Optional<AttachedDisk> disk = tryFind(instance.getDisks(), new Predicate<AttachedDisk>() {
@Override
public boolean apply(AttachedDisk input) {
return PersistentAttachedDisk.class.isInstance(input) &&
PersistentAttachedDisk.class.cast(input).isBoot();
}
});
if (disk.isPresent()) {
diskName = PersistentAttachedDisk.class.cast(disk.get()).getSourceDiskName();
}
}
} catch (Exception e) {
// TODO: what exception actually gets thrown here if the instance doesn't really exist?
}
waitOperationDone(api.getInstanceApiForProject(userProject.get()).deleteInZone(slashEncodedIds.getFirstId(),
slashEncodedIds.getSecondId()));
if (diskName != null) {
waitOperationDone(api.getDiskApiForProject(userProject.get()).deleteInZone(slashEncodedIds.getFirstId(),
diskName));
}
}