Skip to content

Commit

Permalink
Merge pull request #212 from openBackhaul:schiavi-siae/issue210
Browse files Browse the repository at this point in the history
Observing 500 error with API : /v1/provide-list-of-network-element-interfaces-on-path-in-generic-representation
  • Loading branch information
schiavi-siae authored Mar 25, 2024
2 parents 32669bd + 29930b9 commit 19628fc
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions server/service/IndividualServicesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,25 @@ const EmbeddingCausesRequestForListOfDevicesAtMwdi = async function (user, origi


function generateMountAndEgressPairs(data) {
const uniquePairs = {};
const formattedArray = [];

data.forEach(entry => {
const key = `${entry["mount-name"]}:${entry["egress-ltp-uuid"]}`;
uniquePairs[key] = true;
const mounts = {};

data[0].forEach(entry => {
const mountname = entry['mount-name'];
const egressltpuuid = entry['egress-ltp-uuid'];
if (mounts[mountname]) {
mounts[mountname].push(egressltpuuid);
} else {
mounts[mountname] = [egressltpuuid];
}
});

return Object.keys(uniquePairs);
for (const [mount, egresses] of Object.entries(mounts)) {
formattedArray.push(`${mount}:${egresses.join(':')}`);
}

return formattedArray;
}


Expand Down Expand Up @@ -687,27 +698,10 @@ const RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSear
} catch (error) {
reject(error);
}

/* if (transformedArray != null) {
result = generateMountAndEgressPairs(transformedArray);
if (result != null)
resultString = result.join(';');
else
resolve(null);
if (resultString.length > 0) {
resolve(resultString);
} else {
resolve(null);
}
}
else
resolve(null);*/

});
};


/**
* Provides unsorted list of network element interfaces on path to specific MAC address.
*
Expand Down Expand Up @@ -753,12 +747,11 @@ exports.provideListOfNetworkElementInterfacesOnPath = async function (body, url)
**/
exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = async function (body, req) {
return new Promise(async function (resolve, reject) {

const inputValueList = body["input-value-list"];
let fieldValues;
let fieldValueFinal = [];
let result = [];
let responseValueVist;
let result = [];
let arrayMountNameInterface = [];

let operationServerName = req;

Expand All @@ -777,7 +770,14 @@ exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = asy
});
}

// Loop attraverso ogni elemento di fieldValues e esegui la richiesta per ciascuno
let startTime = process.hrtime();
let responseCode = responseCodeEnum.code.OK;
let responseBodyToDocument = {};

let consequentActionList = await genericRepresentation.getConsequentActionList(operationServerName);
let responseValueList = await genericRepresentation.getResponseValueList(operationServerName);


const promises = fieldValueFinal.map(fieldValue => {
return RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSearch(fieldValue)
.then(
Expand All @@ -793,22 +793,23 @@ exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = asy
}
});
});



let existingItem = false;
let element;

Promise.all(promises)
.then(response => {
result.push({
"value": response,
"datatype": "string",
"field-name": "listOfNetworkElementInterfacesOnPath"
const arrayMountNameInterface = generateMountAndEgressPairs(response);

arrayMountNameInterface.forEach(entry => {
result.push({
"value": entry,
"datatype": "string",
"field-name": responseValueList[0]["fieldName"]
});
});


let fullResponse =
{
"consequent-action-list": [],
"consequent-action-list": consequentActionList,
"response-value-list": result
}

Expand All @@ -820,7 +821,6 @@ exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = asy
});
}


function orderData(input) {

const output = {
Expand Down

0 comments on commit 19628fc

Please sign in to comment.