mirror of https://github.com/apache/cloudstack.git
bug 13854: don't allow to remove network offerings if its in use by existing networks
status 13854: resolved fixed Reviewed-by: Alex Huang
This commit is contained in:
parent
8c75bf8805
commit
50fc52ee9b
|
|
@ -3561,6 +3561,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
if (offering.isDefault() == true) {
|
||||
throw new InvalidParameterValueException("Default network offering can't be deleted");
|
||||
}
|
||||
|
||||
//don't allow to delete network offering if it's in use by existing networks (the offering can be disabled though)
|
||||
int networkCount = _networkDao.getNetworkCountByNetworkOffId(offeringId);
|
||||
if (networkCount > 0) {
|
||||
throw new InvalidParameterValueException("Can't delete network offering " + offeringId + " as its used by " + networkCount + " networks. " +
|
||||
"To make the network offering unavaiable, disable it");
|
||||
}
|
||||
|
||||
if (_networkOfferingDao.remove(offeringId)) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -93,5 +93,7 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
|
|||
List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType);
|
||||
|
||||
void setCheckForGc(long networkId);
|
||||
|
||||
int getNetworkCountByNetworkOffId(long networkOfferingId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,13 +60,16 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
|||
final SearchBuilder<NetworkVO> ZoneSecurityGroupSearch;
|
||||
final GenericSearchBuilder<NetworkVO, Long> CountByOfferingId;
|
||||
final SearchBuilder<NetworkVO> PhysicalNetworkSearch;
|
||||
final SearchBuilder<NetworkVO> securityGroupSearch;
|
||||
final SearchBuilder<NetworkVO> SecurityGroupSearch;
|
||||
private final GenericSearchBuilder<NetworkVO, Integer> NetworksCount;
|
||||
|
||||
|
||||
NetworkAccountDaoImpl _accountsDao = ComponentLocator.inject(NetworkAccountDaoImpl.class);
|
||||
NetworkDomainDaoImpl _domainsDao = ComponentLocator.inject(NetworkDomainDaoImpl.class);
|
||||
NetworkOpDaoImpl _opDao = ComponentLocator.inject(NetworkOpDaoImpl.class);
|
||||
NetworkServiceMapDaoImpl _ntwkSvcMap = ComponentLocator.inject(NetworkServiceMapDaoImpl.class);
|
||||
|
||||
|
||||
final TableGenerator _tgMacAddress;
|
||||
Random _rand = new Random(System.currentTimeMillis());
|
||||
long _prefix = 0x2;
|
||||
|
|
@ -132,11 +135,16 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
|||
PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
PhysicalNetworkSearch.done();
|
||||
|
||||
securityGroupSearch = createSearchBuilder();
|
||||
SecurityGroupSearch = createSearchBuilder();
|
||||
SearchBuilder<NetworkServiceMapVO> join3 = _ntwkSvcMap.createSearchBuilder();
|
||||
join3.and("service", join3.entity().getService(), Op.EQ);
|
||||
securityGroupSearch.join("services", join3, securityGroupSearch.entity().getId(), join3.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
|
||||
securityGroupSearch.done();
|
||||
SecurityGroupSearch.join("services", join3, SecurityGroupSearch.entity().getId(), join3.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
|
||||
SecurityGroupSearch.done();
|
||||
|
||||
NetworksCount = createSearchBuilder(Integer.class);
|
||||
NetworksCount.select(null, Func.COUNT, NetworksCount.entity().getId());
|
||||
NetworksCount.and("networkOfferingId", NetworksCount.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
|
||||
NetworksCount.done();
|
||||
|
||||
_tgMacAddress = _tgs.get("macAddress");
|
||||
|
||||
|
|
@ -344,7 +352,7 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
|||
|
||||
@Override
|
||||
public List<NetworkVO> listSecurityGroupEnabledNetworks() {
|
||||
SearchCriteria<NetworkVO> sc = securityGroupSearch.create();
|
||||
SearchCriteria<NetworkVO> sc = SecurityGroupSearch.create();
|
||||
sc.setJoinParameters("services", "service", Service.SecurityGroup.getName());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
|
@ -400,5 +408,13 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
|||
|
||||
return listBy(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNetworkCountByNetworkOffId(long networkOfferingId) {
|
||||
SearchCriteria<Integer> sc = NetworksCount.create();
|
||||
sc.setParameters("networkOfferingId", networkOfferingId);
|
||||
List<Integer> count = customSearch(sc, null);
|
||||
return count.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue