aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-12-24 11:04:49 +0200
committerIttay Stern <ittay.stern@att.com>2019-12-24 12:58:05 +0200
commit206d87766f6547934bf4298de326c63c8e31481a (patch)
treeeb72b44309b35bc414bab3a60d0a721d605d8f6c /vid-app-common/src
parent89de17b50dcd1d29fb87acfe518d1ddf43c1408a (diff)
Write async instantiations request-summary to DB
Issue-ID: VID-724 Change-Id: I8b4bb55f6d7d59da321ef7b52802ea8bd957c1c6 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java26
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java16
2 files changed, 34 insertions, 8 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
index 6729bdac8..2cc76492f 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
@@ -62,6 +62,7 @@ import org.onap.vid.model.Action;
import org.onap.vid.model.NameCounter;
import org.onap.vid.model.ResourceInfo;
import org.onap.vid.model.ServiceInfo;
+import org.onap.vid.model.ServiceInfo.ServiceAction;
import org.onap.vid.model.serviceInstantiation.BaseResource;
import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
import org.onap.vid.model.serviceInstantiation.VfModule;
@@ -177,7 +178,10 @@ public class AsyncInstantiationBusinessLogicImpl implements
Job job = jobAdapter.createServiceInstantiationJob(jobType, requestPerJob, templateId, userId, request.getTestApi(), optimisticUniqueServiceInstanceName, i);
UUID jobId = job.getUuid();
- asyncInstantiationRepository.saveServiceInfo(createServiceInfo(userId, requestPerJob, jobId, templateId, createdBulkDate, optimisticUniqueServiceInstanceName, serviceAction));
+ asyncInstantiationRepository.saveServiceInfo(createServiceInfo(
+ userId, requestPerJob, jobId, templateId, createdBulkDate,
+ optimisticUniqueServiceInstanceName, serviceAction,
+ requestSummaryOrNull(requestPerJob)));
asyncInstantiationRepository.addJobRequest(jobId, requestPerJob);
auditService.auditVidStatus(jobId, job.getStatus());
uuids.add(jobId);
@@ -187,7 +191,19 @@ public class AsyncInstantiationBusinessLogicImpl implements
return uuids;
}
- public Map<String, Long> getSummarizedChildrenMap(ServiceInstantiation serviceInstantiation){
+ Map<String, Long> requestSummaryOrNull(ServiceInstantiation request) {
+ if (!featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)) {
+ return null;
+ }
+
+ if (getAction(request) != ServiceAction.INSTANTIATE) {
+ return null;
+ }
+
+ return summarizedChildrenMap(request);
+ }
+
+ public Map<String, Long> summarizedChildrenMap(ServiceInstantiation serviceInstantiation){
Stream<String> existingTypesStream =
allDeepChildResources(serviceInstantiation)
.map(this::getModelTypes)
@@ -242,7 +258,9 @@ public class AsyncInstantiationBusinessLogicImpl implements
return isNotEmpty(instanceName) ? getUniqueNameFromDbOnly(instanceName) : instanceName;
}
- protected ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId, UUID templateId, Date createdBulkDate, String optimisticUniqueServiceInstanceName, ServiceInfo.ServiceAction serviceAction) {
+ protected ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId,
+ UUID templateId, Date createdBulkDate, String optimisticUniqueServiceInstanceName,
+ ServiceInfo.ServiceAction serviceAction, Map<String, Long> requestSummary) {
return new ServiceInfo(
userId,
serviceInstantiation.isALaCarte(),
@@ -267,7 +285,7 @@ public class AsyncInstantiationBusinessLogicImpl implements
createdBulkDate,
serviceAction,
false,
- null);
+ requestSummary);
}
@Override
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
index 0cfe8059a..7a6b94a1a 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
@@ -502,14 +502,22 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
}
@Test(dataProvider = "dataProviderSummarizedMap")
- public void getSummarizedMap(String pathInResource, Map<String, Long> expectedMap){
+ public void summarizedChildrenMap_givenServiceInstantiation_yieldCorrectMap(String pathInResource, Map<String, Long> expectedMap){
ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject(
pathInResource, ServiceInstantiation.class);
- Map<String, Long> childrenMap = asyncInstantiationBL.getSummarizedChildrenMap(serviceInstantiation);
+ Map<String, Long> childrenMap = asyncInstantiationBL.summarizedChildrenMap(serviceInstantiation);
assertEquals(childrenMap,expectedMap);
-
}
+ @Test
+ public void requestSummaryOrNull_givenActionWhichIsNotCreate_yieldNullRegardlessOfPayload(){
+ ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
+
+ when(serviceInstantiation.getAction()).thenReturn(Action.Upgrade);
+ when(featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(true);
+
+ assertThat(asyncInstantiationBL.requestSummaryOrNull(serviceInstantiation), is(nullValue()));
+ }
@Test
public void whenPushBulkJob_thenJobRequestIsSaveInJobRequestDb() {
@@ -755,7 +763,7 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
UUID.randomUUID(),
UUID.randomUUID(),
new Date(),
- "myName", ServiceInfo.ServiceAction.INSTANTIATE);
+ "myName", ServiceInfo.ServiceAction.INSTANTIATE, null);
assertEquals(SERVICE_MODEL_VERSION_ID, serviceInfo.getServiceModelId());
}