|
53 | 53 | import org.apache.cloudstack.framework.async.AsyncRpcContext; |
54 | 54 | import org.apache.cloudstack.framework.messagebus.MessageBus; |
55 | 55 | import org.apache.cloudstack.framework.messagebus.PublishScope; |
| 56 | +import org.apache.cloudstack.secstorage.heuristics.HeuristicType; |
56 | 57 | import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand; |
57 | 58 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
58 | 59 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
@@ -300,13 +301,29 @@ protected void createTemplateWithinZones(TemplateProfile profile, VMTemplateVO t |
300 | 301 | } |
301 | 302 |
|
302 | 303 | protected List<DataStore> getImageStoresThrowsExceptionIfNotFound(long zoneId, TemplateProfile profile) { |
303 | | - List<DataStore> imageStores = storeMgr.getImageStoresByZoneIds(zoneId); |
| 304 | + List<DataStore> imageStores = storeMgr.getImageStoresByScopeExcludingReadOnly(new ZoneScope(zoneId)); |
304 | 305 | if (imageStores == null || imageStores.size() == 0) { |
305 | 306 | throw new CloudRuntimeException(String.format("Unable to find image store to download the template [%s].", profile.getTemplate())); |
306 | 307 | } |
307 | 308 | return imageStores; |
308 | 309 | } |
309 | 310 |
|
| 311 | + protected DataStore verifyHeuristicRulesForZone(VMTemplateVO template, Long zoneId) { |
| 312 | + HeuristicType heuristicType; |
| 313 | + if (ImageFormat.ISO.equals(template.getFormat())) { |
| 314 | + heuristicType = HeuristicType.ISO; |
| 315 | + } else { |
| 316 | + heuristicType = HeuristicType.TEMPLATE; |
| 317 | + } |
| 318 | + DataStore imageStore = heuristicRuleHelper.getImageStoreIfThereIsHeuristicRule(zoneId, heuristicType, template); |
| 319 | + if (imageStore == null || isWritableImageStore(imageStore, zoneId)) { |
| 320 | + return imageStore; |
| 321 | + } |
| 322 | + |
| 323 | + logger.info("Heuristic rule selected readonly image store [{}] in zone [{}]; skipping it for template upload.", imageStore, zoneId); |
| 324 | + return null; |
| 325 | + } |
| 326 | + |
310 | 327 | protected void standardImageStoreAllocation(List<DataStore> imageStores, VMTemplateVO template) { |
311 | 328 | Set<Long> zoneSet = new HashSet<Long>(); |
312 | 329 | Collections.shuffle(imageStores); |
|
0 commit comments