<commit_before>
/**
 * Copyright (c) 2013 Cask Data, Inc.
 */

var util = require('util'),
  fs = require('fs'),
  xml2js = require('xml2js'),
  sys = require('sys'),
  cluster = require('cluster'),
  http = require('http'),
  https = require('https'),
  os = require('os');

var WebAppServer = require('../common/server');

// The location of continuuity-site.xml
var CONF_DIRECTORY = '/etc/cdap/conf';
// Default port for the Dashboard.
var DEFAULT_BIND_PORT = 9999;

/**
 * Set environment.
 */
process.env.NODE_ENV = 'production';

/**
 * Log level.
 */
var logLevel = 'INFO';

var EntServer = function() {
  var self = this;
  EntServer.super_.call(self, __dirname, logLevel, 'Enterprise UI');
  this.getConfig(function(version) {
    if (self.config['dashboard.https.enabled'] === "true") {
      console.log("HTTPS Enabled");
      this.lib = https;
      this.httpsEnabled = true;
    } else {
      console.log("HTTPS is not Enabled");
      this.lib = http;
      this.httpsEnabled = false;
    }

    self.cookieName = 'continuuity-enterprise-edition';
    self.secret = 'enterprise-edition-secret';
    self.setCookieSession(self.cookieName, self.secret);
    self.configureExpress();
  });
};
util.inherits(EntServer, WebAppServer);

/**
 * Sets config data for application server.
 * @param {Function} opt_callback Callback function to start sever start process.
 */
EntServer.prototype.getConfig = function(opt_callback) {
  var self = this;
  fs.readFile(CONF_DIRECTORY + '/cdap-site.xml', function(error, result) {

    if (error) {
      self.logger.error('Could not read configuration file at ' + CONF_DIRECTORY + '/cdap-site.xml');
      return;
    }

    var parser = new xml2js.Parser();
    parser.parseString(result, function(err, result) {
      result = result.configuration.property;
      var localhost = self.getLocalHost();
      for (var item in result) {
        item = result[item];
        self.config[item.name] = item.value[0];
      }
    });
    self.Api.configure(self.config, null);
    self.configSet = true;

    fs.readFile(process.env.COMPONENT_HOME + '/VERSION', "utf-8", function(error, version) {

      if (typeof opt_callback === "function") {
        opt_callback(version);
      }

    });
  });
};

/**
 * Starts the server after getting config, sets up socket io, configures route handlers.
 */
EntServer.prototype.start = function() {
  var self = this;

  self.getConfig(function(version) {
    if (self.config['dashboard.https.enabled'] === "true") {
      self.lib = https;
      self.httpsEnabled = true;
      self.server = self.getHttpsServerInstance(self.app, self.config['dashboard.ssl.key'],
                                                self.config['dashboard.ssl.cert']);
    } else {
      self.lib = http;
      self.httpsEnabled = false;
      self.server = self.getServerInstance(self.app);
    }

    if (!('dashboard.bind.port' in self.config)) {
      self.config['dashboard.bind.port'] = DEFAULT_BIND_PORT;
    }

    var clusters = 'webapp.cluster.count' in self.config ? self.config['webapp.cluster.count'] : 2;

    self.setEnvironment('enterprise', 'Enterprise Reactor', version, function () {

      self.bindRoutes();
      self.logger.info('I am the master.', cluster.isMaster);

      if (cluster.isMaster) {
        for (var i = 0; i < clusters; i++) {
          cluster.fork();
        }

        cluster.on('online', function (worker) {
          self.logger.info('Worker ' + worker.id + ' was forked with pid ' + worker.process.pid);
        });

        cluster.on('listening', function (worker, address) {
          self.logger.info('Worker ' + worker.id + ' with pid ' + worker.process.pid +
          ' is listening on ' + address.address + ':' + address.port);
        });

        cluster.on('exit', function (worker, code, signal) {
          self.logger.info('Worker ' + worker.process.pid + ' died.');

          // Create a new process once one dies.
          var newWorker = cluster.fork();
          self.logger.info('Started new worker at ' + newWorker.process.pid);
        });

      } else {
        self.server.listen(self.config['dashboard.bind.port']);
      }

      self.logger.info('Listening on port', self.config['dashboard.bind.port']);
      self.logger.info(self.config);

    }.bind(this));

  });
};


var entServer = new EntServer();
entServer.start();

/**
 * Catch anything uncaught.
 */
process.on('uncaughtException', function (err) {
  entServer.logger.info('Uncaught Exception', err);
});

/**
 * Export app.
 */
module.exports = entServer;
<commit_msg>Removes console.log statements<commit_after>
/**
 * Copyright (c) 2013 Cask Data, Inc.
 */

