From b3568581e94345f0753b060158273c57892686dd Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Tue, 6 Aug 2019 18:47:30 +0300 Subject: use cache for retrieving all subscribers list Issue-ID: VID-378 Signed-off-by: Eylon Malin Change-Id: I73fcc78ebbd8ee01349ecefa924c20014ca33907 --- .../java/org/onap/vid/controller/WebConfig.java | 6 ++--- .../org/onap/vid/reports/BasicReportGenerator.java | 27 +++++++++++----------- .../main/java/org/onap/vid/roles/RoleProvider.java | 6 ++--- .../java/org/onap/vid/services/AaiService.java | 3 +-- .../java/org/onap/vid/services/AaiServiceImpl.java | 20 ++++++---------- .../org/onap/vid/controller/LocalWebConfig.java | 6 ++--- .../onap/vid/reports/BasicReportGeneratorTest.java | 16 +++++-------- .../java/org/onap/vid/roles/RoleProviderTest.java | 24 +++++++++---------- .../vid/services/AAIServiceIntegrativeTest.java | 2 +- .../org/onap/vid/services/AaiServiceImplTest.java | 22 +++++++----------- 10 files changed, 56 insertions(+), 76 deletions(-) (limited to 'vid-app-common') diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java index 71c6bf345..b9908d1e3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java @@ -98,9 +98,9 @@ public class WebConfig { } @Bean - public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient, - AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) { - return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiServiceTree, executorService); + public AaiService getAaiService(AaiClientInterface aaiClient, AaiResponseTranslator aaiResponseTranslator, + AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) { + return new AaiServiceImpl(aaiClient, aaiResponseTranslator, aaiServiceTree, executorService); } @Bean diff --git a/vid-app-common/src/main/java/org/onap/vid/reports/BasicReportGenerator.java b/vid-app-common/src/main/java/org/onap/vid/reports/BasicReportGenerator.java index 00f8077d3..4c8447069 100644 --- a/vid-app-common/src/main/java/org/onap/vid/reports/BasicReportGenerator.java +++ b/vid-app-common/src/main/java/org/onap/vid/reports/BasicReportGenerator.java @@ -19,40 +19,39 @@ */ package org.onap.vid.reports; +import static org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID; + import com.google.common.collect.ImmutableMap; import io.joshworks.restclient.http.HttpResponse; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import javax.servlet.http.HttpServletRequest; +import org.onap.vid.aai.AaiOverTLSClientInterface; import org.onap.vid.controller.ControllersUtils; import org.onap.vid.model.GitRepositoryState; import org.onap.vid.model.SubscriberList; import org.onap.vid.model.errorReport.ReportCreationParameters; import org.onap.vid.model.probes.ExternalComponentStatus; -import org.onap.vid.services.AaiService; import org.onap.vid.services.ProbeService; import org.onap.vid.utils.SystemPropertiesWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import static org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID; - @Component public class BasicReportGenerator implements ReportGenerator { private static final String GIT_PROPERTIES_FILENAME = "git.properties"; - private final AaiService aaiService; + private final AaiOverTLSClientInterface aaiOverTLSClient; private final SystemPropertiesWrapper systemPropertiesWrapper; private final ProbeService probeService; @Autowired - public BasicReportGenerator(AaiService aaiService, SystemPropertiesWrapper systemPropertiesWrapper, + public BasicReportGenerator(AaiOverTLSClientInterface aaiOverTLSClient, SystemPropertiesWrapper systemPropertiesWrapper, ProbeService probeService) { - this.aaiService = aaiService; + this.aaiOverTLSClient = aaiOverTLSClient; this.systemPropertiesWrapper = systemPropertiesWrapper; this.probeService = probeService; } @@ -96,7 +95,7 @@ public class BasicReportGenerator implements ReportGenerator { ImmutableMap getFullSubscriberList() { ImmutableMap fullSubscriberList; try { - HttpResponse fullSubscriberListResponse = aaiService.getFullSubscriberList(); + HttpResponse fullSubscriberListResponse = aaiOverTLSClient.getAllSubscribers(); fullSubscriberList = ImmutableMap.builder() .put("status", fullSubscriberListResponse.getStatus()) .put("body", fullSubscriberListResponse.getBody()) diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java index 6c0fd3f52..898db332c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java +++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java @@ -23,7 +23,6 @@ package org.onap.vid.roles; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import io.joshworks.restclient.http.HttpResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -34,6 +33,7 @@ import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.web.support.UserUtils; +import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.exceptions.RoleParsingException; import org.onap.vid.model.ModelConstants; import org.onap.vid.model.Subscriber; @@ -123,8 +123,8 @@ public class RoleProvider { private String replaceSubscriberNameToGlobalCustomerID(String subscriberName, String logPrefix) { // SubscriberList should be cached by cacheProvider so by calling getFullSubscriberList() method we just gat it from cache - HttpResponse subscribersResponse = aaiService.getFullSubscriberList(); - SubscriberList subscribers = subscribersResponse.getBody(); + AaiResponse subscribersResponse = aaiService.getFullSubscriberList(); + SubscriberList subscribers = subscribersResponse.getT(); try { LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "subscribers list size is " + subscribers.customer.size() + " with the values " + om.writeValueAsString(subscribers.customer)); diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java index 6c63ae07c..31fbe65d8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java @@ -21,7 +21,6 @@ package org.onap.vid.services; -import io.joshworks.restclient.http.HttpResponse; import java.util.Collection; import java.util.List; import javax.ws.rs.core.Response; @@ -53,7 +52,7 @@ public interface AaiService { AaiResponse getServiceInstanceSearchResults(String subscriberId, String instanceIdentifier, RoleValidator roleProvider, List owningEntities, List projects); - HttpResponse getFullSubscriberList(); + AaiResponse getFullSubscriberList(); AaiResponse getServices(RoleValidator roleValidator); diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index fcdae441c..9b890478f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -25,7 +25,6 @@ import static org.onap.vid.aai.AaiClient.QUERY_FORMAT_RESOURCE; import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; import com.fasterxml.jackson.databind.JsonNode; -import io.joshworks.restclient.http.HttpResponse; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; @@ -104,7 +103,6 @@ public class AaiServiceImpl implements AaiService { private int indexOfSubscriberName = 6; private AaiClientInterface aaiClient; - private AaiOverTLSClientInterface aaiOverTLSClient; private AaiResponseTranslator aaiResponseTranslator; private AAIServiceTree aaiServiceTree; private ExecutorService executorService; @@ -115,13 +113,11 @@ public class AaiServiceImpl implements AaiService { @Autowired public AaiServiceImpl( AaiClientInterface aaiClient, - AaiOverTLSClientInterface aaiOverTLSClient, AaiResponseTranslator aaiResponseTranslator, AAIServiceTree aaiServiceTree, ExecutorService executorService) { this.aaiClient = aaiClient; - this.aaiOverTLSClient = aaiOverTLSClient; this.aaiResponseTranslator = aaiResponseTranslator; this.aaiServiceTree = aaiServiceTree; this.executorService = executorService; @@ -241,13 +237,11 @@ public class AaiServiceImpl implements AaiService { @Override public SubscriberFilteredResults getFullSubscriberList(RoleValidator roleValidator) { - HttpResponse allSubscribers = aaiOverTLSClient.getAllSubscribers(); - return new SubscriberFilteredResults( - roleValidator, - allSubscribers.getBody(), - allSubscribers.getStatusText(), - allSubscribers.getStatus() - ); + AaiResponse subscriberResponse = aaiClient.getAllSubscribers(); + + return new SubscriberFilteredResults(roleValidator, subscriberResponse.getT(), + subscriberResponse.getErrorMessage(), + subscriberResponse.getHttpCode()); } @Override @@ -256,8 +250,8 @@ public class AaiServiceImpl implements AaiService { } @Override - public HttpResponse getFullSubscriberList() { - return aaiOverTLSClient.getAllSubscribers(); + public AaiResponse getFullSubscriberList() { + return aaiClient.getAllSubscribers(); } @Override diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java b/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java index aae1b0621..17e0c44e0 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java @@ -71,9 +71,9 @@ public class LocalWebConfig { } @Bean - public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient, - AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) { - return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiServiceTree, executorService); + public AaiService getAaiService(AaiClientInterface aaiClient, AaiResponseTranslator aaiResponseTranslator, + AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) { + return new AaiServiceImpl(aaiClient, aaiResponseTranslator, aaiServiceTree, executorService); } @Bean diff --git a/vid-app-common/src/test/java/org/onap/vid/reports/BasicReportGeneratorTest.java b/vid-app-common/src/test/java/org/onap/vid/reports/BasicReportGeneratorTest.java index d34646dcb..cc4578bf0 100644 --- a/vid-app-common/src/test/java/org/onap/vid/reports/BasicReportGeneratorTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/reports/BasicReportGeneratorTest.java @@ -33,6 +33,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.AaiClient; +import org.onap.vid.aai.AaiOverTLSClientInterface; import org.onap.vid.model.SubscriberList; import org.onap.vid.model.errorReport.ReportCreationParameters; import org.onap.vid.model.probes.ExternalComponentStatus; @@ -67,13 +68,8 @@ public class BasicReportGeneratorTest { private ProbeService probeService; @Mock - private AaiClient aaiClient; - @Mock - private SchedulerService schedulerService; - @Mock - private AaiService aaiService; - @Mock - private RoleProvider roleProvider; + AaiOverTLSClientInterface aaiOverTLSClient; + @Mock private SystemPropertiesWrapper systemPropertiesWrapper; @@ -136,7 +132,7 @@ public class BasicReportGeneratorTest { .put("headers", headers) .build(); - when(aaiService.getFullSubscriberList()).thenReturn(subscriberListResponse); + when(aaiOverTLSClient.getAllSubscribers()).thenReturn(subscriberListResponse); when(subscriberListResponse.getStatus()).thenReturn(status); when(subscriberListResponse.getBody()).thenReturn(subscriberList); when(subscriberListResponse.getHeaders()).thenReturn(headers); @@ -154,7 +150,7 @@ public class BasicReportGeneratorTest { RestClientException expectedException = mock(RestClientException.class); ImmutableMap expectedResult = ImmutableMap.of("exception", expectedException.toString()); - when(aaiService.getFullSubscriberList()).thenThrow(expectedException); + when(aaiOverTLSClient.getAllSubscribers()).thenThrow(expectedException); //when ImmutableMap actualResult = basicReportGenerator.getFullSubscriberList(); @@ -162,4 +158,4 @@ public class BasicReportGeneratorTest { //then assertThat(actualResult).isEqualTo(expectedResult); } -} \ No newline at end of file +} diff --git a/vid-app-common/src/test/java/org/onap/vid/roles/RoleProviderTest.java b/vid-app-common/src/test/java/org/onap/vid/roles/RoleProviderTest.java index 6ba0e4039..c1033d2d0 100644 --- a/vid-app-common/src/test/java/org/onap/vid/roles/RoleProviderTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/roles/RoleProviderTest.java @@ -21,10 +21,17 @@ package org.onap.vid.roles; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + import com.google.common.collect.ImmutableMap; -import io.joshworks.restclient.http.HttpResponse; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; import org.assertj.core.util.Lists; import org.mockito.Mock; +import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.exceptions.RoleParsingException; import org.onap.vid.model.Subscriber; import org.onap.vid.model.SubscriberList; @@ -32,14 +39,6 @@ import org.onap.vid.services.AaiService; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - public class RoleProviderTest { private static final String SAMPLE_SUBSCRIBER = "sampleSubscriber"; @@ -57,8 +56,7 @@ public class RoleProviderTest { private HttpServletRequest request; @Mock - private HttpResponse subscriberListHttpResponse; - + private AaiResponse subscriberListResponse; private RoleProvider roleProvider; @@ -150,8 +148,8 @@ public class RoleProviderTest { subscriber.subscriberName = SAMPLE_SUBSCRIBER; subscriber.globalCustomerId = SAMPLE_CUSTOMER_ID; SubscriberList subscriberList = new SubscriberList(Lists.list(subscriber)); - when(aaiService.getFullSubscriberList()).thenReturn(subscriberListHttpResponse); - when(subscriberListHttpResponse.getBody()).thenReturn(subscriberList); + when(aaiService.getFullSubscriberList()).thenReturn(subscriberListResponse); + when(subscriberListResponse.getT()).thenReturn(subscriberList); } private Map createRoles() { diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java index d42747c20..28c844cda 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java @@ -68,7 +68,7 @@ public class AAIServiceIntegrativeTest extends TestWithAaiClient { null, executorService ); - return new AaiServiceImpl(aaiClient, null, null, aaiServiceTree, executorService); + return new AaiServiceImpl(aaiClient, null, aaiServiceTree, executorService); } @BeforeMethod diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java index 09a53684f..20409d327 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java @@ -34,7 +34,6 @@ import static org.onap.vid.model.aaiTree.NodeType.SERVICE_INSTANCE; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.joshworks.restclient.http.HttpResponse; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -54,7 +53,6 @@ import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.vid.aai.AaiClientInterface; import org.onap.vid.aai.AaiGetVnfResponse; -import org.onap.vid.aai.AaiOverTLSClientInterface; import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.AaiResponseTranslator; import org.onap.vid.aai.ServiceInstancesSearchResults; @@ -118,7 +116,7 @@ public class AaiServiceImplTest { private static final String CLOUD_TYPE = "CLOUD_TYPE"; @Mock - private HttpResponse responseAllSubscribers; + private AaiResponse responseAllSubscribers; @Mock private AaiResponse aaiResponseOpEnvList; @Mock @@ -130,8 +128,7 @@ public class AaiServiceImplTest { @Mock private AaiClientInterface aaiClient; - @Mock - private AaiOverTLSClientInterface aaiOverTLSClient; + @Mock private AaiResponseTranslator aaiResponseTranslator; @Mock @@ -144,11 +141,8 @@ public class AaiServiceImplTest { @Test public void shouldGetFullSubscriberListWithoutValidator() { - when(aaiOverTLSClient.getAllSubscribers()).thenReturn(responseAllSubscribers); - - HttpResponse actualResponse = aaiService.getFullSubscriberList(); - - assertThat(actualResponse).isEqualTo(responseAllSubscribers); + when(aaiClient.getAllSubscribers()).thenReturn(responseAllSubscribers); + assertThat(aaiService.getFullSubscriberList()).isEqualTo(responseAllSubscribers); } @Test @@ -156,10 +150,10 @@ public class AaiServiceImplTest { Subscriber subscriber = createSubscriber(); SubscriberList subscriberList = new SubscriberList(Collections.singletonList(subscriber)); - when(aaiOverTLSClient.getAllSubscribers()).thenReturn(responseAllSubscribers); - when(responseAllSubscribers.getBody()).thenReturn(subscriberList); - when(responseAllSubscribers.getStatusText()).thenReturn(STATUS_TEXT); - when(responseAllSubscribers.getStatus()).thenReturn(HttpStatus.SC_OK); + when(aaiClient.getAllSubscribers()).thenReturn(responseAllSubscribers); + when(responseAllSubscribers.getT()).thenReturn(subscriberList); + when(responseAllSubscribers.getErrorMessage()).thenReturn(STATUS_TEXT); + when(responseAllSubscribers.getHttpCode()).thenReturn(HttpStatus.SC_OK); SubscriberFilteredResults expectedSubscribers = new SubscriberFilteredResults(roleValidator, subscriberList, STATUS_TEXT, HttpStatus.SC_OK); -- cgit 1.2.3-korg From 4e965d4d4f40e17841e329d0cff938b029aed89a Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Tue, 6 Aug 2019 19:23:29 +0300 Subject: add endpoints for getVpnList and getActiveNetworkList Issue-ID: VID-378 Signed-off-by: Eylon Malin Change-Id: Iede126556df337b1ab70dd76c9452f4b51e11376 --- .../org/onap/vid/controller/AaiController2.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'vid-app-common') diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java index 19187e0fc..d7d2f85db 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java @@ -20,10 +20,14 @@ package org.onap.vid.controller; +import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.onap.vid.aai.AaiClientInterface; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; import org.onap.vid.aai.model.Permissions; +import org.onap.vid.model.aaiTree.Network; import org.onap.vid.model.aaiTree.RelatedVnf; +import org.onap.vid.model.aaiTree.VpnBinding; import org.onap.vid.roles.RoleProvider; import org.onap.vid.services.AaiService; import org.springframework.beans.factory.annotation.Autowired; @@ -94,5 +98,22 @@ public class AaiController2 extends VidRestrictedBaseController { return aaiService.searchGroupMembers(globalCustomerId, serviceType, invariantId, groupType, groupRole); } + @RequestMapping(value = "/aai_get_vpn_list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public List getVpnList() { + return aaiService.getVpnListByVpnType("SERVICE-INFRASTRUCTURE"); + } + @RequestMapping(value = "/aai_get_active_networks", + method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public List getActiveNetworkList( + @RequestParam("cloudRegion") String cloudRegion, + @RequestParam("tenantId") String tenantId, + @RequestParam(value = "networkRole", required = false) String networkRole) { + return aaiService.getL3NetworksByCloudRegion(cloudRegion, tenantId, networkRole) + .stream() + .filter(Network::isBoundToVpn) + .filter(network -> StringUtils.isNotEmpty(network.getInstanceName())) + .filter(network -> StringUtils.equalsIgnoreCase(network.getOrchStatus(), "active")) + .collect(Collectors.toList()); + } } -- cgit 1.2.3-korg