|
39 | 39 | import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; |
40 | 40 | import org.apache.cloudstack.context.CallContext; |
41 | 41 | import org.apache.cloudstack.direct.download.DirectDownloadManager; |
42 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; |
43 | 42 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
44 | | -import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; |
45 | 43 | import org.apache.cloudstack.engine.subsystem.api.storage.Scope; |
46 | 44 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; |
47 | 45 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService; |
|
57 | 55 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
58 | 56 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
59 | 57 | import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; |
60 | | -import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; |
61 | 58 | import org.apache.cloudstack.utils.security.DigestHelper; |
62 | 59 | import org.apache.commons.collections.CollectionUtils; |
63 | 60 |
|
64 | 61 | import com.cloud.agent.AgentManager; |
65 | 62 | import com.cloud.agent.api.Answer; |
66 | 63 | import com.cloud.alert.AlertManager; |
67 | | -import com.cloud.configuration.Config; |
68 | 64 | import com.cloud.configuration.Resource.ResourceType; |
69 | 65 | import com.cloud.dc.DataCenterVO; |
70 | 66 | import com.cloud.dc.dao.DataCenterDao; |
71 | | -import com.cloud.domain.Domain; |
72 | 67 | import com.cloud.deployasis.dao.TemplateDeployAsIsDetailsDao; |
73 | 68 | import com.cloud.event.EventTypes; |
74 | 69 | import com.cloud.event.UsageEventUtils; |
75 | 70 | import com.cloud.exception.InvalidParameterValueException; |
76 | 71 | import com.cloud.exception.ResourceAllocationException; |
77 | 72 | import com.cloud.host.HostVO; |
78 | 73 | import com.cloud.hypervisor.Hypervisor; |
79 | | -import com.cloud.org.Grouping; |
80 | 74 | import com.cloud.resource.ResourceManager; |
81 | 75 | import com.cloud.storage.ScopeType; |
82 | 76 | import com.cloud.storage.Storage.ImageFormat; |
@@ -300,44 +294,6 @@ protected void validateSecondaryStorageAndCreateTemplate(List<DataStore> imageSt |
300 | 294 | } |
301 | 295 | } |
302 | 296 |
|
303 | | - protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId, Set<Long> zoneSet, boolean isTemplatePrivate) { |
304 | | - if (zoneId == null) { |
305 | | - logger.warn(String.format("Zone ID is null, cannot allocate ISO/template in image store [%s].", imageStore)); |
306 | | - return false; |
307 | | - } |
308 | | - |
309 | | - DataCenterVO zone = _dcDao.findById(zoneId); |
310 | | - if (zone == null) { |
311 | | - logger.warn("Unable to find zone by id [{}], so skip downloading template to its image store [{}].", zoneId, imageStore); |
312 | | - return false; |
313 | | - } |
314 | | - |
315 | | - if (Grouping.AllocationState.Disabled == zone.getAllocationState()) { |
316 | | - logger.info("Zone [{}] is disabled. Skip downloading template to its image store [{}].", zone, imageStore); |
317 | | - return false; |
318 | | - } |
319 | | - |
320 | | - if (!_statsCollector.imageStoreHasEnoughCapacity(imageStore)) { |
321 | | - logger.info("Image store doesn't have enough capacity. Skip downloading template to this image store [{}].", imageStore); |
322 | | - return false; |
323 | | - } |
324 | | - |
325 | | - if (zoneSet == null) { |
326 | | - logger.info(String.format("Zone set is null; therefore, the ISO/template should be allocated in every secondary storage of zone [%s].", zone)); |
327 | | - return true; |
328 | | - } |
329 | | - |
330 | | - if (isTemplatePrivate && zoneSet.contains(zoneId)) { |
331 | | - logger.info(String.format("The template is private and it is already allocated in a secondary storage in zone [%s]; therefore, image store [%s] will be skipped.", |
332 | | - zone, imageStore)); |
333 | | - return false; |
334 | | - } |
335 | | - |
336 | | - logger.info(String.format("Private template will be allocated in image store [%s] in zone [%s].", imageStore, zone)); |
337 | | - zoneSet.add(zoneId); |
338 | | - return true; |
339 | | - } |
340 | | - |
341 | 297 | @Override |
342 | 298 | public List<TemplateOrVolumePostUploadCommand> createTemplateForPostUpload(final TemplateProfile profile) { |
343 | 299 | // 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. |
@@ -391,61 +347,6 @@ public List<TemplateOrVolumePostUploadCommand> doInTransaction(TransactionStatus |
391 | 347 | }); |
392 | 348 | } |
393 | 349 |
|
394 | | - /** |
395 | | - * If the template/ISO is marked as private, then it is allocated to a random secondary storage; otherwise, allocates to every storage pool in every zone given by the |
396 | | - * {@link TemplateProfile#getZoneIdList()}. |
397 | | - */ |
398 | | - protected void postUploadAllocation(List<DataStore> imageStores, VMTemplateVO template, List<TemplateOrVolumePostUploadCommand> payloads) { |
399 | | - Set<Long> zoneSet = new HashSet<>(); |
400 | | - Collections.shuffle(imageStores); |
401 | | - for (DataStore imageStore : imageStores) { |
402 | | - Long zoneId_is = imageStore.getScope().getScopeId(); |
403 | | - |
404 | | - if (!isZoneAndImageStoreAvailable(imageStore, zoneId_is, zoneSet, isPrivateTemplate(template))) { |
405 | | - continue; |
406 | | - } |
407 | | - |
408 | | - TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), imageStore); |
409 | | - |
410 | | - // persist template_store_ref entry |
411 | | - DataObject templateOnStore = imageStore.create(tmpl); |
412 | | - |
413 | | - // update template_store_ref and template state |
414 | | - EndPoint ep = _epSelector.select(templateOnStore); |
415 | | - if (ep == null) { |
416 | | - String errMsg = String.format("There is no secondary storage VM for downloading template to image store %s", imageStore); |
417 | | - logger.warn(errMsg); |
418 | | - throw new CloudRuntimeException(errMsg); |
419 | | - } |
420 | | - |
421 | | - TemplateOrVolumePostUploadCommand payload = new TemplateOrVolumePostUploadCommand(template.getId(), template.getUuid(), tmpl.getInstallPath(), tmpl |
422 | | - .getChecksum(), tmpl.getType().toString(), template.getUniqueName(), template.getFormat().toString(), templateOnStore.getDataStore().getUri(), |
423 | | - templateOnStore.getDataStore().getRole().toString()); |
424 | | - //using the existing max template size configuration |
425 | | - payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key())); |
426 | | - |
427 | | - Long accountId = template.getAccountId(); |
428 | | - Account account = _accountDao.findById(accountId); |
429 | | - Domain domain = _domainDao.findById(account.getDomainId()); |
430 | | - |
431 | | - payload.setDefaultMaxSecondaryStorageInGB(ByteScaleUtils.bytesToGibibytes(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage, null))); |
432 | | - payload.setAccountId(accountId); |
433 | | - payload.setRemoteEndPoint(ep.getPublicAddr()); |
434 | | - payload.setRequiresHvm(template.requiresHvm()); |
435 | | - payload.setDescription(template.getDisplayText()); |
436 | | - payloads.add(payload); |
437 | | - } |
438 | | - } |
439 | | - |
440 | | - protected boolean isPrivateTemplate(VMTemplateVO template){ |
441 | | - |
442 | | - // if public OR featured OR system template |
443 | | - if(template.isPublicTemplate() || template.isFeatured() || template.getTemplateType() == TemplateType.SYSTEM) |
444 | | - return false; |
445 | | - else |
446 | | - return true; |
447 | | - } |
448 | | - |
449 | 350 | private class CreateTemplateContext<T> extends AsyncRpcContext<T> { |
450 | 351 | final TemplateInfo template; |
451 | 352 |
|
|
0 commit comments