var util = require('util'),
  fs = require('fs'),
  xml2js = require('xml2js'),
  sys = require('sys'),
  cluster = require('cluster'),
  http = require('http'),
  https = require('https'),
  os = require('os');

var WebAppServer = require('../common/server');

// The location of continuuity-site.xml
var CONF_DIRECTORY = '/etc/cdap/conf';
// Default port for the Dashboard.
var DEFAULT_BIND_PORT = 9999;

/**
 * Set environment.
 */
process.env.NODE_ENV = 'production';

/**
 * Log level.
 */
var logLevel = 'INFO';

var EntServer = function() {
  var self = this;
  EntServer.super_.call(self, __dirname, logLevel, 'Enterprise UI');
  this.getConfig(function(version) {
    if (self.config['dashboard.https.enabled'] === "true") {
      this.lib = https;
      this.httpsEnabled = true;
    } else {
      this.lib = http;
      this.httpsEnabled = false;
    }

    self.cookieName = 'continuuity-enterprise-edition';
    self.secret = 'enterprise-edition-secret';
    self.setCookieSession(self.cookieName, self.secret);
    self.configureExpress();
  });
};
util.inherits(EntServer, WebAppServer);

/**
 * Sets config data for application server.
 * @param {Function} opt_callback Callback function to start sever start process.
 */
EntServer.prototype.getConfig = function(opt_callback) {
  var self = this;
  fs.readFile(CONF_DIRECTORY + '/cdap-site.xml', function(error, result) {

    if (error) {
      self.logger.error('Could not read configuration file at ' + CONF_DIRECTORY + '/cdap-site.xml');
      return;
    }

    var parser = new xml2js.Parser();
    parser.parseString(result, function(err, result) {
      result = result.configuration.property;
      var localhost = self.getLocalHost();
      for (var item in result) {
        item = result[item];
        self.config[item.name] = item.value[0];
      }
    });
    self.Api.configure(self.config, null);
    self.configSet = true;

    fs.readFile(process.env.COMPONENT_HOME + '/VERSION', "utf-8", function(error, version) {

      if (typeof opt_callback === "function") {
        opt_callback(version);
      }

    });
  });
};

/**
 * Starts the server after getting config, sets up socket io, configures route handlers.
 */
EntServer.prototype.start = function() {
  var self = this;

  self.getConfig(function(version) {
    if (self.config['dashboard.https.enabled'] === "true") {
      self.lib = https;
      self.httpsEnabled = true;
      self.server = self.getHttpsServerInstance(self.app, self.config['dashboard.ssl.key'],
                                                self.config['dashboard.ssl.cert']);
    } else {
      self.lib = http;
      self.httpsEnabled = false;
      self.server = self.getServerInstance(self.app);
    }

    if (!('dashboard.bind.port' in self.config)) {
      self.config['dashboard.bind.port'] = DEFAULT_BIND_PORT;
    }

    var clusters = 'webapp.cluster.count' in self.config ? self.config['webapp.cluster.count'] : 2;

    self.setEnvironment('enterprise', 'Enterprise Reactor', version, function () {

      self.bindRoutes();
      self.logger.info('I am the master.', cluster.isMaster);

      if (cluster.isMaster) {
        for (var i = 0; i < clusters; i++) {
          cluster.fork();
        }

        cluster.on('online', function (worker) {
          self.logger.info('Worker ' + worker.id + ' was forked with pid ' + worker.process.pid);
        });

        cluster.on('listening', function (worker, address) {
          self.logger.info('Worker ' + worker.id + ' with pid ' + worker.process.pid +
          ' is listening on ' + address.address + ':' + address.port);
        });

        cluster.on('exit', function (worker, code, signal) {
          self.logger.info('Worker ' + worker.process.pid + ' died.');

          // Create a new process once one dies.
          var newWorker = cluster.fork();
          self.logger.info('Started new worker at ' + newWorker.process.pid);
        });

      } else {
        self.server.listen(self.config['dashboard.bind.port']);
      }

      self.logger.info('Listening on port', self.config['dashboard.bind.port']);
      self.logger.info(self.config);

    }.bind(this));

  });
};


var entServer = new EntServer();
entServer.start();

/**
 * Catch anything uncaught.
 */
process.on('uncaughtException', function (err) {
  entServer.logger.info('Uncaught Exception', err);
});

/**
 * Export app.
 */
module.exports = entServer;

{'fraction_non_alphanumeric': 0.15537717176160107, 'fraction_numerical': 0.003298878381350341, 'mean_word_length': 2.7959098497495827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4103157', 'n_tokens_mistral': 2818, 'n_tokens_neox': 2763, 'n_words': 606}