Search in sources :

Example 16 with OvfEntityData

use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.

the class StorageHandlingCommandBase method getEntitiesFromStorageOvfDisk.

protected List<OvfEntityData> getEntitiesFromStorageOvfDisk(Guid storageDomainId, Guid storagePoolId) {
    // Initialize a new ArrayList with all the ovfDisks in the specified Storage Domain,
    // so the entities can be removed from the list every time we register the latest OVF disk and we can keep the
    // ovfDisks cache list updated.
    List<DiskImage> ovfStoreDiskImages = new ArrayList<>(getAllOVFDisks(storageDomainId, storagePoolId));
    if (!ovfStoreDiskImages.isEmpty()) {
        while (!ovfStoreDiskImages.isEmpty()) {
            Pair<DiskImage, Long> ovfDiskAndSize = getLatestOVFDisk(ovfStoreDiskImages);
            DiskImage ovfDisk = ovfDiskAndSize.getFirst();
            if (ovfDisk != null) {
                try {
                    ActionReturnValue actionReturnValueReturnValue = runInternalAction(ActionType.RetrieveImageData, new RetrieveImageDataParameters(getParameters().getStoragePoolId(), storageDomainId, ovfDisk.getId(), ovfDisk.getImage().getId(), ovfDiskAndSize.getSecond()), cloneContextAndDetachFromParent());
                    getReturnValue().getVdsmTaskIdList().addAll(actionReturnValueReturnValue.getInternalVdsmTaskIdList());
                    if (actionReturnValueReturnValue.getSucceeded()) {
                        List<OvfEntityData> returnedMap = ovfUtils.getOvfEntities(actionReturnValueReturnValue.getActionReturnValue(), unregisteredDisks, storageDomainId);
                        return returnedMap;
                    } else {
                        log.error("Image data could not be retrieved for disk id '{}' in storage domain id '{}'", ovfDisk.getId(), storageDomainId);
                    }
                } catch (RuntimeException e) {
                    // We are catching RuntimeException, since the call for OvfUtils.getOvfEntities will throw
                    // a RuntimeException if there is a problem to untar the file.
                    log.error("Image data could not be retrieved for disk id '{}' in storage domain id '{}': {}", ovfDisk.getId(), storageDomainId, e.getMessage());
                    log.debug("Exception", e);
                }
                ovfStoreDiskImages.remove(ovfDisk);
            } else {
                log.error("Couldn't find additional ovf store to retrieve the ovf data from in storage domain '{}'", storageDomainId);
                break;
            }
        }
        AuditLogable logable = new AuditLogableImpl();
        logable.setStorageDomainId(storageDomainId);
        logable.setStorageDomainName(storageDomainStaticDao.get(storageDomainId).getName());
        auditLogDirector.log(logable, AuditLogType.RETRIEVE_OVF_STORE_FAILED);
    } else {
        log.warn("There are no OVF_STORE disks on storage domain id {}", storageDomainId);
    }
    return new ArrayList<>();
}
Also used : AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) RetrieveImageDataParameters(org.ovirt.engine.core.bll.RetrieveImageDataParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 17 with OvfEntityData

use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.

the class OvfUtils method getOvfEntities.

public List<OvfEntityData> getOvfEntities(byte[] tar, List<UnregisteredDisk> unregisteredDisks, Guid storageDomainId) {
    List<OvfEntityData> ovfEntityDataFromTar = new ArrayList<>();
    InputStream is = new ByteArrayInputStream(tar);
    log.info("Start fetching files from tar file");
    Map<String, ByteBuffer> filesFromTar;
    try (TarInMemoryExport memoryTar = new TarInMemoryExport(is)) {
        filesFromTar = memoryTar.unTar();
    } catch (IOException e) {
        throw new RuntimeException(String.format("Exception while getting OVFs files from tar file for domain %s", storageDomainId), e);
    }
    Entry<String, ByteBuffer> metaDataFileEntry = null;
    for (Entry<String, ByteBuffer> fileEntry : filesFromTar.entrySet()) {
        if (fileEntry.getKey().endsWith(OVF_FILE_EXT)) {
            analyzeOvfFile(unregisteredDisks, storageDomainId, ovfEntityDataFromTar, fileEntry);
        } else if (fileEntry.getKey().equals(OvfInfoFileConstants.MetaDataFileName)) {
            metaDataFileEntry = fileEntry;
        } else {
            log.info("File '{}' is not an OVF file, will be ignored.", fileEntry.getKey());
        }
    }
    analyzeOvfMetaDataFile(storageDomainId, ovfEntityDataFromTar, metaDataFileEntry);
    log.info("Finish to fetch OVF files from tar file. The number of OVF entities are {}", ovfEntityDataFromTar.size());
    return ovfEntityDataFromTar;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) IOException(java.io.IOException) TarInMemoryExport(org.ovirt.engine.core.utils.archivers.tar.TarInMemoryExport) ByteBuffer(java.nio.ByteBuffer)

Example 18 with OvfEntityData

use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.

the class ProcessOvfUpdateForStorageDomainCommand method retrieveUnprocessedUnregisteredOvfData.

private List<Pair<Guid, String>> retrieveUnprocessedUnregisteredOvfData(Set<Guid> processedIds, Map<String, Object> metaDataForEntities) {
    Map<String, Object> statusMap = (Map<String, Object>) metaDataForEntities.get(OvfInfoFileConstants.VmStatus);
    List<OvfEntityData> ovfList = unregisteredOVFDataDao.getAllForStorageDomainByEntityType(getParameters().getStorageDomainId(), null);
    List<Pair<Guid, String>> ovfData = new LinkedList<>();
    for (OvfEntityData ovfEntityData : ovfList) {
        if (!processedIds.contains(ovfEntityData.getEntityId())) {
            Pair<Guid, String> data = new Pair<>(ovfEntityData.getEntityId(), ovfEntityData.getOvfData());
            ovfData.add(data);
        }
        statusMap.putIfAbsent(ovfEntityData.getEntityId().toString(), ovfEntityData.getStatus().getValue());
    }
    return ovfData;
}
Also used : OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 19 with OvfEntityData

use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.

the class UnregisteredOVFDataDaoTest method testInsertTemplateToUnregisteredEntity.

@Test
public void testInsertTemplateToUnregisteredEntity() {
    final String ovfExtraData = "<ovf> Some extra OVF data </ovf>";
    OvfEntityData ovfEntityData = new OvfEntityData(FixturesTool.VM_TEMPLATE_RHEL5, "AnyVM", VmEntityType.TEMPLATE, ArchitectureType.x86_64, Version.getLast(), FixturesTool.STORAGE_DOMAIN_NFS2_1, null, ovfExtraData);
    dao.saveOVFData(ovfEntityData);
    List<OvfEntityData> fetchedOvfEntityData = dao.getByEntityIdAndStorageDomain(FixturesTool.VM_TEMPLATE_RHEL5, FixturesTool.STORAGE_DOMAIN_NFS2_1);
    assertEquals(1, fetchedOvfEntityData.size());
    assertTrue("The entity type should be template", fetchedOvfEntityData.get(0).getEntityType().isTemplateType());
    assertEquals("The entity OVF extra data should be updated", ovfExtraData, fetchedOvfEntityData.get(0).getOvfExtraData());
}
Also used : OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) Test(org.junit.Test)

Example 20 with OvfEntityData

use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.

the class GetUnregisteredVmTemplatesQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    List<OvfEntityData> entityList = getOvfEntityList(VmEntityType.TEMPLATE);
    List<VmTemplate> vmTemplates = new ArrayList<>();
    for (OvfEntityData ovf : entityList) {
        try {
            vmTemplates.add(ovfHelper.readVmTemplateFromOvf(ovf.getOvfData()).getVmTemplate());
        } catch (OvfReaderException e) {
            log.debug("failed to parse a given ovf configuration: \n" + ovf.getOvfData(), e);
            getQueryReturnValue().setExceptionString("failed to parse a given ovf configuration " + e.getMessage());
        }
    }
    getQueryReturnValue().setSucceeded(true);
    getQueryReturnValue().setReturnValue(vmTemplates);
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Aggregations

OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)21 ArrayList (java.util.ArrayList)10 VM (org.ovirt.engine.core.common.businessentities.VM)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)4 Guid (org.ovirt.engine.core.compat.Guid)4 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 Pair (org.ovirt.engine.core.common.utils.Pair)2 XmlDocument (org.ovirt.engine.core.utils.ovf.xml.XmlDocument)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1