<commit_before>/*
 * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
 */

var rest = require(process.mainModule.exports["corePath"] +
        '/src/serverroot/common/rest.api'),
    config = process.mainModule.exports["config"],
    async = require('async'),
    commonUtils = require(process.mainModule.exports["corePath"] +
                          '/src/serverroot/utils/common.utils'),
    logutils = require(process.mainModule.exports["corePath"] +
                       '/src/serverroot/utils/log.utils'),
    jsonPath = require('JSONPath').eval,
    appErrors = require(process.mainModule.exports["corePath"] +
                        '/src/serverroot/errors/app.errors'),
    adminApiHelper = require('../../../../common/api/adminapi.helper'),
    urlMod = require('url'),
    nwMonUtils = require('../../../../common/api/nwMon.utils'),
    opApiServer = require(process.mainModule.exports["corePath"] +
            '/src/serverroot/common/opServer.api'),
    infraCmn = require('../../../../common/api/infra.common.api'),
    configApiServer = require(process.mainModule.exports["corePath"] +
            '/src/serverroot/common/configServer.api');

opServer = rest.getAPIServer({apiName:global.label.OPS_API_SERVER,
                             server:config.analytics.server_ip,
                             port:config.analytics.server_port });

function getConfigNodesList (req, res, appData)
{
    var url = '/analytics/uves/config-nodes';
    var errResponse = {};

    infraCmn.getUVEByUrlAndSendData(url, errResponse, res, appData);
}

function getConfigNodeDetails (req, res, appData)
{
    var hostName = req.param('hostname');
    var errResponse = {};
    var urlLists = [];
    var resultJSON = {};
    var dataObjArr = [];
    var excludeProcessList = ['contrail-discovery','contrail-svc-monitor','contrail-schema'];
    var genPostData = {};
    reqUrl = '/analytics/uves/config-node/' + hostName + '?flat';
    commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_GET,
                             null, opApiServer, null, appData);
    genPostData['kfilt'] = ['*:contrail-api*',
                            '*:contrail-discovery*',
                            '*:contrail-svc-monitor*',
                            '*:contrail-schema*'];
    reqUrl = '/analytics/uves/generator';
    commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_POST,
                             genPostData, opApiServer, null, appData);
    reqUrl = '/config-nodes?detail=true';
    commonUtils.createReqObj(dataObjArr, reqUrl, null, null,
                             configApiServer, null, appData);
    async.map(dataObjArr,
              commonUtils.getServerResponseByRestApi(configApiServer, true),
              function(err, results) {
        resultJSON = postProcessConfigNodeDetails(results, hostName);
        resultJSON =
            infraCmn.filterOutGeneratorInfoFromGenerators(excludeProcessList,
                                                          resultJSON);
        commonUtils.handleJSONResponse(err, res, resultJSON);
    });
}

