Skip to content

Commit 8300b6f

Browse files
authored
AC-122 Fixing issue where manual vlan assignment could miss (#60)
* Making the manual vlan claim absolute and adding additional logic to reverse that claim when the network is shutdown. * Fixing issue where we set the wrong reservation id if it was missing from a normal network. * Need to set reservation to null to clear it if we don't need it.
1 parent 42759ed commit 8300b6f

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.LinkedList;
2828
import java.util.List;
2929
import java.util.Map;
30+
import java.util.Optional;
3031
import java.util.Set;
3132
import java.util.UUID;
3233
import java.util.concurrent.Executors;
@@ -707,17 +708,15 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
707708
}
708709

709710
if (vo.getBroadcastDomainType() == BroadcastDomainType.Vlan && vo.getBroadcastUri() != null && offering.getSpecifyVlan()) {
710-
s_logger.info("Recording a manually assigned vlan to table");
711711
String vnet = BroadcastDomainType.getValue(vo.getBroadcastUri());
712712
List<DataCenterVnetVO> vnetVOs = _datacenterVnetDao.findVnet(plan.getDataCenterId(), plan.getPhysicalNetworkId(), vnet);
713713
if (vnetVOs.size() == 1) {
714+
s_logger.info("Recording a manually assigned vlan to table");
714715
DataCenterVnetVO vnetVO = vnetVOs.get(0);
715-
if (vnetVO.getTakenAt() == null) {
716-
vnetVO.setTakenAt(new Date());
717-
vnetVO.setAccountId(owner.getId());
718-
vnetVO.setReservationId(vo.getUuid());
719-
_datacenterVnetDao.update(vnetVO.getId(), vnetVO);
720-
}
716+
vnetVO.setTakenAt(new Date());
717+
vnetVO.setAccountId(owner.getId());
718+
vnetVO.setReservationId(vo.getUuid());
719+
_datacenterVnetDao.update(vnetVO.getId(), vnetVO);
721720
}
722721
}
723722
}
@@ -2699,8 +2698,46 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
26992698
}
27002699
}
27012700
if (networkFinal.getBroadcastDomainType() == BroadcastDomainType.Vlan && networkFinal.getBroadcastUri() != null && networkOffering.getSpecifyVlan()) {
2702-
s_logger.info("Cleaning up our manually assigned vlan from table");
2703-
_dcDao.releaseVnet(BroadcastDomainType.getValue(networkFinal.getBroadcastUri()), networkFinal.getDataCenterId(), networkFinal.getPhysicalNetworkId(), networkFinal.getAccountId(), networkFinal.getUuid());
2701+
String vlan = BroadcastDomainType.getValue(networkFinal.getBroadcastUri());
2702+
List<DataCenterVnetVO> vnetVOs = _datacenterVnetDao.findVnet(networkFinal.getDataCenterId(), networkFinal.getPhysicalNetworkId(), vlan);
2703+
2704+
if (vnetVOs.size() == 1) {
2705+
s_logger.info("Cleaning up our manually assigned vlan from table");
2706+
List<NetworkVO> overlappingNetworks = _networksDao.listByZoneAndUriAndGuestType(networkFinal.getDataCenterId(), networkFinal.getBroadcastUri().toString(), null);
2707+
2708+
Optional<NetworkVO> networkToAssign = overlappingNetworks.stream().filter(n -> n.getId() != networkId).sorted((a, b) -> {
2709+
// The entity layer caches these, so performance shouldn't suffer
2710+
NetworkOffering aOff = _networkOfferingDao.findById(a.getNetworkOfferingId());
2711+
NetworkOffering bOff = _networkOfferingDao.findById(b.getNetworkOfferingId());
2712+
// We are sorting so that networks that specify a vlan manually get sorted first, aka smaller
2713+
if (aOff.getSpecifyVlan() && !bOff.getSpecifyVlan()) {
2714+
return -1;
2715+
} else if (bOff.getSpecifyVlan() && !aOff.getSpecifyVlan()) {
2716+
return 1;
2717+
}
2718+
return 0;
2719+
}).findFirst();
2720+
2721+
if (networkToAssign.isPresent()) {
2722+
NetworkVO network = networkToAssign.get();
2723+
NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
2724+
s_logger.info("Re-assigning vlan " + vlan + " to network: " + network);
2725+
DataCenterVnetVO vnetVO = vnetVOs.get(0);
2726+
vnetVO.setTakenAt(network.getCreated());
2727+
vnetVO.setAccountId(network.getAccountId());
2728+
if (network.getReservationId() != null) {
2729+
vnetVO.setReservationId(network.getReservationId());
2730+
} else if (offering.getSpecifyVlan()) {
2731+
// Only do this if it is one of our manually assigned networks
2732+
vnetVO.setReservationId(network.getUuid());
2733+
} else {
2734+
vnetVO.setReservationId(null);
2735+
}
2736+
_datacenterVnetDao.update(vnetVO.getId(), vnetVO);
2737+
} else {
2738+
_dcDao.releaseVnet(BroadcastDomainType.getValue(networkFinal.getBroadcastUri()), networkFinal.getDataCenterId(), networkFinal.getPhysicalNetworkId(), networkFinal.getAccountId(), networkFinal.getUuid());
2739+
}
2740+
}
27042741
}
27052742
}
27062743
});

0 commit comments

Comments
 (0)