255255import com .cloud .vm .dao .VMInstanceDao ;
256256import com .googlecode .ipv6 .IPv6Address ;
257257
258+ import static com .cloud .configuration .ConfigurationManager .MESSAGE_DELETE_VLAN_IP_RANGE_EVENT ;
259+
258260/**
259261 * NetworkManagerImpl implements NetworkManager.
260262 */
@@ -3298,16 +3300,16 @@ public boolean destroyNetwork(final long networkId, final ReservationContext con
32983300
32993301 final NetworkVO networkFinal = network ;
33003302 try {
3301- Transaction .execute (new TransactionCallbackNoReturn () {
3303+ final List < VlanVO > deletedVlanRangeToPublish = Transaction .execute (new TransactionCallback < List < VlanVO >> () {
33023304 @ Override
3303- public void doInTransactionWithoutResult ( final TransactionStatus status ) {
3305+ public List < VlanVO > doInTransaction ( TransactionStatus status ) {
33043306 final NetworkGuru guru = AdapterBase .getAdapterByName (networkGurus , networkFinal .getGuruName ());
33053307
33063308 if (!guru .trash (networkFinal , _networkOfferingDao .findById (networkFinal .getNetworkOfferingId ()))) {
33073309 throw new CloudRuntimeException ("Failed to trash network." );
33083310 }
3309-
3310- if (!deleteVlansInNetwork ( networkFinal , context . getCaller (). getId (), callerAccount )) {
3311+ Pair < Boolean , List < VlanVO >> deletedVlans = deleteVlansInNetwork ( networkFinal , context . getCaller (). getId (), callerAccount );
3312+ if (!deletedVlans . first ( )) {
33113313 s_logger .warn ("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges" );
33123314 throw new CloudRuntimeException ("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges" );
33133315 } else {
@@ -3341,8 +3343,10 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
33413343 _resourceLimitMgr .decrementResourceCount (networkFinal .getAccountId (), ResourceType .network , networkFinal .getDisplayNetwork ());
33423344 }
33433345 }
3346+ return deletedVlans .second ();
33443347 }
33453348 });
3349+ publishDeletedVlanRanges (deletedVlanRangeToPublish );
33463350 if (_networksDao .findById (network .getId ()) == null ) {
33473351 // remove its related ACL permission
33483352 final Pair <Class <?>, Long > networkMsg = new Pair <Class <?>, Long >(Network .class , networkFinal .getId ());
@@ -3360,22 +3364,34 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
33603364 return success ;
33613365 }
33623366
3367+ private void publishDeletedVlanRanges (List <VlanVO > deletedVlanRangeToPublish ) {
3368+ if (CollectionUtils .isNotEmpty (deletedVlanRangeToPublish )) {
3369+ for (VlanVO vlan : deletedVlanRangeToPublish ) {
3370+ _messageBus .publish (_name , MESSAGE_DELETE_VLAN_IP_RANGE_EVENT , PublishScope .LOCAL , vlan );
3371+ }
3372+ }
3373+ }
3374+
33633375 @ Override
33643376 public boolean resourceCountNeedsUpdate (final NetworkOffering ntwkOff , final ACLType aclType ) {
33653377 //Update resource count only for Isolated account specific non-system networks
33663378 final boolean updateResourceCount = ntwkOff .getGuestType () == GuestType .Isolated && !ntwkOff .isSystemOnly () && aclType == ACLType .Account ;
33673379 return updateResourceCount ;
33683380 }
33693381
3370- protected boolean deleteVlansInNetwork (final NetworkVO network , final long userId , final Account callerAccount ) {
3382+ protected Pair < Boolean , List < VlanVO >> deleteVlansInNetwork (final NetworkVO network , final long userId , final Account callerAccount ) {
33713383 final long networkId = network .getId ();
33723384 //cleanup Public vlans
33733385 final List <VlanVO > publicVlans = _vlanDao .listVlansByNetworkId (networkId );
3386+ List <VlanVO > deletedPublicVlanRange = new ArrayList <>();
33743387 boolean result = true ;
33753388 for (final VlanVO vlan : publicVlans ) {
3376- if (!_configMgr .deleteVlanAndPublicIpRange (userId , vlan .getId (), callerAccount )) {
3389+ VlanVO vlanRange = _configMgr .deleteVlanAndPublicIpRange (userId , vlan .getId (), callerAccount );
3390+ if (vlanRange == null ) {
33773391 s_logger .warn ("Failed to delete vlan " + vlan .getId () + ");" );
33783392 result = false ;
3393+ } else {
3394+ deletedPublicVlanRange .add (vlanRange );
33793395 }
33803396 }
33813397
@@ -3395,7 +3411,7 @@ protected boolean deleteVlansInNetwork(final NetworkVO network, final long userI
33953411 _dcDao .releaseVnet (BroadcastDomainType .getValue (network .getBroadcastUri ()), network .getDataCenterId (),
33963412 network .getPhysicalNetworkId (), network .getAccountId (), network .getReservationId ());
33973413 }
3398- return result ;
3414+ return new Pair <>( result , deletedPublicVlanRange ) ;
33993415 }
34003416
34013417 public class NetworkGarbageCollector extends ManagedContextRunnable {
0 commit comments