Skip to content

server: delete template from storage pools on delete #10819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 4.19
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public interface TemplateManager {
*/
void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO);

void evictTemplateFromStoragePools(long templateId);

boolean templateIsDeleteable(long templateId);

Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

import javax.inject.Inject;

import com.cloud.domain.Domain;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.dao.VMInstanceDao;
import org.apache.cloudstack.agent.directdownload.CheckUrlAnswer;
import org.apache.cloudstack.agent.directdownload.CheckUrlCommand;
import org.apache.cloudstack.annotation.AnnotationService;
Expand Down Expand Up @@ -79,6 +76,7 @@
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.deployasis.dao.TemplateDeployAsIsDetailsDao;
import com.cloud.domain.Domain;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.exception.InvalidParameterValueException;
Expand Down Expand Up @@ -110,6 +108,8 @@
import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.dao.VMInstanceDao;

public class HypervisorTemplateAdapter extends TemplateAdapterBase {
protected final static Logger s_logger = Logger.getLogger(HypervisorTemplateAdapter.class);
Expand Down Expand Up @@ -596,7 +596,7 @@ public boolean delete(TemplateProfile profile) {
List<DataStore> imageStores = templateMgr.getImageStoreByTemplate(template.getId(),
zoneId);

if (imageStores == null || imageStores.size() == 0) {
if (CollectionUtils.isEmpty(imageStores)) {
// already destroyed on image stores
success = true;
s_logger.info("Unable to find image store still having template: " + template.getName() + ", so just mark the template removed");
Expand Down Expand Up @@ -631,7 +631,7 @@ public boolean delete(TemplateProfile profile) {

boolean dataDiskDeletetionResult = true;
List<VMTemplateVO> dataDiskTemplates = templateDao.listByParentTemplatetId(template.getId());
if (dataDiskTemplates != null && dataDiskTemplates.size() > 0) {
if (CollectionUtils.isNotEmpty(dataDiskTemplates)) {
s_logger.info("Template: " + template.getId() + " has Datadisk template(s) associated with it. Delete Datadisk templates before deleting the template");
for (VMTemplateVO dataDiskTemplate : dataDiskTemplates) {
s_logger.info("Delete Datadisk template: " + dataDiskTemplate.getId() + " from image store: " + imageStore.getName());
Expand All @@ -653,7 +653,7 @@ public boolean delete(TemplateProfile profile) {
}
// Mark datadisk template as Inactive
List<DataStore> iStores = templateMgr.getImageStoreByTemplate(dataDiskTemplate.getId(), null);
if (iStores == null || iStores.size() == 0) {
if (CollectionUtils.isEmpty(iStores)) {
dataDiskTemplate.setState(VirtualMachineTemplate.State.Inactive);
_tmpltDao.update(dataDiskTemplate.getId(), dataDiskTemplate);
}
Expand Down Expand Up @@ -731,6 +731,8 @@ public boolean delete(TemplateProfile profile) {

}

templateMgr.evictTemplateFromStoragePools(template.getId());

// remove its related ACL permission
Pair<Class<?>, Long> templateClassForId = new Pair<>(VirtualMachineTemplate.class, template.getId());
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, templateClassForId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,14 @@ public void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO)
}
}

@Override
public void evictTemplateFromStoragePools(long templateId) {
List<VMTemplateStoragePoolVO> templatePoolList = _tmpltPoolDao.listByTemplateId(templateId);
for (VMTemplateStoragePoolVO templatePool : templatePoolList) {
evictTemplateFromStoragePool(templatePool);
}
}

@Override
public boolean start() {
return true;
Expand Down
Loading