From 0fbf28a7dbfcec11fdd54eb3f0c879a45da03d11 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 17 Mar 2025 17:34:09 +0100 Subject: [PATCH 01/22] Remove debugger instruction set --- .../CyclicProcessService/cyclicProcess.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index 75c4987..99bcfd0 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -62,7 +62,6 @@ function prepareObjectForWindow(deviceListIndex) { return windowObject; } catch (error) { console.error("Error in prepareObjectForWindow (" + error + ")"); - debugger; } } @@ -82,7 +81,6 @@ function checkDeviceExistsInSlidingWindow(deviceNodeId) { return DEVICE_NOT_PRESENT; } catch (error) { console.log("Error in checkDeviceExistsInSlidingWindow (" + error + ")"); - debugger; } } @@ -103,7 +101,6 @@ function getNextDeviceListIndex() { return lastDeviceListIndex; } catch (error) { console.log("Error in getNextDeviceListIndex (" + error + ")"); - debugger; } } @@ -143,7 +140,6 @@ function addNextDeviceListElementInWindow() { return elementAdded; } catch (error) { console.log("Error in addNextDeviceListElementInWindow (" + error + ")") - debugger } } @@ -162,7 +158,6 @@ function discardElementFromDeviceList(nodeId) { } } catch (error) { console.log("Error in discardElementFromDeviceList (" + error + ")"); - debugger; } } @@ -267,7 +262,6 @@ function startTtlChecking() { } catch (error) { console.log("Error in startTtlChecking (" + error + ")"); - debugger; } } @@ -350,7 +344,6 @@ async function requestMessage(index) { }) } catch (error) { console.log("Error in requestMessage (" + error + ")"); - debugger; } } From b15e79b0938f4dc77345e5401fc89e9b06b1ddc4 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 17 Mar 2025 17:34:28 +0100 Subject: [PATCH 02/22] Adding Pino Logger --- server/package.json | 5 ++++- server/service/LoggingService.js | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 server/service/LoggingService.js diff --git a/server/package.json b/server/package.json index 99fbf2b..13c3c45 100644 --- a/server/package.json +++ b/server/package.json @@ -18,6 +18,9 @@ "oas3-tools": "^2.2.3", "onf-core-model-ap": "2.1.2", "onf-core-model-ap-bs": "2.1.2", - "openbackhaul-oas3-tools": "2.3.1-alpha.3" + "openbackhaul-oas3-tools": "2.3.1-alpha.3", + "pino": "^9.4.0", + "pino-pretty": "^11.2.2", + "pino-roll": "^2.2.0" } } diff --git a/server/service/LoggingService.js b/server/service/LoggingService.js new file mode 100644 index 0000000..2c74c1c --- /dev/null +++ b/server/service/LoggingService.js @@ -0,0 +1,26 @@ +const pino = require('pino'); +const path = require("path"); + +// configuration for pino with pretty console output and logfile output +const transports = pino.transport({ + targets: [ + { + level: 'info', + target: 'pino-pretty', + options: { colorize: true } + }, + { + level: 'trace', + target: 'pino-roll', + options: { file: path.join(__dirname, '../logs/NetExplorerProxy'), extension: '.log', mkdir: true, + frequency: 'daily', dateFormat: 'yyyy-MM-dd', size: "1m", "limit.count": 15 } + } + ] +}); + +// create pino logger instance +const logger = pino({level: 'trace'}, transports); + +exports.getLogger = function getLogger() { + return logger; +}; From 54afd42c42f94797d801cb092b7936cf39278972 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 17 Mar 2025 18:20:58 +0100 Subject: [PATCH 03/22] Update Logname file --- server/service/LoggingService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/service/LoggingService.js b/server/service/LoggingService.js index 2c74c1c..9759b16 100644 --- a/server/service/LoggingService.js +++ b/server/service/LoggingService.js @@ -12,7 +12,7 @@ const transports = pino.transport({ { level: 'trace', target: 'pino-roll', - options: { file: path.join(__dirname, '../logs/NetExplorerProxy'), extension: '.log', mkdir: true, + options: { file: path.join(__dirname, '../logs/MacAddressTableRecorder'), extension: '.log', mkdir: true, frequency: 'daily', dateFormat: 'yyyy-MM-dd', size: "1m", "limit.count": 15 } } ] From 0e9a9170dcc1192d8f6fc48e515f6d2f0e6c7428 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 17 Mar 2025 18:22:47 +0100 Subject: [PATCH 04/22] Replace console output with Logger --- server/index.js | 21 ++--- server/service/IndividualServicesService.js | 79 +++++++++---------- .../ElasticsearchPreparation.js | 6 +- 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/server/index.js b/server/index.js index 99a99c0..5086002 100644 --- a/server/index.js +++ b/server/index.js @@ -1,4 +1,5 @@ const cp = require('./service/individualServices/CyclicProcessService/cyclicProcess'); +const logger = require('./service/LoggingService.js').getLogger(); 'use strict'; @@ -15,14 +16,14 @@ const { env } = require('process'); // uncomment if you do not want to validate security e.g. operation-key, basic auth, etc //appCommons.openApiValidatorOptions.validateSecurity = false; if (process.env.DEBUG && process.env.DEBUG.toLowerCase() === "true") { - console.warn("Working in debug mode"); - console.warn("Checking validation") + logger.warn("Working in debug mode"); + logger.warn("Checking validation") appCommons.openApiValidatorOptions.validateSecurity = false; // appCommons.openApiValidatorOptions.validateResponses = false; // appCommons.openApiValidatorOptions.validateRequests = false; - console.warn("Validate Security: " + appCommons.openApiValidatorOptions.validateSecurity); - console.warn("Validate Responses: " + appCommons.openApiValidatorOptions.validateResponses); - console.warn("Validate Requests: " + appCommons.openApiValidatorOptions.validateRequests); + logger.warn("Validate Security: " + appCommons.openApiValidatorOptions.validateSecurity); + logger.warn("Validate Responses: " + appCommons.openApiValidatorOptions.validateResponses); + logger.warn("Validate Requests: " + appCommons.openApiValidatorOptions.validateRequests); } // swaggerRouter configuration @@ -39,19 +40,19 @@ appCommons.setupExpressApp(app); global.databasePath = './database/load.json' if (process.env.DEBUG && process.env.DEBUG.toLowerCase() === "true") { - console.warn("Working in debug mode"); + logger.warn("Working in debug mode"); global.databasePath = './server/database/load.json' - console.warn("Load data from: " + global.databasePath) + logger.warn("Load data from: " + global.databasePath) } prepareElasticsearch().catch(err => { - console.error(`Error preparing Elasticsearch : ${err}`); + logger.error(`Error preparing Elasticsearch : ${err}`); }).finally( () => { // Initialize the Swagger middleware http.createServer(app).listen(serverPort, function () { - console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort); - console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort); + logger.info('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort); + logger.info('Swagger-ui is available on http://localhost:%d/docs', serverPort); }); appCommons.performApplicationRegistration(); diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 132e2c0..b7bba4e 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -25,6 +25,7 @@ const genericRepresentation = require('onf-core-model-ap-bs/basicServices/Generi const createHttpError = require("http-errors"); const axios = require('axios'); const authKey = require("../application-data/encrypted-odl-key.json"); +const logger = require('../service/LoggingService.js').getLogger(); var appCommons = require('onf-core-model-ap/applicationPattern/commons/AppCommons'); @@ -227,7 +228,7 @@ const RequestForDeleteEquipmentIntoElasticSearch = async function (mountName) { } else { resolve(null); } - console.log('Remove mountName = ' + mountName); + logger.info("Remove mount-name = ", mountName); } catch (error) { reject(error); @@ -318,7 +319,7 @@ async function executeAfterWait() { // Wait 300 seconds await waitAsync(30000); } catch (error) { - console.error('An error occurred during the wait:', error); + logger.error('An error occurred during the wait:', error); } } @@ -336,7 +337,7 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor // Join the elements with a comma and a space let result = outputArray.join(", "); - console.log(result); + logger.info(result); } const refreshIndex = async () => { @@ -344,9 +345,9 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor let client = await elasticsearchService.getClient(false); let indexAlias = await getIndexAliasAsync(); let result = await client.indices.refresh({ index: indexAlias }); - console.log(`Index ${indexAlias} refreshed successfully`); + logger.info(`Index ${indexAlias} refreshed successfully`); } catch (error) { - console.error(`Error refreshing index ${indexAlias}:`, error); + logger.error(`Error refreshing index ${indexAlias}:`, error); } }; @@ -359,10 +360,10 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor //"mount-name-list" from ES try { oldConnectedListFromES = await RequestForListOfConnectedEquipmentFromElasticSearch(); - console.log("mount-name-list (ES), number of elements:" + oldConnectedListFromES['mount-name-list'].length); + logger.info("mount-name-list (ES), number of elements:" + oldConnectedListFromES['mount-name-list'].length); } catch (error) { - console.log("mount-name-list is not present (elastic search error)"); + logger.error("mount-name-list is not present (elastic search error)"); } try { @@ -378,15 +379,15 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor newConnectedListFromMwdi = await EmbeddingCausesRequestForListOfDevicesAtMwdi(user, originator, xCorrelator, traceIndicator, customerJourney); if ((newConnectedListFromMwdi != null) && (newConnectedListFromMwdi.length == 0)) { - console.warning('No Equipment connected. Wait 30 seconds and retry to read...'); + logger.warn('No Equipment connected. Wait 30 seconds and retry to read...'); await executeAfterWait(); } else { - console.log("mount-name-list (MWDI), number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); + logger.info("mount-name-list (MWDI), number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); } } catch (error) { - console.error(error + ', wait 30 seconds and retry to read...'); + logger.error(error + ', wait 30 seconds and retry to read...'); await executeAfterWait(); newConnectedListFromMwdi = null; } @@ -396,16 +397,16 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor //list of equipment that was connected (mac-address data in ES) but now that are not connected listJsonDisconnectedEq = await findNotConnectedElements(oldConnectedListFromES, newConnectedListFromMwdi); if (listJsonDisconnectedEq != null) { - console.log("list of equipments disconnected, number of elements: -" + listJsonDisconnectedEq['mount-name-list'].length + " => remove mac-address data from ES"); + logger.info("list of equipments disconnected, number of elements: -" + listJsonDisconnectedEq['mount-name-list'].length + " => remove mac-address data from ES"); //printArray(listJsonDisconnectedEq['mount-name-list']); } else { - console.log("list of equipments disconnected, number of elements:" + 0); + logger.info("list of equipments disconnected, number of elements:" + 0); } } catch (error) { listJsonDisconnectedEq = null; - console.log('No Equipment disconnected'); + logger.info('No Equipment disconnected'); } //Write new "mount-name-list" list into ES @@ -413,14 +414,14 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor if (areEqualArray(oldConnectedListFromES, newConnectedListFromMwdi) == false) { try { result = await RequestForWriteListConnectedEquipmentIntoElasticSearch(newConnectedListFromMwdi); - console.log("Write new mount-name-list into ES, number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); + logger.info("Write new mount-name-list into ES, number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); } catch (error) { - console.log('mount-name-list are not updated, no difference between old ES mount-name-list and MWDI mount-name-list currently read'); + logger.info('mount-name-list are not updated, no difference between old ES mount-name-list and MWDI mount-name-list currently read'); } } else { - console.log("Write new mount-name-list, number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); + logger.info("Write new mount-name-list, number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); } if (listJsonDisconnectedEq != null) { @@ -434,13 +435,13 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor await RequestForDeleteEquipmentIntoElasticSearch(elementToRemove); } catch (error) { - console.error('Error during remove operation of old mac address data into db (' + elementToRemove + ')'); + logger.error('Error during remove operation of old mac address data into db (' + elementToRemove + ')'); } } } } catch (error) { - console.error('Error during remove operation of old mac address data into db'); + logger.error('Error during remove operation of old mac address data into db'); } } } @@ -484,7 +485,7 @@ const EmbeddingCausesRequestForListOfApplicationsAtRo = async function (user, or let remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName; - console.log("url = " + finalUrl); + logger.info("url = ", finalUrl); let httpRequestHeader = new RequestHeader( user, @@ -567,7 +568,7 @@ const EmbeddingCausesRequestForListOfDevicesAtMwdi = async function (user, origi let remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName; - console.log("url = " + finalUrl); + logger.info("url = ", finalUrl); let httpRequestHeader = new RequestHeader( @@ -674,7 +675,7 @@ const RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSear transformedArray = filteredObjects.map(obj => transformData(obj)); if (transformedArray != null) { - var response = {}; + let response = {}; response['application/json'] = { 'targetMacAddress': transformedArray }; @@ -813,7 +814,7 @@ exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = asy resolve(fullResponse); }) .catch(error => { - console.error(error); + logger.error(error); }); }); } @@ -906,7 +907,6 @@ exports.provideMacTableOfAllDevices = async function (user, originator, xCorrela PromptForProvidingAllMacTablesCausesReadingFromElasticSearch() .then(function (response) { const orderedArray = response.map(obj => orderData(obj)); - //console.log("Data from orderedArray:", response); resolve(orderedArray); }) .catch(function (error) { @@ -957,7 +957,7 @@ const PromptForProvidingSpecificMacTableCausesReadingFromElasticSearch = async f }; }); - var response = {}; + let response = {}; response['application/json'] = { 'mac-address': formattedEntries }; @@ -1020,7 +1020,7 @@ exports.decodeAuthorizationCodeAndExtractUserName = function (authorizationCode) let userName = base64DecodedString.split(":")[0]; return userName; } catch (error) { - console.error(`Could not decode authorization code "${authorizationCode}". Got ${error}.`); + logger.error(`Could not decode authorization code "${authorizationCode}". Got ${error}.`); return undefined; } } @@ -1102,15 +1102,15 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched throw new Error(" Empty data from " + fullUrl); } } catch (error) { - console.log("***********catch axios try Error '404' for URL:", fullUrl) - console.log("*********** response status:", response.status) - console.log("*********** response messge:", response.data) + logger.error("***********catch axios try Error '404' for URL:", fullUrl) + logger.error("*********** response status:", response.status) + logger.error("*********** response messge:", response.data) throw error; } } catch (error) { - console.log("***********catch main try Error '404' for URL:", fullUrl) - console.log("*********** response status:", response.status) - console.log("*********** response messge:", response.data) + logger.error("***********catch main try Error '404' for URL:", fullUrl) + logger.error("*********** response status:", response.status) + logger.error("*********** response messge:", response.data) throw error; } } @@ -1201,7 +1201,6 @@ async function PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIn try { if (body == "LTP-MNGT") { - //console.log("STEP3(" + mountName + ") = LAN-MNGT"); return "LAN-MNGT"; } @@ -1324,9 +1323,9 @@ async function PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch if (body && body["mac-address"] && Array.isArray(body["mac-address"]) && body["mac-address"].length > 0 && body["mac-address"][0]["mount-name"]) { mountName = body["mac-address"][0]["mount-name"]; } else { - console.error('********************************* Body *******************************************') - console.error(JSON.stringify(body)) - console.error('**********************************************************************************') + logger.error('********************************* Body *******************************************') + logger.error(JSON.stringify(body)) + logger.error('**********************************************************************************') throw new Error("Writing operation into Elastic Search Failed : body structure is not correct"); } @@ -1363,7 +1362,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch }); if (/^20[0-9]$/.test(response.status.toString())) //bug @216 { - console.log("Writing (" + mountName + ") data into Elastic Search "); + logger.info("Writing (" + mountName + ") data into Elastic Search "); return (response.data); } else { @@ -1443,7 +1442,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesSendingAnswerToRequestor httpRequestHeaderRequestor = onfAttributeFormatter.modifyJsonObjectKeysToKebabCase(httpRequestHeader); let result = onfAttributeFormatter.modifyJsonObjectKeysToKebabCase(data); - console.log('Send data to Requestor:' + requestorUrl); + logger.info('Send data to Requestor:' + requestorUrl); try { let response = await axios.post(requestorUrl, data, { @@ -1616,9 +1615,9 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, }); if (step2Data.length == 0) { - console.warn("Step2Data is empty!"); - console.warn("Forwarding domain: ", FDomainArray); - console.warn("Data from request:", dataFromRequest) + logger.warn("Step2Data is empty!"); + logger.warn("Forwarding domain: ", FDomainArray); + logger.warn("Data from request:", dataFromRequest) } step2DataArray = Array.from(step2Data); diff --git a/server/service/individualServices/ElasticsearchPreparation.js b/server/service/individualServices/ElasticsearchPreparation.js index 36517bc..17faacf 100644 --- a/server/service/individualServices/ElasticsearchPreparation.js +++ b/server/service/individualServices/ElasticsearchPreparation.js @@ -1,4 +1,6 @@ const { elasticsearchService, getIndexAliasAsync, operationalStateEnum } = require('onf-core-model-ap/applicationPattern/services/ElasticsearchService'); +const logger = require('../LoggingService.js').getLogger(); + /** * @description Elasticsearch preparation. Checks if ES instance is configured properly. @@ -17,12 +19,12 @@ module.exports = async function prepareElasticsearch() { console.log("Configuring Elasticsearch..."); let ping = await elasticsearchService.getElasticsearchClientOperationalStateAsync(); if (ping === operationalStateEnum.UNAVAILABLE) { - console.error(`Elasticsearch unavailable. Skipping Elasticsearch configuration.`); + logger.error(`Elasticsearch unavailable. Skipping Elasticsearch configuration.`); return; } await createIndexTemplate(); await elasticsearchService.createAlias(); - console.log('Elasticsearch is properly configured!'); + logger.info('Elasticsearch is properly configured!'); } /** From 08c9e9c1f2f61178d6813aa981f7f3f037e6aaa0 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 17 Mar 2025 18:24:57 +0100 Subject: [PATCH 05/22] Replace a proper logger in CycleProcess --- .../CyclicProcessService/cyclicProcess.js | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index 99bcfd0..8e35ee3 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -10,6 +10,7 @@ const onfPaths = require('onf-core-model-ap/applicationPattern/onfModel/constant const onfAttributes = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfAttributes'); const forwardingDomain = require('onf-core-model-ap/applicationPattern/onfModel/models/ForwardingDomain'); var fileOperation = require('onf-core-model-ap/applicationPattern/databaseDriver/JSONDriver'); +const logger = require('../../LoggingService.js').getLogger(); const DEVICE_NOT_PRESENT = -1; let maximumNumberOfRetries = 1; @@ -61,7 +62,7 @@ function prepareObjectForWindow(deviceListIndex) { }; return windowObject; } catch (error) { - console.error("Error in prepareObjectForWindow (" + error + ")"); + logger.error("Error in prepareObjectForWindow (" + error + ")"); } } @@ -80,7 +81,7 @@ function checkDeviceExistsInSlidingWindow(deviceNodeId) { } return DEVICE_NOT_PRESENT; } catch (error) { - console.log("Error in checkDeviceExistsInSlidingWindow (" + error + ")"); + logger.error("Error in checkDeviceExistsInSlidingWindow (" + error + ")"); } } @@ -100,7 +101,7 @@ function getNextDeviceListIndex() { } return lastDeviceListIndex; } catch (error) { - console.log("Error in getNextDeviceListIndex (" + error + ")"); + logger.error("Error in getNextDeviceListIndex (" + error + ")"); } } @@ -139,7 +140,7 @@ function addNextDeviceListElementInWindow() { return elementAdded; } catch (error) { - console.log("Error in addNextDeviceListElementInWindow (" + error + ")") + logger.error("Error in addNextDeviceListElementInWindow (" + error + ")") } } @@ -157,7 +158,7 @@ function discardElementFromDeviceList(nodeId) { } } } catch (error) { - console.log("Error in discardElementFromDeviceList (" + error + ")"); + logger.error("Error in discardElementFromDeviceList (" + error + ")"); } } @@ -188,23 +189,23 @@ function printListDevice(listName, list) { */ function printLog(text, print_log) { if (print_log) { - console.log(text); + logger.info(text); } } function printErr(text, print_log) { if (print_log) { - console.error(text); + logger.error(text); } } -function convertTime(millisecondi) { - let secondi = Math.floor(millisecondi / 1000); - let ore = Math.floor(secondi / 3600); - let minuti = Math.floor((secondi % 3600) / 60); - let restantiSecondi = secondi % 60; +function convertTime(milliseconds) { + let seconds = Math.floor(milliseconds / 1000); + let hours = Math.floor(seconds / 3600); + let minutes = Math.floor((seconds % 3600) / 60); + let modSeconds = seconds % 60; - return `${ore.toString().padStart(2, '0')}:${minuti.toString().padStart(2, '0')}:${restantiSecondi.toString().padStart(2, '0')}`; + return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${modSeconds.toString().padStart(2, '0')}`; } @@ -261,7 +262,7 @@ function startTtlChecking() { handle = setInterval(upgradeTtl, 1000); } catch (error) { - console.log("Error in startTtlChecking (" + error + ")"); + logger.error("Error in startTtlChecking (" + error + ")"); } } @@ -343,7 +344,7 @@ async function requestMessage(index) { } }) } catch (error) { - console.log("Error in requestMessage (" + error + ")"); + logger.error("Error in requestMessage (" + error + ")"); } } @@ -423,9 +424,7 @@ async function MATRCycle(firstTime, logging_level) { const formattedDate = `${day}/${month}/${year} ${formattedHours}:${formattedMinutes}:${formattedSeconds}`; printLog('*****************************************************************', print_log_level >= 1); - printLog(' ', print_log_level >= 1); printLog(' MATR CYCLE START AT: ' + formattedDate, print_log_level >= 1); - printLog(' ', print_log_level >= 1); printLog('*****************************************************************', print_log_level >= 1); print_log_level = logging_level; @@ -457,7 +456,7 @@ async function MATRCycle(firstTime, logging_level) { startTtlChecking(); } catch (error) { - console.error("Error on MATR cycle: " + error); + logger.error("Error on MATR cycle: ", error); } }, remainder); From 9f8a18062881098ba6b742ae7ab0bf9da2e20066 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 17 Mar 2025 18:34:41 +0100 Subject: [PATCH 06/22] Adding Log to elasticsearchpreparation --- server/service/individualServices/ElasticsearchPreparation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/service/individualServices/ElasticsearchPreparation.js b/server/service/individualServices/ElasticsearchPreparation.js index 17faacf..daff2cc 100644 --- a/server/service/individualServices/ElasticsearchPreparation.js +++ b/server/service/individualServices/ElasticsearchPreparation.js @@ -16,7 +16,7 @@ const logger = require('../LoggingService.js').getLogger(); * @returns {Promise} */ module.exports = async function prepareElasticsearch() { - console.log("Configuring Elasticsearch..."); + logger.info("Configuring Elasticsearch..."); let ping = await elasticsearchService.getElasticsearchClientOperationalStateAsync(); if (ping === operationalStateEnum.UNAVAILABLE) { logger.error(`Elasticsearch unavailable. Skipping Elasticsearch configuration.`); From d26153b387cc3e6b9de315f914ea41e222a1a483 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Tue, 18 Mar 2025 09:32:15 +0100 Subject: [PATCH 07/22] Update Libs list (ONF) --- server/service/HttpClientService.js | 5 ++++- server/service/OperationClientService.js | 4 +++- server/service/OperationServerService.js | 4 +++- server/service/TcpClientService.js | 7 +++++-- server/service/TcpServerService.js | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/service/HttpClientService.js b/server/service/HttpClientService.js index b55d5c0..80ba2ad 100644 --- a/server/service/HttpClientService.js +++ b/server/service/HttpClientService.js @@ -1,9 +1,12 @@ 'use strict'; + +// ONF Libs var fileOperation = require('onf-core-model-ap/applicationPattern/databaseDriver/JSONDriver'); -const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); const ForwardingAutomationService = require('onf-core-model-ap/applicationPattern/onfModel/services/ForwardingConstructAutomationServices'); const httpClientInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/HttpClientInterface'); +// Custom imports +const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); /** * Returns name of application to be addressed diff --git a/server/service/OperationClientService.js b/server/service/OperationClientService.js index 64a7cf6..a5e6e7f 100644 --- a/server/service/OperationClientService.js +++ b/server/service/OperationClientService.js @@ -1,9 +1,11 @@ 'use strict'; + +// ONF Libs var fileOperation = require('onf-core-model-ap/applicationPattern/databaseDriver/JSONDriver'); -const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); const ForwardingAutomationService = require('onf-core-model-ap/applicationPattern/onfModel/services/ForwardingConstructAutomationServices'); const operationClientInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/OperationClientInterface'); +const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); /** * Returns detailed logging configuration. diff --git a/server/service/OperationServerService.js b/server/service/OperationServerService.js index be8d996..d1febd7 100644 --- a/server/service/OperationServerService.js +++ b/server/service/OperationServerService.js @@ -1,9 +1,11 @@ 'use strict'; + +// ONF Libs var fileOperation = require('onf-core-model-ap/applicationPattern/databaseDriver/JSONDriver'); -const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); const ForwardingAutomationService = require('onf-core-model-ap/applicationPattern/onfModel/services/ForwardingConstructAutomationServices'); const operationServerInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/OperationServerInterface'); +const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); /** * Returns the configured life cycle state of the operation diff --git a/server/service/TcpClientService.js b/server/service/TcpClientService.js index ec56a55..9d1ab1e 100644 --- a/server/service/TcpClientService.js +++ b/server/service/TcpClientService.js @@ -1,11 +1,14 @@ 'use strict'; + +// ONF Libs var fileOperation = require('onf-core-model-ap/applicationPattern/databaseDriver/JSONDriver'); -const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); const ForwardingAutomationService = require('onf-core-model-ap/applicationPattern/onfModel/services/ForwardingConstructAutomationServices'); const tcpClientInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/TcpClientInterface'); -//const prepareElasticsearch = require('./individualServices/ElasticsearchPreparation'); const { isTcpClientElasticsearch, elasticsearchService } = require('onf-core-model-ap/applicationPattern/services/ElasticsearchService'); +// Other Libs +const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); +//const prepareElasticsearch = require('./individualServices/ElasticsearchPreparation'); /** * Returns remote address diff --git a/server/service/TcpServerService.js b/server/service/TcpServerService.js index ce4be09..0e3c747 100644 --- a/server/service/TcpServerService.js +++ b/server/service/TcpServerService.js @@ -1,9 +1,11 @@ 'use strict'; + +// ONF Libs var fileOperation = require('onf-core-model-ap/applicationPattern/databaseDriver/JSONDriver'); -const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); const ForwardingAutomationService = require('onf-core-model-ap/applicationPattern/onfModel/services/ForwardingConstructAutomationServices'); const tcpServerInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/TcpServerInterface'); +const prepareForwardingAutomation = require('./individualServices/PrepareForwardingAutomation'); /** From bb6c8e3197dfb96a427ea51348150a1c5f2f8bbb Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Tue, 18 Mar 2025 09:32:55 +0100 Subject: [PATCH 08/22] Update log level --- server/service/LoggingService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/service/LoggingService.js b/server/service/LoggingService.js index 9759b16..0022028 100644 --- a/server/service/LoggingService.js +++ b/server/service/LoggingService.js @@ -5,7 +5,7 @@ const path = require("path"); const transports = pino.transport({ targets: [ { - level: 'info', + level: 'debug', target: 'pino-pretty', options: { colorize: true } }, From 1967be1a789b34268a425aec737bb2ea97d55c29 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Tue, 18 Mar 2025 09:36:08 +0100 Subject: [PATCH 09/22] Update cycleProcess.js - Reorder libs imports - Use constant for 'node-id' string reference - Adding comments beside code --- .../CyclicProcessService/cyclicProcess.js | 79 +++++++++++-------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index 8e35ee3..e490e18 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -1,15 +1,13 @@ 'use strict'; -const { strict } = require('assert'); -const { setTimeout } = require('timers'); -const path = require("path"); -const individualServices = require("./../../IndividualServicesService.js"); -const { elasticsearchService } = require('onf-core-model-ap/applicationPattern/services/ElasticsearchService'); +// ONF Libs +const profileCollection = require('onf-core-model-ap/applicationPattern/onfModel/models/ProfileCollection'); const RequestHeader = require("onf-core-model-ap/applicationPattern/rest/client/RequestHeader"); -const onfPaths = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfPaths'); -const onfAttributes = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfAttributes'); const forwardingDomain = require('onf-core-model-ap/applicationPattern/onfModel/models/ForwardingDomain'); -var fileOperation = require('onf-core-model-ap/applicationPattern/databaseDriver/JSONDriver'); + +// Other Libs +const { setTimeout } = require('timers'); +const individualServices = require("./../../IndividualServicesService.js"); const logger = require('../../LoggingService.js').getLogger(); const DEVICE_NOT_PRESENT = -1; @@ -26,25 +24,30 @@ let stop = false; var handle = 0; let loopStartTime = 0; +// String constants +const NODE_ID = 'node-id'; -async function sendRequest(device, user, originator, xCorrelator, traceIndicator, customerJourney) { - let ret; +/* + * Function that send request to retrieve Mac Table from specific device +*/ +async function sendRequest(device, user, originator, xCorrelator, traceIndicator, customerJourney) { const body = { - "mount-name": device['node-id'] + "mount-name": device[NODE_ID] }; try { - ret = await individualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney); + await individualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney); + return { 'ret': { 'code': 200, 'message': 'Correctly Managed' }, - 'node-id': device['node-id'] + 'node-id': device[NODE_ID] }; } catch (error) { return { 'ret': { 'code': 500, 'message': error.message }, - 'node-id': device['node-id'] + 'node-id': device[NODE_ID] }; } } @@ -75,7 +78,7 @@ function prepareObjectForWindow(deviceListIndex) { function checkDeviceExistsInSlidingWindow(deviceNodeId) { try { for (let i = 0; i < slidingWindow.length; i++) { - if (slidingWindow[i]['node-id'] == deviceNodeId) { + if (slidingWindow[i][NODE_ID] == deviceNodeId) { return i; } } @@ -168,7 +171,7 @@ function discardElementFromDeviceList(nodeId) { function printList(listName, list) { let listGraph = listName + ': ['; for (let i = 0; i < list.length; i++) { - listGraph += (i < list.length - 1) ? (list[i]['node-id'] + '|') : list[i]['node-id']; + listGraph += (i < list.length - 1) ? (list[i][NODE_ID] + '|') : list[i][NODE_ID]; } listGraph += "] (" + list.length + ")"; return listGraph; @@ -199,6 +202,7 @@ function printErr(text, print_log) { } } + function convertTime(milliseconds) { let seconds = Math.floor(milliseconds / 1000); let hours = Math.floor(seconds / 3600); @@ -223,10 +227,10 @@ function startTtlChecking() { slidingWindow[index].ttl -= 1; if (slidingWindow[index].ttl == 0) { if (slidingWindow[index].retries == 0) { - printLog("Element " + slidingWindow[index]['node-id'] + " Timeout/Retries. -> Dropped from Sliding Window", print_log_level >= 2); + printLog("Element " + slidingWindow[index][NODE_ID] + " Timeout/Retries. -> Dropped from Sliding Window", print_log_level >= 2); slidingWindow.splice(index, 1); if (addNextDeviceListElementInWindow()) { - printLog('Added element ' + slidingWindow[slidingWindow.length - 1]['node-id'] + ' in window and sent request...', print_log_level >= 2); + printLog('Added element ' + slidingWindow[slidingWindow.length - 1][NODE_ID] + ' in window and sent request...', print_log_level >= 2); //printLog(printList('Sliding Window', slidingWindow), print_log_level >= 1); requestMessage(slidingWindow.length - 1); } @@ -238,7 +242,7 @@ function startTtlChecking() { } else { slidingWindow[index].ttl = responseTimeout; slidingWindow[index].retries -= 1; - printLog("Element " + slidingWindow[index]['node-id'] + " Timeout. -> Resend the request...", print_log_level >= 2); + printLog("Element " + slidingWindow[index][NODE_ID] + " Timeout. -> Resend the request...", print_log_level >= 2); requestMessage(index); } } @@ -291,18 +295,18 @@ async function requestMessage(index) { let customerJourney = requestHeader.customerJourney; sendRequest(slidingWindow[index], user, originator, xCorrelator, traceIndicator, customerJourney).then(retObj => { - if (retObj.ret.code != 200) { + if (retObj.ret.code != 200) { // Response error // Response error management - let elementIndex = checkDeviceExistsInSlidingWindow(retObj['node-id']); + let elementIndex = checkDeviceExistsInSlidingWindow(retObj[NODE_ID]); if (elementIndex == DEVICE_NOT_PRESENT) { - printLog('Response from element ' + retObj['node-id'] + ' not more present in Sliding Window. Ignore that.', print_log_level >= 2); + printLog('Response from element ' + retObj[NODE_ID] + ' not more present in Sliding Window. Ignore that.', print_log_level >= 2); } else { if (slidingWindow[elementIndex].retries == 0) { - printErr(retObj.ret.code + ' - ' + retObj.ret.message + ' from element (II time) ' + retObj['node-id'] + ' --> Dropped from Sliding Window', print_log_level >= 2); + printErr(retObj.ret.code + ' - ' + retObj.ret.message + ' from element (II time) ' + retObj[NODE_ID] + ' --> Dropped from Sliding Window', print_log_level >= 2); slidingWindow.splice(elementIndex, 1); if (addNextDeviceListElementInWindow()) { - printLog('Add element ' + slidingWindow[slidingWindow.length - 1]['node-id'] + ' in Sliding Window and send request...', print_log_level >= 2); + printLog('Add element ' + slidingWindow[slidingWindow.length - 1][NODE_ID] + ' in Sliding Window and send request...', print_log_level >= 2); //printLog(printListDevice('Device List', deviceList), print_log_level >= 2); //printLog(printList('Sliding Window', slidingWindow), print_log_level >= 1); requestMessage(slidingWindow.length - 1); @@ -313,23 +317,22 @@ async function requestMessage(index) { } } else { - printErr(retObj.ret.code + ' - ' + retObj.ret.message + ' from element (I time) ' + retObj['node-id'] + ' Resend the request....', print_log_level >= 2); + printErr(retObj.ret.code + ' - ' + retObj.ret.message + ' from element (I time) ' + retObj[NODE_ID] + ' Resend the request....', print_log_level >= 2); slidingWindow[elementIndex].ttl = responseTimeout; slidingWindow[elementIndex].retries -= 1; requestMessage(elementIndex); } } - } else { - //return OK + } else { // Response is like 2XX - OK printLog('****************************************************************************************************', print_log_level >= 2); - let elementIndex = checkDeviceExistsInSlidingWindow(retObj['node-id']); + let elementIndex = checkDeviceExistsInSlidingWindow(retObj[NODE_ID]); if (elementIndex == DEVICE_NOT_PRESENT) { - printLog('Response from element ' + retObj['node-id'] + ' not more present in Sliding Window. Ignore that.', print_log_level >= 2); + printLog('Response from element ' + retObj[NODE_ID] + ' not more present in Sliding Window. Ignore that.', print_log_level >= 2); } else { - printLog('Response from element ' + retObj['node-id'] + ' --> Dropped from Sliding Window. Timestamp: ' + Date.now(), print_log_level >= 2); + printLog('Response from element ' + retObj[NODE_ID] + ' --> Dropped from Sliding Window. Timestamp: ' + Date.now(), print_log_level >= 2); slidingWindow.splice(elementIndex, 1); if (addNextDeviceListElementInWindow()) { - printLog('Add element ' + slidingWindow[slidingWindow.length - 1]['node-id'] + ' in Sliding Window and send request...', print_log_level >= 2); + printLog('Add element ' + slidingWindow[slidingWindow.length - 1][NODE_ID] + ' in Sliding Window and send request...', print_log_level >= 2); //printLog(printListDevice('Device List', deviceList), print_log_level >= 2); //printLog(printList('Sliding Window', slidingWindow), print_log_level >= 1); requestMessage(slidingWindow.length - 1); @@ -350,7 +353,7 @@ async function requestMessage(index) { async function extractProfileConfiguration(uuid) { - const profileCollection = require('onf-core-model-ap/applicationPattern/onfModel/models/ProfileCollection'); + let profile = await profileCollection.getProfileAsync(uuid); let objectKey = Object.keys(profile)[2]; profile = profile[objectKey]; @@ -436,6 +439,16 @@ async function MATRCycle(firstTime, logging_level) { let traceIndicator = "1.3.1"; let customerJourney = "Unknown value"; + // Use a dynamic header + // TODO: TO be validate + // let requestHeader = new RequestHeader("MacAddressTableRecorder", "MacAddressTableRecorder", undefined, "1"); + + // let user = requestHeader.user; + // let originator = requestHeader.originator; + // let xCorrelator = requestHeader.xCorrelator; + // let traceIndicator = requestHeader.traceIndicator; + // let customerJourney = requestHeader.customerJourney; + try { do { deviceListMount = await individualServices.updateCurrentConnectedEquipment(user, originator, xCorrelator, traceIndicator, customerJourney); @@ -449,7 +462,7 @@ async function MATRCycle(firstTime, logging_level) { for (let i = 0; i < slidingWindowSize; i++) { addNextDeviceListElementInWindow(); requestMessage(i); - printLog('Element ' + slidingWindow[i]['node-id'] + ' send request...', print_log_level >= 2); + printLog('Element ' + slidingWindow[i][NODE_ID] + ' send request...', print_log_level >= 2); } //printLog(printList('Sliding Window - MAIN', slidingWindow), print_log_level >= 1); From 2f4c99a4980e561dc91cd21d99eb31b83dd64456 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Tue, 18 Mar 2025 09:59:08 +0100 Subject: [PATCH 10/22] Convert Time optimization --- .../CyclicProcessService/cyclicProcess.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index e490e18..0aca0e5 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -203,17 +203,18 @@ function printErr(text, print_log) { } -function convertTime(milliseconds) { - let seconds = Math.floor(milliseconds / 1000); - let hours = Math.floor(seconds / 3600); - let minutes = Math.floor((seconds % 3600) / 60); - let modSeconds = seconds % 60; - - return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${modSeconds.toString().padStart(2, '0')}`; +function convertTime(s) { + const ms = s % 1000; + s = (s - ms) / 1000; + const secs = s % 60; + s = (s - secs) / 60; + const mins = s % 60; + const hrs = (s - mins) / 60; + + return `${hrs.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`; } - /** * Timeout checking cycle * From 81d18dce1dc7d9f9e9d94e558b420ae4fc6a6863 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Wed, 19 Mar 2025 12:35:20 +0100 Subject: [PATCH 11/22] Update IndividualServicesService with new Log --- server/service/IndividualServicesService.js | 25 ++++++++------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index b7bba4e..3d5df63 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -1,34 +1,32 @@ 'use strict'; -const { getIndexAliasAsync, createResultArray, elasticsearchService } = require('onf-core-model-ap/applicationPattern/services/ElasticsearchService'); -const onfPaths = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfPaths'); +// ONF libs +var appCommons = require('onf-core-model-ap/applicationPattern/commons/AppCommons'); // TODO: To be check +const { getIndexAliasAsync, elasticsearchService } = require('onf-core-model-ap/applicationPattern/services/ElasticsearchService'); const onfAttributes = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfAttributes'); const LogicalTerminationPoint = require('onf-core-model-ap/applicationPattern/onfModel/models/LogicalTerminationPoint'); -const LogicalTerminationPointC = require('./custom/LogicalTerminationPointC'); const tcpClientInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/TcpClientInterface'); const ForwardingDomain = require('onf-core-model-ap/applicationPattern/onfModel/models/ForwardingDomain'); -const ForwardingConstruct = require('onf-core-model-ap/applicationPattern/onfModel/models/ForwardingConstruct'); const FcPort = require('onf-core-model-ap/applicationPattern/onfModel/models/FcPort'); const httpClientInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/HttpClientInterface'); const httpServerInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/HttpServerInterface'); const controlConstruct = require('onf-core-model-ap/applicationPattern/onfModel/models/ControlConstruct'); const LayerProtocol = require('onf-core-model-ap/applicationPattern/onfModel/models/LayerProtocol'); -const eventDispatcher = require('onf-core-model-ap/applicationPattern/rest/client/eventDispatcher'); -const responseBuilder = require('onf-core-model-ap/applicationPattern/rest/server/ResponseBuilder'); const onfAttributeFormatter = require('onf-core-model-ap/applicationPattern/onfModel/utility/OnfAttributeFormatter'); -const operationClientInterface = require('onf-core-model-ap/applicationPattern/onfModel/models/layerProtocols/OperationClientInterface'); const RequestHeader = require('onf-core-model-ap/applicationPattern/rest/client/RequestHeader'); -const RestRequestBuilder = require('onf-core-model-ap/applicationPattern/rest/client/RequestBuilder'); var responseCodeEnum = require('onf-core-model-ap/applicationPattern/rest/server/ResponseCode'); -const TcpClient = require('../service/TcpClientService'); const genericRepresentation = require('onf-core-model-ap-bs/basicServices/GenericRepresentation'); + +// Other Libs const createHttpError = require("http-errors"); const axios = require('axios'); + +const LogicalTerminationPointC = require('./custom/LogicalTerminationPointC'); const authKey = require("../application-data/encrypted-odl-key.json"); const logger = require('../service/LoggingService.js').getLogger(); -var appCommons = require('onf-core-model-ap/applicationPattern/commons/AppCommons'); + async function resolveOperationNameAndOperationKeyFromForwardingName(forwardingName) { const forwardingConstruct = await ForwardingDomain.getForwardingConstructForTheForwardingNameAsync(forwardingName); @@ -1156,7 +1154,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr let fullUrl = finalUrl.replace("{mount-name}", mountName); - var data = { + let data = { "input": {} }; @@ -1705,8 +1703,3 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, }); } - - - - - From c35cb1cc4e63e3a14315f262a5cb772e052797d6 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Wed, 19 Mar 2025 17:27:21 +0100 Subject: [PATCH 12/22] Use dynamic header --- .../CyclicProcessService/cyclicProcess.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index 0aca0e5..99c7222 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -250,7 +250,7 @@ function startTtlChecking() { } if (slidingWindow.length == 0) { clearInterval(handle); - handle = 0; // I just do this so I know I've cleared the interval + handle = 0; // I just do this so I know I've cleared the interval stop = false; const now = new Date(); @@ -434,21 +434,21 @@ async function MATRCycle(firstTime, logging_level) { print_log_level = logging_level; //TO FIX - let user = "User Name"; - let originator = "MacAddressTableResolver"; - let xCorrelator = "550e8400-e29b-11d4-a716-446655440000"; - let traceIndicator = "1.3.1"; - let customerJourney = "Unknown value"; + // let user = "User Name"; + // let originator = "MacAddressTableResolver"; + // let xCorrelator = "550e8400-e29b-11d4-a716-446655440000"; + // let traceIndicator = "1.3.1"; + // let customerJourney = "Unknown value"; // Use a dynamic header // TODO: TO be validate - // let requestHeader = new RequestHeader("MacAddressTableRecorder", "MacAddressTableRecorder", undefined, "1"); + let requestHeader = new RequestHeader("MacAddressTableRecorder", "MacAddressTableRecorder", undefined, "1"); - // let user = requestHeader.user; - // let originator = requestHeader.originator; - // let xCorrelator = requestHeader.xCorrelator; - // let traceIndicator = requestHeader.traceIndicator; - // let customerJourney = requestHeader.customerJourney; + let user = requestHeader.user; + let originator = requestHeader.originator; + let xCorrelator = requestHeader.xCorrelator; + let traceIndicator = requestHeader.traceIndicator; + let customerJourney = requestHeader.customerJourney; try { do { From c5dd183fa182437ba1043cc91652939171f08092 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Thu, 20 Mar 2025 09:49:43 +0100 Subject: [PATCH 13/22] Adding log to IndividualServicesService --- server/service/IndividualServicesService.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 3d5df63..0361001 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -1094,10 +1094,11 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched }); if (response.status === 200) { + logger.debug("OK - Get data from MWDI - mountname: " + mountName); return (response.data); } else { - throw new Error(" Empty data from " + fullUrl); + throw new Error("Empty data from " + fullUrl); } } catch (error) { logger.error("***********catch axios try Error '404' for URL:", fullUrl) @@ -1178,16 +1179,19 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr }); if (response.data == '') { + logger.warn("Get empty data from ODL - mountname: " + mountName); throw new Error("Empty data from " + fullUrl); } else { return response.data; } } catch (error) { + logger.error("KO - Get data from ODL - mountname: " + mountName, error); throw error; } } catch (error) { + logger.error("KO - Get data from ODL - mountname: " + mountName, error); throw error; } } @@ -1531,6 +1535,7 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, //STEP1 //"/core-model-1-4:network-control-domain=cache/control-construct={mount-name}?fields=forwarding-domain(uuid;layer-protocol-name;mac-fd-1-0:mac-fd-pac(mac-fd-status(mac-address-cur)))", try { + logger.debug("Calling PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi - mountname: " + mountName); const data = await PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi(mountName, user, originator, xCorrelator, traceIndicator, customerJourney); if ( @@ -1560,6 +1565,7 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, } } catch (error) { + logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi - mountname: " + mountName + "", error); throw ("(" + mountName + "):" + error.message); } @@ -1567,6 +1573,7 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, //"/rests/operations/network-topology:network-topology/topology=topology-netconf/node={mount-name}/yang-ext:mount/mac-fd-1-0:provide-learned-mac-addresses" if (FDomainArray.length >= 0) { try { + logger.debug("Calling PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice - mountname: " + mountName); const dataFromRequest = await PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice(mountName, user, originator, xCorrelator, traceIndicator, customerJourney); let uuid = 0; @@ -1632,16 +1639,19 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, } } catch (error) { + logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice", error); throw (error.message); } //STEP3 try { + logger.debug("Calling PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi - mountname: " + mountName); const originalLtpNamePromises = eggressUniqArray.map(egressData => { return PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi(mountName, egressData, user, originator, xCorrelator, traceIndicator, customerJourney); }); step3DataArray = await Promise.all(originalLtpNamePromises); } catch (error) { + logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi - mountname:" + mountName, error); throw (error.message); } @@ -1665,9 +1675,11 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, //STEP4 try { + logger.debug("Calling PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch - mountname: "+ mountName); const writingResultPromise = await PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch(macAddressDataDb, user, originator, xCorrelator, traceIndicator, customerJourney); } catch (error) { + logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch", error); throw error; } From 25067e7d42f88ac72ae44b7212e709f9455589d3 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Thu, 20 Mar 2025 18:55:08 +0100 Subject: [PATCH 14/22] Observing "Request failed with status code 404 from element (II time)" for the devices available in MWDI cache Fixes #237 --- server/service/IndividualServicesService.js | 42 ++++++++++--------- .../CyclicProcessService/cyclicProcess.js | 20 ++++++++- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 0361001..8503875 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -483,7 +483,7 @@ const EmbeddingCausesRequestForListOfApplicationsAtRo = async function (user, or let remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName; - logger.info("url = ", finalUrl); + logger.info("url = " + finalUrl); let httpRequestHeader = new RequestHeader( user, @@ -566,8 +566,7 @@ const EmbeddingCausesRequestForListOfDevicesAtMwdi = async function (user, origi let remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName; - logger.info("url = ", finalUrl); - + logger.info("url = " + finalUrl); let httpRequestHeader = new RequestHeader( user, @@ -946,7 +945,7 @@ const PromptForProvidingSpecificMacTableCausesReadingFromElasticSearch = async f id: mountName }); - var source = res2.body._source['mac-address']; + let source = res2.body._source['mac-address']; const formattedEntries = source.map(entry => { return { @@ -1180,7 +1179,9 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr if (response.data == '') { logger.warn("Get empty data from ODL - mountname: " + mountName); - throw new Error("Empty data from " + fullUrl); + return response.data; + // TODO Lorenzo Latta to be check + // throw new Error("Empty data from " + fullUrl); // no that should not happen } else { return response.data; @@ -1516,8 +1517,21 @@ function transformArray(reqId, inputArray) { return returnValue; } - exports.readCurrentMacTableFromDevice = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { + return new Promise(async function (resolve, reject) { + const mountName = body['mount-name']; + let reqId = generateRequestId(mountName); + // Result that return API + let result = {}; + result['application/json'] = { + "request-id": reqId + }; + + resolve(result['application/json']); + }); +} + +exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney, reqId) { const FDomainArray = []; let step2DataArray = []; let step3DataArray = []; @@ -1527,7 +1541,6 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, return new Promise(async function (resolve, reject) { - var result = {}; const mountName = body['mount-name']; try { @@ -1561,6 +1574,7 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, }); } else { + // logger.warn("Data from MWDI is empty"); throw new Error("Received data are not correct (Missing core-model-1-4:control-construct/forwarding-domain)"); } @@ -1631,7 +1645,7 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, eggressUniqSet.add(obj['egress-ltp']); }); - // Convertire il Set in un array + // Set converted into array eggressUniqArray = [...eggressUniqSet]; } else { @@ -1683,12 +1697,6 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, throw error; } - let reqId = generateRequestId(mountName); - // Result that return API - result['application/json'] = { - "request-id": reqId - }; - // Retrieve url requestor from body urlRequestor = getRequestorPath(body); @@ -1701,17 +1709,13 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, throw ("Failed send data to requestor: " + error.message); } } - - resolve(result['application/json']); } else { throw new Error("Missing mac-interface-1-0:LAYER_PROTOCOL_NAME_TYPE_MAC_LAYER"); } } catch (error) { - let internalServerError = createHttpError.InternalServerError(error); - reject(internalServerError); + logger.error(error); } }); - } diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index 99c7222..5b93858 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -4,6 +4,7 @@ const profileCollection = require('onf-core-model-ap/applicationPattern/onfModel/models/ProfileCollection'); const RequestHeader = require("onf-core-model-ap/applicationPattern/rest/client/RequestHeader"); const forwardingDomain = require('onf-core-model-ap/applicationPattern/onfModel/models/ForwardingDomain'); +const axios = require('axios'); // Other Libs const { setTimeout } = require('timers'); @@ -38,7 +39,24 @@ async function sendRequest(device, user, originator, xCorrelator, traceIndicator }; try { - await individualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney); + // Create Request header + let httpRequestHeader = new RequestHeader( + user, + originator, + xCorrelator, + traceIndicator, + customerJourney, + "operation key not yet provided"// operationKey -- "operation key not yet provided" + ); + + // To be fixed + let finalUrl = "http://localhost:8080/v1/read-current-mac-table-from-device"; + let response = await axios.post(finalUrl, body, { + headers: httpRequestHeader + }); + + // Old request + //await individualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney); return { 'ret': { 'code': 200, 'message': 'Correctly Managed' }, From c81c168f8f436d0bba194a9bb95f858071575f78 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Thu, 20 Mar 2025 18:55:23 +0100 Subject: [PATCH 15/22] Update the logger --- server/service/LoggingService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/service/LoggingService.js b/server/service/LoggingService.js index 0022028..330893e 100644 --- a/server/service/LoggingService.js +++ b/server/service/LoggingService.js @@ -5,12 +5,12 @@ const path = require("path"); const transports = pino.transport({ targets: [ { - level: 'debug', + level: 'info', target: 'pino-pretty', options: { colorize: true } }, { - level: 'trace', + level: 'info', target: 'pino-roll', options: { file: path.join(__dirname, '../logs/MacAddressTableRecorder'), extension: '.log', mkdir: true, frequency: 'daily', dateFormat: 'yyyy-MM-dd', size: "1m", "limit.count": 15 } From 46ee254c1ac1c4d25539a00057fd026a5a395367 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Thu, 20 Mar 2025 18:57:16 +0100 Subject: [PATCH 16/22] Fix the controller --- server/controllers/IndividualServices.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/controllers/IndividualServices.js b/server/controllers/IndividualServices.js index ae25345..f7b6076 100644 --- a/server/controllers/IndividualServices.js +++ b/server/controllers/IndividualServices.js @@ -111,11 +111,15 @@ module.exports.readCurrentMacTableFromDevice = async function readCurrentMacTabl let responseCode = responseCodeEnum.code.OK; let responseBodyToDocument = {}; - await IndividualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney, req.url) + await IndividualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney) .then(async function (responseBody) { responseBodyToDocument = responseBody; let responseHeader = await ResponseHeader.createResponseHeader(xCorrelator, startTime, req.url); ResponseBuilder.buildResponse(res, responseCode, responseBody, responseHeader); + // Starting request in async mode + // Moddifyed by @latta-siae + let req_id = responseBody['request-id']; + IndividualServices.readCurrentMacTableFromDeviceCallbacks(body, user, originator, xCorrelator, traceIndicator, customerJourney, req_id); }) .catch(async function (responseBody) { let responseHeader = await ResponseHeader.createResponseHeader(xCorrelator, startTime, req.url); From 90038d89677fe6f36049061b46fde0a90e32cd31 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Fri, 21 Mar 2025 17:22:38 +0100 Subject: [PATCH 17/22] fixing the log --- server/service/IndividualServicesService.js | 44 +++++++++---------- .../CyclicProcessService/cyclicProcess.js | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 8503875..7852be5 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -226,7 +226,7 @@ const RequestForDeleteEquipmentIntoElasticSearch = async function (mountName) { } else { resolve(null); } - logger.info("Remove mount-name = ", mountName); + logger.info("Remove mount-name = "+ mountName); } catch (error) { reject(error); @@ -317,7 +317,7 @@ async function executeAfterWait() { // Wait 300 seconds await waitAsync(30000); } catch (error) { - logger.error('An error occurred during the wait:', error); + logger.error(error, 'An error occurred during the wait:'); } } @@ -345,7 +345,7 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor let result = await client.indices.refresh({ index: indexAlias }); logger.info(`Index ${indexAlias} refreshed successfully`); } catch (error) { - logger.error(`Error refreshing index ${indexAlias}:`, error); + logger.error(error, `Error refreshing index ${indexAlias}:`); } }; @@ -385,7 +385,7 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor } } catch (error) { - logger.error(error + ', wait 30 seconds and retry to read...'); + logger.error(error, ', wait 30 seconds and retry to read...'); await executeAfterWait(); newConnectedListFromMwdi = null; } @@ -1100,15 +1100,15 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched throw new Error("Empty data from " + fullUrl); } } catch (error) { - logger.error("***********catch axios try Error '404' for URL:", fullUrl) - logger.error("*********** response status:", response.status) - logger.error("*********** response messge:", response.data) + logger.error(error, "***********catch axios try Error '404' for URL: " + fullUrl); + logger.error("*********** response status: " + response.status); + logger.error("*********** response messge: " + response.data); throw error; } } catch (error) { - logger.error("***********catch main try Error '404' for URL:", fullUrl) - logger.error("*********** response status:", response.status) - logger.error("*********** response messge:", response.data) + logger.error(error, "***********catch main try Error '404' for URL: "); + logger.error("*********** response status:" + response.status); + logger.error("*********** response messge:" + response.data); throw error; } } @@ -1187,12 +1187,12 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr return response.data; } } catch (error) { - logger.error("KO - Get data from ODL - mountname: " + mountName, error); + logger.error(error, "KO - Get data from ODL - mountname: " + mountName); throw error; } } catch (error) { - logger.error("KO - Get data from ODL - mountname: " + mountName, error); + logger.error(error, "KO - Get data from ODL - mountname: " + mountName); throw error; } } @@ -1326,9 +1326,9 @@ async function PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch if (body && body["mac-address"] && Array.isArray(body["mac-address"]) && body["mac-address"].length > 0 && body["mac-address"][0]["mount-name"]) { mountName = body["mac-address"][0]["mount-name"]; } else { - logger.error('********************************* Body *******************************************') - logger.error(JSON.stringify(body)) - logger.error('**********************************************************************************') + logger.error('********************************* Body *******************************************'); + logger.error(body); + logger.error('**********************************************************************************'); throw new Error("Writing operation into Elastic Search Failed : body structure is not correct"); } @@ -1579,7 +1579,7 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori } } catch (error) { - logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi - mountname: " + mountName + "", error); + logger.error(error, "Failing calling PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi - mountname: " + mountName); throw ("(" + mountName + "):" + error.message); } @@ -1635,8 +1635,8 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori if (step2Data.length == 0) { logger.warn("Step2Data is empty!"); - logger.warn("Forwarding domain: ", FDomainArray); - logger.warn("Data from request:", dataFromRequest) + logger.warn("Forwarding domain: %d", FDomainArray); + logger.warn("Data from request: %d", dataFromRequest) } step2DataArray = Array.from(step2Data); @@ -1653,7 +1653,7 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori } } catch (error) { - logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice", error); + logger.error(error, "Failing calling PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice"); throw (error.message); } @@ -1665,7 +1665,7 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori }); step3DataArray = await Promise.all(originalLtpNamePromises); } catch (error) { - logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi - mountname:" + mountName, error); + logger.error(error, "Failing calling PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi - mountname:" + mountName); throw (error.message); } @@ -1689,11 +1689,11 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori //STEP4 try { - logger.debug("Calling PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch - mountname: "+ mountName); + logger.debug("Calling PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch - mountname: " + mountName); const writingResultPromise = await PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch(macAddressDataDb, user, originator, xCorrelator, traceIndicator, customerJourney); } catch (error) { - logger.error("Failing calling PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch", error); + logger.error(error, "Failing calling PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch"); throw error; } diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index 5b93858..5dec46a 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -488,7 +488,7 @@ async function MATRCycle(firstTime, logging_level) { startTtlChecking(); } catch (error) { - logger.error("Error on MATR cycle: ", error); + logger.error(error, "Error on MATR cycle: "); } }, remainder); From 5031a5afa0953a72e78c019e61ba26ab9142dde6 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Tue, 25 Mar 2025 17:55:57 +0100 Subject: [PATCH 18/22] Update pino logger --- server/controllers/IndividualServices.js | 5 ----- server/service/LoggingService.js | 2 +- .../CyclicProcessService/cyclicProcess.js | 20 ++----------------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/server/controllers/IndividualServices.js b/server/controllers/IndividualServices.js index f7b6076..1406b2c 100644 --- a/server/controllers/IndividualServices.js +++ b/server/controllers/IndividualServices.js @@ -110,16 +110,11 @@ module.exports.readCurrentMacTableFromDevice = async function readCurrentMacTabl let startTime = process.hrtime(); let responseCode = responseCodeEnum.code.OK; let responseBodyToDocument = {}; - await IndividualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney) .then(async function (responseBody) { responseBodyToDocument = responseBody; let responseHeader = await ResponseHeader.createResponseHeader(xCorrelator, startTime, req.url); ResponseBuilder.buildResponse(res, responseCode, responseBody, responseHeader); - // Starting request in async mode - // Moddifyed by @latta-siae - let req_id = responseBody['request-id']; - IndividualServices.readCurrentMacTableFromDeviceCallbacks(body, user, originator, xCorrelator, traceIndicator, customerJourney, req_id); }) .catch(async function (responseBody) { let responseHeader = await ResponseHeader.createResponseHeader(xCorrelator, startTime, req.url); diff --git a/server/service/LoggingService.js b/server/service/LoggingService.js index 330893e..74b8982 100644 --- a/server/service/LoggingService.js +++ b/server/service/LoggingService.js @@ -19,7 +19,7 @@ const transports = pino.transport({ }); // create pino logger instance -const logger = pino({level: 'trace'}, transports); +const logger = pino({level: 'info'}, transports); exports.getLogger = function getLogger() { return logger; diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index 5dec46a..e0924c0 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -39,24 +39,8 @@ async function sendRequest(device, user, originator, xCorrelator, traceIndicator }; try { - // Create Request header - let httpRequestHeader = new RequestHeader( - user, - originator, - xCorrelator, - traceIndicator, - customerJourney, - "operation key not yet provided"// operationKey -- "operation key not yet provided" - ); - - // To be fixed - let finalUrl = "http://localhost:8080/v1/read-current-mac-table-from-device"; - let response = await axios.post(finalUrl, body, { - headers: httpRequestHeader - }); - - // Old request - //await individualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney); + // Sent request to "read current MacTable from Device" + await individualServices.readCurrentMacTableFromDeviceCallbacks(body, user, originator, xCorrelator, traceIndicator, customerJourney); return { 'ret': { 'code': 200, 'message': 'Correctly Managed' }, From 6d1f24a2fbb2d7b7e07bbbbab87e8b3611b69bb7 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Tue, 25 Mar 2025 17:57:10 +0100 Subject: [PATCH 19/22] Refactoring Individual ServicesService - Add contants - Rework of provide mac address --- server/service/IndividualServicesService.js | 260 +++++++++++--------- 1 file changed, 146 insertions(+), 114 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 7852be5..7f5801f 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -1,6 +1,6 @@ 'use strict'; -// ONF libs +// ONF Libs var appCommons = require('onf-core-model-ap/applicationPattern/commons/AppCommons'); // TODO: To be check const { getIndexAliasAsync, elasticsearchService } = require('onf-core-model-ap/applicationPattern/services/ElasticsearchService'); const onfAttributes = require('onf-core-model-ap/applicationPattern/onfModel/constants/OnfAttributes'); @@ -21,12 +21,30 @@ const genericRepresentation = require('onf-core-model-ap-bs/basicServices/Generi const createHttpError = require("http-errors"); const axios = require('axios'); +// Internal routines const LogicalTerminationPointC = require('./custom/LogicalTerminationPointC'); const authKey = require("../application-data/encrypted-odl-key.json"); const logger = require('../service/LoggingService.js').getLogger(); +// ------------- Constants +const FWD_DOMAIN = "forwarding-domain"; +const CTRL_CONSTR = "core-model-1-4:control-construct"; +const MAC_ADDR = "mac-address"; +const MAC_OUTPUT = "mac-fd-1-0:output"; +const OWN_MAC = "own-mac-address"; +const REMOTE_MAC = "remote-mac-address" +const MAC_ENTRY_LIST = "mac-table-entry-list"; +const MOUNT_NAME = "mount-name"; +const MOUNT_NAME_LIST = "mount-name-list"; +const EGRESS_LTP = "egress-ltp"; +const EGRESS_LTP_UUID = "egress-ltp-uuid"; +const ORIG_LTP_NAME = "original-ltp-name"; + +const VLAN_ID = "vlan-id"; +const T_STAMP = "time-stamp-of-data"; +// ----------------------------------- async function resolveOperationNameAndOperationKeyFromForwardingName(forwardingName) { const forwardingConstruct = await ForwardingDomain.getForwardingConstructForTheForwardingNameAsync(forwardingName); @@ -132,12 +150,12 @@ exports.bequeathYourDataAndDie = async function (body, user, originator, xCorrel function transformData(inputData) { const outputData = { - "target-mac-address": `${inputData["remote-mac-address"]}`, - "mount-name": inputData["mount-name"], - "original-ltp-name": inputData["original-ltp-name"], - "egress-ltp-uuid": inputData["egress-ltp-uuid"], - "vlan-id": inputData["vlan-id"], - "time-stamp-of-data": new Date(inputData["time-stamp-of-data"]).toISOString() + "target-mac-address": `${inputData[REMOTE_MAC]}`, + "mount-name": inputData[MOUNT_NAME], + "original-ltp-name": inputData[ORIG_LTP_NAME], + "egress-ltp-uuid": inputData[EGRESS_LTP_UUID], + "vlan-id": inputData[VLAN_ID], + "time-stamp-of-data": new Date(inputData[T_STAMP]).toISOString() }; return outputData; } @@ -154,7 +172,7 @@ const RequestForListOfConnectedEquipmentFromElasticSearch = async function () { try { let result = await client.get({ index: indexAlias, - id: 'mount-name-list' + id: MOUNT_NAME_LIST }); let mergedArray = []; @@ -163,7 +181,7 @@ const RequestForListOfConnectedEquipmentFromElasticSearch = async function () { var response = {}; response['application/json'] = { - 'mount-name-list': mountList['mount-name-list'] + 'mount-name-list': mountList[MOUNT_NAME_LIST] }; if (Object.keys(response).length > 0) { @@ -191,7 +209,7 @@ const RequestForWriteListConnectedEquipmentIntoElasticSearch = async function (b let result = await client.index({ index: indexAlias, - id: 'mount-name-list', + id: MOUNT_NAME_LIST, body: body }); @@ -245,9 +263,9 @@ const findNotConnectedElements = async function (listJsonES, listJsonMD) { if (listJsonES == null) resolve(null); else { - listES = listJsonES["mount-name-list"]; + listES = listJsonES[MOUNT_NAME_LIST]; if (listJsonMD != null) { - listMD = listJsonMD["mount-name-list"]; + listMD = listJsonMD[MOUNT_NAME_LIST]; // Filter the elements present in listES but not in listMD let missingElements = listES.filter(element => !listMD.includes(element)); @@ -276,11 +294,11 @@ function areEqualArray(listJsonES, listJsonMD) { let array2 = null; if (listJsonES != null && listJsonES != undefined) { - array1 = listJsonES["mount-name-list"]; + array1 = listJsonES[MOUNT_NAME_LIST]; } if (listJsonMD != null && listJsonMD != undefined) { - array2 = listJsonMD["mount-name-list"]; + array2 = listJsonMD[MOUNT_NAME_LIST]; } if ((array1 != null) && (array2 != null)) { @@ -358,7 +376,7 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor //"mount-name-list" from ES try { oldConnectedListFromES = await RequestForListOfConnectedEquipmentFromElasticSearch(); - logger.info("mount-name-list (ES), number of elements:" + oldConnectedListFromES['mount-name-list'].length); + logger.info("mount-name-list (ES), number of elements:" + oldConnectedListFromES[MOUNT_NAME_LIST].length); } catch (error) { logger.error("mount-name-list is not present (elastic search error)"); @@ -381,7 +399,7 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor await executeAfterWait(); } else { - logger.info("mount-name-list (MWDI), number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); + logger.info("mount-name-list (MWDI), number of elements:" + newConnectedListFromMwdi[MOUNT_NAME_LIST].length); } } catch (error) { @@ -395,8 +413,8 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor //list of equipment that was connected (mac-address data in ES) but now that are not connected listJsonDisconnectedEq = await findNotConnectedElements(oldConnectedListFromES, newConnectedListFromMwdi); if (listJsonDisconnectedEq != null) { - logger.info("list of equipments disconnected, number of elements: -" + listJsonDisconnectedEq['mount-name-list'].length + " => remove mac-address data from ES"); - //printArray(listJsonDisconnectedEq['mount-name-list']); + logger.info("list of equipments disconnected, number of elements: -" + listJsonDisconnectedEq[MOUNT_NAME_LIST].length + " => remove mac-address data from ES"); + //printArray(listJsonDisconnectedEq[MOUNT_NAME_LIST]); } else { logger.info("list of equipments disconnected, number of elements:" + 0); @@ -408,22 +426,22 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor } //Write new "mount-name-list" list into ES - printArray(newConnectedListFromMwdi['mount-name-list']); + printArray(newConnectedListFromMwdi[MOUNT_NAME_LIST]); if (areEqualArray(oldConnectedListFromES, newConnectedListFromMwdi) == false) { try { result = await RequestForWriteListConnectedEquipmentIntoElasticSearch(newConnectedListFromMwdi); - logger.info("Write new mount-name-list into ES, number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); + logger.info("Write new mount-name-list into ES, number of elements:" + newConnectedListFromMwdi[MOUNT_NAME_LIST].length); } catch (error) { logger.info('mount-name-list are not updated, no difference between old ES mount-name-list and MWDI mount-name-list currently read'); } } else { - logger.info("Write new mount-name-list, number of elements:" + newConnectedListFromMwdi['mount-name-list'].length); + logger.info("Write new mount-name-list, number of elements:" + newConnectedListFromMwdi[MOUNT_NAME_LIST].length); } if (listJsonDisconnectedEq != null) { - listDisconnectedEq = listJsonDisconnectedEq["mount-name-list"]; + listDisconnectedEq = listJsonDisconnectedEq[MOUNT_NAME_LIST]; //remove mac-address data in ES of equipment that are that are no longer connected try { @@ -612,8 +630,8 @@ function generateMountAndEgressPairs(data) { const mounts = {}; data[0].forEach(entry => { - const mountname = entry['mount-name']; - const egressltpuuid = entry['egress-ltp-uuid']; + const mountname = entry[MOUNT_NAME]; + const egressltpuuid = entry[EGRESS_LTP_UUID]; if (mounts[mountname]) { mounts[mountname].push(egressltpuuid); } else { @@ -647,7 +665,7 @@ const RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSear let res2 = await client.search({ index: indexAlias, - _source: 'mac-address', + _source: MAC_ADDR, body: { query: { match: { @@ -661,12 +679,12 @@ const RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSear const hits = res2.body.hits.hits; for (const hit of hits) { - const source = hit._source['mac-address']; + const source = hit._source[MAC_ADDR]; mergedArray = mergedArray.concat(source); } const filteredObjects = mergedArray.filter(obj => - obj['remote-mac-address'].toLowerCase() === targetMacAddress.toLowerCase() + obj[REMOTE_MAC].toLowerCase() === targetMacAddress.toLowerCase() ); transformedArray = filteredObjects.map(obj => transformData(obj)); @@ -709,7 +727,7 @@ exports.provideListOfNetworkElementInterfacesOnPath = async function (body, url) // Remove the key "egress-ltp-uuid" newArray.forEach(obj => { - delete obj["egress-ltp-uuid"]; + delete obj[EGRESS_LTP_UUID]; }); resolve(newArray); @@ -819,13 +837,13 @@ exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = asy function orderData(input) { const output = { - "mount-name": input['mount-name'], - "own-mac-address": input['own-mac-address'], - "egress-ltp-uuid": input['egress-ltp-uuid'], - "original-ltp-name": input['original-ltp-name'], - "vlan-id": input['vlan-id'], - "remote-mac-address": input['remote-mac-address'], - "time-stamp-of-data": input['time-stamp-of-data'] + "mount-name": input[MOUNT_NAME], + "own-mac-address": input[OWN_MAC], + "egress-ltp-uuid": input[EGRESS_LTP_UUID], + "original-ltp-name": input[ORIG_LTP_NAME], + "vlan-id": input[VLAN_ID], + "remote-mac-address": input[REMOTE_MAC], + "time-stamp-of-data": input[T_STAMP] }; return output; @@ -842,12 +860,12 @@ const PromptForProvidingAllMacTablesCausesReadingFromElasticSearch = async funct // Inizialize scroll operation let res2 = await client.search({ index: indexAlias, - _source: 'mac-address', + _source: MAC_ADDR, scroll: '1m', // Keep window scroll opened for 1 minute body: { query: { match: { - 'datatype': 'mac-address' + 'datatype': MAC_ADDR } } } @@ -859,10 +877,10 @@ const PromptForProvidingAllMacTablesCausesReadingFromElasticSearch = async funct // Continue to retrieve as long as there are documents. while (hits.length > 0) { for (const hit of hits) { - const source = hit._source['mac-address']; + const source = hit._source[MAC_ADDR]; for (const element of source) { - element["time-stamp-of-data"] = formatTimestamp(element["time-stamp-of-data"]); + element[T_STAMP] = formatTimestamp(element[T_STAMP]); response['application/json'].push(element); } } @@ -938,33 +956,40 @@ const PromptForProvidingSpecificMacTableCausesReadingFromElasticSearch = async f let indexAlias = await getIndexAliasAsync(); try { - let mountName = body['mount-name']; + let mountName = body[MOUNT_NAME]; res2 = await client.get({ index: indexAlias, id: mountName }); - let source = res2.body._source['mac-address']; + let source = res2.body._source[MAC_ADDR]; - const formattedEntries = source.map(entry => { - return { - ...entry, - "time-stamp-of-data": formatTimestamp(entry["time-stamp-of-data"]) + if (source) { + const formattedEntries = source.map(entry => { + return { + ...entry, + "time-stamp-of-data": formatTimestamp(entry[T_STAMP]) + }; + }); + + let response = {}; + response['application/json'] = { + 'mac-address': formattedEntries }; - }); - - let response = {}; - response['application/json'] = { - 'mac-address': formattedEntries - }; - - - if (Object.keys(response).length > 0) { - resolve(response['application/json']['mac-address']); + + + if (Object.keys(response).length > 0) { + resolve(response['application/json'][MAC_ADDR]); + } else { + logger.error("No data found in ElasticSearch! - Mountname: " + mountName) + throw new Error("No data found in ElasticSearch!"); + } } else { - resolve(null); // Resolve the promise with null if necessary + logger.error("No MAC Address data found in ElasticSearch! - Mountname: " + mountName) + throw new Error("No MAC Address data found in ElasticSearch!"); } + } catch (error) { reject(error); } @@ -1086,9 +1111,10 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched const encodedFields = customEncode(fields); const fullUrl = newBaseUrl + 'fields=' + encodedFields; - + + let response; try { - let response = await axios.get(fullUrl, { + response = await axios.get(fullUrl, { headers: httpRequestHeader }); @@ -1101,14 +1127,14 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched } } catch (error) { logger.error(error, "***********catch axios try Error '404' for URL: " + fullUrl); - logger.error("*********** response status: " + response.status); - logger.error("*********** response messge: " + response.data); + // logger.error("*********** response status: " + response.status); + // logger.error("*********** response messge: " + response.data); throw error; } } catch (error) { logger.error(error, "***********catch main try Error '404' for URL: "); - logger.error("*********** response status:" + response.status); - logger.error("*********** response messge:" + response.data); + // logger.error("*********** response status:" + response.status); + // logger.error("*********** response messge:" + response.data); throw error; } } @@ -1266,7 +1292,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIn headers: httpRequestHeader }); - let data = response.data['ltp-augment-1-0:ltp-augment-pac']['original-ltp-name']; + let data = response.data['ltp-augment-1-0:ltp-augment-pac'][ORIG_LTP_NAME]; if (data !== null && data !== undefined) { additionaResponse = { @@ -1287,7 +1313,8 @@ async function PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIn 'egress-ltp': body, 'original-ltp-name': "undefined" }; - throw error; + return additionaResponse; + // throw error; } } catch (error) { throw error; @@ -1323,8 +1350,8 @@ async function PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch let remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); - if (body && body["mac-address"] && Array.isArray(body["mac-address"]) && body["mac-address"].length > 0 && body["mac-address"][0]["mount-name"]) { - mountName = body["mac-address"][0]["mount-name"]; + if (body && body[MAC_ADDR] && Array.isArray(body[MAC_ADDR]) && body[MAC_ADDR].length > 0 && body[MAC_ADDR][0][MOUNT_NAME]) { + mountName = body[MAC_ADDR][0][MOUNT_NAME]; } else { logger.error('********************************* Body *******************************************'); logger.error(body); @@ -1418,7 +1445,7 @@ function createMacAddressDataForDb(datatype, macAddressArray) { function getOriginalLtpName(jsonArray, egressLtp) { for (let entry of jsonArray) { if (entry['egress-ltp'] === egressLtp) { - return entry['original-ltp-name']; + return entry[ORIG_LTP_NAME]; } } @@ -1496,13 +1523,13 @@ function transformArray(reqId, inputArray) { inputArray.forEach(item => { // Create object with requested information let transformedObject= { - "mount-name": item["mount-name"], - "own-mac-address": item["own-mac-address"], - "egress-ltp-uuid": item["egress-ltp-uuid"], - "original-ltp-name": item["original-ltp-name"], - "vlan-id": item["vlan-id"], - "remote-mac-address": item["remote-mac-address"], - "time-stamp-of-data": new Date(item["time-stamp-of-data"]).toISOString() // Add formatted time stamp + "mount-name": item[MOUNT_NAME], + "own-mac-address": item[OWN_MAC], + "egress-ltp-uuid": item[EGRESS_LTP_UUID], + "original-ltp-name": item[ORIG_LTP_NAME], + "vlan-id": item[VLAN_ID], + "remote-mac-address": item[REMOTE_MAC], + "time-stamp-of-data": new Date(item[T_STAMP]).toISOString() // Add formatted time stamp }; onfAttributeFormatter.modifyJsonObjectKeysToKebabCase(transformedObject); @@ -1517,21 +1544,7 @@ function transformArray(reqId, inputArray) { return returnValue; } -exports.readCurrentMacTableFromDevice = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { - return new Promise(async function (resolve, reject) { - const mountName = body['mount-name']; - let reqId = generateRequestId(mountName); - // Result that return API - let result = {}; - result['application/json'] = { - "request-id": reqId - }; - - resolve(result['application/json']); - }); -} - -exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney, reqId) { +const readCurrentMacTableFromDeviceCallbacks = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney, reqId) { const FDomainArray = []; let step2DataArray = []; let step3DataArray = []; @@ -1541,7 +1554,7 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori return new Promise(async function (resolve, reject) { - const mountName = body['mount-name']; + const mountName = body[MOUNT_NAME]; try { @@ -1553,15 +1566,15 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori if ( data && - data["core-model-1-4:control-construct"] && - Array.isArray(data["core-model-1-4:control-construct"]) && - data["core-model-1-4:control-construct"].length > 0 && - data["core-model-1-4:control-construct"][0]["forwarding-domain"] && - Array.isArray(data["core-model-1-4:control-construct"][0]["forwarding-domain"]) && - data["core-model-1-4:control-construct"][0]["forwarding-domain"].length > 0 + data[CTRL_CONSTR] && + Array.isArray(data[CTRL_CONSTR]) && + data[CTRL_CONSTR].length > 0 && + data[CTRL_CONSTR][0][FWD_DOMAIN] && + Array.isArray(data[CTRL_CONSTR][0][FWD_DOMAIN]) && + data[CTRL_CONSTR][0][FWD_DOMAIN].length > 0 ) { - data["core-model-1-4:control-construct"].forEach(controlConstruct => { - controlConstruct["forwarding-domain"].forEach(forwardingDomain => { + data[CTRL_CONSTR].forEach(controlConstruct => { + controlConstruct[FWD_DOMAIN].forEach(forwardingDomain => { if ( forwardingDomain["layer-protocol-name"].includes( "mac-interface-1-0:LAYER_PROTOCOL_NAME_TYPE_MAC_LAYER" @@ -1574,7 +1587,7 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori }); } else { - // logger.warn("Data from MWDI is empty"); + logger.warn("Data from MWDI is empty"); throw new Error("Received data are not correct (Missing core-model-1-4:control-construct/forwarding-domain)"); } @@ -1604,31 +1617,31 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori if ( dataFromRequest && - dataFromRequest["mac-fd-1-0:output"] && - dataFromRequest["mac-fd-1-0:output"]["mac-table-entry-list"] && - Array.isArray(dataFromRequest["mac-fd-1-0:output"]["mac-table-entry-list"]) + dataFromRequest[MAC_OUTPUT] && + dataFromRequest[MAC_OUTPUT][MAC_ENTRY_LIST] && + Array.isArray(dataFromRequest[MAC_OUTPUT][MAC_ENTRY_LIST]) ) { - dataFromRequest["mac-fd-1-0:output"]["mac-table-entry-list"].forEach(entry => { + dataFromRequest[MAC_OUTPUT][MAC_ENTRY_LIST].forEach(entry => { if (FDomainArray.length > 0) { FDomainArray.forEach(entryFD => { uuid = entryFD["uuid"]; macAddressCur = entryFD['mac-fd-1-0:mac-fd-pac']['mac-fd-status']['mac-address-cur']; if ((FDomainArray.length > 0) && (entry["affected-mac-fd"] === uuid)) { - entry["own-mac-address"] = macAddressCur; + entry[OWN_MAC] = macAddressCur; step2Data.add(entry); } }); } else { - entry["own-mac-address"] = macAddressCur; + entry[OWN_MAC] = macAddressCur; step2Data.add(entry); } // if ((FDomainArray.length > 0) && (entry["affected-mac-fd"] === uuid)) { - // entry["own-mac-address"] = macAddressCur; + // entry[OWN_MAC] = macAddressCur; // step2Data.add(entry); // } // else if (FDomainArray.length == 0) { - // entry["own-mac-address"] = macAddressCur; + // entry[OWN_MAC] = macAddressCur; // step2Data.add(entry); // } }); @@ -1642,7 +1655,7 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori const eggressUniqSet = new Set(); step2DataArray.forEach(obj => { - eggressUniqSet.add(obj['egress-ltp']); + eggressUniqSet.add(obj[EGRESS_LTP]); }); // Set converted into array @@ -1676,16 +1689,16 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori step2DataArray.forEach((step2Data, index) => { const entry = createMacAddressEntry( mountName, - step2Data['own-mac-address'], - step2Data['egress-ltp'], - getOriginalLtpName(step3DataArray, step2Data['egress-ltp']), - step2Data['vlan-id'], - step2Data['mac-address'], + step2Data[OWN_MAC], + step2Data[EGRESS_LTP], + getOriginalLtpName(step3DataArray, step2Data[EGRESS_LTP]), + step2Data[VLAN_ID], + step2Data[MAC_ADDR], timestamp); macAddressArray.push(entry); }); - const macAddressDataDb = createMacAddressDataForDb("mac-address", macAddressArray); + const macAddressDataDb = createMacAddressDataForDb(MAC_ADDR, macAddressArray); //STEP4 try { @@ -1719,3 +1732,22 @@ exports.readCurrentMacTableFromDeviceCallbacks = async function (body, user, ori } }); } + +exports.readCurrentMacTableFromDeviceCallbacks; + +exports.readCurrentMacTableFromDevice = function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { + return new Promise(async function (resolve, reject) { + const mountName = body[MOUNT_NAME]; + let reqId = generateRequestId(mountName); + // Result that return API + let result = {}; + result['application/json'] = { + "request-id": reqId + }; + + // Start reading data + readCurrentMacTableFromDeviceCallbacks(body, user, originator, xCorrelator, traceIndicator, customerJourney, reqId); + + resolve(result['application/json']); + }); +} From 180f18f21916a2a12aa7a35afe3b609cfcd00c19 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Tue, 25 Mar 2025 18:09:09 +0100 Subject: [PATCH 20/22] add logger in the exception --- server/service/IndividualServicesService.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 7f5801f..e112b1e 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -991,6 +991,7 @@ const PromptForProvidingSpecificMacTableCausesReadingFromElasticSearch = async f } } catch (error) { + logger.error(error); reject(error); } }); From c1af00403a3318ef9ac60e4dbe27294271c50293 Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 31 Mar 2025 10:46:01 +0200 Subject: [PATCH 21/22] Observing "Request failed with status code 404 from element (II time)" for the devices available in MWDI cache Fixes #237 --- server/service/IndividualServicesService.js | 12 ++---------- .../CyclicProcessService/cyclicProcess.js | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index e112b1e..31ff9e4 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -1133,9 +1133,6 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched throw error; } } catch (error) { - logger.error(error, "***********catch main try Error '404' for URL: "); - // logger.error("*********** response status:" + response.status); - // logger.error("*********** response messge:" + response.data); throw error; } } @@ -1207,19 +1204,16 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr if (response.data == '') { logger.warn("Get empty data from ODL - mountname: " + mountName); return response.data; - // TODO Lorenzo Latta to be check - // throw new Error("Empty data from " + fullUrl); // no that should not happen } else { + logger.info("Get data from ODL - mountname: " + mountName); return response.data; } } catch (error) { - logger.error(error, "KO - Get data from ODL - mountname: " + mountName); + logger.error(error, "Failing Get data from ODL - mountname: " + mountName); throw error; } - } catch (error) { - logger.error(error, "KO - Get data from ODL - mountname: " + mountName); throw error; } } @@ -1734,8 +1728,6 @@ const readCurrentMacTableFromDeviceCallbacks = async function (body, user, origi }); } -exports.readCurrentMacTableFromDeviceCallbacks; - exports.readCurrentMacTableFromDevice = function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { return new Promise(async function (resolve, reject) { const mountName = body[MOUNT_NAME]; diff --git a/server/service/individualServices/CyclicProcessService/cyclicProcess.js b/server/service/individualServices/CyclicProcessService/cyclicProcess.js index e0924c0..f35c076 100644 --- a/server/service/individualServices/CyclicProcessService/cyclicProcess.js +++ b/server/service/individualServices/CyclicProcessService/cyclicProcess.js @@ -40,7 +40,7 @@ async function sendRequest(device, user, originator, xCorrelator, traceIndicator try { // Sent request to "read current MacTable from Device" - await individualServices.readCurrentMacTableFromDeviceCallbacks(body, user, originator, xCorrelator, traceIndicator, customerJourney); + await individualServices.readCurrentMacTableFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney); return { 'ret': { 'code': 200, 'message': 'Correctly Managed' }, From 9a8ebdb7429a4c2f704129f948c56d9fe20a47cc Mon Sep 17 00:00:00 2001 From: Lorenzo Latta Date: Mon, 31 Mar 2025 12:59:21 +0200 Subject: [PATCH 22/22] Update the logger level --- server/service/LoggingService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/service/LoggingService.js b/server/service/LoggingService.js index 74b8982..1007522 100644 --- a/server/service/LoggingService.js +++ b/server/service/LoggingService.js @@ -10,10 +10,10 @@ const transports = pino.transport({ options: { colorize: true } }, { - level: 'info', + level: 'warn', target: 'pino-roll', options: { file: path.join(__dirname, '../logs/MacAddressTableRecorder'), extension: '.log', mkdir: true, - frequency: 'daily', dateFormat: 'yyyy-MM-dd', size: "1m", "limit.count": 15 } + frequency: 'daily', dateFormat: 'yyyy-MM-dd', size: "1m", "limit.count": 10 } } ] });