Search in sources :

Example 1 with VnfRecipe

use of org.onap.so.db.catalog.beans.VnfRecipe in project so by onap.

the class VnfRestHandler method findVnfModuleRecipe.

public Recipe findVnfModuleRecipe(String modelCustomizationId, String modelType, String action) {
    VnfRecipe recipe = new VnfRecipe();
    recipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
    return recipe;
}
Also used : VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe)

Example 2 with VnfRecipe

use of org.onap.so.db.catalog.beans.VnfRecipe in project so by onap.

the class CatalogDbClient method postVnfRecipe.

public void postVnfRecipe(VnfRecipe recipe) {
    try {
        HttpHeaders headers = getHttpHeaders();
        HttpEntity<VnfRecipe> entity = new HttpEntity<>(recipe, headers);
        restTemplate.exchange(UriComponentsBuilder.fromUriString(endpoint + "/vnfRecipe").build().encode().toString(), HttpMethod.POST, entity, VnfRecipe.class).getBody();
    } catch (HttpClientErrorException e) {
        if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
            throw new EntityNotFoundException("Unable to find VnfRecipe with  Id: " + recipe.getId());
        }
        throw e;
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 3 with VnfRecipe

use of org.onap.so.db.catalog.beans.VnfRecipe in project so by onap.

the class RequestHandlerUtils method getDefaultVnfUri.

private RecipeLookupResult getDefaultVnfUri(ServiceInstancesRequest sir, Actions action) {
    String defaultSource = getDefaultModel(sir);
    VnfRecipe vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString());
    if (vnfRecipe == null) {
        return null;
    }
    return new RecipeLookupResult(vnfRecipe.getOrchestrationUri(), vnfRecipe.getRecipeTimeout());
}
Also used : VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe)

Example 4 with VnfRecipe

use of org.onap.so.db.catalog.beans.VnfRecipe in project so by onap.

the class RequestHandlerUtils method getVnfOrVfModuleUri.

