use of org.onap.so.apihandler.common.RequestClientParameter in project so by onap.
the class ResumeOrchestrationRequest method setRequestClientParameter.
protected RequestClientParameter setRequestClientParameter(RecipeLookupResult recipeLookupResult, String version, InfraActiveRequests infraActiveRequest, InfraActiveRequests currentActiveRequest, String pnfCorrelationId, Boolean aLaCarte, ServiceInstancesRequest sir) throws ApiException {
RequestClientParameter requestClientParameter = null;
Action action = Action.valueOf(infraActiveRequest.getRequestAction());
ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
Boolean isBaseVfModule = false;
if (requestHandlerUtils.getModelType(action, modelInfo).equals(ModelType.vfModule)) {
isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, infraActiveRequest.getVnfType(), msoRequest.getSDCServiceModelVersion(sir), currentActiveRequest);
}
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())).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 = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
throw new ValidateException.Builder("IOException while generating requestClientParameter to send to BPMN: " + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
}
return requestClientParameter;
}
use of org.onap.so.apihandler.common.RequestClientParameter 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.apihandler.common.RequestClientParameter 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);
}
use of org.onap.so.apihandler.common.RequestClientParameter in project so by onap.
the class ServiceInstances method deleteInstanceGroups.
/**
* This method deletes the Instance Groups.
*
* This method will check whether the request is not duplicate in requestdb. if its not then will save as a new
* request. And will send a POST request to BEPL client to delete the Insatnce Groups.
*
* @param action
* @param instanceIdMap
* @param version
* @param requestId
* @param requestUri
* @param requestContext
* @return
* @throws ApiException
*/
public Response deleteInstanceGroups(Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, ContainerRequestContext requestContext) throws ApiException {
String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID);
Boolean aLaCarte = true;
String apiVersion = version.substring(1);
ServiceInstancesRequest sir = new ServiceInstancesRequest();
sir.setInstanceGroupId(instanceGroupId);
String requestScope = ModelType.instanceGroup.toString();
InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, null, requestScope);
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
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.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null);
ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
RequestReferences referencesResponse = new RequestReferences();
referencesResponse.setRequestId(requestId);
serviceResponse.setRequestReferences(referencesResponse);
Boolean isBaseVfModule = false;
RecipeLookupResult recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
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();
}
RequestClientParameter requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
use of org.onap.so.apihandler.common.RequestClientParameter in project so by onap.
the class ResumeOrchestrationRequestTest method setRequestClientParameterTest.
@Test
public void setRequestClientParameterTest() throws ApiException, IOException {
doReturn(ModelType.service).when(requestHandler).getModelType(action, modelInfo);
when(requestHandler.mapJSONtoMSOStyle(anyString(), any(ServiceInstancesRequest.class), anyBoolean(), any(Action.class))).thenReturn(requestBody);
RequestClientParameter result = resumeReq.setRequestClientParameter(lookupResult, version, infraActiveRequest, currentActiveRequest, "pnfCorrelationId", aLaCarte, sir);
assertThat(requestClientParameter, sameBeanAs(result));
}
Aggregations