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

Unable to retrieve all data using API:/provided-mac-table-of-all-devices #232

Merged
merged 1 commit into from
Jul 30, 2024
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
5 changes: 3 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ var expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, 'api/open
var app = expressAppConfig.getApp();
appCommons.setupExpressApp(app);

//TO FIX!
//global.databasePath ='d:/Working/VSCode/MacAddressTableRecorder/server/database/load.json'
//TO REMOVE, ONLY FOR DEBUG
//global.databasePath = 'D:/\VALE/\WorkindDoc/\MICROSERVIZI/\loadjson/\loadMATRRunning.json'
global.databasePath = './database/load.json'


prepareElasticsearch().catch(err => {
console.error(`Error preparing Elasticsearch : ${err}`);
}).finally(
Expand Down
33 changes: 24 additions & 9 deletions server/service/IndividualServicesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,17 +889,19 @@ function orderData(input) {
return output;
}


const PromptForProvidingAllMacTablesCausesReadingFromElasticSearch = async function () {
return new Promise(async function (resolve, reject) {

let client = await elasticsearchService.getClient(false);

let indexAlias = await getIndexAliasAsync();
const response = { 'application/json': [] };

try {
// Inizialize scroll operation
let res2 = await client.search({
index: indexAlias,
_source: 'mac-address',
scroll: '1m', // Keep window scroll opened for 1 minute
body: {
query: {
match: {
Expand All @@ -909,16 +911,28 @@ const PromptForProvidingAllMacTablesCausesReadingFromElasticSearch = async funct
}
});

const response = { 'application/json': [] };
let scrollId = res2.body._scroll_id;
let hits = res2.body.hits.hits;

const hits = res2.body.hits.hits;
for (const hit of hits) {
const source = hit._source['mac-address'];
// Continue to retrieve as long as there are documents.
while (hits.length > 0) {
for (const hit of hits) {
const source = hit._source['mac-address'];

for (const element of source) {
element["time-stamp-of-data"] = formatTimestamp(element["time-stamp-of-data"]);
response['application/json'].push(element);
for (const element of source) {
element["time-stamp-of-data"] = formatTimestamp(element["time-stamp-of-data"]);
response['application/json'].push(element);
}
}

// Next scroll request
res2 = await client.scroll({
scroll_id: scrollId,
scroll: '1m'
});

scrollId = res2.body._scroll_id;
hits = res2.body.hits.hits;
}

if (Object.keys(response).length > 0) {
Expand All @@ -932,6 +946,7 @@ const PromptForProvidingAllMacTablesCausesReadingFromElasticSearch = async funct
});
};


/**
* Responses with a list of MAC tables of all connected devices.
*
Expand Down
Loading