<commit_before>'use strict';

var events = require('events');
var Promise = require('bluebird');
var _ = require('lodash');

function create(customConfig, logger) {
    var hdfsClient = require('node-webhdfs').WebHDFSClient;

    var highAvailibility = false;
    var currentNameNode;

    if (Array.isArray(customConfig.namenode_host)) {
        currentNameNode = customConfig.namenode_host[0];
        customConfig.namenode_list = customConfig.namenode_host;
        highAvailibility = true;
    }
    else {
        currentNameNode = customConfig.namenode_host;
    }

    var config = _.assign({}, customConfig, {namenode_host: currentNameNode});
    var client = new hdfsClient(config);

    logger.info(`Using hdfs hosts: ${currentNameNode}, high-availability: ${highAvailibility}`);

    return {
        client: Promise.promisifyAll(client)
    }
}

function config_schema() {
    return {
        user: {
            doc: '',
            default: 'webuser'
        },
        namenode_port: {
            doc: '',
            default: 50070
        },
        namenode_host: {
            doc: 'a single host, or multiple hosts listed in an array',
            default: [],
            format: function(val) {
                if (typeof val === 'string') {
                    return;
                }
                if (Array.isArray(val)) {
                    if (val.length < 2) {
                        throw new Error("namenode_list must have at least two namenodes listed in the array")
                    }
                    return;
                }
                throw new Error('namenode_list configuration must be set to an array for high availability or a string')
            }
        },
        path_prefix: {
            doc: '',
            default: '/webhdfs/v1'
        }
    }
}<commit_msg>fix internal lib and schema (#78)<commit_after>'use strict';

var events = require('events');
var Promise = require('bluebird');
var _ = require('lodash');

function create(customConfig, logger) {
    var hdfsClient = require('node-webhdfs').WebHDFSClient;

    var highAvailibility = false;
    var currentNameNode;

    if (Array.isArray(customConfig.namenode_host)) {
        currentNameNode = customConfig.namenode_host[0];
        customConfig.namenode_list = customConfig.namenode_host;
        highAvailibility = true;
    }
    else {
        currentNameNode = customConfig.namenode_host;
    }

    var config = _.assign({}, customConfig, {namenode_host: currentNameNode});
    var client = new hdfsClient(config);

    logger.info(`Using hdfs hosts: ${currentNameNode}, high-availability: ${highAvailibility}`);

    return {
        client: Promise.promisifyAll(client)
    }
}

function config_schema() {
    return {
        user: {
            doc: 'user type for hdfs requests',
            default: 'hdfs',
            format: String
        },
        namenode_port: {
            doc: 'port of hdfs',
            default: 50070
        },
        namenode_host: {
            doc: 'a single host, or multiple hosts listed in an array',
            default: [],
            format: function(val) {
                if (typeof val === 'string') {
                    return;
                }
                if (Array.isArray(val)) {
                    if (val.length < 2) {
                        throw new Error("namenode_host must have at least two namenodes listed in the array")
                    }
                    return;
                }
                throw new Error('namenode_host configuration must be set to an array for high availability or a string')
            }
        },
        path_prefix: {
            doc: 'endpoint for hdfs web interface',
            default: '/webhdfs/v1'
        }
    }
}
{'fraction_non_alphanumeric': 0.1020949350304959, 'fraction_numerical': 0.00477326968973747, 'mean_word_length': 1.8191330343796712, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '365106', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1028, 'n_words': 262}