From 47d3bea99e44211533e9e014164cc7e245f5e5bd Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 7 Aug 2018 11:50:06 -0400 Subject: E2EServiceInstances to be free of catalogdb Fixing Junits Making MSO requests free from direct repository calls Add @Param annotation so as to fix JPA methods with query parameters Fix createE2EServiceInstance Test Add Unit Tests for Sunny day scenarios revert import auto-alignment Issue-ID: SO-811 Change-Id: I9f69d817622b0807642a783311d6959817a77970 Signed-off-by: Benjamin, Max (mb388a) --- .../onap/so/db/catalog/client/CatalogDbClient.java | 103 ++++++++++++++------- .../data/repository/ServiceRecipeRepository.java | 3 +- .../catalog/data/repository/ServiceRepository.java | 8 +- 3 files changed, 77 insertions(+), 37 deletions(-) (limited to 'mso-catalog-db/src/main/java/org') diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index d3a1c5d8d6..edfaba0fb2 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -20,14 +20,6 @@ package org.onap.so.db.catalog.client; -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.ws.rs.core.UriBuilder; - import org.onap.so.db.catalog.beans.BuildingBlockDetail; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; @@ -40,6 +32,7 @@ import org.onap.so.db.catalog.beans.ResourceType; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; +import org.onap.so.db.catalog.beans.ServiceRecipe; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus; @@ -54,38 +47,58 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; - import uk.co.blackpepper.bowman.Client; import uk.co.blackpepper.bowman.ClientFactory; import uk.co.blackpepper.bowman.Configuration; import uk.co.blackpepper.bowman.RestTemplateConfigurer; +import javax.annotation.PostConstruct; +import javax.ws.rs.core.UriBuilder; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + @Component("CatalogDbClient") public class CatalogDbClient { - protected Client serviceClient; + private static final String SERVICE_RECIPE_SEARCH = "/serviceRecipe/search"; + private static final String SERVICE_MODEL_UUID = "SERVICE_MODEL_UUID"; + private static final String ACTION = "ACTION"; + private static final String MODEL_NAME = "MODEL_NAME"; + private static final String SERVICE_SEARCH = "/service/search"; + private static final String MODEL_VERSION = "MODEL_VERSION"; + private static final String MODEL_INVARIANT_UUID = "MODEL_INVARIANT_UUID"; + private String findFirstByModelNameURI = "/findFirstByModelNameOrderByModelVersionDesc"; + private String findFirstByServiceModelUUIDAndActionURI = "/findFirstByServiceModelUUIDAndAction"; + private String findByModelVersionAndModelInvariantUUIDURI = "/findByModelVersionAndModelInvariantUUID"; + + private Client serviceClient; - protected Client vfModuleCustomizationClient; + private Client vfModuleCustomizationClient; - protected Client orchestrationClient; + private Client orchestrationClient; - protected Client northBoundRequestClient; + private Client northBoundRequestClient; - protected Client rainyDayHandlerStatusClient; + private Client rainyDayHandlerStatusClient; - protected Client buildingBlockDetailClient; + private Client buildingBlockDetailClient; - protected Client orchestrationStatusStateTransitionDirectiveClient; + private Client orchestrationStatusStateTransitionDirectiveClient; - protected Client vnfcInstanceGroupCustomizationClient; + private Client vnfcInstanceGroupCustomizationClient; - protected Client collectionResourceInstanceGroupCustomizationClient; + private Client collectionResourceInstanceGroupCustomizationClient; - protected Client instanceGroupClient; + private Client instanceGroupClient; - protected Client networkCollectionResourceCustomizationClient; + private Client networkCollectionResourceCustomizationClient; - protected Client collectionNetworkResourceCustomizationClient; + private Client collectionNetworkResourceCustomizationClient; + + private Client serviceRecipeClient; @Value("${mso.catalog.db.spring.endpoint}") protected String endpoint; @@ -93,6 +106,13 @@ public class CatalogDbClient { @Value("${mso.db.auth}") private String msoAdaptersAuth; + @PostConstruct + public void init(){ + findFirstByModelNameURI = endpoint + SERVICE_SEARCH + findFirstByModelNameURI; + findByModelVersionAndModelInvariantUUIDURI = endpoint + SERVICE_SEARCH + findByModelVersionAndModelInvariantUUIDURI; + findFirstByServiceModelUUIDAndActionURI = endpoint + SERVICE_RECIPE_SEARCH + findFirstByServiceModelUUIDAndActionURI; + } + public CatalogDbClient() { ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()); @@ -126,6 +146,7 @@ public class CatalogDbClient { instanceGroupClient = clientFactory.create(InstanceGroup.class); networkCollectionResourceCustomizationClient = clientFactory.create(NetworkCollectionResourceCustomization.class); collectionNetworkResourceCustomizationClient = clientFactory.create(CollectionNetworkResourceCustomization.class); + serviceRecipeClient = clientFactory.create(ServiceRecipe.class); } public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID(String modelCustomizationUUID) { @@ -198,7 +219,7 @@ public class CatalogDbClient { return this.getMultipleOrchestrationFlows(UriBuilder.fromUri(endpoint + "/orchestrationFlow/").build()); } - protected List getMultipleOrchestrationFlows(URI uri) { + private List getMultipleOrchestrationFlows(URI uri) { Iterable orchIterator = orchestrationClient.getAll(uri); List orchList = new ArrayList<>(); Iterator it = orchIterator.iterator(); @@ -229,7 +250,7 @@ public class CatalogDbClient { return collectionInstanceGroupCustList; } - protected List getMultipleVnfcInstanceGroupCustomizations(URI uri) { + private List getMultipleVnfcInstanceGroupCustomizations(URI uri) { Iterable vnfcIterator = vnfcInstanceGroupCustomizationClient.getAll(uri); List vnfcList = new ArrayList<>(); Iterator it = vnfcIterator.iterator(); @@ -264,35 +285,53 @@ public class CatalogDbClient { .build()); } - protected CollectionNetworkResourceCustomization getSingleCollectionNetworkResourceCustomization(URI uri) { + public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action){ + return this.getSingleServiceRecipe(UriBuilder.fromUri(findFirstByServiceModelUUIDAndActionURI) + .queryParam(SERVICE_MODEL_UUID,modelUUID) + .queryParam(ACTION,action) + .build()); + } + + public Service getFirstByModelNameOrderByModelVersionDesc(String modelName){ + return this.getSingleService(UriBuilder.fromUri(findFirstByModelNameURI) + .queryParam(MODEL_NAME,modelName) + .build()); + } + + + private CollectionNetworkResourceCustomization getSingleCollectionNetworkResourceCustomization(URI uri) { return collectionNetworkResourceCustomizationClient.get(uri); } - protected InstanceGroup getSingleInstanceGroup(URI uri) { + private InstanceGroup getSingleInstanceGroup(URI uri) { return instanceGroupClient.get(uri); } - protected Service getSingleService(URI uri) { + private Service getSingleService(URI uri) { return serviceClient.get(uri); } - protected VfModuleCustomization getSingleVfModuleCustomization(URI uri) { + private VfModuleCustomization getSingleVfModuleCustomization(URI uri) { return vfModuleCustomizationClient.get(uri); } - protected NorthBoundRequest getSingleNorthBoundRequest(URI uri) { + private NorthBoundRequest getSingleNorthBoundRequest(URI uri) { return northBoundRequestClient.get(uri); } - protected RainyDayHandlerStatus getSingleRainyDayHandlerStatus(URI uri) { + private RainyDayHandlerStatus getSingleRainyDayHandlerStatus(URI uri) { return rainyDayHandlerStatusClient.get(uri); } + + private ServiceRecipe getSingleServiceRecipe(URI uri){ + return serviceRecipeClient.get(uri); + } public Service getServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) { return this.getSingleService( - UriBuilder.fromUri(endpoint + "/service/search/findByModelVersionAndModelInvariantUUID") - .queryParam("MODEL_VERSION", modelVersion) - .queryParam("MODEL_INVARIANT_UUID", modelInvariantUUID).build()); + UriBuilder.fromUri(findByModelVersionAndModelInvariantUUIDURI) + .queryParam(MODEL_VERSION, modelVersion) + .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build()); } //USED FOR TEST ONLY diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java index 57578cfb07..cd46846d78 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java @@ -22,6 +22,7 @@ package org.onap.so.db.catalog.data.repository; import org.onap.so.db.catalog.beans.ServiceRecipe; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "serviceRecipe", path = "serviceRecipe") @@ -30,5 +31,5 @@ public interface ServiceRecipeRepository extends JpaRepository { * @return */ @Query(value = "SELECT * FROM service WHERE MODEL_NAME = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true) - Service findFirstByModelNameOrderByModelVersionDesc(String modelName); + Service findFirstByModelNameOrderByModelVersionDesc(@Param("MODEL_NAME") String modelName); /** * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting @@ -59,7 +59,7 @@ public interface ServiceRepository extends JpaRepository { /** * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting - * @param modelName + * @param modelUUID * @return */ @Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true) @@ -67,7 +67,7 @@ public interface ServiceRepository extends JpaRepository { /** * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting - * @param modelName + * @param modelUUID * @return */ @Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true) @@ -78,7 +78,7 @@ public interface ServiceRepository extends JpaRepository { /** * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting - * @param modelName + * @param modelInvariantUUID * @return */ @Query(value = "SELECT * FROM service WHERE MODEL_INVARIANT_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true) -- cgit 1.2.3-korg