mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
Remove almost all VMTemplateHostDao references except S3Manager and
SwiftManager.
This commit is contained in:
parent
7543f314a7
commit
0cfef3aa4e
@ -29,6 +29,7 @@ public interface DataStoreManager {
|
|||||||
public DataStore getPrimaryDataStore(long storeId);
|
public DataStore getPrimaryDataStore(long storeId);
|
||||||
public DataStore getDataStore(String uuid, DataStoreRole role);
|
public DataStore getDataStore(String uuid, DataStoreRole role);
|
||||||
public List<DataStore> getImageStoresByScope(ZoneScope scope);
|
public List<DataStore> getImageStoresByScope(ZoneScope scope);
|
||||||
|
public DataStore getImageStore(long zoneId);
|
||||||
public List<DataStore> getImageStoresByProvider(String provider);
|
public List<DataStore> getImageStoresByProvider(String provider);
|
||||||
public List<DataStore> getImageCacheStores(Scope scope);
|
public List<DataStore> getImageCacheStores(Scope scope);
|
||||||
public DataStore registerDataStore(Map<String, String> params, String providerUuid);
|
public DataStore registerDataStore(Map<String, String> params, String providerUuid);
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
|
|||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy;
|
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
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.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.DataStoreManager;
|
||||||
|
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||||
@ -38,6 +39,8 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
|||||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||||
|
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||||
|
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -124,7 +127,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
@Inject
|
@Inject
|
||||||
DataStoreManager dataStoreMgr;
|
DataStoreManager dataStoreMgr;
|
||||||
@Inject
|
@Inject
|
||||||
VMTemplateHostDao templateHostDao;
|
TemplateDataStoreDao templateStoreDao;
|
||||||
@Inject DiskOfferingDao diskOfferingDao;
|
@Inject DiskOfferingDao diskOfferingDao;
|
||||||
@Inject VMTemplatePoolDao templatePoolDao;
|
@Inject VMTemplatePoolDao templatePoolDao;
|
||||||
@Inject
|
@Inject
|
||||||
@ -399,7 +402,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
answer = copyFromSnapshot(srcData, destData);
|
answer = copyFromSnapshot(srcData, destData);
|
||||||
} else if (srcData.getType() == DataObjectType.SNAPSHOT
|
} else if (srcData.getType() == DataObjectType.SNAPSHOT
|
||||||
&& destData.getType() == DataObjectType.TEMPLATE) {
|
&& destData.getType() == DataObjectType.TEMPLATE) {
|
||||||
answer = createTemplateFromSnashot(srcData, destData);
|
answer = createTemplateFromSnapshot(srcData, destData);
|
||||||
} else if (srcData.getType() == DataObjectType.VOLUME
|
} else if (srcData.getType() == DataObjectType.VOLUME
|
||||||
&& destData.getType() == DataObjectType.TEMPLATE) {
|
&& destData.getType() == DataObjectType.TEMPLATE) {
|
||||||
answer = createTemplateFromVolume(srcData, destData);
|
answer = createTemplateFromVolume(srcData, destData);
|
||||||
@ -425,7 +428,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@DB
|
||||||
protected Answer createTemplateFromSnashot(DataObject srcData,
|
protected Answer createTemplateFromSnapshot(DataObject srcData,
|
||||||
DataObject destData) {
|
DataObject destData) {
|
||||||
long snapshotId = srcData.getId();
|
long snapshotId = srcData.getId();
|
||||||
SnapshotVO snapshot = snapshotDao.findById(snapshotId);
|
SnapshotVO snapshot = snapshotDao.findById(snapshotId);
|
||||||
@ -434,8 +437,11 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
+ srcData.getId());
|
+ srcData.getId());
|
||||||
}
|
}
|
||||||
Long zoneId = snapshot.getDataCenterId();
|
Long zoneId = snapshot.getDataCenterId();
|
||||||
|
DataStore secStore = destData.getDataStore();
|
||||||
|
/*
|
||||||
HostVO secondaryStorageHost = this.templateMgr
|
HostVO secondaryStorageHost = this.templateMgr
|
||||||
.getSecondaryStorageHost(zoneId);
|
.getSecondaryStorageHost(zoneId);
|
||||||
|
*/
|
||||||
String secondaryStorageURL = snapshotMgr
|
String secondaryStorageURL = snapshotMgr
|
||||||
.getSecondaryStorageURL(snapshot);
|
.getSecondaryStorageURL(snapshot);
|
||||||
VMTemplateVO template = this.templateDao.findById(destData.getId());
|
VMTemplateVO template = this.templateDao.findById(destData.getId());
|
||||||
@ -536,13 +542,12 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
origTemplateInstallPath, template.getId(), name,
|
origTemplateInstallPath, template.getId(), name,
|
||||||
_createprivatetemplatefromsnapshotwait);
|
_createprivatetemplatefromsnapshotwait);
|
||||||
|
|
||||||
return sendCommand(cmd, pool, template.getId(), dcId,
|
return sendCommand(cmd, pool, template.getId(), dcId, secStore);
|
||||||
secondaryStorageHost.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@DB
|
||||||
protected Answer sendCommand(Command cmd, StoragePool pool,
|
protected Answer sendCommand(Command cmd, StoragePool pool,
|
||||||
long templateId, long zoneId, long hostId) {
|
long templateId, long zoneId, DataStore secStore) {
|
||||||
|
|
||||||
CreatePrivateTemplateAnswer answer = null;
|
CreatePrivateTemplateAnswer answer = null;
|
||||||
try {
|
try {
|
||||||
@ -573,7 +578,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String checkSum = this.templateMgr
|
String checkSum = this.templateMgr
|
||||||
.getChecksum(hostId, answer.getPath());
|
.getChecksum(secStore, answer.getPath());
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
|
|
||||||
@ -584,7 +589,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
|
|
||||||
// add template zone ref for this template
|
// add template zone ref for this template
|
||||||
templateDao.addTemplateToZone(privateTemplate, zoneId);
|
templateDao.addTemplateToZone(privateTemplate, zoneId);
|
||||||
VMTemplateHostVO templateHostVO = new VMTemplateHostVO(hostId,
|
TemplateDataStoreVO templateHostVO = new TemplateDataStoreVO(secStore.getId(),
|
||||||
privateTemplate.getId());
|
privateTemplate.getId());
|
||||||
templateHostVO.setDownloadPercent(100);
|
templateHostVO.setDownloadPercent(100);
|
||||||
templateHostVO.setDownloadState(Status.DOWNLOADED);
|
templateHostVO.setDownloadState(Status.DOWNLOADED);
|
||||||
@ -592,7 +597,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
templateHostVO.setLastUpdated(new Date());
|
templateHostVO.setLastUpdated(new Date());
|
||||||
templateHostVO.setSize(answer.getVirtualSize());
|
templateHostVO.setSize(answer.getVirtualSize());
|
||||||
templateHostVO.setPhysicalSize(answer.getphysicalSize());
|
templateHostVO.setPhysicalSize(answer.getphysicalSize());
|
||||||
templateHostDao.persist(templateHostVO);
|
templateStoreDao.persist(templateHostVO);
|
||||||
txn.close();
|
txn.close();
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
@ -609,13 +614,8 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
|
|
||||||
String vmName = this.volumeMgr.getVmNameOnVolume(volume);
|
String vmName = this.volumeMgr.getVmNameOnVolume(volume);
|
||||||
Long zoneId = volume.getDataCenterId();
|
Long zoneId = volume.getDataCenterId();
|
||||||
HostVO secondaryStorageHost = this.templateMgr
|
DataStore secStore = destObj.getDataStore();
|
||||||
.getSecondaryStorageHost(zoneId);
|
String secondaryStorageURL = secStore.getUri();
|
||||||
if (secondaryStorageHost == null) {
|
|
||||||
throw new CloudRuntimeException(
|
|
||||||
"Can not find the secondary storage for zoneId " + zoneId);
|
|
||||||
}
|
|
||||||
String secondaryStorageURL = secondaryStorageHost.getStorageUrl();
|
|
||||||
VMTemplateVO template = this.templateDao.findById(destObj.getId());
|
VMTemplateVO template = this.templateDao.findById(destObj.getId());
|
||||||
StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(
|
StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(
|
||||||
volume.getPoolId(), DataStoreRole.Primary);
|
volume.getPoolId(), DataStoreRole.Primary);
|
||||||
@ -630,8 +630,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
template.getName(), template.getUniqueName(), volume.getPath(),
|
template.getName(), template.getUniqueName(), volume.getPath(),
|
||||||
vmName, _createprivatetemplatefromvolumewait);
|
vmName, _createprivatetemplatefromvolumewait);
|
||||||
|
|
||||||
return sendCommand(cmd, pool, template.getId(), zoneId,
|
return sendCommand(cmd, pool, template.getId(), zoneId, secStore);
|
||||||
secondaryStorageHost.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HostVO getSecHost(long volumeId, long dcId) {
|
private HostVO getSecHost(long volumeId, long dcId) {
|
||||||
|
|||||||
@ -33,6 +33,8 @@ import org.springframework.stereotype.Component;
|
|||||||
import com.cloud.storage.DataStoreRole;
|
import com.cloud.storage.DataStoreRole;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
|
||||||
|
import edu.emory.mathcs.backport.java.util.Collections;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DataStoreManagerImpl implements DataStoreManager {
|
public class DataStoreManagerImpl implements DataStoreManager {
|
||||||
@Inject
|
@Inject
|
||||||
@ -74,6 +76,17 @@ public class DataStoreManagerImpl implements DataStoreManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataStore getImageStore(long zoneId) {
|
||||||
|
List<DataStore> stores = getImageStoresByScope(new ZoneScope(zoneId));
|
||||||
|
if (stores == null || stores.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Collections.shuffle(stores);
|
||||||
|
return stores.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DataStore> getImageStoresByProvider(String provider) {
|
public List<DataStore> getImageStoresByProvider(String provider) {
|
||||||
return imageDataStoreMgr.listImageStoreByProvider(provider);
|
return imageDataStoreMgr.listImageStoreByProvider(provider);
|
||||||
|
|||||||
@ -18,8 +18,6 @@ package com.cloud.template;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
|
|
||||||
import org.apache.cloudstack.api.command.user.template.UpdateTemplateCmd;
|
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||||
@ -100,13 +98,8 @@ public interface TemplateManager extends TemplateApiService{
|
|||||||
|
|
||||||
String getSecondaryStorageURL(long zoneId);
|
String getSecondaryStorageURL(long zoneId);
|
||||||
|
|
||||||
//HostVO getSecondaryStorageHost(long zoneId, long tmpltId);
|
|
||||||
|
|
||||||
DataStore getImageStore(long zoneId, long tmpltId);
|
DataStore getImageStore(long zoneId, long tmpltId);
|
||||||
|
|
||||||
// VMTemplateHostVO getTemplateHostRef(long zoneId, long tmpltId,
|
|
||||||
// boolean readyOnly);
|
|
||||||
|
|
||||||
HostVO getSecondaryStorageHost(long zoneId);
|
HostVO getSecondaryStorageHost(long zoneId);
|
||||||
|
|
||||||
List<HostVO> getSecondaryStorageHosts(long zoneId);
|
List<HostVO> getSecondaryStorageHosts(long zoneId);
|
||||||
@ -115,8 +108,6 @@ public interface TemplateManager extends TemplateApiService{
|
|||||||
|
|
||||||
DataStore getImageStore(String storeUuid, Long zoneId);
|
DataStore getImageStore(String storeUuid, Long zoneId);
|
||||||
|
|
||||||
String getChecksum(Long hostId, String templatePath);
|
|
||||||
|
|
||||||
String getChecksum(DataStore store, String templatePath);
|
String getChecksum(DataStore store, String templatePath);
|
||||||
|
|
||||||
List<DataStore> getImageStoreByTemplate(long templateId, Long zoneId);
|
List<DataStore> getImageStoreByTemplate(long templateId, Long zoneId);
|
||||||
|
|||||||
@ -106,7 +106,6 @@ import com.cloud.exception.InvalidParameterValueException;
|
|||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.host.Host;
|
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
import com.cloud.host.dao.HostDao;
|
import com.cloud.host.dao.HostDao;
|
||||||
import com.cloud.hypervisor.Hypervisor;
|
import com.cloud.hypervisor.Hypervisor;
|
||||||
@ -647,24 +646,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChecksum(Long hostId, String templatePath) {
|
|
||||||
HostVO ssHost = _hostDao.findById(hostId);
|
|
||||||
Host.Type type = ssHost.getType();
|
|
||||||
if (type != Host.Type.SecondaryStorage
|
|
||||||
&& type != Host.Type.LocalSecondaryStorage) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String secUrl = ssHost.getStorageUrl();
|
|
||||||
Answer answer;
|
|
||||||
answer = _agentMgr.sendToSecStorage(ssHost, new ComputeChecksumCommand(
|
|
||||||
secUrl, templatePath));
|
|
||||||
if (answer != null && answer.getResult()) {
|
|
||||||
return answer.getDetails();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getChecksum(DataStore store, String templatePath) {
|
public String getChecksum(DataStore store, String templatePath) {
|
||||||
|
|
||||||
@ -1741,33 +1722,24 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSecondaryStorageURL(long zoneId) {
|
public String getSecondaryStorageURL(long zoneId) {
|
||||||
// Determine the secondary storage URL
|
DataStore secStore = this._dataStoreMgr.getImageStore(zoneId);
|
||||||
HostVO secondaryStorageHost = getSecondaryStorageHost(zoneId);
|
if (secStore == null) {
|
||||||
|
|
||||||
if (secondaryStorageHost == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return secondaryStorageHost.getStorageUrl();
|
return secStore.getUri();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the image store where a template in a given zone is downloaded to, just pick one is enough.
|
// get the image store where a template in a given zone is downloaded to, just pick one is enough.
|
||||||
@Override
|
@Override
|
||||||
public DataStore getImageStore(long zoneId, long tmpltId) {
|
public DataStore getImageStore(long zoneId, long tmpltId) {
|
||||||
List<DataStore> stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
TemplateDataStoreVO tmpltStore = this._tmplStoreDao.findByTemplateZoneDownloadStatus(tmpltId, zoneId, VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||||
if (stores == null || stores.size() == 0) {
|
if (tmpltStore != null){
|
||||||
return null;
|
return this._dataStoreMgr.getDataStore(tmpltStore.getDataStoreId(), DataStoreRole.Image);
|
||||||
}
|
|
||||||
for (DataStore host : stores) {
|
|
||||||
List<TemplateDataStoreVO> tmpltStore = this._tmplStoreDao.listByTemplateStoreDownloadStatus(
|
|
||||||
tmpltId, host.getId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
|
||||||
if ( tmpltStore != null && tmpltStore.size() > 0 ){
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user