Search in sources :

Example 1 with ModelInfo

use of org.onap.so.serviceinstancebeans.ModelInfo in project so by onap.

the class RequestHandlerUtilsTest method test_mapJSONtoMSOStyle.

@Test
public void test_mapJSONtoMSOStyle() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);
    String testRequest = inputStream("/ServiceInstanceDefault.json");
    String resultString = requestHandlerUtils.mapJSONtoMSOStyle(testRequest, null, false, null);
    ServiceInstancesRequest sir = mapper.readValue(resultString, ServiceInstancesRequest.class);
    ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
    assertEquals("f7ce78bb-423b-11e7-93f8-0050569a796", modelInfo.getModelCustomizationUuid());
    assertEquals("modelInstanceName", modelInfo.getModelInstanceName());
    assertEquals("f7ce78bb-423b-11e7-93f8-0050569a7965", modelInfo.getModelInvariantUuid());
    assertEquals("10", modelInfo.getModelUuid());
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) Test(org.junit.Test)

Example 2 with ModelInfo

use of org.onap.so.serviceinstancebeans.ModelInfo in project so by onap.

the class RequestHandlerUtilsTest method setServiceTypeTestDefault.

@Test
public void setServiceTypeTestDefault() throws JsonProcessingException {
    String requestScope = ModelType.service.toString();
    Boolean aLaCarteFlag = false;
    ServiceInstancesRequest sir = new ServiceInstancesRequest();
    RequestDetails requestDetails = new RequestDetails();
    RequestInfo requestInfo = new RequestInfo();
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
    requestInfo.setSource("VID");
    requestDetails.setModelInfo(modelInfo);
    requestDetails.setRequestInfo(requestInfo);
    sir.setRequestDetails(requestDetails);
    Service defaultService = new Service();
    defaultService.setServiceType("testServiceType");
    wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND)));
    wireMockServer.stubFor(get(urlMatching(".*/service/search/.*")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
    String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
    assertEquals(serviceType, "testServiceType");
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) Service(org.onap.so.db.catalog.beans.Service) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) Test(org.junit.Test)

Example 3 with ModelInfo

use of org.onap.so.serviceinstancebeans.ModelInfo in project so by onap.

the class RequestHandlerUtilsTest method setServiceTypeTest.

@Test
public void setServiceTypeTest() throws JsonProcessingException {
    String requestScope = ModelType.service.toString();
    Boolean aLaCarteFlag = false;
    ServiceInstancesRequest sir = new ServiceInstancesRequest();
    RequestDetails requestDetails = new RequestDetails();
    RequestInfo requestInfo = new RequestInfo();
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
    requestInfo.setSource("VID");
    requestDetails.setModelInfo(modelInfo);
    requestDetails.setRequestInfo(requestInfo);
    sir.setRequestDetails(requestDetails);
    Service defaultService = new Service();
    defaultService.setServiceType("testServiceType");
    wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
    String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
    assertEquals(serviceType, "testServiceType");
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) Service(org.onap.so.db.catalog.beans.Service) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) Test(org.junit.Test)

Example 4 with ModelInfo

use of org.onap.so.serviceinstancebeans.ModelInfo in project so by onap.

