Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use field "operation-key" in load.json to store authentication data #172

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 91 additions & 52 deletions server/service/IndividualServicesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,10 @@ const RequestForDeleteEquipmentIntoElasticSearch = async function (mountName) {
id: mountName
});

resolve(result);

if (Object.keys(result).length > 0) {
resolve(result);
} else {
resolve();
resolve(null);
}
console.log('Remove mountName={' + mountName + '}');
}
Expand All @@ -287,40 +285,45 @@ const findNotConnectedElements = async function (listJsonES, listJsonMD) {
let listES;
let listMD;

if (listJsonES == null)
resolve(null);
else {
listES = listJsonES["mount-name-list"];
if (listJsonMD != null) {
listMD = listJsonMD["mount-name-list"];

// Filter the elements present in listES but not in listMD
let missingElements = listES.filter(element => !listMD.includes(element));

if (missingElements.length > 0) {
// Create a new JSON object with the result
const resultJSON = {
"mount-name-list": missingElements
};
resolve(resultJSON);
}
else {
resolve(null);
try {
if (listJsonES == null)
resolve(null);
else {
listES = listJsonES["mount-name-list"];
if (listJsonMD != null) {
listMD = listJsonMD["mount-name-list"];

// Filter the elements present in listES but not in listMD
let missingElements = listES.filter(element => !listMD.includes(element));

if (missingElements.length > 0) {
// Create a new JSON object with the result
const resultJSON = {
"mount-name-list": missingElements
};
resolve(resultJSON);
}
else {
resolve(null);
}
}
}
}
catch (error) {
reject(error)
}
});
}

function areEqualArray(listJsonES, listJsonMD) {
let array1 = null;
let array2 = null;

if (listJsonES != null) {
if (listJsonES != null && listJsonES != undefined) {
array1 = listJsonES["mount-name-list"];
}

if (listJsonMD != null) {
if (listJsonMD != null && listJsonMD != undefined) {
array2 = listJsonMD["mount-name-list"];
}

Expand Down Expand Up @@ -353,6 +356,8 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor
let result;
let listDisconnectedEq = [];
let oldConnectedListFromES = null;
let newConnectedListFromMwdi = null;
let listJsonDisconnectedEq = [];
return new Promise(async function (resolve, reject) {
try {
//"mount-name-list" from ES
Expand All @@ -368,34 +373,65 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor
//MIDW applicationInfo
let MIDWApplicationInfo = await EmbeddingCausesRequestForListOfApplicationsAtRo(user, originator, xCorrelator, traceIndicator, customerJourney);
}
catch(error) {
catch (error) {
console.error('MIDW application is not registered. Skypping');
}

//mountName - list from network/Mwdi
let newConnectedListFromMwdi = await EmbeddingCausesRequestForListOfDevicesAtMwdi(user, originator, xCorrelator, traceIndicator, customerJourney);
try {
//mountName - list from network/Mwdi
newConnectedListFromMwdi = await EmbeddingCausesRequestForListOfDevicesAtMwdi(user, originator, xCorrelator, traceIndicator, customerJourney);
}
catch (error) {
console.error('No Equipment connected. Retry to read...');
newConnectedListFromMwdi = null;
}

//list of equipment that was connected (mac-address data in ES) but now that are not connected
const listJsonDisconnectedEq = await findNotConnectedElements(oldConnectedListFromES, newConnectedListFromMwdi);
if (newConnectedListFromMwdi != null) {
try {
//list of equipment that was connected (mac-address data in ES) but now that are not connected
listJsonDisconnectedEq = await findNotConnectedElements(oldConnectedListFromES, newConnectedListFromMwdi);
}
catch (error) {
listJsonDisconnectedEq = null;
console.error('No Equipment disconnected');
}

//Write new "mountName - list" list into ES
if (areEqualArray(oldConnectedListFromES, newConnectedListFromMwdi) == false) {
result = await RequestForWriteListConnectedEquipmentIntoElasticSearch(newConnectedListFromMwdi);
}

if (listJsonDisconnectedEq != null) {
listDisconnectedEq = listJsonDisconnectedEq["mount-name-list"];
console.log("Number of disconnected equipment:" + listDisconnectedEq.length + "=> remove mac-adress data from ES");
//Write new "mount-name-list" list into ES
if (areEqualArray(oldConnectedListFromES, newConnectedListFromMwdi) == false) {
try {
result = await RequestForWriteListConnectedEquipmentIntoElasticSearch(newConnectedListFromMwdi);
}
catch (error) {
console.error('Error during updating operation of mount-name-list into db');
}
}

//remove mac-address data in ES of equipment that are that are no longer connected
if (Array.isArray(listDisconnectedEq)) {
for (const elementToRemove of listDisconnectedEq) {
RequestForDeleteEquipmentIntoElasticSearch(elementToRemove);
if (listJsonDisconnectedEq != null) {
listDisconnectedEq = listJsonDisconnectedEq["mount-name-list"];
console.log("Number of disconnected equipment:" + listDisconnectedEq.length + "=> remove mac-adress data from ES");

//remove mac-address data in ES of equipment that are that are no longer connected
try {
if (Array.isArray(listDisconnectedEq)) {
for (const elementToRemove of listDisconnectedEq) {
try{
RequestForDeleteEquipmentIntoElasticSearch(elementToRemove);
}
catch(error)
{
console.error('Error during deleting operation of old mac address data into db (' + elementToRemove +')');
}
}
}
}
catch (error) {
console.error('Error during deleting operation of old mac address data into db');
}
}
}

resolve(newConnectedListFromMwdi);

}
catch (error) {
reject(error);
Expand All @@ -409,6 +445,7 @@ const EmbeddingCausesRequestForListOfApplicationsAtRo = async function (user, or
return new Promise(async function (resolve, reject) {
try {

let auth = "Basic YWRtaW46YWRtaW4=";
let applicationNameAndHttpClient =
await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName('EmbeddingCausesRequestForListOfApplicationsAtRo');

Expand All @@ -435,9 +472,6 @@ const EmbeddingCausesRequestForListOfApplicationsAtRo = async function (user, or
let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName;
console.log("url = " + finalUrl);

//TO FIX
let auth = "Basic YWRtaW46YWRtaW4=";

let httpRequestHeader = new RequestHeader(
user,
originator,
Expand All @@ -447,6 +481,9 @@ const EmbeddingCausesRequestForListOfApplicationsAtRo = async function (user, or
operationKey
);

if (operationKey != "Operation key not yet provided.")
auth = httpRequestHeader['operationKey'];

let httpRequestHeaderAuth = {
"content-type": httpRequestHeader['contentType'],
"user": httpRequestHeader['user'],
Expand Down Expand Up @@ -496,7 +533,7 @@ const EmbeddingCausesRequestForListOfApplicationsAtRo = async function (user, or
const EmbeddingCausesRequestForListOfDevicesAtMwdi = async function (user, originator, xCorrelator, traceIndicator, customerJourney) {
return new Promise(async function (resolve, reject) {
try {

let auth = "Basic YWRtaW46YWRtaW4=";
let applicationNameAndHttpClient =
await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName('EmbeddingCausesRequestForListOfDevicesAtMwdi');

Expand All @@ -523,9 +560,6 @@ const EmbeddingCausesRequestForListOfDevicesAtMwdi = async function (user, origi
let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName;
console.log("url = " + finalUrl);

//TO FIX
let auth = "Basic YWRtaW46YWRtaW4=";


let httpRequestHeader = new RequestHeader(
user,
Expand All @@ -536,6 +570,10 @@ const EmbeddingCausesRequestForListOfDevicesAtMwdi = async function (user, origi
operationKey
);

if (operationKey != "Operation key not yet provided.")
auth = httpRequestHeader['operationKey']; //#issue171


let httpRequestHeaderAuth = {
"content-type": httpRequestHeader['contentType'],
"user": httpRequestHeader['user'],
Expand Down Expand Up @@ -563,11 +601,11 @@ const EmbeddingCausesRequestForListOfDevicesAtMwdi = async function (user, origi
console.log("Number of connected devices = " + response.data['mount-name-list'].length);
resolve(response.data);
} catch (error) {
resolve(error);
reject(error);
}

} catch (error) {
resolve(error);
reject(error);
}
});
};
Expand Down Expand Up @@ -993,6 +1031,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched
//STEP 2
async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice(mountName, user, originator, xCorrelator, traceIndicator, customerJourney) {
try {
let auth = "Basic YWRtaW46YWRtaW4=";
let applicationNameAndHttpClient =
await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice');

Expand Down Expand Up @@ -1037,8 +1076,8 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr
{}
};

//TO FIX
let auth = "Basic YWRtaW46YWRtaW4=";
if (operationKey != "Operation key not yet provided.")
auth = httpRequestHeader['operationKey']; //#issue171

let httpRequestHeaderAuth = {
"content-type": httpRequestHeader['contentType'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function startTtlChecking() {
if (slidingWindow.length == 0) {
clearInterval(handle);
handle = 0; // I just do this so I know I've cleared the interval
stop = false;
stop = false;
MATRCycle(2);
}
}
Expand Down Expand Up @@ -304,10 +304,10 @@ async function requestMessage(index) {
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(printListDevice('Device List', deviceList), print_log_level >= 2);
printLog(printList('Sliding Window', slidingWindow), print_log_level >= 1);
requestMessage(slidingWindow.length - 1);
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);
}
else {
printLog(printListDevice('Device List', deviceList), print_log_level >= 2);
Expand Down Expand Up @@ -345,6 +345,8 @@ module.exports.embeddingCausesCyclicRequestsForUpdatingMacTableFromDeviceAtMatr

async function MATRCycle(logging_level) {

let deviceListMount = null;

printLog('*****************************************************************', print_log_level >= 1);
printLog(' ', print_log_level >= 1);
printLog(' START MATR CYCLE ', print_log_level >= 1);
Expand All @@ -365,7 +367,10 @@ async function MATRCycle(logging_level) {
let customerJourney = "Unknown value";

try {
let deviceListMount = await individualServices.updateCurrentConnectedEquipment(user, originator, xCorrelator, traceIndicator, customerJourney);
do {
deviceListMount = await individualServices.updateCurrentConnectedEquipment(user, originator, xCorrelator, traceIndicator, customerJourney);
} while (deviceListMount == null);

deviceList = deviceListMount['mount-name-list'];

slidingWindowSize = (slidingWindowSizeDb > deviceList.length) ? deviceList.length : slidingWindowSizeDb;
Expand All @@ -379,6 +384,7 @@ async function MATRCycle(logging_level) {

printLog(printList('Sliding Window - MAIN', slidingWindow), print_log_level >= 1);
startTtlChecking();

}
catch (error) {
console.error("Error on MATR cycle: " + error);
Expand Down
Loading