mirror of https://github.com/apache/cloudstack.git
Incremental checkin for volume lineage
This commit is contained in:
parent
27b038efcb
commit
7454f0f24a
|
|
@ -37,6 +37,9 @@ public interface Volume extends PartOf, OwnedBy, BasedOn {
|
|||
Destroyed
|
||||
}
|
||||
|
||||
enum SourceType {
|
||||
Snapshot,DiskOffering,Template,Blank
|
||||
}
|
||||
/**
|
||||
* @return the volume name
|
||||
*/
|
||||
|
|
@ -75,4 +78,12 @@ public interface Volume extends PartOf, OwnedBy, BasedOn {
|
|||
Long getPoolId();
|
||||
|
||||
State getState();
|
||||
|
||||
SourceType getSourceType();
|
||||
|
||||
void setSourceType(SourceType sourceType);
|
||||
|
||||
void setSourceId(Long sourceId);
|
||||
|
||||
Long getSourceId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
|
|||
String path = rootdiskFolder + File.separator + "rootdisk";
|
||||
long totalSize = getVolumeSize(path);
|
||||
|
||||
VolumeVO vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), rootdiskFolder, path, totalSize, Volume.VolumeType.ROOT);
|
||||
VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), rootdiskFolder, path, totalSize, Volume.VolumeType.ROOT);
|
||||
vols.add(vol);
|
||||
|
||||
// Get the datadisk volume
|
||||
|
|
@ -203,7 +203,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
|
|||
path = datadiskFolder + File.separator + datadiskName;
|
||||
totalSize = getVolumeSize(path);
|
||||
|
||||
vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), datadiskFolder, path, totalSize, Volume.VolumeType.DATADISK);
|
||||
vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), datadiskFolder, path, totalSize, Volume.VolumeType.DATADISK);
|
||||
vols.add(vol);
|
||||
}
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
|
|||
String path = getVolumeName(imagePath, null);
|
||||
long totalSize = getVolumeSize(path);
|
||||
|
||||
VolumeVO vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.ROOT);
|
||||
VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.ROOT);
|
||||
|
||||
vols.add(vol);
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
|
|||
totalSize = getVolumeSize(path);
|
||||
|
||||
|
||||
vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.DATADISK);
|
||||
vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.DATADISK);
|
||||
vols.add(vol);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,13 @@ public class VolumeVO implements Volume {
|
|||
@Enumerated(value=EnumType.STRING)
|
||||
private State state;
|
||||
|
||||
@Column(name="source_type")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
Volume.SourceType sourceType;
|
||||
|
||||
@Column(name="source_id")
|
||||
Long sourceId;
|
||||
|
||||
/**
|
||||
* Constructor for data disk.
|
||||
* @param type
|
||||
|
|
@ -178,8 +185,7 @@ public class VolumeVO implements Volume {
|
|||
}
|
||||
|
||||
// Real Constructor
|
||||
public VolumeVO(long id, VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
|
||||
this.id = id;
|
||||
public VolumeVO(VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
|
||||
this.volumeType = type;
|
||||
this.name = name;
|
||||
this.dataCenterId = dcId;
|
||||
|
|
@ -212,8 +218,7 @@ public class VolumeVO implements Volume {
|
|||
}
|
||||
|
||||
|
||||
public VolumeVO(Long id, String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.VolumeType vType) {
|
||||
this.id = id;
|
||||
public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.VolumeType vType) {
|
||||
this.name = name;
|
||||
this.accountId = accountId;
|
||||
this.domainId = domainId;
|
||||
|
|
@ -510,4 +515,24 @@ public class VolumeVO implements Volume {
|
|||
public String toString() {
|
||||
return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceType getSourceType() {
|
||||
return this.sourceType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSourceType(SourceType sourceType) {
|
||||
this.sourceType = sourceType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSourceId(Long sourceId){
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSourceId(){
|
||||
return this.sourceId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ import com.cloud.service.dao.ServiceOfferingDao;
|
|||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.Volume.MirrorState;
|
||||
import com.cloud.storage.Volume.SourceType;
|
||||
import com.cloud.storage.Volume.VolumeType;
|
||||
import com.cloud.storage.allocator.StoragePoolAllocator;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
|
|
@ -233,7 +234,7 @@ public class StorageManagerImpl implements StorageManager {
|
|||
long deviceId = 0;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
rootVol = new VolumeVO(rootDisk.getVolumeId(), VolumeType.ROOT, rootDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize());
|
||||
rootVol = new VolumeVO(VolumeType.ROOT, rootDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize());
|
||||
if (rootDisk.getTemplateId() != null) {
|
||||
rootVol.setTemplateId(rootDisk.getTemplateId());
|
||||
}
|
||||
|
|
@ -242,7 +243,7 @@ public class StorageManagerImpl implements StorageManager {
|
|||
rootVol = _volsDao.persist(rootVol);
|
||||
vols.add(rootVol);
|
||||
for (DiskCharacteristics dataDisk : dataDisks) {
|
||||
dataVol = new VolumeVO(dataDisk.getVolumeId(), VolumeType.DATADISK, dataDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize());
|
||||
dataVol = new VolumeVO(VolumeType.DATADISK, dataDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize());
|
||||
dataVol.setDeviceId(deviceId++);
|
||||
dataVol.setInstanceId(vm.getId());
|
||||
dataVol = _volsDao.persist(dataVol);
|
||||
|
|
@ -484,7 +485,7 @@ public class StorageManagerImpl implements StorageManager {
|
|||
|
||||
// Create the Volume object and save it so that we can return it to the user
|
||||
Account account = _accountDao.findById(accountId);
|
||||
VolumeVO volume = new VolumeVO(null, userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK);
|
||||
VolumeVO volume = new VolumeVO(userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK);
|
||||
volume.setPoolId(null);
|
||||
volume.setDataCenterId(dc.getId());
|
||||
volume.setPodId(null);
|
||||
|
|
@ -499,6 +500,8 @@ public class StorageManagerImpl implements StorageManager {
|
|||
volume.setInstanceId(null);
|
||||
volume.setUpdated(new Date());
|
||||
volume.setStatus(AsyncInstanceCreateStatus.Creating);
|
||||
volume.setSourceType(SourceType.Snapshot);
|
||||
volume.setSourceId(snapshot.getId());
|
||||
volume = _volsDao.persist(volume);
|
||||
volumeId = volume.getId();
|
||||
|
||||
|
|
@ -853,18 +856,24 @@ public class StorageManagerImpl implements StorageManager {
|
|||
if (Storage.ImageFormat.ISO == template.getFormat()) {
|
||||
rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(),(size>0)? size : diskOffering.getDiskSizeInBytes());
|
||||
rootVol.setDiskOfferingId(diskOffering.getId());
|
||||
rootVol.setSourceType(SourceType.Template);
|
||||
rootVol.setSourceId(template.getId());
|
||||
rootVol.setDeviceId(0l);
|
||||
rootVol = _volsDao.persist(rootVol);
|
||||
} else {
|
||||
rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), template.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), offering.isRecreatable());
|
||||
rootVol.setDiskOfferingId(offering.getId());
|
||||
rootVol.setTemplateId(template.getId());
|
||||
rootVol.setSourceId(template.getId());
|
||||
rootVol.setSourceType(SourceType.Template);
|
||||
rootVol.setDeviceId(0l);
|
||||
rootVol = _volsDao.persist(rootVol);
|
||||
|
||||
if (diskOffering != null && diskOffering.getDiskSizeInBytes() > 0) {
|
||||
dataVol = new VolumeVO(VolumeType.DATADISK, vm.getId(), vm.getInstanceName() + "-DATA", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), (size>0)? size : diskOffering.getDiskSizeInBytes());
|
||||
dataVol.setDiskOfferingId(diskOffering.getId());
|
||||
dataVol.setSourceType(SourceType.DiskOffering);
|
||||
dataVol.setSourceId(diskOffering.getId());
|
||||
dataVol.setDeviceId(1l);
|
||||
dataVol = _volsDao.persist(dataVol);
|
||||
}
|
||||
|
|
@ -1572,7 +1581,7 @@ public class StorageManagerImpl implements StorageManager {
|
|||
|
||||
// Create the Volume object and save it so that we can return it to the user
|
||||
Account account = _accountDao.findById(accountId);
|
||||
VolumeVO volume = new VolumeVO(null, userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK);
|
||||
VolumeVO volume = new VolumeVO(userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK);
|
||||
volume.setPoolId(null);
|
||||
volume.setDataCenterId(dc.getId());
|
||||
volume.setPodId(null);
|
||||
|
|
@ -1585,6 +1594,8 @@ public class StorageManagerImpl implements StorageManager {
|
|||
volume.setUpdated(new Date());
|
||||
volume.setStatus(AsyncInstanceCreateStatus.Creating);
|
||||
volume.setDomainId(account.getDomainId());
|
||||
volume.setSourceId(diskOffering.getId());
|
||||
volume.setSourceType(SourceType.DiskOffering);
|
||||
volume = _volsDao.persist(volume);
|
||||
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
|
|
|
|||
|
|
@ -250,6 +250,8 @@ CREATE TABLE `cloud`.`volumes` (
|
|||
`removed` datetime COMMENT 'Date removed. not null if removed',
|
||||
`status` varchar(32) COMMENT 'Async API volume creation status',
|
||||
`state` varchar(32) COMMENT 'State machine',
|
||||
`source_id` bigint unsigned COMMENT 'id for the source',
|
||||
`source_type` varchar(32) COMMENT 'source from which the volume is created -- snapshot, diskoffering, template, blank',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue