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;
}
Aggregations