Search in sources :

Example 1 with Recipe

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

the class Vnf method deleteVnfInstance.

@DELETE
@ResponseUpdater
@Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Delete a Vnf instance", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServiceInstancesResponse.class)))))
@Transactional
public Response deleteVnfInstance(@PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId, @Context ContainerRequestContext requestContext) throws AAIEntityNotFound, JsonProcessingException, WorkflowEngineConnectionException, ValidateException {
    String requestId = vnfRestHandler.getRequestId(requestContext);
    String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID);
    String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
    String requestURL = requestContext.getUriInfo().getAbsolutePath().toString();
    InfraActiveRequests currentRequest = vnfRestHandler.createInfraActiveRequestForDelete(requestId, serviceInstanceId, vnfInstanceId, requestorId, source, requestURL);
    ServiceInstancesRequest request = requestBuilder.buildVnfDeleteRequest(vnfInstanceId);
    vnfRestHandler.saveInstanceName(request, currentRequest);
    vnfRestHandler.checkDuplicateRequest(serviceInstanceId, vnfInstanceId, request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
    Recipe recipe = vnfRestHandler.findVnfModuleRecipe(request.getRequestDetails().getModelInfo().getModelCustomizationId(), "vnf", "deleteInstance");
    vnfRestHandler.callWorkflowEngine(vnfRestHandler.buildRequestParams(request, vnfRestHandler.getRequestUri(requestContext), requestId, serviceInstanceId, vnfInstanceId), recipe.getOrchestrationUri());
    ServiceInstancesResponse response = vnfRestHandler.createResponse(vnfInstanceId, requestId, requestContext);
    return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();
}
Also used : Recipe(org.onap.so.db.catalog.beans.Recipe) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) Path(javax.ws.rs.Path) ResponseUpdater(org.onap.so.apihandler.filters.ResponseUpdater) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 2 with Recipe

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

the class VnfRestHandlerTest method test_find_vnf_recipe.

@Test
public void test_find_vnf_recipe() throws MalformedURLException, NoRecipeException {
    ServiceRecipe expected = new ServiceRecipe();
    expected.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
    Recipe actual = restHandler.findVnfModuleRecipe("testModelId", ModelType.vnf.toString(), Action.createInstance.toString());
    assertThat(actual, sameBeanAs(expected));
}
Also used : Recipe(org.onap.so.db.catalog.beans.Recipe) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) Test(org.junit.Test)

Example 3 with Recipe

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

the class VfModuleRestHandlerTest method test_find_vf_module_recipe.

@Test
public void test_find_vf_module_recipe() throws MalformedURLException, NoRecipeException {
    VnfComponentsRecipe expected = new VnfComponentsRecipe();
    expected.setAction("createInstance");
    doReturn(expected).when(catalogDbClient).getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction("testModelId", ModelType.vfModule.toString(), Action.createInstance.toString());
    Recipe actual = restHandler.findVfModuleRecipe("testModelId", ModelType.vfModule.toString(), Action.createInstance.toString());
    assertThat(actual, sameBeanAs(expected));
    Mockito.verify(catalogDbClient, Mockito.times(1)).getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction("testModelId", ModelType.vfModule.toString(), Action.createInstance.toString());
}
Also used : Recipe(org.onap.so.db.catalog.beans.Recipe) VnfComponentsRecipe(org.onap.so.db.catalog.beans.VnfComponentsRecipe) VnfComponentsRecipe(org.onap.so.db.catalog.beans.VnfComponentsRecipe) Test(org.junit.Test)

Example 4 with Recipe

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

the class ServiceInstanceRestHandlerTest method test_find_service_recipe.

@Test
public void test_find_service_recipe() throws MalformedURLException, NoRecipeException {
    ServiceRecipe expected = new ServiceRecipe();
    expected.setAction("createInstance");
    doReturn(expected).when(catalogDbClient).findServiceRecipeByActionAndServiceModelUUID(Action.createInstance.toString(), "testModelId");
    Recipe actual = restHandler.findServiceRecipe("testModelId", Action.createInstance.toString());
    assertThat(actual, sameBeanAs(expected));
    Mockito.verify(catalogDbClient, Mockito.times(1)).findServiceRecipeByActionAndServiceModelUUID(Action.createInstance.toString(), "testModelId");
}
Also used : Recipe(org.onap.so.db.catalog.beans.Recipe) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) Test(org.junit.Test)

Example 5 with Recipe

use of org.onap.so.db.catalog.beans.Recipe 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)

Aggregations

Recipe (org.onap.so.db.catalog.beans.Recipe)14 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Test (org.junit.Test)6 ServiceRecipe (org.onap.so.db.catalog.beans.ServiceRecipe)6 Operation (io.swagger.v3.oas.annotations.Operation)5 Transactional (javax.transaction.Transactional)5 Consumes (javax.ws.rs.Consumes)5 DELETE (javax.ws.rs.DELETE)5 ResponseUpdater (org.onap.so.apihandler.filters.ResponseUpdater)5 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)5 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)5 ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)5 VnfRecipe (org.onap.so.db.catalog.beans.VnfRecipe)4 NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)2 VnfComponentsRecipe (org.onap.so.db.catalog.beans.VnfComponentsRecipe)2 VnfResource (org.onap.so.db.catalog.beans.VnfResource)2 ValidationException (org.onap.so.exceptions.ValidationException)2 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)2 GET (javax.ws.rs.GET)1