function getConfigNodesSummary (req, res, appData)
{
    var nodesHostIp = {'hosts': {}, 'ips': {}};
    var addGen = req.param('addGen');
    var dataObjArr = [];

    var reqUrl = '/analytics/uves/config-node';
    var postData = {};
    postData['cfilt'] = ['ModuleCpuState','NodeStatus', 'UVEAlarms'];
    commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_POST,
                             postData, opApiServer, null, appData);
    reqUrl = '/config-nodes?detail=true';
    commonUtils.createReqObj(dataObjArr, reqUrl, null, null,
                             configApiServer, null, appData);
    if (null != addGen) {
        reqUrl = '/analytics/uves/generator';
        var genPostData = {};
        genPostData['kfilt'] = ['*:contrail-api*'];
        genPostData['cfilt'] = ['ModuleClientState:client_info',
                                'ModuleServerState:generator_info'];
        commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_POST,
                                 genPostData, opApiServer, null, appData);
    }

    var resultJSON = [];

    async.map(dataObjArr,
              commonUtils.getServerResponseByRestApi(opApiServer, true),
              function(err, results) {
        resultJSON = postProcessConfigNodeSummary(results);
        var nodeCnt = 0;
        try {
            nodeCnt = resultJSON.length;
        } catch(e) {
            nodeCnt = 0;
        }
        for (var i = 0; i < nodeCnt; i++) {
            try {
                nodesHostIp['hosts'][resultJSON[i]['name']] = [];
            } catch(e) {
            }
            var nodeIpsCnt = 0;
            try {
                var nodeIps =
                    resultJSON[i]['value']['configNode']['ModuleCpuState']
                                    ['config_node_ip'];
                nodeIpsCnt = nodeIps.length;
            } catch(e) {
                logutils.logger.error("Config UVE IP parse error: " + e);
                nodeIpsCnt = 0;
            }
            for (var j = 0; j < nodeIpsCnt; j++) {<commit_msg>Closes-Bug: #1587368 - Fixing the introspect proxy link in the ConfigNode Details page.<commit_after>/*
 * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
 */

var rest = require(process.mainModule.exports["corePath"] +
        '/src/serverroot/common/rest.api'),
    config = process.mainModule.exports["config"],
    async = require('async'),
    commonUtils = require(process.mainModule.exports["corePath"] +
                          '/src/serverroot/utils/common.utils'),
    logutils = require(process.mainModule.exports["corePath"] +
                       '/src/serverroot/utils/log.utils'),
    jsonPath = require('JSONPath').eval,
    appErrors = require(process.mainModule.exports["corePath"] +
                        '/src/serverroot/errors/app.errors'),
    adminApiHelper = require('../../../../common/api/adminapi.helper'),
    urlMod = require('url'),
    nwMonUtils = require('../../../../common/api/nwMon.utils'),
    opApiServer = require(process.mainModule.exports["corePath"] +
            '/src/serverroot/common/opServer.api'),
    infraCmn = require('../../../../common/api/infra.common.api'),
    configApiServer = require(process.mainModule.exports["corePath"] +
            '/src/serverroot/common/configServer.api');

opServer = rest.getAPIServer({apiName:global.label.OPS_API_SERVER,
                             server:config.analytics.server_ip,
                             port:config.analytics.server_port });

function getConfigNodesList (req, res, appData)
{
    var url = '/analytics/uves/config-nodes';
    var errResponse = {};

    infraCmn.getUVEByUrlAndSendData(url, errResponse, res, appData);
}

function getConfigNodeDetails (req, res, appData)
{
    var hostName = req.param('hostname');
    var errResponse = {};
    var urlLists = [];
    var resultJSON = {};
    var dataObjArr = [];
    var excludeProcessList = ['contrail-discovery','contrail-svc-monitor','contrail-schema'];
    var genPostData = {};
    reqUrl = '/analytics/uves/config-node/' + hostName + '?flat';
    commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_GET,
                             null, opApiServer, null, appData);
    genPostData['kfilt'] = ['*:contrail-api*',
                            '*:contrail-discovery*',
                            '*:contrail-svc-monitor*',
                            '*:contrail-schema*'];
    reqUrl = '/analytics/uves/generator';
    commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_POST,
                             genPostData, opApiServer, null, appData);
    reqUrl = '/config-nodes?detail=true';
    commonUtils.createReqObj(dataObjArr, reqUrl, null, null,
                             configApiServer, null, appData);
    async.map(dataObjArr,
              commonUtils.getServerResponseByRestApi(configApiServer, true),
              function(err, results) {
        resultJSON = postProcessConfigNodeDetails(results, hostName);
        resultJSON =
            infraCmn.filterOutGeneratorInfoFromGenerators(excludeProcessList,
                                                          resultJSON);
        commonUtils.handleJSONResponse(err, res, resultJSON);
    });
}

function getConfigNodesSummary (req, res, appData)
{
    var nodesHostIp = {'hosts': {}, 'ips': {}};
    var addGen = req.param('addGen');
    var dataObjArr = [];

    var reqUrl = '/analytics/uves/config-node';
    var postData = {};
    postData['cfilt'] = ['ModuleCpuState','NodeStatus', 'UVEAlarms'];
    commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_POST,
                             postData, opApiServer, null, appData);
    reqUrl = '/config-nodes?detail=true';
    commonUtils.createReqObj(dataObjArr, reqUrl, null, null,
                             configApiServer, null, appData);
    if (null != addGen) {
        reqUrl = '/analytics/uves/generator';
        var genPostData = {};
        genPostData['kfilt'] = ['*:contrail-api*'];
        genPostData['cfilt'] = ['ModuleClientState:client_info',
                                'ModuleServerState:generator_info'];
        commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_POST,
                                 genPostData, opApiServer, null, appData);
    }

    var resultJSON = [];

    async.map(dataObjArr,
              commonUtils.getServerResponseByRestApi(opApiServer, true),
              function(err, results) {
        resultJSON = postProcessConfigNodeSummary(results);
        var nodeCnt = 0;
        try {
            nodeCnt = resultJSON.length;
        } catch(e) {
            nodeCnt = 0;
        }
        for (var i = 0; i < nodeCnt; i++) {
            try {
                nodesHostIp['hosts'][resultJSON[i]['name']] = [];
            } catch(e) {
            }
            var nodeIpsCnt = 0;
            try {
                var nodeIps =
                    resultJSON[i]['value']['ModuleCpuState']
                                    ['config_node_ip'];
                nodeIpsCnt = nodeIps.length;
            } catch(e) {
                logutils.logger.error("Config UVE IP parse error: " + e);
                nodeIpsCnt = 0;
            }
            for (var j = 0; j < nodeIpsCnt; j++) {
{'fraction_non_alphanumeric': 0.1337770061728395, 'fraction_numerical': 0.0026041666666666665, 'mean_word_length': 2.1440266828380836, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4939372', 'n_tokens_mistral': 2994, 'n_tokens_neox': 2910, 'n_words': 493}