Search in sources :

Example 1 with OVFInformationTO

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);
}
Also used : Answer(com.cloud.agent.api.Answer) OVFInformationTO(com.cloud.agent.api.to.OVFInformationTO) ArrayList(java.util.ArrayList) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) Test(org.junit.Test)

Example 2 with OVFInformationTO

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;
}
Also used : OVFInformationTO(com.cloud.agent.api.to.OVFInformationTO) OVFHelper(com.cloud.agent.api.storage.OVFHelper) Document(org.w3c.dom.Document)

Example 3 with 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;
}
Also used : OVFInformationTO(com.cloud.agent.api.to.OVFInformationTO) OVFConfigurationTO(com.cloud.agent.api.to.deployasis.OVFConfigurationTO) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) OVFEulaSectionTO(com.cloud.agent.api.to.deployasis.OVFEulaSectionTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) OVFVirtualHardwareSectionTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO)

Example 4 with 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;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) OVFInformationTO(com.cloud.agent.api.to.OVFInformationTO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Aggregations

OVFInformationTO (com.cloud.agent.api.to.OVFInformationTO)4 OVFNetworkTO (com.cloud.agent.api.to.deployasis.OVFNetworkTO)2 OVFPropertyTO (com.cloud.agent.api.to.deployasis.OVFPropertyTO)2 Answer (com.cloud.agent.api.Answer)1 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)1 OVFHelper (com.cloud.agent.api.storage.OVFHelper)1 DatadiskTO (com.cloud.agent.api.to.DatadiskTO)1 OVFConfigurationTO (com.cloud.agent.api.to.deployasis.OVFConfigurationTO)1 OVFEulaSectionTO (com.cloud.agent.api.to.deployasis.OVFEulaSectionTO)1 OVFVirtualHardwareItemTO (com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO)1 OVFVirtualHardwareSectionTO (com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)1 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1