From f646731541eb0a720c83da2d7b8e70a33ca2fbe6 Mon Sep 17 00:00:00 2001 From: deepikasatheesh Date: Tue, 22 Feb 2022 11:58:53 +0000 Subject: Implemented OOF call in TN NSSMF for deallocate flow Issue-ID: SO-3864 Signed-off-by: deepikasatheesh Change-Id: Ibb7342a2eb6adb44c5a03e717e908699997e79b4 --- .../scripts/DoDeallocateTnNssi.groovy | 68 ++++- .../infrastructure/scripts/TnNssmfUtils.groovy | 12 + .../scripts/DoDeallocateTnNssiTest.groovy | 39 +++ .../subprocess/DoDeallocateTransportNSSI.bpmn | 290 ++++++++++++++++----- 4 files changed, 343 insertions(+), 66 deletions(-) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy index b09161d5cd..ea4c29b202 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy @@ -34,6 +34,13 @@ import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.RequestDBUtil import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.common.scripts.OofUtils +import org.onap.so.client.HttpClient +import org.onap.so.client.HttpClientFactory +import org.onap.so.client.oof.adapter.beans.payload.OofRequest +import javax.ws.rs.core.Response +import org.onap.logging.filter.base.ONAPComponents import org.onap.so.db.request.beans.ResourceOperationStatus import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -48,6 +55,7 @@ class DoDeallocateTnNssi extends AbstractServiceTaskProcessor { JsonUtils jsonUtil = new JsonUtils() RequestDBUtil requestDBUtil = new RequestDBUtil() TnNssmfUtils tnNssmfUtils = new TnNssmfUtils() + OofUtils oofUtils = new OofUtils() JsonSlurper jsonSlurper = new JsonSlurper() ObjectMapper objectMapper = new ObjectMapper() private static final Logger logger = LoggerFactory.getLogger(DoDeallocateTnNssi.class) @@ -92,10 +100,69 @@ class DoDeallocateTnNssi extends AbstractServiceTaskProcessor { "enableSdnc", "enableSdnc"))) { tnNssmfUtils.setEnableSdncConfig(execution) } + if (isBlank(additionalPropJsonStr) || + isBlank(tnNssmfUtils.setExecVarFromJsonIfExists(execution, + additionalPropJsonStr, + "enableOof", "enableOof"))) { + tnNssmfUtils.setEnableOofConfig(execution) + } + String nsiId = jsonUtil.getJsonValue(additionalPropJsonStr, "nsiId") + execution.setVariable("nsiId", nsiId) logger.debug("Finish preProcessRequest") } + void prepareOOFNssiTerminationRequest(DelegateExecution execution) { + logger.debug("Start prepareOOFTnNssiTerminationRequest") + String requestId = execution.getVariable("msoRequestId") + String messageType = "TN_NSSITermination" + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + String serviceInstanceId = execution.getVariable("sliceServiceInstanceId") + + String relatedNsiId = execution.getVariable("nsiId") + + String oofRequest = oofUtils.buildTerminateNxiRequest(requestId,serviceInstanceId, "NSSI",messageType,relatedNsiId) + execution.setVariable("oofTnNssiPayload", oofRequest) + logger.debug("Finish prepareOOFTnNssiTerminationRequest") + } + + void performOofNSSITerminationCall(DelegateExecution execution) { + boolean terminateTnNSSI = callOofAdapter(execution,execution.getVariable("oofTnNssiPayload")) + execution.setVariable("terminateTnNSSI", terminateTnNSSI) + } + + /** + * @param execution + * @param oofRequest - Request payload to be sent to adapter + * @return + */ + boolean callOofAdapter(DelegateExecution execution, Object oofRequest) { + logger.debug("Start callOofAdapter") + String requestId = execution.getVariable("msoRequestId") + String oofAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution) + URL requestUrl = new URL(oofAdapterEndpoint) + OofRequest oofPayload = new OofRequest() + oofPayload.setApiPath("/api/oof/terminate/nxi/v1") + oofPayload.setRequestDetails(oofRequest) + String requestJson = objectMapper.writeValueAsString(oofPayload) + logger.debug("Calling OOF adapter : ${requestUrl} with payload : ${requestJson}") + HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL) + Response httpResponse = httpClient.post(requestJson) + int responseCode = httpResponse.getStatus() + logger.debug("OOF sync response code is: " + responseCode) + if(responseCode < 200 || responseCode >= 300){ + logger.debug("OOF request failed with reason : " + httpResponse) + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.") + }else { + Map response = objectMapper.readValue(httpResponse.getEntity(),Map.class) + boolean terminateResponse = response.get("terminateResponse") + if(!terminateResponse) { + logger.debug("Terminate response is false because " + response.get("reason")) + } + return terminateResponse + } + } + void preprocessSdncDeallocateTnNssiRequest(DelegateExecution execution) { def method = getClass().getSimpleName() + '.preprocessSdncDeallocateTnNssiRequest(' + 'execution=' + execution.getId() + ')' @@ -174,4 +241,3 @@ class DoDeallocateTnNssi extends AbstractServiceTaskProcessor { requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) } } - diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy index d6e94efea1..d1e2b11676 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy @@ -382,6 +382,18 @@ class TnNssmfUtils { execution.setVariable("enableSdnc", enableSdnc) } + void setEnableOofConfig(DelegateExecution execution) { + String enableOof = UrnPropertiesReader.getVariable( + "mso.workflow.TnNssmf.enableOOFNetworkConfig") + if (isBlank(enableOof)) { + logger.debug("mso.workflow.TnNssmf.enableOOFNetworkConfig is undefined, so use default value (true)") + enableOof = "true" + } + logger.debug("setEnableOofConfig: enableOof=" + enableOof) + + execution.setVariable("enableOof", enableOof) + } + String setExecVarFromJsonIfExists(DelegateExecution execution, String jsonStr, String jsonKey, String varName) { return setExecVarFromJsonStr(execution, jsonStr, jsonKey, varName, false) diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssiTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssiTest.groovy index 31bd3b56f5..2bb2270928 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssiTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssiTest.groovy @@ -32,8 +32,10 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types import org.onap.so.bpmn.common.scripts.MsoGroovyTest +import org.onap.so.bpmn.common.scripts.OofUtils import static org.junit.Assert.assertNotNull +import static org.junit.Assert.assertTrue import static org.mockito.ArgumentMatchers.eq import static org.mockito.Mockito.* @@ -135,4 +137,41 @@ class DoDeallocateTnNssiTest extends MsoGroovyTest { obj.deleteServiceInstance(mockExecution) Mockito.verify(client, times(1)).delete(serviceInstanceUri) } + + @Test + void testPrepareOOFNssiTerminationRequest() { + when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82") + when(mockExecution.getVariable("sliceServiceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be") + when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56") + when(mockExecution.getVariable("mso.adapters.oof.timeout")).thenReturn("") + DoDeallocateTnNssi obj = spy(DoDeallocateTnNssi.class) + OofUtils oofUtils = spy(OofUtils.class) + when(oofUtils.buildTerminateNxiRequest()).thenReturn(""" + { + "apiPath": "/api/oof/terminate/nxi/v1", + "requestDetails": "{\"type\":\"NSSI\",\"NxIId\":\"f78c1531-55a7-4dfa-8a12-1e2544c9b248\",\"requestInfo\":{\"transactionId\":\"863fb189-33d8-455f-9d3f-bf3f6a2e4509\",\"requestId\":\"863fb189-33d8-455f-9d3f-bf3f6a2e4509\",\"callbackUrl\":\"http://so-oof-adapter.onap:8090/so/adapters/oof/callback/v1/TN_NSSITermination/863fb189-33d8-455f-9d3f-bf3f6a2e4509\",\"sourceId\":\"SO\",\"timeout\":600,\"addtnlArgs\":{\"serviceInstanceId\":\"fe6f0901-292d-4493-bcad-485793605781\"}}}" + }""".replaceAll("\\\\s+", "")) + obj.prepareOOFNssiTerminationRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("oofTnNssiPayload"), captor.capture()) + String oofTnNssiPayload = captor.getValue() + assertNotNull(oofTnNssiPayload) + } + + @Test + void testPerformOofNSSITerminationCall() { + when(mockExecution.getVariable("oofTnNssiPayload")).thenReturn(""" + { + "reason": "", + "requestId": "e0a026a9-dd6d-4800-ab27-0fdd8f5f64f5", + "requestStatus": "success", + "terminateResponse": true, + "transactionId": "e0a026a9-dd6d-4800-ab27-0fdd8f5f64f5" + }""".replaceAll("\\\\s+", "")) + DoDeallocateTnNssi obj = spy(DoDeallocateTnNssi.class) + when(obj.callOofAdapter()).thenReturn(true) + obj.performOofNSSITerminationCall(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("terminateTnNSSI"), captor.capture()) + String terminateTnNSSI = captor.getValue() + assertTrue(terminateTnNSSI) + } } diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateTransportNSSI.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateTransportNSSI.bpmn index 1dd362bf4b..48978500e3 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateTransportNSSI.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateTransportNSSI.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_03s744c @@ -26,7 +26,7 @@ ex.processJavaException(execution) Flow_0ca4l8d - SequenceFlow_1jygjln + Flow_14tkuoh SequenceFlow_1qv8qw1 import org.onap.so.bpmn.infrastructure.scripts.* def runScript = new DoDeallocateTnNssi() @@ -69,7 +69,7 @@ runScript.validateSDNCResponse(execution, response, "deallocate") SequenceFlow_1jdb2oq Flow_0dirb5b - SequenceFlow_1jygjln + Flow_14pzrs9 import org.onap.so.bpmn.infrastructure.scripts.* def runScript = new DoDeallocateTnNssi() runScript.deleteServiceInstance(execution) @@ -77,13 +77,11 @@ runScript.deleteServiceInstance(execution) SequenceFlow_03s744c - SequenceFlow_07e12rt + Flow_1xxj5g6 import org.onap.so.bpmn.infrastructure.scripts.* def runScript = new DoDeallocateTnNssi() runScript.preProcessRequest(execution) - - @@ -108,7 +106,7 @@ runScript.preProcessRequest(execution) - SequenceFlow_07e12rt + Flow_08so17j Flow_0sj0mtu Flow_0dirb5b @@ -116,119 +114,281 @@ runScript.preProcessRequest(execution) #{(execution.getVariable("enableSdnc" ) == true)} + + Flow_1xxj5g6 + Flow_0elnhnt + Flow_0buil9w + + + Flow_18xmkvl + Flow_1oxjcb2 + Flow_083usqs + + + + Flow_0elnhnt + Flow_1yadxwl + import org.onap.so.bpmn.infrastructure.scripts.* +def deallocator = new DoDeallocateTnNssi() +deallocator.prepareOOFNssiTerminationRequest(execution) + + + Flow_1yadxwl + Flow_18xmkvl + import org.onap.so.bpmn.infrastructure.scripts.* +def deallocator = new DoDeallocateTnNssi() +deallocator.performOofNSSITerminationCall(execution) + + + #{execution.getVariable("enableOof") == true} + + + + Flow_14tkuoh + + + + + Flow_14pzrs9 + + + + + Flow_1oxjcb2 + + + + + + Flow_083usqs + + + + #{execution.getVariable("terminateTnNSSI") == true} + + + Flow_08so17j + + + + + Flow_0buil9w + + + - - - + + + + + + - - - + + + + + + - - - + + + - - - - - + + + + + - - + + - - + + - - + + - - + + - - - + + + + + + + - + - - - + + + + + + + + + + + + + + + + + + + + - + - - + + + - + + + + + + + + + + + + + + + + + + + - - - - + + + + - + - + - + - - + + + + + - - + + + + + + + + + + + + + + - + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - + + - + - + - - - - + -- cgit 1.2.3-korg