From b4b33231cead2ace0dbf18d3c5df89930101dc8c Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 14 Jul 2021 21:33:45 +0100 Subject: Fix upgrade for different vendor release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id5769b45c4b41fd40b7bac25407c046b8fe787e7 Issue-ID: SDC-3644 Signed-off-by: André Schmid --- .../files/default/error-configuration.yaml | 17 +++++++ .../be/components/impl/ResourceImportManager.java | 53 ++++++++++++---------- 2 files changed, 47 insertions(+), 23 deletions(-) (limited to 'catalog-be/src/main') 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 c87e1e394b..df13e80fe8 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 @@ -2519,3 +2519,20 @@ errors: message: "Error: Component %1 with Model %2 already exist.", messageId: "SVC4150" } + #-----------SVC4151--------------------------- + # %1 - "Component name" + # %2 - "Vendor release" + # %3 - "Model name" + COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL: { + code: 409, + message: "Error: Component '%1' with Vendor Release '%2' already exists in Model '%3'.", + messageId: "SVC4151" + } + #-----------SVC4152--------------------------- + # %1 - "Component name" + # %2 - "Vendor release" + COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS: { + code: 409, + message: "Error: Component '%1' with Vendor Release '%2' already exists.", + messageId: "SVC4152" + } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 77d8f897e7..a7defab60a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -171,7 +171,7 @@ public class ResourceImportManager { setMetaDataFromJson(resourceMetaData, resource); populateResourceFromYaml(resourceYml, resource); validationFunction.apply(resource); - checkResourceExistsBeforeCreate(createNewVersion, csarInfo, resource); + checkResourceExists(createNewVersion, csarInfo, resource); resource = resourceBusinessLogic .createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo, nodeName, isNested).left; Resource changeStateResponse; @@ -198,32 +198,39 @@ public class ResourceImportManager { return responsePair; } - private void checkResourceExistsBeforeCreate(final boolean createNewVersion, final CsarInfo csarInfo, final Resource resource) { - final String resourceName = resource.getName(); - final String model = resource.getModel(); - final Either latestByToscaName = toscaOperationFacade - .getLatestByToscaResourceNameAndModel(resourceName, model); - if (latestByToscaName.isLeft()) { - final Resource foundResource = latestByToscaName.left().value(); - validateComponentWithModelExist(resourceName, model, foundResource); - if (!createNewVersion) { - throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resourceName); - } - if (!isCsarPresent(csarInfo)) { - final Either component = toscaOperationFacade - .getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), resource.getVendorRelease(), - JsonParseFlagEnum.ParseAll); - if (component.isLeft()) { - validateComponentWithModelExist(resourceName, model, foundResource); - throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource.getName()); - } + private void checkResourceExists(final boolean isCreate, final CsarInfo csarInfo, final Resource resource) { + if (isCreate) { + checkResourceExistsOnCreate(resource, csarInfo); + } else { + checkResourceExistsOnUpdate(resource); + } + } + + private void checkResourceExistsOnCreate(final Resource resource, final CsarInfo csarInfo) { + if (isCsarPresent(csarInfo)) { + return; + } + final Either resourceEither = + toscaOperationFacade.getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), + resource.getVendorRelease(), JsonParseFlagEnum.ParseAll); + if (resourceEither.isLeft() && toscaOperationFacade.isNodeAssociatedToModel(resource.getModel(), resource)) { + if (resource.getModel() == null) { + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS, + resource.getName(), resource.getVendorRelease()); } + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL, + resource.getName(), resource.getVendorRelease(), resource.getModel()); } } - private void validateComponentWithModelExist(final String resourceName, final String model, final Resource foundResource) { - if (model != null && toscaOperationFacade.isNodeAssociatedToModel(model, foundResource).isPresent()) { - throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_MODEL_ALREADY_EXIST, resourceName, model); + private void checkResourceExistsOnUpdate(final Resource resource) { + final String model = resource.getModel(); + final Either latestByName = toscaOperationFacade.getLatestByName(resource.getName(), model); + if (latestByName.isLeft() && toscaOperationFacade.isNodeAssociatedToModel(model, resource)) { + if (model == null) { + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource.getName()); + } + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_MODEL_ALREADY_EXIST, resource.getName(), model); } } -- cgit 1.2.3-korg