Delete cache entries of template, snapshot, and volume when

deleteTemplate, deleteSnapshot, deleteVolume are invoked.
This commit is contained in:
Min Chen 2013-10-23 14:05:05 -07:00
parent 184e53940a
commit 730832d8fa
21 changed files with 181 additions and 33 deletions

View File

@ -19,6 +19,7 @@
package org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.List;
import com.cloud.storage.DataStoreRole;
public interface DataStoreManager {
@ -37,4 +38,6 @@ public interface DataStoreManager {
DataStore getImageCacheStore(long zoneId);
List<DataStore> listImageStores();
List<DataStore> listImageCacheStores();
}

View File

@ -18,6 +18,8 @@
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.List;
import com.cloud.storage.DataStoreRole;
public interface SnapshotDataFactory {
@ -26,4 +28,6 @@ public interface SnapshotDataFactory {
SnapshotInfo getSnapshot(DataObject obj, DataStore store);
SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role);
List<SnapshotInfo> listSnapshotOnCache(long snapshotId);
}

View File

@ -18,6 +18,8 @@
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.List;
import com.cloud.storage.DataStoreRole;
public interface TemplateDataFactory {
@ -30,4 +32,6 @@ public interface TemplateDataFactory {
TemplateInfo getTemplate(long templateId, DataStoreRole storeRole, Long zoneId);
TemplateInfo getReadyTemplateOnCache(long templateId);
List<TemplateInfo> listTemplateOnCache(long templateId);
}

View File

@ -18,6 +18,8 @@
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.List;
import com.cloud.storage.DataStoreRole;
public interface VolumeDataFactory {
@ -28,4 +30,6 @@ public interface VolumeDataFactory {
VolumeInfo getVolume(long volumeId, DataStoreRole storeRole);
VolumeInfo getVolume(long volumeId);
List<VolumeInfo> listVolumeOnCache(long volumeId);
}

View File

@ -36,4 +36,6 @@ public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
List<ImageStoreVO> findImageCacheByScope(ZoneScope scope);
List<ImageStoreVO> listImageStores();
List<ImageStoreVO> listImageCacheStores();
}

View File

@ -43,4 +43,6 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId);
void duplicateCacheRecordsOnRegionStore(long storeId);
List<SnapshotDataStoreVO> listOnCache(long snapshotId);
}

View File

@ -66,4 +66,6 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
void duplicateCacheRecordsOnRegionStore(long storeId);
TemplateDataStoreVO findReadyOnCache(long templateId);
List<TemplateDataStoreVO> listOnCache(long templateId);
}

View File

@ -18,6 +18,9 @@
*/
package org.apache.cloudstack.storage.image;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.apache.log4j.Logger;
@ -127,4 +130,17 @@ public class TemplateDataFactoryImpl implements TemplateDataFactory {
}
@Override
public List<TemplateInfo> listTemplateOnCache(long templateId) {
List<TemplateDataStoreVO> cacheTmpls = templateStoreDao.listOnCache(templateId);
List<TemplateInfo> tmplObjs = new ArrayList<TemplateInfo>();
for (TemplateDataStoreVO cacheTmpl : cacheTmpls) {
long storeId = cacheTmpl.getDataStoreId();
DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
TemplateInfo tmplObj = getTemplate(templateId, store);
tmplObjs.add(tmplObj);
}
return tmplObjs;
}
}

View File

@ -26,6 +26,9 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider;
@ -37,8 +40,6 @@ import org.apache.cloudstack.storage.image.ImageStoreDriver;
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.storage.ScopeType;
import com.cloud.storage.dao.VMTemplateDao;
@ -94,6 +95,16 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager
return imageStores;
}
@Override
public List<DataStore> listImageCacheStores() {
List<ImageStoreVO> stores = dataStoreDao.listImageCacheStores();
List<DataStore> imageStores = new ArrayList<DataStore>();
for (ImageStoreVO store : stores) {
imageStores.add(getImageStore(store.getId()));
}
return imageStores;
}
@Override
public List<DataStore> listImageStoresByScope(ZoneScope scope) {
List<ImageStoreVO> stores = dataStoreDao.findByScope(scope);

View File

@ -18,8 +18,13 @@
*/
package org.apache.cloudstack.storage.snapshot;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@ -28,7 +33,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
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;
import com.cloud.storage.SnapshotVO;
@ -70,8 +74,22 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
if (snapshotStore == null) {
return null;
}
DataStore store = this.storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
DataStore store = storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
return so;
}
@Override
public List<SnapshotInfo> listSnapshotOnCache(long snapshotId) {
List<SnapshotDataStoreVO> cacheSnapshots = snapshotStoreDao.listOnCache(snapshotId);
List<SnapshotInfo> snapObjs = new ArrayList<SnapshotInfo>();
for (SnapshotDataStoreVO cacheSnap : cacheSnapshots) {
long storeId = cacheSnap.getDataStoreId();
DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
SnapshotInfo tmplObj = getSnapshot(snapshotId, store);
snapObjs.add(tmplObj);
}
return snapObjs;
}
}

