aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2018-01-03 17:53:32 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-01-04 11:28:53 +0000
commitc09a82325a1518bd1fce7221b9be2fac32511f2d (patch)
tree68d9218cbb8db5edb73a57091486d4f5a8668655 /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src
parenta9602f8f97a64cc1855b5228bfc3c7502c82fe92 (diff)
Heat reupload component dependency issue fix
Resolved merge conflict Change-Id: Ib9561aa7d5814c3dd9c6015214d656a2800984a9 Issue-ID: SDC-872 Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java49
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java5
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java145
3 files changed, 120 insertions, 79 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java
index 8211749fe1..73598a2aee 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.model.dao.ServiceModelDao;
@@ -77,8 +79,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
-import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME;
-
public class OrchestrationUtil {
public static final String ORCHESTRATION_CONFIG_NAMESPACE = "orchestration";
@@ -344,39 +344,42 @@ public class OrchestrationUtil {
}
public void updateVspComponentDependencies(String vspId, Version version,
- Map<String, String> vspComponentIdNameInfoBeforeProcess) {
+ Map<String, String>
+ vspComponentIdNameInfoBeforeProcess,
+ Collection<ComponentDependencyModelEntity>
+ componentDependenciesBeforeDelete) {
Map<String, String> updatedVspComponentNameIdInfo = getVspComponentNameIdInfo(vspId, version);
if (MapUtils.isNotEmpty(updatedVspComponentNameIdInfo)) {
Set<String> updatedVspComponentNames = updatedVspComponentNameIdInfo.keySet();
- Collection<ComponentDependencyModelEntity> componentDependencies =
- componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId,
- version, null));
- if (CollectionUtils.isNotEmpty(componentDependencies)) {
- updateComponentDependency(vspComponentIdNameInfoBeforeProcess, componentDependencies,
- updatedVspComponentNames, updatedVspComponentNameIdInfo);
+ if (CollectionUtils.isNotEmpty(componentDependenciesBeforeDelete)) {
+ restoreComponentDependencies(vspId, version, vspComponentIdNameInfoBeforeProcess,
+ componentDependenciesBeforeDelete, updatedVspComponentNames,
+ updatedVspComponentNameIdInfo);
}
}
}
- private void updateComponentDependency(Map<String, String> vspComponentIdNameInfoBeforeProcess,
- Collection<ComponentDependencyModelEntity>
- componentDependencies,
- Set<String> updatedVspComponentNames,
- Map<String, String> updatedVspComponentNameIdInfo) {
- for (ComponentDependencyModelEntity componentDependency : componentDependencies) {
+ private void restoreComponentDependencies(String vspId, Version version,
+ Map<String, String> vspComponentIdNameInfoBeforeProcess,
+ Collection<ComponentDependencyModelEntity>
+ componentDependenciesBeforeDelete,
+ Set<String> updatedVspComponentNames,
+ Map<String, String> updatedVspComponentNameIdInfo) {
+ for (ComponentDependencyModelEntity componentDependency : componentDependenciesBeforeDelete) {
String sourceComponentName = vspComponentIdNameInfoBeforeProcess.get(componentDependency
.getSourceComponentId());
String targetComponentName = vspComponentIdNameInfoBeforeProcess.get(componentDependency
.getTargetComponentId());
if (updatedVspComponentNames.contains(sourceComponentName)
&& (updatedVspComponentNames.contains(targetComponentName))) {
+ ComponentDependencyModelEntity restoredDependency =
+ new ComponentDependencyModelEntity(vspId, version, null);
String newSourceComponentId = updatedVspComponentNameIdInfo.get(sourceComponentName);
- componentDependency.setSourceComponentId(newSourceComponentId);
+ restoredDependency.setSourceComponentId(newSourceComponentId);
String newTargetComponentId = updatedVspComponentNameIdInfo.get(targetComponentName);
- componentDependency.setTargetComponentId(newTargetComponentId);
- componentDependencyModelDao.update(componentDependency);
- } else {
- componentDependencyModelDao.delete(componentDependency);
+ restoredDependency.setTargetComponentId(newTargetComponentId);
+ restoredDependency.setRelation(componentDependency.getRelation());
+ componentDependencyModelDao.create(restoredDependency);
}
}
}
@@ -395,6 +398,12 @@ public class OrchestrationUtil {
return vspComponentIdNameMap;
}
+ public Collection<ComponentDependencyModelEntity> getComponentDependenciesBeforeDelete(String
+ vspId, Version version) {
+ return componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId,
+ version, null));
+ }
+
private Map<String, String> getVspComponentNameIdInfo(String vspId,
Version version) {
Collection<ComponentEntity> updatedVspComponents =
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java
index 13728b0c72..41ca8ace9a 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java
@@ -35,6 +35,7 @@ import org.openecomp.sdc.logging.messages.AuditMessages;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.validation.util.ValidationManagerUtil;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
@@ -122,6 +123,8 @@ public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemp
OrchestrationUtil orchestrationUtil = new OrchestrationUtil();
Map<String, String> vspComponentIdNameInfoBeforeProcess =
orchestrationUtil.getVspComponentIdNameInfo(vspId, version);
+ Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete =
+ orchestrationUtil.getComponentDependenciesBeforeDelete(vspId, version);
orchestrationUtil
.backupComponentsQuestionnaireBeforeDelete(vspId, version, componentsQuestionnaire,
componentNicsQuestionnaire, componentMibList, processes, processArtifact);
@@ -150,7 +153,7 @@ public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemp
orchestrationUtil.retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire,
componentNicsQuestionnaire, componentMibList, processes, processArtifact);
orchestrationUtil.updateVspComponentDependencies(vspId, version,
- vspComponentIdNameInfoBeforeProcess);
+ vspComponentIdNameInfoBeforeProcess, componentDependenciesBeforeDelete);
LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId);
uploadFileResponse.addStructureErrors(uploadErrors);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java
index 71a477bd28..5af39551b4 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java
@@ -1,7 +1,14 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
@@ -20,8 +27,9 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.testng.Assert;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.nio.ByteBuffer;
@@ -32,15 +40,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
public class OrchestrationTemplateCandidateManagerImplTest {
private static final String VSP_ID = "vspId";
private static final Version VERSION01 = new Version("versionId");
@@ -77,12 +76,21 @@ public class OrchestrationTemplateCandidateManagerImplTest {
@InjectMocks
private OrchestrationUtil orchestrationUtil;
- @BeforeMethod
+ @BeforeClass
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@AfterMethod
+ private void resetMocks() {
+ Mockito.reset(vspInfoDaoMock);
+ Mockito.reset(candidateServiceMock);
+ Mockito.reset(orchestrationTemplateDaoMock);
+ Mockito.reset(componentDependencyModelDaoMock);
+ Mockito.reset(componentDaoMock);
+ }
+
+ @AfterClass
public void tearDown() {
candidateManager = null;
orchestrationUtil = null;
@@ -104,17 +112,17 @@ public class OrchestrationTemplateCandidateManagerImplTest {
" ]\n" +
"}");
doReturn(orchTemplate)
- .when(candidateServiceMock).getOrchestrationTemplateCandidate(anyObject(), anyObject());
+ .when(candidateServiceMock).getOrchestrationTemplateCandidate(any(), any());
doReturn(new VspDetails(VSP_ID, VERSION01))
- .when(vspInfoDaoMock).get(anyObject());
+ .when(vspInfoDaoMock).get(any());
doReturn(null)
- .when(orchestrationTemplateDaoMock).getInfo(anyObject(), anyObject());
+ .when(orchestrationTemplateDaoMock).getInfo(any(), any());
- doReturn("{}").when(candidateServiceMock).createManifest(anyObject(), anyObject());
+ doReturn("{}").when(candidateServiceMock).createManifest(any(), any());
doReturn(Optional.empty()).when(candidateServiceMock)
- .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(),
- eq(OnboardingTypesEnum.ZIP), anyObject());
+ .fetchZipFileByteArrayInputStream(any(), any(), any(),
+ eq(OnboardingTypesEnum.ZIP), any());
OrchestrationTemplateActionResponse response =
@@ -125,69 +133,69 @@ public class OrchestrationTemplateCandidateManagerImplTest {
@Test
public void testUpdateVspComponentDependenciesHeatReuploadMoreComponents() {
- doReturn(getExistingComponentDependencies())
- .when(componentDependencyModelDaoMock).list(anyObject());
- doReturn(getComponentListWithMoreComponentsInHeat())
- .when(componentDaoMock).list(anyObject());
+ Collection<ComponentDependencyModelEntity> existingComponentsDependencies =
+ getExistingComponentDependencies();
+ Collection<ComponentEntity> componentListWithMoreComponentsInHeat =
+ getComponentListWithMoreComponentsInHeat();
- orchestrationUtil
- .updateVspComponentDependencies(VSP_ID, VERSION01, getVspInitComponentIdNameInfo());
-
- verify(componentDependencyModelDaoMock, times(2)).update(anyObject());
- verify(componentDependencyModelDaoMock, never()).delete(anyObject());
+ doReturn(componentListWithMoreComponentsInHeat).when(componentDaoMock).list(any());
+ Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo();
+ orchestrationUtil.updateVspComponentDependencies(VSP_ID, VERSION01,
+ componentIdNameInfoBeforeProcess, existingComponentsDependencies);
+ Mockito.verify(componentDependencyModelDaoMock, Mockito.times(2)).create(any());
}
@Test
public void testUpdateVspComponentDependenciesHeatReuploadLessComponents() {
- doReturn(getExistingComponentDependencies())
- .when(componentDependencyModelDaoMock).list(anyObject());
- doReturn(getComponentListWithLessComponentsInHeat()).when(componentDaoMock).list(anyObject());
-
+ Collection<ComponentDependencyModelEntity> existingComponentsDependencies =
+ getExistingComponentDependencies();
+ Collection<ComponentEntity> componentListWithLessComponentsInHeat =
+ getComponentListWithLessComponentsInHeat();
+ doReturn(componentListWithLessComponentsInHeat).when(componentDaoMock).list(any());
+ Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo();
orchestrationUtil.updateVspComponentDependencies(VSP_ID, VERSION01,
- getVspInitComponentIdNameInfo());
-
- verify(componentDependencyModelDaoMock).update(anyObject());
- verify(componentDependencyModelDaoMock).delete(anyObject());
+ componentIdNameInfoBeforeProcess, existingComponentsDependencies);
+ Mockito.verify(componentDependencyModelDaoMock, Mockito.times(1)).create(any());
}
@Test
public void testUpdateVspComponentDependenciesHeatReuploadSameComponents() {
- doReturn(getExistingComponentDependencies())
- .when(componentDependencyModelDaoMock).list(anyObject());
- doReturn(getComponentListWithSameComponentsInHeat()).when(componentDaoMock).list(anyObject());
-
- orchestrationUtil
- .updateVspComponentDependencies(VSP_ID, VERSION01, getVspInitComponentIdNameInfo());
-
- verify(componentDependencyModelDaoMock, times(2)).update(anyObject());
- verify(componentDependencyModelDaoMock, never()).delete(anyObject());
+ Collection<ComponentDependencyModelEntity> existingComponentsDependencies =
+ getExistingComponentDependencies();
+ Collection<ComponentEntity> componentListWithSameComponentsInHeat =
+ getComponentListWithSameComponentsInHeat();
+ doReturn(componentListWithSameComponentsInHeat).when(componentDaoMock).list(any());
+ Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo();
+ orchestrationUtil.updateVspComponentDependencies(VSP_ID, VERSION01,
+ componentIdNameInfoBeforeProcess, existingComponentsDependencies);
+ Mockito.verify(componentDependencyModelDaoMock, Mockito.times(2)).create(any());
}
@Test
public void testUpdateVspComponentDependenciesHeatReuploadNoComponents() {
- doReturn(getExistingComponentDependencies())
- .when(componentDependencyModelDaoMock).list(anyObject());
- doReturn(new ArrayList<>()).when(componentDaoMock).list(anyObject());
-
- orchestrationUtil
- .updateVspComponentDependencies(VSP_ID, VERSION01, getVspInitComponentIdNameInfo());
-
- verify(componentDependencyModelDaoMock, never()).update(anyObject());
- verify(componentDependencyModelDaoMock, never()).delete(anyObject());
+ Collection<ComponentDependencyModelEntity> existingComponentsDependencies =
+ getExistingComponentDependencies();
+ Collection<ComponentEntity> componentListWithMoreComponentsInHeat =
+ new ArrayList<>();
+ doReturn(componentListWithMoreComponentsInHeat).when(componentDaoMock).list(any());
+ Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo();
+ orchestrationUtil.updateVspComponentDependencies(VSP_ID, VERSION01,
+ componentIdNameInfoBeforeProcess, existingComponentsDependencies);
+ Mockito.verify(componentDependencyModelDaoMock, Mockito.times(0)).create(any());
}
@Test
public void testVspComponentIdNameInfoNoComponents() {
+ Collection<ComponentEntity> initialVspComponents = new ArrayList<>();
+ doReturn(initialVspComponents).when(componentDaoMock).list(any());
Map<String, String> vspComponentIdNameInfo =
orchestrationUtil.getVspComponentIdNameInfo(VSP_ID, VERSION01);
-
- assertEquals(vspComponentIdNameInfo.size(), 0);
+ Assert.assertEquals(vspComponentIdNameInfo.size(), 0);
}
@Test
public void testVspComponentIdNameInfo() {
- doReturn(getInitialVspComponents()).when(componentDaoMock).list(anyObject());
-
+ doReturn(getInitialVspComponents()).when(componentDaoMock).list(any());
Map<String, String> vspComponentIdNameInfo =
orchestrationUtil.getVspComponentIdNameInfo(VSP_ID, VERSION01);
@@ -204,8 +212,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
componentEntity.setId(COMPONENT_ORIG_ID_4);
initialVspComponents.add(componentEntity);
- doReturn(initialVspComponents).when(componentDaoMock).list(anyObject());
-
+ doReturn(initialVspComponents).when(componentDaoMock).list(any());
Map<String, String> vspComponentIdNameInfo =
orchestrationUtil.getVspComponentIdNameInfo(VSP_ID, VERSION01);
@@ -216,6 +223,23 @@ public class OrchestrationTemplateCandidateManagerImplTest {
Assert.assertNull(vspComponentIdNameInfo.get(COMPONENT_ORIG_ID_4));
}
+ @Test
+ public void testGetComponentDependenciesBeforeDeleteInvalid() {
+ Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete =
+ orchestrationUtil.getComponentDependenciesBeforeDelete(null, null);
+ Assert.assertEquals(componentDependenciesBeforeDelete.size(), 0);
+ }
+
+ @Test
+ public void testGetComponentDependenciesBeforeDeleteValid() {
+ Collection<ComponentDependencyModelEntity> existingComponentsDependencies =
+ getExistingComponentDependencies();
+ doReturn(existingComponentsDependencies).when(componentDependencyModelDaoMock).list(any());
+ Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete =
+ orchestrationUtil.getComponentDependenciesBeforeDelete(VSP_ID, VERSION01);
+ Assert.assertEquals(componentDependenciesBeforeDelete.size(), 2);
+ }
+
private Map<String, String> getVspInitComponentIdNameInfo() {
Map<String, String> componentIdNameInfoBeforeProcess = new HashMap<>();
componentIdNameInfoBeforeProcess.put(COMPONENT_ORIG_ID_1, COMPONENT_NAME_1);
@@ -281,6 +305,8 @@ public class OrchestrationTemplateCandidateManagerImplTest {
private ComponentEntity createComponentEntity(String componentId, String componentName) {
ComponentEntity componentEntity = new ComponentEntity();
+ componentEntity.setVspId(VSP_ID);
+ componentEntity.setVersion(VERSION01);
componentEntity.setId(componentId);
ComponentData data = new ComponentData();
data.setName(componentName);
@@ -291,6 +317,9 @@ public class OrchestrationTemplateCandidateManagerImplTest {
private ComponentDependencyModelEntity createComponentDependencyEntity(String sourceComponentId,
String targetComponentId) {
ComponentDependencyModelEntity componentDependency = new ComponentDependencyModelEntity();
+ componentDependency.setVspId(VSP_ID);
+ componentDependency.setVersion(VERSION01);
+ componentDependency.setRelation("dependsOn");
componentDependency.setSourceComponentId(sourceComponentId);
componentDependency.setTargetComponentId(targetComponentId);
return componentDependency;