bug 7105: improvements to editZone. Now you can add more vlan ranges to the existing set, as long as the range addition is additive in nature. eg. 400-410 can be changed to 398-410/400-412/200-800 as all these are additive in nature

status 7105: resolved fixed
This commit is contained in:
abhishek 2011-02-15 11:43:44 -08:00
parent 3e1fa215c3
commit fa70c8af52
2 changed files with 72 additions and 18 deletions

View File

@ -66,7 +66,7 @@ public class DataCenterVnetDaoImpl extends
try {
txn.start();
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertVnet);
for (int i = start; i < end; i++) {
for (int i = start; i <= end; i++) {
stmt.setString(1, String.valueOf(i));
stmt.setLong(2, dcId);
stmt.addBatch();

View File

@ -644,7 +644,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
@Override
public DataCenterVO editZone(long userId, long zoneId, String newZoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr) throws InvalidParameterValueException, InternalErrorException {
// Make sure the zone exists
boolean isVnetEditingAdditive = false;
String existingVnetRange = null;
// Make sure the zone exists
if (!validZone(zoneId)) {
throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist.");
}
@ -660,7 +663,35 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
// If the Vnet range is being changed, make sure there are no allocated VNets
if (vnetRange != null) {
if (zoneHasAllocatedVnets(zoneId)) {
existingVnetRange = zone.getVnet();
if(existingVnetRange != null) {
String[] existingVnetArray = existingVnetRange.split("-");
String[] newVnetArray = vnetRange.split("-");
int existingVnetArrayLength = existingVnetArray.length;
int newVnetArrayLength = newVnetArray.length;
boolean compareFirstOnly = false;
if(existingVnetArrayLength == 1 || newVnetArrayLength == 1) {
//only compare arr[0]
compareFirstOnly = true;
}
if(compareFirstOnly) {
if(new Integer(newVnetArray[0]) <= new Integer(existingVnetArray[0])) {
isVnetEditingAdditive = true;
}
} else if((new Integer(newVnetArray[0]) <= new Integer(existingVnetArray[0])) && (new Integer(newVnetArray[1]) >= new Integer(existingVnetArray[1]))) {
isVnetEditingAdditive = true;
}
} else {
isVnetEditingAdditive = true;
}
if (zoneHasAllocatedVnets(zoneId) && !isVnetEditingAdditive) {
throw new InternalErrorException("The vlan range is not editable because there are allocated vlans.");
}
}
@ -670,14 +701,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
//2. Check if any of these has the current data center associated
//3. If yes, throw exception
//4, If no, edit
List<DomainRouterVO> allDomainRoutersAvailable = _domrDao.listAll();
for(DomainRouterVO domR : allDomainRoutersAvailable)
{
if(domR.getDataCenterId() == zoneId)
{
throw new InternalErrorException("The zone is not editable because there are domR's associated with the zone.");
}
if(!isVnetEditingAdditive) {
List<DomainRouterVO> allDomainRoutersAvailable = _domrDao.listAll();
for(DomainRouterVO domR : allDomainRoutersAvailable)
{
if(domR.getDataCenterId() == zoneId)
{
throw new InternalErrorException("The zone is not editable because there are domR's associated with the zone.");
}
}
}
//5. Reached here, hence editable
@ -711,11 +743,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
if (vnetRange != null) {
zone.setVnet(vnetRange);
}
if (!_zoneDao.update(zoneId, zone)) {
throw new InternalErrorException("Failed to edit zone. Please contact Cloud Support.");
}
if (vnetRange != null) {
String[] tokens = vnetRange.split("-");
@ -733,10 +761,36 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
throw new InvalidParameterValueException("Please specify a valid vnet range between 0-4096");
}
_zoneDao.deleteVnet(zoneId);
_zoneDao.addVnet(zone.getId(), begin, end);
if(isVnetEditingAdditive) {
if(existingVnetRange == null) {
_zoneDao.addVnet(zone.getId(), begin, end);
} else {
String[] oldTokens = existingVnetRange.split("-");
int oldBegin = 0;
int oldEnd = 0;
try {
oldBegin = Integer.parseInt(oldTokens[0]);
oldEnd = tokens.length == 1 ? (begin + 1) : Integer.parseInt(oldTokens[1]);
_zoneDao.addVnet(zone.getId(), begin, oldBegin-1);
_zoneDao.addVnet(zone.getId(), oldEnd+1, end);
} catch (NumberFormatException e) {
s_logger.warn("Unable to parse vnet range");
throw new InvalidParameterValueException("Please specify a valid vnet range between 0-4096");
}
}
} else {
_zoneDao.deleteVnet(zoneId);
_zoneDao.addVnet(zone.getId(), begin, end);
}
}
if (!_zoneDao.update(zoneId, zone)) {
throw new InternalErrorException("Failed to edit zone. Please contact Cloud Support.");
}
saveConfigurationEvent(userId, null, EventTypes.EVENT_ZONE_EDIT, "Successfully edited zone with name: " + zone.getName() + ".", "dcId=" + zone.getId(), "dns1=" + dns1, "dns2=" + dns2, "internalDns1=" + internalDns1, "internalDns2=" + internalDns2, "vnetRange=" + vnetRange, "guestCidr=" + guestCidr);
return zone;