diff options
Diffstat (limited to 'common-be/src/main/java')
3 files changed, 26 insertions, 27 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java index cfbbc4fe4e..9e72522682 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java @@ -20,11 +20,9 @@ package org.openecomp.sdc.be.csar.storage; -import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; -@AllArgsConstructor -@Getter +@Data public class MinIoStorageArtifactStorageConfig implements ArtifactStorageConfig { private final boolean isEnabled; @@ -33,8 +31,7 @@ public class MinIoStorageArtifactStorageConfig implements ArtifactStorageConfig private final String tempPath; private final int uploadPartSize; - @AllArgsConstructor - @Getter + @Data public static class EndPoint { private final String host; @@ -42,8 +39,7 @@ public class MinIoStorageArtifactStorageConfig implements ArtifactStorageConfig private final boolean secure; } - @AllArgsConstructor - @Getter + @Data public static class Credentials { private final String accessKey; diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java index 98c54988a0..63a6820634 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java @@ -26,6 +26,7 @@ import java.io.BufferedOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.UUID; @@ -40,6 +41,7 @@ import lombok.Getter; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FilenameUtils; import org.openecomp.sdc.be.csar.storage.exception.CsarSizeReducerException; +import org.openecomp.sdc.common.CommonConfigurationManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,15 +52,31 @@ public class MinIoStorageCsarSizeReducer implements PackageSizeReducer { private static final Set<String> ALLOWED_CERTIFICATE_EXTENSIONS = Set.of("cert", "crt"); private static final String CSAR_EXTENSION = "csar"; private static final String UNEXPECTED_PROBLEM_HAPPENED_WHILE_READING_THE_CSAR = "An unexpected problem happened while reading the CSAR '%s'"; + private static final String EXTERNAL_CSAR_STORE = "externalCsarStore"; + @Getter private final AtomicBoolean reduced = new AtomicBoolean(false); private final CsarPackageReducerConfiguration configuration; - public MinIoStorageCsarSizeReducer(final CsarPackageReducerConfiguration configuration) { + public MinIoStorageCsarSizeReducer() { + this.configuration = readPackageReducerConfiguration(); + } + + MinIoStorageCsarSizeReducer(final CsarPackageReducerConfiguration configuration) { this.configuration = configuration; } + private CsarPackageReducerConfiguration readPackageReducerConfiguration() { + final var commonConfigurationManager = CommonConfigurationManager.getInstance(); + final List<String> foldersToStrip = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "foldersToStrip", new ArrayList<>()); + final int sizeLimit = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "sizeLimit", 1000000); + final int thresholdEntries = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "thresholdEntries", 10000); + LOGGER.info("Folders to strip: '{}'", String.join(", ", foldersToStrip)); + final Set<Path> foldersToStripPathSet = foldersToStrip.stream().map(Path::of).collect(Collectors.toSet()); + return new CsarPackageReducerConfiguration(foldersToStripPathSet, sizeLimit, thresholdEntries); + } + @Override public byte[] reduce(final Path csarPackagePath) { if (hasSignedPackageStructure(csarPackagePath)) { @@ -76,7 +94,7 @@ public class MinIoStorageCsarSizeReducer implements PackageSizeReducer { zf.entries().asIterator().forEachRemaining(zipProcessingFunction.getProcessZipConsumer(csarPackagePath, zf, zos)); } catch (final IOException ex1) { rollback(reducedCsarPath); - LOGGER.error("Could not read ZIP stream '{}'", csarPackagePath.toString(), ex1); + LOGGER.error("Could not read ZIP stream '{}'", csarPackagePath, ex1); final var errorMsg = String.format(UNEXPECTED_PROBLEM_HAPPENED_WHILE_READING_THE_CSAR, csarPackagePath); throw new CsarSizeReducerException(errorMsg, ex1); } @@ -190,7 +208,7 @@ public class MinIoStorageCsarSizeReducer implements PackageSizeReducer { .map(ZipEntry::getName).map(Path::of) .collect(Collectors.toList()); } catch (final IOException e) { - LOGGER.error("Failed to read ZipFile '{}'", csarPackagePath.toString(), e); + LOGGER.error("Failed to read ZipFile '{}'", csarPackagePath, e); final var errorMsg = String.format(UNEXPECTED_PROBLEM_HAPPENED_WHILE_READING_THE_CSAR, csarPackagePath); throw new CsarSizeReducerException(errorMsg, e); } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java index 8c86917e01..b1bf9ebf12 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java @@ -23,12 +23,7 @@ package org.openecomp.sdc.be.csar.storage; import static org.openecomp.sdc.be.csar.storage.StorageFactory.StorageType.NONE; import static org.openecomp.sdc.be.csar.storage.StorageFactory.StorageType.findByName; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; import lombok.NoArgsConstructor; import org.openecomp.sdc.common.CommonConfigurationManager; import org.openecomp.sdc.logging.api.Logger; @@ -52,7 +47,7 @@ public class StorageFactory { public Optional<PackageSizeReducer> createPackageSizeReducer() { switch (getConfiguredArtifactStorageType()) { case MINIO: // MinIoStorage enabled - return Optional.of(new MinIoStorageCsarSizeReducer(readPackageReducerConfiguration())); + return Optional.of(new MinIoStorageCsarSizeReducer()); default:// all configured, nothing enabled return Optional.empty(); } @@ -66,16 +61,6 @@ public class StorageFactory { return findByName(storageType); } - private CsarPackageReducerConfiguration readPackageReducerConfiguration() { - final var commonConfigurationManager = CommonConfigurationManager.getInstance(); - final List<String> foldersToStrip = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "foldersToStrip", new ArrayList<>()); - final int sizeLimit = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "sizeLimit", 1000000); - final int thresholdEntries = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "thresholdEntries", 10000); - LOGGER.info("Folders to strip: '{}'", String.join(", ", foldersToStrip)); - final Set<Path> foldersToStripPathSet = foldersToStrip.stream().map(Path::of).collect(Collectors.toSet()); - return new CsarPackageReducerConfiguration(foldersToStripPathSet, sizeLimit, thresholdEntries); - } - public enum StorageType { NONE, MINIO; |