aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-07-14 21:33:45 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-23 17:05:23 +0000
commitb4b33231cead2ace0dbf18d3c5df89930101dc8c (patch)
treea46ad2d47f06c189ba7af270ed0ca7c51e888121 /catalog-be/src/main
parentcba52c9e6c67ae2ee723c76f0c9ed165b657df63 (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')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java53
2 files changed, 47 insertions, 23 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 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<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);
}
}