Source:
<code>public void removeDatabase(String providerDatabaseId) throws CloudException, InternalException { APITrace.begin(getProvider(), "RDBMS.removeDatabase"); try { long timeout = System.currentTimeMillis() + (CalendarWrapper.MINUTE*10L); Database db = getDatabase(providerDatabaseId); while( timeout > System.currentTimeMillis() ) { if( db == null || DatabaseState.DELETED.equals(db.getCurrentState()) ) { return; } if( DatabaseState.AVAILABLE.equals(db.getCurrentState()) ) { break; } try { Thread.sleep(15000L); } catch( InterruptedException ignore ) { } try { db = getDatabase(providerDatabaseId); } catch( Throwable ignore ) { } } Iterable<String> securityGroups = getSecurityGroups(providerDatabaseId); Map<String,String> parameters = getProvider().getStandardRdsParameters(getProvider().getContext(), DELETE_DB_INSTANCE); EC2Method method; parameters.put("DBInstanceIdentifier", providerDatabaseId); parameters.put("FinalDBSnapshotIdentifier", providerDatabaseId + "-FINAL-" + System.currentTimeMillis()); method = new EC2Method(SERVICE_ID, getProvider(), parameters); try { method.invoke(); } catch( EC2Exception e ) { parameters = getProvider().getStandardRdsParameters(getProvider().getContext(), DELETE_DB_INSTANCE); parameters.put("DBInstanceIdentifier", providerDatabaseId); parameters.put("SkipFinalSnapshot", "true"); method = new EC2Method(SERVICE_ID, getProvider(), parameters); try { method.invoke(); } catch( EC2Exception again ) { throw new CloudException(e); } } try { for( String securityGroupId : securityGroups ) { if( securityGroupId.equals(providerDatabaseId) ) { for( int i=0; i<5; i++ ) { try { removeSecurityGroup(securityGroupId); break; } catch( CloudException ignore ) { try { Thread.sleep(4000L); } catch( InterruptedException e ) { } <START> } <END> } } } } catch( Throwable t ) { t.printStackTrace(); } } finally { APITrace.end(); } }</code><technical_language>CloudException is a shared group if a error</technical_language>

Target:
public void removeDatabase(String providerDatabaseId) throws CloudException, InternalException { APITrace.begin(getProvider(), "RDBMS.removeDatabase"); try { long timeout = System.currentTimeMillis() + (CalendarWrapper.MINUTE*10L); Database db = getDatabase(providerDatabaseId); while( timeout > System.currentTimeMillis() ) { if( db == null || DatabaseState.DELETED.equals(db.getCurrentState()) ) { return; } if( DatabaseState.AVAILABLE.equals(db.getCurrentState()) ) { break; } try { Thread.sleep(15000L); } catch( InterruptedException ignore ) { } try { db = getDatabase(providerDatabaseId); } catch( Throwable ignore ) { } } Iterable<String> securityGroups = getSecurityGroups(providerDatabaseId); Map<String,String> parameters = getProvider().getStandardRdsParameters(getProvider().getContext(), DELETE_DB_INSTANCE); EC2Method method; parameters.put("DBInstanceIdentifier", providerDatabaseId); parameters.put("FinalDBSnapshotIdentifier", providerDatabaseId + "-FINAL-" + System.currentTimeMillis()); method = new EC2Method(SERVICE_ID, getProvider(), parameters); try { method.invoke(); } catch( EC2Exception e ) { parameters = getProvider().getStandardRdsParameters(getProvider().getContext(), DELETE_DB_INSTANCE); parameters.put("DBInstanceIdentifier", providerDatabaseId); parameters.put("SkipFinalSnapshot", "true"); method = new EC2Method(SERVICE_ID, getProvider(), parameters); try { method.invoke(); } catch( EC2Exception again ) { throw new CloudException(e); } } try { for( String securityGroupId : securityGroups ) { if( securityGroupId.equals(providerDatabaseId) ) { for( int i=0; i<3; i++ ) { try { removeSecurityGroup(securityGroupId); break; } catch( EC2Exception e ) { if (e.getProviderCode().equalsIgnoreCase("InvalidDBSecurityGroupState")) { try { Thread.sleep(6000L); } catch( InterruptedException ie ) { } } else throw new CloudException(e); } } } } } catch( Throwable t ) { t.printStackTrace(); } } finally { APITrace.end(); } }