Search in sources :

Example 1 with TarInMemoryExport

use of org.ovirt.engine.core.utils.archivers.tar.TarInMemoryExport 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)1 TarInMemoryExport (org.ovirt.engine.core.utils.archivers.tar.TarInMemoryExport)1