diff options
author | andre.schmid <andre.schmid@est.tech> | 2021-08-18 14:34:33 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-08-26 12:13:58 +0000 |
commit | aea64ba99fa9c9b51112b30aeb0872c4cdb89759 (patch) | |
tree | 8645ba4b820f8615e54ecd053f7232c2fcd7dca9 /catalog-be/src/main | |
parent | 5a0703ffad1492ec6b6c78143f63dca83ee030d2 (diff) |
Validate the Resource Model before importing VSP
Validates the Resource Model selected during the Import VSP.
This model must be aligned with one of the models that the
imported VSP relates to.
Fix VSP package retrieval to get the exact version from the
VSP chosen during the Import VSP process.
Introduces a client in the Catalog to retrieve from the
Onboarding backend a VSP information using its Id and
version Id.
Change-Id: Ic8fb52b6daadc0e7203c81a9c15c3e46d5b9fffb
Issue-ID: SDC-3675
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main')
4 files changed, 94 insertions, 11 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml index 6d243d2e94..563594a728 100644 --- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml +++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml @@ -2554,3 +2554,29 @@ errors: messageId: "SVC4154" } + #-----------SVC4155--------------------------- + # %1 - "VSP id" + # %2 - "VSP version id" + VSP_FIND_ERROR: { + code: 500, + message: "An error has occurred while retrieving the Vendor Software Product of id '%1', version id '%2'", + messageId: "SVC4155" + } + + #-----------SVC4156--------------------------- + # %1 - "VSP id" + # %2 - "VSP version id" + VSP_NOT_FOUND: { + code: 404, + message: "Could not find Vendor Software Product of id '%1', version id '%2'", + messageId: "SVC4156" + } + + #-----------SVC4157--------------------------- + # %1 - "The model name" + # %2 - "List of allowed models" + VSP_MODEL_NOT_ALLOWED: { + code: 400, + message: "The Model '%1' is not allowed for the imported Vendor Software Product. Allowed Models: '%2'", + messageId: "SVC4157" + }
\ No newline at end of file diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb index 9f49bc52e1..60616c2709 100644 --- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb +++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb @@ -945,7 +945,9 @@ onboarding: protocol: http port: <%= node['ONBOARDING_BE'][:http_port] %> <% end -%> - downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages" + getVspPackageUri: "/onboarding-api/v1.0/vendor-software-products/packages/%s?versionId=%s" # /onboarding-api/v1.0/vendor-software-products/packages/:vspId?versionId=:vspVersionId + getLatestVspPackageUri: "/onboarding-api/v1.0/vendor-software-products/packages/%s" # /onboarding-api/v1.0/vendor-software-products/packages/:vspId + getVspUri: "/onboarding-api/v1.0/vendor-software-products/%s/versions/%s" # /onboarding-api/v1.0/vendor-software-products/:vspId/versions/:vspVersionId healthCheckUri: "/onboarding-api/v1.0/healthcheck" # #GSS IDNS diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java index 6f530ccd3a..b8a5d67d4a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java @@ -23,10 +23,10 @@ package org.openecomp.sdc.be.components.csar; import fj.data.Either; import java.util.Map; +import java.util.Optional; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.BaseBusinessLogic; import org.openecomp.sdc.be.components.impl.CsarValidationUtils; -import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -37,6 +37,7 @@ import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.VendorSoftwareProduct; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation; import org.openecomp.sdc.be.model.operations.StorageException; @@ -48,6 +49,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.CsarOperation; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; @@ -63,7 +65,7 @@ public class CsarBusinessLogic extends BaseBusinessLogic { @Autowired public CsarBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation, - IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic, InterfaceOperation interfaceOperation, + IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation, InterfaceLifecycleOperation interfaceLifecycleTypeOperation, YamlTemplateParsingHandler yamlHandler, ArtifactsOperations artifactToscaOperation) { super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, @@ -99,13 +101,19 @@ public class CsarBusinessLogic extends BaseBusinessLogic { if (status == StorageOperationStatus.ENTITY_ALREADY_EXISTS) { log.debug("Failed to create resource {}, csarUUID {} already exist for a different VF ", resource.getSystemName(), csarUUID); } else if (status != StorageOperationStatus.OK) { - log.debug("Failed to validate uniqueness of CsarUUID {} for resource", csarUUID, resource.getSystemName()); + log.debug("Failed to validate uniqueness of CsarUUID '{}' for resource '{}'", csarUUID, resource.getSystemName()); throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status)); } } public CsarInfo getCsarInfo(Resource resource, Resource oldResource, User user, Map<String, byte[]> payload, String csarUUID) { - Map<String, byte[]> csar = getCsar(resource, user, payload, csarUUID); + Map<String, byte[]> csar = payload; + if (csar == null) { + final var vendorSoftwareProduct = getCsar(resource, user); + validateModel(resource, vendorSoftwareProduct); + + csar = vendorSoftwareProduct.getFileMap(); + } ImmutablePair<String, String> toscaYamlCsarStatus = validateAndParseCsar(resource, user, csar, csarUUID).left() .on(this::throwComponentException); String checksum = CsarValidationUtils.getToscaYamlChecksum(csar, csarUUID, componentsUtils).left() @@ -117,7 +125,23 @@ public class CsarBusinessLogic extends BaseBusinessLogic { csarUUID, oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().getImportedToscaChecksum(), checksum); oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().setImportedToscaChecksum(checksum); } - return new CsarInfo(user, csarUUID, csar, resource.getName(), toscaYamlCsarStatus.getKey(), toscaYamlCsarStatus.getValue(), true); + return new CsarInfo(user, csarUUID, resource.getCsarVersionId(), csar, resource.getName(), toscaYamlCsarStatus.getKey(), + toscaYamlCsarStatus.getValue(), true); + } + + private void validateModel(final Resource resource, final VendorSoftwareProduct vendorSoftwareProduct) { + if (resource.getModel() == null) { + if (!vendorSoftwareProduct.getModelList().isEmpty()) { + var modelStringList = String.join(", ", vendorSoftwareProduct.getModelList()); + throw new ByActionStatusComponentException(ActionStatus.VSP_MODEL_NOT_ALLOWED, "SDC AID", modelStringList); + } + return; + } + if (!vendorSoftwareProduct.getModelList().contains(resource.getModel())) { + var modelStringList = + vendorSoftwareProduct.getModelList().isEmpty() ? "SDC AID" : String.join(", ", vendorSoftwareProduct.getModelList()); + throw new ByActionStatusComponentException(ActionStatus.VSP_MODEL_NOT_ALLOWED, resource.getModel(), modelStringList); + } } public CsarInfo getCsarInfo(Service service, Service oldResource, User user, Map<String, byte[]> payload, String csarUUID) { @@ -152,9 +176,8 @@ public class CsarBusinessLogic extends BaseBusinessLogic { throw new ByResponseFormatComponentException(responseFormat); } - private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Component component, User user, Map<String, byte[]> payload, + private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Component component, User user, Map<String, byte[]> csar, String csarUUID) { - Map<String, byte[]> csar = getCsar(component, user, payload, csarUUID); Either<Boolean, ResponseFormat> validateCsarStatus = CsarValidationUtils.validateCsar(csar, csarUUID, componentsUtils); if (validateCsarStatus.isRight()) { ResponseFormat responseFormat = validateCsarStatus.right().value(); @@ -182,7 +205,7 @@ public class CsarBusinessLogic extends BaseBusinessLogic { if (payload != null) { return payload; } - Either<Map<String, byte[]>, StorageOperationStatus> csar = csarOperation.getCsar(csarUUID, user); + Either<Map<String, byte[]>, StorageOperationStatus> csar = csarOperation.findVspLatestPackage(csarUUID, user); if (csar.isRight()) { StorageOperationStatus value = csar.right().value(); log.debug("#getCsar - failed to fetch csar with ID {}, error: {}", csarUUID, value); @@ -197,6 +220,31 @@ public class CsarBusinessLogic extends BaseBusinessLogic { return csar.left().value(); } + private VendorSoftwareProduct getCsar(final Resource resource, final User user) { + final Optional<VendorSoftwareProduct> vendorSoftwareProductOpt; + try { + vendorSoftwareProductOpt = csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user); + } catch (final Exception exception) { + log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, CsarBusinessLogic.class.getName(), exception.getMessage()); + auditGetCsarError(resource, user, resource.getCsarUUID(), StorageOperationStatus.GENERAL_ERROR); + throw new ByActionStatusComponentException(ActionStatus.VSP_FIND_ERROR, resource.getCsarUUID(), resource.getCsarVersionId()); + } + if (vendorSoftwareProductOpt.isEmpty()) { + auditGetCsarError(resource, user, resource.getCsarUUID(), StorageOperationStatus.CSAR_NOT_FOUND); + throw new ByActionStatusComponentException(ActionStatus.VSP_NOT_FOUND, resource.getCsarUUID(), resource.getCsarVersionId()); + } + return vendorSoftwareProductOpt.get(); + } + + private void auditGetCsarError(Component component, User user, String csarUUID, StorageOperationStatus storageOperationStatus) { + log.debug("#getCsar - failed to fetch csar with ID {}, error: {}", csarUUID, storageOperationStatus); + BeEcompErrorManager.getInstance().logBeDaoSystemError(CREATING_RESOURCE_FROM_CSAR_FETCHING_CSAR_WITH_ID + csarUUID + FAILED); + var responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageOperationStatus), csarUUID); + if (component instanceof Resource) { + componentsUtils.auditResource(responseFormat, user, (Resource) component, AuditingActionEnum.CREATE_RESOURCE); + } + } + private void auditAndThrowException(Resource resource, User user, AuditingActionEnum auditingAction, ActionStatus status, String... params) { ResponseFormat errorResponse = componentsUtils.getResponseFormat(status, params); componentsUtils.auditResource(errorResponse, user, resource, auditingAction); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java index 14ede6305b..0571f55c32 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java @@ -71,6 +71,8 @@ public class CsarInfo { @Setter private String csarUUID; @Getter + private String csarVersionId; + @Getter @Setter private Map<String, byte[]> csar; @Getter @@ -89,7 +91,6 @@ public class CsarInfo { private List<Map.Entry<String, byte[]>> globalSubstitutes; - @SuppressWarnings("unchecked") public CsarInfo(User modifier, String csarUUID, Map<String, byte[]> csar, String vfResourceName, String mainTemplateName, String mainTemplateContent, boolean isUpdate) { this.vfResourceName = vfResourceName; @@ -98,7 +99,7 @@ public class CsarInfo { this.csar = csar; this.mainTemplateName = mainTemplateName; this.mainTemplateContent = mainTemplateContent; - this.mappedToscaMainTemplate = (Map<String, Object>) new Yaml().load(mainTemplateContent); + this.mappedToscaMainTemplate = new Yaml().load(mainTemplateContent); this.createdNodesToscaResourceNames = new HashMap<>(); this.cvfcToCreateQueue = new PriorityQueue<>(); this.isUpdate = isUpdate; @@ -117,6 +118,12 @@ public class CsarInfo { return globalSubstitutesInCsar; } + public CsarInfo(final User modifier, final String csarUUID, final String csarVersionId, final Map<String, byte[]> csarContent, + final String vfResourceName, final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) { + this(modifier, csarUUID, csarContent, vfResourceName, mainTemplateName, mainTemplateContent, isUpdate); + this.csarVersionId = csarVersionId; + } + @VisibleForTesting CsarInfo(final NonManoConfiguration nonManoConfiguration) { this.nonManoConfiguration = nonManoConfiguration; |