Search in sources :

Example 11 with VnfResourceCustomization

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

the class CatalogDbClientTest method testFindVnfResourceCustomizationInListNullString.

@Test
public final void testFindVnfResourceCustomizationInListNullString() {
    thrown.expect(EntityNotFoundException.class);
    thrown.expectMessage("a NULL UUID was provided in query to search for VnfResourceCustomization");
    String vnfCustomizationUUID = null;
    VnfResourceCustomization vrc = new VnfResourceCustomization();
    vrc.setModelCustomizationUUID("z789J");
    VnfResourceCustomization vrc2 = new VnfResourceCustomization();
    vrc2.setModelCustomizationUUID("a123");
    ArrayList<VnfResourceCustomization> vrcs = new ArrayList<VnfResourceCustomization>();
    vrcs.add(vrc);
    vrcs.add(vrc2);
    catalogDbClient.findVnfResourceCustomizationInList(vnfCustomizationUUID, vrcs);
}
Also used : ArrayList(java.util.ArrayList) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) Test(org.junit.Test)

Example 12 with VnfResourceCustomization

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

the class CatalogDbClientTest method testFindVnfResourceCustomizationInListNullInList.

@Test
public final void testFindVnfResourceCustomizationInListNullInList() {
    thrown.expect(EntityNotFoundException.class);
    String vnfCustomizationUUID = "a123";
    VnfResourceCustomization vrc = new VnfResourceCustomization();
    vrc.setModelCustomizationUUID("z789J");
    VnfResourceCustomization vrc2 = new VnfResourceCustomization();
    vrc2.setModelCustomizationUUID(null);
    ArrayList<VnfResourceCustomization> vrcs = new ArrayList<VnfResourceCustomization>();
    vrcs.add(vrc);
    vrcs.add(vrc2);
    catalogDbClient.findVnfResourceCustomizationInList(vnfCustomizationUUID, vrcs);
}
Also used : ArrayList(java.util.ArrayList) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) Test(org.junit.Test)

Example 13 with VnfResourceCustomization

use of org.onap.so.db.catalog.beans.VnfResourceCustomization 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 14 with VnfResourceCustomization

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

the class VnfRestImpl method findService.

@PUT
@Operation(description = "Update a VNF model contained within a service", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Vnf.class)))))
@Path("/{modelCustomizationUUID}")
@Produces({ MediaType.APPLICATION_JSON })
@Transactional
public Response findService(@PathParam("modelUUID") String serviceModelUUID, @PathParam("modelCustomizationUUID") String modelCustomizationUUID, Vnf vnf) {
    org.onap.so.db.catalog.beans.Service service = serviceRepo.findOneByModelUUID(serviceModelUUID);
    List<VnfResourceCustomization> vnfCustom = service.getVnfCustomizations().stream().filter(vnfCust -> vnfCust.getModelCustomizationUUID().equals(modelCustomizationUUID)).collect(Collectors.toList());
    if (vnfCustom.isEmpty()) {
        throw new RuntimeException("No Vnf Found");
    } else if (vnfCustom.size() > 1) {
        throw new RuntimeException("More than one Vnf model returned with model Customization UUID: " + modelCustomizationUUID);
    }
    VnfResourceCustomization vnfCust = vnfMapper.mapVnf(vnfCustom.get(0), vnf);
    vnfCustRepo.save(vnfCust);
    return Response.ok().build();
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) Content(io.swagger.v3.oas.annotations.media.Content) MediaType(javax.ws.rs.core.MediaType) Vnf(org.onap.so.rest.catalog.beans.Vnf) Operation(io.swagger.v3.oas.annotations.Operation) QueryParam(javax.ws.rs.QueryParam) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Schema(io.swagger.v3.oas.annotations.media.Schema) Info(io.swagger.v3.oas.annotations.info.Info) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) Response(javax.ws.rs.core.Response) OpenAPIDefinition(io.swagger.v3.oas.annotations.OpenAPIDefinition) ServiceRepository(org.onap.so.db.catalog.data.repository.ServiceRepository) WebApplicationException(javax.ws.rs.WebApplicationException) PUT(javax.ws.rs.PUT) VnfCustomizationRepository(org.onap.so.db.catalog.data.repository.VnfCustomizationRepository) Transactional(org.springframework.transaction.annotation.Transactional) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with VnfResourceCustomization

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

