Я использую API Tibco, чтобы получить какой-либо статус сервиса (запущен или остановлен). Мне нужны определенные значения из полученных json. Я использовал для l oop, но это продолжает цикл больше, чем его длина. Может кто-нибудь, пожалуйста, посоветуйте.
Ниже приведен код
var async = require('async');
var fetch = require('node-fetch');
const HttpsProxyAgent = require('https-proxy-agent');
var API_PORT = "8079";
var ALL_DOMAIN_API = "/bw/v1/browse/domains?full=false&status=true";
var URLS = {
cit1: "http://x.x.x.x",
cit2: "http://y.y.y.y"
};
exports.getdomainstatus = function (req, res) {
if (!req.body.env || !URLS[req.body.env]) {
res.status(500).json({ error: "Enviroment details not found...!" });
return;
}
var url = URLS[req.body.env] + ":" + API_PORT + ALL_DOMAIN_API;
//console.log(req.body.env);
//console.log("+++++++++++++++++++++++++++++++++++++++")
console.log(url);
fetch(url, {
method: 'GET',
agent: new HttpsProxyAgent('http://a.a.0.0:50683')
}).then(resRaw => {
return resRaw.text();
}).then(resJson => {
if (!resJson || !resJson.length) {
res.status(200).json({ domainstatus: [] });
return;
}
resJson = JSON.parse(resJson);
//console.log(resJson);
var domainstatus = [];
async.eachLimit(resJson, 1, (domain, callback) => {
if (!domain || !domain.name) {
callback();
return;
}
var statusurl = URLS[req.body.env] + ":" + API_PORT + "/bw/v1/browse/apps?domain=" + domain.name + "&full=false&status=true";
//console.log(statusurl);
fetch(statusurl, {
method: 'GET',
agent: new HttpsProxyAgent('http://0.0.0.0:0000')
}).then(resRaw => {
return resRaw.text();
}).then(itemJson => {
if (!itemJson || !itemJson.length) {
callback();
return;
}
itemJson = JSON.parse(itemJson);
if (!itemJson || !itemJson[0]) {
callback();
return;
}
// console.log("/////////////////////////////////////")
// //console.log(itemJson)
// console.log("===================")
console.log(itemJson.length)
//Here I get Output as 9
console.log("+++++++++++++++++++++++++++++++++")
for (let i = 0; i < itemJson.length; i++) {
//itemJson = itemJson[0];
console.log(itemJson[i].name)
//Here I get correct output
var temp = {
owner: itemJson[i].owner,
name: itemJson[i].name,
date: itemJson[i].date,
description: itemJson[i].description,
status: itemJson[i].state,
domainName: itemJson[i].domainName,
}
console.log("--------")
console.log(i)
console.log(temp)
//domainstatus.push(temp);
//temp.status(200).json({ domainstatus: domainstatus });
}
callback();
}).catch(err => {
callback();
});
}, () => {
console.log("All Completed...!")
});
}).catch(err => {
res.status(500).json({ error: err });
});
}
Я тоже пробовал foreach, но тщетно. Это как-то связано с asyn c .eachLimit. Я попытался использовать второй параметр eachLimit как 1 вместо 10, но тот же результат. пожалуйста, найдите следующий вывод. после 0 до 9 (элемент Json .lenth) он снова начинается с 0 до 9 и повторяется снова.
BS_127_NotifyCustomerOrderStatus.application
--------
0
{ owner: undefined,
name: 'BS_127_NotifyCustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_PPE_001-CustomerOrderStatus.application
--------
1
{ owner: undefined,
name: 'AS_PPE_001-CustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_EX_003-CustomerOrder_EX.application
--------
2
{ owner: undefined,
name: 'AS_EX_003-CustomerOrder_EX.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_FM_003_CustomerBillingAccount.application
--------
3
{ owner: undefined,
name: 'AS_FM_003_CustomerBillingAccount.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_DW_008_UpsertCustomerOrder_DW.application
--------
4
{ owner: undefined,
name: 'AS_DW_008_UpsertCustomerOrder_DW.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_DW_016-CustomerOrderStatus_DW.application
--------
5
{ owner: undefined,
name: 'AS_DW_016-CustomerOrderStatus_DW.application',
date: undefined,
description: '',
status: 'Stopped',
domainName: 'CustomerOrderManagementService' }
AS_FM_004_01_NotifyCustomerOrderStatus.application
--------
6
{ owner: undefined,
name: 'AS_FM_004_01_NotifyCustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_ANV_001-ResourceOrder_ANV.application
--------
7
{ owner: undefined,
name: 'AS_ANV_001-ResourceOrder_ANV.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_FM_005-NotifyCustomerOrderStatus.application
--------
8
{ owner: undefined,
name: 'AS_FM_005-NotifyCustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
+++++++++++++++++++++++++++++++++
9
BS_127_NotifyCustomerOrderStatus.application
--------
0
{ owner: undefined,
name: 'BS_127_NotifyCustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_PPE_001-CustomerOrderStatus.application
--------
1
{ owner: undefined,
name: 'AS_PPE_001-CustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_EX_003-CustomerOrder_EX.application
--------
2
{ owner: undefined,
name: 'AS_EX_003-CustomerOrder_EX.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_FM_003_CustomerBillingAccount.application
--------
3
{ owner: undefined,
name: 'AS_FM_003_CustomerBillingAccount.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_DW_008_UpsertCustomerOrder_DW.application
--------
4
{ owner: undefined,
name: 'AS_DW_008_UpsertCustomerOrder_DW.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_DW_016-CustomerOrderStatus_DW.application
--------
5
{ owner: undefined,
name: 'AS_DW_016-CustomerOrderStatus_DW.application',
date: undefined,
description: '',
status: 'Unreachable',
domainName: 'CustomerOrderManagementService' }
AS_FM_004_01_NotifyCustomerOrderStatus.application
--------
6
{ owner: undefined,
name: 'AS_FM_004_01_NotifyCustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_ANV_001-ResourceOrder_ANV.application
--------
7
{ owner: undefined,
name: 'AS_ANV_001-ResourceOrder_ANV.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
AS_FM_005-NotifyCustomerOrderStatus.application
--------
8
{ owner: undefined,
name: 'AS_FM_005-NotifyCustomerOrderStatus.application',
date: undefined,
description: '',
status: 'Running',
domainName: 'CustomerOrderManagementService' }
+++++++++++++++++++++++++++++++++
9