diff options
Diffstat (limited to 'mso-api-handlers')
54 files changed, 569 insertions, 471 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/.gitignore b/mso-api-handlers/mso-api-handler-common/.gitignore new file mode 100644 index 0000000000..da7560e07f --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/.gitignore @@ -0,0 +1 @@ +/.apt_generated_tests/ diff --git a/mso-api-handlers/mso-api-handler-common/pom.xml b/mso-api-handlers/mso-api-handler-common/pom.xml index 865de7998f..4e92775d02 100644 --- a/mso-api-handlers/mso-api-handler-common/pom.xml +++ b/mso-api-handlers/mso-api-handler-common/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.onap.so</groupId> <artifactId>mso-api-handlers</artifactId> - <version>1.6.0-SNAPSHOT</version> + <version>1.7.1-SNAPSHOT</version> </parent> @@ -23,7 +23,6 @@ <reflections-version>0.9.9-RC1</reflections-version> <paranamer-version>2.5.2</paranamer-version> <scannotation-version>1.0.3</scannotation-version> - <java.version>1.8</java.version> </properties> <dependencyManagement> <dependencies> diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java index af1258e963..65e8b438ad 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/ResponseHandler.java @@ -32,6 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -43,6 +44,7 @@ public class ResponseHandler { String responseBody = camundaResponse.getBody(); CamundaResponse response = null; ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); try { response = mapper.readValue(responseBody, CamundaResponse.class); } catch (IOException | NullPointerException e) { diff --git a/mso-api-handlers/mso-api-handler-infra/.gitignore b/mso-api-handlers/mso-api-handler-infra/.gitignore index ae3c172604..9920c72893 100644 --- a/mso-api-handlers/mso-api-handler-infra/.gitignore +++ b/mso-api-handlers/mso-api-handler-infra/.gitignore @@ -1 +1,2 @@ /bin/ +/.apt_generated_tests/ diff --git a/mso-api-handlers/mso-api-handler-infra/pom.xml b/mso-api-handlers/mso-api-handler-infra/pom.xml index 7d6bbc4fc4..542b8db932 100644 --- a/mso-api-handlers/mso-api-handler-infra/pom.xml +++ b/mso-api-handlers/mso-api-handler-infra/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.onap.so</groupId> <artifactId>mso-api-handlers</artifactId> - <version>1.6.0-SNAPSHOT</version> + <version>1.7.1-SNAPSHOT</version> </parent> @@ -25,7 +25,6 @@ <reflections-version>0.9.9-RC1</reflections-version> <paranamer-version>2.5.2</paranamer-version> <scannotation-version>1.0.3</scannotation-version> - <java.version>1.8</java.version> </properties> <dependencyManagement> <dependencies> @@ -53,10 +52,14 @@ <artifactId>camunda-engine</artifactId> </dependency> <dependency> + <groupId>org.javassist</groupId> + <artifactId>javassist</artifactId> + <version>3.25.0-GA</version> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> - <dependency> <groupId>io.swagger.core.v3</groupId> <artifactId>swagger-annotations</artifactId> @@ -127,6 +130,10 @@ <version>${json4s-core-version}</version> </dependency> <dependency> + <groupId>javax.xml.ws</groupId> + <artifactId>jaxws-api</artifactId> + </dependency> + <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> @@ -151,7 +158,6 @@ <artifactId>mso-catalog-db</artifactId> <version>${project.version}</version> </dependency> - <!-- Test Dependencies --> <dependency> <groupId>pl.pragmatists</groupId> @@ -232,19 +238,38 @@ <dependency> <groupId>org.onap.aaf.authz</groupId> <artifactId>aaf-cadi-aaf</artifactId> - <version>2.1.9</version> + <version>${aaf.cadi.version}</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> </exclusions> </dependency> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>2.3.0</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-core</artifactId> + <version>2.3.0</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>2.3.0</version> + </dependency> </dependencies> <build> <finalName>${project.artifactId}-${project.version}</finalName> - <pluginManagement> + <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> @@ -311,6 +336,9 @@ <executions> <execution> <id>extract-docker-file</id> + <configuration> + <skip>false</skip> + </configuration> </execution> </executions> </plugin> @@ -320,9 +348,7 @@ <executions> <execution> <id>original</id> - <configuration> - <skip>false</skip> - </configuration> + <phase>package</phase> </execution> </executions> </plugin> diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java index f39a95e92c..b59f298022 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java @@ -9,6 +9,8 @@ * ================================================================================ * Modifications Copyright (c) 2020 Nokia * ================================================================================ + * Modifications Copyright (c) 2020 Nordix + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,7 +27,28 @@ package org.onap.so.apihandlerinfra; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import javax.transaction.Transactional; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; +import org.onap.logging.filter.base.ErrorCode; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandler.common.RequestClientParameter; import org.onap.so.apihandlerinfra.exceptions.ApiException; @@ -39,35 +62,13 @@ import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; -import org.onap.logging.filter.base.ErrorCode; import org.onap.so.logger.MessageEnum; import org.onap.so.serviceinstancebeans.ModelType; -import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; -import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.transaction.Transactional; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.util.HashMap; -import io.swagger.v3.oas.annotations.OpenAPIDefinition; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.info.Info; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; @Component @Path("/onap/so/infra/instanceManagement") @@ -75,8 +76,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; description = "Infrastructure API Requests for Instance Management")) public class InstanceManagement { - private static Logger logger = LoggerFactory.getLogger(InstanceManagement.class); - private static String uriPrefix = "/instanceManagement/"; + private static final Logger LOG = LoggerFactory.getLogger(InstanceManagement.class); + private static final String URI_PREFIX = "/instanceManagement/"; private static final String SAVE_TO_DB = "save instance to db"; @Autowired @@ -102,13 +103,13 @@ public class InstanceManagement { @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId, @PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext) throws ApiException { - String requestId = requestHandlerUtils.getRequestId(requestContext); - HashMap<String, String> instanceIdMap = new HashMap<>(); + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map<String, String> instanceIdMap = new HashMap<>(); instanceIdMap.put("serviceInstanceId", serviceInstanceId); instanceIdMap.put("vnfInstanceId", vnfInstanceId); instanceIdMap.put("workflowUuid", workflowUuid); return processCustomWorkflowRequest(request, Action.inPlaceSoftwareUpdate, instanceIdMap, version, requestId, - requestContext); + requestContext, true); } @POST @@ -122,34 +123,61 @@ public class InstanceManagement { @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("pnfName") String pnfName, @PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext) throws ApiException { - String requestId = requestHandlerUtils.getRequestId(requestContext); - HashMap<String, String> instanceIdMap = new HashMap<>(); + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map<String, String> instanceIdMap = new HashMap<>(); instanceIdMap.put("serviceInstanceId", serviceInstanceId); instanceIdMap.put("pnfName", pnfName); instanceIdMap.put("workflowUuid", workflowUuid); - return processPNFCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId, - requestContext); + return processCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId, + requestContext, false); + } + + @POST + @Path("/{version:[vV][1]}/serviceInstances/{serviceInstanceId}/workflows/{workflowUuid}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Execute custom Service Level workflow", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Transactional + public Response executeServiceLevelCustomWorkflow(String request, @PathParam("version") String version, + @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("workflowUuid") String workflowUuid, + @Context ContainerRequestContext requestContext) throws ApiException { + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map<String, String> instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", serviceInstanceId); + instanceIdMap.put("workflowUuid", workflowUuid); + return processCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId, + requestContext, false); } - private Response processCustomWorkflowRequest(String requestJSON, Actions action, - HashMap<String, String> instanceIdMap, String version, String requestId, - ContainerRequestContext requestContext) throws ApiException { - String serviceInstanceId; - boolean aLaCarte = true; - ServiceInstancesRequest sir; - String apiVersion = version.substring(1); + private Response processCustomWorkflowRequest(final String requestJSON, final Actions action, + final Map<String, String> instanceIdMap, final String version, final String requestId, + final ContainerRequestContext requestContext, final boolean aLaCarte) throws ApiException { + String pnfName = null; + String vnfType = null; + String workflowUuid = null; + String vnfInstanceId = null; + String svcInstanceId = null; + final String apiVersion = version.substring(1); - String requestUri = requestHandlerUtils.getRequestUri(requestContext, uriPrefix); + if (instanceIdMap != null && !instanceIdMap.isEmpty()) { + pnfName = instanceIdMap.get("pnfName"); + workflowUuid = instanceIdMap.get("workflowUuid"); + vnfInstanceId = instanceIdMap.get("vnfInstanceId"); + svcInstanceId = instanceIdMap.get("serviceInstanceId"); + } - sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); - String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri); - InfraActiveRequests currentActiveReq = - msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope); + final String requestUri = requestHandlerUtils.getRequestUri(requestContext, URI_PREFIX); + final ServiceInstancesRequest svcInsReq = + requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); + final String requestScope = requestHandlerUtils.deriveRequestScope(action, svcInsReq, requestUri); + InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(svcInsReq, action, requestId, + Status.IN_PROGRESS, requestJSON, requestScope); try { requestHandlerUtils.validateHeaders(requestContext); } catch (ValidationException e) { - logger.error("Exception occurred", e); + LOG.error("Exception occurred", e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); @@ -160,42 +188,18 @@ public class InstanceManagement { throw validateException; } - requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, + requestHandlerUtils.parseRequest(svcInsReq, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq); requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); - String vnfType = msoRequest.getVnfType(sir, requestScope); - - if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) { + if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) { + vnfType = msoRequest.getVnfType(svcInsReq, requestScope); currentActiveReq.setVnfType(vnfType); } checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq); - - ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse(); - - RequestReferences referencesResponse = new RequestReferences(); - - referencesResponse.setRequestId(requestId); - - serviceResponse.setRequestReferences(referencesResponse); - boolean isBaseVfModule = false; - - String workflowUuid = null; - if (instanceIdMap != null) { - workflowUuid = instanceIdMap.get("workflowUuid"); - } - - RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); - - String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, true); - - serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir); - String vnfId = ""; - - if (sir.getVnfInstanceId() != null) { - vnfId = sir.getVnfInstanceId(); - } + final RecipeLookupResult recipeLookupResult = + getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); currentActiveReq = setWorkflowNameAndOperationName(currentActiveReq, workflowUuid); saveCurrentActiveRequest(currentActiveReq); @@ -203,11 +207,11 @@ public class InstanceManagement { RequestClientParameter requestClientParameter; try { requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) - .setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) - .setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setVnfId(vnfId) - .setServiceType(serviceInstanceType).setVnfType(vnfType) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()) + .setServiceInstanceId(svcInstanceId).setVnfId(vnfInstanceId).setVnfType(vnfType) + .setPnfCorrelationId(pnfName).setApiVersion(apiVersion) .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action)) - .setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).build(); + .setALaCarte(aLaCarte).setRequestUri(requestUri).build(); } catch (IOException e) { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) @@ -232,7 +236,7 @@ public class InstanceManagement { } } - private void checkDuplicateAndBuildError(Actions action, HashMap<String, String> instanceIdMap, String requestScope, + private void checkDuplicateAndBuildError(Actions action, Map<String, String> instanceIdMap, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = @@ -248,74 +252,6 @@ public class InstanceManagement { } } - private Response processPNFCustomWorkflowRequest(String requestJSON, Actions action, - HashMap<String, String> instanceIdMap, String version, String requestId, - ContainerRequestContext requestContext) throws ApiException { - boolean aLaCarte = false; - ServiceInstancesRequest sir; - String apiVersion = version.substring(1); - - String serviceInstanceId = ""; - String pnfName = ""; - String workflowUuid = ""; - if (instanceIdMap != null) { - serviceInstanceId = instanceIdMap.get("serviceInstanceId"); - pnfName = instanceIdMap.get("pnfName"); - workflowUuid = instanceIdMap.get("workflowUuid"); - } - - String requestUri = requestHandlerUtils.getRequestUri(requestContext, uriPrefix); - sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); - sir.setServiceInstanceId(serviceInstanceId); - sir.setPnfName(pnfName); - String requestScope = ModelType.pnf.name(); - InfraActiveRequests currentActiveReq = - msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope); - - try { - requestHandlerUtils.validateHeaders(requestContext); - } catch (ValidationException e) { - logger.error("Exception occurred", e); - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = - new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, - ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); - requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage()); - throw validateException; - } - - requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, - currentActiveReq); - requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); - - checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq); - - RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); - - currentActiveReq = setWorkflowNameAndOperationName(currentActiveReq, workflowUuid); - saveCurrentActiveRequest(currentActiveReq); - - RequestClientParameter requestClientParameter; - try { - requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) - .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()) - .setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfName) - .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action)) - .setApiVersion(apiVersion).setRequestUri(requestUri).build(); - } catch (IOException e) { - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), - HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) - .build(); - } - return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, - recipeLookupResult.getOrchestrationURI(), requestScope); - } - private RecipeLookupResult getInstanceManagementWorkflowRecipe(InfraActiveRequests currentActiveReq, String workflowUuid) throws ApiException { RecipeLookupResult recipeLookupResult; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index f3c3ec5ff1..4ac8b73698 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -154,9 +154,8 @@ public class MsoRequest { // Parse request JSON - public void parse(ServiceInstancesRequest sir, HashMap<String, String> instanceIdMap, Actions action, - String version, String originalRequestJSON, int reqVersion, Boolean aLaCarteFlag) - throws ValidationException, IOException { + public void parse(ServiceInstancesRequest sir, Map<String, String> instanceIdMap, Actions action, String version, + String originalRequestJSON, int reqVersion, Boolean aLaCarteFlag) throws ValidationException, IOException { logger.debug("Validating the Service Instance request"); List<ValidationRule> rules = new ArrayList<>(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index a61975f529..a68309f199 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -261,8 +261,8 @@ public class RequestHandlerUtils extends AbstractRestHandler { } } - public InfraActiveRequests duplicateCheck(Actions action, HashMap<String, String> instanceIdMap, - String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { + public InfraActiveRequests duplicateCheck(Actions action, Map<String, String> instanceIdMap, String instanceName, + String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = null; try { if (!(instanceName == null && "service".equals(requestScope) && (action == Action.createInstance @@ -332,7 +332,7 @@ public class RequestHandlerUtils extends AbstractRestHandler { } } - public void parseRequest(ServiceInstancesRequest sir, HashMap<String, String> instanceIdMap, Actions action, + public void parseRequest(ServiceInstancesRequest sir, Map<String, String> instanceIdMap, Actions action, String version, String requestJSON, Boolean aLaCarte, String requestId, InfraActiveRequests currentActiveReq) throws ValidateException, RequestDbFailureException { int reqVersion = Integer.parseInt(version.substring(1)); @@ -354,7 +354,7 @@ public class RequestHandlerUtils extends AbstractRestHandler { } public void buildErrorOnDuplicateRecord(InfraActiveRequests currentActiveReq, Actions action, - HashMap<String, String> instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup) + Map<String, String> instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup) throws ApiException { String instance = null; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java index 357497591d..0f7cf5fc6a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java @@ -81,12 +81,13 @@ public class WorkflowSpecificationsHandler { @Transactional public Response queryWorkflowSpecifications(@QueryParam("vnfModelVersionId") String vnfModelVersionId, - @QueryParam("pnfModelVersionId") String pnfModelVersionId, @PathParam("version") String version) + @QueryParam("pnfModelVersionId") String pnfModelVersionId, + @QueryParam("resourceTarget") String resourceTarget, @PathParam("version") String version) throws Exception { String apiVersion = version.substring(1); List<Workflow> workflows = new ArrayList<>(); - if (vnfModelVersionId == null && pnfModelVersionId == null) { + if (vnfModelVersionId == null && pnfModelVersionId == null && resourceTarget == null) { workflows.addAll(queryWorkflowSpecificationsForAll()); } else { // 1. query workflow specifications for given vnfModelVersionId if need. @@ -106,6 +107,16 @@ public class WorkflowSpecificationsHandler { workflows.addAll(pnfWorkflows); } } + + // 3. query workflow specifications for given resourceTarget + if (resourceTarget != null) { + List<Workflow> workflowsForResourceTarget = queryWorkflowsForResourceTarget(resourceTarget); + logger.debug( + "Retrieved " + workflowsForResourceTarget.size() + " workflows for given resource target."); + if (workflowsForResourceTarget.size() > 0) { + workflows.addAll(workflowsForResourceTarget); + } + } } // Deduplication @@ -119,11 +130,16 @@ public class WorkflowSpecificationsHandler { apiVersion); } + /** + * @deprecated As of G release, workflows for all resource types (pnf,vnf,service) can be fetched using + * /workflowSpecifications/{version:[vV]1}/workflows?resourceTarget={resourceType} API + */ @Path("/{version:[vV]1}/pnfWorkflows") @GET @Operation(description = "Finds pnf workflow specifications", responses = @ApiResponse( content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) @Transactional + @Deprecated public Response getWorkflowsSpecForPnf(@PathParam("version") String version) throws Exception { final String pnf_resource = "pnf"; @@ -132,7 +148,7 @@ public class WorkflowSpecificationsHandler { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - List<Workflow> workflows = catalogDbClient.findWorkflowByResourceTarget(pnf_resource); + List<Workflow> workflows = queryWorkflowsForResourceTarget(pnf_resource); Optional<String> optional = getResponseByWorkflowSpec(workflows); return builder.buildResponse(HttpStatus.SC_OK, "", optional.isPresent() ? optional.get() : EMPTY_BODY, @@ -296,4 +312,11 @@ public class WorkflowSpecificationsHandler { List<Workflow> workflows = catalogDbClient.findWorkflowByPnfModelUUID(pnfModelVersionId); return workflows; } + + private List<Workflow> queryWorkflowsForResourceTarget(String resourceTarget) { + List<Workflow> workflows = catalogDbClient.findWorkflowByResourceTarget(resourceTarget); + return workflows; + } + + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java index fc0048bacf..70de94a3ef 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java @@ -148,7 +148,7 @@ public class AAIDataRetrieval { } public List<LInterface> getLinterfacesOfVnf(String vnfId) { - DSLStartNode startNode = new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("generic-vnf-id", vnfId)); + DSLStartNode startNode = new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", vnfId)); DSLQueryBuilder<Start, Node> builder = TraversalBuilder.fragment(startNode) .to(__.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.L_INTERFACE).output())); List<LInterface> linterfaces = diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java index e8046a2cd9..6e7947bb58 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java @@ -38,6 +38,7 @@ import org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFou import org.onap.so.constants.Status; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; @@ -436,7 +437,7 @@ public class BpmnRequestBuilder { RequestInfo requestInfo = new RequestInfo(); requestInfo.setSuppressRollback(false); requestInfo.setSource(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); - requestInfo.setRequestorId(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + requestInfo.setRequestorId(MDC.get(HttpHeadersConstants.REQUESTOR_ID)); return requestInfo; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Network.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Network.java index 3104c8415f..81ad3106b0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Network.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Network.java @@ -32,7 +32,6 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.fasterxml.jackson.core.JsonProcessingException; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandler.filters.ResponseUpdater; import org.onap.so.apihandlerinfra.Action; @@ -43,12 +42,14 @@ import org.onap.so.apihandlerinfra.infra.rest.exception.WorkflowEngineConnection import org.onap.so.apihandlerinfra.infra.rest.handler.NetworkRestHandler; import org.onap.so.db.catalog.beans.Recipe; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -80,7 +81,7 @@ public class Network { ValidateException { String requestId = networkRestHandler.getRequestId(requestContext); - String requestorId = "Unknown"; + String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID); String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME); String requestURI = requestContext.getUriInfo().getAbsolutePath().toString(); InfraActiveRequests currentRequest = networkRestHandler.createInfraActiveRequestForDelete(requestId, diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/ServiceInstance.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/ServiceInstance.java index 7aaf470e18..515862e249 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/ServiceInstance.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/ServiceInstance.java @@ -32,7 +32,6 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.fasterxml.jackson.core.JsonProcessingException; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandler.filters.ResponseUpdater; import org.onap.so.apihandlerinfra.Action; @@ -43,12 +42,14 @@ import org.onap.so.apihandlerinfra.infra.rest.exception.WorkflowEngineConnection import org.onap.so.apihandlerinfra.infra.rest.handler.ServiceInstanceRestHandler; import org.onap.so.db.catalog.beans.Recipe; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -79,7 +80,7 @@ public class ServiceInstance { ValidateException { String requestId = requestHandler.getRequestId(requestContext); - String requestorId = "Unknown"; + String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID); String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME); String requestURI = requestContext.getUriInfo().getAbsolutePath().toString(); InfraActiveRequests currentRequest = requestHandler.createInfraActiveRequestForDelete(requestId, diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/VfModules.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/VfModules.java index ddbced98a4..81879c4281 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/VfModules.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/VfModules.java @@ -32,7 +32,6 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.fasterxml.jackson.core.JsonProcessingException; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandler.filters.ResponseUpdater; import org.onap.so.apihandlerinfra.Action; @@ -43,6 +42,7 @@ import org.onap.so.apihandlerinfra.infra.rest.exception.WorkflowEngineConnection import org.onap.so.apihandlerinfra.infra.rest.handler.VFModuleRestHandler; import org.onap.so.db.catalog.beans.Recipe; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; @@ -50,6 +50,7 @@ import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -81,7 +82,7 @@ public class VfModules { ValidateException { String requestId = restHandler.getRequestId(requestContext); - String requestorId = "Unknown"; + String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID); String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME); String requestURL = requestContext.getUriInfo().getAbsolutePath().toString(); InfraActiveRequests currentRequest = restHandler.createInfraActiveRequestForDelete(requestId, diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Vnf.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Vnf.java index 68e6eb5858..f1331a3185 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Vnf.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Vnf.java @@ -32,7 +32,6 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.fasterxml.jackson.core.JsonProcessingException; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandler.filters.ResponseUpdater; import org.onap.so.apihandlerinfra.exceptions.ValidateException; @@ -41,12 +40,14 @@ import org.onap.so.apihandlerinfra.infra.rest.exception.WorkflowEngineConnection import org.onap.so.apihandlerinfra.infra.rest.handler.VnfRestHandler; import org.onap.so.db.catalog.beans.Recipe; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -77,7 +78,7 @@ public class Vnf { throws AAIEntityNotFound, JsonProcessingException, WorkflowEngineConnectionException, ValidateException { String requestId = vnfRestHandler.getRequestId(requestContext); - String requestorId = "Unknown"; + String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID); String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME); String requestURL = requestContext.getUriInfo().getAbsolutePath().toString(); InfraActiveRequests currentRequest = vnfRestHandler.createInfraActiveRequestForDelete(requestId, diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Volumes.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Volumes.java index b842580b3f..001a8069d9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Volumes.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/Volumes.java @@ -32,7 +32,6 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.fasterxml.jackson.core.JsonProcessingException; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandler.filters.ResponseUpdater; import org.onap.so.apihandlerinfra.Action; @@ -44,6 +43,7 @@ import org.onap.so.apihandlerinfra.infra.rest.handler.VFModuleRestHandler; import org.onap.so.apihandlerinfra.infra.rest.handler.VolumeRestHandler; import org.onap.so.db.catalog.beans.Recipe; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; @@ -51,6 +51,7 @@ import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -85,7 +86,7 @@ public class Volumes { ValidateException { String requestId = volumeRestHandler.getRequestId(requestContext); - String requestorId = "Unknown"; + String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID); String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME); String requestURL = requestContext.getUriInfo().getAbsolutePath().toString(); InfraActiveRequests currentRequest = volumeRestHandler.createInfraActiveRequestForDelete(requestId, diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java index c806e9fc1b..fec512ac44 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java @@ -163,12 +163,14 @@ public abstract class AbstractRestHandler { try { URL aUrl = new URL(url); String aPath = aUrl.getPath(); - if (aPath.indexOf("/v") == -1) { - version = aPath.substring(aPath.indexOf("/V"), aPath.indexOf("/V") + 4); - } else { - version = aPath.substring(aPath.indexOf("/v"), aPath.indexOf("/v") + 4); - } - String selfLinkPath = Constants.ORCHESTRATION_REQUESTS_PATH.concat(version).concat(requestId); + int indexOfVersion = Math.max(aPath.indexOf("/V"), aPath.indexOf("/v")); + version = aPath.substring(indexOfVersion, indexOfVersion + 4); + + String pathWithSOAction = aPath.substring(0, indexOfVersion); + String pathWithoutSOAction = pathWithSOAction.substring(0, pathWithSOAction.lastIndexOf("/")); + + String selfLinkPath = + pathWithoutSOAction.concat(Constants.ORCHESTRATION_REQUESTS_PATH).concat(version).concat(requestId); selfLinkUrl = Optional.of(new URL(aUrl.getProtocol(), aUrl.getHost(), aUrl.getPort(), selfLinkPath)); } catch (Exception e) { selfLinkUrl = Optional.empty(); // ignore diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java index 89c5cbed9b..c875764b7b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java @@ -25,7 +25,7 @@ public class NetworkDeleteValidator implements RequestValidator { @Override public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, - Map<String, String> queryParams) { + Map<String, String> queryParams, Actions action) { if (aaiDataRetrieval.isNetworkRelatedToModules(instanceIdMap.get("networkInstanceId"))) { return Optional.of("Cannot delete network it is still related to existing vf-modules"); } else { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java index 50938e6826..dc6d01ea8a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java @@ -39,5 +39,5 @@ public interface RequestValidator { public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, - Map<String, String> queryParams); + Map<String, String> queryParams, Actions action); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java index 3aba39b501..7ab761aeef 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java @@ -73,8 +73,8 @@ public class RequestValidatorListenerRunner extends ListenerRunner { filterListeners(validators, (item -> item.shouldRunFor(requestURI, request, action))); List<Pair<String, Optional<String>>> results = new ArrayList<>(); - filtered.forEach(item -> results - .add(new Pair<>(item.getClass().getName(), item.validate(instanceIdMap, request, queryParams)))); + filtered.forEach(item -> results.add( + new Pair<>(item.getClass().getName(), item.validate(instanceIdMap, request, queryParams, action)))); return results.stream().filter(item -> item.getValue1().isPresent()).collect(Collectors.toList()); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java index 843d94ce6c..74dbf579c0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java @@ -34,7 +34,7 @@ public class ServiceInstanceDeleteValidator implements RequestValidator { @Override public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, - Map<String, String> queryParams) { + Map<String, String> queryParams, Actions action) { if (aaiDataRetrieval.isServiceRelatedToGenericVnf(instanceIdMap.get("serviceInstanceId"))) { return Optional.of("Cannot delete service it is still related to existing vf-modules"); } else if (aaiDataRetrieval.isServiceRelatedToNetworks(instanceIdMap.get("serviceInstanceId"))) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java index a48fca8d0f..44bab7e087 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java @@ -24,7 +24,7 @@ public class VnfDeleteValidator implements RequestValidator { @Override public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, - Map<String, String> queryParams) { + Map<String, String> queryParams, Actions action) { final Optional<String> volumeGroupIds = aaiDataRetrieval.getVolumeGroupIdsByVnfId(instanceIdMap.get("vnfInstanceId")); final Optional<String> vfModuleIds = aaiDataRetrieval.getVfModuleIdsByVnfId(instanceIdMap.get("vnfInstanceId")); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java index e3598af31d..550db19af4 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java @@ -24,7 +24,7 @@ public class VolumeGroupDeleteValidator implements RequestValidator { @Override public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, - Map<String, String> queryParams) { + Map<String, String> queryParams, Actions action) { if (aaiDataRetrieval.isVolumeGroupRelatedToVFModule(instanceIdMap.get("volumeGroupInstanceId"))) { return Optional.of("Cannot delete volume group it is related to existing vf-modules"); } else { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java index 2cf01f9390..55a68ff7df 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java @@ -21,7 +21,7 @@ package org.onap.so.apihandlerinfra.validation; -import java.util.HashMap; +import java.util.Map; import org.onap.so.apihandler.common.CommonConstants; import org.onap.so.exceptions.ValidationException; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -31,6 +31,7 @@ public class InstanceIdMapValidation implements ValidationRule { private static final String Service_InstanceId = "serviceInstanceId"; private static final String Vnf_InstanceId = "vnfInstanceId"; + private static final String PNF_NAME = "pnfName"; private static final String vfModule_InstanceId = "vfModuleInstanceId"; private static final String volume_Group_InstanceId = "volumeGroupInstanceId"; @@ -39,7 +40,7 @@ public class InstanceIdMapValidation implements ValidationRule { @Override public ValidationInformation validate(ValidationInformation info) throws ValidationException { - HashMap<String, String> instanceIdMap = info.getInstanceIdMap(); + Map<String, String> instanceIdMap = info.getInstanceIdMap(); ServiceInstancesRequest sir = info.getSir(); if (instanceIdMap != null) { if (instanceIdMap.get(Service_InstanceId) != null) { @@ -90,6 +91,10 @@ public class InstanceIdMapValidation implements ValidationRule { } sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID)); } + + if (instanceIdMap.get(PNF_NAME) != null) { + sir.setPnfName(instanceIdMap.get(PNF_NAME)); + } } return info; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java index 68b2a78a85..ee4fde02eb 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java @@ -21,7 +21,7 @@ package org.onap.so.apihandlerinfra.validation; -import java.util.HashMap; +import java.util.Map; import org.onap.so.apihandlerinfra.Actions; import org.onap.so.serviceinstancebeans.LineOfBusiness; import org.onap.so.serviceinstancebeans.OwningEntity; @@ -34,7 +34,7 @@ import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; public class ValidationInformation { ServiceInstancesRequest sir; - HashMap<String, String> instanceIdMap; + Map<String, String> instanceIdMap; Actions action; int reqVersion; String requestScope; @@ -53,7 +53,7 @@ public class ValidationInformation { OwningEntity owningEntity; Service userParams; - public ValidationInformation(ServiceInstancesRequest sir, HashMap<String, String> instanceIdMap, Actions action, + public ValidationInformation(ServiceInstancesRequest sir, Map<String, String> instanceIdMap, Actions action, int reqVersion, Boolean aLaCarteFlag, RequestParameters requestParameters) { this.sir = sir; this.instanceIdMap = instanceIdMap; @@ -71,11 +71,11 @@ public class ValidationInformation { this.sir = value; } - public HashMap<String, String> getInstanceIdMap() { + public Map<String, String> getInstanceIdMap() { return this.instanceIdMap; } - public void setInstanceIdMap(HashMap<String, String> value) { + public void setInstanceIdMap(Map<String, String> value) { this.instanceIdMap = value; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java index 5da16f4326..0ca98883c9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java @@ -70,6 +70,10 @@ public abstract class BaseTest { return "http://localhost:" + port + uri; } + protected String createURLWithPort(String uri, String orchestrationPath) { + return "http://localhost:" + port + orchestrationPath + uri; + } + protected String createURLWithPort(String uri, int iPort) { return "http://localhost:" + iPort + uri; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java index 081f235db1..7b2e502892 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java @@ -29,10 +29,12 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID; -import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID; import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_PARTNER_NAME; +import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID; import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID; +import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -46,7 +48,6 @@ import org.junit.Before; import org.junit.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -57,8 +58,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.util.ResourceUtils; import org.springframework.web.util.UriComponentsBuilder; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; public class InstanceManagementTest extends BaseTest { @@ -72,6 +71,7 @@ public class InstanceManagementTest extends BaseTest { private String wiremockPort; private final String instanceManagementUri = "/onap/so/infra/instanceManagement/"; + private final String orchestration_path = "/onap/so/infra"; private String uri; private URL selfLink; @@ -93,7 +93,7 @@ public class InstanceManagementTest extends BaseTest { headers.set(ONAP_PARTNER_NAME, "VID"); headers.set(REQUESTOR_ID, "xxxxxx"); try { // generate one-time port number to avoid RANDOM port number later. - initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH)); + initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH, orchestration_path)); initialPort = initialUrl.getPort(); } catch (MalformedURLException e) { e.printStackTrace(); @@ -208,6 +208,35 @@ public class InstanceManagementTest extends BaseTest { } @Test + public void executeServiceLevelCustomWorkflow() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/testingServiceLevelWorkflow")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlMatching( + ".*/workflow/search/findByArtifactUUID[?]artifactUUID=81526781-e55c-4cb7-adb3-97e09d9c76bf")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("workflow_ServiceLevel_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + // expected response + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v1", "32807a28-1a14-4b88-b7b3-2950918aa76d")); + expectedResponse.setRequestReferences(requestReferences); + uri = instanceManagementUri + "v1" + + "/serviceInstances/5df8b6de-2083-11e7-93ae-92361f002676/workflows/81526781-e55c-4cb7-adb3-97e09d9c76bf"; + ResponseEntity<String> response = + sendRequest(inputStream("/ExecuteServiceLevelCustomWorkflow.json"), uri, HttpMethod.POST, headers); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + + ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); + assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + } + + @Test public void workflowAndOperationNameTest() { wireMockServer.stubFor(get(urlMatching( ".*/workflow/search/findByArtifactUUID[?]artifactUUID=71526781-e55c-4cb7-adb3-97e09d9c76be")) diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java index 9b892af869..7711608288 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java @@ -133,7 +133,6 @@ public class OrchestrationRequestsTest extends BaseTest { testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); RequestProcessingData e = new RequestProcessingData(); e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - e.setTag("pincFabricConfigRequest"); List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); HashMap<String, String> data1 = new HashMap<String, String>(); data1.put("requestAction", "assign"); @@ -210,7 +209,6 @@ public class OrchestrationRequestsTest extends BaseTest { testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); RequestProcessingData e = new RequestProcessingData(); e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - e.setTag("pincFabricConfigRequest"); List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); HashMap<String, String> data1 = new HashMap<String, String>(); data1.put("requestAction", "assign"); @@ -256,7 +254,6 @@ public class OrchestrationRequestsTest extends BaseTest { testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); RequestProcessingData e = new RequestProcessingData(); e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - e.setTag("pincFabricConfigRequest"); List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); HashMap<String, String> data1 = new HashMap<String, String>(); data1.put("requestAction", "assign"); @@ -463,13 +460,11 @@ public class OrchestrationRequestsTest extends BaseTest { HashMap<String, String> secondExpectedMap = new HashMap<>(); List<RequestProcessingData> expectedDataList = new ArrayList<>(); entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - entry.setTag("pincFabricConfigRequest"); expectedMap.put("requestAction", "assign"); - expectedMap.put("pincFabricId", "testId"); + expectedMap.put("fabricId", "testId"); expectedList.add(expectedMap); entry.setDataPairs(expectedList); secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715"); - secondEntry.setTag("pincFabricConfig"); secondExpectedMap.put("requestAction", "unassign"); secondExpectedList.add(secondExpectedMap); secondEntry.setDataPairs(secondExpectedList); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index ef90b22b01..33d86a2cc6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -1,8 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +13,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -97,6 +97,8 @@ public class ServiceInstancesTest extends BaseTest { private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/"; private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/"; + private final String orchestration_path = "/onap/so/infra"; + private String uri; private URL selfLink; private URL initialUrl; @@ -115,7 +117,7 @@ public class ServiceInstancesTest extends BaseTest { headers.set(ONAP_PARTNER_NAME, "VID"); headers.set(REQUESTOR_ID, "xxxxxx"); try { // generate one-time port number to avoid RANDOM port number later. - initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH)); + initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH, orchestration_path)); initialPort = initialUrl.getPort(); } catch (MalformedURLException e) { e.printStackTrace(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java index 4ab88f40f6..1fa71cefc2 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java @@ -58,6 +58,9 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest { @Autowired WorkflowSpecificationsHandler workflowSpecificationsHandler; + @Autowired + ObjectMapper mapper; + @Value("${wiremock.server.port}") private String wiremockPort; @@ -152,7 +155,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); WorkflowSpecifications expectedResponse = mapper.readValue( @@ -306,7 +308,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest { WorkflowSpecifications workflowSpecifications = workflowSpecificationsHandler.mapWorkflowsToWorkflowSpecifications(workflows); - ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String workflowSpecificationsJson = mapper.writeValueAsString(workflowSpecifications); @@ -349,7 +350,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); WorkflowSpecifications expectedResponse = mapper.readValue( @@ -367,6 +367,52 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest { } @Test + public void queryWorkflowSpecificationsByResourceTarget_Test_Success() throws JSONException, IOException { + + String URL_PATH = basePath + "/v1/workflows"; + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + HttpEntity<String> entity = new HttpEntity<String>(null, headers); + String WORKFLOW_QUERY = "/workflow/search/findByResourceTarget[?]resourceTarget=service"; + String WORKFLOW_SPEC_QUERY = "/workflow/5/workflowActivitySpecSequence"; + String JSON_FILE_PATH = "src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json"; + String MOCK_RESP_FILE = "WorkflowSpecificationsForServiceWorkflows_Response.json"; + String MOCK_RESP_SPEC_FILE = "Empty_workflowActivitySpecSequence_Response.json"; + + wireMockServer.stubFor(get(urlMatching(WORKFLOW_QUERY)) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_FILE)) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlMatching(WORKFLOW_SPEC_QUERY)) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_SPEC_FILE)) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + UriComponentsBuilder builder = + UriComponentsBuilder.fromHttpUrl(createURLWithPort(URL_PATH)).queryParam("resourceTarget", "service"); + + ResponseEntity<String> response = + restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + WorkflowSpecifications expectedResponse = mapper + .readValue(new String(Files.readAllBytes(Paths.get(JSON_FILE_PATH))), WorkflowSpecifications.class); + WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(expectedResponse, sameBeanAs(realResponse)); + assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); + assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); + assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); + assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0)); + } + + @Test public void testWorkflowSpecificationsForPnf_Success() throws JSONException, IOException { final String urlPath = basePath + "/v1/pnfWorkflows"; @@ -397,7 +443,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); WorkflowSpecifications expectedResponse = mapper.readValue( diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java index d39192cdf0..6c643c77d7 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java @@ -61,4 +61,15 @@ public class AbstractRestHandlerTest { restHandler.createResponse("instanceId", "requestId", mockRequestContext); assertThat(actualResponse, sameBeanAs(expectedResponse)); } + + @Test + public void test_buildSelfLinkUrl() throws MalformedURLException { + String initialLink = "http://some.domain.com:30277/onap/so/infra/serviceInstantiation/v7/serviceInstances"; + String requestId = "4d0437c3-ee48-4361-a4f7-e1613c82493a"; + Optional<URL> expectedLink = Optional.of(new URL( + "http://some.domain.com:30277/onap/so/infra/orchestrationRequests/v7/4d0437c3-ee48-4361-a4f7-e1613c82493a")); + Optional<URL> resultURL = restHandler.buildSelfLinkUrl(initialLink, requestId); + + assertThat(resultURL, sameBeanAs(expectedLink)); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java index 7780f0ee2b..20ec6d6708 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java @@ -58,7 +58,7 @@ public class NetworkDeleteValidatorTest { public void validateSuccessTest() { instanceIdMap.put("networkInstanceId", "1"); when(aaiDataRetrieval.isNetworkRelatedToModules("1")).thenReturn(false); - Optional<String> result = networkValidator.validate(instanceIdMap, null, null); + Optional<String> result = networkValidator.validate(instanceIdMap, null, null, null); assertEquals(false, result.isPresent()); } @@ -66,7 +66,7 @@ public class NetworkDeleteValidatorTest { public void validateFailureTest() { instanceIdMap.put("networkInstanceId", "1"); when(aaiDataRetrieval.isNetworkRelatedToModules("1")).thenReturn(true); - Optional<String> result = networkValidator.validate(instanceIdMap, null, null); + Optional<String> result = networkValidator.validate(instanceIdMap, null, null, null); assertEquals(true, result.isPresent()); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java index f461df3720..c082c96074 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java @@ -76,7 +76,7 @@ public class ServiceInstanceDeleteValidatorTest { when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(false); when(aaiDataRetrieval.isServiceRelatedToNetworks("1")).thenReturn(false); when(aaiDataRetrieval.isServiceRelatedToConfiguration("1")).thenReturn(false); - Optional<String> result = serviceValidator.validate(instanceIdMap, null, null); + Optional<String> result = serviceValidator.validate(instanceIdMap, null, null, null); assertEquals(false, result.isPresent()); } @@ -84,7 +84,7 @@ public class ServiceInstanceDeleteValidatorTest { public void validateFailureVnfTest() { instanceIdMap.put("serviceInstanceId", "1"); when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(true); - Optional<String> result = serviceValidator.validate(instanceIdMap, null, null); + Optional<String> result = serviceValidator.validate(instanceIdMap, null, null, null); assertEquals(true, result.isPresent()); } @@ -93,7 +93,7 @@ public class ServiceInstanceDeleteValidatorTest { instanceIdMap.put("serviceInstanceId", "1"); when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(false); when(aaiDataRetrieval.isServiceRelatedToNetworks("1")).thenReturn(true); - Optional<String> result = serviceValidator.validate(instanceIdMap, null, null); + Optional<String> result = serviceValidator.validate(instanceIdMap, null, null, null); assertEquals(true, result.isPresent()); } @@ -103,7 +103,7 @@ public class ServiceInstanceDeleteValidatorTest { when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(false); when(aaiDataRetrieval.isServiceRelatedToNetworks("1")).thenReturn(false); when(aaiDataRetrieval.isServiceRelatedToConfiguration("1")).thenReturn(true); - Optional<String> result = serviceValidator.validate(instanceIdMap, null, null); + Optional<String> result = serviceValidator.validate(instanceIdMap, null, null, null); assertEquals(true, result.isPresent()); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java index 65ce355ad1..6eb6fc95d6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java @@ -53,7 +53,7 @@ public class VnfDeleteValidatorTest { public void validateFailureVfModuleVnfTest() { instanceIdMap.put("vnfInstanceId", "1"); doReturn(Optional.of("test")).when(aaiDataRetrieval).getVfModuleIdsByVnfId("1"); - Optional<String> result = vnfValidator.validate(instanceIdMap, null, null); + Optional<String> result = vnfValidator.validate(instanceIdMap, null, null, null); assertEquals(true, result.isPresent()); } @@ -61,7 +61,7 @@ public class VnfDeleteValidatorTest { public void validateSuccessVfModuleVnfTest() { instanceIdMap.put("vnfInstanceId", "1"); doReturn(Optional.empty()).when(aaiDataRetrieval).getVfModuleIdsByVnfId("1"); - Optional<String> result = vnfValidator.validate(instanceIdMap, null, null); + Optional<String> result = vnfValidator.validate(instanceIdMap, null, null, null); assertEquals(false, result.isPresent()); } @@ -69,7 +69,7 @@ public class VnfDeleteValidatorTest { public void validateFailureVolumeGroupVnfTest() { instanceIdMap.put("vnfInstanceId", "1"); doReturn(Optional.of("test")).when(aaiDataRetrieval).getVolumeGroupIdsByVnfId("1"); - Optional<String> result = vnfValidator.validate(instanceIdMap, null, null); + Optional<String> result = vnfValidator.validate(instanceIdMap, null, null, null); assertEquals(true, result.isPresent()); } @@ -77,7 +77,7 @@ public class VnfDeleteValidatorTest { public void validateSuccessVolumeGroupVnfTest() { instanceIdMap.put("vnfInstanceId", "1"); doReturn(Optional.empty()).when(aaiDataRetrieval).getVolumeGroupIdsByVnfId("1"); - Optional<String> result = vnfValidator.validate(instanceIdMap, null, null); + Optional<String> result = vnfValidator.validate(instanceIdMap, null, null, null); assertEquals(false, result.isPresent()); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java index 3d81ee66c9..7aa12a61a6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java @@ -54,7 +54,7 @@ public class VolumeGroupDeleteValidatorTest { public void validateSuccessTest() { instanceIdMap.put("volumeGroupInstanceId", "1"); when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule("1")).thenReturn(false); - Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null); + Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null, null); assertEquals(false, result.isPresent()); } @@ -62,7 +62,7 @@ public class VolumeGroupDeleteValidatorTest { public void validateFailureVnfTest() { instanceIdMap.put("volumeGroupInstanceId", "1"); when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule("1")).thenReturn(true); - Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null); + Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null, null); assertEquals(true, result.isPresent()); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java index b21b468ce3..0b968520d6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java @@ -39,6 +39,7 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.onap.aaiclient.client.aai.AAIVersion; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.BaseTest; import org.onap.so.apihandlerinfra.exceptions.ApiException; @@ -46,7 +47,6 @@ import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestrationRequest; import org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution; import org.onap.so.apihandlerinfra.tenantisolationbeans.DistributionStatus; import org.onap.so.apihandlerinfra.tenantisolationbeans.Status; -import org.onap.aaiclient.client.aai.AAIVersion; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json index 79caa33419..a84b2dbe11 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json @@ -4,21 +4,18 @@ "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", "name": "requestAction", - "value": "assign", - "tag": "pincFabricConfigRequest" + "value": "assign" },{ "id": 2, "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", - "name": "pincFabricId", - "value": "testId", - "tag": "pincFabricConfigRequest" + "name": "fabricId", + "value": "testId" },{ "id": 3, "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca715", "name": "requestAction", - "value": "unassign", - "tag": "pincFabricConfig" + "value": "unassign" } ]
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json index af28007900..6ebe55201a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json @@ -3,6 +3,5 @@ "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", "name": "requestAction", - "value": "assign", - "tag": "pincFabricConfigRequest" + "value": "assign" } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json index c746020e7f..c3554c86a5 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json @@ -3,6 +3,5 @@ "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", "name": "requestAction", - "value": "assign", - "tag": "pincFabricConfigRequest" + "value": "assign" }] diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json new file mode 100644 index 0000000000..e466ac08a3 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json @@ -0,0 +1,39 @@ +{ + "requestDetails":{ + "subscriberInfo":{ + "globalSubscriberId":"Test" + }, + "requestInfo":{ + "suppressRollback": false, + "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "requestorId": "demo", + "instanceName":"testInstanceName", + "source":"VID" + }, + "cloudConfiguration":{ + "lcpCloudRegionId": "RegionOne", + "tenantId": "7320ec4a5b9d4589ba7c4412ccfd290f", + "cloudOwner": "CloudOwner" + }, + "requestParameters":{ + "subscriptionServiceType": "test", + "userParams":[], + "aLaCarte": false, + "payload": "{\"k1\": \"v1\"}" + }, + "project":{ + "projectName": "PNFSWUProject" + }, + "owningEntity":{ + "owningEntityId":"67f2e84c-734d-4e90-a1e4-d2ffa2e75849", + "owningEntityName":"OE-Test" + }, + "modelInfo":{ + "modelVersion": "2.0", + "modelVersionId": "d88da85c-d9e8-4f73-b837-3a72a431622b", + "modelInvariantId": "fe41489e-1563-46a3-b90a-1db629e4375b", + "modelName": "Demo_svc", + "modelType": "service" + } + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json new file mode 100644 index 0000000000..aaaad17470 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json @@ -0,0 +1,20 @@ +{ + "workflowSpecificationList": [ + { + "workflowSpecification": { + "artifactInfo": { + "artifactType": "workflow", + "artifactUuid": "a1fe8726-66d5-3e7f-2212-7e5h662e9255", + "artifactName": "DummyServiceWorkflow", + "artifactVersion": "1.0", + "artifactDescription": "Dummy Service Workflow to test custom Service workflow", + "workflowName": "Dummy Service Workflow", + "operationName": "DummyServiceWorkflow", + "workflowSource": "native", + "workflowResourceTarget": "service" + }, + "workflowInputParameters": [] + } + } + ] +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json new file mode 100644 index 0000000000..9a836e033b --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json @@ -0,0 +1,41 @@ +{ + "_embedded": { + "workflow": [ + { + "artifactChecksum": "MANUAL RECORD", + "artifactName": "DummyServiceWorkflow", + "artifactUUID": "a1fe8726-66d5-3e7f-2212-7e5h662e9255", + "body": null, + "created": "2020-06-29T08:28:15.000+0000", + "description": "Dummy Service Workflow to test custom Service workflow", + "id": 4, + "name": "Dummy Service Workflow", + "operationName": "DummyServiceWorkflow", + "pnfResourceWorkflow": null, + "resourceTarget": "service", + "source": "native", + "timeoutMinutes": null, + "version": 1.0, + "_links": { + "self": { + "href": "http://localhost:8090/workflow/search/findByResourceTarget?resourceTarget=service" + }, + "workflow": { + "href": "http://localhost:8090/workflow/5" + }, + "workflowActivitySpecSequence": { + "href": "http://localhost:8090/workflow/5/workflowActivitySpecSequence" + } + } + } + ] + }, + "_links": { + "self": { + "href": "http://localhost:8090/workflow/search/findByResourceTarget?resourceTarget=service" + }, + "workflowActivitySpecSequence": { + "href": "http://localhost:8090/workflow/5/workflowActivitySpecSequence" + } + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json new file mode 100644 index 0000000000..133c724b43 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json @@ -0,0 +1,6 @@ +{ + "artifactUUID": "81526781-e55c-4cb7-adb3-97e09d9c76bf", + "artifactName": "testingServiceLevelWorkflow.bpmn", + "name": "testingServiceLevelWorkflow", + "operationName": "testServiceLevelOperation" +} diff --git a/mso-api-handlers/mso-requests-db-repositories/pom.xml b/mso-api-handlers/mso-requests-db-repositories/pom.xml index efc81384d4..8f623ad9e5 100644 --- a/mso-api-handlers/mso-requests-db-repositories/pom.xml +++ b/mso-api-handlers/mso-requests-db-repositories/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.onap.so</groupId> <artifactId>mso-api-handlers</artifactId> - <version>1.6.0-SNAPSHOT</version> + <version>1.7.1-SNAPSHOT</version> </parent> <artifactId>mso-requests-db-repositories</artifactId> diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java index f0d717df3c..ea1aeb95a6 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java @@ -20,7 +20,6 @@ package org.onap.so.db.request.data.repository; -import java.util.List; import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; import org.onap.so.db.request.beans.OperationalEnvServiceModelStatusId; import org.springframework.data.jpa.repository.JpaRepository; @@ -35,7 +34,7 @@ public interface OperationalEnvServiceModelStatusRepository public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndRequestId(String operationalEnvId, String requestId); - public List<OperationalEnvServiceModelStatus> findAllByOperationalEnvIdAndRequestId( + public OperationalEnvServiceModelStatus[] findAllByOperationalEnvIdAndRequestId( @Param("OPERATIONAL_ENV_ID") String operationalEnvId, @Param("REQUEST_ID") String requestId); public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId( diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OrchestrationTaskRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OrchestrationTaskRepository.java index 1093c79638..953361fd40 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OrchestrationTaskRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OrchestrationTaskRepository.java @@ -24,10 +24,9 @@ import org.onap.so.db.request.beans.OrchestrationTask; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; -import java.util.List; @RepositoryRestResource(collectionResourceRel = "orchestrationTask", path = "orchestrationTask") public interface OrchestrationTaskRepository extends JpaRepository<OrchestrationTask, String> { - public List<OrchestrationTask> findByStatus(@Param("status") String status); + public OrchestrationTask[] findByStatus(@Param("status") String status); } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java index cb02b7c491..21bc2a697a 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java @@ -37,11 +37,11 @@ public interface RequestProcessingDataRepository extends JpaRepository<RequestPr RequestProcessingData findOneBySoRequestIdAndName(@Param("SO_REQUEST_ID") String soRequestId, @Param("NAME") String name); - List<RequestProcessingData> findBySoRequestIdOrderByGroupingIdDesc(@Param("SO_REQUEST_ID") String soRequestId); + RequestProcessingData[] findBySoRequestIdOrderByGroupingIdDesc(@Param("SO_REQUEST_ID") String soRequestId); RequestProcessingData[] findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc( @Param("SO_REQUEST_ID") String soRequestId, @Param("IS_INTERNAL_DATA") Boolean isDataInternal); - List<RequestProcessingData> findByGroupingIdAndNameAndTag(@Param("GROUPING_ID") String groupingId, + RequestProcessingData[] findByGroupingIdAndNameAndTag(@Param("GROUPING_ID") String groupingId, @Param("NAME") String name, @Param("TAG") String tag); } diff --git a/mso-api-handlers/mso-requests-db/pom.xml b/mso-api-handlers/mso-requests-db/pom.xml index 37bb4175a5..6c1df3e450 100644 --- a/mso-api-handlers/mso-requests-db/pom.xml +++ b/mso-api-handlers/mso-requests-db/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.onap.so</groupId> <artifactId>mso-api-handlers</artifactId> - <version>1.6.0-SNAPSHOT</version> + <version>1.7.1-SNAPSHOT</version> </parent> <artifactId>mso-requests-db</artifactId> @@ -17,11 +17,6 @@ </properties> <dependencies> <dependency> - <groupId>uk.co.blackpepper.bowman</groupId> - <artifactId>bowman-client</artifactId> - <version>0.3.0</version> - </dependency> - <dependency> <groupId>org.onap.so</groupId> <artifactId>common</artifactId> <version>${project.version}</version> diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java index cf6cf687b0..cc721d38b6 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java @@ -40,8 +40,6 @@ import javax.persistence.TemporalType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.apache.commons.lang3.builder.ToStringBuilder; import org.onap.so.requestsdb.TimestampXMLAdapter; -import uk.co.blackpepper.bowman.annotation.LinkedResource; -import uk.co.blackpepper.bowman.annotation.ResourceId; @MappedSuperclass public abstract class InfraRequests implements java.io.Serializable { @@ -164,7 +162,6 @@ public abstract class InfraRequests implements java.io.Serializable { @JoinColumn(name = "SO_REQUEST_ID", referencedColumnName = "REQUEST_ID", updatable = false) private List<CloudApiRequests> cloudApiRequests = new ArrayList<>(); - @ResourceId public URI getRequestURI() { return URI.create(this.requestId); } @@ -443,7 +440,6 @@ public abstract class InfraRequests implements java.io.Serializable { return requestAction; } - @LinkedResource public List<CloudApiRequests> getCloudApiRequests() { return cloudApiRequests; } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/OperationalEnvServiceModelStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/OperationalEnvServiceModelStatus.java index 2278c8cd9d..a7444a49d1 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/OperationalEnvServiceModelStatus.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/OperationalEnvServiceModelStatus.java @@ -22,6 +22,7 @@ package org.onap.so.db.request.beans; import java.io.Serializable; import java.util.Date; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -31,7 +32,6 @@ import javax.persistence.PreUpdate; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; -import java.util.Objects; import org.apache.commons.lang3.builder.ToStringBuilder; /** diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java index e386789c7f..c52d311146 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java @@ -48,7 +48,6 @@ import com.openpojo.business.annotation.BusinessKey; */ @Entity - @JsonInclude(Include.NON_NULL) @Table(name = "request_processing_data") public class RequestProcessingData implements Serializable { diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 6aa00caeed..17b22ec216 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -22,32 +22,26 @@ package org.onap.so.db.request.client; import java.net.URI; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import javax.annotation.PostConstruct; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.apache.http.HttpStatus; -import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.db.request.beans.ArchivedInfraRequests; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; +import org.onap.so.db.request.beans.OrchestrationTask; import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.db.request.beans.ResourceOperationStatus; import org.onap.so.db.request.beans.SiteStatus; import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; import org.onap.so.db.request.beans.WatchdogDistributionStatus; import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; -import org.onap.so.db.request.beans.OrchestrationTask; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; -import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Primary; @@ -56,14 +50,9 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpRequestFactory; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; -import uk.co.blackpepper.bowman.ClientFactory; -import uk.co.blackpepper.bowman.Configuration; @Component("RequestsDbClient") @Primary @@ -166,25 +155,6 @@ public class RequestsDbClient { return endpoint; } - protected ClientFactory getClientFactory() { - URI baseUri = UriBuilder.fromUri(getEndpoint()).build(); - ClientHttpRequestFactory factory = - new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()); - - return Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory) - .setRestTemplateConfigurer(restTemplate -> { - restTemplate.getInterceptors().add((new SOSpringClientFilter())); - restTemplate.getInterceptors().add((new SpringClientPayloadFilter())); - - restTemplate.getInterceptors().add((request, body, execution) -> { - - request.getHeaders().add(HttpHeaders.AUTHORIZATION, msoAdaptersAuth); - return execution.execute(request, body); - }); - }).build().buildClientFactory(); - } - - public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap) { URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); HttpHeaders headers = getHttpHeaders(); @@ -201,30 +171,21 @@ public class RequestsDbClient { } public List<InfraActiveRequests> getInProgressVolumeGroupsAndVfModules() { - HttpHeaders headers = getHttpHeaders(); URI uri = getUri(endpoint + getInProgressVolumeGroupsAndVfModules); - HttpEntity<Map<String, List<String>>> entity = new HttpEntity<>(headers); - return restTemplate - .exchange(uri, HttpMethod.GET, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}) - .getBody(); + + return getMultipleResponse(uri, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}); + } public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) { - try { - HttpEntity<?> entity = getHttpEntity(); - InfraActiveRequests infraActiveRequests = - restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, - entity, InfraActiveRequests.class).getBody(); - if (infraActiveRequests != null) { - infraActiveRequests.setRequestId(requestId); - } - return infraActiveRequests; - } catch (HttpClientErrorException e) { - if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { - return null; - } - throw e; + + + InfraActiveRequests infraActiveRequests = + getSingleResponse(getUri(endpoint + "/infraActiveRequests/" + requestId), InfraActiveRequests.class); + if (infraActiveRequests != null) { + infraActiveRequests.setRequestId(requestId); } + return infraActiveRequests; } public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive( @@ -238,9 +199,8 @@ public class RequestsDbClient { } public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) { - HttpEntity<?> entity = getHttpEntity(); URI uri = getUri(checkVnfIdStatus + operationalEnvironmentId); - return restTemplate.exchange(uri, HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); + return getSingleResponse(uri, InfraActiveRequests.class); } public InfraActiveRequests checkInstanceNameDuplicate(Map<String, String> instanceIdMap, String instanceName, @@ -249,66 +209,40 @@ public class RequestsDbClient { URI uri = getUri(checkInstanceNameDuplicate); HttpEntity<InstanceNameDuplicateCheckRequest> entity = new HttpEntity<>( new InstanceNameDuplicateCheckRequest(instanceIdMap, instanceName, requestScope), headers); - try { - ResponseEntity<InfraActiveRequests> response = - restTemplate.exchange(uri, HttpMethod.POST, entity, InfraActiveRequests.class); - if (response != null && response.hasBody()) { - return restTemplate.exchange(uri, HttpMethod.POST, entity, InfraActiveRequests.class).getBody(); - } else { - return null; - } - } catch (HttpClientErrorException e) { - if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { - return null; - } - throw e; - } + + return postSingleResponse(uri, entity, InfraActiveRequests.class); } public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId) { - try { - HttpEntity<?> entity = getHttpEntity(); - OperationStatus operationStatus = restTemplate.exchange(getUri( - UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)).queryParam(SERVICE_ID, serviceId) - .queryParam(OPERATION_ID, operationId).build().toString()), - HttpMethod.GET, entity, OperationStatus.class).getBody(); - if (operationStatus != null) { - operationStatus.setServiceId(serviceId); - operationStatus.setOperationId(operationId); - } - - return operationStatus; - } catch (HttpClientErrorException e) { - if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { - return null; - } - throw e; + OperationStatus operationStatus = getSingleResponse( + getUri(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)).queryParam(SERVICE_ID, serviceId) + .queryParam(OPERATION_ID, operationId).build().toString()), + OperationStatus.class); + if (operationStatus != null) { + operationStatus.setServiceId(serviceId); + operationStatus.setOperationId(operationId); } + return operationStatus; } public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId( String operationalEnvironmentId, String serviceModelVersionId, String requestId) { - try { - HttpEntity<?> entity = getHttpEntity(); - OperationalEnvServiceModelStatus modelStatus = restTemplate.exchange( - getUri(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdURI) - .queryParam(OPERATIONAL_ENVIRONMENT_ID, operationalEnvironmentId) - .queryParam(SERVICE_MODEL_VERSION_ID, serviceModelVersionId) - .queryParam(REQUEST_ID, requestId).build().toString()), - HttpMethod.GET, entity, OperationalEnvServiceModelStatus.class).getBody(); - if (null != modelStatus) { - modelStatus.setOperationalEnvId(operationalEnvironmentId); - modelStatus.setServiceModelVersionId(serviceModelVersionId); - modelStatus.setRequestId(requestId); - } - return modelStatus; - } catch (HttpClientErrorException e) { - if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { - return null; - } - throw e; + + OperationalEnvServiceModelStatus modelStatus = + getSingleResponse( + getUri(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdURI) + .queryParam(OPERATIONAL_ENVIRONMENT_ID, operationalEnvironmentId) + .queryParam(SERVICE_MODEL_VERSION_ID, serviceModelVersionId) + .queryParam(REQUEST_ID, requestId).build().toString()), + OperationalEnvServiceModelStatus.class); + if (null != modelStatus) { + modelStatus.setOperationalEnvId(operationalEnvironmentId); + modelStatus.setServiceModelVersionId(serviceModelVersionId); + modelStatus.setRequestId(requestId); } + return modelStatus; + } public List<OperationalEnvServiceModelStatus> getAllByOperationalEnvIdAndRequestId(String operationalEnvironmentId, @@ -320,30 +254,18 @@ public class RequestsDbClient { } public OperationalEnvDistributionStatus getDistributionStatusById(String distributionId) { - try { - HttpEntity<?> entity = getHttpEntity(); - OperationalEnvDistributionStatus distributionStatus = - restTemplate.exchange(getUri(operationalEnvDistributionStatusURI + distributionId), HttpMethod.GET, - entity, OperationalEnvDistributionStatus.class).getBody(); - if (null != distributionStatus) { - distributionStatus.setDistributionId(distributionId); - } - return distributionStatus; - } catch (HttpClientErrorException e) { - if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { - return null; - } - throw e; + + OperationalEnvDistributionStatus distributionStatus = getSingleResponse( + getUri(operationalEnvDistributionStatusURI + distributionId), OperationalEnvDistributionStatus.class); + if (null != distributionStatus) { + distributionStatus.setDistributionId(distributionId); } + return distributionStatus; + } private List<OperationalEnvServiceModelStatus> getMultipleOperationalEnvServiceModelStatus(URI uri) { - Iterable<OperationalEnvServiceModelStatus> iterable = - getClientFactory().create(OperationalEnvServiceModelStatus.class).getAll(uri); - List<OperationalEnvServiceModelStatus> serviceModelStatuses = new ArrayList<>(); - Iterator<OperationalEnvServiceModelStatus> statusIterator = iterable.iterator(); - statusIterator.forEachRemaining(serviceModelStatuses::add); - return serviceModelStatuses; + return getMultipleResponse(uri, new ParameterizedTypeReference<List<OperationalEnvServiceModelStatus>>() {}); } public void save(InfraActiveRequests infraActiveRequests) { @@ -376,38 +298,16 @@ public class RequestsDbClient { } public InfraActiveRequests getInfraActiveRequests(String requestId, String basicAuth, String host) { - RestTemplate template = new RestTemplate(); - HttpHeaders headers = new HttpHeaders(); - headers.set(HttpHeaders.AUTHORIZATION, basicAuth); - headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); - headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); + URI uri = getUri(host + "/infraActiveRequests/" + requestId); - try { - InfraActiveRequests infraActiveRequests = template - .exchange(uri, HttpMethod.GET, new HttpEntity<>(headers), InfraActiveRequests.class).getBody(); - if (infraActiveRequests != null) { - infraActiveRequests.setRequestId(requestId); - } - return infraActiveRequests; - } catch (HttpClientErrorException e) { - if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { - return null; - } - throw e; - } + + return getSingleResponse(uri, InfraActiveRequests.class); } public void updateInfraActiveRequests(InfraActiveRequests request, String basicAuth, String host) { - RestTemplate template = new RestTemplate(); - template.getInterceptors().add(new SOSpringClientFilter()); - template.getInterceptors().add(new SpringClientPayloadFilter()); - HttpHeaders headers = new HttpHeaders(); - headers.set(HttpHeaders.AUTHORIZATION, basicAuth); - headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); - headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); URI uri = getUri(host + "/infraActiveRequests/" + request.getRequestId()); - HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, headers); - template.put(uri, entity); + HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, getHttpHeaders()); + restTemplate.put(uri, entity); } protected URI getUri(String uri) { @@ -437,41 +337,30 @@ public class RequestsDbClient { public List<RequestProcessingData> getExternalRequestProcessingDataBySoRequestId(String soRequestId) { URI uri = getUri(UriBuilder.fromUri(getEndpoint() + findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc) .queryParam(SO_REQUEST_ID, soRequestId).queryParam(IS_INTERNAL_DATA, false).build().toString()); - ResponseEntity<RequestProcessingData[]> array = - restTemplate.exchange(uri, HttpMethod.GET, getHttpEntity(), RequestProcessingData[].class); - if (array != null) { - return Arrays.asList(array.getBody()); - } else { - return null; - } + return getMultipleResponse(uri, new ParameterizedTypeReference<List<RequestProcessingData>>() {}); } public RequestProcessingData getRequestProcessingDataBySoRequestIdAndNameAndGrouping(String soRequestId, String name, String groupingId) { - return getClientFactory().create(RequestProcessingData.class) - .get(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdAndGroupIdAndName) - .queryParam(SO_REQUEST_ID, soRequestId).queryParam(NAME, name) - .queryParam(GROUPING_ID, groupingId).build().toString())); + return getSingleResponse(getUri( + UriBuilder.fromUri(endpoint + findBySoRequestIdAndGroupIdAndName).queryParam(SO_REQUEST_ID, soRequestId) + .queryParam(NAME, name).queryParam(GROUPING_ID, groupingId).build().toString()), + RequestProcessingData.class); } public List<RequestProcessingData> getRequestProcessingDataByGroupingIdAndNameAndTag(String groupingId, String name, String tag) { - Iterable<RequestProcessingData> requestProcessingDataListIt = - getClientFactory().create(RequestProcessingData.class) - .getAll(getUri(UriBuilder.fromUri(endpoint + findByGroupingIdAndNameAndTag) - .queryParam(GROUPING_ID, groupingId).queryParam(NAME, name).queryParam(TAG, tag).build() - .toString())); - - List<RequestProcessingData> requestProcessingDataList = - StreamSupport.stream(requestProcessingDataListIt.spliterator(), false).collect(Collectors.toList()); - return requestProcessingDataList; + return getMultipleResponse( + getUri(UriBuilder.fromUri(endpoint + findByGroupingIdAndNameAndTag).queryParam(GROUPING_ID, groupingId) + .queryParam(NAME, name).queryParam(TAG, tag).build().toString()), + new ParameterizedTypeReference<List<RequestProcessingData>>() {}); } public RequestProcessingData getRequestProcessingDataBySoRequestIdAndName(String soRequestId, String name) { - return getClientFactory().create(RequestProcessingData.class) - .get(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdAndName) - .queryParam(SO_REQUEST_ID, soRequestId).queryParam(NAME, name).build().toString())); + return getSingleResponse(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdAndName) + .queryParam(SO_REQUEST_ID, soRequestId).queryParam(NAME, name).build().toString()), + RequestProcessingData.class); } @@ -491,26 +380,14 @@ public class RequestsDbClient { } private List<RequestProcessingData> getRequestProcessingData(URI uri) { - Iterable<RequestProcessingData> requestProcessingDataIterator = - getClientFactory().create(RequestProcessingData.class).getAll(uri); - List<RequestProcessingData> requestProcessingDataList = new ArrayList<>(); - Iterator<RequestProcessingData> it = requestProcessingDataIterator.iterator(); - it.forEachRemaining(requestProcessingDataList::add); - return requestProcessingDataList; + return getMultipleResponse(uri, new ParameterizedTypeReference<List<RequestProcessingData>>() {}); } public InfraActiveRequests findOneByRequestId(String requestId) { - try { - HttpEntity<?> entity = getHttpEntity(); - return restTemplate.exchange( - getUri(UriBuilder.fromUri(findOneByRequestId).queryParam(REQUEST_ID, requestId).build().toString()), - HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); - } catch (HttpClientErrorException e) { - if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { - return null; - } - throw e; - } + return getSingleResponse( + getUri(UriBuilder.fromUri(findOneByRequestId).queryParam(REQUEST_ID, requestId).build().toString()), + InfraActiveRequests.class); + } // From and To are defaulted to ignore start/endtime on query to database @@ -525,11 +402,8 @@ public class RequestsDbClient { } public List<OrchestrationTask> getAllOrchestrationTasks() { - String url = UriBuilder.fromUri(getUri(orchestrationTasksURI)).build().toString(); - HttpEntity<?> entity = getHttpEntity(); - return restTemplate - .exchange(url, HttpMethod.GET, entity, new ParameterizedTypeReference<List<OrchestrationTask>>() {}) - .getBody(); + return getMultipleResponse(getUri(orchestrationTasksURI), + new ParameterizedTypeReference<List<OrchestrationTask>>() {}); } public OrchestrationTask getOrchestrationTask(String taskId) { @@ -605,4 +479,54 @@ public class RequestsDbClient { return new HttpEntity<>(headers); } + private <T> T getSingleResponse(URI uri, Class<T> clazz) { + try { + HttpEntity<?> entity = getHttpEntity(); + return restTemplate.exchange(uri, HttpMethod.GET, entity, clazz).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } + } + + private <T> List<T> getMultipleResponse(URI uri, ParameterizedTypeReference<List<T>> type) { + try { + HttpEntity<?> entity = getHttpEntity(); + return restTemplate.exchange(uri, HttpMethod.GET, entity, type).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return new ArrayList<T>(); + } + throw e; + } + } + + private <T> T postSingleResponse(URI uri, HttpEntity<?> payload, Class<T> clazz) { + try { + HttpEntity<?> entity = new HttpEntity<>(payload.getBody(), getHttpHeaders()); + return restTemplate.exchange(uri, HttpMethod.POST, entity, clazz).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } + } + + private <T> List<T> postMultipleResponse(URI uri, HttpEntity<?> payload, ParameterizedTypeReference<List<T>> type) { + try { + HttpEntity<?> entity = new HttpEntity<>(payload.getBody(), getHttpHeaders()); + ResponseEntity<List<T>> result = restTemplate.exchange(uri, HttpMethod.POST, entity, type); + + return result.getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return new ArrayList<T>(); + } + throw e; + } + } + } diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java index 0ad8d1458e..32886bf62e 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java @@ -1,11 +1,14 @@ package org.onap.so.db.request.client; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.times; +import static org.mockito.Mockito.when; import java.net.URI; +import java.util.ArrayList; +import java.util.List; import javax.ws.rs.core.UriBuilder; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -13,21 +16,14 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.RequestProcessingData; -import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpRequestFactory; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -import uk.co.blackpepper.bowman.ClientFactory; -import uk.co.blackpepper.bowman.Configuration; @RunWith(MockitoJUnitRunner.class) @@ -61,12 +57,16 @@ public class RequestDbClientTest { @Test public void testGetRequestProcessingDataBySoRequestIdAndIsInternalData() { Mockito.doReturn("host").when(requestsDbClient).getEndpoint(); - requestsDbClient.getExternalRequestProcessingDataBySoRequestId("12345"); URI uri = URI.create(UriBuilder .fromUri("host/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc") .queryParam("SO_REQUEST_ID", "12345").queryParam("IS_INTERNAL_DATA", false).build().toString()); - Mockito.verify(restTemplate, times(1)).exchange(eq(uri), eq(HttpMethod.GET), isA(HttpEntity.class), - eq(RequestProcessingData[].class)); + when(restTemplate.exchange(eq(uri), eq(HttpMethod.GET), isA(HttpEntity.class), + isA(ParameterizedTypeReference.class))).thenReturn( + new ResponseEntity<List<RequestProcessingData>>(new ArrayList<RequestProcessingData>(), + HttpStatus.NOT_FOUND)); + assertTrue(requestsDbClient.getExternalRequestProcessingDataBySoRequestId("12345").isEmpty()); + + } } diff --git a/mso-api-handlers/pom.xml b/mso-api-handlers/pom.xml index db939a6868..9463d5d6b6 100644 --- a/mso-api-handlers/pom.xml +++ b/mso-api-handlers/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.onap.so</groupId> <artifactId>so</artifactId> - <version>1.6.0-SNAPSHOT</version> + <version>1.7.1-SNAPSHOT</version> </parent> <artifactId>mso-api-handlers</artifactId> @@ -19,7 +19,6 @@ <module>mso-api-handler-common</module> <module>mso-api-handler-infra</module> </modules> - <dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> |