summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-12-01 14:18:41 +0000
committerGerrit Code Review <gerrit@onap.org>2019-12-01 14:18:41 +0000
commitd8a9536b717d0ff48f25deee301f033eceb6e100 (patch)
tree5ab9a6faa3bb284ead0cf74655351e6f8c360c47 /vid-app-common/src
parentb167cf459a0064310235c3f48918378202e4a41f (diff)
parentc4c9b3b399036c71f80abe3cb2ba53e8eb8fefd4 (diff)
Merge "Add filter for serviceInfo by service model id"
Diffstat (limited to 'vid-app-common/src')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt18
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java34
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java72
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java77
4 files changed, 147 insertions, 54 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt b/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
index 79c7297a3..43d501656 100644
--- a/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
@@ -86,13 +86,22 @@ class AsyncInstantiationRepository @Autowired constructor(val dataAccessService:
private fun filterByCreationDateAndNotDeleted(): String {
val minus3Months = LocalDateTime.now().minusMonths(3)
val filterDate = Timestamp.valueOf(minus3Months)
+ return filterServicesByNotHiddenAndNotDeleted() +
+ " and created >= '" + filterDate + "' "
+ }
+
+ private fun filterByServiceModelId(serviceModelUuid: UUID): String {
+ return filterServicesByNotHiddenAndNotDeleted() +
+ " and SERVICE_MODEL_ID = '$serviceModelUuid'"
+ }
+
+ private fun filterServicesByNotHiddenAndNotDeleted(): String {
return " WHERE" +
" hidden = false" +
- " and deleted_at is null" + // don't fetch deleted
-
- " and created >= '" + filterDate + "' "
+ " and deleted_at is null" // don't fetch deleted
}
+
private fun orderByCreatedDateAndStatus(): String {
return " createdBulkDate DESC ,\n" +
" (CASE jobStatus\n" +
@@ -144,4 +153,7 @@ class AsyncInstantiationRepository @Autowired constructor(val dataAccessService:
.joinToString(" $conditionType ")
return dataAccessService.getList(className, " WHERE $condition", orderBy, null) as List<T>
}
+
+ fun listServicesByServiceModelId(modelUuid: UUID): List<ServiceInfo> =
+ dataAccessService.getList(ServiceInfo::class.java, filterByServiceModelId(modelUuid), orderByCreatedDateAndStatus(), null) as List<ServiceInfo>;
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java
index be5a44e82..4a893608d 100644
--- a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java
@@ -20,18 +20,21 @@
package org.onap.vid.dal;
+import static java.util.stream.Collectors.toList;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.core.IsEqual.equalTo;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED;
import com.google.common.collect.ImmutableList;
+import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import java.util.stream.Collectors;
import javax.inject.Inject;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.util.SystemProperties;
@@ -39,6 +42,7 @@ import org.onap.vid.config.DataSourceConfig;
import org.onap.vid.config.MockedAaiClientAndFeatureManagerConfig;
import org.onap.vid.job.Job;
import org.onap.vid.model.ResourceInfo;
+import org.onap.vid.model.ServiceInfo;
import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
import org.onap.vid.mso.rest.AsyncRequestStatus;
import org.onap.vid.mso.rest.RequestStatus;
@@ -59,6 +63,30 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest
createInstanceParamsMaps();
}
+ private void createNewTestServicesInfoWithServiceModelID() {
+
+ LocalDateTime NOW = LocalDateTime.now();
+
+ addNewServiceInfo(UUID.randomUUID(), "abc", "1", NOW.minusDays(1L), NOW, COMPLETED, false, false,
+ MODEL_UUID);
+ addNewServiceInfo(UUID.randomUUID(), "abc", "2", NOW, NOW, COMPLETED, false, false,
+ MODEL_UUID_2);
+ addNewServiceInfo(UUID.randomUUID(), "abc", "3", NOW, NOW, COMPLETED, false, false,
+ MODEL_UUID);
+ addNewServiceInfo(UUID.randomUUID(), "abc", "hidden", NOW, NOW, COMPLETED, true, false,
+ MODEL_UUID);
+ }
+
+ @Test
+ public void testListServicesByServiceModelId() {
+ AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService);
+ createNewTestServicesInfoWithServiceModelID();
+ List<ServiceInfo> serviceInfoListResult = underTest.listServicesByServiceModelId(UUID.fromString(MODEL_UUID));
+
+ assertThat(serviceInfoListResult.stream().map(ServiceInfo::getServiceInstanceName).collect(toList()),
+ contains("3", "1"));
+ }
+
@Test
public void whenSaveNewRequest_thenRequestIsRetrieved() {
AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService);
@@ -98,6 +126,8 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest
assertThat(storedByTrackId.get("cccccc").getErrorMessage().request.requestStatus.getStatusMessage(), equalTo("MSO failed resource"));
assertThat(storedByTrackId.get("cccccc").getErrorMessage().request.requestStatus.getRequestState(), equalTo("FAILED"));
assertThat(storedByTrackId.get("dddddd").getErrorMessage(), equalTo(null));
- assertThat(storedByTrackId.values(), jsonEquals(requestInfoList.stream().filter(i-> i.getRootJobId().equals(jobId1)).collect(Collectors.toList())).when(IGNORING_ARRAY_ORDER));
+ assertThat(storedByTrackId.values(),
+ jsonEquals(requestInfoList.stream().filter(i -> i.getRootJobId().equals(jobId1)).collect(
+ toList())).when(IGNORING_ARRAY_ORDER));
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
index cd66107e2..d41ce87bf 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
@@ -22,6 +22,8 @@ package org.onap.vid.services;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -32,9 +34,12 @@ import static org.onap.vid.model.VidNotions.ModelCategory;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -43,9 +48,14 @@ import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
+import org.hibernate.SessionFactory;
+import org.onap.portalsdk.core.domain.FusionObject;
+import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.vid.aai.AaiClientInterface;
import org.onap.vid.aai.ExceptionWithRequestInfo;
+import org.onap.vid.job.Job.JobStatus;
import org.onap.vid.model.Action;
+import org.onap.vid.model.ServiceInfo;
import org.onap.vid.model.VidNotions;
import org.onap.vid.model.serviceInstantiation.InstanceGroup;
import org.onap.vid.model.serviceInstantiation.Network;
@@ -57,13 +67,19 @@ import org.onap.vid.mso.model.ModelInfo;
import org.onap.vid.mso.rest.AsyncRequestStatus;
import org.onap.vid.mso.rest.RequestStatus;
import org.onap.vid.properties.Features;
+import org.onap.vid.services.AsyncInstantiationBusinessLogicTest.ServiceInfoComparator;
+import org.onap.vid.utils.DaoUtils;
import org.onap.vid.utils.TimeUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.togglz.core.manager.FeatureManager;
public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests {
+ public static final String MODEL_UUID = "337be3fc-293e-43ec-af0b-cf932dad07e6";
+ public static final String MODEL_UUID_2 = "ce052844-22ba-4030-a838-822f2b39eb9b";
+
public static final String OWNING_ENTITY_ID = "038d99af-0427-42c2-9d15-971b99b9b489";
public static final String JULIO_ERICKSON = "JULIO ERICKSON";
public static final String PROJECT_NAME = "{some project name}";
@@ -90,6 +106,12 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
protected HashMap<String, String> vfModuleInstanceParamsMapWithParamsToRemove;
protected HashMap<String, String> vnfInstanceParamsMapWithParamsToRemove;
+ protected int serviceCount = 0;
+
+
+ @Inject
+ protected DataAccessService dataAccessService;
+
@Inject
protected FeatureManager featureManager;
@@ -99,6 +121,56 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
@Inject
protected CloudOwnerService cloudOwnerService;
+ @Autowired
+ protected SessionFactory sessionFactory;
+
+
+ protected static Date toDate(LocalDateTime localDateTime) {
+ return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+ }
+
+ protected HashMap<String, Object> getPropsMap() {
+ HashMap<String, Object> props = new HashMap<>();
+ props.put(FusionObject.Parameters.PARAM_USERID, 0);
+ return props;
+ }
+
+
+ private void setCreateDateToServiceInfo(UUID jobUuid, LocalDateTime createDate) {
+ List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, getPropsMap());
+ DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> {
+ serviceInfoList.stream()
+ .filter(serviceInfo -> jobUuid.equals(serviceInfo.getJobId()))
+ .forEach(serviceInfo -> {
+ serviceInfo.setCreated(toDate(createDate));
+ session.saveOrUpdate(serviceInfo);
+ });
+ return 1;
+ });
+ }
+
+ protected void addNewServiceInfo(UUID uuid, String userId, String serviceName, LocalDateTime createDate,
+ LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled,
+ String modelUUID) {
+ ServiceInfo serviceInfo = new ServiceInfo();
+ serviceInfo.setJobId(uuid);
+ serviceInfo.setUserId(userId);
+ serviceInfo.setServiceInstanceName(serviceName);
+ serviceInfo.setStatusModifiedDate(toDate(statusModifiedDate));
+ serviceInfo.setJobStatus(status);
+ serviceInfo.setPause(false);
+ serviceInfo.setOwningEntityId("1234");
+ serviceInfo.setCreatedBulkDate(toDate(createDate));
+ serviceInfo.setRetryEnabled(retryEnabled);
+ serviceInfo.setServiceModelId(modelUUID);
+ serviceInfo.setHidden(isHidden);
+ dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
+ setCreateDateToServiceInfo(uuid, createDate);
+ serviceCount++;
+
+ }
+
+
public ServiceInstantiation generateMockMacroServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure) {
return generateMockServiceInstantiationPayload(isPause, vnfs, Collections.EMPTY_MAP, Collections.EMPTY_MAP, bulkSize, isUserProvidedNaming, projectName, rollbackOnFailure, false, null, Action.Create, null);
}
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 c1a6abc73..54015d4b3 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
@@ -93,10 +93,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-import javax.inject.Inject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.time.DateUtils;
-import org.hibernate.SessionFactory;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.mockito.ArgumentCaptor;
@@ -104,8 +102,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
-import org.onap.portalsdk.core.domain.FusionObject;
-import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.aai.model.ResourceType;
@@ -143,7 +139,6 @@ import org.onap.vid.properties.Features;
import org.onap.vid.testUtils.TestUtils;
import org.onap.vid.utils.DaoUtils;
import org.onap.vid.utils.TimeUtils;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
@@ -155,8 +150,7 @@ import org.testng.annotations.Test;
@ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class})
public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseTest {
- @Inject
- private DataAccessService dataAccessService;
+
@Mock
private JobAdapter jobAdapterMock;
@@ -168,15 +162,11 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
private AuditService auditService;
- @Autowired
- private SessionFactory sessionFactory;
private AsyncInstantiationBusinessLogicImpl asyncInstantiationBL;
protected MsoRequestBuilder msoRequestBuilder;
- private int serviceCount = 0;
-
private static final String UPDATE_SERVICE_INFO_EXCEPTION_MESSAGE =
"Failed to retrieve class .*ServiceInfo with jobId .* from table. no resource found";
@@ -236,13 +226,15 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
uuid = UUID.randomUUID();
addNewJob(uuid);
createdDate = NOW.minusYears(1);
- addNewServiceInfo(uuid, userId, "Old", createdDate, createdDate, COMPLETED, false, false);
+ addNewServiceInfo(uuid, userId, "Old", createdDate, createdDate, COMPLETED, false, false,
+ MODEL_UUID);
uuid = UUID.randomUUID();
addNewJob(uuid);
createdDate = NOW.minusDays(20);
modifiedDate = NOW.minusDays(19);
- addNewServiceInfo(uuid, userId, "Hidden", createdDate, modifiedDate, PAUSE, true, false);
+ addNewServiceInfo(uuid, userId, "Hidden", createdDate, modifiedDate, PAUSE, true, false,
+ MODEL_UUID);
createNewTestServicesInfo(String.valueOf(userId));
}
@@ -257,20 +249,26 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
addNewJob(uuid);
createdDate = NOW.minusDays(40);
- addNewServiceInfo(uuid, userId, "service instance 5", createdDate, createdDate, COMPLETED, false, false);
- addNewServiceInfo(uuid, userId, "service instance 6", createdDate, createdDate, STOPPED, false, false);
+ addNewServiceInfo(uuid, userId, "service instance 5", createdDate, createdDate, COMPLETED, false, false,
+ MODEL_UUID);
+ addNewServiceInfo(uuid, userId, "service instance 6", createdDate, createdDate, STOPPED, false, false,
+ MODEL_UUID);
uuid = UUID.randomUUID();
addNewJob(uuid);
createdDate = NOW.minusDays(20);
modifiedDate = NOW.minusDays(10);
- addNewServiceInfo(uuid, userId, "service instance 4", createdDate, modifiedDate, STOPPED, false, false);
- addNewServiceInfo(uuid, userId, "service instance 2", createdDate, modifiedDate, COMPLETED, false, false);
- addNewServiceInfo(uuid, userId, "service instance 3", createdDate, modifiedDate, PAUSE, false, false);
+ addNewServiceInfo(uuid, userId, "service instance 4", createdDate, modifiedDate, STOPPED, false, false,
+ MODEL_UUID);
+ addNewServiceInfo(uuid, userId, "service instance 2", createdDate, modifiedDate, COMPLETED, false, false,
+ MODEL_UUID);
+ addNewServiceInfo(uuid, userId, "service instance 3", createdDate, modifiedDate, PAUSE, false, false,
+ MODEL_UUID);
modifiedDate = NOW.minusDays(19);
- addNewServiceInfo(uuid, userId, "service instance 1", createdDate, modifiedDate, FAILED, false, false);
+ addNewServiceInfo(uuid, userId, "service instance 1", createdDate, modifiedDate, FAILED, false, false,
+ MODEL_UUID);
// Job to a different user
@@ -278,10 +276,13 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
addNewJob(uuid);
createdDate = NOW.minusMonths(2);
- addNewServiceInfo(uuid, "2221", "service instance 7", createdDate, createdDate, COMPLETED, false, false);
+ addNewServiceInfo(uuid, "2221", "service instance 7", createdDate, createdDate, COMPLETED, false, false,
+ MODEL_UUID);
}
+
+
private UUID createServicesInfoWithDefaultValues(Job.JobStatus status) {
LocalDateTime NOW = LocalDateTime.now();
@@ -290,7 +291,8 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
uuid = UUID.randomUUID();
addNewJob(uuid, status);
- addNewServiceInfo(uuid, null, "service instance 1", NOW, NOW, status, false, false);
+ addNewServiceInfo(uuid, null, "service instance 1", NOW, NOW, status, false, false,
+ MODEL_UUID);
return uuid;
@@ -303,9 +305,7 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
return expectedOrderServiceInfo;
}
- private static Date toDate(LocalDateTime localDateTime) {
- return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
- }
+
private LocalDateTime fromDate(Date date) {
return Instant.ofEpochMilli(date.getTime())
@@ -313,25 +313,6 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
.toLocalDateTime();
}
- private void addNewServiceInfo(UUID uuid, String userId, String serviceName, LocalDateTime createDate, LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled) {
- ServiceInfo serviceInfo = new ServiceInfo();
- serviceInfo.setJobId(uuid);
- serviceInfo.setUserId(userId);
- serviceInfo.setServiceInstanceName(serviceName);
- serviceInfo.setStatusModifiedDate(toDate(statusModifiedDate));
- serviceInfo.setJobStatus(status);
- serviceInfo.setPause(false);
- serviceInfo.setOwningEntityId("1234");
- serviceInfo.setCreatedBulkDate(toDate(createDate));
- serviceInfo.setRetryEnabled(retryEnabled);
-
- serviceInfo.setHidden(isHidden);
- dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
- setCreateDateToServiceInfo(uuid, createDate);
- serviceCount++;
-
- }
-
private void setCreateDateToServiceInfo(UUID jobUuid, LocalDateTime createDate) {
List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, getPropsMap());
DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> {
@@ -357,7 +338,9 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
}
private ServiceInstantiation addOriginalService(UUID jobId, String userID){
- addNewServiceInfo(jobId, userID, "name", LocalDateTime.now(), LocalDateTime.now(), COMPLETED_WITH_ERRORS, false, true);
+ addNewServiceInfo(jobId, userID, "name", LocalDateTime.now(), LocalDateTime.now(), COMPLETED_WITH_ERRORS, false,
+ true,
+ MODEL_UUID);
assertThat(asyncInstantiationRepository.getServiceInfoByJobId(jobId).isRetryEnabled(), is(true));
ServiceInstantiation originalServiceInstantiation = prepareServiceInstantiation(true, 1);
doReturn(originalServiceInstantiation).when(asyncInstantiationRepository).getJobRequest(jobId);
@@ -469,11 +452,7 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
when(aaiClient.isNodeTypeExistsByName(uniqueName, serviceInstance)).thenReturn(true);
}
- private HashMap<String, Object> getPropsMap() {
- HashMap<String, Object> props = new HashMap<>();
- props.put(FusionObject.Parameters.PARAM_USERID, 0);
- return props;
- }
+
@DataProvider