Search in sources :

Example 1 with InMemoryTar

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Guid(org.ovirt.engine.core.compat.Guid) EngineException(org.ovirt.engine.core.common.errors.EngineException) IOException(java.io.IOException) InMemoryTar(org.ovirt.engine.core.utils.archivers.tar.InMemoryTar) HashSet(java.util.HashSet) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 Guid (org.ovirt.engine.core.compat.Guid)1 InMemoryTar (org.ovirt.engine.core.utils.archivers.tar.InMemoryTar)1