use of org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2ESliceServiceActivateRequest in project so by onap.
the class E2EServiceInstances method Activate5GSliceServiceInstances.
private Response Activate5GSliceServiceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException {
// TODO should be a new one or the same service instance Id
E2ESliceServiceActivateRequest e2eActReq;
ObjectMapper mapper = new ObjectMapper();
try {
e2eActReq = mapper.readValue(requestJSON, E2ESliceServiceActivateRequest.class);
} catch (Exception e) {
logger.debug("Mapping of request to JSON object failed : ", e);
Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
String requestId = UUID.randomUUID().toString();
RecipeLookupResult recipeLookupResult;
try {
// TODO Get the service template model version uuid from AAI.
String modelVersionId = null;
AAIResourcesClient client = new AAIResourcesClient();
AAIResourceUri url = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(e2eActReq.getGlobalSubscriberId()).serviceSubscription(e2eActReq.getServiceType()).serviceInstance(instanceIdMap.get(SERVICE_ID)));
Optional<ServiceInstance> serviceInstanceOpt = client.get(ServiceInstance.class, url);
if (serviceInstanceOpt.isPresent()) {
modelVersionId = serviceInstanceOpt.get().getModelVersionId();
}
recipeLookupResult = getServiceInstanceOrchestrationURI(modelVersionId, action);
} catch (Exception e) {
logger.error(MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);
Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON, null, null);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
if (recipeLookupResult == null) {
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");
Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action, ModelType.service.name(), requestJSON, null, null);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
String bpmnRequest = null;
RequestClientParameter postParam = null;
try {
JSONObject jjo = new JSONObject(requestJSON);
jjo.put("operationId", requestId);
bpmnRequest = jjo.toString();
String serviceId = instanceIdMap.get(SERVICE_ID);
String operationType = instanceIdMap.get("operationType");
String serviceInstanceType = e2eActReq.getServiceType();
postParam = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceId).setOperationType(operationType).setServiceType(serviceInstanceType).setRequestDetails(bpmnRequest).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
} catch (Exception e) {
Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communicate with BPMN engine");
logger.debug("End of the transaction, the final response is: " + resp.getEntity());
return resp;
}
return postRequest(recipeLookupResult.getOrchestrationURI(), postParam, version);
}
Aggregations