the class RelatedInstancesValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    ServiceInstancesRequest sir = info.getSir();
    Actions action = info.getAction();
    int reqVersion = info.getReqVersion();
    String requestScope = info.getRequestScope();
    String serviceInstanceType = null;
    String networkType = null;
    String vnfType = null;
    String vfModuleType = null;
    String vfModuleModelName = null;
    ModelInfo modelInfo = info.getSir().getRequestDetails().getModelInfo();
    RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
    String serviceModelName = null;
    String vnfModelName = null;
    String asdcServiceModelVersion = null;
    String volumeGroupId = null;
    boolean isRelatedServiceInstancePresent = false;
    boolean isRelatedVnfInstancePresent = false;
    boolean isSourceVnfPresent = false;
    boolean isDestinationVnfPresent = false;
    boolean isConnectionPointPresent = false;
    if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
        serviceInstanceType = modelInfo.getModelName();
        info.setServiceInstanceType(serviceInstanceType);
    }
    if (requestScope.equalsIgnoreCase(ModelType.network.name())) {
        networkType = modelInfo.getModelName();
        info.setNetworkType(networkType);
    }
    if (instanceList != null) {
        for (RelatedInstanceList relatedInstanceList : instanceList) {
            RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
            ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo();
            if (relatedInstanceModelInfo == null) {
                throw new ValidationException("modelInfo in relatedInstance");
            }
            if (relatedInstanceModelInfo.getModelType() == null) {
                throw new ValidationException("modelType in relatedInstance");
            }
            if (empty(relatedInstance.getInstanceName()) && ModelType.pnf.equals(relatedInstanceModelInfo.getModelType())) {
                throw new ValidationException("instanceName in relatedInstance for pnf modelType");
            }
            if (!empty(relatedInstance.getInstanceName())) {
                if (!relatedInstance.getInstanceName().matches(Constants.VALID_INSTANCE_NAME_FORMAT)) {
                    throw new ValidationException("instanceName format in relatedInstance");
                }
            }
            if (empty(relatedInstance.getInstanceId()) && !ModelType.pnf.equals(relatedInstanceModelInfo.getModelType())) {
                throw new ValidationException("instanceId in relatedInstance");
            }
            if (!empty(relatedInstance.getInstanceId()) && !UUIDChecker.isValidUUID(relatedInstance.getInstanceId())) {
                throw new ValidationException("instanceId format in relatedInstance");
            }
            if (empty(relatedInstanceModelInfo.getModelVersionId()) && requestScope.equals(ModelType.instanceGroup.toString()) && relatedInstanceModelInfo.getModelType().equals(ModelType.service)) {
                throw new ValidationException("modelVersionId in relatedInstance", true);
            }
            if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString()) && relatedInstanceModelInfo.getModelType().equals(ModelType.service)) {
                isRelatedServiceInstancePresent = true;
            }
            if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
                if (empty(relatedInstance.getInstanceName()) && ModelType.vpnBinding.equals(relatedInstanceModelInfo.getModelType())) {
                    throw new ValidationException("instanceName in relatedInstance for vpnBinding modelType", true);
                }
                if (empty(relatedInstance.getInstanceName()) && ModelType.network.equals(relatedInstanceModelInfo.getModelType())) {
                    throw new ValidationException("instanceName in relatedInstance for network modelType", true);
                }
            }
            if (action != Action.deleteInstance && !requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) {
                if (!(relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup) || relatedInstanceModelInfo.getModelType().equals(ModelType.connectionPoint) || relatedInstanceModelInfo.getModelType().equals(ModelType.pnf) || relatedInstanceModelInfo.getModelType().equals(ModelType.networkInstanceGroup) || relatedInstanceModelInfo.getModelType().equals(ModelType.network) || relatedInstanceModelInfo.getModelType().equals(ModelType.vpnBinding))) {
                    if (empty(relatedInstanceModelInfo.getModelInvariantId())) {
                        throw new ValidationException("modelInvariantId in relatedInstance");
                    } else if (reqVersion >= 4 && empty(relatedInstanceModelInfo.getModelVersionId())) {
                        throw new ValidationException("modelVersionId in relatedInstance");
                    } else if (empty(relatedInstanceModelInfo.getModelName())) {
                        throw new ValidationException("modelName in relatedInstance");
                    } else if (empty(relatedInstanceModelInfo.getModelVersion())) {
                        throw new ValidationException("modelVersion in relatedInstance");
                    }
                }
                if (!empty(relatedInstanceModelInfo.getModelInvariantId()) && !UUIDChecker.isValidUUID(relatedInstanceModelInfo.getModelInvariantId())) {
                    throw new ValidationException("modelInvariantId format in relatedInstance");
                }
                if (ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
                    if (InstanceDirection.source.equals(relatedInstance.getInstanceDirection()) && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) {
                        isSourceVnfPresent = true;
                    } else if (InstanceDirection.destination.equals(relatedInstance.getInstanceDirection()) && (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) || (relatedInstanceModelInfo.getModelType().equals(ModelType.pnf)))) {
                        isDestinationVnfPresent = true;
                    }
                }
                if (ModelType.connectionPoint.equals(relatedInstanceModelInfo.getModelType()) && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
                    isConnectionPointPresent = true;
                }
            }
            if (empty(relatedInstanceModelInfo.getModelCustomizationName()) && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) {
                if (reqVersion >= 4 && empty(relatedInstanceModelInfo.getModelCustomizationId()) && action != Action.deleteInstance) {
                    throw new ValidationException("modelCustomizationName or modelCustomizationId in relatedInstance of vnf");
                }
            }
            if (relatedInstanceModelInfo.getModelType().equals(ModelType.service) && !(requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString()) && action == Action.createInstance)) {
                isRelatedServiceInstancePresent = true;
                if (!relatedInstance.getInstanceId().equals(sir.getServiceInstanceId())) {
                    throw new ValidationException("serviceInstanceId matching the serviceInstanceId in request URI");
                }
                serviceModelName = relatedInstanceModelInfo.getModelName();
                asdcServiceModelVersion = relatedInstanceModelInfo.getModelVersion();
            } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) && !(ModelType.configuration.name().equalsIgnoreCase(requestScope))) {
                isRelatedVnfInstancePresent = true;
                if (!relatedInstance.getInstanceId().equals(sir.getVnfInstanceId())) {
                    throw new ValidationException("vnfInstanceId matching the vnfInstanceId in request URI");
                }
                vnfModelName = relatedInstanceModelInfo.getModelCustomizationName();
            } else if (relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup)) {
                volumeGroupId = relatedInstance.getInstanceId();
            }
        }
        if (action == Action.createInstance && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
            if (!isSourceVnfPresent) {
                throw new ValidationException("source vnf relatedInstance for Port Configuration");
            }
            if (!isDestinationVnfPresent) {
                throw new ValidationException("destination vnf relatedInstance for Port Configuration");
            }
        }
        if ((action == Action.enablePort || action == Action.disablePort) && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
            if (!isConnectionPointPresent) {
                throw new ValidationException("connectionPoint relatedInstance for Port Configuration");
            }
        }
        if (requestScope.equals(ModelType.instanceGroup.toString())) {
            if (!isRelatedServiceInstancePresent) {
                throw new ValidationException("related service instance for instanceGroup request", true);
            }
        }
        if (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())) {
            if (!isRelatedServiceInstancePresent) {
                throw new ValidationException("related service instance for volumeGroup request");
            }
            if (!isRelatedVnfInstancePresent) {
                throw new ValidationException("related vnf instance for volumeGroup request");
            }
            serviceInstanceType = serviceModelName;
            vnfType = serviceModelName + "/" + vnfModelName;
            info.setServiceInstanceType(serviceInstanceType);
            info.setVnfType(vnfType);
        } else if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) {
            if (!isRelatedServiceInstancePresent) {
                throw new ValidationException("related service instance for vfModule request");
            }
            if (!isRelatedVnfInstancePresent) {
                throw new ValidationException("related vnf instance for vfModule request");
            }
            vfModuleModelName = modelInfo.getModelName();
            serviceInstanceType = serviceModelName;
            vnfType = serviceModelName + "/" + vnfModelName;
            vfModuleType = vnfType + "::" + vfModuleModelName;
            sir.setVolumeGroupInstanceId(volumeGroupId);
            info.setVfModuleModelName(vfModuleModelName);
            info.setVnfType(vnfType);
            info.setServiceInstanceType(serviceInstanceType);
            info.setVfModuleType(vfModuleType);
        } else if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
            if (!isRelatedServiceInstancePresent) {
                throw new ValidationException("related service instance for vnf request");
            }
            vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName();
            info.setVnfType(vnfType);
        }
    } else if (((requestScope.equalsIgnoreCase(ModelType.vnf.name()) || requestScope.equalsIgnoreCase(ModelType.volumeGroup.name()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name()) || requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.createInstance || action == Action.enablePort || action == Action.disablePort)) || (reqVersion >= 4 && (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name())) && action == Action.updateInstance || (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)) || (requestScope.equalsIgnoreCase(ModelType.service.name()) && (action.equals(Action.addRelationships) || action.equals(Action.removeRelationships)))) {
        logger.debug("related instance exception");
        throw new ValidationException("related instances");
    }
    if (instanceList == null && requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString()) && action == Action.createInstance) {
        throw new ValidationException("relatedInstanceList", true);
    }
    info.setVfModuleModelName(vfModuleModelName);
    info.setServiceInstanceType(serviceInstanceType);
    info.setVnfType(vnfType);
    info.setAsdcServiceModelVersion(asdcServiceModelVersion);
    info.setVfModuleType(vfModuleType);
    return info;
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ValidationException(org.onap.so.exceptions.ValidationException) Actions(org.onap.so.apihandlerinfra.Actions) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest)

