Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 3758 ElasticSearch Agent: fix for calculateVersionSizes method in StorageFileMapper #3759

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
import com.epam.pipeline.entity.search.SearchDocumentType;
import com.epam.pipeline.entity.search.StorageFileSearchMask;
import com.epam.pipeline.utils.FileContentUtils;
import com.epam.pipeline.utils.StreamUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.collections4.SetUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.slf4j.Logger;
Expand All @@ -42,12 +40,12 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -131,19 +129,24 @@ public XContentBuilder fileToDocument(final DataStorageFile dataStorageFile,

private Map<String, ImmutablePair<Long, Integer>> calculateVersionSizes(
final Map<String, AbstractDataStorageItem> versions) {
return StreamUtils.grouped(
versions.values().stream().map(v -> (DataStorageFile) v),
Comparator.comparing(v -> MapUtils.emptyIfNull(v.getLabels())
.getOrDefault(ESConstants.STORAGE_CLASS_LABEL, STANDARD_TIER)
)
).map(tierVersions -> {
final String storageClass = tierVersions.stream().findFirst()
.map(v -> MapUtils.emptyIfNull(v.getLabels()).get(ESConstants.STORAGE_CLASS_LABEL))
.orElse(STANDARD_TIER);
final long totalSize = tierVersions.stream()
.collect(Collectors.summarizingLong(DataStorageFile::getSize)).getSum();
return ImmutablePair.of(storageClass, ImmutablePair.of(totalSize, tierVersions.size()));
}).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
final HashMap<String, ImmutablePair<Long, Integer>> result = new HashMap<>();
for (final AbstractDataStorageItem v : versions.values()) {
final DataStorageFile version = (DataStorageFile) v;
final String storageClass = Optional.ofNullable(
MapUtils.emptyIfNull(version.getLabels()).get(ESConstants.STORAGE_CLASS_LABEL)
).orElse(STANDARD_TIER);
result.compute(
storageClass,
(tier, tierSize) -> {
if (tierSize == null) {
return ImmutablePair.of(version.getSize(), 1);
} else {
return ImmutablePair.of(tierSize.getLeft() + version.getSize(), tierSize.getRight() + 1);
}
}
);
}
return result;
}

// This method construct mount path assuming that default mount point is /cloud-data/,
Expand Down
Loading