From 84f5768e64bdc316a586cfa149e4ac591ade5a1b Mon Sep 17 00:00:00 2001 From: Nicolas Vazquez Date: Wed, 26 Jan 2022 02:58:52 -0300 Subject: [PATCH] [VMware][Deploy-as-is] OVF properties not importing when template is uploaded from local (#5861) * Fix ova upload missing details * Refactor and cleanup * Unused import --- .../storage/command/UploadStatusAnswer.java | 21 ++--- .../image/BaseImageStoreDriverImpl.java | 6 +- .../deployasis/DeployAsIsHelperImpl.java | 76 ++++++++++--------- .../storage/ImageStoreUploadMonitorImpl.java | 23 +++--- .../image/deployasis/DeployAsIsHelper.java | 6 +- .../resource/NfsSecondaryStorageResource.java | 12 +-- .../storage/template/UploadEntity.java | 21 ++--- 7 files changed, 70 insertions(+), 95 deletions(-) diff --git a/core/src/main/java/org/apache/cloudstack/storage/command/UploadStatusAnswer.java b/core/src/main/java/org/apache/cloudstack/storage/command/UploadStatusAnswer.java index 5c880c3de98..ee89ec0c486 100644 --- a/core/src/main/java/org/apache/cloudstack/storage/command/UploadStatusAnswer.java +++ b/core/src/main/java/org/apache/cloudstack/storage/command/UploadStatusAnswer.java @@ -20,7 +20,7 @@ package org.apache.cloudstack.storage.command; import com.cloud.agent.api.Answer; -import com.cloud.utils.Pair; +import com.cloud.agent.api.to.OVFInformationTO; public class UploadStatusAnswer extends Answer { public static enum UploadStatus { @@ -32,8 +32,7 @@ public class UploadStatusAnswer extends Answer { private long physicalSize = 0; private String installPath = null; private int downloadPercent = 0; - private Pair guestOsInfo; - private String minimumHardwareVersion; + private OVFInformationTO ovfInformationTO; protected UploadStatusAnswer() { } @@ -89,19 +88,11 @@ public class UploadStatusAnswer extends Answer { this.downloadPercent = downloadPercent; } - public Pair getGuestOsInfo() { - return guestOsInfo; + public OVFInformationTO getOvfInformationTO() { + return ovfInformationTO; } - public void setGuestOsInfo(Pair guestOsInfo) { - this.guestOsInfo = guestOsInfo; - } - - public void setMinimumHardwareVersion(String minimumHardwareVersion) { - this.minimumHardwareVersion = minimumHardwareVersion; - } - - public String getMinimumHardwareVersion() { - return minimumHardwareVersion; + public void setOvfInformationTO(OVFInformationTO ovfInformationTO) { + this.ovfInformationTO = ovfInformationTO; } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java index 0c55545d66a..3ef9fbc4225 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java @@ -33,6 +33,7 @@ import java.util.stream.Collectors; import javax.inject.Inject; import com.cloud.agent.api.to.NfsTO; +import com.cloud.agent.api.to.OVFInformationTO; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Upload; import org.apache.cloudstack.storage.image.deployasis.DeployAsIsHelper; @@ -207,8 +208,9 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId()); if (tmpltStoreVO != null) { if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { - if (template.isDeployAsIs()) { - boolean persistDeployAsIs = deployAsIsHelper.persistTemplateDeployAsIsDetails(template.getId(), answer, tmpltStoreVO); + if (template.isDeployAsIs() && answer != null) { + OVFInformationTO ovfInformationTO = answer.getOvfInformationTO(); + boolean persistDeployAsIs = deployAsIsHelper.persistTemplateOVFInformationAndUpdateGuestOS(template.getId(), ovfInformationTO, tmpltStoreVO); if (!persistDeployAsIs) { LOGGER.info("Failed persisting deploy-as-is template details for template " + template.getName()); return null; diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java index 9d26da84bf6..0fac4791053 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.storage.image.deployasis; -import com.cloud.agent.api.storage.DownloadAnswer; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.OVFInformationTO; import com.cloud.agent.api.to.deployasis.OVFConfigurationTO; @@ -100,41 +99,44 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { gson = builder.create(); } - public boolean persistTemplateDeployAsIsDetails(long templateId, DownloadAnswer answer, TemplateDataStoreVO tmpltStoreVO) { - try { - OVFInformationTO ovfInformationTO = answer.getOvfInformationTO(); - if (ovfInformationTO != null) { - List ovfProperties = ovfInformationTO.getProperties(); - List networkRequirements = ovfInformationTO.getNetworks(); - OVFVirtualHardwareSectionTO ovfHardwareSection = ovfInformationTO.getHardwareSection(); - List eulaSections = ovfInformationTO.getEulaSections(); - Pair guestOsInfo = ovfInformationTO.getGuestOsInfo(); + private void persistTemplateOVFInformation(long templateId, OVFInformationTO ovfInformationTO) { + List ovfProperties = ovfInformationTO.getProperties(); + List networkRequirements = ovfInformationTO.getNetworks(); + OVFVirtualHardwareSectionTO ovfHardwareSection = ovfInformationTO.getHardwareSection(); + List eulaSections = ovfInformationTO.getEulaSections(); + Pair guestOsInfo = ovfInformationTO.getGuestOsInfo(); - if (CollectionUtils.isNotEmpty(ovfProperties)) { - persistTemplateDeployAsIsInformationTOList(templateId, ovfProperties); - } - if (CollectionUtils.isNotEmpty(networkRequirements)) { - persistTemplateDeployAsIsInformationTOList(templateId, networkRequirements); - } - if (CollectionUtils.isNotEmpty(eulaSections)) { - persistTemplateDeployAsIsInformationTOList(templateId, eulaSections); - } - String minimumHardwareVersion = null; - if (ovfHardwareSection != null) { - if (CollectionUtils.isNotEmpty(ovfHardwareSection.getConfigurations())) { - persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getConfigurations()); - } - if (CollectionUtils.isNotEmpty(ovfHardwareSection.getCommonHardwareItems())) { - persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getCommonHardwareItems()); - } - minimumHardwareVersion = ovfHardwareSection.getMinimiumHardwareVersion(); - } - if (guestOsInfo != null) { - String osType = guestOsInfo.first(); - String osDescription = guestOsInfo.second(); - LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); - handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion); - } + if (CollectionUtils.isNotEmpty(ovfProperties)) { + persistTemplateDeployAsIsInformationTOList(templateId, ovfProperties); + } + if (CollectionUtils.isNotEmpty(networkRequirements)) { + persistTemplateDeployAsIsInformationTOList(templateId, networkRequirements); + } + if (CollectionUtils.isNotEmpty(eulaSections)) { + persistTemplateDeployAsIsInformationTOList(templateId, eulaSections); + } + String minimumHardwareVersion = null; + if (ovfHardwareSection != null) { + if (CollectionUtils.isNotEmpty(ovfHardwareSection.getConfigurations())) { + persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getConfigurations()); + } + if (CollectionUtils.isNotEmpty(ovfHardwareSection.getCommonHardwareItems())) { + persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getCommonHardwareItems()); + } + minimumHardwareVersion = ovfHardwareSection.getMinimiumHardwareVersion(); + } + if (guestOsInfo != null) { + String osType = guestOsInfo.first(); + String osDescription = guestOsInfo.second(); + LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); + handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion); + } + } + + public boolean persistTemplateOVFInformationAndUpdateGuestOS(long templateId, OVFInformationTO ovfInformationTO, TemplateDataStoreVO tmpltStoreVO) { + try { + if (ovfInformationTO != null) { + persistTemplateOVFInformation(templateId, ovfInformationTO); } } catch (Exception e) { LOGGER.error("Error persisting deploy-as-is details for template " + templateId, e); @@ -151,7 +153,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { /** * Returns the mapped guest OS from the OVF file of the template to the CloudStack database OS ID */ - public Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription, + private Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription, String minimumHardwareVersion) { VMTemplateVO template = templateDao.findById(templateId); Hypervisor.HypervisorType hypervisor = template.getHypervisorType(); @@ -337,7 +339,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { return map; } - private void persistTemplateDeployAsIsInformationTOList(long templateId, + public void persistTemplateDeployAsIsInformationTOList(long templateId, List informationTOList) { for (TemplateDeployAsIsInformationTO informationTO : informationTOList) { String propKey = getKeyFromInformationTO(informationTO); diff --git a/server/src/main/java/com/cloud/storage/ImageStoreUploadMonitorImpl.java b/server/src/main/java/com/cloud/storage/ImageStoreUploadMonitorImpl.java index 072092780ea..7916f4afe3d 100755 --- a/server/src/main/java/com/cloud/storage/ImageStoreUploadMonitorImpl.java +++ b/server/src/main/java/com/cloud/storage/ImageStoreUploadMonitorImpl.java @@ -25,8 +25,7 @@ import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.hypervisor.Hypervisor; -import com.cloud.utils.Pair; +import com.cloud.agent.api.to.OVFInformationTO; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; @@ -412,18 +411,14 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto VMTemplateVO templateUpdate = _templateDao.createForUpdate(); templateUpdate.setSize(answer.getVirtualSize()); - if (template.getHypervisorType() == Hypervisor.HypervisorType.VMware) { - Pair guestOsInfo = answer.getGuestOsInfo(); - String minimumHardwareVersion = answer.getMinimumHardwareVersion(); - String osType = guestOsInfo.first(); - String osDescription = guestOsInfo.second(); - s_logger.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); - try { - Long guestOsId = deployAsIsHelper.retrieveTemplateGuestOsIdFromGuestOsInfo(template.getId(), - osType, osDescription, minimumHardwareVersion); - templateUpdate.setGuestOSId(guestOsId); - } catch (CloudRuntimeException e) { - s_logger.error("Could not map the guest OS to a CloudStack guest OS", e); + + OVFInformationTO ovfInformationTO = answer.getOvfInformationTO(); + if (template.isDeployAsIs() && ovfInformationTO != null) { + s_logger.debug("Received OVF information from the uploaded template"); + boolean persistDeployAsIs = deployAsIsHelper.persistTemplateOVFInformationAndUpdateGuestOS(tmpTemplate.getId(), ovfInformationTO, tmpTemplateDataStore); + if (!persistDeployAsIs) { + s_logger.info("Failed persisting deploy-as-is template details for template " + template.getName()); + break; } } _templateDao.update(tmpTemplate.getId(), templateUpdate); diff --git a/server/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelper.java b/server/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelper.java index a04b043f228..c1be0d82d7c 100644 --- a/server/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelper.java +++ b/server/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelper.java @@ -16,8 +16,8 @@ // under the License. package org.apache.cloudstack.storage.image.deployasis; -import com.cloud.agent.api.storage.DownloadAnswer; import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.OVFInformationTO; import com.cloud.vm.VirtualMachineProfile; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; @@ -25,9 +25,7 @@ import java.util.Map; public interface DeployAsIsHelper { - boolean persistTemplateDeployAsIsDetails(long templateId, DownloadAnswer answer, TemplateDataStoreVO tmpltStoreVO); + boolean persistTemplateOVFInformationAndUpdateGuestOS(long templateId, OVFInformationTO ovfInformationTO, TemplateDataStoreVO tmpltStoreVO); Map getVirtualMachineDeployAsIsProperties(VirtualMachineProfile vmId); Map getAllocatedVirtualMachineNicsAdapterMapping(VirtualMachineProfile vm, NicTO[] nics); - Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription, - String minimumHardwareVersion); } diff --git a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index 565c4dfb98c..ed5530c3fff 100644 --- a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -2280,8 +2280,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S answer.setInstallPath(uploadEntity.getTmpltPath()); answer.setPhysicalSize(uploadEntity.getPhysicalSize()); answer.setDownloadPercent(100); - answer.setGuestOsInfo(uploadEntity.getGuestOsInfo()); - answer.setMinimumHardwareVersion(uploadEntity.getMinimumHardwareVersion()); + if (uploadEntity.getOvfInformationTO() != null) { + answer.setOvfInformationTO(uploadEntity.getOvfInformationTO()); + } uploadEntityStateMap.remove(entityUuid); return answer; } else if (uploadEntity.getUploadState() == UploadEntity.Status.IN_PROGRESS) { @@ -3424,12 +3425,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S uploadEntity.setVirtualSize(info.virtualSize); uploadEntity.setPhysicalSize(info.size); if (info.ovfInformationTO != null) { - if (info.ovfInformationTO.getGuestOsInfo() != null) { - uploadEntity.setGuestOsInfo(info.ovfInformationTO.getGuestOsInfo()); - } - if (info.ovfInformationTO.getHardwareSection() != null) { - uploadEntity.setMinimumHardwareVersion(info.ovfInformationTO.getHardwareSection().getMinimiumHardwareVersion()); - } + uploadEntity.setOvfInformationTO(info.ovfInformationTO); } break; } diff --git a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadEntity.java b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadEntity.java index 6d5154e8ef8..8acf4d788e8 100644 --- a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadEntity.java +++ b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadEntity.java @@ -18,8 +18,8 @@ package org.apache.cloudstack.storage.template; +import com.cloud.agent.api.to.OVFInformationTO; import com.cloud.storage.Storage; -import com.cloud.utils.Pair; public class UploadEntity { private long downloadedsize; @@ -36,8 +36,7 @@ public class UploadEntity { private String description; private long contentLength; private long processTimeout; - private Pair guestOsInfo; - private String minimumHardwareVersion; + private OVFInformationTO ovfInformationTO; public static enum ResourceType { VOLUME, TEMPLATE @@ -211,19 +210,11 @@ public class UploadEntity { this.contentLength = contentLength; } - public Pair getGuestOsInfo() { - return guestOsInfo; + public OVFInformationTO getOvfInformationTO() { + return ovfInformationTO; } - public void setGuestOsInfo(Pair guestOsInfo) { - this.guestOsInfo = guestOsInfo; - } - - public void setMinimumHardwareVersion(String minimumHardwareVersion) { - this.minimumHardwareVersion = minimumHardwareVersion; - } - - public String getMinimumHardwareVersion() { - return minimumHardwareVersion; + public void setOvfInformationTO(OVFInformationTO ovfInformationTO) { + this.ovfInformationTO = ovfInformationTO; } }