diff --git a/core/src/com/cloud/server/ManagementServer.java b/core/src/com/cloud/server/ManagementServer.java index 157c3685ba8..9b85f40c31e 100755 --- a/core/src/com/cloud/server/ManagementServer.java +++ b/core/src/com/cloud/server/ManagementServer.java @@ -1836,8 +1836,9 @@ public interface ManagementServer { * @param mirrored boolean value of whether or not the offering provides disk mirroring * @param tags Comma separated string to indicate special tags for the disk offering. * @return the created disk offering, null if failed to create + * @throws InternalErrorException */ - DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException; + DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException, InternalErrorException; /** * Delete a disk offering diff --git a/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java b/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java index b77c51ba7bb..64a458e78a1 100644 --- a/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java +++ b/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java @@ -27,6 +27,7 @@ import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; import com.cloud.api.ServerApiException; import com.cloud.domain.DomainVO; +import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.storage.DiskOfferingVO; import com.cloud.user.User; @@ -86,7 +87,9 @@ public class CreateDiskOfferingCmd extends BaseCmd { diskOffering = getManagementServer().createDiskOffering(userId, domainId.longValue(), name, displayText, numGB.intValue(),tags); } catch (InvalidParameterValueException ex) { throw new ServerApiException (BaseCmd.VM_INVALID_PARAM_ERROR, ex.getMessage()); - } + } catch (InternalErrorException e) { + throw new ServerApiException (BaseCmd.INTERNAL_ERROR, e.getMessage()); + } if (diskOffering == null) { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering"); diff --git a/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java b/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java index 8c38a24857b..12a448fade8 100644 --- a/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java +++ b/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java @@ -64,7 +64,7 @@ public class DeleteDiskOfferingCmd extends BaseCmd { throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find a disk offering with id " + id); } - if(disk.getName().equals("Private") && disk.getDisplayText().equals("Private Disk")){ + if(disk.getDiskSize()==0){ //block deletion of these disks throw new ServerApiException(BaseCmd.INTERNAL_ERROR,"Cannot delete this diskoffering as it is private"); } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 35a63ae5bc2..a678f157817 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -145,7 +145,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { _configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Small", "Small Disk, 5 GB", 5, null); _configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Medium", "Medium Disk, 20 GB", 20, null); _configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Large", "Large Disk, 100 GB", 100, null); - _configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Private", "Private Disk", 0, null); + //_configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Private", "Private Disk", 0, null); //Add default manual snapshot policy SnapshotPolicyVO snapPolicy = new SnapshotPolicyVO(0L, "00", "GMT", (short)4, 0); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 93198b7fe63..3a5e02187d3 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -368,7 +368,7 @@ public class ManagementServerImpl implements ManagementServer { private final int _proxyRamSize; private final int _ssRamSize; - private final long _maxVolumeSizeInTb; + private final long _maxVolumeSizeInGb; private final Map _availableIdsMap; private boolean _networkGroupsEnabled = false; @@ -465,9 +465,9 @@ public class ManagementServerImpl implements ManagementServer { // and set them in the right places String maxVolumeSizeInTbString = _configs.get("max.volume.size.gb"); - long maxVolumeSizeTb = NumbersUtil.parseLong(maxVolumeSizeInTbString, new Long("2093049000000")); + long maxVolumeSizeBytes = NumbersUtil.parseLong(maxVolumeSizeInTbString, new Long("2093049000000")); - _maxVolumeSizeInTb = maxVolumeSizeTb; + _maxVolumeSizeInGb = maxVolumeSizeBytes/1000000000; _routerRamSize = NumbersUtil.parseInt(_configs.get("router.ram.size"),NetworkManager.DEFAULT_ROUTER_VM_RAMSIZE); _proxyRamSize = NumbersUtil.parseInt(_configs.get("consoleproxy.ram.size"), ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); @@ -7091,12 +7091,22 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException { - if (numGibibytes!=0 && numGibibytes < 1) { - throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb."); - } else if (numGibibytes > _maxVolumeSizeInTb) { - throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInTb + " Gb."); + public DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException, InternalErrorException { + + if(numGibibytes!=0 && numGibibytes<1){ + throw new InvalidParameterValueException("The minimum disk offering size is 1 GB"); + } + + if (numGibibytes > _maxVolumeSizeInGb) { + throw new InvalidParameterValueException("The maximum allowed size for a disk is " + _maxVolumeSizeInGb + " Gb."); } + + if(numGibibytes==0){ + List existingOffering = _diskOfferingDao.findPrivateDiskOffering(); + + if(existingOffering!=null && existingOffering.size()>0) + throw new InternalErrorException("There already exists a private disk offering"); + } return _configMgr.createDiskOffering(userId, domainId, name, description, numGibibytes, tags); } @@ -8820,7 +8830,7 @@ public class ManagementServerImpl implements ManagementServer { public boolean validateCustomVolumeSizeRange(long size) throws InvalidParameterValueException { if (size<0 || (size>0 && size < 2097152)) { throw new InvalidParameterValueException("Please specify a size (in bytes) of at least 2 MB or above."); - } else if (size > _maxVolumeSizeInTb) { + } else if (size > (_maxVolumeSizeInGb*1000000000)) { throw new InvalidParameterValueException("The maximum size allowed is 2 TB"); }