DaanHoogland commented on code in PR #7630:
URL: https://github.com/apache/cloudstack/pull/7630#discussion_r1242283633
##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -4264,23 +4256,38 @@ public boolean deletePhysicalNetwork(final Long
physicalNetworkId) {
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
- // delete vlans for this zone
- List<VlanVO> vlans =
_vlanDao.listVlansByPhysicalNetworkId(physicalNetworkId);
- for (VlanVO vlan : vlans) {
- _vlanDao.remove(vlan.getId());
- }
-
- // Delete networks
- List<NetworkVO> networks =
_networksDao.listByPhysicalNetwork(physicalNetworkId);
- if (networks != null && !networks.isEmpty()) {
- for (NetworkVO network : networks) {
- _networksDao.remove(network.getId());
- }
- }
+ disablePhysicalNetwork(physicalNetworkId, pNetwork);
+ deleteIpAddresses();
+ deleteVlans();
+ deleteNetworks();
// delete vnets
_dcDao.deleteVnet(physicalNetworkId);
+ if (!deleteProviders()) {
+ return false;
+ }
+
+ // delete traffic types
+ _pNTrafficTypeDao.deleteTrafficTypes(physicalNetworkId);
+
+ return _physicalNetworkDao.remove(physicalNetworkId);
+ }
+
+ private void disablePhysicalNetwork(Long physicalNetworkId,
PhysicalNetworkVO pNetwork) {
+ pNetwork.setState(PhysicalNetwork.State.Disabled);
+ _physicalNetworkDao.update(physicalNetworkId, pNetwork);
+ }
+
+ private void deleteIpAddresses() {
+ List<IPAddressVO> ipAddresses =
_ipAddressDao.listByPhysicalNetworkId(physicalNetworkId);
+ for (IPAddressVO ipaddress : ipAddresses) {
+ _ipAddressDao.remove(ipaddress.getId());
+ }
+ }
+
+ @Nullable
Review Comment:
hm, that must be some remnance of an automatic addition by intellij, that
remained after I refactored the method to return boolean (instead of some
Object)
```suggestion
```
##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -4264,23 +4256,38 @@ public boolean deletePhysicalNetwork(final Long
physicalNetworkId) {
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
- // delete vlans for this zone
- List<VlanVO> vlans =
_vlanDao.listVlansByPhysicalNetworkId(physicalNetworkId);
- for (VlanVO vlan : vlans) {
- _vlanDao.remove(vlan.getId());
- }
-
- // Delete networks
- List<NetworkVO> networks =
_networksDao.listByPhysicalNetwork(physicalNetworkId);
- if (networks != null && !networks.isEmpty()) {
- for (NetworkVO network : networks) {
- _networksDao.remove(network.getId());
- }
- }
+ disablePhysicalNetwork(physicalNetworkId, pNetwork);
+ deleteIpAddresses();
+ deleteVlans();
+ deleteNetworks();
// delete vnets
_dcDao.deleteVnet(physicalNetworkId);
+ if (!deleteProviders()) {
+ return false;
+ }
+
+ // delete traffic types
+ _pNTrafficTypeDao.deleteTrafficTypes(physicalNetworkId);
+
+ return _physicalNetworkDao.remove(physicalNetworkId);
+ }
+
+ private void disablePhysicalNetwork(Long physicalNetworkId,
PhysicalNetworkVO pNetwork) {
+ pNetwork.setState(PhysicalNetwork.State.Disabled);
+ _physicalNetworkDao.update(physicalNetworkId, pNetwork);
+ }
+
+ private void deleteIpAddresses() {
+ List<IPAddressVO> ipAddresses =
_ipAddressDao.listByPhysicalNetworkId(physicalNetworkId);
+ for (IPAddressVO ipaddress : ipAddresses) {
+ _ipAddressDao.remove(ipaddress.getId());
Review Comment:
@weizhouapache, not sure what you mean. This is what we do here, right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]