From 1ceb7d62d1c1f53e680b5d5dbcc2cdd5e339bf28 Mon Sep 17 00:00:00 2001 From: Mukesh Paliwal Date: Mon, 16 Aug 2021 20:08:16 +0530 Subject: [PATCH] Add recipe data in catalogdb Issue-ID: SO-3741 Signed-off-by: Mukesh Paliwal Change-Id: Ie873e250111b7ab61afa2581624df8ae8c7212e0 --- .../onap/so/db/catalog/client/CatalogDbClient.java | 88 +++++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) 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 91cfb00911..ae6d51c6a2 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 @@ -70,6 +70,7 @@ 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; import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; +import org.onap.so.rest.catalog.beans.Vnf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -276,6 +277,8 @@ public class CatalogDbClient { private final Client serviceRecipeClient; + private final Client networkResourceClient; + private final Client externalServiceToInternalServiceClient; private final Client cloudSiteClient; @@ -441,7 +444,7 @@ public class CatalogDbClient { workflowClient = clientFactory.create(Workflow.class); bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class); processingFlagsClient = clientFactory.create(ProcessingFlags.class); - + networkResourceClient = clientFactory.create(NetworkResource.class); } public CatalogDbClient(String baseUri, String auth) { @@ -494,6 +497,7 @@ public class CatalogDbClient { workflowClient = clientFactory.create(Workflow.class); bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class); processingFlagsClient = clientFactory.create(ProcessingFlags.class); + networkResourceClient = clientFactory.create(NetworkResource.class); } public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID( @@ -630,7 +634,6 @@ public class CatalogDbClient { } - public BuildingBlockDetail getBuildingBlockDetail(String buildingBlockName) { BuildingBlockDetail buildingBlockDetail = getSingleResource(buildingBlockDetailClient, getUri(UriBuilder.fromUri(findOneByBuildingBlockName) @@ -722,7 +725,6 @@ public class CatalogDbClient { } - public NetworkRecipe getFirstNetworkRecipeByModelNameAndAction(String modelName, String action) { return this.getSingleResource(networkRecipeClient, UriBuilder.fromUri(findFirstByModelNameAndAction) .queryParam(MODEL_NAME, modelName).queryParam(ACTION, action).build()); @@ -1042,6 +1044,72 @@ public class CatalogDbClient { } } + public void deleteServiceRecipe(String recipeId) { + this.deleteSingleResource(serviceRecipeClient, + UriBuilder.fromUri(endpoint + SERVICE_RECIPE + URI_SEPARATOR + recipeId).build()); + } + + public void postServiceRecipe(ServiceRecipe recipe) { + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity entity = new HttpEntity<>(recipe, headers); + restTemplate.exchange( + UriComponentsBuilder.fromUriString(endpoint + "/serviceRecipe").build().encode().toString(), + HttpMethod.POST, entity, ServiceRecipe.class).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find ServiceRecipe with Id: " + recipe.getId()); + } + throw e; + } + } + + public void postVnfRecipe(VnfRecipe recipe) { + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity entity = new HttpEntity<>(recipe, headers); + restTemplate + .exchange(UriComponentsBuilder.fromUriString(endpoint + "/vnfRecipe").build().encode().toString(), + HttpMethod.POST, entity, VnfRecipe.class) + .getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find VnfRecipe with Id: " + recipe.getId()); + } + throw e; + } + } + + public void postNetworkRecipe(NetworkRecipe recipe) { + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity entity = new HttpEntity<>(recipe, headers); + restTemplate.exchange( + UriComponentsBuilder.fromUriString(endpoint + "/networkRecipe").build().encode().toString(), + HttpMethod.POST, entity, NetworkRecipe.class).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find NetworkRecipe with Id: " + recipe.getId()); + } + throw e; + } + } + + public List getServiceRecipes() { + return this.getMultipleResources(serviceRecipeClient, + UriBuilder.fromUri(endpoint + SERVICE_RECIPE).queryParam("size", "1000").build()); + } + + public List getNetworkRecipes() { + return this.getMultipleResources(networkRecipeClient, + UriBuilder.fromUri(endpoint + NETWORK_RECIPE).queryParam("size", "1000").build()); + } + + public List getNetworkResources() { + return this.getMultipleResources(networkResourceClient, + UriBuilder.fromUri(endpoint + "/networkResource").queryParam("size", "1000").build()); + } + public List getServices() { try { HttpEntity entity = getHttpEntity(); @@ -1058,6 +1126,20 @@ public class CatalogDbClient { } } + public List getVnfResources() { + return this.getMultipleResources(vnfResourceClient, + UriBuilder.fromUri(endpoint + "/vnfResource").queryParam("size", "1000").build()); + } + + public List getVnfRecipes() { + return this.getMultipleResources(vnfRecipeClient, + UriBuilder.fromUri(endpoint + VNF_RECIPE).queryParam("size", "1000").build()); + } + + private void deleteSingleResource(Client client, URI uri) { + client.delete(uri); + } + public org.onap.so.rest.catalog.beans.Vnf getVnfModelInformation(String serviceModelUUID, String vnfCustomizationUUID, String depth) { if (Strings.isNullOrEmpty(serviceModelUUID)) { -- 2.16.6