CS-14673 when a template is deleted and then copied over again , it is still marked as "Removed" in template_zone_ref table.

This commit is contained in:
Bharat kumar 2012-09-07 16:05:09 +05:30
parent 5999c61c83
commit 7ddeefe563
4 changed files with 28 additions and 17 deletions

View File

@ -539,15 +539,19 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
_templateDetailsDao.persist(tmplt.getId(), tmplt.getDetails());
}
}
VMTemplateZoneVO tmpltZoneVO = _templateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
if ( tmpltZoneVO == null ) {
tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
_templateZoneDao.persist(tmpltZoneVO);
} else {
tmpltZoneVO.setRemoved(null);
List<VMTemplateZoneVO> tmpltZoneVOs = _templateZoneDao.listByZoneTemplate(zoneId, tmplt.getId());
if (tmpltZoneVOs != null && tmpltZoneVOs.size()!=0) {
VMTemplateZoneVO tmpltZoneVO = tmpltZoneVOs.get(0);
tmpltZoneVO.setLastUpdated(new Date());
_templateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
}
else {
VMTemplateZoneVO tmpltZone = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
_templateZoneDao.persist(tmpltZone);
}
txn.commit();
return tmplt.getId();

View File

@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.storage.dao;
import java.util.List;

View File

@ -196,11 +196,17 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
} else {
_tmpltHostDao.remove(templateHostVO.getId());
}
VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(sZoneId, templateId);
/**check if the list is not null and empty.
* check to see if there is a entry and remove it.
*/
List<VMTemplateZoneVO> templateZones = _tmpltZoneDao.listByZoneTemplate(sZoneId, templateId);
if (templateZones != null && templateZones.size()!=0) {
VMTemplateZoneVO templateZone = templateZones.get(0);
if (templateZone != null) {
_tmpltZoneDao.remove(templateZone.getId());
}
}
UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), sZoneId, templateId, null);
_usageEventDao.persist(usageEvent);

View File

@ -561,7 +561,6 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
return true;
}
} else if (dstTmpltHost != null && dstTmpltHost.getDownloadState() == Status.DOWNLOAD_ERROR){
if (dstTmpltHost.getDestroyed() == true) {
dstTmpltHost.setDestroyed(false);
dstTmpltHost.setDownloadState(Status.NOT_DOWNLOADED);
dstTmpltHost.setDownloadPercent(0);
@ -569,7 +568,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
dstTmpltHost.setErrorString("");
dstTmpltHost.setJobId(null);
_tmpltHostDao.update(dstTmpltHost.getId(), dstTmpltHost);
}
}
}
} finally {
@ -618,19 +618,22 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
throw new InvalidParameterValueException("Unable to find template with id");
}
HostVO dstSecHost = _storageMgr.getSecondaryStorageHost(destZoneId, templateId);
if ( dstSecHost != null ) {
s_logger.debug("There is template " + templateId + " in secondary storage " + dstSecHost.getId() + " in zone " + destZoneId + " , don't need to copy");
return template;
}
HostVO srcSecHost = _storageMgr.getSecondaryStorageHost(sourceZoneId, templateId);
if ( srcSecHost == null ) {
throw new InvalidParameterValueException("There is no template " + templateId + " in zone " + sourceZoneId );
}
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, template);
VMTemplateHostVO dsttmpltHost = _storageMgr.getTemplateHostRef(destZoneId,templateId,true);
// Check if the template is not destroyed and is downloaded or being downloaded.
if (dsttmpltHost != null && !dsttmpltHost.getDestroyed() && (dsttmpltHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED || dsttmpltHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS ) ){
s_logger.debug(" The template " + templateId + " in secondary storage " + dsttmpltHost.getId() + " in zone " + destZoneId + "already exists");
return template;
}
boolean success = copy(userId, template, srcSecHost, sourceZone, dstZone);
if (success) {
@ -666,7 +669,6 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
if (template.getTemplateType() == TemplateType.SYSTEM) {
continue;
}
// If the template is not yet downloaded to the pool, consider it in use
if (templatePoolVO.getDownloadState() != Status.DOWNLOADED) {
continue;