private RecipeLookupResult getVnfOrVfModuleUri(ServiceInstancesRequest servInstReq, Actions action) throws ValidationException {
    ModelInfo modelInfo = servInstReq.getRequestDetails().getModelInfo();
    String vnfComponentType = modelInfo.getModelType().name();
    RelatedInstanceList[] instanceList = null;
    if (servInstReq.getRequestDetails() != null) {
        instanceList = servInstReq.getRequestDetails().getRelatedInstanceList();
    }
    Recipe recipe;
    String defaultSource = getDefaultModel(servInstReq);
    String modelCustomizationId = modelInfo.getModelCustomizationId();
    String modelCustomizationName = modelInfo.getModelCustomizationName();
    String relatedInstanceModelVersionId = null;
    String relatedInstanceModelInvariantId = null;
    String relatedInstanceVersion = null;
    String relatedInstanceModelCustomizationName = null;
    if (instanceList != null) {
        for (RelatedInstanceList relatedInstanceList : instanceList) {
            RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
            ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo();
            if (relatedInstanceModelInfo.getModelType().equals(ModelType.service)) {
                relatedInstanceModelVersionId = relatedInstanceModelInfo.getModelVersionId();
                relatedInstanceVersion = relatedInstanceModelInfo.getModelVersion();
            }
            if (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) {
                relatedInstanceModelVersionId = relatedInstanceModelInfo.getModelVersionId();
                relatedInstanceModelInvariantId = relatedInstanceModelInfo.getModelInvariantId();
                relatedInstanceVersion = relatedInstanceModelInfo.getModelVersion();
                relatedInstanceModelCustomizationName = relatedInstanceModelInfo.getModelCustomizationName();
            }
        }
        if (modelInfo.getModelType().equals(ModelType.vnf)) {
            // a. For a vnf request (only create, no update currently):
            // i. (v3-v4) If modelInfo.modelCustomizationId is provided, use it to validate catalog DB has record in
            // vnf_resource_customization.model_customization_uuid.
            // ii. (v2-v4) If modelInfo.modelCustomizationId is NOT provided (because it is a pre-1702 ASDC model or
            // pre-v3), then modelInfo.modelCustomizationName must have
            // been provided (else create request should be rejected). APIH should use the
            // relatedInstance.modelInfo[service].modelVersionId** + modelInfo[vnf].modelCustomizationName
            // to “join�? service_to_resource_customizations with vnf_resource_customization to confirm a
            // vnf_resource_customization.model_customization_uuid record exists.
            // **If relatedInstance.modelInfo[service].modelVersionId was not provided, use
            // relatedInstance.modelInfo[service].modelInvariantId + modelVersion instead to lookup modelVersionId
            // (MODEL_UUID) in SERVICE table.
            // iii. Regardless of how the value was provided/obtained above, APIH must always populate
            // vnfModelCustomizationId in bpmnRequest. It would be assumed it was MSO generated
            // during 1707 data migration if VID did not provide it originally on request.
            // iv. Note: continue to construct the “vnf-type�? value and pass to BPMN (must still be populated
            // in A&AI).
            // 1. If modelCustomizationName is NOT provided on a vnf/vfModule request, use modelCustomizationId to
            // look it up in our catalog to construct vnf-type value to pass to BPMN.
            VnfResource vnfResource = null;
            VnfResourceCustomization vrc = null;
            if (modelCustomizationId != null) {
                vrc = catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(modelCustomizationId);
                if (vrc != null) {
                    vnfResource = vrc.getVnfResources();
                }
            } else {
                org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(relatedInstanceModelVersionId);
                if (service == null) {
                    service = catalogDbClient.getServiceByModelVersionAndModelInvariantUUID(relatedInstanceVersion, relatedInstanceModelInvariantId);
                }
                if (service == null) {
                    throw new ValidationException("service in relatedInstance");
                }
                for (VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()) {
                    if (vnfResourceCustom.getModelInstanceName().equals(modelCustomizationName)) {
                        vrc = vnfResourceCustom;
                    }
                }
                if (vrc != null) {
                    vnfResource = vrc.getVnfResources();
                    modelInfo.setModelCustomizationId(vrc.getModelCustomizationUUID());
                    modelInfo.setModelCustomizationUuid(vrc.getModelCustomizationUUID());
                }
            }
            if (vnfResource == null) {
                throw new ValidationException("vnfResource");
            } else {
                if (modelInfo.getModelVersionId() == null) {
                    modelInfo.setModelVersionId(vnfResource.getModelUUID());
                }
            }
            VnfRecipe vnfRecipe = null;
            if (vrc != null) {
                String nfRole = vrc.getNfRole();
                if (nfRole != null) {
                    vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(vrc.getNfRole(), action.toString());
                }
            }
            if (vnfRecipe == null) {
                vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString());
            }
            if (vnfRecipe == null) {
                return null;
            }
            return new RecipeLookupResult(vnfRecipe.getOrchestrationUri(), vnfRecipe.getRecipeTimeout());
        } else {
            /*
                 * (v5-v7) If modelInfo.modelCustomizationId is NOT provided (because it is a pre-1702 ASDC model or
                 * pre-v3), then modelInfo.modelCustomizationName must have // been provided (else create request should
                 * be rejected). APIH should use the relatedInstance.modelInfo[vnf].modelVersionId +
                 * modelInfo[vnf].modelCustomizationName // to join vnf_to_resource_customizations with
                 * vf_resource_customization to confirm a vf_resource_customization.model_customization_uuid record
                 * exists. // Once the vnfs model_customization_uuid has been obtained, use it to find all vfModule
                 * customizations for that vnf customization in the vnf_res_custom_to_vf_module_custom join table. //
                 * For each vf_module_cust_model_customization_uuid value returned, use that UUID to query
                 * vf_module_customization table along with modelInfo[vfModule|volumeGroup].modelVersionId to // confirm
                 * record matches request data (and to identify the modelCustomizationId associated with the vfModule in
                 * the request). This means taking each record found // in vf_module_customization and looking up in
                 * vf_module (using vf_module_customization’s FK into vf_module) to find a match on
                 * MODEL_INVARIANT_UUID (modelInvariantId) // and MODEL_VERSION (modelVersion).
                 */
            VfModuleCustomization vfmc = null;
            VnfResource vnfr;
            VnfResourceCustomization vnfrc;
            VfModule vfModule = null;
            if (modelInfo.getModelCustomizationId() != null) {
                vfmc = catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(modelInfo.getModelCustomizationId());
            } else {
                vnfr = catalogDbClient.getVnfResourceByModelUUID(relatedInstanceModelVersionId);
                if (vnfr == null) {
                    vnfr = catalogDbClient.getFirstVnfResourceByModelInvariantUUIDAndModelVersion(relatedInstanceModelInvariantId, relatedInstanceVersion);
                }
                vnfrc = catalogDbClient.getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources(relatedInstanceModelCustomizationName, vnfr);
                List<VfModuleCustomization> list = vnfrc.getVfModuleCustomizations();
                String vfModuleModelUUID = modelInfo.getModelVersionId();
                for (VfModuleCustomization vf : list) {
                    VfModuleCustomization vfmCustom;
                    if (vfModuleModelUUID != null) {
                        vfmCustom = catalogDbClient.getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(vf.getModelCustomizationUUID(), vfModuleModelUUID);
                        if (vfmCustom != null) {
                            vfModule = vfmCustom.getVfModule();
                        }
                    } else {
                        vfmCustom = catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(vf.getModelCustomizationUUID());
                        if (vfmCustom != null) {
                            vfModule = vfmCustom.getVfModule();
                        } else {
                            vfModule = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(relatedInstanceModelInvariantId, relatedInstanceVersion);
                        }
                    }
                    if (vfModule != null) {
                        modelInfo.setModelCustomizationId(vf.getModelCustomizationUUID());
                        modelInfo.setModelCustomizationUuid(vf.getModelCustomizationUUID());
                        break;
                    }
                }
            }
            if (vfmc == null && vfModule == null) {
                throw new ValidationException("vfModuleCustomization");
            } else if (vfModule == null && vfmc != null) {
                // can't be null as vfModuleModelUUID is not-null property in
                vfModule = vfmc.getVfModule();
            // VfModuleCustomization table
            }
            if (modelInfo.getModelVersionId() == null) {
                modelInfo.setModelVersionId(vfModule.getModelUUID());
            }
            recipe = catalogDbClient.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(vfModule.getModelUUID(), vnfComponentType, action.toString());
            if (recipe == null) {
                List<VfModule> vfModuleRecords = catalogDbClient.getVfModuleByModelInvariantUUIDOrderByModelVersionDesc(vfModule.getModelInvariantUUID());
                if (!vfModuleRecords.isEmpty()) {
                    for (VfModule record : vfModuleRecords) {
                        recipe = catalogDbClient.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(record.getModelUUID(), vnfComponentType, action.toString());
                        if (recipe != null) {
                            break;
                        }
                    }
                }
            }
            if (recipe == null) {
                recipe = catalogDbClient.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(defaultSource, vnfComponentType, action.toString());
                if (recipe == null) {
                    recipe = catalogDbClient.getFirstVnfComponentsRecipeByVnfComponentTypeAndAction(vnfComponentType, action.toString());
                }
                if (recipe == null) {
                    return null;
                }
            }
        }
    } else {
        if (modelInfo.getModelType().equals(ModelType.vnf)) {
            recipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString());
            if (recipe == null) {
                return null;
            }
        } else {
            recipe = catalogDbClient.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(defaultSource, vnfComponentType, action.toString());
            if (recipe == null) {
                return null;
            }
        }
    }
    return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout());
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ValidationException(org.onap.so.exceptions.ValidationException) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) Recipe(org.onap.so.db.catalog.beans.Recipe) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) VfModule(org.onap.so.db.catalog.beans.VfModule) VnfResource(org.onap.so.db.catalog.beans.VnfResource) VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization)

