diff options
Diffstat (limited to 'vid-app-common/src')
6 files changed, 79 insertions, 28 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java index 6bd98fff6..c46266790 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.dal.AsyncInstantiationRepository; import org.onap.vid.exceptions.AccessDeniedException; import org.onap.vid.model.JobAuditStatus; import org.onap.vid.model.ServiceInfo; @@ -37,6 +38,7 @@ import org.onap.vid.services.AsyncInstantiationBusinessLogic; import org.onap.vid.services.AuditService; import org.onap.vid.utils.SystemPropertiesWrapper; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -53,6 +55,7 @@ public class AsyncInstantiationController extends VidRestrictedBaseController { public static final String ASYNC_INSTANTIATION = "asyncInstantiation"; protected final AsyncInstantiationBusinessLogic asyncInstantiationBL; + protected final AsyncInstantiationRepository asyncInstantiationRepository; private final SystemPropertiesWrapper systemPropertiesWrapper; private final RoleProvider roleProvider; @@ -63,8 +66,11 @@ public class AsyncInstantiationController extends VidRestrictedBaseController { protected AuditService auditService; @Autowired - public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL, RoleProvider roleProvider, FeatureManager featureManager, SystemPropertiesWrapper systemPropertiesWrapper) { + public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL, + AsyncInstantiationRepository asyncInstantiationRepository, RoleProvider roleProvider, + FeatureManager featureManager, SystemPropertiesWrapper systemPropertiesWrapper) { this.asyncInstantiationBL = asyncInstantiationBL; + this.asyncInstantiationRepository = asyncInstantiationRepository; this.roleProvider = roleProvider; this.featureManager = featureManager; this.systemPropertiesWrapper = systemPropertiesWrapper; @@ -76,8 +82,13 @@ public class AsyncInstantiationController extends VidRestrictedBaseController { * @return the services list */ @RequestMapping(method = RequestMethod.GET) - public List<ServiceInfo> getServicesInfo(HttpServletRequest request) { - return asyncInstantiationBL.getAllServicesInfo(); + public List<ServiceInfo> getServicesInfo(HttpServletRequest request, + @RequestParam(value = "serviceModelId", required = false) UUID serviceModelId) { + if (serviceModelId == null) { + return asyncInstantiationBL.getAllServicesInfo(); + } else { + return asyncInstantiationRepository.listServicesByServiceModelId(serviceModelId); + } } @RequestMapping(value = "bulk", method = RequestMethod.POST) @@ -158,6 +169,11 @@ public class AsyncInstantiationController extends VidRestrictedBaseController { return new MsoResponseWrapper2(200, uuids); } + @GetMapping("templateTopology/{jobId}") + public ServiceInstantiation getTemplateTopology(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId) { + return asyncInstantiationBL.getJobRequestAsTemplate(jobId); + } + @RequestMapping(value = "/auditStatusForRetry/{trackById}", method = RequestMethod.GET) public JobAuditStatus getResourceAuditStatus(HttpServletRequest request, @PathVariable(value="trackById") String trackById) { return auditService.getResourceAuditStatus(trackById); 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 43d501656..c26b88a5e 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 @@ -154,6 +154,6 @@ class AsyncInstantiationRepository @Autowired constructor(val dataAccessService: 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>; + fun listServicesByServiceModelId(serviceModelId: UUID): List<ServiceInfo> = + dataAccessService.getList(ServiceInfo::class.java, filterByServiceModelId(serviceModelId), orderByCreatedDateAndStatus(), null) as List<ServiceInfo>; } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java index 1202fc9e3..e00758aa1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java @@ -20,6 +20,10 @@ package org.onap.vid.services; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.job.Job; import org.onap.vid.job.impl.JobSharedData; @@ -28,11 +32,6 @@ import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; import org.onap.vid.mso.RestObject; import org.onap.vid.mso.rest.AsyncRequestStatus; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.function.Consumer; - public interface AsyncInstantiationBusinessLogic { List<String> PARAMS_TO_IGNORE = Arrays.asList("vnf_name", "vf_module_name"); @@ -109,5 +108,7 @@ public interface AsyncInstantiationBusinessLogic { ServiceInstantiation getBulkForRetry(UUID jobId); + ServiceInstantiation getJobRequestAsTemplate(UUID jobId); + String getResumeRequestPath(String requestId); } 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 c77eb8230..86d630b2a 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 @@ -534,6 +534,11 @@ public class AsyncInstantiationBusinessLogicImpl implements } @Override + public ServiceInstantiation getJobRequestAsTemplate(UUID jobId) { + return asyncInstantiationRepository.getJobRequest(jobId); + } + + @Override public void addResourceInfo(JobSharedData sharedData, Job.JobStatus jobStatus, String instanceId) { String trackById = ((BaseResource) sharedData.getRequest()).getTrackById(); ResourceInfo resourceInfo = new ResourceInfo(trackById, sharedData.getRootJobId(), instanceId, jobStatus, null); 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 4a893608d..012c37f4d 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 @@ -25,6 +25,8 @@ 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.Matchers.empty; +import static org.hamcrest.Matchers.is; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.core.IsEqual.equalTo; import static org.onap.vid.job.Job.JobStatus.COMPLETED; @@ -50,6 +52,7 @@ import org.onap.vid.services.AsyncInstantiationBaseTest; import org.onap.vid.utils.TimeUtils; import org.springframework.test.context.ContextConfiguration; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class}) @@ -57,17 +60,20 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest @Inject private DataAccessService dataAccessService; + private AsyncInstantiationRepository asyncInstantiationRepository; @BeforeClass void initServicesInfoService() { + asyncInstantiationRepository = new AsyncInstantiationRepository(dataAccessService); createInstanceParamsMaps(); + createNewTestServicesInfoWithServiceModelID(); } private void createNewTestServicesInfoWithServiceModelID() { LocalDateTime NOW = LocalDateTime.now(); - addNewServiceInfo(UUID.randomUUID(), "abc", "1", NOW.minusDays(1L), NOW, COMPLETED, false, false, + addNewServiceInfo(UUID.randomUUID(), "abc", "1", NOW.minusYears(1L), NOW, COMPLETED, false, false, MODEL_UUID); addNewServiceInfo(UUID.randomUUID(), "abc", "2", NOW, NOW, COMPLETED, false, false, MODEL_UUID_2); @@ -77,23 +83,33 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest MODEL_UUID); } - @Test - public void testListServicesByServiceModelId() { - AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService); - createNewTestServicesInfoWithServiceModelID(); - List<ServiceInfo> serviceInfoListResult = underTest.listServicesByServiceModelId(UUID.fromString(MODEL_UUID)); + @DataProvider + public static Object[][] listServicesByServiceModelIdDataProvider() { + return new Object[][]{ + { "services info filtered by MODEL_UUID not hidden , ordered by newer first", MODEL_UUID, "3", "1" }, + { "services info filtered by MODEL_UUID2", MODEL_UUID_2, "2" }, + }; + } - assertThat(serviceInfoListResult.stream().map(ServiceInfo::getServiceInstanceName).collect(toList()), - contains("3", "1")); + @Test(dataProvider = "listServicesByServiceModelIdDataProvider") + public void testListServicesByServiceModelId(String desc, String modelUUID, String... expectedResult) { + List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listServicesByServiceModelId(UUID.fromString(modelUUID)); + assertThat(desc, serviceInfoListResult.stream().map(ServiceInfo::getServiceInstanceName).collect(toList()), + contains(expectedResult)); + } + + @Test + public void whenFilterServiceByNotExistUUID_emptyListIsReturned() { + List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listServicesByServiceModelId(UUID.randomUUID()); + assertThat(serviceInfoListResult, is(empty())); } @Test public void whenSaveNewRequest_thenRequestIsRetrieved() { - AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService); ServiceInstantiation serviceInstantiation = generateALaCarteWithVnfsServiceInstantiationPayload(); UUID jobUuid = UUID.randomUUID(); - underTest.addJobRequest(jobUuid, serviceInstantiation); - ServiceInstantiation stored = underTest.getJobRequest(jobUuid); + asyncInstantiationRepository.addJobRequest(jobUuid, serviceInstantiation); + ServiceInstantiation stored = asyncInstantiationRepository.getJobRequest(jobUuid); assertThat(stored, jsonEquals(serviceInstantiation).when(IGNORING_ARRAY_ORDER)); } @@ -105,7 +121,6 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest @Test public void getResourceInfoByRootJobId_returnsMapOfjobIdResources(){ - AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService); UUID jobId1= UUID.randomUUID(); UUID jobId2= UUID.randomUUID(); AsyncRequestStatus errorMessage= createAsyncRequestStatus("MSO failed resource", "FAILED"); @@ -118,9 +133,9 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest new ResourceInfo("ffffff",jobId2, "66f3123a-f9a8-4591-b481-ghfgh6767567", Job.JobStatus.COMPLETED, null) ); for(ResourceInfo info: requestInfoList){ - underTest.saveResourceInfo(info); + asyncInstantiationRepository.saveResourceInfo(info); } - Map<String, ResourceInfo> storedByTrackId = underTest.getResourceInfoByRootJobId(jobId1); + Map<String, ResourceInfo> storedByTrackId = asyncInstantiationRepository.getResourceInfoByRootJobId(jobId1); assertThat(storedByTrackId.values(), hasSize(4)); assertThat(storedByTrackId.get("aaaaaa").getInstanceId(), equalTo("64f3123a-f9a8-4591-b481-d662134bcb52")); assertThat(storedByTrackId.get("cccccc").getErrorMessage().request.requestStatus.getStatusMessage(), equalTo("MSO failed resource")); 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 54015d4b3..56aaf1e83 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 @@ -35,15 +35,16 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.core.Every.everyItem; import static org.hamcrest.core.IsEqual.equalTo; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; @@ -199,6 +200,7 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT Mockito.reset(aaiClient); Mockito.reset(jobAdapterMock); Mockito.reset(jobsBrokerServiceMock); + Mockito.reset(asyncInstantiationRepository); mockAaiClientAnyNameFree(); enableAddCloudOwnerOnMsoRequest(); } @@ -1366,4 +1368,16 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT assertThat(path, equalTo("/serviceInstantiation/v7/serviceInstances/myService/vnfs/myVNF/vfModules/myVFModule/replace")); } + + @Test + public void getJobRequestAsTemplate_whenIsCalled_asyncInstantiationRepositoryGetJobRequestIsDelegated() { + UUID jobId = UUID.randomUUID(); + ServiceInstantiation expected = mock(ServiceInstantiation.class); + doReturn(expected).when(asyncInstantiationRepository).getJobRequest(jobId); + + ServiceInstantiation jobRequestAsTemplate = asyncInstantiationBL.getJobRequestAsTemplate(jobId); + + assertThat(jobRequestAsTemplate, is(sameInstance(expected))); + + } } |