bug 8216: create volume from snapshot can take a disk_offering_id, if disk_offering_id is not specified, use the one from original volume

status 8216: resolved fixed
This commit is contained in:
anthony 2011-02-28 16:18:42 -08:00
parent 8571d04034
commit cd27202a26
4 changed files with 17 additions and 8 deletions

View File

@ -52,7 +52,10 @@ public class SnapshotVO implements Snapshot {
long domainId;
@Column(name="volume_id")
Long volumeId;
Long volumeId;
@Column(name="disk_offering_id")
Long diskOfferingId;
@Expose
@Column(name="path")
@ -94,11 +97,12 @@ public class SnapshotVO implements Snapshot {
public SnapshotVO() { }
public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, String path, String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType) {
public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, Long diskOfferingId, String path, String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType) {
this.dataCenterId = dcId;
this.accountId = accountId;
this.domainId = domainId;
this.volumeId = volumeId;
this.volumeId = volumeId;
this.diskOfferingId = diskOfferingId;
this.path = path;
this.name = name;
this.snapshotType = snapshotType;
@ -132,6 +136,10 @@ public class SnapshotVO implements Snapshot {
return volumeId;
}
public long getDiskOfferingId() {
return diskOfferingId;
}
public void setVolumeId(Long volumeId) {
this.volumeId = volumeId;
}

View File

@ -1395,7 +1395,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
throw new InvalidParameterValueException("Either disk Offering Id or snapshot Id must be passed whilst creating volume");
}
if (cmd.getSnapshotId() == null) {
if (cmd.getSnapshotId() == null) {// create a new volume
zoneId = cmd.getZoneId();
if ((zoneId == null)) {
throw new InvalidParameterValueException("Missing parameter, zoneid must be specified.");
@ -1441,15 +1441,15 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
size = (size * 1024 * 1024 * 1024);// custom size entered is in GB, to be converted to bytes
}
} else {
} else { // create volume from snapshot
Long snapshotId = cmd.getSnapshotId();
SnapshotVO snapshotCheck = _snapshotDao.findById(snapshotId);
diskOfferingId = cmd.getDiskOfferingId();
diskOfferingId = (cmd.getDiskOfferingId() != null) ? cmd.getDiskOfferingId() : snapshotCheck.getDiskOfferingId();
if (snapshotCheck == null) {
throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId);
}
zoneId = snapshotCheck.getDataCenterId();
size = snapshotCheck.getSize(); //we maintain size from org vol ; disk offering is used for tags purposes
size = snapshotCheck.getSize(); //; disk offering is used for tags purposes
if (account != null) {
if (isAdmin(account.getType())) {

View File

@ -1191,7 +1191,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
// user
Type snapshotType = getSnapshotType(policyId);
HypervisorType hypervisorType = this._volsDao.getHypervisorType(volumeId);
SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), null, snapshotName,
SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), null, snapshotName,
(short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), hypervisorType);
return _snapshotDao.persist(snapshotVO);
}

View File

@ -401,6 +401,7 @@ CREATE TABLE `cloud`.`snapshots` (
`account_id` bigint unsigned NOT NULL COMMENT 'owner. foreign key to account table',
`domain_id` bigint unsigned NOT NULL COMMENT 'the domain that the owner belongs to',
`volume_id` bigint unsigned NOT NULL COMMENT 'volume it belongs to. foreign key to volume table',
`disk_offering_id` bigint unsigned NOT NULL COMMENT ,
`status` varchar(32) COMMENT 'snapshot creation status',
`path` varchar(255) COMMENT 'Path',
`name` varchar(255) NOT NULL COMMENT 'snapshot name',