|
27 | 27 | import com.epam.pipeline.entity.search.SearchDocumentType;
|
28 | 28 | import com.epam.pipeline.entity.search.StorageFileSearchMask;
|
29 | 29 | import com.epam.pipeline.utils.FileContentUtils;
|
30 |
| -import com.epam.pipeline.utils.StreamUtils; |
31 | 30 | import org.apache.commons.collections4.CollectionUtils;
|
32 | 31 | import org.apache.commons.collections4.ListUtils;
|
33 | 32 | import org.apache.commons.collections4.MapUtils;
|
34 | 33 | import org.apache.commons.collections4.SetUtils;
|
35 | 34 | import org.apache.commons.lang3.tuple.ImmutablePair;
|
36 |
| -import org.apache.commons.lang3.tuple.Pair; |
37 | 35 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
38 | 36 | import org.elasticsearch.common.xcontent.XContentFactory;
|
39 | 37 | import org.slf4j.Logger;
|
|
42 | 40 |
|
43 | 41 | import java.io.IOException;
|
44 | 42 | import java.nio.charset.StandardCharsets;
|
45 |
| -import java.util.Comparator; |
46 |
| -import java.util.HashMap; |
47 |
| -import java.util.List; |
48 |
| -import java.util.Locale; |
49 |
| -import java.util.Map; |
50 |
| -import java.util.Objects; |
51 |
| -import java.util.Set; |
| 43 | +import java.util.*; |
52 | 44 | import java.util.function.Function;
|
53 | 45 | import java.util.stream.Collectors;
|
54 | 46 |
|
@@ -131,21 +123,27 @@ public XContentBuilder fileToDocument(final DataStorageFile dataStorageFile,
|
131 | 123 |
|
132 | 124 | private Map<String, ImmutablePair<Long, Integer>> calculateVersionSizes(
|
133 | 125 | final Map<String, AbstractDataStorageItem> versions) {
|
134 |
| - return StreamUtils.grouped( |
135 |
| - versions.values().stream().map(v -> (DataStorageFile) v), |
136 |
| - Comparator.comparing(v -> MapUtils.emptyIfNull(v.getLabels()) |
137 |
| - .getOrDefault(ESConstants.STORAGE_CLASS_LABEL, STANDARD_TIER) |
138 |
| - ) |
139 |
| - ).map(tierVersions -> { |
140 |
| - final String storageClass = tierVersions.stream().findFirst() |
141 |
| - .map(v -> MapUtils.emptyIfNull(v.getLabels()).get(ESConstants.STORAGE_CLASS_LABEL)) |
142 |
| - .orElse(STANDARD_TIER); |
143 |
| - final long totalSize = tierVersions.stream() |
144 |
| - .collect(Collectors.summarizingLong(DataStorageFile::getSize)).getSum(); |
145 |
| - return ImmutablePair.of(storageClass, ImmutablePair.of(totalSize, tierVersions.size())); |
146 |
| - }).collect(Collectors.toMap(Pair::getKey, Pair::getValue)); |
| 126 | + final HashMap<String, ImmutablePair<Long, Integer>> result = new HashMap<>(); |
| 127 | + for (final AbstractDataStorageItem v : versions.values()) { |
| 128 | + final DataStorageFile version = (DataStorageFile) v; |
| 129 | + final String storageClass = Optional.ofNullable( |
| 130 | + MapUtils.emptyIfNull(version.getLabels()).get(ESConstants.STORAGE_CLASS_LABEL) |
| 131 | + ).orElse(STANDARD_TIER); |
| 132 | + result.compute( |
| 133 | + storageClass, |
| 134 | + (tier, tierSize) -> { |
| 135 | + if (tierSize == null) { |
| 136 | + return ImmutablePair.of(version.getSize(), 1); |
| 137 | + } else { |
| 138 | + return ImmutablePair.of(tierSize.getLeft() + version.getSize(), tierSize.getRight() + 1); |
| 139 | + } |
| 140 | + } |
| 141 | + ); |
| 142 | + } |
| 143 | + return result; |
147 | 144 | }
|
148 | 145 |
|
| 146 | + |
149 | 147 | // This method construct mount path assuming that default mount point is /cloud-data/,
|
150 | 148 | // if f.e. CP_STORAGE_MOUNT_ROOT_DIR is defined in launch.env.properties or somewhere else,
|
151 | 149 | // this method will return wrong results
|
|
0 commit comments