From 0156ec7cdd4850bd01630d03200e9afb0ce2dd90 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 12 Jan 2012 16:20:44 -0800 Subject: [PATCH] bug 11497: 1. remove Garbagecollection primary storage allocator. other storage allocators fails may because there is primary storage with the same tag, it is not caused by no primary storage capacity. 2. delete template will try to delete templates in secondary storage in the API. status 11497: resolved fixed GarbageCollecting Conflicts: server/src/com/cloud/template/HyervisorTemplateAdapter.java --- client/tomcatconf/components.xml.in | 1 - .../template/HyervisorTemplateAdapter.java | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 9ef7f6769d5..1fa6785652b 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -43,7 +43,6 @@ - diff --git a/server/src/com/cloud/template/HyervisorTemplateAdapter.java b/server/src/com/cloud/template/HyervisorTemplateAdapter.java index c81c1dbc181..213273c59ed 100755 --- a/server/src/com/cloud/template/HyervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HyervisorTemplateAdapter.java @@ -11,6 +11,9 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.storage.DeleteTemplateCommand; import com.cloud.api.commands.DeleteIsoCmd; import com.cloud.api.commands.DeleteTemplateCmd; import com.cloud.api.commands.RegisterIsoCmd; @@ -40,6 +43,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem private final static Logger s_logger = Logger.getLogger(HyervisorTemplateAdapter.class); @Inject DownloadMonitor _downloadMonitor; @Inject SecondaryStorageVmManager _ssvmMgr; + @Inject AgentManager _agentMgr; private String validateUrl(String url) { try { @@ -176,7 +180,6 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem List templateHostVOs = _tmpltHostDao.listByHostTemplate(hostId, templateId); for (VMTemplateHostVO templateHostVO : templateHostVOs) { VMTemplateHostVO lock = _tmpltHostDao.acquireInLockTable(templateHostVO.getId()); - try { if (lock == null) { s_logger.debug("Failed to acquire lock when deleting templateHostVO with ID: " + templateHostVO.getId()); @@ -187,6 +190,19 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem _usageEventDao.persist(usageEvent); templateHostVO.setDestroyed(true); _tmpltHostDao.update(templateHostVO.getId(), templateHostVO); + String installPath = templateHostVO.getInstallPath(); + if (installPath != null) { + Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new DeleteTemplateCommand(secondaryStorageHost.getStorageUrl(), installPath)); + + if (answer == null || !answer.getResult()) { + s_logger.debug("Failed to delete " + templateHostVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails())); + } else { + _tmpltHostDao.remove(templateHostVO.getId()); + s_logger.debug("Deleted template at: " + installPath); + } + } else { + _tmpltHostDao.remove(templateHostVO.getId()); + } VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(sZoneId, templateId); if (templateZone != null) {