From cda97d50c0fa04c131e923889b833013cb0e9a88 Mon Sep 17 00:00:00 2001 From: Dana Sunalova Date: Mon, 10 Jul 2023 11:05:47 +0200 Subject: [PATCH] issue-743 : added fcports deletions when deleting op-c Signed-off-by: Dana Sunalova --- ...icalTerminationPointWithMappingServices.js | 141 +++++++++--------- ...erminationPointWithMappingServices.test.js | 79 ++++++++++ 2 files changed, 149 insertions(+), 71 deletions(-) create mode 100644 server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.test.js diff --git a/server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.js b/server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.js index 4ad47e2e..9fbf3b08 100644 --- a/server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.js +++ b/server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.js @@ -16,7 +16,10 @@ const operationClientInterface = require('../models/layerProtocols/OperationClie const LogicalTerminationPointConfigurationStatus = require('./models/logicalTerminationPoint/ConfigurationStatus'); const ConfigurationStatus = require('./models/ConfigurationStatus'); const TcpClientInterface = require('../models/layerProtocols/TcpClientInterface'); - +const ForwardingConstruct = require('../models/ForwardingConstruct'); +const ForwardingDomain = require('../models/ForwardingDomain'); +const FcPort = require('../models/FcPort'); +const onfAttributes = require('../constants/OnfAttributes'); /** * @description This function find a application in the same or different release and updates the http, @@ -179,78 +182,74 @@ exports.findOrCreateApplicationInformationAsync = function (logicalTerminationPo /** * @description This function deletes the tcp,http,operation client for the provided application and release number. - * @param {String} applicationName name of the client application
- * @param {String} releaseNumber release of the client application
- * @returns {Promise} OperationClientLists associated to the application + * @param {String} applicationName name of the client application + * @param {String} releaseNumber release of the client application + * @returns {Promise} status of deletions **/ -exports.deleteApplicationInformationAsync = function (applicationName, releaseNumber, newReleaseForwardingName) { - return new Promise(async function (resolve, reject) { - - let logicalTerminationPointConfigurationStatus; - let httpClientConfigurationStatus; - let tcpClientConfigurationStatusList = []; - let operationClientConfigurationStatusList = []; - try { - let httpClientUuid; - let tcpClientUuid; +exports.deleteApplicationInformationAsync = async function (applicationName, releaseNumber, newReleaseForwardingName) { + let httpClientConfigurationStatus; + let tcpClientConfigurationStatusList = []; + let operationClientConfigurationStatusList = []; + + let httpClientUuid = await httpClientInterface.getHttpClientUuidExcludingOldReleaseAndNewRelease( + applicationName, + releaseNumber, + newReleaseForwardingName + ); + if (httpClientUuid === undefined) { + console.log(`Could not find Http Client UUID with ${applicationName}, ${releaseNumber} and ${newReleaseForwardingName}`); + return new LogicalTerminationPointConfigurationStatus( + operationClientConfigurationStatusList, + httpClientConfigurationStatus, + tcpClientConfigurationStatusList + ); + } + // remove tcp clients + let serverLtpList = await logicalTerminationPoint.getServerLtpListAsync(httpClientUuid); + for (let tcpClientUuid of serverLtpList) { + let isDeleted = await controlConstruct.deleteLogicalTerminationPointAsync(tcpClientUuid); + let tcpClientConfigurationStatus = new ConfigurationStatus( + tcpClientUuid, + '', + isDeleted); + tcpClientConfigurationStatusList.push(tcpClientConfigurationStatus); + } + // remove operations + let clientLtpList = await logicalTerminationPoint.getClientLtpListAsync(httpClientUuid); + for (let operationClientUuid of clientLtpList) { + let isDeleted = await deleteOperationClientLTPAsync(operationClientUuid); + let operationClientConfigurationStatus = new ConfigurationStatus( + operationClientUuid, + '', + isDeleted); + operationClientConfigurationStatusList.push(operationClientConfigurationStatus); + } + // remove http client + let isDeleted = await controlConstruct.deleteLogicalTerminationPointAsync(httpClientUuid); + httpClientConfigurationStatus = new ConfigurationStatus( + httpClientUuid, + '', + isDeleted); + return new LogicalTerminationPointConfigurationStatus( + operationClientConfigurationStatusList, + httpClientConfigurationStatus, + tcpClientConfigurationStatusList + ); +} - httpClientUuid = await httpClientInterface.getHttpClientUuidExcludingOldReleaseAndNewRelease( - applicationName, - releaseNumber, - newReleaseForwardingName - ); - if (httpClientUuid !== undefined) { - let serverLtpList = await logicalTerminationPoint.getServerLtpListAsync( - httpClientUuid); - if (serverLtpList != undefined && serverLtpList.length > 0) { - for (let i = 0; i < serverLtpList.length; i++) { - tcpClientUuid = serverLtpList[i]; - if (tcpClientUuid) { - let isDeleted = await controlConstruct.deleteLogicalTerminationPointAsync( - tcpClientUuid); - let tcpClientConfigurationStatus = new ConfigurationStatus( - tcpClientUuid, - '', - isDeleted); - tcpClientConfigurationStatusList.push(tcpClientConfigurationStatus); - } - } - } - let clientLtpList = await logicalTerminationPoint.getClientLtpListAsync( - httpClientUuid); - if (clientLtpList != undefined && clientLtpList.length > 0) { - for (let i = 0; i < clientLtpList.length; i++) { - let operationClientuuid = clientLtpList[i]; - if (operationClientuuid) { - let isDeleted = await controlConstruct.deleteLogicalTerminationPointAsync( - operationClientuuid); - let operationClientConfigurationStatus = new ConfigurationStatus( - operationClientuuid, - '', - isDeleted); - operationClientConfigurationStatusList.push( - operationClientConfigurationStatus); - } - } - } - let isDeleted = await controlConstruct.deleteLogicalTerminationPointAsync( - httpClientUuid); - httpClientConfigurationStatus = new ConfigurationStatus( - httpClientUuid, - '', - isDeleted); - } - logicalTerminationPointConfigurationStatus = new LogicalTerminationPointConfigurationStatus( - operationClientConfigurationStatusList, - httpClientConfigurationStatus, - tcpClientConfigurationStatusList - ); - resolve(logicalTerminationPointConfigurationStatus); - } catch (error) { - reject(error); +async function deleteOperationClientLTPAsync(operationClientUuid) { + let fcList = await ForwardingDomain.getForwardingConstructListForTheFcPortAsync(operationClientUuid, FcPort.portDirectionEnum.OUTPUT); + for (let fc of fcList) { + let fcPorts = fc[onfAttributes.FORWARDING_CONSTRUCT.FC_PORT] + let filteredFcPorts = fcPorts.filter(fc => + fc[onfAttributes.FC_PORT.LOGICAL_TERMINATION_POINT] === operationClientUuid + ); + for (let port of filteredFcPorts) { + await ForwardingConstruct.deleteFcPortAsync(fc[onfAttributes.GLOBAL_CLASS.UUID], port[onfAttributes.LOCAL_CLASS.LOCAL_ID]); } - }); -} + } + return await controlConstruct.deleteLogicalTerminationPointAsync(operationClientUuid); + } /** * @description This function creates logical-termination-point for the provided values. @@ -1141,4 +1140,4 @@ function findAndUpdateOperationClientInterface(httpClientUuid, operationServerNa reject(error); } }); -} \ No newline at end of file +} diff --git a/server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.test.js b/server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.test.js new file mode 100644 index 00000000..d41c6e78 --- /dev/null +++ b/server/applicationPattern/applicationPattern/onfModel/services/LogicalTerminationPointWithMappingServices.test.js @@ -0,0 +1,79 @@ +const LtpWithMappingServices = require("./LogicalTerminationPointWithMappingServices"); +const HttpClientInterface = require('../models/layerProtocols/HttpClientInterface'); +const ControlConstruct = require('../models/ControlConstruct'); +const LogicalTerminationPoint = require('../models/LogicalTerminationPoint'); +const ConfigurationStatus = require('./models/ConfigurationStatus'); +const LogicalTerminationPointConfigurationStatus = require('./models/logicalTerminationPoint/ConfigurationStatus'); +const ForwardingDomain = require('../models/ForwardingDomain'); +const ForwardingConstruct = require('../models/ForwardingConstruct'); + +jest.mock('../models/layerProtocols/HttpClientInterface'); +jest.mock('../models/ControlConstruct'); +jest.mock('../models/LogicalTerminationPoint'); +jest.mock('../models/ForwardingDomain'); +jest.mock('../models/ForwardingConstruct'); + +const fc = { + "uuid" : "ol-2-0-1-op-fc-bm-010", + "name" : [], + "fc-port" : [ + { + "local-id" : "000", + "port-direction" : "core-model-1-4:PORT_DIRECTION_TYPE_MANAGEMENT", + "logical-termination-point" : "ol-2-0-1-op-s-bm-009" + }, + { + "local-id" : "100", + "port-direction" : "core-model-1-4:PORT_DIRECTION_TYPE_INPUT", + "logical-termination-point" : "ol-2-0-1-op-s-bm-004" + }, + { + "local-id" : "200", + "port-direction" : "core-model-1-4:PORT_DIRECTION_TYPE_OUTPUT", + "logical-termination-point" : "ol-2-0-1-op-c-im-cc-1-0-0-004" + }, + { + "local-id" : "201", + "port-direction" : "core-model-1-4:PORT_DIRECTION_TYPE_OUTPUT", + "logical-termination-point" : "nl-2-0-1-op-c-bm-alt-1-0-0-006" + } + ] +}; + +beforeEach(() => { + +}); + +test("deleteApplicationInformationAsync", async () => { + jest.spyOn(LogicalTerminationPoint, 'getServerLtpListAsync').mockReturnValue(["ol-2-0-1-tcp-c-cc-1-0-0-000"]); + jest.spyOn(LogicalTerminationPoint, 'getClientLtpListAsync').mockReturnValue( + ["ol-2-0-1-op-c-im-cc-1-0-0-004", "ol-2-0-1-op-c-im-cc-1-0-0-005"] + ); + jest.spyOn(ControlConstruct, 'deleteLogicalTerminationPointAsync').mockReturnValue(true); + jest.spyOn(HttpClientInterface, 'getHttpClientUuidExcludingOldReleaseAndNewRelease').mockReturnValue("ol-2-0-1-http-c-cc-1-0-0-000"); + jest.spyOn(ForwardingDomain, 'getForwardingConstructListForTheFcPortAsync').mockReturnValue([fc]); + let result = await LtpWithMappingServices.deleteApplicationInformationAsync( + "foo", "bar", "baz" + ); + + let expectedOperationClientConfigurationStatusList = [ + new ConfigurationStatus("ol-2-0-1-op-c-im-cc-1-0-0-004", '', true), + new ConfigurationStatus("ol-2-0-1-op-c-im-cc-1-0-0-005", '', true) + ]; + let expectedHttpClientConfigurationStatus = new ConfigurationStatus("ol-2-0-1-http-c-cc-1-0-0-000", '', true) + let expectedTcpClientConfigurationStatusList = [ + new ConfigurationStatus("ol-2-0-1-tcp-c-cc-1-0-0-000", '', true), + ]; + + expect(ForwardingConstruct.deleteFcPortAsync).toHaveBeenCalledWith("ol-2-0-1-op-fc-bm-010", "200"); + + expect(result).toStrictEqual(new LogicalTerminationPointConfigurationStatus( + expectedOperationClientConfigurationStatusList, + expectedHttpClientConfigurationStatus, + expectedTcpClientConfigurationStatusList + )); +}); + +afterEach(() => { + jest.resetAllMocks(); +});