use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class E2EServiceInstances method mapReqJsonToSvcInstReq.
/**
* Converting E2EServiceInstanceRequest to ServiceInstanceRequest and passing it to camunda engine.
*
* @param e2eSir
* @return
*/
private ServiceInstancesRequest mapReqJsonToSvcInstReq(E2EServiceInstanceRequest e2eSir, String requestJSON) {
ServiceInstancesRequest sir = new ServiceInstancesRequest();
RequestDetails requestDetails = new RequestDetails();
ModelInfo modelInfo = new ModelInfo();
// ModelInvariantId
modelInfo.setModelInvariantId(e2eSir.getService().getServiceInvariantUuid());
// modelNameVersionId
modelInfo.setModelNameVersionId(e2eSir.getService().getServiceUuid());
// String modelInfoValue =
// e2eSir.getService().getParameters().getNodeTemplateName();
// String[] arrayOfInfo = modelInfoValue.split(":");
// String modelName = arrayOfInfo[0];
// String modelVersion = arrayOfInfo[1];
// TODO: To ensure, if we dont get the values from the UUI
String modelName = "voLTE";
String modelVersion = "1.0";
// modelName
modelInfo.setModelName(modelName);
// modelVersion
modelInfo.setModelVersion(modelVersion);
// modelType
modelInfo.setModelType(ModelType.service);
// setting modelInfo to requestDetails
requestDetails.setModelInfo(modelInfo);
SubscriberInfo subscriberInfo = new SubscriberInfo();
// globalsubscriberId
subscriberInfo.setGlobalSubscriberId(e2eSir.getService().getGlobalSubscriberId());
// setting subscriberInfo to requestDetails
requestDetails.setSubscriberInfo(subscriberInfo);
RequestInfo requestInfo = new RequestInfo();
// instanceName
requestInfo.setInstanceName(e2eSir.getService().getName());
// source
requestInfo.setSource("UUI");
// suppressRollback
requestInfo.setSuppressRollback(true);
// setting requestInfo to requestDetails
requestDetails.setRequestInfo(requestInfo);
RequestParameters requestParameters = new RequestParameters();
// subscriptionServiceType
requestParameters.setSubscriptionServiceType("MOG");
List<Map<String, Object>> userParamList = new ArrayList<>();
Map<String, Object> userParamMap = new HashMap<>();
// complete json request updated in the camunda
userParamMap.put("UUIRequest", requestJSON);
userParamMap.put("ServiceInstanceName", e2eSir.getService().getName());
userParamList.add(userParamMap);
requestParameters.setUserParams(userParamList);
// setting requestParameters to requestDetails
requestDetails.setRequestParameters(requestParameters);
sir.setRequestDetails(requestDetails);
return sir;
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class InstanceManagement method processCustomWorkflowRequest.
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);
if (instanceIdMap != null && !instanceIdMap.isEmpty()) {
pnfName = instanceIdMap.get("pnfName");
workflowUuid = instanceIdMap.get("workflowUuid");
vnfInstanceId = instanceIdMap.get("vnfInstanceId");
svcInstanceId = instanceIdMap.get("serviceInstanceId");
}
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) {
LOG.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(svcInsReq, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
vnfType = msoRequest.getVnfType(svcInsReq, requestScope);
currentActiveReq.setVnfType(vnfType);
}
checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq);
final 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(svcInstanceId).setVnfId(vnfInstanceId).setVnfType(vnfType).setPnfCorrelationId(pnfName).setApiVersion(apiVersion).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action)).setALaCarte(aLaCarte).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);
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class OrchestrationRequests method unlockOrchestrationRequest.
@POST
@Path("/{version: [vV][4-7]}/{requestId}/unlock")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Unlock Orchestrated Requests for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response unlockOrchestrationRequest(String requestJSON, @PathParam("requestId") String requestId, @PathParam("version") String version) throws ApiException {
logger.debug("requestId is: {}", requestId);
ServiceInstancesRequest sir;
try {
ObjectMapper mapper = new ObjectMapper();
sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
} catch (IOException e) {
logger.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
try {
msoRequest.parseOrchestration(sir);
} catch (Exception e) {
logger.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder("Error parsing request: " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
InfraActiveRequests infraActiveRequest = infraActiveRequestLookup(requestId);
String status = infraActiveRequest.getRequestStatus();
if (Status.IN_PROGRESS.toString().equalsIgnoreCase(status) || Status.PENDING.toString().equalsIgnoreCase(status) || Status.PENDING_MANUAL_TASK.toString().equalsIgnoreCase(status)) {
infraActiveRequest.setRequestStatus(Status.UNLOCKED.toString());
infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
infraActiveRequest.setRequestId(requestId);
requestsDbClient.save(infraActiveRequest);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
}
return Response.status(HttpStatus.SC_NO_CONTENT).entity("").build();
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class ServiceInstances method configurationRecipeLookup.
private Response configurationRecipeLookup(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri) throws ApiException {
String serviceInstanceId;
Boolean aLaCarte = null;
String apiVersion = version.substring(1);
ServiceInstancesRequest sir;
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);
if (sir.getRequestDetails().getRequestParameters() != null) {
aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
}
requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
RequestReferences referencesResponse = new RequestReferences();
referencesResponse.setRequestId(requestId);
serviceResponse.setRequestReferences(referencesResponse);
String orchestrationUri = env.getProperty(CommonConstants.ALACARTE_ORCHESTRATION);
String timeOut = env.getProperty(CommonConstants.ALACARTE_RECIPE_TIMEOUT);
if (StringUtils.isBlank(orchestrationUri) || StringUtils.isBlank(timeOut)) {
String error = StringUtils.isBlank(orchestrationUri) ? "ALaCarte Orchestration URI not found in properties" : "ALaCarte Recipe Timeout not found in properties";
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
ValidateException validateException = new ValidateException.Builder(error, HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
throw validateException;
}
serviceInstanceId = "";
String configurationId = "";
String pnfCorrelationId = "";
if (sir.getServiceInstanceId() != null) {
serviceInstanceId = sir.getServiceInstanceId();
}
if (sir.getConfigurationId() != null) {
configurationId = sir.getConfigurationId();
}
pnfCorrelationId = getPnfCorrelationId(sir);
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();
}
if (!requestScope.equalsIgnoreCase(ModelType.service.name())) {
aLaCarte = true;
} else if (aLaCarte == null) {
aLaCarte = false;
}
RequestClientParameter requestClientParameter = null;
try {
requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(Integer.parseInt(timeOut)).setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfCorrelationId).setConfigurationId(configurationId).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, sir, aLaCarte, action)).setApiVersion(apiVersion).setALaCarte(aLaCarte).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, orchestrationUri, requestScope);
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class ServiceInstances method serviceInstances.
public Response serviceInstances(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, HashMap<String, String> queryParams) throws ApiException {
String serviceInstanceId;
Boolean aLaCarte = null;
ServiceInstancesRequest sir;
String apiVersion = version.substring(1);
sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
action = handleReplaceInstance(action, sir);
String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
try {
requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
} catch (ApiException e) {
msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope, requestJSON, requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null), sir);
throw e;
}
InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
if (sir.getRequestDetails().getRequestParameters() != null) {
aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
}
requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
if ((action == Action.replaceInstance || action == Action.replaceInstanceRetainAssignments) && (requestScope.equals(ModelType.vnf.toString()) || requestScope.equals(ModelType.vfModule.toString())) && sir.getRequestDetails().getCloudConfiguration() == null) {
CloudConfiguration cloudConfiguration = getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveReq);
sir.getRequestDetails().setCloudConfiguration(cloudConfiguration);
setCloudConfigurationCurrentActiveRequest(cloudConfiguration, currentActiveReq);
}
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
String instanceName = null;
if (sir.getRequestDetails().getRequestInfo() != null) {
instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
}
boolean alaCarteFlag = msoRequest.getAlacarteFlag(sir);
String vnfType = msoRequest.getVnfType(sir, requestScope);
String networkType = msoRequest.getNetworkType(sir, requestScope);
String sdcServiceModelVersion = msoRequest.getSDCServiceModelVersion(sir);
String vfModuleType = msoRequest.getVfModuleType(sir, requestScope);
if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) {
currentActiveReq.setVnfType(vnfType);
} else if (requestScope.equalsIgnoreCase(ModelType.network.name()) && networkType != null) {
currentActiveReq.setNetworkType(networkType);
}
requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
RequestReferences referencesResponse = new RequestReferences();
referencesResponse.setRequestId(requestId);
serviceResponse.setRequestReferences(referencesResponse);
RecipeLookupResult recipeLookupResult = requestHandlerUtils.getServiceInstanceOrchestrationURI(sir, action, alaCarteFlag, currentActiveReq);
String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, alaCarteFlag);
ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
ModelType modelType = requestHandlerUtils.getModelType(action, modelInfo);
Boolean isBaseVfModule = false;
if (modelType.equals(ModelType.vfModule)) {
isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, currentActiveReq);
}
serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir);
String vnfId = "";
String vfModuleId = "";
String volumeGroupId = "";
String networkId = "";
String pnfCorrelationId = "";
String instanceGroupId = null;
if (sir.getVnfInstanceId() != null) {
vnfId = sir.getVnfInstanceId();
}
if (sir.getVfModuleInstanceId() != null) {
vfModuleId = sir.getVfModuleInstanceId();
}
if (sir.getVolumeGroupInstanceId() != null) {
volumeGroupId = sir.getVolumeGroupInstanceId();
}
if (sir.getNetworkInstanceId() != null) {
networkId = sir.getNetworkInstanceId();
}
if (sir.getInstanceGroupId() != null) {
instanceGroupId = sir.getInstanceGroupId();
}
pnfCorrelationId = getPnfCorrelationId(sir);
try {
infraActiveRequestsClient.save(currentActiveReq);
} catch (Exception e) {
logger.error("Exception occurred", 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();
}
if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance && !requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
aLaCarte = true;
} else if (aLaCarte == null) {
aLaCarte = false;
}
RequestClientParameter requestClientParameter;
try {
requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfCorrelationId).setVnfId(vnfId).setVfModuleId(vfModuleId).setVolumeGroupId(volumeGroupId).setNetworkId(networkId).setServiceType(serviceInstanceType).setVnfType(vnfType).setVfModuleType(vfModuleType).setNetworkType(networkType).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, sir, aLaCarte, action)).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
} catch (IOException e) {
logger.error("Exception occurred", 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);
}
Aggregations