Search in sources :

Example 6 with ModelType

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);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) BpmnRequestBuilder(org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder) IOException(java.io.IOException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) IOException(java.io.IOException) CloudConfigurationNotFoundException(org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) ModelType(org.onap.so.serviceinstancebeans.ModelType) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

Example 7 with ModelType

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;
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ModelType(org.onap.so.serviceinstancebeans.ModelType) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo)

Example 8 with ModelType

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);
}
Also used : ModelType(org.onap.so.serviceinstancebeans.ModelType) Test(org.junit.Test)

Example 9 with ModelType

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);
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ModelType(org.onap.so.serviceinstancebeans.ModelType) Test(org.junit.Test)

Example 10 with ModelType

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);
}
Also used : ModelType(org.onap.so.serviceinstancebeans.ModelType) Test(org.junit.Test)

Aggregations

ModelType (org.onap.so.serviceinstancebeans.ModelType)12 Test (org.junit.Test)5 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)3 ValidationException (org.onap.so.exceptions.ValidationException)2 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)1 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)1 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)1 BpmnRequestBuilder (org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder)1 CloudConfigurationNotFoundException (org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException)1 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)1 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)1 CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)1 RelatedInstance (org.onap.so.serviceinstancebeans.RelatedInstance)1 RelatedInstanceList (org.onap.so.serviceinstancebeans.RelatedInstanceList)1 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)1 RequestInfo (org.onap.so.serviceinstancebeans.RequestInfo)1 RequestReferences (org.onap.so.serviceinstancebeans.RequestReferences)1