use of com.cloud.agent.api.to.OVFInformationTO in project cloudstack by apache.
the class DownloadAnswerTest method properties.
@Test
public void properties() {
List<OVFPropertyTO> properties = new ArrayList<>();
properties.add(new OVFPropertyTO());
List<OVFNetworkTO> networks = new ArrayList<>();
networks.add(new OVFNetworkTO());
OVFInformationTO informationTO = new OVFInformationTO();
informationTO.setProperties(properties);
informationTO.setNetworks(networks);
answer.setOvfInformationTO(informationTO);
String json = gson.toJson(answer);
Answer received = gson.fromJson(json, Answer.class);
Assert.assertEquals(received, answer);
}
use of com.cloud.agent.api.to.OVFInformationTO in project cloudstack by apache.
the class OVAProcessor method validateOva.
/**
* side effect; properties are added to the info
*
* @throws InternalErrorException on an invalid ova contents
*/
private void validateOva(String templateFileFullPath, FormatInfo info) throws InternalErrorException {
String ovfFilePath = getOVFFilePath(templateFileFullPath);
OVFHelper ovfHelper = new OVFHelper();
Document doc = ovfHelper.getOvfParser().parseOVFFile(ovfFilePath);
OVFInformationTO ovfInformationTO = createOvfInformationTO(ovfHelper, doc, ovfFilePath);
info.ovfInformationTO = ovfInformationTO;
}
use of com.cloud.agent.api.to.OVFInformationTO in project cloudstack by apache.
the class OVAProcessor method createOvfInformationTO.
private OVFInformationTO createOvfInformationTO(OVFHelper ovfHelper, Document doc, String ovfFilePath) throws InternalErrorException {
OVFInformationTO ovfInformationTO = new OVFInformationTO();
List<DatadiskTO> disks = ovfHelper.getOVFVolumeInfoFromFile(ovfFilePath, doc, null);
if (CollectionUtils.isNotEmpty(disks)) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(String.format("Found %d disks in template %s", disks.size(), ovfFilePath));
}
ovfInformationTO.setDisks(disks);
}
List<OVFNetworkTO> nets = ovfHelper.getNetPrerequisitesFromDocument(doc);
if (CollectionUtils.isNotEmpty(nets)) {
LOGGER.info("Found " + nets.size() + " prerequisite networks");
ovfInformationTO.setNetworks(nets);
} else if (LOGGER.isTraceEnabled()) {
LOGGER.trace(String.format("no net prerequisites found in template %s", ovfFilePath));
}
List<OVFPropertyTO> ovfProperties = ovfHelper.getConfigurableOVFPropertiesFromDocument(doc);
if (CollectionUtils.isNotEmpty(ovfProperties)) {
LOGGER.info("Found " + ovfProperties.size() + " configurable OVF properties");
ovfInformationTO.setProperties(ovfProperties);
} else if (LOGGER.isTraceEnabled()) {
LOGGER.trace(String.format("no ovf properties found in template %s", ovfFilePath));
}
OVFVirtualHardwareSectionTO hardwareSection = ovfHelper.getVirtualHardwareSectionFromDocument(doc);
List<OVFConfigurationTO> configurations = hardwareSection.getConfigurations();
if (CollectionUtils.isNotEmpty(configurations)) {
LOGGER.info("Found " + configurations.size() + " deployment option configurations");
}
List<OVFVirtualHardwareItemTO> hardwareItems = hardwareSection.getCommonHardwareItems();
if (CollectionUtils.isNotEmpty(hardwareItems)) {
LOGGER.info("Found " + hardwareItems.size() + " virtual hardware items");
}
if (StringUtils.isNotBlank(hardwareSection.getMinimiumHardwareVersion())) {
LOGGER.info("Found minimum hardware version " + hardwareSection.getMinimiumHardwareVersion());
}
ovfInformationTO.setHardwareSection(hardwareSection);
List<OVFEulaSectionTO> eulaSections = ovfHelper.getEulaSectionsFromDocument(doc);
if (CollectionUtils.isNotEmpty(eulaSections)) {
LOGGER.info("Found " + eulaSections.size() + " license agreements");
ovfInformationTO.setEulaSections(eulaSections);
}
Pair<String, String> guestOsPair = ovfHelper.getOperatingSystemInfoFromDocument(doc);
if (guestOsPair != null) {
LOGGER.info("Found guest OS information: " + guestOsPair.first() + " - " + guestOsPair.second());
ovfInformationTO.setGuestOsInfo(guestOsPair);
}
return ovfInformationTO;
}
use of com.cloud.agent.api.to.OVFInformationTO in project cloudstack by apache.
the class BaseImageStoreDriverImpl method createTemplateAsyncCallback.
protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, CreateContext<CreateCmdResult> context) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Performing image store createTemplate async callback");
}
DownloadAnswer answer = callback.getResult();
DataObject obj = context.data;
DataStore store = obj.getDataStore();
VMTemplateVO template = _templateDao.findById(obj.getId());
TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
if (tmpltStoreVO != null) {
if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
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;
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
}
return null;
}
LOGGER.info("Updating store ref entry for template " + template.getName());
TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate();
updateBuilder.setDownloadPercent(answer.getDownloadPct());
updateBuilder.setDownloadState(answer.getDownloadStatus());
updateBuilder.setLastUpdated(new Date());
updateBuilder.setErrorString(answer.getErrorString());
updateBuilder.setJobId(answer.getJobId());
updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
updateBuilder.setInstallPath(answer.getInstallPath());
updateBuilder.setSize(answer.getTemplateSize());
updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
_templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
// update size in vm_template table
VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
tmlptUpdater.setSize(answer.getTemplateSize());
_templateDao.update(obj.getId(), tmlptUpdater);
}
AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
CreateCmdResult result = new CreateCmdResult(null, null);
result.setSuccess(false);
result.setResult(answer.getErrorString());
caller.complete(result);
String msg = "Failed to register template: " + obj.getUuid() + " with error: " + answer.getErrorString();
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, _vmTemplateZoneDao.listByTemplateId(obj.getId()).get(0).getZoneId(), null, msg, msg);
LOGGER.error(msg);
} else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
if (answer.getCheckSum() != null) {
VMTemplateVO templateDaoBuilder = _templateDao.createForUpdate();
templateDaoBuilder.setChecksum(answer.getCheckSum());
_templateDao.update(obj.getId(), templateDaoBuilder);
}
CreateCmdResult result = new CreateCmdResult(null, null);
caller.complete(result);
}
return null;
}
Aggregations