mirror of https://github.com/apache/cloudstack.git
Fix message publish in transaction (#438)
* Fix message publish in transaction * Resolve comments
This commit is contained in:
parent
04a589d013
commit
2f4cea6dca
|
|
@ -20,6 +20,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.dc.VlanVO;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationSubGroupVO;
|
||||
|
||||
|
|
@ -189,7 +190,7 @@ public interface ConfigurationManager {
|
|||
* @param caller TODO
|
||||
* @return success/failure
|
||||
*/
|
||||
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller);
|
||||
VlanVO deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller);
|
||||
|
||||
void checkZoneAccess(Account caller, DataCenter zone);
|
||||
|
||||
|
|
|
|||
|
|
@ -256,6 +256,8 @@ import com.cloud.vm.dao.UserVmDao;
|
|||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.googlecode.ipv6.IPv6Address;
|
||||
|
||||
import static com.cloud.configuration.ConfigurationManager.MESSAGE_DELETE_VLAN_IP_RANGE_EVENT;
|
||||
|
||||
/**
|
||||
* NetworkManagerImpl implements NetworkManager.
|
||||
*/
|
||||
|
|
@ -3292,16 +3294,16 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
|
||||
final NetworkVO networkFinal = network;
|
||||
try {
|
||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||
final List<VlanVO> deletedVlanRangeToPublish = Transaction.execute(new TransactionCallback<List<VlanVO>>() {
|
||||
@Override
|
||||
public void doInTransactionWithoutResult(final TransactionStatus status) {
|
||||
public List<VlanVO> doInTransaction(TransactionStatus status) {
|
||||
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, networkFinal.getGuruName());
|
||||
|
||||
if (!guru.trash(networkFinal, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()))) {
|
||||
throw new CloudRuntimeException("Failed to trash network.");
|
||||
}
|
||||
|
||||
if (!deleteVlansInNetwork(networkFinal, context.getCaller().getId(), callerAccount)) {
|
||||
Pair<Boolean, List<VlanVO>> deletedVlans = deleteVlansInNetwork(networkFinal, context.getCaller().getId(), callerAccount);
|
||||
if (!deletedVlans.first()) {
|
||||
s_logger.warn("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
|
||||
throw new CloudRuntimeException("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
|
||||
} else {
|
||||
|
|
@ -3335,8 +3337,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
_resourceLimitMgr.decrementResourceCount(networkFinal.getAccountId(), ResourceType.network, networkFinal.getDisplayNetwork());
|
||||
}
|
||||
}
|
||||
return deletedVlans.second();
|
||||
}
|
||||
});
|
||||
publishDeletedVlanRanges(deletedVlanRangeToPublish);
|
||||
if (_networksDao.findById(network.getId()) == null) {
|
||||
// remove its related ACL permission
|
||||
final Pair<Class<?>, Long> networkMsg = new Pair<Class<?>, Long>(Network.class, networkFinal.getId());
|
||||
|
|
@ -3352,6 +3356,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
return success;
|
||||
}
|
||||
|
||||
private void publishDeletedVlanRanges(List<VlanVO> deletedVlanRangeToPublish) {
|
||||
if (CollectionUtils.isNotEmpty(deletedVlanRangeToPublish)) {
|
||||
for (VlanVO vlan : deletedVlanRangeToPublish) {
|
||||
_messageBus.publish(_name, MESSAGE_DELETE_VLAN_IP_RANGE_EVENT, PublishScope.LOCAL, vlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resourceCountNeedsUpdate(final NetworkOffering ntwkOff, final ACLType aclType) {
|
||||
//Update resource count only for Isolated account specific non-system networks
|
||||
|
|
@ -3359,15 +3371,19 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
return updateResourceCount;
|
||||
}
|
||||
|
||||
protected boolean deleteVlansInNetwork(final NetworkVO network, final long userId, final Account callerAccount) {
|
||||
protected Pair<Boolean, List<VlanVO>> deleteVlansInNetwork(final NetworkVO network, final long userId, final Account callerAccount) {
|
||||
final long networkId = network.getId();
|
||||
//cleanup Public vlans
|
||||
final List<VlanVO> publicVlans = _vlanDao.listVlansByNetworkId(networkId);
|
||||
List<VlanVO> deletedPublicVlanRange = new ArrayList<>();
|
||||
boolean result = true;
|
||||
for (final VlanVO vlan : publicVlans) {
|
||||
if (!_configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId(), callerAccount)) {
|
||||
VlanVO vlanRange = _configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId(), callerAccount);
|
||||
if (vlanRange == null) {
|
||||
s_logger.warn("Failed to delete vlan " + vlan.getId() + ");");
|
||||
result = false;
|
||||
} else {
|
||||
deletedPublicVlanRange.add(vlanRange);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3387,7 +3403,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
_dcDao.releaseVnet(BroadcastDomainType.getValue(network.getBroadcastUri()), network.getDataCenterId(),
|
||||
network.getPhysicalNetworkId(), network.getAccountId(), network.getReservationId());
|
||||
}
|
||||
return result;
|
||||
return new Pair<>(result, deletedPublicVlanRange);
|
||||
}
|
||||
|
||||
public class NetworkGarbageCollector extends ManagedContextRunnable {
|
||||
|
|
|
|||
|
|
@ -5236,7 +5236,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
|
||||
@Override
|
||||
@DB
|
||||
public boolean deleteVlanAndPublicIpRange(final long userId, final long vlanDbId, final Account caller) {
|
||||
public VlanVO deleteVlanAndPublicIpRange(final long userId, final long vlanDbId, final Account caller) {
|
||||
VlanVO vlanRange = _vlanDao.findById(vlanDbId);
|
||||
if (vlanRange == null) {
|
||||
throw new InvalidParameterValueException("Please specify a valid IP range id.");
|
||||
|
|
@ -5342,9 +5342,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
}
|
||||
});
|
||||
|
||||
messageBus.publish(_name, MESSAGE_DELETE_VLAN_IP_RANGE_EVENT, PublishScope.LOCAL, vlanRange);
|
||||
|
||||
return true;
|
||||
return vlanRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -5850,7 +5848,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
throw new InvalidParameterValueException("Please specify a valid IP range id.");
|
||||
}
|
||||
|
||||
return deleteVlanAndPublicIpRange(CallContext.current().getCallingUserId(), vlanDbId, CallContext.current().getCallingAccount());
|
||||
return deleteAndPublishVlanAndPublicIpRange(CallContext.current().getCallingUserId(), vlanDbId, CallContext.current().getCallingAccount());
|
||||
}
|
||||
|
||||
private boolean deleteAndPublishVlanAndPublicIpRange(final long userId, final long vlanDbId, final Account caller) {
|
||||
VlanVO deletedVlan = deleteVlanAndPublicIpRange(userId, vlanDbId, caller);
|
||||
if (deletedVlan != null) {
|
||||
messageBus.publish(_name, MESSAGE_DELETE_VLAN_IP_RANGE_EVENT, PublishScope.LOCAL, deletedVlan);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.util.Set;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.dc.VlanVO;
|
||||
import org.apache.cloudstack.api.command.admin.config.ResetCfgCmd;
|
||||
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.CreateGuestNetworkIpv6PrefixCmd;
|
||||
|
|
@ -517,9 +518,9 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu
|
|||
* @see com.cloud.configuration.ConfigurationManager#deleteVlanAndPublicIpRange(long, long, com.cloud.user.Account)
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller) {
|
||||
public VlanVO deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
|||
Loading…
Reference in New Issue