diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
4 files changed, 171 insertions, 2 deletions
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 31e026b332..ce371203ab 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 @@ -42,7 +42,11 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.Tenant; import org.onap.so.apihandler.common.ResponseBuilder; +import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.apihandlerinfra.tasksbeans.TasksRequest; import org.onap.so.apihandlerinfra.validation.ApplyUpdatedConfigValidation; import org.onap.so.apihandlerinfra.validation.CloudConfigurationValidation; @@ -97,7 +101,6 @@ import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; - @Component public class MsoRequest { @@ -107,6 +110,9 @@ public class MsoRequest { @Autowired private ResponseBuilder builder; + @Autowired + private AAIDataRetrieval aaiDataRet; + @Value("${mso.enforceDLP:false}") private boolean enforceDLP; @@ -316,6 +322,25 @@ public class MsoRequest { aq.setPnfName(servInsReq.getPnfName()); } + if (servInsReq.getRequestDetails() != null && servInsReq.getRequestDetails().getRequestInfo() != null + && servInsReq.getRequestDetails().getRequestInfo().getProductFamilyId() != null) { + logger.debug("Retrieving productFamilyName to put into requests db"); + + org.onap.aai.domain.yang.Service service = + aaiDataRet.getService(servInsReq.getRequestDetails().getRequestInfo().getProductFamilyId()); + if (service != null) { + logger.debug("Found service by service-id"); + String productFamilyName = service.getServiceDescription(); + if (productFamilyName != null) { + aq.setProductFamilyName(productFamilyName); + } + } + } + + aq.setProductFamilyName(getProductFamilyNameFromAAI(servInsReq)); + + aq.setTenantName(getTenantNameFromAAI(servInsReq)); + if (ModelType.service.name().equalsIgnoreCase(requestScope)) { if (servInsReq.getRequestDetails().getRequestInfo() != null) { if (servInsReq.getRequestDetails().getRequestInfo().getInstanceName() != null) { @@ -683,4 +708,31 @@ public class MsoRequest { return vnfType; } + protected String getTenantNameFromAAI(ServiceInstancesRequest servInsReq) { + String tenantName = null; + if (servInsReq.getRequestDetails() != null && servInsReq.getRequestDetails().getCloudConfiguration() != null + && servInsReq.getRequestDetails().getCloudConfiguration().getTenantId() != null) { + Tenant tenant = aaiDataRet.getTenant(servInsReq.getRequestDetails().getCloudConfiguration().getCloudOwner(), + servInsReq.getRequestDetails().getCloudConfiguration().getLcpCloudRegionId(), + servInsReq.getRequestDetails().getCloudConfiguration().getTenantId()); + if (tenant != null) { + tenantName = tenant.getTenantName(); + } + } + return tenantName; + } + + protected String getProductFamilyNameFromAAI(ServiceInstancesRequest servInsReq) { + String productFamilyName = null; + if (servInsReq.getRequestDetails() != null && servInsReq.getRequestDetails().getRequestInfo() != null + && servInsReq.getRequestDetails().getRequestInfo().getProductFamilyId() != null) { + org.onap.aai.domain.yang.Service service = + aaiDataRet.getService(servInsReq.getRequestDetails().getRequestInfo().getProductFamilyId()); + if (service != null) { + productFamilyName = service.getServiceDescription(); + } + } + return productFamilyName; + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index ae68cc6032..fec93f72e4 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -347,6 +347,13 @@ public class OrchestrationRequests { } else { requestDetails = mapper.readValue(requestBody, RequestDetails.class); } + if (requestDetails.getRequestInfo() != null && iar.getProductFamilyName() != null) { + requestDetails.getRequestInfo().setProductFamilyName(iar.getProductFamilyName()); + } + if (requestDetails.getCloudConfiguration() != null && iar.getTenantName() != null) { + requestDetails.getCloudConfiguration().setTenantName(iar.getTenantName()); + } + } catch (IOException e) { logger.error("Exception occurred", e); ErrorLoggerInfo errorLoggerInfo = 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 index 21129d7c2d..90cf50262b 100644 --- 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 @@ -206,4 +206,95 @@ public class OrchestrationTasks { } } + @POST + @Path("/{version:[vV][4-7]}/{taskId}/commit") + @Operation(description = "Commit an Orchestrated Task", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Produces(MediaType.APPLICATION_JSON) + @Transactional + public Response CommitOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version) { + OrchestrationTask orchestrationTask; + try { + orchestrationTask = requestsDbClient.getOrchestrationTask(taskId); + } 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 Commit", e); + Response response = + msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version); + return response; + } + try { + String taskName = orchestrationTask.getName(); + Map<String, String> commitVar = new HashMap<>(); + commitVar.put("taskAction", "commit"); + JSONObject msgJson = createMessageBody(taskId, taskName, commitVar); + camundaRequestHandler.sendCamundaMessages(msgJson); + 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 Delete", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, e.getMessage(), ErrorNumbers.ERROR_FROM_BPEL, null, version); + return response; + } + + } + + @POST + @Path("/{version:[vV][4-7]}/{taskId}/abort") + @Operation(description = "Commit an Orchestrated Task", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Produces(MediaType.APPLICATION_JSON) + @Transactional + public Response AbortOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version) { + OrchestrationTask orchestrationTask; + try { + orchestrationTask = requestsDbClient.getOrchestrationTask(taskId); + } 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 Commit", e); + Response response = + msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version); + return response; + } + try { + String taskName = orchestrationTask.getName(); + Map<String, String> commitVar = new HashMap<>(); + commitVar.put("taskAction", "abort"); + JSONObject msgJson = createMessageBody(taskId, taskName, commitVar); + camundaRequestHandler.sendCamundaMessages(msgJson); + 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 Delete", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, e.getMessage(), ErrorNumbers.ERROR_FROM_BPEL, null, version); + return response; + } + + } + + private JSONObject createMessageBody(String taskId, String taskName, Map<String, ?> variables) { + JSONObject msgJson = new JSONObject(); + msgJson.put("messageName", taskName); + msgJson.put("businessKey", taskId); + JSONObject processVariables = new JSONObject(); + for (Map.Entry<String, ?> entry : variables.entrySet()) { + JSONObject valueInfo = new JSONObject(); + String key = entry.getKey(); + Object value = entry.getValue(); + valueInfo.put("value", value.toString()); + valueInfo.put("type", value.getClass().getSimpleName()); + processVariables.put(key, valueInfo); + } + msgJson.put("processVariables", processVariables); + return msgJson; + } + } 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 344e5438c9..fee7a3a8f4 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 @@ -3,7 +3,9 @@ package org.onap.so.apihandlerinfra.infra.rest; import java.util.Optional; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.L3Network; +import org.onap.aai.domain.yang.Service; import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.Tenant; import org.onap.aai.domain.yang.VfModule; import org.onap.aai.domain.yang.VolumeGroup; import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound; @@ -34,7 +36,6 @@ public class AAIDataRetrieval { }); } - public VfModule getAAIVfModule(String vnfId, String vfModuleId) { return this.getAaiResourcesClient() .get(VfModule.class, AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)) @@ -75,6 +76,24 @@ public class AAIDataRetrieval { }); } + public Service getService(String serviceId) { + return this.getAaiResourcesClient() + .get(Service.class, AAIUriFactory.createResourceUri(AAIObjectType.SERVICE, serviceId)).orElseGet(() -> { + logger.debug("No Service found in A&AI ServiceId: {}", serviceId); + return null; + }); + } + + public Tenant getTenant(String cloudOwner, String cloudRegion, String tenantId) { + return this.getAaiResourcesClient() + .get(Tenant.class, + AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegion, tenantId)) + .orElseGet(() -> { + logger.debug("No Tenant found in A&AI TenantId: {}", tenantId); + return null; + }); + } + protected AAIResourcesClient getAaiResourcesClient() { if (aaiResourcesClient == null) { aaiResourcesClient = new AAIResourcesClient(); |