From a640faf880d7cd094e25576548f988952e08dbfc Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Sep 2021 19:15:58 +0300 Subject: [PATCH] Wrong additional parameter for OOF's terminateNxiRequest Issue-ID: SO-3760 Change-Id: If4211e67ae2debcf394fd69c7e301a99d3bb9658 Signed-off-by: Alex --- .../infrastructure/scripts/DoCommonCoreNSSI.groovy | 26 ++-- .../scripts/DoDeallocateCoreNSSI.groovy | 64 ++++++---- .../scripts/DoDeallocateCoreNSSITest.groovy | 16 ++- .../resources/subprocess/DoDeallocateCoreNSSI.bpmn | 136 ++++++++++----------- 4 files changed, 139 insertions(+), 103 deletions(-) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy index 67e4b9227d..b07f5c965d 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy @@ -121,6 +121,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { currentNSSI['S-NSSAI'] = sNssai } + LOGGER.debug("S-NSSAI=" + currentNSSI['S-NSSAI']) // Slice Profile id String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId") @@ -381,9 +382,10 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { } + LOGGER.debug("${getPrefix()} Exit callPUTServiceInstance") + return response - LOGGER.debug("${getPrefix()} Exit callPUTServiceInstance") } @@ -742,6 +744,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { // Supported S-NSSAI List snssais = (List) currentNSSI['S-NSSAIs'] + LOGGER.debug("prepareInstanceParams: snssais size = " + snssais.size()) + ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi'] String orchStatus = nssi.getOrchestrationStatus() @@ -750,6 +754,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { List> snssaiList = new ArrayList<>() for(String snssai:snssais) { + LOGGER.debug("prepareInstanceParams: snssai = " + snssai) Map snssaisMap = new HashMap<>() snssaisMap.put("snssai", snssai) snssaisMap.put("status", orchStatus) @@ -761,12 +766,15 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { ObjectMapper mapper = new ObjectMapper() - String supportedNssaiDetailsStr = mapper.writeValueAsString(snssaiList) + Map nSsai= new LinkedHashMap<>() + nSsai.put("sNssai", snssaiList) + // String supportedsNssaiJson = mapper.writeValueAsString(snssaiList) + String supportedsNssaiJson = mapper.writeValueAsString(nSsai) instanceParamsMap.put("k8s-rb-profile-name", "default") // ??? instanceParamsMap.put("config-type", "day2") // ??? - instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr) + instanceParamsMap.put("supportedsNssai", supportedsNssaiJson) instanceParams.add(instanceParamsMap) LOGGER.debug("${getPrefix()} Exit prepareInstanceParams") @@ -1177,9 +1185,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { sliceProfileInstanceUri = (AAIResourceUri)spURI } else { - String msg = "Slice Profile URI not found" - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + String msg = "Slice Profile association with NSSI was already removed" + LOGGER.info(msg) } } @@ -1220,13 +1227,12 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { sliceProfileInstanceUri = (AAIResourceUri)spURI } else { - String msg = "Slice Profile URI not found" - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + String msg = "Slice Profile instance was already deleted" + LOGGER.info(msg) } } - if(sliceProfileInstanceUri != null) { // NSSI should not be terminated + if(sliceProfileInstanceUri != null) { try { client.delete(sliceProfileInstanceUri) } catch (Exception e) { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy index c559845e12..11058748fd 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy @@ -238,6 +238,22 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } + + // NSI + String nsiId = currentNSSI['nsiId'] + ServiceInstance nsi = null + AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId)) + Optional nsiOpt = client.get(ServiceInstance.class, nsiUri) + if (nsiOpt.isPresent()) { + nsi = nsiOpt.get() + } + else { + String msg = "NSI service instance not found in AAI for nsi id " + nsiId + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + //Setting correlator as requestId String requestId = execution.getVariable("msoRequestId") execution.setVariable("NSSI_correlator", requestId) @@ -257,7 +273,7 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { String nxlId = nssi.getServiceInstanceId() String nxlType = "NSSI" - String oofRequest = getOofUtils().buildTerminateNxiRequest(requestId, nxlId, nxlType, messageType, nssi.getServiceInstanceId()) + String oofRequest = getOofUtils().buildTerminateNxiRequest(requestId, nxlId, nxlType, messageType, nsi.getServiceInstanceId()) LOGGER.debug("**** Terminate Nxi Request: "+oofRequest) LOGGER.debug("${PREFIX} Exit buildOOFRequest") @@ -289,32 +305,31 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5 String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) + LOGGER.debug("url = " + url) + currentNSSI['deleteServiceOrderURL'] = url String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution) String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution) - /*String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) - def authHeader = "" - if (basicAuthValue != null) { - String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) - String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode") - if(errorCode == null || errorCode.isEmpty()) { // No error - authHeader = responseAuthHeader - } - else { - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage")) - } - } else { - LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null") - exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " + - "value null") - } */ - def authHeader = utils.getBasicAuth(basicAuth, msoKey) - String callDeleteServiceOrderResponse = callDeleteServiceOrder(execution, url, authHeader) - String errorCode = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorCode") + def requestDetails = "" + + String prepareRequestDetailsResponse = prepareRequestDetails(execution) + LOGGER.debug("deleteServiceOrder: prepareRequestDetailsResponse=" + prepareRequestDetailsResponse) + + String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode") + LOGGER.debug("deleteServiceOrder: errorCode=" + errorCode) + if(errorCode == null || errorCode.isEmpty()) { // No error + requestDetails = prepareRequestDetailsResponse + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage")) + } + + String callDeleteServiceOrderResponse = callDeleteServiceOrder(url, authHeader, requestDetails) + errorCode = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorCode") if(errorCode == null || errorCode.isEmpty()) { // No error String macroOperationId = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "requestReferences.requestId") @@ -339,21 +354,24 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { } - String callDeleteServiceOrder(DelegateExecution execution, String url, String authHeader) { + String callDeleteServiceOrder(String url, String authHeader, String requestDetailsStr) { LOGGER.debug("${PREFIX} Start callDeleteServiceOrder") String errorCode = "" String errorMessage = "" String response = "" + LOGGER.debug("callDeleteServiceOrder: url = " + url) + LOGGER.debug("callDeleteServiceOrder: authHeader = " + authHeader) + try { HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO) httpClient.addAdditionalHeader("Authorization", authHeader) httpClient.addAdditionalHeader("Accept", "application/json") - Response httpResponse = httpClient.delete() + Response httpResponse = httpClient.delete(requestDetailsStr) int soResponseCode = httpResponse.getStatus() - LOGGER.debug("callDeleteServiceInstance: soResponseCode = " + soResponseCode) + LOGGER.debug("callDeleteServiceOrder: soResponseCode = " + soResponseCode) if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) { response = httpResponse.readEntity(String.class) diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy index 5bf4f40e50..acace8c1c7 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy @@ -95,6 +95,9 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { String nssiId = "5G-999" currentNSSI.put("nssiId", nssiId) + String nsiId = "ns-777" + currentNSSI.put("nsiId", nsiId) + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) when(mockExecution.getVariable("mso.oof.endpoint")).thenReturn("http://oof.onap:8088") @@ -127,6 +130,14 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt) + AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId)) + + ServiceInstance nsi = new ServiceInstance() + nsi.setServiceInstanceId("5G-777") + Optional nsiOpt = Optional.of(nsi) + + when(client.get(ServiceInstance.class, nsiUri)).thenReturn(nsiOpt) + String urlString = "http://oof.onap:8088" String httpRequest = "{\n" + @@ -143,7 +154,7 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { String nxlId = nssi.getServiceInstanceId() String nxlType = "NSSI" String messageType = "cn" - String serviceInstanceId = nssi.getServiceInstanceId() + String serviceInstanceId = nsi.getServiceInstanceId() when(mockExecution.getVariable("msoRequestId")).thenReturn(requestId) when(oofUtilsMock.buildTerminateNxiRequest(requestId, nxlId, nxlType, messageType, serviceInstanceId)).thenReturn(httpRequest) @@ -213,6 +224,7 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { genericVnf.setVnfName("vnf-name") genericVnf.setVnfId("vnf-id") + currentNSSI.put("constituteVnf", genericVnf) String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId()) @@ -235,7 +247,7 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock) - when(httpClientMock.delete()).thenReturn(responseMock) + when(httpClientMock.delete(requestDetailsStr)).thenReturn(responseMock) when(responseMock.getStatus()).thenReturn(200) when(responseMock.hasEntity()).thenReturn(true) diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn index bfc45f26b7..3966caeba5 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn @@ -20,11 +20,11 @@ def dcnssi= new DoDeallocateCoreNSSI() dcnssi.getNetworkServiceInstance(execution) - Flow_16192dm + Flow_01q7kcf Flow_15ew9rs Flow_0e3yvck - + Flow_15ew9rs Flow_1b14can @@ -33,14 +33,14 @@ def dcnssi= new DoDeallocateCoreNSSI() dcnssi.deleteServiceOrder(execution) - Flow_1v68jns - Flow_1eev81t + Flow_16192dm + Flow_01q7kcf import org.onap.so.bpmn.infrastructure.scripts.* def dcnssi= new DoDeallocateCoreNSSI() dcnssi.getConstituteVNFFromNetworkServiceInst(execution) - Flow_1eev81t + Flow_1v68jns Flow_0xrq94a import org.onap.so.bpmn.infrastructure.scripts.* def dcnssi= new DoDeallocateCoreNSSI() @@ -113,8 +113,7 @@ def dcnssi= new DoDeallocateCoreNSSI() #{(execution.getVariable("isTerminateNSSI" ) == true)} - - + @@ -282,9 +281,18 @@ dcnssi.timeDelay(execution) + + + + + + + + + @@ -295,8 +303,8 @@ dcnssi.timeDelay(execution) - - + + @@ -326,14 +334,14 @@ dcnssi.timeDelay(execution) - + - + - + @@ -344,13 +352,13 @@ dcnssi.timeDelay(execution) - + - + @@ -376,41 +384,37 @@ dcnssi.timeDelay(execution) - - + + - - + + - - + + - + - - + + - - - - - + - - + + - + @@ -418,20 +422,16 @@ dcnssi.timeDelay(execution) - - + + - - - - - - - + + + @@ -442,18 +442,6 @@ dcnssi.timeDelay(execution) - - - - - - - - - - - - @@ -493,32 +481,47 @@ dcnssi.timeDelay(execution) + + + + + + + + + + + + - + - + - - + + - + - - + + - + - - + + - + - - + + + + + @@ -563,9 +566,6 @@ dcnssi.timeDelay(execution) - - - -- 2.16.6