View File

@ -16,8 +16,13 @@
// under the License.
package org.apache.cloudstack.storage.snapshot;
import java.util.List;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
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.ObjectInDataStoreStateMachine.Event;
@ -33,8 +38,6 @@ import org.apache.cloudstack.storage.command.CreateObjectAnswer;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.storage.DataStoreRole;
@ -74,7 +77,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath())) {
s_logger.debug("backup an empty snapshot");
// don't need to backup this snapshot
SnapshotDataStoreVO parentSnapshotOnBackupStore = this.snapshotStoreDao.findBySnapshot(
SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(
parentSnapshot.getId(), DataStoreRole.Image);
if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState() == State.Ready) {
DataStore store = dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(),
@ -96,7 +99,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString());
throw new CloudRuntimeException(e.toString());
}
return this.snapshotDataFactory.getSnapshot(snapObj.getId(), store);
return snapshotDataFactory.getSnapshot(snapObj.getId(), store);
} else {
s_logger.debug("parent snapshot hasn't been backed up yet");
}
@ -114,7 +117,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
int i;
SnapshotDataStoreVO parentSnapshotOnBackupStore = null;
for (i = 1; i < deltaSnap; i++) {
parentSnapshotOnBackupStore = this.snapshotStoreDao.findBySnapshot(parentSnapshot.getId(),
parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(),
DataStoreRole.Image);
if (parentSnapshotOnBackupStore == null) {
break;
@ -125,7 +128,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
break;
}
parentSnapshotOnBackupStore = this.snapshotStoreDao.findBySnapshot(prevBackupId, DataStoreRole.Image);
parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(prevBackupId, DataStoreRole.Image);
}
if (i >= deltaSnap) {
fullBackup = true;
@ -133,7 +136,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
}
snapshot.addPayload(fullBackup);
return this.snapshotSvr.backupSnapshot(snapshot);
return snapshotSvr.backupSnapshot(snapshot);
}
protected boolean deleteSnapshotChain(SnapshotInfo snapshot) {
@ -167,7 +170,15 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
}
}
if (!deleted) {
boolean r = this.snapshotSvr.deleteSnapshot(snapshot);
boolean r = snapshotSvr.deleteSnapshot(snapshot);
if (r) {
// delete snapshot in cache if there is
List<SnapshotInfo> cacheSnaps = snapshotDataFactory.listSnapshotOnCache(snapshot.getId());
for (SnapshotInfo cacheSnap : cacheSnaps) {
s_logger.debug("Delete snapshot " + snapshot.getId() + " from image cache store: " + cacheSnap.getDataStore().getName());
cacheSnap.delete();
}
}
if (!resultIsSet) {
result = r;
resultIsSet = true;
@ -203,7 +214,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
// first mark the snapshot as destroyed, so that ui can't see it, but we
// may not destroy the snapshot on the storage, as other snapshots may
// depend on it.
SnapshotInfo snapshotOnImage = this.snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image);
SnapshotInfo snapshotOnImage = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image);
if (snapshotOnImage == null) {
s_logger.debug("Can't find snapshot on backup storage, delete it in db");
snapshotDao.remove(snapshotId);
@ -276,7 +287,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
snapshot = result.getSnashot();
DataStore primaryStore = snapshot.getDataStore();
SnapshotInfo backupedSnapshot = this.backupSnapshot(snapshot);
SnapshotInfo backupedSnapshot = backupSnapshot(snapshot);
try {
SnapshotInfo parent = snapshot.getParent();

View File

@ -107,6 +107,11 @@ public class DataStoreManagerImpl implements DataStoreManager {
return imageDataStoreMgr.listImageStores();
}
@Override
public List<DataStore> listImageCacheStores() {
return imageDataStoreMgr.listImageCacheStores();
}
public void setPrimaryStoreMgr(PrimaryDataStoreProviderManager primaryStoreMgr) {
this.primaryStoreMgr = primaryStoreMgr;
}

View File

@ -32,6 +32,8 @@ public interface ImageStoreProviderManager {
List<DataStore> listImageStores();
List<DataStore> listImageCacheStores();
List<DataStore> listImageStoresByScope(ZoneScope scope);
List<DataStore> listImageStoreByProvider(String provider);

View File

@ -23,10 +23,11 @@ import java.util.Map;
import javax.naming.ConfigurationException;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.springframework.stereotype.Component;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.ScopeType;
@ -118,4 +119,11 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
return listBy(sc);
}
@Override
public List<ImageStoreVO> listImageCacheStores() {
SearchCriteria<ImageStoreVO> sc = createSearchCriteria();
sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.ImageCache);
return listBy(sc);
}
}

