diff options
author | andre.schmid <andre.schmid@est.tech> | 2021-07-14 21:33:45 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-07-23 17:05:23 +0000 |
commit | b4b33231cead2ace0dbf18d3c5df89930101dc8c (patch) | |
tree | a46ad2d47f06c189ba7af270ed0ca7c51e888121 /catalog-be/src/main/java | |
parent | cba52c9e6c67ae2ee723c76f0c9ed165b657df63 (diff) |
Fix upgrade for different vendor release
Change-Id: Id5769b45c4b41fd40b7bac25407c046b8fe787e7
Issue-ID: SDC-3644
Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java | 53 |
1 files changed, 30 insertions, 23 deletions
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<Resource, StorageOperationStatus> 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<Resource, StorageOperationStatus> 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<Resource, StorageOperationStatus> 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<Resource, StorageOperationStatus> 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); } } |