|
26 | 26 |
|
27 | 27 | import javax.inject.Inject; |
28 | 28 |
|
29 | | -import com.cloud.configuration.Config; |
30 | | -import com.cloud.deployasis.dao.TemplateDeployAsIsDetailsDao; |
31 | | -import com.cloud.storage.dao.VMTemplateDetailsDao; |
32 | | -import com.cloud.utils.db.Transaction; |
33 | | -import com.cloud.utils.db.TransactionCallback; |
34 | | -import com.cloud.utils.db.TransactionStatus; |
35 | 29 | import org.apache.cloudstack.agent.directdownload.CheckUrlAnswer; |
36 | 30 | import org.apache.cloudstack.agent.directdownload.CheckUrlCommand; |
37 | 31 | import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; |
|
62 | 56 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
63 | 57 | import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; |
64 | 58 | import org.apache.cloudstack.utils.security.DigestHelper; |
| 59 | +import org.apache.commons.collections.CollectionUtils; |
65 | 60 | import org.apache.log4j.Logger; |
66 | 61 |
|
67 | 62 | import com.cloud.agent.AgentManager; |
68 | 63 | import com.cloud.agent.api.Answer; |
69 | 64 | import com.cloud.alert.AlertManager; |
| 65 | +import com.cloud.configuration.Config; |
70 | 66 | import com.cloud.configuration.Resource.ResourceType; |
71 | 67 | import com.cloud.dc.DataCenterVO; |
72 | 68 | import com.cloud.dc.dao.DataCenterDao; |
| 69 | +import com.cloud.deployasis.dao.TemplateDeployAsIsDetailsDao; |
73 | 70 | import com.cloud.event.EventTypes; |
74 | 71 | import com.cloud.event.UsageEventUtils; |
75 | 72 | import com.cloud.exception.InvalidParameterValueException; |
|
87 | 84 | import com.cloud.storage.VMTemplateVO; |
88 | 85 | import com.cloud.storage.VMTemplateZoneVO; |
89 | 86 | import com.cloud.storage.dao.VMTemplateDao; |
| 87 | +import com.cloud.storage.dao.VMTemplateDetailsDao; |
90 | 88 | import com.cloud.storage.dao.VMTemplateZoneDao; |
91 | 89 | import com.cloud.storage.download.DownloadMonitor; |
92 | 90 | import com.cloud.template.VirtualMachineTemplate.State; |
|
95 | 93 | import com.cloud.utils.UriUtils; |
96 | 94 | import com.cloud.utils.db.DB; |
97 | 95 | import com.cloud.utils.db.EntityManager; |
| 96 | +import com.cloud.utils.db.Transaction; |
| 97 | +import com.cloud.utils.db.TransactionCallback; |
| 98 | +import com.cloud.utils.db.TransactionStatus; |
98 | 99 | import com.cloud.utils.exception.CloudRuntimeException; |
99 | 100 |
|
100 | 101 | public class HypervisorTemplateAdapter extends TemplateAdapterBase { |
@@ -169,6 +170,12 @@ private Long performDirectDownloadUrlValidation(final String format, final Strin |
169 | 170 | return ans.getTemplateSize(); |
170 | 171 | } |
171 | 172 |
|
| 173 | + private void checkZoneImageStores(final List<Long> zoneIdList) { |
| 174 | + if (zoneIdList != null && CollectionUtils.isEmpty(storeMgr.getImageStoresByScope(new ZoneScope(zoneIdList.get(0))))) { |
| 175 | + throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone."); |
| 176 | + } |
| 177 | + } |
| 178 | + |
172 | 179 | @Override |
173 | 180 | public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException { |
174 | 181 | TemplateProfile profile = super.prepare(cmd); |
@@ -637,29 +644,17 @@ public boolean delete(TemplateProfile profile) { |
637 | 644 | public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) { |
638 | 645 | TemplateProfile profile = super.prepareDelete(cmd); |
639 | 646 | VMTemplateVO template = profile.getTemplate(); |
640 | | - List<Long> zoneIdList = profile.getZoneIdList(); |
641 | | - |
642 | 647 | if (template.getTemplateType() == TemplateType.SYSTEM) { |
643 | 648 | throw new InvalidParameterValueException("The DomR template cannot be deleted."); |
644 | 649 | } |
645 | | - |
646 | | - if (zoneIdList != null && (storeMgr.getImageStoreWithFreeCapacity(zoneIdList.get(0)) == null)) { |
647 | | - throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone."); |
648 | | - } |
649 | | - |
| 650 | + checkZoneImageStores(profile.getZoneIdList()); |
650 | 651 | return profile; |
651 | 652 | } |
652 | 653 |
|
653 | 654 | @Override |
654 | 655 | public TemplateProfile prepareDelete(DeleteIsoCmd cmd) { |
655 | 656 | TemplateProfile profile = super.prepareDelete(cmd); |
656 | | - List<Long> zoneIdList = profile.getZoneIdList(); |
657 | | - |
658 | | - if (zoneIdList != null && |
659 | | - (storeMgr.getImageStoreWithFreeCapacity(zoneIdList.get(0)) == null)) { |
660 | | - throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone."); |
661 | | - } |
662 | | - |
| 657 | + checkZoneImageStores(profile.getZoneIdList()); |
663 | 658 | return profile; |
664 | 659 | } |
665 | 660 | } |
0 commit comments