diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java')
6 files changed, 305 insertions, 256 deletions
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 dbdc274bc6..028abd6d25 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 @@ -7,12 +7,14 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -133,7 +135,7 @@ public class InstanceManagement { HashMap<String, String> instanceIdMap, String version, String requestId, ContainerRequestContext requestContext) throws ApiException { String serviceInstanceId; - Boolean aLaCarte = true; + boolean aLaCarte = true; ServiceInstancesRequest sir; String apiVersion = version.substring(1); @@ -162,26 +164,14 @@ public class InstanceManagement { currentActiveReq); requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); - int requestVersion = Integer.parseInt(version.substring(1)); - String vnfType = msoRequest.getVnfType(sir, requestScope, action, requestVersion); + String vnfType = msoRequest.getVnfType(sir, requestScope); if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) { currentActiveReq.setVnfType(vnfType); } - InfraActiveRequests dup = null; - boolean inProgress = false; - - dup = requestHandlerUtils.duplicateCheck(action, instanceIdMap, null, requestScope, currentActiveReq); - - if (dup != null) { - inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq); - } + checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq); - if (dup != null && inProgress) { - requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, null, requestScope, - dup); - } ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse(); RequestReferences referencesResponse = new RequestReferences(); @@ -189,7 +179,7 @@ public class InstanceManagement { referencesResponse.setRequestId(requestId); serviceResponse.setRequestReferences(referencesResponse); - Boolean isBaseVfModule = false; + boolean isBaseVfModule = false; String workflowUuid = null; if (instanceIdMap != null) { @@ -207,17 +197,9 @@ public class InstanceManagement { vnfId = sir.getVnfInstanceId(); } - try { - infraActiveRequestsClient.save(currentActiveReq); - } catch (Exception e) { - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, - ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build(); - } + saveCurrentActiveRequest(currentActiveReq); - RequestClientParameter requestClientParameter = null; + RequestClientParameter requestClientParameter; try { requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) .setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) @@ -237,10 +219,38 @@ public class InstanceManagement { recipeLookupResult.getOrchestrationURI(), requestScope); } + private void saveCurrentActiveRequest(InfraActiveRequests currentActiveReq) throws RequestDbFailureException { + try { + infraActiveRequestsClient.save(currentActiveReq); + } catch (Exception e) { + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build(); + } + } + + private void checkDuplicateAndBuildError(Actions action, HashMap<String, String> instanceIdMap, String requestScope, + InfraActiveRequests currentActiveReq) throws ApiException { + + InfraActiveRequests dup = + requestHandlerUtils.duplicateCheck(action, instanceIdMap, null, requestScope, currentActiveReq); + if (dup == null) { + return; + } + + boolean inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq); + if (inProgress) { + requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, null, requestScope, + dup); + } + } + private Response processPNFCustomWorkflowRequest(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, ContainerRequestContext requestContext) throws ApiException { - Boolean aLaCarte = false; + boolean aLaCarte = false; ServiceInstancesRequest sir; String apiVersion = version.substring(1); @@ -279,33 +289,13 @@ public class InstanceManagement { currentActiveReq); requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); - InfraActiveRequests dup = null; - boolean inProgress = false; - - dup = requestHandlerUtils.duplicateCheck(action, instanceIdMap, null, requestScope, currentActiveReq); - - if (dup != null) { - inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq); - } - - if (dup != null && inProgress) { - requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, null, requestScope, - dup); - } + checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq); RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); - try { - infraActiveRequestsClient.save(currentActiveReq); - } catch (Exception e) { - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, - ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build(); - } + saveCurrentActiveRequest(currentActiveReq); - RequestClientParameter requestClientParameter = null; + RequestClientParameter requestClientParameter; try { requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()) @@ -326,7 +316,7 @@ public class InstanceManagement { private RecipeLookupResult getInstanceManagementWorkflowRecipe(InfraActiveRequests currentActiveReq, String workflowUuid) throws ApiException { - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { recipeLookupResult = getCustomWorkflowUri(workflowUuid); @@ -359,14 +349,12 @@ public class InstanceManagement { private RecipeLookupResult getCustomWorkflowUri(String workflowUuid) { - String recipeUri = null; Workflow workflow = catalogDbClient.findWorkflowByArtifactUUID(workflowUuid); - if (workflow == null) { - return null; - } else { + if (workflow != null) { String workflowName = workflow.getName(); - recipeUri = "/mso/async/services/" + workflowName; + String recipeUri = "/mso/async/services/" + workflowName; + return new RecipeLookupResult(recipeUri, 180); } - return new RecipeLookupResult(recipeUri, 180); + return null; } } 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 c077558301..5c81f4e6a5 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 @@ -7,12 +7,14 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,7 +32,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; +import java.util.Optional; import java.util.StringTokenizer; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; @@ -69,7 +71,6 @@ import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.LogConstants; import org.onap.so.serviceinstancebeans.CloudConfiguration; -import org.onap.so.serviceinstancebeans.InstanceDirection; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.PolicyException; @@ -148,7 +149,6 @@ 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) @@ -222,44 +222,31 @@ public class MsoRequest { } } - public Map<String, List<String>> getOrchestrationFilters(MultivaluedMap<String, String> queryParams) - throws ValidationException { - - String queryParam = null; + public Map<String, List<String>> getOrchestrationFilters(MultivaluedMap<String, String> queryParams) { + final String FILTER_KEY = "filter"; Map<String, List<String>> orchestrationFilterParams = new HashMap<>(); + Optional.ofNullable(queryParams.get(FILTER_KEY)).ifPresent(listValues -> listValues + .forEach(value -> addValueToOrchestrationFilterParamsMap(orchestrationFilterParams, value))); - for (Entry<String, List<String>> entry : queryParams.entrySet()) { - queryParam = entry.getKey(); - - try { - if ("filter".equalsIgnoreCase(queryParam)) { - for (String value : entry.getValue()) { - StringTokenizer st = new StringTokenizer(value, ":"); - - int counter = 0; - String mapKey = null; - List<String> orchestrationList = new ArrayList<>(); - while (st.hasMoreElements()) { - if (counter == 0) { - mapKey = st.nextElement() + ""; - } else { - orchestrationList.add(st.nextElement() + ""); - } - counter++; - } - orchestrationFilterParams.put(mapKey, orchestrationList); - } - } + return orchestrationFilterParams; + } - } catch (Exception e) { - throw new ValidationException("QueryParam ServiceInfo", e); - } + private void addValueToOrchestrationFilterParamsMap(Map<String, List<String>> orchestrationFilterParams, + String value) { + final String TOKEN_DELIMITER = ":"; + StringTokenizer stringTokenizer = new StringTokenizer(value, TOKEN_DELIMITER); + if (!stringTokenizer.hasMoreTokens()) { + return; + } + String mapKey = stringTokenizer.nextToken(); + List<String> orchestrationList = new ArrayList<>(); + while (stringTokenizer.hasMoreTokens()) { + orchestrationList.add(stringTokenizer.nextToken()); } - - return orchestrationFilterParams; + orchestrationFilterParams.put(mapKey, orchestrationList); } public InfraActiveRequests createRequestObject(ServiceInstancesRequest servInsReq, Actions action, String requestId, @@ -465,7 +452,6 @@ public class MsoRequest { } - public Response buildResponse(int httpResponseCode, String errorCode, InfraActiveRequests inProgress) { return buildResponseWithError(httpResponseCode, errorCode, inProgress, null); } @@ -474,7 +460,6 @@ public class MsoRequest { String errorString) { - // Log the failed request into the MSO Requests database return Response.status(httpResponseCode).entity(null).build(); @@ -487,7 +472,6 @@ public class MsoRequest { } - public String getServiceType(VnfInputs vnfInputs) { if (vnfInputs.getServiceType() != null) return vnfInputs.getServiceType(); @@ -625,156 +609,78 @@ public class MsoRequest { } - public String getVfModuleType(ServiceInstancesRequest sir, String requestScope, Actions action, int reqVersion) { + public String getVfModuleType(ServiceInstancesRequest sir, String requestScope) { - String serviceInstanceType = null; - - String vnfType = null; + String vnfType; String vfModuleType = null; - String vfModuleModelName = null; + String vfModuleModelName; ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList(); String serviceModelName = null; String vnfModelName = null; - String asdcServiceModelVersion = null; String volumeGroupId = null; - boolean isRelatedServiceInstancePresent = false; - boolean isRelatedVnfInstancePresent = false; - boolean isSourceVnfPresent = false; - boolean isDestinationVnfPresent = false; - boolean isConnectionPointPresent = false; - - if (instanceList != null) { - for (RelatedInstanceList relatedInstanceList : instanceList) { - RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); - ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo(); - - if (action != Action.deleteInstance) { - - if (ModelType.configuration.name().equalsIgnoreCase(requestScope)) { - if (InstanceDirection.source.equals(relatedInstance.getInstanceDirection()) - && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) { - isSourceVnfPresent = true; - } else if (InstanceDirection.destination.equals(relatedInstance.getInstanceDirection()) - && (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) - || (relatedInstanceModelInfo.getModelType().equals(ModelType.pnf) - && reqVersion == 6))) { - isDestinationVnfPresent = true; - } - } - if (ModelType.connectionPoint.equals(relatedInstanceModelInfo.getModelType()) - && ModelType.configuration.name().equalsIgnoreCase(requestScope)) { - isConnectionPointPresent = true; - } - } - - - if (relatedInstanceModelInfo.getModelType().equals(ModelType.service)) { - isRelatedServiceInstancePresent = true; - serviceModelName = relatedInstanceModelInfo.getModelName(); - asdcServiceModelVersion = relatedInstanceModelInfo.getModelVersion(); - } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) - && !(ModelType.configuration.name().equalsIgnoreCase(requestScope))) { - isRelatedVnfInstancePresent = true; - vnfModelName = relatedInstanceModelInfo.getModelCustomizationName(); - } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup)) { - volumeGroupId = relatedInstance.getInstanceId(); - } + if (instanceList == null) { + return null; + } + for (RelatedInstanceList relatedInstanceList : instanceList) { + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo(); + + if (relatedInstanceModelInfo.getModelType().equals(ModelType.service)) { + serviceModelName = relatedInstanceModelInfo.getModelName(); + } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) + && !(ModelType.configuration.name().equalsIgnoreCase(requestScope))) { + vnfModelName = relatedInstanceModelInfo.getModelCustomizationName(); + } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup)) { + volumeGroupId = relatedInstance.getInstanceId(); } - - if (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())) { - serviceInstanceType = serviceModelName; - vnfType = serviceModelName + "/" + vnfModelName; - } else if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) { - vfModuleModelName = modelInfo.getModelName(); - serviceInstanceType = serviceModelName; - vnfType = serviceModelName + "/" + vnfModelName; - vfModuleType = vnfType + "::" + vfModuleModelName; - sir.setVolumeGroupInstanceId(volumeGroupId); - } else if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) - vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName(); - + } + if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) { + vfModuleModelName = modelInfo.getModelName(); + vnfType = serviceModelName + "/" + vnfModelName; + vfModuleType = vnfType + "::" + vfModuleModelName; + sir.setVolumeGroupInstanceId(volumeGroupId); } return vfModuleType; } - public String getVnfType(ServiceInstancesRequest sir, String requestScope, Actions action, int reqVersion) { + public String getVnfType(ServiceInstancesRequest sir, String requestScope) { - String serviceInstanceType = null; - String networkType = null; String vnfType = null; - String vfModuleType = null; - String vfModuleModelName = null; - ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList(); String serviceModelName = null; String vnfModelName = null; - String asdcServiceModelVersion = null; String volumeGroupId = null; - boolean isRelatedServiceInstancePresent = false; - boolean isRelatedVnfInstancePresent = false; - boolean isSourceVnfPresent = false; - boolean isDestinationVnfPresent = false; - boolean isConnectionPointPresent = false; - - if (instanceList != null) { - for (RelatedInstanceList relatedInstanceList : instanceList) { - RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); - ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo(); - - if (action != Action.deleteInstance) { - - if (ModelType.configuration.name().equalsIgnoreCase(requestScope)) { - if (InstanceDirection.source.equals(relatedInstance.getInstanceDirection()) - && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) { - isSourceVnfPresent = true; - } else if (InstanceDirection.destination.equals(relatedInstance.getInstanceDirection()) - && (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) - || (relatedInstanceModelInfo.getModelType().equals(ModelType.pnf) - && reqVersion == 6))) { - isDestinationVnfPresent = true; - } - } - if (ModelType.connectionPoint.equals(relatedInstanceModelInfo.getModelType()) - && ModelType.configuration.name().equalsIgnoreCase(requestScope)) { - isConnectionPointPresent = true; - } - } - - - if (relatedInstanceModelInfo.getModelType().equals(ModelType.service)) { - isRelatedServiceInstancePresent = true; - serviceModelName = relatedInstanceModelInfo.getModelName(); - asdcServiceModelVersion = relatedInstanceModelInfo.getModelVersion(); - } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) - && !(ModelType.configuration.name().equalsIgnoreCase(requestScope))) { - isRelatedVnfInstancePresent = true; - vnfModelName = relatedInstanceModelInfo.getModelCustomizationName(); - } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup)) { - volumeGroupId = relatedInstance.getInstanceId(); - } + if (instanceList == null) { + return null; + } + for (RelatedInstanceList relatedInstanceList : instanceList) { + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo(); + + if (relatedInstanceModelInfo.getModelType().equals(ModelType.service)) { + serviceModelName = relatedInstanceModelInfo.getModelName(); + } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) + && !(ModelType.configuration.name().equalsIgnoreCase(requestScope))) { + vnfModelName = relatedInstanceModelInfo.getModelCustomizationName(); + } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup)) { + volumeGroupId = relatedInstance.getInstanceId(); } - - if (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())) { - serviceInstanceType = serviceModelName; - vnfType = serviceModelName + "/" + vnfModelName; - } else if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) { - vfModuleModelName = modelInfo.getModelName(); - serviceInstanceType = serviceModelName; - vnfType = serviceModelName + "/" + vnfModelName; - vfModuleType = vnfType + "::" + vfModuleModelName; - sir.setVolumeGroupInstanceId(volumeGroupId); - } else if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) - vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName(); - } - return vnfType; + if (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())) { + vnfType = serviceModelName + "/" + vnfModelName; + } else if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) { + vnfType = serviceModelName + "/" + vnfModelName; + sir.setVolumeGroupInstanceId(volumeGroupId); + } else if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) + vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName(); + return vnfType; } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java new file mode 100644 index 0000000000..7961cb0886 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra; + +import com.fasterxml.jackson.databind.ObjectMapper; +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 org.apache.http.HttpStatus; +import org.json.JSONObject; +import org.onap.so.apihandler.common.ErrorNumbers; +import org.onap.so.apihandler.common.ResponseBuilder; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.db.request.beans.OrchestrationTask; +import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.logger.ErrorCode; +import org.onap.so.logger.LoggingAnchor; +import org.onap.so.logger.MessageEnum; +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.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import static org.onap.so.apihandlerinfra.Constants.MSO_PROP_APIHANDLER_INFRA; + +@Path("/onap/so/infra/orchestrationTasks") +@OpenAPIDefinition( + info = @Info(title = "onap/so/infra/orchestrationTasks", description = "API Requests for Orchestration Task")) +@Component +public class OrchestrationTasks { + + private static Logger logger = LoggerFactory.getLogger(OrchestrationTasks.class); + + @Autowired + private MsoRequest msoRequest; + + @Autowired + private CamundaRequestHandler camundaRequestHandler; + + @Autowired + private RequestsDbClient requestsDbClient; + + @Autowired + private ResponseBuilder builder; + + private ObjectMapper mapper = new ObjectMapper(); + + @GET + @Path("/{version:[vV][4-7]}/") + @Operation(description = "Find All Orchestrated Task", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Produces(MediaType.APPLICATION_JSON) + @Transactional + public Response getAllOrchestrationTasks(@QueryParam("status") String status, + @PathParam("version") String version) { + List<OrchestrationTask> orchestrationTaskList = requestsDbClient.getAllOrchestrationTasks(); + if (status != null && !status.isEmpty()) { + for (Iterator<OrchestrationTask> it = orchestrationTaskList.iterator(); it.hasNext();) { + OrchestrationTask task = it.next(); + if (!status.equals(task.getStatus())) { + it.remove(); + } + } + } + return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTaskList, version); + } + + @GET + @Path("/{version:[vV][4-7]}/{taskId}") + @Operation(description = "Find Orchestrated Task for a given TaskId", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Produces(MediaType.APPLICATION_JSON) + @Transactional + public Response getOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version) + throws ApiException { + try { + OrchestrationTask orchestrationTask = requestsDbClient.getOrchestrationTask(taskId); + return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTask, version); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), + "Exception while communciate with Request DB - Orchestration Task Lookup", e); + Response response = + msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version); + return response; + } + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java index 65537cbba0..a15d9cfd48 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java @@ -251,25 +251,22 @@ public class ResumeOrchestrationRequest { } try { - requestClientParameter = - new RequestClientParameter.Builder().setRequestId(currentActiveRequest.getRequestId()) - .setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) - .setRequestAction(infraActiveRequest.getRequestAction()) - .setServiceInstanceId(infraActiveRequest.getServiceInstanceId()) - .setPnfCorrelationId(pnfCorrelationId).setVnfId(infraActiveRequest.getVnfId()) - .setVfModuleId(infraActiveRequest.getVfModuleId()) - .setVolumeGroupId(infraActiveRequest.getVolumeGroupId()) - .setNetworkId(infraActiveRequest.getNetworkId()) - .setServiceType(infraActiveRequest.getServiceType()) - .setVnfType(infraActiveRequest.getVnfType()) - .setVfModuleType(msoRequest.getVfModuleType(sir, infraActiveRequest.getRequestScope(), - action, Integer.parseInt(version))) - .setNetworkType(infraActiveRequest.getNetworkType()) - .setRequestDetails(requestHandlerUtils - .mapJSONtoMSOStyle(infraActiveRequest.getRequestBody(), sir, aLaCarte, action)) - .setApiVersion(version).setALaCarte(aLaCarte) - .setRequestUri(currentActiveRequest.getRequestUrl()) - .setInstanceGroupId(infraActiveRequest.getInstanceGroupId()).build(); + requestClientParameter = new RequestClientParameter.Builder() + .setRequestId(currentActiveRequest.getRequestId()).setBaseVfModule(isBaseVfModule) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) + .setRequestAction(infraActiveRequest.getRequestAction()) + .setServiceInstanceId(infraActiveRequest.getServiceInstanceId()) + .setPnfCorrelationId(pnfCorrelationId).setVnfId(infraActiveRequest.getVnfId()) + .setVfModuleId(infraActiveRequest.getVfModuleId()) + .setVolumeGroupId(infraActiveRequest.getVolumeGroupId()) + .setNetworkId(infraActiveRequest.getNetworkId()).setServiceType(infraActiveRequest.getServiceType()) + .setVnfType(infraActiveRequest.getVnfType()) + .setVfModuleType(msoRequest.getVfModuleType(sir, infraActiveRequest.getRequestScope())) + .setNetworkType(infraActiveRequest.getNetworkType()) + .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(infraActiveRequest.getRequestBody(), sir, + aLaCarte, action)) + .setApiVersion(version).setALaCarte(aLaCarte).setRequestUri(currentActiveRequest.getRequestUrl()) + .setInstanceGroupId(infraActiveRequest.getInstanceGroupId()).build(); } catch (IOException e) { logger.error("IOException while generating requestClientParameter to send to BPMN", e); ErrorLoggerInfo errorLoggerInfo = diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 175b212c86..33eae43e44 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -844,17 +844,15 @@ public class ServiceInstances extends AbstractRestHandler { } requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); - - int requestVersion = Integer.parseInt(version.substring(1)); String instanceName = null; if (sir.getRequestDetails().getRequestInfo() != null) { instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName(); } boolean alaCarteFlag = msoRequest.getAlacarteFlag(sir); - String vnfType = msoRequest.getVnfType(sir, requestScope, action, requestVersion); + String vnfType = msoRequest.getVnfType(sir, requestScope); String networkType = msoRequest.getNetworkType(sir, requestScope); String sdcServiceModelVersion = msoRequest.getSDCServiceModelVersion(sir); - String vfModuleType = msoRequest.getVfModuleType(sir, requestScope, action, requestVersion); + String vfModuleType = msoRequest.getVfModuleType(sir, requestScope); if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) { currentActiveReq.setVnfType(vnfType); @@ -935,7 +933,7 @@ public class ServiceInstances extends AbstractRestHandler { } - RequestClientParameter requestClientParameter = null; + RequestClientParameter requestClientParameter; try { requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) .setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) 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 925d10179f..0d0e6ee92f 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 @@ -23,6 +23,8 @@ package org.onap.so.apihandlerinfra; import java.util.ArrayList; import java.util.HashMap; +import java.util.TreeSet; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -90,21 +92,40 @@ public class WorkflowSpecificationsHandler { @Transactional public Response queryWorkflowSpecifications(@QueryParam("vnfModelVersionId") String vnfModelVersionId, - @PathParam("version") String version) throws Exception { - + @QueryParam("pnfModelVersionId") String pnfModelVersionId, @PathParam("version") String version) + throws Exception { String apiVersion = version.substring(1); - ObjectMapper mapper1 = new ObjectMapper(); - mapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - List<Workflow> workflows = catalogDbClient.findWorkflowByModelUUID(vnfModelVersionId); + List<Workflow> workflows = new ArrayList<>(); + if (vnfModelVersionId == null && pnfModelVersionId == null) { + workflows.addAll(queryWorkflowSpecificationsForAll()); + } else { + // 1. query workflow specifications for given vnfModelVersionId if need. + if (vnfModelVersionId != null) { + List<Workflow> vnfWorkflows = queryWorkflowSpecificationsForVnf(vnfModelVersionId); + logger.debug("Retrieved " + vnfWorkflows.size() + " workflows for given vnfModelVersionId."); + if (vnfWorkflows.size() > 0) { + workflows.addAll(vnfWorkflows); + } + } - List<Workflow> nativeWorkflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW); - if (nativeWorkflows != null && !nativeWorkflows.isEmpty()) { - workflows.addAll(nativeWorkflows); + // 2. query workflow specifications for given pnfModelVersionId if need. + if (pnfModelVersionId != null) { + List<Workflow> pnfWorkflows = queryWorkflowSpecificationsForPnf(pnfModelVersionId); + logger.debug("Retrieved " + pnfWorkflows.size() + " workflows for given pnfModelVerionId."); + if (pnfWorkflows.size() > 0) { + workflows.addAll(pnfWorkflows); + } + } } - WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(workflows); + // Deduplication + List<Workflow> retWorkflows = workflows.stream() + .collect(Collectors.collectingAndThen( + Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Workflow::getArtifactUUID))), + ArrayList::new)); + + WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(retWorkflows); String jsonResponse; try { @@ -239,4 +260,24 @@ public class WorkflowSpecificationsHandler { } return validationList; } + + private List<Workflow> queryWorkflowSpecificationsForAll() { + List<Workflow> workflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW); + return workflows; + } + + private List<Workflow> queryWorkflowSpecificationsForVnf(String vnfModelVersionId) { + List<Workflow> workflows = catalogDbClient.findWorkflowByVnfModelUUID(vnfModelVersionId); + + List<Workflow> nativeWorkflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW); + if (!nativeWorkflows.isEmpty()) { + workflows.addAll(nativeWorkflows); + } + return workflows; + } + + private List<Workflow> queryWorkflowSpecificationsForPnf(String pnfModelVersionId) { + List<Workflow> workflows = catalogDbClient.findWorkflowByPnfModelUUID(pnfModelVersionId); + return workflows; + } } |