CLOUDSTACK-7155 Re-copying templates to other zones doesn't work

This commit is contained in:
Bharat Kumar 2014-08-19 20:09:02 +05:30 committed by root
parent ffa4d73290
commit cab2b12d7d
4 changed files with 20 additions and 0 deletions

View File

@ -76,4 +76,6 @@ public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Lo
void updateStoreRoleToCachce(long storeId); void updateStoreRoleToCachce(long storeId);
List<TemplateDataStoreVO> listTemplateDownloadUrls(); List<TemplateDataStoreVO> listTemplateDownloadUrls();
void removeByTemplateStore(long templateId, long imageStoreId);
} }

View File

@ -291,6 +291,16 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
return null; return null;
} }
@Override
public void removeByTemplateStore(long templateId, long imageStoreId) {
SearchCriteria<TemplateDataStoreVO> sc = storeTemplateSearch.create();
sc.setParameters("template_id", templateId);
sc.setParameters("store_id", imageStoreId);
sc.setParameters("destroyed", false);
expunge(sc);
}
@Override @Override
public TemplateDataStoreVO findByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) { public TemplateDataStoreVO findByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) {
// get all elgible image stores // get all elgible image stores

View File

@ -27,6 +27,7 @@ import javax.inject.Inject;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; 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.iso.RegisterIsoCmd;
import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd; import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
@ -83,6 +84,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
@Inject @Inject
AgentManager _agentMgr; AgentManager _agentMgr;
@Inject TemplateDataStoreDao templateDataStoreDao;
@Inject @Inject
DataStoreManager storeMgr; DataStoreManager storeMgr;
@Inject @Inject
@ -306,6 +308,9 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
templateZoneDao.remove(templateZone.getId()); templateZoneDao.remove(templateZone.getId());
} }
} }
//mark all the occurrences of this template in the given store as destroyed.
templateDataStoreDao.removeByTemplateStore(template.getId(), imageStore.getId());
} catch (InterruptedException e) { } catch (InterruptedException e) {
s_logger.debug("delete template Failed", e); s_logger.debug("delete template Failed", e);
throw new CloudRuntimeException("delete template Failed", e); throw new CloudRuntimeException("delete template Failed", e);

View File

@ -648,6 +648,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOADED) { if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOADED) {
return true; // already downloaded on this image store return true; // already downloaded on this image store
} }
if (dstTmpltStore != null && dstTmpltStore.getDownloadState() != Status.DOWNLOAD_IN_PROGRESS) {
_tmplStoreDao.removeByTemplateStore(tmpltId, dstSecStore.getId());
}
AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.copyTemplate(srcTemplate, dstSecStore); AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.copyTemplate(srcTemplate, dstSecStore);
try { try {