Example 5 with ModelInfo

use of org.onap.so.serviceinstancebeans.ModelInfo in project so by onap.

the class ServiceInstancesTest method setServiceTypeTestNetwork.

@Test
public void setServiceTypeTestNetwork() throws JsonProcessingException {
    String requestScope = ModelType.network.toString();
    Boolean aLaCarteFlag = null;
    ServiceInstancesRequest sir = new ServiceInstancesRequest();
    RequestDetails requestDetails = new RequestDetails();
    RequestInfo requestInfo = new RequestInfo();
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setModelName("networkModelName");
    requestInfo.setSource("VID");
    requestDetails.setModelInfo(modelInfo);
    requestDetails.setRequestInfo(requestInfo);
    sir.setRequestDetails(requestDetails);
    String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
    assertEquals(serviceType, "networkModelName");
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) Test(org.junit.Test)

Aggregations

ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)84 Test (org.junit.Test)46 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)35 Service (org.onap.so.db.catalog.beans.Service)30 HashMap (java.util.HashMap)18 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)18 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)17 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)17 RelatedInstanceList (org.onap.so.serviceinstancebeans.RelatedInstanceList)15 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)14 RelatedInstance (org.onap.so.serviceinstancebeans.RelatedInstance)14 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)14 VnfResourceCustomization (org.onap.so.db.catalog.beans.VnfResourceCustomization)12 RequestInfo (org.onap.so.serviceinstancebeans.RequestInfo)12 ServiceModel (org.onap.so.bpmn.servicedecomposition.entities.ServiceModel)11 CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)11 File (java.io.File)10 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)10 VolumeGroup (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup)10 ModelInfoGenericVnf (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf)10