use of org.ovirt.engine.core.utils.archivers.tar.InMemoryTar in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStorageDomainCommand method buildOvfInfoFileByteArray.
private byte[] buildOvfInfoFileByteArray(List<Guid> vmAndTemplatesIds) {
ByteArrayOutputStream bufferedOutputStream = new ByteArrayOutputStream();
Set<Guid> processedIds = new HashSet<>();
try (InMemoryTar inMemoryTar = new InMemoryTar(bufferedOutputStream)) {
inMemoryTar.addTarEntry(generateInfoFileData().getBytes(), OvfInfoFileConstants.InfoFileName);
Map<String, Object> metaDataForEntities = generateMetaDataFile(vmAndTemplatesIds);
int i = 0;
while (i < vmAndTemplatesIds.size()) {
int size = Math.min(StorageConstants.OVF_MAX_ITEMS_PER_SQL_STATEMENT, vmAndTemplatesIds.size() - i);
List<Guid> idsToProcess = vmAndTemplatesIds.subList(i, i + size);
i += size;
List<Pair<Guid, String>> ovfs = vmAndTemplatesGenerationsDao.loadOvfDataForIds(idsToProcess);
if (!ovfs.isEmpty()) {
processedIds.addAll(buildFilesForOvfs(ovfs, inMemoryTar));
}
}
List<Pair<Guid, String>> unprocessedOvfData = retrieveUnprocessedUnregisteredOvfData(processedIds, metaDataForEntities);
inMemoryTar.addTarEntry(buildJson(metaDataForEntities, true).getBytes(), OvfInfoFileConstants.MetaDataFileName);
buildFilesForOvfs(unprocessedOvfData, inMemoryTar);
} catch (Exception e) {
throw new RuntimeException(String.format("Exception while building in memory tar of the OVFs of domain %s", getParameters().getStorageDomainId()), e);
}
return bufferedOutputStream.toByteArray();
}
Aggregations