Skip to content

Commit 84f5768

Browse files
authored
[VMware][Deploy-as-is] OVF properties not importing when template is uploaded from local (apache#5861)
* Fix ova upload missing details * Refactor and cleanup * Unused import
1 parent 1ed0830 commit 84f5768

7 files changed

Lines changed: 69 additions & 94 deletions

File tree

core/src/main/java/org/apache/cloudstack/storage/command/UploadStatusAnswer.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package org.apache.cloudstack.storage.command;
2121

2222
import com.cloud.agent.api.Answer;
23-
import com.cloud.utils.Pair;
23+
import com.cloud.agent.api.to.OVFInformationTO;
2424

2525
public class UploadStatusAnswer extends Answer {
2626
public static enum UploadStatus {
@@ -32,8 +32,7 @@ public static enum UploadStatus {
3232
private long physicalSize = 0;
3333
private String installPath = null;
3434
private int downloadPercent = 0;
35-
private Pair<String, String> guestOsInfo;
36-
private String minimumHardwareVersion;
35+
private OVFInformationTO ovfInformationTO;
3736

3837
protected UploadStatusAnswer() {
3938
}
@@ -89,19 +88,11 @@ public void setDownloadPercent(int downloadPercent) {
8988
this.downloadPercent = downloadPercent;
9089
}
9190

92-
public Pair<String, String> getGuestOsInfo() {
93-
return guestOsInfo;
91+
public OVFInformationTO getOvfInformationTO() {
92+
return ovfInformationTO;
9493
}
9594

96-
public void setGuestOsInfo(Pair<String, String> guestOsInfo) {
97-
this.guestOsInfo = guestOsInfo;
98-
}
99-
100-
public void setMinimumHardwareVersion(String minimumHardwareVersion) {
101-
this.minimumHardwareVersion = minimumHardwareVersion;
102-
}
103-
104-
public String getMinimumHardwareVersion() {
105-
return minimumHardwareVersion;
95+
public void setOvfInformationTO(OVFInformationTO ovfInformationTO) {
96+
this.ovfInformationTO = ovfInformationTO;
10697
}
10798
}

engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javax.inject.Inject;
3434

3535
import com.cloud.agent.api.to.NfsTO;
36+
import com.cloud.agent.api.to.OVFInformationTO;
3637
import com.cloud.storage.DataStoreRole;
3738
import com.cloud.storage.Upload;
3839
import org.apache.cloudstack.storage.image.deployasis.DeployAsIsHelper;
@@ -207,8 +208,9 @@ protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends Bas
207208
TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
208209
if (tmpltStoreVO != null) {
209210
if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
210-
if (template.isDeployAsIs()) {
211-
boolean persistDeployAsIs = deployAsIsHelper.persistTemplateDeployAsIsDetails(template.getId(), answer, tmpltStoreVO);
211+
if (template.isDeployAsIs() && answer != null) {
212+
OVFInformationTO ovfInformationTO = answer.getOvfInformationTO();
213+
boolean persistDeployAsIs = deployAsIsHelper.persistTemplateOVFInformationAndUpdateGuestOS(template.getId(), ovfInformationTO, tmpltStoreVO);
212214
if (!persistDeployAsIs) {
213215
LOGGER.info("Failed persisting deploy-as-is template details for template " + template.getName());
214216
return null;

engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.cloudstack.storage.image.deployasis;
2020

21-
import com.cloud.agent.api.storage.DownloadAnswer;
2221
import com.cloud.agent.api.to.NicTO;
2322
import com.cloud.agent.api.to.OVFInformationTO;
2423
import com.cloud.agent.api.to.deployasis.OVFConfigurationTO;
@@ -100,41 +99,44 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper {
10099
gson = builder.create();
101100
}
102101

103-
public boolean persistTemplateDeployAsIsDetails(long templateId, DownloadAnswer answer, TemplateDataStoreVO tmpltStoreVO) {
102+
private void persistTemplateOVFInformation(long templateId, OVFInformationTO ovfInformationTO) {
103+
List<OVFPropertyTO> ovfProperties = ovfInformationTO.getProperties();
104+
List<OVFNetworkTO> networkRequirements = ovfInformationTO.getNetworks();
105+
OVFVirtualHardwareSectionTO ovfHardwareSection = ovfInformationTO.getHardwareSection();
106+
List<OVFEulaSectionTO> eulaSections = ovfInformationTO.getEulaSections();
107+
Pair<String, String> guestOsInfo = ovfInformationTO.getGuestOsInfo();
108+
109+
if (CollectionUtils.isNotEmpty(ovfProperties)) {
110+
persistTemplateDeployAsIsInformationTOList(templateId, ovfProperties);
111+
}
112+
if (CollectionUtils.isNotEmpty(networkRequirements)) {
113+
persistTemplateDeployAsIsInformationTOList(templateId, networkRequirements);
114+
}
115+
if (CollectionUtils.isNotEmpty(eulaSections)) {
116+
persistTemplateDeployAsIsInformationTOList(templateId, eulaSections);
117+
}
118+
String minimumHardwareVersion = null;
119+
if (ovfHardwareSection != null) {
120+
if (CollectionUtils.isNotEmpty(ovfHardwareSection.getConfigurations())) {
121+
persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getConfigurations());
122+
}
123+
if (CollectionUtils.isNotEmpty(ovfHardwareSection.getCommonHardwareItems())) {
124+
persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getCommonHardwareItems());
125+
}
126+
minimumHardwareVersion = ovfHardwareSection.getMinimiumHardwareVersion();
127+
}
128+
if (guestOsInfo != null) {
129+
String osType = guestOsInfo.first();
130+
String osDescription = guestOsInfo.second();
131+
LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription);
132+
handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion);
133+
}
134+
}
135+
136+
public boolean persistTemplateOVFInformationAndUpdateGuestOS(long templateId, OVFInformationTO ovfInformationTO, TemplateDataStoreVO tmpltStoreVO) {
104137
try {
105-
OVFInformationTO ovfInformationTO = answer.getOvfInformationTO();
106138
if (ovfInformationTO != null) {
107-
List<OVFPropertyTO> ovfProperties = ovfInformationTO.getProperties();
108-
List<OVFNetworkTO> networkRequirements = ovfInformationTO.getNetworks();
109-
OVFVirtualHardwareSectionTO ovfHardwareSection = ovfInformationTO.getHardwareSection();
110-
List<OVFEulaSectionTO> eulaSections = ovfInformationTO.getEulaSections();
111-
Pair<String, String> guestOsInfo = ovfInformationTO.getGuestOsInfo();
112-
113-
if (CollectionUtils.isNotEmpty(ovfProperties)) {
114-
persistTemplateDeployAsIsInformationTOList(templateId, ovfProperties);
115-
}
116-
if (CollectionUtils.isNotEmpty(networkRequirements)) {
117-
persistTemplateDeployAsIsInformationTOList(templateId, networkRequirements);
118-
}
119-
if (CollectionUtils.isNotEmpty(eulaSections)) {
120-
persistTemplateDeployAsIsInformationTOList(templateId, eulaSections);
121-
}
122-
String minimumHardwareVersion = null;
123-
if (ovfHardwareSection != null) {
124-
if (CollectionUtils.isNotEmpty(ovfHardwareSection.getConfigurations())) {
125-
persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getConfigurations());
126-
}
127-
if (CollectionUtils.isNotEmpty(ovfHardwareSection.getCommonHardwareItems())) {
128-
persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getCommonHardwareItems());
129-
}
130-
minimumHardwareVersion = ovfHardwareSection.getMinimiumHardwareVersion();
131-
}
132-
if (guestOsInfo != null) {
133-
String osType = guestOsInfo.first();
134-
String osDescription = guestOsInfo.second();
135-
LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription);
136-
handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion);
137-
}
139+
persistTemplateOVFInformation(templateId, ovfInformationTO);
138140
}
139141
} catch (Exception e) {
140142
LOGGER.error("Error persisting deploy-as-is details for template " + templateId, e);
@@ -151,7 +153,7 @@ public boolean persistTemplateDeployAsIsDetails(long templateId, DownloadAnswer
151153
/**
152154
* Returns the mapped guest OS from the OVF file of the template to the CloudStack database OS ID
153155
*/
154-
public Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription,
156+
private Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription,
155157
String minimumHardwareVersion) {
156158
VMTemplateVO template = templateDao.findById(templateId);
157159
Hypervisor.HypervisorType hypervisor = template.getHypervisorType();
@@ -337,7 +339,7 @@ public Map<Integer, String> getAllocatedVirtualMachineNicsAdapterMapping(Virtual
337339
return map;
338340
}
339341

340-
private void persistTemplateDeployAsIsInformationTOList(long templateId,
342+
public void persistTemplateDeployAsIsInformationTOList(long templateId,
341343
List<? extends TemplateDeployAsIsInformationTO> informationTOList) {
342344
for (TemplateDeployAsIsInformationTO informationTO : informationTOList) {
343345
String propKey = getKeyFromInformationTO(informationTO);

server/src/main/java/com/cloud/storage/ImageStoreUploadMonitorImpl.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28-
import com.cloud.hypervisor.Hypervisor;
29-
import com.cloud.utils.Pair;
28+
import com.cloud.agent.api.to.OVFInformationTO;
3029
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3130
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3231
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@ -412,18 +411,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
412411

413412
VMTemplateVO templateUpdate = _templateDao.createForUpdate();
414413
templateUpdate.setSize(answer.getVirtualSize());
415-
if (template.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
416-
Pair<String, String> guestOsInfo = answer.getGuestOsInfo();
417-
String minimumHardwareVersion = answer.getMinimumHardwareVersion();
418-
String osType = guestOsInfo.first();
419-
String osDescription = guestOsInfo.second();
420-
s_logger.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription);
421-
try {
422-
Long guestOsId = deployAsIsHelper.retrieveTemplateGuestOsIdFromGuestOsInfo(template.getId(),
423-
osType, osDescription, minimumHardwareVersion);
424-
templateUpdate.setGuestOSId(guestOsId);
425-
} catch (CloudRuntimeException e) {
426-
s_logger.error("Could not map the guest OS to a CloudStack guest OS", e);
414+
415+
OVFInformationTO ovfInformationTO = answer.getOvfInformationTO();
416+
if (template.isDeployAsIs() && ovfInformationTO != null) {
417+
s_logger.debug("Received OVF information from the uploaded template");
418+
boolean persistDeployAsIs = deployAsIsHelper.persistTemplateOVFInformationAndUpdateGuestOS(tmpTemplate.getId(), ovfInformationTO, tmpTemplateDataStore);
419+
if (!persistDeployAsIs) {
420+
s_logger.info("Failed persisting deploy-as-is template details for template " + template.getName());
421+
break;
427422
}
428423
}
429424
_templateDao.update(tmpTemplate.getId(), templateUpdate);

server/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelper.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.image.deployasis;
1818

19-
import com.cloud.agent.api.storage.DownloadAnswer;
2019
import com.cloud.agent.api.to.NicTO;
20+
import com.cloud.agent.api.to.OVFInformationTO;
2121
import com.cloud.vm.VirtualMachineProfile;
2222
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
2323

2424
import java.util.Map;
2525

2626
public interface DeployAsIsHelper {
2727

28-
boolean persistTemplateDeployAsIsDetails(long templateId, DownloadAnswer answer, TemplateDataStoreVO tmpltStoreVO);
28+
boolean persistTemplateOVFInformationAndUpdateGuestOS(long templateId, OVFInformationTO ovfInformationTO, TemplateDataStoreVO tmpltStoreVO);
2929
Map<String, String> getVirtualMachineDeployAsIsProperties(VirtualMachineProfile vmId);
3030
Map<Integer, String> getAllocatedVirtualMachineNicsAdapterMapping(VirtualMachineProfile vm, NicTO[] nics);
31-
Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription,
32-
String minimumHardwareVersion);
3331
}

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,8 +2280,9 @@ private UploadStatusAnswer execute(UploadStatusCommand cmd) {
22802280
answer.setInstallPath(uploadEntity.getTmpltPath());
22812281
answer.setPhysicalSize(uploadEntity.getPhysicalSize());
22822282
answer.setDownloadPercent(100);
2283-
answer.setGuestOsInfo(uploadEntity.getGuestOsInfo());
2284-
answer.setMinimumHardwareVersion(uploadEntity.getMinimumHardwareVersion());
2283+
if (uploadEntity.getOvfInformationTO() != null) {
2284+
answer.setOvfInformationTO(uploadEntity.getOvfInformationTO());
2285+
}
22852286
uploadEntityStateMap.remove(entityUuid);
22862287
return answer;
22872288
} else if (uploadEntity.getUploadState() == UploadEntity.Status.IN_PROGRESS) {
@@ -3424,12 +3425,7 @@ public String postUpload(String uuid, String filename, long processTimeout) {
34243425
uploadEntity.setVirtualSize(info.virtualSize);
34253426
uploadEntity.setPhysicalSize(info.size);
34263427
if (info.ovfInformationTO != null) {
3427-
if (info.ovfInformationTO.getGuestOsInfo() != null) {
3428-
uploadEntity.setGuestOsInfo(info.ovfInformationTO.getGuestOsInfo());
3429-
}
3430-
if (info.ovfInformationTO.getHardwareSection() != null) {
3431-
uploadEntity.setMinimumHardwareVersion(info.ovfInformationTO.getHardwareSection().getMinimiumHardwareVersion());
3432-
}
3428+
uploadEntity.setOvfInformationTO(info.ovfInformationTO);
34333429
}
34343430
break;
34353431
}

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadEntity.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package org.apache.cloudstack.storage.template;
1919

2020

21+
import com.cloud.agent.api.to.OVFInformationTO;
2122
import com.cloud.storage.Storage;
22-
import com.cloud.utils.Pair;
2323

2424
public class UploadEntity {
2525
private long downloadedsize;
@@ -36,8 +36,7 @@ public class UploadEntity {
3636
private String description;
3737
private long contentLength;
3838
private long processTimeout;
39-
private Pair<String, String> guestOsInfo;
40-
private String minimumHardwareVersion;
39+
private OVFInformationTO ovfInformationTO;
4140

4241
public static enum ResourceType {
4342
VOLUME, TEMPLATE
@@ -211,19 +210,11 @@ public void setContentLength(long contentLength) {
211210
this.contentLength = contentLength;
212211
}
213212

214-
public Pair<String, String> getGuestOsInfo() {
215-
return guestOsInfo;
213+
public OVFInformationTO getOvfInformationTO() {
214+
return ovfInformationTO;
216215
}
217216

218-
public void setGuestOsInfo(Pair<String, String> guestOsInfo) {
219-
this.guestOsInfo = guestOsInfo;
220-
}
221-
222-
public void setMinimumHardwareVersion(String minimumHardwareVersion) {
223-
this.minimumHardwareVersion = minimumHardwareVersion;
224-
}
225-
226-
public String getMinimumHardwareVersion() {
227-
return minimumHardwareVersion;
217+
public void setOvfInformationTO(OVFInformationTO ovfInformationTO) {
218+
this.ovfInformationTO = ovfInformationTO;
228219
}
229220
}

0 commit comments

Comments
 (0)