Example 5 with VnfRecipe

use of org.onap.so.db.catalog.beans.VnfRecipe in project so by onap.

the class CatalogDbClientTest method testGetFirstVnfRecipeByNfRoleAndAction.

@Test
public void testGetFirstVnfRecipeByNfRoleAndAction() {
    VnfRecipe vnfRecipe = client.getFirstVnfRecipeByNfRoleAndAction("GR-API-DEFAULT", "createInstance");
    assertNotNull(vnfRecipe);
    assertNotNull(vnfRecipe.getNfRole());
    assertNotNull(vnfRecipe.getAction());
    assertEquals("Gr api recipe to create vnf", vnfRecipe.getDescription());
    assertEquals("/mso/async/services/WorkflowActionBB", vnfRecipe.getOrchestrationUri());
}
Also used : VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

Aggregations

VnfRecipe (org.onap.so.db.catalog.beans.VnfRecipe)7 Test (org.junit.Test)3 CatalogDbAdapterBaseTest (org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 ArRecipe (org.onap.so.db.catalog.beans.ArRecipe)1 NetworkRecipe (org.onap.so.db.catalog.beans.NetworkRecipe)1 Recipe (org.onap.so.db.catalog.beans.Recipe)1 ServiceRecipe (org.onap.so.db.catalog.beans.ServiceRecipe)1 VfModule (org.onap.so.db.catalog.beans.VfModule)1 VfModuleCustomization (org.onap.so.db.catalog.beans.VfModuleCustomization)1 VnfResource (org.onap.so.db.catalog.beans.VnfResource)1 VnfResourceCustomization (org.onap.so.db.catalog.beans.VnfResourceCustomization)1 ValidationException (org.onap.so.exceptions.ValidationException)1 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)1 RelatedInstance (org.onap.so.serviceinstancebeans.RelatedInstance)1 RelatedInstanceList (org.onap.so.serviceinstancebeans.RelatedInstanceList)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1