From 0248e0fe15cb1712e0216de64b0c4000bc2a1547 Mon Sep 17 00:00:00 2001 From: "raviteja.karumuri" Date: Wed, 13 Jul 2022 13:17:49 +0100 Subject: [SO] SO BPMN Infra shall trigger Delete AS Instance workflow(s). Issue-ID: SO-3885 Change-Id: I6e5a1501fcbb68b98ce0c7787d67996b96fa95f2 Signed-off-by: raviteja.karumuri --- .../main/resources/db/migration/R__MacroData.sql | 15 ++-- .../subprocess/BuildingBlock/CnfDeleteBB.bpmn | 38 ++++++++++ .../adapter/cnfm/tasks/CnfDeleteTask.java | 82 ++++++++++++++++++++++ .../onap/so/apihandlerinfra/ServiceInstances.java | 26 ++++++- 4 files changed, 153 insertions(+), 8 deletions(-) create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql index dbc9deb51e..aea0c222b8 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql @@ -41,7 +41,8 @@ INSERT INTO northbound_request_ref_lookup(MACRO_ACTION, ACTION, REQUEST_SCOPE, I ('VNF-InPlaceUpdate', 'inPlaceSoftwareUpdate', 'Vnf', true, true, '7','7', 'DEFAULT', '*'), ('VNF-Config-Update', 'applyUpdatedConfig', 'Vnf', true, true, '7','7', 'DEFAULT', '*'), ('CNF-Macro-Upgrade', 'upgradeCnf', 'Vnf', false,true, '7', '7','DEFAULT', '*'), -('Cnf-Create', 'createInstance', 'Cnf', true, true, '7','7','DEFAULT', '*'); +('Cnf-Create', 'createInstance', 'Cnf', true, true, '7','7','DEFAULT', '*'), +('Cnf-Delete', 'deleteInstance', 'Cnf', true, true, '7','7','DEFAULT', '*'); INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, SCOPE, ACTION, FLOW_VERSION, NB_REQ_REF_LOOKUP_ID) VALUES @@ -271,7 +272,8 @@ INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, SC ('CNF-Macro-Upgrade', '10', 'ChangeModelVnfBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'CNF-Macro-Upgrade' and CLOUD_OWNER = 'DEFAULT')), ('CNF-Macro-Upgrade', '11', 'ActivateVnfBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'CNF-Macro-Upgrade' and CLOUD_OWNER = 'DEFAULT')), ('CNF-Macro-Upgrade', '12', 'AAIUnsetVnfInMaintBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'CNF-Macro-Upgrade' and CLOUD_OWNER = 'DEFAULT')), -('CNF-Create', '1', 'CnfInstantiateBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'Cnf-Create' and CLOUD_OWNER = 'DEFAULT')); +('CNF-Create', '1', 'CnfInstantiateBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'Cnf-Create' and CLOUD_OWNER = 'DEFAULT')), +('CNF-Delete', '1', 'CnfDeleteBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'Cnf-Delete' and CLOUD_OWNER = 'DEFAULT')); INSERT INTO rainy_day_handler_macro (FLOW_NAME, SERVICE_TYPE, VNF_TYPE, ERROR_CODE, WORK_STEP, POLICY, SECONDARY_POLICY, REG_EX_ERROR_MESSAGE, SERVICE_ROLE) VALUES @@ -336,7 +338,8 @@ VALUES ('VNFHealthCheckActivity','*','*','*','*','Manual','Abort','*', '*'), ('VNFConfigModifyActivity','*','*','*','*','Manual','Abort','*', '*'), ('VNFUnsetInMaintFlagActivity','*','*','*','*','Manual','Abort','*', '*'), -('VNFUnsetClosedLoopDisabledActivity','*','*','*','*','Manual','Abort','*', '*'); +('VNFUnsetClosedLoopDisabledActivity','*','*','*','*','Manual','Abort','*', '*'), +('CnfDeleteBB', '*', '*', '*', '*' , 'Abort', 'Abort', '*', '*'); INSERT INTO building_block_detail (building_block_name, resource_type, target_action) VALUES @@ -430,7 +433,8 @@ VALUES ('StatusCheckBB', 'NO_VALIDATE', 'CUSTOM'), ('HealthCheckBB', 'NO_VALIDATE', 'CUSTOM'), ('UpgradeVfModuleBB', 'NO_VALIDATE', 'CUSTOM'), -('CnfInstantiateBB', 'CNF', 'ACTIVATE'); +('CnfInstantiateBB', 'CNF', 'ACTIVATE'), +('CnfDeleteBB', 'CNF', 'DEACTIVATE'); INSERT INTO orchestration_status_state_transition_directive (resource_type, orchestration_status, target_action, flow_directive) @@ -863,7 +867,8 @@ VALUES ('CONFIGURATION', 'PENDING ACTIVATION', 'DEACTIVATE', 'FAIL'), ('CONFIGURATION', 'PENDING', 'DEACTIVATE', 'FAIL'), ('VNF','CONFIGDEPLOYED','ACTIVATE','CONTINUE'), -('CNF','PRECREATED','ACTIVATE','CONTINUE'); +('CNF','PRECREATED','ACTIVATE','CONTINUE'), +('CNF','PRECREATED','DEACTIVATE','CONTINUE'); INSERT INTO vnf_components_recipe (VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, VERSION, ORCHESTRATION_URI, RECIPE_TIMEOUT) diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn new file mode 100644 index 0000000000..45d51d78a8 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn @@ -0,0 +1,38 @@ + + + + + SequenceFlow_016sgof + + + Flow_1s7gtbc + + + SequenceFlow_016sgof + Flow_1s7gtbc + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java new file mode 100644 index 0000000000..6bbb391ca9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; + +import org.onap.logging.filter.base.ONAPComponents; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import static java.util.Objects.isNull; + + +/** + * This class performs CNF Delete + * + * @author raviteja.karumuri@est.tech + */ +@Component +public class CnfDeleteTask { + + private static final String AS_INSTANCE_ID = "asInstanceid"; + private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class); + private final ExceptionBuilder exceptionUtil; + private final CnfmHttpServiceProvider cnfmHttpServiceProvider; + + @Autowired + public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil) { + this.cnfmHttpServiceProvider = cnfmHttpServiceProvider; + this.exceptionUtil = exceptionUtil; + } + + public void invokeCnfmToDeleteAsInstnace(final BuildingBlockExecution execution) { + try { + LOGGER.debug("Executing DelteAsInstance task ..."); + final ExecuteBuildingBlock executeBuildingBlock = + (ExecuteBuildingBlock) execution.getVariable("buildingBlock"); + + final GeneralBuildingBlock generalBuildingBlock = execution.getGeneralBuildingBlock(); + + final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails(); + LOGGER.debug("RequestDetails of DeleteAsInstance: {}", requestDetails); + + if (isNull(requestDetails) && isNull(requestDetails.getModelInfo()) + && isNull(requestDetails.getRequestInfo()) && isNull(requestDetails.getCloudConfiguration()) + && isNull(generalBuildingBlock)) { + LOGGER.error("Missing Mandatory attribute from RequestDetails: {} or GeneralBuildingBlock: {}", + requestDetails, generalBuildingBlock); + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, + "Missing Mandatory attribute from RequestDetails or GeneralBuildingBlock", ONAPComponents.SO); + } + + LOGGER.debug("Finished executing DeleteAsInstance task ..."); + + } catch (final Exception exception) { + LOGGER.error("Unable to invoke DeleteAsInstance", exception); + exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception); + } + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 955d6a9a94..d11ae75c69 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -6,15 +6,15 @@ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ * Modifications Copyright (c) 2019 Samsung - * ================================================================================ + * ================================================================================ * Modifications Copyright (c) 2022 Ericsson. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -418,6 +418,26 @@ public class ServiceInstances extends AbstractRestHandler { } } + @DELETE + @Path("/{version:[vV][7]}/serviceInstances/{serviceInstanceId}/cnfs/{asInstanceId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Delete provided for CNF instance", + responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Transactional + public Response deleteCnfInstance(String request, @PathParam("version") String version, + @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("asInstanceId") String asInstanceId, + @Context ContainerRequestContext requestContext) throws ApiException { + logger.debug("Inside API Handler to perform delete CNF Instance"); + String requestId = requestHandlerUtils.getRequestId(requestContext); + HashMap instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", serviceInstanceId); + instanceIdMap.put("asInstanceId", asInstanceId); + return serviceInstances(request, Action.deleteInstance, instanceIdMap, version, requestId, + requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); + } + @POST @Path("/{version:[vV][5-7]}/serviceInstances/{serviceInstanceId}/upgrade") @Consumes(MediaType.APPLICATION_JSON) -- cgit 1.2.3-korg