From 754d115bdbeac0585985d3404453d53044eb77be Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 12 Jan 2012 16:12:42 -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 --- 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 c6307bfac6e..4937c514590 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -39,7 +39,6 @@ - diff --git a/server/src/com/cloud/template/HyervisorTemplateAdapter.java b/server/src/com/cloud/template/HyervisorTemplateAdapter.java index 2d7244c2beb..64194454d5b 100755 --- a/server/src/com/cloud/template/HyervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HyervisorTemplateAdapter.java @@ -12,6 +12,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; @@ -39,6 +42,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class HyervisorTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter { private final static Logger s_logger = Logger.getLogger(HyervisorTemplateAdapter.class); @Inject DownloadMonitor _downloadMonitor; + @Inject AgentManager _agentMgr; private String validateUrl(String url) { try { @@ -171,7 +175,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()); @@ -180,6 +183,19 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem } 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) {