mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 18:12:35 +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 getDataStore(String uuid, DataStoreRole role);
|
||||
public List<DataStore> getImageStoresByScope(ZoneScope scope);
|
||||
public DataStore getImageStore(long zoneId);
|
||||
public List<DataStore> getImageStoresByProvider(String provider);
|
||||
public List<DataStore> getImageCacheStores(Scope scope);
|
||||
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.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.EndPoint;
|
||||
@ -38,6 +39,8 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
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.springframework.stereotype.Component;
|
||||
|
||||
@ -124,7 +127,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
@Inject
|
||||
DataStoreManager dataStoreMgr;
|
||||
@Inject
|
||||
VMTemplateHostDao templateHostDao;
|
||||
TemplateDataStoreDao templateStoreDao;
|
||||
@Inject DiskOfferingDao diskOfferingDao;
|
||||
@Inject VMTemplatePoolDao templatePoolDao;
|
||||
@Inject
|
||||
@ -319,7 +322,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
protected Answer cloneVolume(DataObject template, DataObject volume) {
|
||||
CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0);
|
||||
StoragePool pool = (StoragePool)volume.getDataStore();
|
||||
|
||||
|
||||
try {
|
||||
Answer answer = storageMgr.sendToPool(pool, null, cmd);
|
||||
return answer;
|
||||
@ -399,7 +402,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
answer = copyFromSnapshot(srcData, destData);
|
||||
} else if (srcData.getType() == DataObjectType.SNAPSHOT
|
||||
&& destData.getType() == DataObjectType.TEMPLATE) {
|
||||
answer = createTemplateFromSnashot(srcData, destData);
|
||||
answer = createTemplateFromSnapshot(srcData, destData);
|
||||
} else if (srcData.getType() == DataObjectType.VOLUME
|
||||
&& destData.getType() == DataObjectType.TEMPLATE) {
|
||||
answer = createTemplateFromVolume(srcData, destData);
|
||||
@ -425,7 +428,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
}
|
||||
|
||||
@DB
|
||||
protected Answer createTemplateFromSnashot(DataObject srcData,
|
||||
protected Answer createTemplateFromSnapshot(DataObject srcData,
|
||||
DataObject destData) {
|
||||
long snapshotId = srcData.getId();
|
||||
SnapshotVO snapshot = snapshotDao.findById(snapshotId);
|
||||
@ -434,8 +437,11 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
+ srcData.getId());
|
||||
}
|
||||
Long zoneId = snapshot.getDataCenterId();
|
||||
DataStore secStore = destData.getDataStore();
|
||||
/*
|
||||
HostVO secondaryStorageHost = this.templateMgr
|
||||
.getSecondaryStorageHost(zoneId);
|
||||
*/
|
||||
String secondaryStorageURL = snapshotMgr
|
||||
.getSecondaryStorageURL(snapshot);
|
||||
VMTemplateVO template = this.templateDao.findById(destData.getId());
|
||||
@ -536,13 +542,12 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
origTemplateInstallPath, template.getId(), name,
|
||||
_createprivatetemplatefromsnapshotwait);
|
||||
|
||||
return sendCommand(cmd, pool, template.getId(), dcId,
|
||||
secondaryStorageHost.getId());
|
||||
return sendCommand(cmd, pool, template.getId(), dcId, secStore);
|
||||
}
|
||||
|
||||
@DB
|
||||
protected Answer sendCommand(Command cmd, StoragePool pool,
|
||||
long templateId, long zoneId, long hostId) {
|
||||
long templateId, long zoneId, DataStore secStore) {
|
||||
|
||||
CreatePrivateTemplateAnswer answer = null;
|
||||
try {
|
||||
@ -573,7 +578,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
}
|
||||
|
||||
String checkSum = this.templateMgr
|
||||
.getChecksum(hostId, answer.getPath());
|
||||
.getChecksum(secStore, answer.getPath());
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
@ -584,7 +589,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
|
||||
// add template zone ref for this template
|
||||
templateDao.addTemplateToZone(privateTemplate, zoneId);
|
||||
VMTemplateHostVO templateHostVO = new VMTemplateHostVO(hostId,
|
||||
TemplateDataStoreVO templateHostVO = new TemplateDataStoreVO(secStore.getId(),
|
||||
privateTemplate.getId());
|
||||
templateHostVO.setDownloadPercent(100);
|
||||
templateHostVO.setDownloadState(Status.DOWNLOADED);
|
||||
@ -592,7 +597,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
templateHostVO.setLastUpdated(new Date());
|
||||
templateHostVO.setSize(answer.getVirtualSize());
|
||||
templateHostVO.setPhysicalSize(answer.getphysicalSize());
|
||||
templateHostDao.persist(templateHostVO);
|
||||
templateStoreDao.persist(templateHostVO);
|
||||
txn.close();
|
||||
return answer;
|
||||
}
|
||||
@ -609,13 +614,8 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
|
||||
String vmName = this.volumeMgr.getVmNameOnVolume(volume);
|
||||
Long zoneId = volume.getDataCenterId();
|
||||
HostVO secondaryStorageHost = this.templateMgr
|
||||
.getSecondaryStorageHost(zoneId);
|
||||
if (secondaryStorageHost == null) {
|
||||
throw new CloudRuntimeException(
|
||||
"Can not find the secondary storage for zoneId " + zoneId);
|
||||
}
|
||||
String secondaryStorageURL = secondaryStorageHost.getStorageUrl();
|
||||
DataStore secStore = destObj.getDataStore();
|
||||
String secondaryStorageURL = secStore.getUri();
|
||||
VMTemplateVO template = this.templateDao.findById(destObj.getId());
|
||||
StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(
|
||||
volume.getPoolId(), DataStoreRole.Primary);
|
||||
@ -630,8 +630,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
template.getName(), template.getUniqueName(), volume.getPath(),
|
||||
vmName, _createprivatetemplatefromvolumewait);
|
||||
|
||||
return sendCommand(cmd, pool, template.getId(), zoneId,
|
||||
secondaryStorageHost.getId());
|
||||
return sendCommand(cmd, pool, template.getId(), zoneId, secStore);
|
||||
}
|
||||
|
||||
private HostVO getSecHost(long volumeId, long dcId) {
|
||||
|
||||
@ -33,6 +33,8 @@ import org.springframework.stereotype.Component;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
||||
@Component
|
||||
public class DataStoreManagerImpl implements DataStoreManager {
|
||||
@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
|
||||
public List<DataStore> getImageStoresByProvider(String provider) {
|
||||
return imageDataStoreMgr.listImageStoreByProvider(provider);
|
||||
|
||||
@ -18,8 +18,6 @@ package com.cloud.template;
|
||||
|
||||
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.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
@ -100,13 +98,8 @@ public interface TemplateManager extends TemplateApiService{
|
||||
|
||||
String getSecondaryStorageURL(long zoneId);
|
||||
|
||||
//HostVO getSecondaryStorageHost(long zoneId, long tmpltId);
|
||||
|
||||
DataStore getImageStore(long zoneId, long tmpltId);
|
||||
|
||||
// VMTemplateHostVO getTemplateHostRef(long zoneId, long tmpltId,
|
||||
// boolean readyOnly);
|
||||
|
||||
HostVO getSecondaryStorageHost(long zoneId);
|
||||
|
||||
List<HostVO> getSecondaryStorageHosts(long zoneId);
|
||||
@ -115,8 +108,6 @@ public interface TemplateManager extends TemplateApiService{
|
||||
|
||||
DataStore getImageStore(String storeUuid, Long zoneId);
|
||||
|
||||
String getChecksum(Long hostId, String templatePath);
|
||||
|
||||
String getChecksum(DataStore store, String templatePath);
|
||||
|
||||
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.ResourceAllocationException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
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
|
||||
public String getChecksum(DataStore store, String templatePath) {
|
||||
|
||||
@ -1741,35 +1722,26 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
|
||||
@Override
|
||||
public String getSecondaryStorageURL(long zoneId) {
|
||||
// Determine the secondary storage URL
|
||||
HostVO secondaryStorageHost = getSecondaryStorageHost(zoneId);
|
||||
|
||||
if (secondaryStorageHost == null) {
|
||||
DataStore secStore = this._dataStoreMgr.getImageStore(zoneId);
|
||||
if (secStore == 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.
|
||||
@Override
|
||||
public DataStore getImageStore(long zoneId, long tmpltId) {
|
||||
List<DataStore> stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
||||
if (stores == null || stores.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
for (DataStore host : stores) {
|
||||
List<TemplateDataStoreVO> tmpltStore = this._tmplStoreDao.listByTemplateStoreDownloadStatus(
|
||||
tmpltId, host.getId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
if ( tmpltStore != null && tmpltStore.size() > 0 ){
|
||||
return host;
|
||||
}
|
||||
TemplateDataStoreVO tmpltStore = this._tmplStoreDao.findByTemplateZoneDownloadStatus(tmpltId, zoneId, VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
if (tmpltStore != null){
|
||||
return this._dataStoreMgr.getDataStore(tmpltStore.getDataStoreId(), DataStoreRole.Image);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public HostVO getSecondaryStorageHost(long zoneId) {
|
||||
List<HostVO> hosts = _ssvmMgr
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user