diff --git a/api/src/com/cloud/api/commands/CreateVolumeCmd.java b/api/src/com/cloud/api/commands/CreateVolumeCmd.java index 0b51bca2e10..b29ff749d81 100644 --- a/api/src/com/cloud/api/commands/CreateVolumeCmd.java +++ b/api/src/com/cloud/api/commands/CreateVolumeCmd.java @@ -46,7 +46,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the disk volume. Must be used with the domainId parameter.") private String accountName; - @Parameter(name=ApiConstants.DISK_OFFERING_ID,required = true, type=CommandType.LONG, description="the ID of the disk offering. Either diskOfferingId or snapshotId must be passed in.") + @Parameter(name=ApiConstants.DISK_OFFERING_ID,required = false, type=CommandType.LONG, description="the ID of the disk offering. Either diskOfferingId or snapshotId must be passed in.") private Long diskOfferingId; @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the disk offering. If used with the account parameter returns the disk volume associated with the account for the specified domain.") @@ -58,7 +58,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { @Parameter(name=ApiConstants.SIZE, type=CommandType.LONG, description="Arbitrary volume size. Mutually exclusive with diskOfferingId") private Long size; - @Parameter(name=ApiConstants.SNAPSHOT_ID, type=CommandType.LONG, description="the snapshot ID for the disk volume. If snapshot id is passed in, a private disk offering id must be passed in as well (no disk size, only tags).") + @Parameter(name=ApiConstants.SNAPSHOT_ID, type=CommandType.LONG, description="the snapshot ID for the disk volume. Either diskOfferingId or snapshotId must be passed in.") private Long snapshotId; @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the ID of the availability zone") diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 7402a8d2438..91cbcf47c67 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -427,7 +427,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag String volumeUUID = null; String details = null; - DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); + DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()); DataCenterVO dc = _dcDao.findById(volume.getDataCenterId()); DiskProfile dskCh = new DiskProfile(volume, diskOffering, snapshot.getHypervisorType()); @@ -526,7 +526,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag // Create an event Long templateId = originalVolume.getTemplateId(); ; - Long diskOfferingId = volume.getDiskOfferingId(); + Long diskOfferingId = originalVolume.getDiskOfferingId(); if (createdVolume.getPath() != null) { Long offeringId = null; @@ -665,9 +665,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag volume.setPodId(pod.getId()); volume.setState(Volume.State.Ready); _volsDao.persist(volume); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), - volume.getId(), volume.getName(), diskOffering.getId(), null, dskCh.getSize()); - _usageEventDao.persist(usageEvent); + } txn.commit(); @@ -1399,7 +1397,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag Long size = null; // validate input parameters before creating the volume - if (cmd.getSnapshotId() == null && cmd.getDiskOfferingId() == null) { + if ((cmd.getSnapshotId() == null && cmd.getDiskOfferingId() == null) || (cmd.getSnapshotId() != null && cmd.getDiskOfferingId() != null)) { throw new InvalidParameterValueException("Either disk Offering Id or snapshot Id must be passed whilst creating volume"); } @@ -1450,30 +1448,18 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag size = (size * 1024 * 1024 * 1024);// custom size entered is in GB, to be converted to bytes } } else { - DiskOfferingVO privOffering = null; Long snapshotId = cmd.getSnapshotId(); Snapshot snapshotCheck = _snapshotDao.findById(snapshotId); - diskOfferingId = cmd.getDiskOfferingId(); + if (snapshotCheck == null) { throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId); } - - if(diskOfferingId == null) { - throw new InvalidParameterValueException("Please specify a valid private disk offering"); - } else { - privOffering = _diskOfferingDao.findById(diskOfferingId); - if(privOffering == null) { - throw new InvalidParameterValueException("Please specify a valid private disk offering"); - } else { - if(!privOffering.isCustomized()) - throw new InvalidParameterValueException("Please specify a valid private disk offering"); - } - } VolumeVO vol = _volsDao.findByIdIncludingRemoved(snapshotCheck.getVolumeId()); zoneId = vol.getDataCenterId(); size = vol.getSize(); //we maintain size from org vol ; disk offering is used for tags purposes - + diskOfferingId = vol.getDiskOfferingId(); + if (account != null) { if (isAdmin(account.getType())) { Account snapshotOwner = _accountDao.findById(snapshotCheck.getAccountId()); @@ -1527,6 +1513,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag volume.setState(Volume.State.Allocated); volume = _volsDao.persist(volume); UserContext.current().setEventDetails("Volume Id: "+volume.getId()); + + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), + volume.getId(), volume.getName(), diskOfferingId, null, size); + + _usageEventDao.persist(usageEvent); + return volume; }