Bug 7772: Add hypervisor type to snapshots table, fix issues with createVolumeFromSnapshot if snapshot was taken under data volume

This commit is contained in:
Kelven Yang 2010-12-29 21:52:06 -08:00
parent bd788b1827
commit e7749afdfe
6 changed files with 32 additions and 12 deletions

View File

@ -19,6 +19,8 @@
package com.cloud.storage;
import java.util.Date;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
public interface Snapshot {
public enum Type {
@ -59,5 +61,6 @@ public interface Snapshot {
String getName();
Date getCreated();
short getSnapshotType();
Status getStatus();
Status getStatus();
HypervisorType getHypervisorType();
}

View File

@ -31,6 +31,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.db.GenericDao;
import com.google.gson.annotations.Expose;
@ -79,10 +80,14 @@ public class SnapshotVO implements Snapshot {
@Column(name="prev_snap_id")
long prevSnapshotId;
@Column(name="hypervisor_type")
@Enumerated(value=EnumType.STRING)
HypervisorType hypervisorType;
public SnapshotVO() { }
public SnapshotVO(long id, long accountId, long volumeId, String path, String name, short snapshotType, String typeDescription) {
public SnapshotVO(long id, long accountId, long volumeId, String path, String name, short snapshotType, String typeDescription, HypervisorType hypervisorType) {
this.id = id;
this.accountId = accountId;
this.volumeId = volumeId;
@ -91,7 +96,8 @@ public class SnapshotVO implements Snapshot {
this.snapshotType = snapshotType;
this.typeDescription = typeDescription;
this.status = Status.Creating;
this.prevSnapshotId = 0;
this.prevSnapshotId = 0;
this.hypervisorType = hypervisorType;
}
@Override
@ -126,7 +132,13 @@ public class SnapshotVO implements Snapshot {
@Override
public short getSnapshotType() {
return snapshotType;
}
}
@Override
public HypervisorType getHypervisorType() {
return hypervisorType;
}
public void setSnapshotType(short snapshotType) {
this.snapshotType = snapshotType;
}

View File

@ -546,7 +546,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
@DB
protected Pair<VolumeVO, String> createVolumeFromSnapshot(VolumeVO volume, SnapshotVO snapshot, VMTemplateVO template, long virtualsize) {
protected Pair<VolumeVO, String> createVolumeFromSnapshot(VolumeVO volume, SnapshotVO snapshot, long virtualsize) {
VolumeVO createdVolume = null;
Long volumeId = volume.getId();
@ -565,7 +565,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
DataCenterVO dc = _dcDao.findById(volume.getDataCenterId());
DiskProfile dskCh = new DiskProfile(volume, diskOffering, template.getHypervisorType());
DiskProfile dskCh = new DiskProfile(volume, diskOffering, snapshot.getHypervisorType());
int retry = 0;
// Determine what pod to store the volume in
@ -658,7 +658,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
template = _templateDao.findById(originalVolume.getTemplateId());
}
Pair<VolumeVO, String> volumeDetails = createVolumeFromSnapshot(volume, snapshot, template, originalVolume.getSize());
Pair<VolumeVO, String> volumeDetails = createVolumeFromSnapshot(volume, snapshot, originalVolume.getSize());
createdVolume = volumeDetails.first();
Transaction txn = Transaction.currentTxn();

View File

@ -231,8 +231,9 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
// Create the Snapshot object and save it so we can return it to the
// user
Type snapshotType = SnapshotVO.getSnapshotType(policyId);
HypervisorType hypervisorType = this._volsDao.getHypervisorType(volumeId);
SnapshotVO snapshotVO = new SnapshotVO(snapshotId, volume.getAccountId(), volume.getId(), null, snapshotName,
(short) snapshotType.ordinal(), snapshotType.name());
(short) snapshotType.ordinal(), snapshotType.name(), hypervisorType);
snapshotVO = _snapshotDao.persist(snapshotVO);
id = snapshotVO.getId();
assert id != null;

View File

@ -1844,7 +1844,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
// Specify RAW format makes it unusable for snapshots.
privateTemplate.setFormat(ImageFormat.RAW);
}
if(snapshot != null)
privateTemplate.setHypervisorType(snapshot.getHypervisorType());
_templateDao.update(templateId, privateTemplate);
// add template zone ref for this template

View File

@ -228,7 +228,7 @@ CREATE TABLE `cloud`.`cluster` (
`guid` varchar(255) UNIQUE DEFAULT NULL COMMENT 'guid for the cluster',
`pod_id` bigint unsigned NOT NULL COMMENT 'pod id',
`data_center_id` bigint unsigned NOT NULL COMMENT 'data center id',
`hypervisor_type` varchar(255),
`hypervisor_type` varchar(32),
`cluster_type` varchar(64) DEFAULT 'CloudManaged',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -361,6 +361,7 @@ CREATE TABLE `cloud`.`snapshots` (
`removed` datetime COMMENT 'Date removed. not null if removed',
`backup_snap_id` varchar(255) COMMENT 'Back up uuid of the snapshot',
`prev_snap_id` bigint unsigned COMMENT 'Id of the most recent snapshot',
`hypervisor_type` varchar(32) NOT NULL COMMENT 'hypervisor that the snapshot was taken under',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -693,7 +694,7 @@ CREATE TABLE `cloud`.`vm_template` (
`prepopulate` int(1) unsigned NOT NULL default 0 COMMENT 'prepopulate this template to primary storage',
`cross_zones` int(1) unsigned NOT NULL default 0 COMMENT 'Make this template available in all zones',
`extractable` int(1) unsigned NOT NULL default 1 COMMENT 'Is this template extractable',
`hypervisor_type` varchar(255) COMMENT 'hypervisor that the template is belonged to',
`hypervisor_type` varchar(32) COMMENT 'hypervisor that the template is belonged to',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -1144,7 +1145,7 @@ CREATE TABLE `cloud`.`guest_os` (
CREATE TABLE `cloud`.`guest_os_hypervisor` (
`id` bigint unsigned NOT NULL auto_increment,
`hypervisor_type` varchar(255) NOT NULL,
`hypervisor_type` varchar(32) NOT NULL,
`guest_os_name` varchar(255) NOT NULL,
`guest_os_id` bigint unsigned NOT NULL,
PRIMARY KEY (`id`)