View File

@ -263,4 +263,12 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
}
@Override
public List<SnapshotDataStoreVO> listOnCache(long snapshotId) {
SearchCriteria<SnapshotDataStoreVO> sc = storeSnapshotSearch.create();
sc.setParameters("snapshot_id", snapshotId);
sc.setParameters("store_role", DataStoreRole.ImageCache);
return search(sc, null);
}
}

View File

@ -334,6 +334,14 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
return findOneIncludingRemovedBy(sc);
}
@Override
public List<TemplateDataStoreVO> listOnCache(long templateId) {
SearchCriteria<TemplateDataStoreVO> sc = templateRoleSearch.create();
sc.setParameters("template_id", templateId);
sc.setParameters("store_role", DataStoreRole.ImageCache);
return search(sc, null);
}
@Override
public List<TemplateDataStoreVO> listByTemplate(long templateId) {
SearchCriteria<TemplateDataStoreVO> sc = templateSearch.create();

View File

@ -43,6 +43,7 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
private static final Logger s_logger = Logger.getLogger(VolumeDataStoreDaoImpl.class);
private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
private SearchBuilder<VolumeDataStoreVO> volumeSearch;
private SearchBuilder<VolumeDataStoreVO> volumeRoleSearch;
private SearchBuilder<VolumeDataStoreVO> storeSearch;
private SearchBuilder<VolumeDataStoreVO> cacheSearch;
private SearchBuilder<VolumeDataStoreVO> storeVolumeSearch;

View File

@ -18,8 +18,13 @@
*/
package org.apache.cloudstack.storage.volume;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@ -27,7 +32,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
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;
import com.cloud.storage.VolumeVO;
@ -58,13 +62,13 @@ public class VolumeDataFactoryImpl implements VolumeDataFactory {
if (storeRole == DataStoreRole.Image) {
VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
if (volumeStore != null) {
DataStore store = this.storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
DataStore store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
vol = VolumeObject.getVolumeObject(store, volumeVO);
}
} else {
// Primary data store
if (volumeVO.getPoolId() != null) {
DataStore store = this.storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
vol = VolumeObject.getVolumeObject(store, volumeVO);
}
}
@ -82,11 +86,11 @@ public class VolumeDataFactoryImpl implements VolumeDataFactory {
DataStore store = null;
VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
if (volumeStore != null) {
store = this.storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
}
vol = VolumeObject.getVolumeObject(store, volumeVO);
} else {
DataStore store = this.storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
vol = VolumeObject.getVolumeObject(store, volumeVO);
}
return vol;
@ -99,4 +103,23 @@ public class VolumeDataFactoryImpl implements VolumeDataFactory {
return vol;
}
@Override
public List<VolumeInfo> listVolumeOnCache(long volumeId) {
List<VolumeInfo> cacheVols = new ArrayList<VolumeInfo>();
// find all image cache stores for this zone scope
List<DataStore> cacheStores = storeMgr.listImageCacheStores();
if (cacheStores == null || cacheStores.size() == 0) {
return cacheVols;
}
for (DataStore store : cacheStores) {
// check if the volume is stored there
VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(store.getId(), volumeId);
if (volStore != null) {
VolumeInfo vol = getVolume(volumeId, store);
cacheVols.add(vol);
}
}
return cacheVols;
}
}

View File

@ -25,6 +25,8 @@ import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
@ -64,7 +66,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
@ -945,6 +946,13 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
AsyncCallFuture<VolumeApiResult> future2 = volService.expungeVolumeAsync(volOnSecondary);
future2.get();
}
// delete all cache entries for this volume
List<VolumeInfo> cacheVols = volFactory.listVolumeOnCache(volume.getId());
for (VolumeInfo volOnCache : cacheVols) {
s_logger.info("Delete volume from image cache store: " + volOnCache.getDataStore().getName());
volOnCache.delete();
}
} catch (Exception e) {
s_logger.warn("Failed to expunge volume:", e);
return false;
@ -1725,7 +1733,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@Inject
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
this._storagePoolAllocators = storagePoolAllocators;
_storagePoolAllocators = storagePoolAllocators;
}
}

