mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
CLOUDSTACK-3144: [Automation] Deletion of templates failing. Fails to
find image store housing template.
This commit is contained in:
parent
2c31f38c05
commit
87c401aaaf
@ -28,8 +28,6 @@ import javax.ejb.Local;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent;
|
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -56,9 +54,7 @@ import com.cloud.utils.db.JoinBuilder;
|
|||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.db.SearchCriteria.Func;
|
import com.cloud.utils.db.SearchCriteria.Func;
|
||||||
import com.cloud.utils.db.SearchCriteria.Op;
|
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.utils.db.UpdateBuilder;
|
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ -102,7 +98,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
|||||||
private SearchBuilder<VMTemplateVO> PublicIsoSearch;
|
private SearchBuilder<VMTemplateVO> PublicIsoSearch;
|
||||||
private SearchBuilder<VMTemplateVO> UserIsoSearch;
|
private SearchBuilder<VMTemplateVO> UserIsoSearch;
|
||||||
private GenericSearchBuilder<VMTemplateVO, Long> CountTemplatesByAccount;
|
private GenericSearchBuilder<VMTemplateVO, Long> CountTemplatesByAccount;
|
||||||
// private SearchBuilder<VMTemplateVO> updateStateSearch;
|
// private SearchBuilder<VMTemplateVO> updateStateSearch;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ResourceTagDao _tagsDao;
|
ResourceTagDao _tagsDao;
|
||||||
@ -344,6 +340,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
|||||||
AccountIdSearch = createSearchBuilder();
|
AccountIdSearch = createSearchBuilder();
|
||||||
AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||||
AccountIdSearch.and("publicTemplate", AccountIdSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
|
AccountIdSearch.and("publicTemplate", AccountIdSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
|
||||||
|
AccountIdSearch.and("removed", AccountIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL); // only list not removed templates for this account
|
||||||
AccountIdSearch.done();
|
AccountIdSearch.done();
|
||||||
|
|
||||||
SearchBuilder<VMTemplateZoneVO> tmpltZoneSearch = _templateZoneDao.createSearchBuilder();
|
SearchBuilder<VMTemplateZoneVO> tmpltZoneSearch = _templateZoneDao.createSearchBuilder();
|
||||||
@ -369,11 +366,11 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
|||||||
CountTemplatesByAccount.and("removed", CountTemplatesByAccount.entity().getRemoved(), SearchCriteria.Op.NULL);
|
CountTemplatesByAccount.and("removed", CountTemplatesByAccount.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||||
CountTemplatesByAccount.done();
|
CountTemplatesByAccount.done();
|
||||||
|
|
||||||
// updateStateSearch = this.createSearchBuilder();
|
// updateStateSearch = this.createSearchBuilder();
|
||||||
// updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
|
// updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
|
||||||
// updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
|
// updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
|
||||||
// updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
|
// updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
|
||||||
// updateStateSearch.done();
|
// updateStateSearch.done();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,8 +41,8 @@ import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
|
|||||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||||
import org.apache.cloudstack.framework.async.AsyncRpcConext;
|
import org.apache.cloudstack.framework.async.AsyncRpcConext;
|
||||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.agent.AgentManager;
|
import com.cloud.agent.AgentManager;
|
||||||
import com.cloud.agent.api.Answer;
|
import com.cloud.agent.api.Answer;
|
||||||
@ -54,14 +54,13 @@ import com.cloud.event.EventTypes;
|
|||||||
import com.cloud.event.UsageEventUtils;
|
import com.cloud.event.UsageEventUtils;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
import com.cloud.host.HostVO;
|
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.storage.Storage.ImageFormat;
|
import com.cloud.storage.Storage.ImageFormat;
|
||||||
import com.cloud.storage.Storage.TemplateType;
|
import com.cloud.storage.Storage.TemplateType;
|
||||||
import com.cloud.storage.TemplateProfile;
|
import com.cloud.storage.TemplateProfile;
|
||||||
import com.cloud.storage.VMTemplateZoneVO;
|
|
||||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
import com.cloud.storage.VMTemplateVO;
|
||||||
|
import com.cloud.storage.VMTemplateZoneVO;
|
||||||
import com.cloud.storage.dao.VMTemplateZoneDao;
|
import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||||
import com.cloud.storage.download.DownloadMonitor;
|
import com.cloud.storage.download.DownloadMonitor;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
@ -71,9 +70,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||||||
|
|
||||||
@Local(value=TemplateAdapter.class)
|
@Local(value=TemplateAdapter.class)
|
||||||
public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
||||||
private final static Logger s_logger = Logger.getLogger(HypervisorTemplateAdapter.class);
|
private final static Logger s_logger = Logger.getLogger(HypervisorTemplateAdapter.class);
|
||||||
@Inject DownloadMonitor _downloadMonitor;
|
@Inject DownloadMonitor _downloadMonitor;
|
||||||
@Inject AgentManager _agentMgr;
|
@Inject AgentManager _agentMgr;
|
||||||
|
|
||||||
@Inject DataStoreManager storeMgr;
|
@Inject DataStoreManager storeMgr;
|
||||||
@Inject TemplateService imageService;
|
@Inject TemplateService imageService;
|
||||||
@ -90,92 +89,92 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
|
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
|
||||||
TemplateProfile profile = super.prepare(cmd);
|
TemplateProfile profile = super.prepare(cmd);
|
||||||
String url = profile.getUrl();
|
String url = profile.getUrl();
|
||||||
|
|
||||||
if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
||||||
&&(!url.toLowerCase().endsWith("iso.gz"))){
|
&&(!url.toLowerCase().endsWith("iso.gz"))){
|
||||||
throw new InvalidParameterValueException("Please specify a valid iso");
|
throw new InvalidParameterValueException("Please specify a valid iso");
|
||||||
}
|
}
|
||||||
|
|
||||||
UriUtils.validateUrl(url);
|
UriUtils.validateUrl(url);
|
||||||
profile.setUrl(url);
|
profile.setUrl(url);
|
||||||
// Check that the resource limit for secondary storage won't be exceeded
|
// Check that the resource limit for secondary storage won't be exceeded
|
||||||
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()),
|
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()),
|
||||||
ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
|
ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
|
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
|
||||||
TemplateProfile profile = super.prepare(cmd);
|
TemplateProfile profile = super.prepare(cmd);
|
||||||
String url = profile.getUrl();
|
String url = profile.getUrl();
|
||||||
|
|
||||||
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
||||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
||||||
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
||||||
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz"))
|
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz"))
|
||||||
&&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip"))
|
&&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip"))
|
||||||
&&(!url.toLowerCase().endsWith("ova.bz2"))&&(!url.toLowerCase().endsWith("ova.gz"))
|
&&(!url.toLowerCase().endsWith("ova.bz2"))&&(!url.toLowerCase().endsWith("ova.gz"))
|
||||||
&&(!url.toLowerCase().endsWith("tar"))&&(!url.toLowerCase().endsWith("tar.zip"))
|
&&(!url.toLowerCase().endsWith("tar"))&&(!url.toLowerCase().endsWith("tar.zip"))
|
||||||
&&(!url.toLowerCase().endsWith("tar.bz2"))&&(!url.toLowerCase().endsWith("tar.gz"))
|
&&(!url.toLowerCase().endsWith("tar.bz2"))&&(!url.toLowerCase().endsWith("tar.gz"))
|
||||||
&&(!url.toLowerCase().endsWith("img"))&&(!url.toLowerCase().endsWith("raw"))){
|
&&(!url.toLowerCase().endsWith("img"))&&(!url.toLowerCase().endsWith("raw"))){
|
||||||
throw new InvalidParameterValueException("Please specify a valid "+ cmd.getFormat().toLowerCase());
|
throw new InvalidParameterValueException("Please specify a valid "+ cmd.getFormat().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cmd.getFormat().equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|
if ((cmd.getFormat().equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|
||||||
|| (cmd.getFormat().equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|
|| (cmd.getFormat().equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|
||||||
|| (cmd.getFormat().equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|
|| (cmd.getFormat().equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|
||||||
|| (cmd.getFormat().equalsIgnoreCase("tar") && (!url.toLowerCase().endsWith("tar") && !url.toLowerCase().endsWith("tar.zip") && !url.toLowerCase().endsWith("tar.bz2") && !url.toLowerCase().endsWith("tar.gz")))
|
|| (cmd.getFormat().equalsIgnoreCase("tar") && (!url.toLowerCase().endsWith("tar") && !url.toLowerCase().endsWith("tar.zip") && !url.toLowerCase().endsWith("tar.bz2") && !url.toLowerCase().endsWith("tar.gz")))
|
||||||
|| (cmd.getFormat().equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
|
|| (cmd.getFormat().equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
|
||||||
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + cmd.getFormat().toLowerCase());
|
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + cmd.getFormat().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
UriUtils.validateUrl(url);
|
UriUtils.validateUrl(url);
|
||||||
profile.setUrl(url);
|
profile.setUrl(url);
|
||||||
// Check that the resource limit for secondary storage won't be exceeded
|
// Check that the resource limit for secondary storage won't be exceeded
|
||||||
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()),
|
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()),
|
||||||
ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
|
ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VMTemplateVO create(TemplateProfile profile) {
|
public VMTemplateVO create(TemplateProfile profile) {
|
||||||
// persist entry in vm_template, vm_template_details and template_zone_ref tables, not that entry at template_store_ref is not created here, and created in createTemplateAsync.
|
// persist entry in vm_template, vm_template_details and template_zone_ref tables, not that entry at template_store_ref is not created here, and created in createTemplateAsync.
|
||||||
VMTemplateVO template = persistTemplate(profile);
|
VMTemplateVO template = persistTemplate(profile);
|
||||||
|
|
||||||
if (template == null) {
|
if (template == null) {
|
||||||
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
|
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
// find all eligible image stores for this zone scope
|
// find all eligible image stores for this zone scope
|
||||||
List<DataStore> imageStores = this.storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId()));
|
List<DataStore> imageStores = this.storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId()));
|
||||||
if ( imageStores == null || imageStores.size() == 0 ){
|
if ( imageStores == null || imageStores.size() == 0 ){
|
||||||
throw new CloudRuntimeException("Unable to find image store to download template "+ profile.getTemplate());
|
throw new CloudRuntimeException("Unable to find image store to download template "+ profile.getTemplate());
|
||||||
}
|
}
|
||||||
for (DataStore imageStore : imageStores) {
|
for (DataStore imageStore : imageStores) {
|
||||||
TemplateInfo tmpl = this.imageFactory.getTemplate(template.getId(), imageStore);
|
TemplateInfo tmpl = this.imageFactory.getTemplate(template.getId(), imageStore);
|
||||||
CreateTemplateContext<TemplateApiResult> context = new CreateTemplateContext<TemplateApiResult>(null, tmpl);
|
CreateTemplateContext<TemplateApiResult> context = new CreateTemplateContext<TemplateApiResult>(null, tmpl);
|
||||||
AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> caller = AsyncCallbackDispatcher.create(this);
|
AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> caller = AsyncCallbackDispatcher.create(this);
|
||||||
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
|
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
|
||||||
caller.setContext(context);
|
caller.setContext(context);
|
||||||
this.imageService
|
this.imageService
|
||||||
.createTemplateAsync(tmpl, imageStore, caller);
|
.createTemplateAsync(tmpl, imageStore, caller);
|
||||||
}
|
}
|
||||||
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
||||||
|
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CreateTemplateContext<T> extends AsyncRpcConext<T> {
|
private class CreateTemplateContext<T> extends AsyncRpcConext<T> {
|
||||||
final TemplateInfo template;
|
final TemplateInfo template;
|
||||||
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateInfo template) {
|
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateInfo template) {
|
||||||
super(callback);
|
super(callback);
|
||||||
this.template = template;
|
this.template = template;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Void createTemplateAsyncCallBack(AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> callback,
|
protected Void createTemplateAsyncCallBack(AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> callback,
|
||||||
CreateTemplateContext<TemplateApiResult> context) {
|
CreateTemplateContext<TemplateApiResult> context) {
|
||||||
@ -193,73 +192,80 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
public boolean delete(TemplateProfile profile) {
|
public boolean delete(TemplateProfile profile) {
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
|
|
||||||
VMTemplateVO template = profile.getTemplate();
|
VMTemplateVO template = profile.getTemplate();
|
||||||
|
|
||||||
// find all eligible image stores for this template
|
// find all eligible image stores for this template
|
||||||
List<DataStore> imageStores = this.templateMgr.getImageStoreByTemplate(template.getId(), profile.getZoneId());
|
List<DataStore> imageStores = this.templateMgr.getImageStoreByTemplate(template.getId(), profile.getZoneId());
|
||||||
if ( imageStores == null || imageStores.size() == 0 ){
|
if (imageStores == null || imageStores.size() == 0) {
|
||||||
throw new CloudRuntimeException("Unable to find image store to delete template "+ profile.getTemplate());
|
// already destroyed on image stores
|
||||||
}
|
s_logger.info("Unable to find image store still having template: " + template.getName()
|
||||||
|
+ ", so just mark the template removed");
|
||||||
// Make sure the template is downloaded to all found image stores
|
|
||||||
for (DataStore store : imageStores) {
|
|
||||||
long storeId = store.getId();
|
|
||||||
List<TemplateDataStoreVO> templateStores = _tmpltStoreDao.listByTemplateStore(template.getId(), storeId);
|
|
||||||
for (TemplateDataStoreVO templateStore : templateStores) {
|
|
||||||
if (templateStore.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
|
|
||||||
String errorMsg = "Please specify a template that is not currently being downloaded.";
|
|
||||||
s_logger.debug("Template: " + template.getName() + " is currently being downloaded to secondary storage host: " + store.getName() + "; cant' delete it.");
|
|
||||||
throw new CloudRuntimeException(errorMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String eventType = "";
|
|
||||||
if (template.getFormat().equals(ImageFormat.ISO)) {
|
|
||||||
eventType = EventTypes.EVENT_ISO_DELETE;
|
|
||||||
} else {
|
} else {
|
||||||
eventType = EventTypes.EVENT_TEMPLATE_DELETE;
|
// Make sure the template is downloaded to all found image stores
|
||||||
}
|
for (DataStore store : imageStores) {
|
||||||
|
long storeId = store.getId();
|
||||||
for (DataStore imageStore : imageStores) {
|
List<TemplateDataStoreVO> templateStores = _tmpltStoreDao
|
||||||
// publish zone-wide usage event
|
.listByTemplateStore(template.getId(), storeId);
|
||||||
Long sZoneId = ((ImageStoreEntity)imageStore).getDataCenterId();
|
for (TemplateDataStoreVO templateStore : templateStores) {
|
||||||
if (sZoneId != null) {
|
if (templateStore.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
|
||||||
UsageEventUtils.publishUsageEvent(eventType, template.getAccountId(), sZoneId, template.getId(), null, null, null);
|
String errorMsg = "Please specify a template that is not currently being downloaded.";
|
||||||
}
|
s_logger.debug("Template: " + template.getName()
|
||||||
|
+ " is currently being downloaded to secondary storage host: " + store.getName()
|
||||||
s_logger.info("Delete template from image store: " + imageStore.getName());
|
+ "; cant' delete it.");
|
||||||
AsyncCallFuture<TemplateApiResult> future = this.imageService
|
throw new CloudRuntimeException(errorMsg);
|
||||||
.deleteTemplateAsync(this.imageFactory.getTemplate(template.getId(), imageStore));
|
|
||||||
try {
|
|
||||||
TemplateApiResult result = future.get();
|
|
||||||
success = result.isSuccess();
|
|
||||||
if ( !success )
|
|
||||||
break;
|
|
||||||
|
|
||||||
// remove from template_zone_ref
|
|
||||||
List<VMTemplateZoneVO> templateZones = templateZoneDao.listByZoneTemplate(sZoneId, template.getId());
|
|
||||||
if (templateZones != null) {
|
|
||||||
for (VMTemplateZoneVO templateZone : templateZones) {
|
|
||||||
templateZoneDao.remove(templateZone.getId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
}
|
||||||
s_logger.debug("delete template Failed", e);
|
|
||||||
throw new CloudRuntimeException("delete template Failed", e);
|
String eventType = "";
|
||||||
} catch (ExecutionException e) {
|
if (template.getFormat().equals(ImageFormat.ISO)) {
|
||||||
s_logger.debug("delete template Failed", e);
|
eventType = EventTypes.EVENT_ISO_DELETE;
|
||||||
throw new CloudRuntimeException("delete template Failed", e);
|
} else {
|
||||||
|
eventType = EventTypes.EVENT_TEMPLATE_DELETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DataStore imageStore : imageStores) {
|
||||||
|
// publish zone-wide usage event
|
||||||
|
Long sZoneId = ((ImageStoreEntity) imageStore).getDataCenterId();
|
||||||
|
if (sZoneId != null) {
|
||||||
|
UsageEventUtils.publishUsageEvent(eventType, template.getAccountId(), sZoneId, template.getId(),
|
||||||
|
null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
s_logger.info("Delete template from image store: " + imageStore.getName());
|
||||||
|
AsyncCallFuture<TemplateApiResult> future = this.imageService.deleteTemplateAsync(this.imageFactory
|
||||||
|
.getTemplate(template.getId(), imageStore));
|
||||||
|
try {
|
||||||
|
TemplateApiResult result = future.get();
|
||||||
|
success = result.isSuccess();
|
||||||
|
if (!success) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove from template_zone_ref
|
||||||
|
List<VMTemplateZoneVO> templateZones = templateZoneDao
|
||||||
|
.listByZoneTemplate(sZoneId, template.getId());
|
||||||
|
if (templateZones != null) {
|
||||||
|
for (VMTemplateZoneVO templateZone : templateZones) {
|
||||||
|
templateZoneDao.remove(templateZone.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
s_logger.debug("delete template Failed", e);
|
||||||
|
throw new CloudRuntimeException("delete template Failed", e);
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
s_logger.debug("delete template Failed", e);
|
||||||
|
throw new CloudRuntimeException("delete template Failed", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
s_logger.info("Delete template from template table");
|
s_logger.info("Delete template from template table");
|
||||||
// remove template from vm_templates table
|
// remove template from vm_templates table
|
||||||
@ -275,36 +281,36 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||||||
return success;
|
return success;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
|
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
|
||||||
TemplateProfile profile = super.prepareDelete(cmd);
|
TemplateProfile profile = super.prepareDelete(cmd);
|
||||||
VMTemplateVO template = profile.getTemplate();
|
VMTemplateVO template = profile.getTemplate();
|
||||||
Long zoneId = profile.getZoneId();
|
Long zoneId = profile.getZoneId();
|
||||||
|
|
||||||
if (template.getTemplateType() == TemplateType.SYSTEM) {
|
if (template.getTemplateType() == TemplateType.SYSTEM) {
|
||||||
throw new InvalidParameterValueException("The DomR template cannot be deleted.");
|
throw new InvalidParameterValueException("The DomR template cannot be deleted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
|
if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
|
||||||
throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone.");
|
throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
|
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
|
||||||
TemplateProfile profile = super.prepareDelete(cmd);
|
TemplateProfile profile = super.prepareDelete(cmd);
|
||||||
Long zoneId = profile.getZoneId();
|
Long zoneId = profile.getZoneId();
|
||||||
|
|
||||||
if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
|
if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
|
||||||
throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone.");
|
throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemplateProfile prepareExtractTemplate(ExtractTemplateCmd extractcmd) {
|
public TemplateProfile prepareExtractTemplate(ExtractTemplateCmd extractcmd) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user