mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Update DataObjectInStore interface and unify implementation of
ImageDataFactory, VolumeDataFactory and SnapshotDataFactory implementations.
This commit is contained in:
parent
c74969fcb0
commit
fe3b01ece1
@ -44,66 +44,66 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
Long id;
|
||||
|
||||
|
||||
@Column(name="host_id")
|
||||
private long hostId;
|
||||
|
||||
|
||||
@Column(name="template_id")
|
||||
private long templateId;
|
||||
|
||||
|
||||
@Column(name=GenericDaoBase.CREATED_COLUMN)
|
||||
private Date created = null;
|
||||
|
||||
|
||||
@Column(name="last_updated")
|
||||
@Temporal(value=TemporalType.TIMESTAMP)
|
||||
private Date lastUpdated = null;
|
||||
|
||||
|
||||
@Column (name="download_pct")
|
||||
private int downloadPercent;
|
||||
|
||||
|
||||
@Column (name="size")
|
||||
private long size;
|
||||
|
||||
|
||||
@Column (name="physical_size")
|
||||
private long physicalSize;
|
||||
|
||||
|
||||
@Column (name="download_state")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status downloadState;
|
||||
|
||||
|
||||
@Column (name="local_path")
|
||||
private String localDownloadPath;
|
||||
|
||||
|
||||
@Column (name="error_str")
|
||||
private String errorString;
|
||||
|
||||
|
||||
@Column (name="job_id")
|
||||
private String jobId;
|
||||
|
||||
private String jobId;
|
||||
|
||||
@Column (name="install_path")
|
||||
private String installPath;
|
||||
|
||||
|
||||
@Column (name="url")
|
||||
private String downloadUrl;
|
||||
|
||||
@Column(name="is_copy")
|
||||
private boolean isCopy = false;
|
||||
|
||||
|
||||
@Column(name="destroyed")
|
||||
boolean destroyed = false;
|
||||
|
||||
|
||||
@Column(name="update_count", updatable = true, nullable=false)
|
||||
protected long updatedCount;
|
||||
|
||||
|
||||
@Column(name = "updated")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
Date updated;
|
||||
|
||||
|
||||
@Column(name = "state")
|
||||
@Enumerated(EnumType.STRING)
|
||||
ObjectInDataStoreStateMachine.State state;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getInstallPath() {
|
||||
return installPath;
|
||||
@ -156,12 +156,12 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
public Date getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setLastUpdated(Date date) {
|
||||
lastUpdated = date;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setInstallPath(String installPath) {
|
||||
this.installPath = installPath;
|
||||
@ -197,7 +197,7 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
}
|
||||
|
||||
protected VMTemplateHostVO() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -234,7 +234,7 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof VMTemplateHostVO) {
|
||||
VMTemplateHostVO other = (VMTemplateHostVO)obj;
|
||||
return (this.templateId==other.getTemplateId() && this.hostId==other.getHostId());
|
||||
return (this.templateId==other.getTemplateId() && this.hostId==other.getHostId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -253,8 +253,8 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setPhysicalSize(long physicalSize) {
|
||||
this.physicalSize = physicalSize;
|
||||
}
|
||||
@ -286,12 +286,12 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
public boolean isCopy() {
|
||||
return isCopy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getTemplateSize() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("TmplHost[").append(id).append("-").append(templateId).append("-").append(hostId).append(installPath).append("]").toString();
|
||||
@ -302,11 +302,11 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
// TODO Auto-generated method stub
|
||||
return this.state;
|
||||
}
|
||||
|
||||
|
||||
public long getUpdatedCount() {
|
||||
return this.updatedCount;
|
||||
}
|
||||
|
||||
|
||||
public void incrUpdatedCount() {
|
||||
this.updatedCount++;
|
||||
}
|
||||
@ -314,9 +314,20 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObj
|
||||
public void decrUpdatedCount() {
|
||||
this.updatedCount--;
|
||||
}
|
||||
|
||||
|
||||
public Date getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getObjectId() {
|
||||
return this.getTemplateId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataStoreId() {
|
||||
return this.getHostId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -45,32 +45,32 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
long id;
|
||||
|
||||
|
||||
@Column(name="pool_id")
|
||||
private long poolId;
|
||||
|
||||
|
||||
@Column(name="template_id") long templateId;
|
||||
|
||||
|
||||
@Column(name=GenericDaoBase.CREATED_COLUMN) Date created = null;
|
||||
|
||||
|
||||
@Column(name="last_updated")
|
||||
@Temporal(value=TemporalType.TIMESTAMP) Date lastUpdated = null;
|
||||
|
||||
|
||||
@Column (name="download_pct") int downloadPercent;
|
||||
|
||||
|
||||
@Column (name="download_state")
|
||||
@Enumerated(EnumType.STRING) Status downloadState;
|
||||
|
||||
|
||||
@Column (name="local_path") String localDownloadPath;
|
||||
|
||||
|
||||
@Column (name="error_str") String errorString;
|
||||
|
||||
|
||||
@Column (name="job_id") String jobId;
|
||||
|
||||
|
||||
@Column (name="install_path") String installPath;
|
||||
|
||||
|
||||
@Column (name="template_size") long templateSize;
|
||||
|
||||
|
||||
@Column (name="marked_for_gc") boolean markedForGC;
|
||||
|
||||
@Column(name="update_count", updatable = true, nullable=false)
|
||||
@ -88,7 +88,7 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
public String getInstallPath() {
|
||||
return installPath;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getTemplateSize() {
|
||||
return templateSize;
|
||||
@ -141,12 +141,12 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
public Date getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setLastUpdated(Date date) {
|
||||
lastUpdated = date;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setInstallPath(String installPath) {
|
||||
this.installPath = installPath;
|
||||
@ -184,7 +184,7 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
}
|
||||
|
||||
protected VMTemplateStoragePoolVO() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -216,15 +216,15 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
public String getJobId() {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
|
||||
public void setTemplateSize(long templateSize) {
|
||||
this.templateSize = templateSize;
|
||||
}
|
||||
|
||||
|
||||
public boolean getMarkedForGC() {
|
||||
return markedForGC;
|
||||
}
|
||||
|
||||
|
||||
public void setMarkedForGC(boolean markedForGC) {
|
||||
this.markedForGC = markedForGC;
|
||||
}
|
||||
@ -244,7 +244,7 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
Long hid = new Long(poolId);
|
||||
return tid.hashCode()+hid.hashCode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("TmplPool[").append(id).append("-").append(templateId).append("-").append("poolId").append("-").append(installPath).append("]").toString();
|
||||
@ -254,11 +254,11 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
public State getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
|
||||
public long getUpdatedCount() {
|
||||
return this.updatedCount;
|
||||
}
|
||||
|
||||
|
||||
public void incrUpdatedCount() {
|
||||
this.updatedCount++;
|
||||
}
|
||||
@ -266,10 +266,20 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
|
||||
public void decrUpdatedCount() {
|
||||
this.updatedCount--;
|
||||
}
|
||||
|
||||
|
||||
public Date getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getObjectId() {
|
||||
return this.getTemplateId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataStoreId() {
|
||||
return this.getPoolId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -47,71 +47,71 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
Long id;
|
||||
|
||||
|
||||
@Column(name="host_id")
|
||||
private long hostId;
|
||||
|
||||
|
||||
@Column(name="volume_id")
|
||||
private long volumeId;
|
||||
|
||||
|
||||
@Column(name="zone_id")
|
||||
private long zoneId;
|
||||
|
||||
|
||||
@Column(name=GenericDaoBase.CREATED_COLUMN)
|
||||
private Date created = null;
|
||||
|
||||
|
||||
@Column(name="last_updated")
|
||||
@Temporal(value=TemporalType.TIMESTAMP)
|
||||
private Date lastUpdated = null;
|
||||
|
||||
|
||||
@Column (name="download_pct")
|
||||
private int downloadPercent;
|
||||
|
||||
|
||||
@Column (name="size")
|
||||
private long size;
|
||||
|
||||
|
||||
@Column (name="physical_size")
|
||||
private long physicalSize;
|
||||
|
||||
|
||||
@Column (name="download_state")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status downloadState;
|
||||
|
||||
|
||||
@Column(name="checksum")
|
||||
private String checksum;
|
||||
|
||||
|
||||
@Column (name="local_path")
|
||||
private String localDownloadPath;
|
||||
|
||||
|
||||
@Column (name="error_str")
|
||||
private String errorString;
|
||||
|
||||
|
||||
@Column (name="job_id")
|
||||
private String jobId;
|
||||
|
||||
private String jobId;
|
||||
|
||||
@Column (name="install_path")
|
||||
private String installPath;
|
||||
|
||||
|
||||
@Column (name="url")
|
||||
private String downloadUrl;
|
||||
|
||||
|
||||
@Column(name="format")
|
||||
private Storage.ImageFormat format;
|
||||
|
||||
|
||||
@Column(name="destroyed")
|
||||
boolean destroyed = false;
|
||||
|
||||
|
||||
@Column(name="update_count", updatable = true, nullable=false)
|
||||
protected long updatedCount;
|
||||
|
||||
|
||||
@Column(name = "updated")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
Date updated;
|
||||
|
||||
|
||||
@Column(name = "state")
|
||||
@Enumerated(EnumType.STRING)
|
||||
ObjectInDataStoreStateMachine.State state;
|
||||
|
||||
|
||||
public String getInstallPath() {
|
||||
return installPath;
|
||||
}
|
||||
@ -124,17 +124,17 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getVolumeId() {
|
||||
return volumeId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setVolumeId(long volumeId) {
|
||||
this.volumeId = volumeId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
@ -147,42 +147,42 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
return downloadPercent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setDownloadPercent(int downloadPercent) {
|
||||
this.downloadPercent = downloadPercent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setDownloadState(Status downloadState) {
|
||||
this.downloadState = downloadState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setLastUpdated(Date date) {
|
||||
lastUpdated = date;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setInstallPath(String installPath) {
|
||||
this.installPath = installPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Status getDownloadState() {
|
||||
return downloadState;
|
||||
}
|
||||
@ -223,49 +223,49 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
}
|
||||
|
||||
protected VolumeHostVO() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLocalDownloadPath(String localPath) {
|
||||
this.localDownloadPath = localPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getLocalDownloadPath() {
|
||||
return localDownloadPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setErrorString(String errorString) {
|
||||
this.errorString = errorString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getErrorString() {
|
||||
return errorString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setJobId(String jobId) {
|
||||
this.jobId = jobId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getJobId() {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof VolumeHostVO) {
|
||||
VolumeHostVO other = (VolumeHostVO)obj;
|
||||
return (this.volumeId==other.getVolumeId() && this.hostId==other.getHostId());
|
||||
return (this.volumeId==other.getVolumeId() && this.hostId==other.getHostId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
Long tid = new Long(volumeId);
|
||||
Long hid = new Long(hostId);
|
||||
@ -279,8 +279,8 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setPhysicalSize(long physicalSize) {
|
||||
this.physicalSize = physicalSize;
|
||||
}
|
||||
@ -303,8 +303,8 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
|
||||
public String getDownloadUrl() {
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Storage.ImageFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
@ -316,16 +316,16 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
public long getVolumeSize() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String toString() {
|
||||
return new StringBuilder("VolumeHost[").append(id).append("-").append(volumeId).append("-").append(hostId).append(installPath).append("]").toString();
|
||||
}
|
||||
|
||||
|
||||
public long getUpdatedCount() {
|
||||
return this.updatedCount;
|
||||
}
|
||||
|
||||
|
||||
public void incrUpdatedCount() {
|
||||
this.updatedCount++;
|
||||
}
|
||||
@ -333,7 +333,7 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
public void decrUpdatedCount() {
|
||||
this.updatedCount--;
|
||||
}
|
||||
|
||||
|
||||
public Date getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
@ -344,4 +344,15 @@ public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getObjectId() {
|
||||
return this.getVolumeId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataStoreId() {
|
||||
return this.getHostId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -24,4 +24,6 @@ import com.cloud.utils.fsm.StateObject;
|
||||
public interface DataObjectInStore extends StateObject<ObjectInDataStoreStateMachine.State> {
|
||||
public String getInstallPath();
|
||||
public void setInstallPath(String path);
|
||||
public long getObjectId();
|
||||
public long getDataStoreId();
|
||||
}
|
||||
|
||||
@ -31,4 +31,12 @@ public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Lo
|
||||
public List<SnapshotDataStoreVO> listByStoreId(long id);
|
||||
|
||||
public void deletePrimaryRecordsForStore(long id);
|
||||
|
||||
public SnapshotDataStoreVO findByStoreSnapshot(long storeId, long snapshotId);
|
||||
|
||||
public SnapshotDataStoreVO findByStoreSnapshot(long storeId, long snapshotId, boolean lock);
|
||||
|
||||
public SnapshotDataStoreVO findBySnapshot(long snapshotId);
|
||||
|
||||
public List<SnapshotDataStoreVO> listDestroyed(long storeId);
|
||||
}
|
||||
|
||||
@ -95,6 +95,7 @@ public class SnapshotDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
return installPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataStoreId() {
|
||||
return dataStoreId;
|
||||
}
|
||||
@ -239,4 +240,10 @@ public class SnapshotDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
return this.state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getObjectId() {
|
||||
return this.getSnapshotId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -113,6 +113,7 @@ public class TemplateDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getDataStoreId() {
|
||||
return dataStoreId;
|
||||
}
|
||||
@ -313,4 +314,11 @@ public class TemplateDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
return updated;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getObjectId() {
|
||||
return this.getTemplateId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -32,7 +32,11 @@ public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>,
|
||||
|
||||
public void deletePrimaryRecordsForStore(long id);
|
||||
|
||||
public VolumeDataStoreVO findByVolumeId(long volumeId);
|
||||
public VolumeDataStoreVO findByVolume(long volumeId);
|
||||
|
||||
public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId);
|
||||
|
||||
public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId, boolean lock);
|
||||
|
||||
public List<VolumeDataStoreVO> listDestroyed(long storeId);
|
||||
}
|
||||
|
||||
@ -117,6 +117,7 @@ public class VolumeDataStoreVO implements StateObject<ObjectInDataStoreStateMach
|
||||
return installPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataStoreId() {
|
||||
return dataStoreId;
|
||||
}
|
||||
@ -345,4 +346,10 @@ public class VolumeDataStoreVO implements StateObject<ObjectInDataStoreStateMach
|
||||
return this.state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getObjectId() {
|
||||
return this.getVolumeId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -21,13 +21,10 @@ package org.apache.cloudstack.storage.image;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.TemplateObject;
|
||||
@ -47,8 +44,6 @@ public class ImageDataFactoryImpl implements ImageDataFactory {
|
||||
@Inject
|
||||
VMTemplateDao imageDataDao;
|
||||
@Inject
|
||||
ObjectInDataStoreManager objMap;
|
||||
@Inject
|
||||
DataStoreManager storeMgr;
|
||||
@Inject
|
||||
VMTemplatePoolDao templatePoolDao;
|
||||
@ -61,6 +56,7 @@ public class ImageDataFactoryImpl implements ImageDataFactory {
|
||||
TemplateObject tmpl = TemplateObject.getTemplate(templ, null);
|
||||
return tmpl;
|
||||
}
|
||||
// verify if the given input parameters are consistent with our db data.
|
||||
boolean found = false;
|
||||
if (store.getRole() == DataStoreRole.Primary) {
|
||||
VMTemplateStoragePoolVO templatePoolVO = templatePoolDao.findByPoolTemplate(store.getId(), templateId);
|
||||
@ -68,8 +64,8 @@ public class ImageDataFactoryImpl implements ImageDataFactory {
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
DataObjectInStore obj = objMap.findObject(templ.getId(), DataObjectType.TEMPLATE, store.getId(), store.getRole());
|
||||
if (obj != null) {
|
||||
TemplateDataStoreVO templateStoreVO = templateStoreDao.findByStoreTemplate(store.getId(), templateId);
|
||||
if (templateStoreVO != null) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
@ -82,8 +78,9 @@ public class ImageDataFactoryImpl implements ImageDataFactory {
|
||||
return tmpl;
|
||||
}
|
||||
|
||||
// NOTE that this method can only be used for get template information stored in secondary storage
|
||||
//TODO: this method is problematic, since one template can be stored in multiple image stores.
|
||||
// need to see if we can get rid of this method or change to plural format.
|
||||
// need to see if we can get rid of this method or change to plural format, or restrict to 1:1 mapping
|
||||
@Override
|
||||
public TemplateInfo getTemplate(long templateId) {
|
||||
VMTemplateVO templ = imageDataDao.findById(templateId);
|
||||
@ -94,6 +91,7 @@ public class ImageDataFactoryImpl implements ImageDataFactory {
|
||||
}
|
||||
return this.getTemplate(templateId, store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateInfo getTemplate(DataObject obj, DataStore store) {
|
||||
return this.getTemplate(obj.getId(), store);
|
||||
|
||||
@ -21,15 +21,14 @@ package org.apache.cloudstack.storage.snapshot;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
@ -43,7 +42,7 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
|
||||
@Inject
|
||||
SnapshotDao snapshotDao;
|
||||
@Inject
|
||||
ObjectInDataStoreManager objMap;
|
||||
SnapshotDataStoreDao snapshotStoreDao;
|
||||
@Inject
|
||||
DataStoreManager storeMgr;
|
||||
@Inject
|
||||
@ -51,19 +50,20 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
|
||||
@Override
|
||||
public SnapshotInfo getSnapshot(long snapshotId, DataStore store) {
|
||||
SnapshotVO snapshot = snapshotDao.findByIdIncludingRemoved(snapshotId);
|
||||
DataObjectInStore obj = objMap.findObject(snapshot.getId(), DataObjectType.SNAPSHOT, store.getId(), store.getRole());
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
|
||||
return so;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotInfo getSnapshot(long snapshotId) {
|
||||
SnapshotVO snapshot = snapshotDao.findByIdIncludingRemoved(snapshotId);
|
||||
SnapshotObject so = null;
|
||||
if (snapshot.getState() == Snapshot.State.BackedUp) {
|
||||
DataStore store = objMap.findStore(snapshot.getId(), DataObjectType.SNAPSHOT, DataStoreRole.Image);
|
||||
DataStore store = null;
|
||||
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshotId);
|
||||
if ( snapshotStore != null ){
|
||||
store = this.storeMgr.getDataStore(snapshotStore.getDataStoreId(), DataStoreRole.Image);
|
||||
}
|
||||
so = SnapshotObject.getSnapshotObject(snapshot, store);
|
||||
} else {
|
||||
VolumeInfo volume = this.volumeFactory.getVolume(snapshot.getVolumeId());
|
||||
|
||||
@ -218,20 +218,11 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {
|
||||
if (role == DataStoreRole.Image) {
|
||||
switch (type){
|
||||
case TEMPLATE:
|
||||
SearchCriteria<TemplateDataStoreVO> ts = templateDataStoreDao.createSearchCriteria();
|
||||
ts.addAnd("templateId", SearchCriteria.Op.EQ, objId);
|
||||
ts.addAnd("dataStoreId", SearchCriteria.Op.EQ, dataStoreId);
|
||||
vo = templateDataStoreDao.findOneBy(ts);
|
||||
vo = templateDataStoreDao.findByStoreTemplate(dataStoreId, objId);
|
||||
case SNAPSHOT:
|
||||
SearchCriteria<SnapshotDataStoreVO> ss = snapshotDataStoreDao.createSearchCriteria();
|
||||
ss.addAnd("snapshotId", SearchCriteria.Op.EQ, objId);
|
||||
ss.addAnd("dataStoreId", SearchCriteria.Op.EQ, objId);
|
||||
vo = snapshotDataStoreDao.findOneBy(ss);
|
||||
vo = snapshotDataStoreDao.findByStoreSnapshot(dataStoreId, objId);
|
||||
case VOLUME:
|
||||
SearchCriteria<VolumeDataStoreVO> vs = volumeDataStoreDao.createSearchCriteria();
|
||||
vs.addAnd("volumeId", SearchCriteria.Op.EQ, objId);
|
||||
vs.addAnd("dataStoreId", SearchCriteria.Op.EQ, objId);
|
||||
vo = volumeDataStoreDao.findOneBy(vs);
|
||||
vo = volumeDataStoreDao.findByStoreVolume(dataStoreId, objId);
|
||||
}
|
||||
} else if (type == DataObjectType.TEMPLATE && role == DataStoreRole.Primary) {
|
||||
vo = templatePoolDao.findByPoolTemplate(dataStoreId, objId);
|
||||
@ -255,13 +246,17 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {
|
||||
public DataStore findStore(long objId, DataObjectType type, DataStoreRole role) {
|
||||
DataStore store = null;
|
||||
if (role == DataStoreRole.Image) {
|
||||
SearchCriteriaService<ObjectInDataStoreVO, ObjectInDataStoreVO> sc = SearchCriteria2.create(ObjectInDataStoreVO.class);
|
||||
sc.addAnd(sc.getEntity().getDataStoreRole(), Op.EQ, role);
|
||||
sc.addAnd(sc.getEntity().getObjectId(), Op.EQ, objId);
|
||||
sc.addAnd(sc.getEntity().getObjectType(), Op.EQ, type);
|
||||
ObjectInDataStoreVO vo = sc.find();
|
||||
DataObjectInStore vo = null;
|
||||
switch (type){
|
||||
case TEMPLATE:
|
||||
vo = templateDataStoreDao.findByTemplate(objId);
|
||||
case SNAPSHOT:
|
||||
vo = snapshotDataStoreDao.findBySnapshot(objId);
|
||||
case VOLUME:
|
||||
vo = volumeDataStoreDao.findByVolume(objId);
|
||||
}
|
||||
if (vo != null) {
|
||||
store = this.storeMgr.getDataStore(vo.getDataStoreId(), vo.getDataStoreRole());
|
||||
store = this.storeMgr.getDataStore(vo.getDataStoreId(), DataStoreRole.Image);
|
||||
}
|
||||
}
|
||||
return store;
|
||||
|
||||
@ -48,14 +48,14 @@ public class ObjectInDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
|
||||
@Column(name = "datastore_id")
|
||||
private long dataStoreId;
|
||||
|
||||
|
||||
@Column(name = "datastore_role")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private DataStoreRole dataStoreRole;
|
||||
|
||||
@Column(name = "object_id")
|
||||
long objectId;
|
||||
|
||||
|
||||
@Column(name = "object_type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
DataObjectType objectType;
|
||||
@ -76,13 +76,13 @@ public class ObjectInDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
|
||||
@Column(name = "local_path")
|
||||
String localDownloadPath;
|
||||
|
||||
|
||||
@Column (name="url")
|
||||
private String downloadUrl;
|
||||
|
||||
|
||||
@Column(name="format")
|
||||
private Storage.ImageFormat format;
|
||||
|
||||
|
||||
@Column(name="checksum")
|
||||
private String checksum;
|
||||
|
||||
@ -97,46 +97,47 @@ public class ObjectInDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
|
||||
@Column(name = "size")
|
||||
Long size;
|
||||
|
||||
|
||||
@Column(name = "state")
|
||||
@Enumerated(EnumType.STRING)
|
||||
ObjectInDataStoreStateMachine.State state;
|
||||
|
||||
@Column(name="update_count", updatable = true, nullable=false)
|
||||
protected long updatedCount;
|
||||
|
||||
|
||||
@Column(name = "updated")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
Date updated;
|
||||
|
||||
|
||||
public ObjectInDataStoreVO() {
|
||||
this.state = ObjectInDataStoreStateMachine.State.Allocated;
|
||||
}
|
||||
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
public DataStoreRole getDataStoreRole() {
|
||||
return this.dataStoreRole;
|
||||
}
|
||||
|
||||
|
||||
public void setDataStoreRole(DataStoreRole role) {
|
||||
this.dataStoreRole = role;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getObjectId() {
|
||||
return this.objectId;
|
||||
}
|
||||
|
||||
|
||||
public void setObjectId(long id) {
|
||||
this.objectId = id;
|
||||
}
|
||||
|
||||
|
||||
public DataObjectType getObjectType() {
|
||||
return this.objectType;
|
||||
}
|
||||
|
||||
|
||||
public void setObjectType(DataObjectType type) {
|
||||
this.objectType = type;
|
||||
}
|
||||
@ -145,27 +146,27 @@ public class ObjectInDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
public ObjectInDataStoreStateMachine.State getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
|
||||
public void setInstallPath(String path) {
|
||||
this.installPath = path;
|
||||
}
|
||||
|
||||
|
||||
public String getInstallPath() {
|
||||
return this.installPath;
|
||||
}
|
||||
|
||||
|
||||
public void setSize(Long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
|
||||
public Long getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
|
||||
public long getUpdatedCount() {
|
||||
return this.updatedCount;
|
||||
}
|
||||
|
||||
|
||||
public void incrUpdatedCount() {
|
||||
this.updatedCount++;
|
||||
}
|
||||
@ -173,15 +174,16 @@ public class ObjectInDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
||||
public void decrUpdatedCount() {
|
||||
this.updatedCount--;
|
||||
}
|
||||
|
||||
|
||||
public Date getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataStoreId() {
|
||||
return dataStoreId;
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreState
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -42,6 +43,8 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
|
||||
private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreDaoImpl.class);
|
||||
private SearchBuilder<SnapshotDataStoreVO> updateStateSearch;
|
||||
private SearchBuilder<SnapshotDataStoreVO> storeSearch;
|
||||
private SearchBuilder<SnapshotDataStoreVO> snapshotSearch;
|
||||
private SearchBuilder<SnapshotDataStoreVO> storeSnapshotSearch;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
@ -57,6 +60,18 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
|
||||
updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
|
||||
updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
|
||||
updateStateSearch.done();
|
||||
|
||||
snapshotSearch = createSearchBuilder();
|
||||
snapshotSearch.and("snapshot_id", snapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
|
||||
snapshotSearch.and("destroyed", snapshotSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||
snapshotSearch.done();
|
||||
|
||||
storeSnapshotSearch = createSearchBuilder();
|
||||
storeSnapshotSearch.and("snapshot_id", storeSnapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
|
||||
storeSnapshotSearch.and("store_id", storeSnapshotSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
|
||||
storeSnapshotSearch.and("destroyed", storeSnapshotSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||
storeSnapshotSearch.done();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -116,6 +131,41 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotDataStoreVO findByStoreSnapshot(long storeId, long snapshotId) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = storeSnapshotSearch.create();
|
||||
sc.setParameters("store_id", storeId);
|
||||
sc.setParameters("snapshot_id", snapshotId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SnapshotDataStoreVO findByStoreSnapshot(long storeId, long snapshotId, boolean lock) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = storeSnapshotSearch.create();
|
||||
sc.setParameters("store_id", storeId);
|
||||
sc.setParameters("snapshot_id", snapshotId);
|
||||
sc.setParameters("destroyed", false);
|
||||
if (!lock)
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
else
|
||||
return lockOneRandomRow(sc, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotDataStoreVO findBySnapshot(long snapshotId) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = snapshotSearch.create();
|
||||
sc.setParameters("snapshot_id", snapshotId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotDataStoreVO> listDestroyed(long id) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
sc.setParameters("destroyed", true);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,12 +133,13 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
|
||||
|
||||
|
||||
@Override
|
||||
public VolumeDataStoreVO findByVolumeId(long volumeId) {
|
||||
public VolumeDataStoreVO findByVolume(long volumeId) {
|
||||
SearchCriteria<VolumeDataStoreVO> sc = volumeSearch.create();
|
||||
sc.setParameters("volume_id", volumeId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId) {
|
||||
SearchCriteria<VolumeDataStoreVO> sc = storeVolumeSearch.create();
|
||||
@ -148,5 +149,23 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId, boolean lock) {
|
||||
SearchCriteria<VolumeDataStoreVO> sc = storeVolumeSearch.create();
|
||||
sc.setParameters("store_id", storeId);
|
||||
sc.setParameters("volume_id", volumeId);
|
||||
sc.setParameters("destroyed", false);
|
||||
if (!lock)
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
else
|
||||
return lockOneRandomRow(sc, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeDataStoreVO> listDestroyed(long id) {
|
||||
SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
|
||||
sc.setParameters("store_id", id);
|
||||
sc.setParameters("destroyed", true);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,12 +21,12 @@ package org.apache.cloudstack.storage.volume;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
@ -38,24 +38,28 @@ public class VolumeDataFactoryImpl implements VolumeDataFactory {
|
||||
@Inject
|
||||
VolumeDao volumeDao;
|
||||
@Inject
|
||||
ObjectInDataStoreManager objMap;
|
||||
VolumeDataStoreDao volumeStoreDao;
|
||||
@Inject
|
||||
DataStoreManager storeMgr;
|
||||
@Override
|
||||
public VolumeInfo getVolume(long volumeId, DataStore store) {
|
||||
VolumeVO volumeVO = volumeDao.findById(volumeId);
|
||||
|
||||
|
||||
VolumeObject vol = VolumeObject.getVolumeObject(store, volumeVO);
|
||||
|
||||
|
||||
return vol;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VolumeInfo getVolume(long volumeId) {
|
||||
VolumeVO volumeVO = volumeDao.findById(volumeId);
|
||||
VolumeObject vol = null;
|
||||
if (volumeVO.getPoolId() == null) {
|
||||
DataStore store = objMap.findStore(volumeVO.getId(), DataObjectType.VOLUME, DataStoreRole.Image);
|
||||
DataStore store = null;
|
||||
VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
|
||||
if ( volumeStore != null ){
|
||||
store = this.storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
|
||||
}
|
||||
vol = VolumeObject.getVolumeObject(store, volumeVO);
|
||||
} else {
|
||||
DataStore store = this.storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
|
||||
|
||||
@ -774,7 +774,7 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
|
||||
if (volInfo.getSize() > 0) {
|
||||
try {
|
||||
String url = _volumeStoreDao.findByVolumeId(volume.getId()).getDownloadUrl();
|
||||
String url = _volumeStoreDao.findByVolume(volume.getId()).getDownloadUrl();
|
||||
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(volume.getAccountId()),
|
||||
com.cloud.configuration.Resource.ResourceType.secondary_storage,
|
||||
volInfo.getSize() - UriUtils.getRemoteSize(url));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user