Skip to content

Commit

Permalink
server: remove dedicated bgp peers and ipv4 subnets when delete an ac…
Browse files Browse the repository at this point in the history
…count or domain
  • Loading branch information
weizhouapache committed Aug 29, 2024
1 parent 2212f22 commit a73801b
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,12 @@ public interface RoutedIpv4Manager extends PluggableService, Configurable {
Vpc changeBgpPeersForVpc(ChangeBgpPeersForVpcCmd changeBgpPeersForVpcCmd);

List<Long> getBgpPeerIdsForAccount(Account owner, long zoneIdd);

void removeIpv4SubnetsForZoneByAccountId(long accountId);

void removeIpv4SubnetsForZoneByDomainId(long domainId);

void removeBgpPeersByAccountId(long accountId);

void removeBgpPeersByDomainId(long domainId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface DataCenterIpv4GuestSubnetDao extends GenericDao<DataCenterIpv4G
List<DataCenterIpv4GuestSubnetVO> listByDataCenterId(long dcId);
List<DataCenterIpv4GuestSubnetVO> listByDataCenterIdAndAccountId(long dcId, long accountId);
List<DataCenterIpv4GuestSubnetVO> listByDataCenterIdAndDomainId(long dcId, long domainId);
List<DataCenterIpv4GuestSubnetVO> listByAccountId(long accountId);
List<DataCenterIpv4GuestSubnetVO> listByDomainId(long domainId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ public List<DataCenterIpv4GuestSubnetVO> listByDataCenterIdAndDomainId(long dcId
sc.and(sc.entity().getAccountId(), SearchCriteria.Op.NULL);
return sc.list();
}

@Override
public List<DataCenterIpv4GuestSubnetVO> listByAccountId(long accountId) {
QueryBuilder<DataCenterIpv4GuestSubnetVO> sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class);
sc.and(sc.entity().getAccountId(), SearchCriteria.Op.EQ, accountId);
return sc.list();
}

@Override
public List<DataCenterIpv4GuestSubnetVO> listByDomainId(long domainId) {
QueryBuilder<DataCenterIpv4GuestSubnetVO> sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class);
sc.and(sc.entity().getDomainId(), SearchCriteria.Op.EQ, domainId);
return sc.list();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public interface BgpPeerDao extends GenericDao<BgpPeerVO, Long> {
BgpPeerVO persist(BgpPeerVO bgpPeerVO, Map<BgpPeer.Detail, String> details);

List<Long> listAvailableBgpPeerIdsForAccount(long zoneId, long domainId, long accountId, boolean useSystemBgpPeers);

int removeByAccountId(long accountId);
int removeByDomainId(long domainId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,18 @@ private List<Long> listBgpPeerIdsForAccount(long zoneId, long domainId, long acc
throw new CloudRuntimeException("Caught: " + sql, e);
}
}

@Override
public int removeByAccountId(long accountId) {
SearchCriteria<BgpPeerVO> sc = createSearchCriteria();
sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
return remove(sc);
}

@Override
public int removeByDomainId(long domainId) {
SearchCriteria<BgpPeerVO> sc = createSearchCriteria();
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
return remove(sc);
}
}
9 changes: 9 additions & 0 deletions server/src/main/java/com/cloud/user/AccountManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
import org.apache.cloudstack.resourcedetail.UserDetailVO;
import org.apache.cloudstack.resourcedetail.dao.UserDetailsDao;
Expand Down Expand Up @@ -320,6 +321,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
private IpAddressManager _ipAddrMgr;
@Inject
private RoleService roleService;
@Inject
private RoutedIpv4Manager routedIpv4Manager;

@Inject
private PasswordPolicy passwordPolicy;
Expand Down Expand Up @@ -1067,6 +1070,12 @@ public int compare(NetworkVO network1, NetworkVO network2) {
}
}

// remove dedicated IPv4 subnets
routedIpv4Manager.removeIpv4SubnetsForZoneByAccountId(accountId);

// remove dedicated BGP peers
routedIpv4Manager.removeBgpPeersByAccountId(accountId);

// release account specific guest vlans
List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId);
for (AccountGuestVlanMapVO map : maps) {
Expand Down
9 changes: 9 additions & 0 deletions server/src/main/java/com/cloud/user/DomainManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.region.RegionManager;
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -161,6 +162,8 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
private ResourceLimitService resourceLimitService;
@Inject
private AffinityGroupDomainMapDao affinityGroupDomainMapDao;
@Inject
private RoutedIpv4Manager routedIpv4Manager;

@Inject
MessageBus _messageBus;
Expand Down Expand Up @@ -393,6 +396,12 @@ private boolean cleanDomain(DomainVO domain, Boolean cleanup) {
removeDomainWithNoAccountsForCleanupNetworksOrDedicatedResources(domain);
}

// remove dedicated IPv4 subnets
routedIpv4Manager.removeIpv4SubnetsForZoneByDomainId(domain.getId());

// remove dedicated BGP peers
routedIpv4Manager.removeBgpPeersByDomainId(domain.getId());

if (!_configMgr.releaseDomainSpecificVirtualRanges(domain.getId())) {
CloudRuntimeException e = new CloudRuntimeException("Can't delete the domain yet because failed to release domain specific virtual ip ranges");
e.addProxyObject(domain.getUuid(), "domainId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1592,4 +1592,32 @@ private Vpc changeBgpPeersForVpcInternal(Vpc vpc, List<Long> bgpPeerIds) {

return vpcDao.findById(vpc.getId());
}

@Override
public void removeIpv4SubnetsForZoneByAccountId(long accountId) {
List<DataCenterIpv4GuestSubnetVO> existingSubnets = dataCenterIpv4GuestSubnetDao.listByAccountId(accountId);
for (DataCenterIpv4GuestSubnetVO subnet : existingSubnets) {
ipv4GuestSubnetNetworkMapDao.deleteByParentId(subnet.getId());
dataCenterIpv4GuestSubnetDao.remove(subnet.getId());
}
}

@Override
public void removeIpv4SubnetsForZoneByDomainId(long domainId) {
List<DataCenterIpv4GuestSubnetVO> existingSubnets = dataCenterIpv4GuestSubnetDao.listByDomainId(domainId);
for (DataCenterIpv4GuestSubnetVO subnet : existingSubnets) {
ipv4GuestSubnetNetworkMapDao.deleteByParentId(subnet.getId());
dataCenterIpv4GuestSubnetDao.remove(subnet.getId());
}
}

@Override
public void removeBgpPeersByAccountId(long accountId) {
bgpPeerDao.removeByAccountId(accountId);
}

@Override
public void removeBgpPeersByDomainId(long domainId) {
bgpPeerDao.removeByDomainId(domainId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.apache.cloudstack.engine.service.api.OrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
import org.apache.cloudstack.resourcedetail.dao.UserDetailsDao;
import org.junit.After;
Expand Down Expand Up @@ -203,6 +204,8 @@ public class AccountManagetImplTestBase {
UsageEventDao _usageEventDao;
@Mock
AccountService _accountService;
@Mock
RoutedIpv4Manager routedIpv4Manager;

@Before
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.region.RegionManager;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -108,6 +109,8 @@ public class DomainManagerImplTest {
DomainDetailsDao _domainDetailsDao;
@Mock
AnnotationDao annotationDao;
@Mock
RoutedIpv4Manager routedIpv4Manager;

@Spy
@InjectMocks
Expand Down

0 comments on commit a73801b

Please sign in to comment.