private void deleteEverythingExceptNSAndSOA ( String id , String name ) { List < ActionOnResourceRecordSet > deletes = new ArrayList < ActionOnResourceRecordSet > ( ) ; ResourceRecordSetList page = api . listResourceRecordSets ( id ) ; while ( ! page . isEmpty ( ) ) { for ( ResourceRecordSet < ? > rrset : page ) { if ( rrset . type ( ) . equals ( "SOA" ) || rrset . type ( ) . equals ( "NS" ) && rrset . name ( ) . equals ( name ) ) { continue ; } deletes . add ( ActionOnResourceRecordSet . delete ( rrset ) ) ; } if ( ! deletes . isEmpty ( ) ) { api . changeResourceRecordSets ( id , deletes ) ; } if ( page . next == null ) { page . clear ( ) ; } else { deletes . clear ( ) ; page = api . listResourceRecordSets ( id , page . next . name , page . next . type , page . next . identifier ) ; } } }
Works through the zone deleting each page of rrsets except the zone s SOA and the NS rrsets . Once the zone is cleared it can be deleted .