the class QueryServiceVnfs method JSON2.

@Override
public String JSON2(boolean isArray, boolean isEmbed) {
    StringBuilder sb = new StringBuilder();
    if (!isEmbed && isArray)
        sb.append("{ ");
    if (isArray)
        sb.append("\"serviceVnfs\": [");
    Map<String, String> valueMap = new HashMap<>();
    String sep = "";
    boolean first = true;
    for (VnfResourceCustomization o : serviceVnfs) {
        if (first)
            sb.append("\n");
        first = false;
        boolean vrNull = o.getVnfResources() == null;
        put(valueMap, "MODEL_NAME", vrNull ? null : o.getVnfResources().getModelName());
        put(valueMap, "MODEL_UUID", vrNull ? null : o.getVnfResources().getModelUUID());
        put(valueMap, "MODEL_INVARIANT_ID", vrNull ? null : o.getVnfResources().getModelInvariantId());
        put(valueMap, "MODEL_VERSION", vrNull ? null : o.getVnfResources().getModelVersion());
        put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
        put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
        put(valueMap, "TOSCA_NODE_TYPE", vrNull ? null : o.getVnfResources().getToscaNodeType());
        put(valueMap, "NF_FUNCTION", o.getNfFunction());
        put(valueMap, "NF_TYPE", o.getNfType());
        put(valueMap, "NF_ROLE", o.getNfRole());
        put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
        put(valueMap, "VNFC_INSTANCE_GROUP_ORDER", o.getVnfcInstanceGroupOrder());
        put(valueMap, "MULTI_STEP_DESIGN", o.getMultiStageDesign());
        if (isJSONValid(StringEscapeUtils.unescapeJava(o.getResourceInput()))) {
            put(valueMap, "RESOURCE_INPUT", o.getResourceInput());
        }
        String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true);
        valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t"));
        List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations = o.getVnfcInstanceGroupCustomizations();
        String grpSubItem = new QueryGroups(vrNull ? null : vnfcInstanceGroupCustomizations).JSON2(true, true);
        valueMap.put("_GROUPS_", grpSubItem.replaceAll("(?m)^", "\t\t"));
        sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
        sep = ",\n";
    }
    if (!first)
        sb.append("\n");
    if (isArray)
        sb.append("]");
    if (!isEmbed && isArray)
        sb.append("}");
    return sb.toString();
}
Also used : HashMap(java.util.HashMap) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) VnfcInstanceGroupCustomization(org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization)

Aggregations

VnfResourceCustomization (org.onap.so.db.catalog.beans.VnfResourceCustomization)43 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)17 Service (org.onap.so.db.catalog.beans.Service)15 VfModuleCustomization (org.onap.so.db.catalog.beans.VfModuleCustomization)13 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)11 VnfResource (org.onap.so.db.catalog.beans.VnfResource)10 VfModule (org.onap.so.db.catalog.beans.VfModule)7 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)7 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)6 PnfResourceCustomization (org.onap.so.db.catalog.beans.PnfResourceCustomization)6 Transactional (org.springframework.transaction.annotation.Transactional)6 List (java.util.List)5 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)5 VnfcInstanceGroupCustomization (org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 BuildingBlockExecution (org.onap.so.bpmn.common.BuildingBlockExecution)4 Resource (org.onap.so.bpmn.infrastructure.workflow.tasks.Resource)4 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)4 NetworkResourceCustomization (org.onap.so.db.catalog.beans.NetworkResourceCustomization)4