use of org.onap.so.serviceinstancebeans.ModelType 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.serviceinstancebeans.ModelType in project so by onap.
the class MembersValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
RelatedInstanceList[] relatedInstanceList = info.getSir().getRequestDetails().getRelatedInstanceList();
boolean vnfRelatedInstance = false;
if (requestInfo == null) {
throw new ValidationException("requestInfo", true);
} else if (empty(requestInfo.getRequestorId())) {
throw new ValidationException("requestorId", true);
} else if (empty(requestInfo.getSource())) {
throw new ValidationException("source", true);
}
if (relatedInstanceList == null) {
throw new ValidationException("related instances", true);
} else {
for (RelatedInstanceList instanceList : relatedInstanceList) {
RelatedInstance relatedInstance = instanceList.getRelatedInstance();
ModelType modelType = relatedInstance.getModelInfo().getModelType();
if (empty(relatedInstance.getInstanceId())) {
throw new ValidationException("instanceId in relatedInstances", true);
}
if (modelType == null) {
throw new ValidationException("modelType in relatedInstance", true);
}
if (modelType == ModelType.vnf) {
vnfRelatedInstance = true;
}
}
if (!vnfRelatedInstance) {
throw new ValidationException("vnf relatedInstance", true);
}
}
return info;
}
use of org.onap.so.serviceinstancebeans.ModelType in project so by onap.
the class RequestHandlerUtilsUnitTest method getModelTypeRemoveMembersTest.
@Test
public void getModelTypeRemoveMembersTest() throws ApiException {
ModelType modelTypeExpected = ModelType.instanceGroup;
ModelType modelTypeResult = requestHandler.getModelType(Action.removeMembers, null);
assertEquals(modelTypeResult, modelTypeExpected);
}
use of org.onap.so.serviceinstancebeans.ModelType in project so by onap.
the class RequestHandlerUtilsUnitTest method getModelTypeTest.
@Test
public void getModelTypeTest() throws ApiException {
ModelType modelTypeExpected = ModelType.service;
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelType(ModelType.service);
ModelType modelTypeResult = requestHandler.getModelType(Action.createInstance, modelInfo);
assertEquals(modelTypeResult, modelTypeExpected);
}
use of org.onap.so.serviceinstancebeans.ModelType in project so by onap.
the class RequestHandlerUtilsUnitTest method getModelTypeApplyUpdatedConfigTest.
@Test
public void getModelTypeApplyUpdatedConfigTest() throws ApiException {
ModelType modelTypeExpected = ModelType.vnf;
ModelType modelTypeResult = requestHandler.getModelType(Action.applyUpdatedConfig, null);
assertEquals(modelTypeResult, modelTypeExpected);
}
Aggregations