This is an automated email from the ASF dual-hosted git repository.

nvazquez pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit eaab991a44a3a8428cbce6793451db2f2b2df5a6
Merge: 3d8d4875fe3 7a9bb835bc7
Author: nvazquez <nicovazque...@gmail.com>
AuthorDate: Tue Aug 20 11:29:05 2024 -0300

    Merge branch '4.18' into 4.19

 .../java/com/cloud/template/HypervisorTemplateAdapter.java   | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --cc server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
index da47fe66311,7fdabf3a8cd..0090b35fb21
--- a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
@@@ -412,27 -361,90 +414,37 @@@ public class HypervisorTemplateAdapter 
                      throw new CloudRuntimeException("Unable to persist the 
template " + profile.getTemplate());
                  }
  
 +                List<Long> zoneIdList = profile.getZoneIdList();
 +
 +                if (zoneIdList == null) {
 +                    throw new CloudRuntimeException("Zone ID is null, cannot 
upload ISO/template.");
 +                }
 +
 +                if (zoneIdList.size() > 1)
 +                    throw new CloudRuntimeException("Operation is not 
supported for more than one zone id at a time.");
 +
+                 // Set Event Details for Template/ISO Upload
+                 String eventType = 
template.getFormat().equals(ImageFormat.ISO) ? "Iso" : "Template";
+                 String eventResourceId = template.getUuid();
+                 CallContext.current().setEventDetails(String.format("%s Id: 
%s", eventType, eventResourceId));
+                 
CallContext.current().putContextParameter(eventType.equals("Iso") ? eventType : 
VirtualMachineTemplate.class, eventResourceId);
+                 if (template.getFormat().equals(ImageFormat.ISO)) {
+                     
CallContext.current().setEventResourceType(ApiCommandResourceType.Iso);
+                     
CallContext.current().setEventResourceId(template.getId());
+                 }
+ 
 -                if (profile.getZoneIdList() != null && 
profile.getZoneIdList().size() > 1)
 -                    throw new CloudRuntimeException("Operation is not 
supported for more than one zone id at a time");
 +                Long zoneId = zoneIdList.get(0);
 +                DataStore imageStore = verifyHeuristicRulesForZone(template, 
zoneId);
 +                List<TemplateOrVolumePostUploadCommand> payloads = new 
LinkedList<>();
  
 -                Long zoneId = null;
 -                if (profile.getZoneIdList() != null)
 -                    zoneId = profile.getZoneIdList().get(0);
 +                if (imageStore == null) {
 +                    List<DataStore> imageStores = 
getImageStoresThrowsExceptionIfNotFound(zoneId, profile);
 +                    postUploadAllocation(imageStores, template, payloads);
 +                } else {
 +                    postUploadAllocation(List.of(imageStore), template, 
payloads);
  
 -                // find all eligible image stores for this zone scope
 -                List<DataStore> imageStores = 
storeMgr.getImageStoresByScopeExcludingReadOnly(new ZoneScope(zoneId));
 -                if (imageStores == null || imageStores.size() == 0) {
 -                    throw new CloudRuntimeException("Unable to find image 
store to download template " + profile.getTemplate());
                  }
  
 -                List<TemplateOrVolumePostUploadCommand> payloads = new 
LinkedList<>();
 -                Set<Long> zoneSet = new HashSet<Long>();
 -                Collections.shuffle(imageStores); // For private templates 
choose a random store. TODO - Have a better algorithm based on size, no. of 
objects, load etc.
 -                for (DataStore imageStore : imageStores) {
 -                    // skip data stores for a disabled zone
 -                    Long zoneId_is = imageStore.getScope().getScopeId();
 -                    if (zoneId != null) {
 -                        DataCenterVO zone = _dcDao.findById(zoneId_is);
 -                        if (zone == null) {
 -                            s_logger.warn("Unable to find zone by id " + 
zoneId_is +
 -                                        ", so skip downloading template to 
its image store " + imageStore.getId());
 -                            continue;
 -                        }
 -
 -                        // Check if zone is disabled
 -                        if (Grouping.AllocationState.Disabled == 
zone.getAllocationState()) {
 -                            s_logger.info("Zone " + zoneId_is +
 -                                    " is disabled, so skip downloading 
template to its image store " + imageStore.getId());
 -                            continue;
 -                        }
 -
 -                        // We want to download private template to one of the 
image store in a zone
 -                        if (isPrivateTemplate(template) && 
zoneSet.contains(zoneId_is)) {
 -                            continue;
 -                        } else {
 -                            zoneSet.add(zoneId_is);
 -                        }
 -
 -                    }
 -
 -                    TemplateInfo tmpl = 
imageFactory.getTemplate(template.getId(), imageStore);
 -                    //imageService.createTemplateAsync(tmpl, imageStore, 
caller);
 -
 -                    // persist template_store_ref entry
 -                    DataObject templateOnStore = imageStore.create(tmpl);
 -                    // update template_store_ref and template state
 -
 -                    EndPoint ep = _epSelector.select(templateOnStore);
 -                    if (ep == null) {
 -                        String errMsg = "There is no secondary storage VM for 
downloading template to image store " + imageStore.getName();
 -                        s_logger.warn(errMsg);
 -                        throw new CloudRuntimeException(errMsg);
 -                    }
 -
 -                    TemplateOrVolumePostUploadCommand payload = new 
TemplateOrVolumePostUploadCommand(template.getId(), template.getUuid(), 
tmpl.getInstallPath(), tmpl
 -                            .getChecksum(), tmpl.getType().toString(), 
template.getUniqueName(), template.getFormat().toString(), 
templateOnStore.getDataStore().getUri(),
 -                            
templateOnStore.getDataStore().getRole().toString());
 -                    //using the existing max template size configuration
 -                    
payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key()));
 -
 -                    Long accountId = template.getAccountId();
 -                    Account account = _accountDao.findById(accountId);
 -                    Domain domain = 
_domainDao.findById(account.getDomainId());
 -
 -                    
payload.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account,
 domain, ResourceType.secondary_storage));
 -                    payload.setAccountId(accountId);
 -                    payload.setRemoteEndPoint(ep.getPublicAddr());
 -                    payload.setRequiresHvm(template.requiresHvm());
 -                    payload.setDescription(template.getDisplayText());
 -                    payloads.add(payload);
 -                }
                  if(payloads.isEmpty()) {
                      throw new CloudRuntimeException("unable to find zone or 
an image store with enough capacity");
                  }

Reply via email to