aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
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
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')
-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
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java89
3 files changed, 89 insertions, 70 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);
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
index f56ff2e5b9..a9368b2b01 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
@@ -22,14 +22,16 @@
package org.openecomp.sdc.be.components;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import fj.data.Either;
@@ -38,11 +40,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
@@ -53,6 +54,7 @@ import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.config.Configuration;
@@ -101,7 +103,7 @@ public class ResourceImportManagerTest {
protected static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
private static final CapabilityTypeOperation capabilityTypeOperation = Mockito.mock(CapabilityTypeOperation.class);
- @BeforeClass
+ @BeforeAll
public static void beforeClass() {
importManager = new ResourceImportManager(componentsUtils, capabilityTypeOperation, interfaceDefinitionHandler);
importManager.setAuditingManager(auditingManager);
@@ -120,7 +122,7 @@ public class ResourceImportManagerTest {
configurationManager.setConfiguration(configuration);
}
- @Before
+ @BeforeEach
public void beforeTest() {
Mockito.reset(auditingManager, responseFormatManager, resourceBusinessLogic, userAdmin);
Either<Component, StorageOperationStatus> notFound = Either.right(StorageOperationStatus.NOT_FOUND);
@@ -129,7 +131,7 @@ public class ResourceImportManagerTest {
}
@Test
- public void testBasicResourceCreation() throws IOException {
+ void testBasicResourceCreation() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
@@ -152,11 +154,11 @@ public class ResourceImportManagerTest {
testSetDerivedFrom(resource);
testSetProperties(resource);
- Mockito.verify(resourceBusinessLogic, Mockito.times(1)).propagateStateToCertified(Mockito.eq(user), Mockito.eq(resource), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true), Mockito.eq(false));
+ Mockito.verify(resourceBusinessLogic, Mockito.times(1)).propagateStateToCertified(eq(user), eq(resource), Mockito.any(LifecycleChangeInfoWithAction.class), eq(false), eq(true), eq(false));
}
@Test()
- public void testResourceCreationFailed() throws IOException {
+ void testResourceCreationFailed() {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
user.setUserId(resourceMD.getContactId());
@@ -174,14 +176,14 @@ public class ResourceImportManagerTest {
errorInfoFromTest = e;
}
assertNotNull(errorInfoFromTest);
- assertEquals(errorInfoFromTest.getActionStatus(), ActionStatus.GENERAL_ERROR);
+ assertEquals(ActionStatus.GENERAL_ERROR, errorInfoFromTest.getActionStatus());
- Mockito.verify(resourceBusinessLogic, Mockito.times(0)).createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.eq(user), Mockito.eq(true), Mockito.eq(false), Mockito.eq(true), Mockito.eq(null), Mockito.eq(null), Mockito.eq(false));
- Mockito.verify(resourceBusinessLogic, Mockito.times(0)).propagateStateToCertified(Mockito.eq(user), Mockito.any(Resource.class), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true), Mockito.eq(false));
+ Mockito.verify(resourceBusinessLogic, Mockito.times(0)).createOrUpdateResourceByImport(Mockito.any(Resource.class), eq(user), eq(true), eq(false), eq(true), eq(null), eq(null), eq(false));
+ Mockito.verify(resourceBusinessLogic, Mockito.times(0)).propagateStateToCertified(eq(user), Mockito.any(Resource.class), Mockito.any(LifecycleChangeInfoWithAction.class), eq(false), eq(true), eq(false));
}
@Test
- public void testResourceCreationWithCapabilities() throws IOException {
+ void testResourceCreationWithCapabilities() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
user.setUserId(resourceMD.getContactId());
@@ -195,13 +197,13 @@ public class ResourceImportManagerTest {
Resource resource = createResource.left;
testSetCapabilities(resource);
- Mockito.verify(resourceBusinessLogic, Mockito.times(1)).propagateStateToCertified(Mockito.eq(user), Mockito.eq(resource), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true), Mockito.eq(false));
+ Mockito.verify(resourceBusinessLogic, Mockito.times(1)).propagateStateToCertified(eq(user), eq(resource), Mockito.any(LifecycleChangeInfoWithAction.class), eq(false), eq(true), eq(false));
Mockito.verify(resourceBusinessLogic, Mockito.times(1)).createOrUpdateResourceByImport(resource, user, true, false, true, null, null, false);
}
@Test
- public void testResourceCreationWithRequirments() throws IOException {
+ void testResourceCreationWithRequirments() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
user.setUserId(resourceMD.getContactId());
@@ -217,7 +219,7 @@ public class ResourceImportManagerTest {
}
@Test
- public void testResourceCreationWithInterfaceImplementation() throws IOException {
+ void testResourceCreationWithInterfaceImplementation() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
user.setUserId(resourceMD.getContactId());
@@ -242,7 +244,7 @@ public class ResourceImportManagerTest {
}
@Test
- public void testResourceCreationWithInterfaceImplementation_UnknownInterface() throws IOException {
+ void testResourceCreationWithInterfaceImplementation_UnknownInterface() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
user.setUserId(resourceMD.getContactId());
@@ -266,7 +268,7 @@ public class ResourceImportManagerTest {
}
@Test
- public void testResourceCreationWitInterfaceImplementation_UnknownOperation() throws IOException {
+ void testResourceCreationWitInterfaceImplementation_UnknownOperation() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
user.setUserId(resourceMD.getContactId());
@@ -290,7 +292,7 @@ public class ResourceImportManagerTest {
}
@Test
- public void testResourceCreationFailedVendorReleaseAlreadyExists() throws IOException {
+ void testResourceCreationFailedVendorReleaseAlreadyExists() throws IOException {
UploadResourceInfo resourceMD = createDummyResourceMD();
User user = new User();
@@ -301,34 +303,27 @@ public class ResourceImportManagerTest {
when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(user);
setResourceBusinessLogicMock();
-
- Either<Component, StorageOperationStatus> notFound = Either.left(Mockito.mock(Resource.class));
+ final Either<Component, StorageOperationStatus> foundResourceEither = Either.left(Mockito.mock(Resource.class));
when(toscaOperationFacade.getComponentByNameAndVendorRelease(any(ComponentTypeEnum.class), anyString(), anyString(),
- any(JsonParseFlagEnum.class))).thenReturn(notFound);
-
+ any(JsonParseFlagEnum.class))).thenReturn(foundResourceEither);
+ when(toscaOperationFacade.isNodeAssociatedToModel(eq(null), any(Resource.class))).thenReturn(true);
+
String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-blockStorage.yml");
-
- ComponentException errorInfoFromTest = null;
- try {
- when(toscaOperationFacade
- .getLatestByToscaResourceNameAndModel(resourceMD.getName(), StringUtils.EMPTY)).thenReturn(Either.left(new Resource()));
- importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
- }catch (ComponentException e){
- errorInfoFromTest = e;
- }
- assertNotNull(errorInfoFromTest);
- assertEquals(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, errorInfoFromTest.getActionStatus());
+
+ var actualException = assertThrows(ByActionStatusComponentException.class,
+ () -> importManager.importNormativeResource(jsonContent, resourceMD, user, true, true));
+ assertEquals(ActionStatus.COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS, actualException.getActionStatus());
}
private void setResourceBusinessLogicMock() {
when(resourceBusinessLogic.getUserAdmin()).thenReturn(userAdmin);
- when(resourceBusinessLogic.createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.eq(null), Mockito.eq(null), Mockito.eq(false)))
+ when(resourceBusinessLogic.createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(), eq(null), eq(null), eq(false)))
.thenAnswer((Answer<ImmutablePair<Resource, ActionStatus>>) invocation -> {
Object[] args = invocation.getArguments();
return new ImmutablePair<>((Resource) args[0], ActionStatus.CREATED);
});
- when(resourceBusinessLogic.propagateStateToCertified(Mockito.any(User.class), Mockito.any(Resource.class), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true), Mockito.eq(false)))
+ when(resourceBusinessLogic.propagateStateToCertified(Mockito.any(User.class), Mockito.any(Resource.class), Mockito.any(LifecycleChangeInfoWithAction.class), eq(false), eq(true), eq(false)))
.thenAnswer((Answer<Resource>) invocation -> {
Object[] args = invocation.getArguments();
return (Resource) args[1];
@@ -339,7 +334,7 @@ public class ResourceImportManagerTest {
return Either.left((Resource) args[0]);
});
- when(resourceBusinessLogic.validateResourceBeforeCreate(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(AuditingActionEnum.class), Mockito.eq(false), Mockito.eq(null))).thenAnswer((Answer<Either<Resource, ResponseFormat>>) invocation -> {
+ when(resourceBusinessLogic.validateResourceBeforeCreate(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(AuditingActionEnum.class), eq(false), eq(null))).thenAnswer((Answer<Either<Resource, ResponseFormat>>) invocation -> {
Object[] args = invocation.getArguments();
return Either.left((Resource) args[0]);
@@ -476,10 +471,10 @@ public class ResourceImportManagerTest {
private void testSetConstantMetaData(Resource resource) {
assertEquals(resource.getVersion(), TypeUtils.getFirstCertifiedVersionVersion());
- assertSame(resource.getLifecycleState(), ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE);
- assertEquals(resource.isHighestVersion(), ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION);
- assertEquals(resource.getVendorName(), ImportUtils.Constants.VENDOR_NAME);
- assertEquals(resource.getVendorRelease(), ImportUtils.Constants.VENDOR_RELEASE);
+ assertSame(ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE, resource.getLifecycleState());
+ assertEquals(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION, resource.isHighestVersion());
+ assertEquals(ImportUtils.Constants.VENDOR_NAME, resource.getVendorName());
+ assertEquals(ImportUtils.Constants.VENDOR_RELEASE, resource.getVendorRelease());
}
}