View File

@ -25,6 +25,8 @@ import java.util.concurrent.ExecutionException;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
@ -44,7 +46,6 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcContext;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager;
@ -56,11 +57,11 @@ import com.cloud.event.UsageEventUtils;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.org.Grouping;
import com.cloud.storage.ScopeType;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.TemplateType;
import com.cloud.storage.TemplateProfile;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.ScopeType;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VMTemplateZoneVO;
import com.cloud.storage.dao.VMTemplateZoneDao;
@ -182,7 +183,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
}
// find all eligible image stores for this zone scope
List<DataStore> imageStores = this.storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId()));
List<DataStore> imageStores = storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId()));
if ( imageStores == null || imageStores.size() == 0 ){
throw new CloudRuntimeException("Unable to find image store to download template "+ profile.getTemplate());
}
@ -205,12 +206,12 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
}
}
TemplateInfo tmpl = this.imageFactory.getTemplate(template.getId(), imageStore);
TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), imageStore);
CreateTemplateContext<TemplateApiResult> context = new CreateTemplateContext<TemplateApiResult>(null, tmpl);
AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
caller.setContext(context);
this.imageService.createTemplateAsync(tmpl, imageStore, caller);
imageService.createTemplateAsync(tmpl, imageStore, caller);
if( !(profile.getIsPublic() || profile.getFeatured()) ){ // If private template then break
break;
}
@ -237,7 +238,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
// populated template entry
_tmpltDao.remove(template.getId());
} else {
VMTemplateVO tmplt = this._tmpltDao.findById(template.getId());
VMTemplateVO tmplt = _tmpltDao.findById(template.getId());
long accountId = tmplt.getAccountId();
if (template.getSize() != null) {
// publish usage event
@ -283,7 +284,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
VMTemplateVO template = profile.getTemplate();
// find all eligible image stores for this template
List<DataStore> imageStores = this.templateMgr.getImageStoreByTemplate(template.getId(), profile.getZoneId());
List<DataStore> imageStores = templateMgr.getImageStoreByTemplate(template.getId(), profile.getZoneId());
if (imageStores == null || imageStores.size() == 0) {
// already destroyed on image stores
s_logger.info("Unable to find image store still having template: " + template.getName()
@ -321,7 +322,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
}
s_logger.info("Delete template from image store: " + imageStore.getName());
AsyncCallFuture<TemplateApiResult> future = this.imageService.deleteTemplateAsync(this.imageFactory
AsyncCallFuture<TemplateApiResult> future = imageService.deleteTemplateAsync(imageFactory
.getTemplate(template.getId(), imageStore));
try {
TemplateApiResult result = future.get();
@ -350,9 +351,15 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
}
}
if (success) {
// delete all cache entries for this template
List<TemplateInfo> cacheTmpls = imageFactory.listTemplateOnCache(template.getId());
for (TemplateInfo tmplOnCache : cacheTmpls) {
s_logger.info("Delete template from image cache store: " + tmplOnCache.getDataStore().getName());
tmplOnCache.delete();
}
// find all eligible image stores for this template
List<DataStore> iStores = this.templateMgr.getImageStoreByTemplate(template.getId(), null);
List<DataStore> iStores = templateMgr.getImageStoreByTemplate(template.getId(), null);
if (iStores == null || iStores.size() == 0) {
// remove template from vm_templates table
if (_tmpltDao.remove(template.getId())) {
@ -380,7 +387,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
throw new InvalidParameterValueException("The DomR template cannot be deleted.");
}
if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
if (zoneId != null && (storeMgr.getImageStore(zoneId) == null)) {
throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone.");
}
@ -392,7 +399,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
TemplateProfile profile = super.prepareDelete(cmd);
Long zoneId = profile.getZoneId();
if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
if (zoneId != null && (storeMgr.getImageStore(zoneId) == null)) {
throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone.");
}

View File

@ -1707,6 +1707,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
return stores;
}
@Override
public VMTemplateVO updateTemplate(UpdateIsoCmd cmd) {
return updateTemplateOrIso(cmd);