diff options
Diffstat (limited to 'common-be/src/main/java/org')
8 files changed, 432 insertions, 176 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/PersistentStorageArtifactInfo.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoArtifactInfo.java index 0472661fd9..a193cdd6db 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/PersistentStorageArtifactInfo.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoArtifactInfo.java @@ -20,14 +20,19 @@ package org.openecomp.sdc.be.csar.storage; -import java.nio.file.Path; import lombok.AllArgsConstructor; import lombok.Getter; @AllArgsConstructor -public class PersistentStorageArtifactInfo implements ArtifactInfo { +@Getter +public class MinIoArtifactInfo implements ArtifactInfo { - @Getter - private final Path path; + private final String bucket; + private final String objectName; + @Override + public String getInfo() { + return String.format("bucket: %s\n" + + "object: %s", bucket, objectName); + } } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/PersistentVolumeArtifactStorageConfig.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java index d3cd6fb302..6f6778f2b0 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/PersistentVolumeArtifactStorageConfig.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java @@ -20,13 +20,33 @@ package org.openecomp.sdc.be.csar.storage; -import java.nio.file.Path; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; -@Data -public class PersistentVolumeArtifactStorageConfig implements ArtifactStorageConfig { +@AllArgsConstructor +@Getter +public class MinIoStorageArtifactStorageConfig implements ArtifactStorageConfig { private final boolean isEnabled; - private final Path storagePath; + private final EndPoint endPoint; + private final Credentials credentials; + private final String tempPath; + + @AllArgsConstructor + @Getter + public static class EndPoint { + + private final String host; + private final int port; + private final boolean secure; + } + + @AllArgsConstructor + @Getter + public static class Credentials { + + private final String accessKey; + private final String secretKey; + } } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java new file mode 100644 index 0000000000..0a48c2233c --- /dev/null +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java @@ -0,0 +1,247 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.csar.storage; + +import static org.openecomp.sdc.common.errors.Messages.EXTERNAL_CSAR_STORE_CONFIGURATION_FAILURE_MISSING; + +import io.minio.BucketExistsArgs; +import io.minio.CopyObjectArgs; +import io.minio.CopySource; +import io.minio.GetObjectArgs; +import io.minio.MakeBucketArgs; +import io.minio.MinioClient; +import io.minio.MinioClient.Builder; +import io.minio.PutObjectArgs; +import io.minio.RemoveObjectArgs; +import java.io.InputStream; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import lombok.Getter; +import org.openecomp.sdc.be.csar.storage.MinIoStorageArtifactStorageConfig.Credentials; +import org.openecomp.sdc.be.csar.storage.MinIoStorageArtifactStorageConfig.EndPoint; +import org.openecomp.sdc.be.csar.storage.exception.ArtifactStorageException; +import org.openecomp.sdc.common.CommonConfigurationManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MinIoStorageArtifactStorageManager implements ArtifactStorageManager { + + private static final Logger LOGGER = LoggerFactory.getLogger(MinIoStorageArtifactStorageManager.class); + private static final String EXTERNAL_CSAR_STORE = "externalCsarStore"; + + @Getter + private final MinIoStorageArtifactStorageConfig storageConfiguration; + private final MinioClient minioClient; + + public MinIoStorageArtifactStorageManager() { + this.storageConfiguration = readMinIoStorageArtifactStorageConfig(); + minioClient = initMinioClient(); + } + + //for testing only + MinIoStorageArtifactStorageManager(final ArtifactStorageConfig storageConfiguration) { + this.storageConfiguration = (MinIoStorageArtifactStorageConfig) storageConfiguration; + minioClient = initMinioClient(); + } + + @Override + public ArtifactInfo persist(final String vspId, final String versionId, final ArtifactInfo uploadedArtifactInfo) { + final MinIoArtifactInfo minioObjectTemp = (MinIoArtifactInfo) uploadedArtifactInfo; + try { + minioClient.getObject( + GetObjectArgs.builder() + .bucket(minioObjectTemp.getBucket()) + .object(minioObjectTemp.getObjectName()) + .build() + ); + } catch (final Exception e) { + throw new ArtifactStorageException( + String.format("Failed to retrieve uploaded artifact with bucket '%s' and name '%s' while persisting", + minioObjectTemp.getBucket(), minioObjectTemp.getObjectName()), e); + } + + final var backupPath = backupPreviousVersion(vspId, versionId).orElse(null); + try { + moveFile(minioObjectTemp, vspId, versionId); + } catch (final Exception e) { + rollback(minioObjectTemp, vspId, versionId); + final var errorMsg = String.format("Could not persist artifact for VSP '%s', version '%s'", vspId, versionId); + throw new ArtifactStorageException(errorMsg, e); + } + + removePreviousVersion(backupPath); + + return new MinIoArtifactInfo(vspId, versionId); + } + + @Override + public ArtifactInfo upload(final String vspId, final String versionId, final InputStream fileToUpload) { + + final String name = versionId + "--" + UUID.randomUUID(); + try { + // Make bucket if not exist. + final boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(vspId).build()); + + if (!found) { + // Make a new bucket ${vspId} . + minioClient.makeBucket(MakeBucketArgs.builder().bucket(vspId).build()); + } else { + LOGGER.info("Bucket '{}' already exists.", vspId); + } + + minioClient.putObject( + PutObjectArgs.builder() + .bucket(vspId) + .object(name) + .stream(fileToUpload, fileToUpload.available(), -1) + .build() + ); + + } catch (final Exception e) { + throw new ArtifactStorageException("Failed to upload artifact", e); + } + + return new MinIoArtifactInfo(vspId, name); + } + + @Override + public boolean isEnabled() { + return storageConfiguration != null && storageConfiguration.isEnabled(); + } + + @Override + public InputStream get(final ArtifactInfo artifactInfo) { + final MinIoArtifactInfo minioObject = (MinIoArtifactInfo) artifactInfo; + try { + return minioClient.getObject(GetObjectArgs.builder() + .bucket(minioObject.getBucket()) + .object(minioObject.getObjectName()) + .build()); + } catch (final Exception e) { + throw new ArtifactStorageException("Failed to get Object", e); + } + } + + @Override + public void delete(final ArtifactInfo artifactInfo) { + final MinIoArtifactInfo minioObject = (MinIoArtifactInfo) artifactInfo; + try { + minioClient.removeObject(RemoveObjectArgs.builder() + .bucket(minioObject.getBucket()) + .object(minioObject.getObjectName()) + .bypassGovernanceMode(true) + .build()); + } catch (final Exception e) { + throw new ArtifactStorageException(String.format("Failed to delete '%s'", minioObject.getObjectName()), e); + } + + } + + private Optional<MinIoArtifactInfo> backupPreviousVersion(final String vspId, final String versionId) { + + final String tempName = versionId + "--" + UUID.randomUUID().toString(); + try { + copy(vspId, tempName, versionId); + } catch (final Exception e) { + return Optional.empty(); + } + + return Optional.of(new MinIoArtifactInfo(vspId, tempName)); + } + + private void rollback(final MinIoArtifactInfo minioObject, final String vspId, final String versionId) { + try { + moveFile(minioObject, vspId, versionId); + } catch (final Exception ex) { + LOGGER.warn("Could not rollback the backup '{}' to the original '{}'", versionId, minioObject.getObjectName(), ex); + } + } + + private void removePreviousVersion(final MinIoArtifactInfo minioObject) { + if (minioObject == null) { + return; + } + delete(minioObject); + } + + private void moveFile(final MinIoArtifactInfo minioObject, final String vspId, final String versionId) { + try { + copy(vspId, versionId, minioObject.getObjectName()); + } catch (final Exception e) { + throw new ArtifactStorageException("Failed to move", e); + } + delete(minioObject); + } + + private void copy(final String vspId, final String versionId, final String objectName) throws Exception { + minioClient.copyObject( + CopyObjectArgs.builder() + .bucket(vspId) + .object(versionId) + .source(CopySource.builder() + .bucket(vspId) + .object(objectName) + .build()) + .build()); + } + + private MinIoStorageArtifactStorageConfig readMinIoStorageArtifactStorageConfig() { + final var commonConfigurationManager = CommonConfigurationManager.getInstance(); + + final Map<String, Object> endpoint = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "endpoint", null); + final Map<String, Object> credentials = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "credentials", null); + final String tempPath = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "tempPath", null); + LOGGER.info("ArtifactConfig.endpoint: '{}'", endpoint); + LOGGER.info("ArtifactConfig.credentials: '{}'", credentials); + LOGGER.info("ArtifactConfig.tempPath: '{}'", tempPath); + + if (endpoint == null) { + throw new RuntimeException(EXTERNAL_CSAR_STORE_CONFIGURATION_FAILURE_MISSING.formatMessage("endpoint")); + } + if (credentials == null) { + throw new RuntimeException(EXTERNAL_CSAR_STORE_CONFIGURATION_FAILURE_MISSING.formatMessage("credentials")); + } + if (tempPath == null) { + throw new RuntimeException(EXTERNAL_CSAR_STORE_CONFIGURATION_FAILURE_MISSING.formatMessage("tempPath")); + } + final String host = (String) endpoint.getOrDefault("host", null); + final int port = (int) endpoint.getOrDefault("port", 0); + final boolean secure = (boolean) endpoint.getOrDefault("secure", false); + + final String accessKey = (String) credentials.getOrDefault("accessKey", null); + final String secretKey = (String) credentials.getOrDefault("secretKey", null); + + return new MinIoStorageArtifactStorageConfig(true, new EndPoint(host, port, secure), new Credentials(accessKey, secretKey), tempPath); + } + + private MinioClient initMinioClient() { + final EndPoint endPoint = storageConfiguration.getEndPoint(); + final Credentials credentials = storageConfiguration.getCredentials(); + + final Builder builder = MinioClient.builder(); + return builder + .endpoint(endPoint.getHost(), endPoint.getPort(), endPoint.isSecure()) + .credentials(credentials.getAccessKey(), credentials.getSecretKey()) + .build(); + } + +} diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/CsarSizeReducer.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java index 822acc0766..3181b088c0 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/CsarSizeReducer.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java @@ -43,9 +43,9 @@ import org.openecomp.sdc.be.csar.storage.exception.CsarSizeReducerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class CsarSizeReducer implements PackageSizeReducer { +public class MinIoStorageCsarSizeReducer implements PackageSizeReducer { - private static final Logger LOGGER = LoggerFactory.getLogger(CsarSizeReducer.class); + private static final Logger LOGGER = LoggerFactory.getLogger(MinIoStorageCsarSizeReducer.class); private static final Set<String> ALLOWED_SIGNATURE_EXTENSIONS = Set.of("cms"); private static final Set<String> ALLOWED_CERTIFICATE_EXTENSIONS = Set.of("cert", "crt"); private static final String CSAR_EXTENSION = "csar"; @@ -55,7 +55,7 @@ public class CsarSizeReducer implements PackageSizeReducer { private final CsarPackageReducerConfiguration configuration; - public CsarSizeReducer(final CsarPackageReducerConfiguration configuration) { + public MinIoStorageCsarSizeReducer(final CsarPackageReducerConfiguration configuration) { this.configuration = configuration; } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java new file mode 100644 index 0000000000..3fa22d41be --- /dev/null +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.csar.storage; + +import java.io.InputStream; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class NoneStorageManager implements ArtifactStorageManager { + + @Override + public ArtifactInfo persist(final String vspId, final String versionId, final ArtifactInfo uploadedArtifactInfo) { + throw new UnsupportedOperationException(); + } + + @Override + public ArtifactInfo upload(final String vspId, final String versionId, final InputStream fileToUpload) { + throw new UnsupportedOperationException(); + } + + @Override + public ArtifactStorageConfig getStorageConfiguration() { + throw new UnsupportedOperationException(); + } + + @Override + public InputStream get(final ArtifactInfo artifactInfo) { + throw new UnsupportedOperationException(); + } + + @Override + public void delete(final ArtifactInfo artifactInfo) { + throw new UnsupportedOperationException(); + } + +} diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/PersistentVolumeArtifactStorageManager.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/PersistentVolumeArtifactStorageManager.java deleted file mode 100644 index 10629b3edb..0000000000 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/PersistentVolumeArtifactStorageManager.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.csar.storage; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.Optional; -import java.util.UUID; -import org.openecomp.sdc.be.csar.storage.exception.PersistentVolumeArtifactStorageException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PersistentVolumeArtifactStorageManager implements ArtifactStorageManager { - - private static final Logger LOGGER = LoggerFactory.getLogger(PersistentVolumeArtifactStorageManager.class); - - private final PersistentVolumeArtifactStorageConfig storageConfiguration; - - public PersistentVolumeArtifactStorageManager(final ArtifactStorageConfig storageConfiguration) { - this.storageConfiguration = (PersistentVolumeArtifactStorageConfig) storageConfiguration; - } - - @Override - public ArtifactInfo persist(final String vspId, final String versionId, final ArtifactInfo uploadedArtifactInfo) { - final var temporaryPath = uploadedArtifactInfo.getPath(); - if (!Files.exists(temporaryPath)) { - throw new PersistentVolumeArtifactStorageException(String.format("Given artifact does not exist '%s'", uploadedArtifactInfo.getPath())); - } - - final var filePath = buildFilePath(vspId, versionId); - final var backupPath = backupPreviousVersion(filePath).orElse(null); - try { - moveFile(temporaryPath, filePath); - } catch (final Exception e) { - rollback(backupPath, filePath); - final var errorMsg = String.format("Could not persist artifact for VSP '%s', version '%s'", vspId, versionId); - throw new PersistentVolumeArtifactStorageException(errorMsg, e); - } - - removePreviousVersion(backupPath); - - return new PersistentStorageArtifactInfo(filePath); - } - - @Override - public ArtifactInfo upload(final String vspId, final String versionId, final InputStream artifactInputStream) { - final var destinationFolder = buildDestinationFolder(vspId, versionId); - try { - Files.createDirectories(destinationFolder); - } catch (final IOException e) { - throw new PersistentVolumeArtifactStorageException(String.format("Could not create directory '%s'", destinationFolder), e); - } - - final var filePath = createTempFilePath(destinationFolder); - try { - persist(artifactInputStream, filePath); - } catch (final IOException e) { - throw new PersistentVolumeArtifactStorageException(String.format("Could not persist artifact '%s'", filePath), e); - } - - return new PersistentStorageArtifactInfo(filePath); - } - - private Path buildFilePath(final String vspId, final String versionId) { - return buildDestinationFolder(vspId, versionId).resolve(versionId); - } - - @Override - public boolean isEnabled() { - return storageConfiguration != null && storageConfiguration.isEnabled(); - } - - private Optional<Path> backupPreviousVersion(final Path filePath) { - if (!Files.exists(filePath)) { - return Optional.empty(); - } - - final var backupPath = Path.of(filePath + UUID.randomUUID().toString()); - moveFile(filePath, backupPath); - return Optional.ofNullable(backupPath); - } - - private void rollback(final Path backupPath, final Path filePath) { - try { - moveFile(backupPath, filePath); - } catch (final Exception ex) { - LOGGER.warn("Could not rollback the backup file '{}' to the original '{}'", backupPath, filePath, ex); - } - } - - private void removePreviousVersion(final Path filePath) { - if (filePath == null || !Files.exists(filePath)) { - return; - } - - try { - Files.delete(filePath); - } catch (final IOException e) { - throw new PersistentVolumeArtifactStorageException(String.format("Could not delete previous version '%s'", filePath), e); - } - } - - private Path createTempFilePath(final Path destinationFolder) { - final var retries = 10; - return createTempFilePath(destinationFolder, retries).orElseThrow(() -> { - throw new PersistentVolumeArtifactStorageException(String.format("Could not generate upload file path after '%s' retries", retries)); - }); - } - - private Optional<Path> createTempFilePath(final Path destinationFolder, int retries) { - for (var i = 0; i < retries; i++) { - final var filePath = destinationFolder.resolve(UUID.randomUUID().toString()); - if (Files.notExists(filePath)) { - return Optional.of(filePath); - } - } - return Optional.empty(); - } - - private Path buildDestinationFolder(final String vspId, final String versionId) { - return storageConfiguration.getStoragePath().resolve(vspId).resolve(versionId); - } - - private void persist(final InputStream artifactInputStream, final Path filePath) throws IOException { - try (final var inputStream = artifactInputStream; - final var fileOutputStream = new FileOutputStream(filePath.toFile());) { - inputStream.transferTo(fileOutputStream); - } - } - - private void moveFile(final Path from, final Path to) { - try { - Files.move(from, to, StandardCopyOption.REPLACE_EXISTING); - } catch (final IOException e) { - throw new PersistentVolumeArtifactStorageException(String.format("Could not move file '%s' to '%s'", from, to), 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 new file mode 100644 index 0000000000..d120b3af8d --- /dev/null +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java @@ -0,0 +1,91 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +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; +import org.openecomp.sdc.logging.api.LoggerFactory; + +@NoArgsConstructor +public class StorageFactory { + + private static final Logger LOGGER = LoggerFactory.getLogger(StorageFactory.class); + private static final String EXTERNAL_CSAR_STORE = "externalCsarStore"; + + public ArtifactStorageManager createArtifactStorageManager() { + switch (getConfiguredArtifactStorageType()) { + case MINIO: // MinIoStorage enabled + return new MinIoStorageArtifactStorageManager(); + default:// all configured, nothing enabled + return new NoneStorageManager(); + } + } + + public Optional<PackageSizeReducer> createPackageSizeReducer() { + switch (getConfiguredArtifactStorageType()) { + case MINIO: // MinIoStorage enabled + return Optional.of(new MinIoStorageCsarSizeReducer(readPackageReducerConfiguration())); + default:// all configured, nothing enabled + return Optional.empty(); + } + } + + private StorageType getConfiguredArtifactStorageType() { + final var commonConfigurationManager = CommonConfigurationManager.getInstance(); + final String storageType = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "storageType", NONE.name()); + LOGGER.info("ArtifactConfig.storageType: '{}'", storageType); + 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; + + public static StorageType findByName(String name) { + for (StorageType curr : StorageType.values()) { + if (curr.name().equals(name)) { + return curr; + } + } + return null; + } + } +} diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/exception/PersistentVolumeArtifactStorageException.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/exception/ArtifactStorageException.java index 28fff65bb6..aa621611df 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/exception/PersistentVolumeArtifactStorageException.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/exception/ArtifactStorageException.java @@ -22,13 +22,13 @@ package org.openecomp.sdc.be.csar.storage.exception; import org.openecomp.sdc.be.exception.BusinessException; -public class PersistentVolumeArtifactStorageException extends BusinessException { +public class ArtifactStorageException extends BusinessException { - public PersistentVolumeArtifactStorageException(final String message, final Throwable cause) { + public ArtifactStorageException(final String message, final Throwable cause) { super(message, cause); } - public PersistentVolumeArtifactStorageException(final String message) { + public ArtifactStorageException(final String message) { super(message); } } |