<commit_before># -*- encoding: utf-8 -*-
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
##   https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : elasticsearch_helper.rb
## Author : DennyZhang.com <<EMAIL>>
## Description :
## --
## Created : <2016-05-10>
## Updated: Time-stamp: <2016-06-05 11:30:50>
##-------------------------------------------------------------------
require 'socket'
require 'serverspec'
require 'open3'

# Required by serverspec
set :backend, :exec

################################################################################
def elasticsearch_general_check(es_port)
  # Basic verification logic for elasticsearch installation
  describe command('/usr/share/elasticsearch/bin/elasticsearch --version') do
    its(:stdout) { should contain 'Version: 2.1.1' }
  end

  describe service('elasticsearch') do
    it { should be_running }
  end

  describe port(es_port) do
    it { should be_listening }
  end
end

def verify_es_node_count(server_ip, tcp_port, expected_node_count)
  describe command("curl '#{server_ip}:#{tcp_port}/_cat/nodes' | wc -l") do
    its(:stdout) { should eq "#{expected_node_count}\n" }
  end
end

def verify_es_cluster_health(server_ip, es_port)<commit_msg>update serverspec<commit_after># -*- encoding: utf-8 -*-
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
##   https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : elasticsearch_helper.rb
## Author : DennyZhang.com <<EMAIL>>
## Description :
## --
## Created : <2016-05-10>
## Updated: Time-stamp: <2016-06-07 09:52:27>
##-------------------------------------------------------------------
require 'socket'
require 'serverspec'
require 'open3'

# Required by serverspec
set :backend, :exec

################################################################################
def elasticsearch_general_check(es_port, cmd_pattern)
  # Basic verification logic for elasticsearch installation
  describe command('/usr/share/elasticsearch/bin/elasticsearch --version') do
    its(:stdout) { should contain 'Version: 2.1.1' }
  end

  describe service('elasticsearch') do
    it { should be_running }
  end

  describe port(es_port) do
    it { should be_listening }
  end

  es_pidfile = '/var/run/elasticsearch/elasticsearch.pid'
  # TODO: dependes on general_helper.rb
  verify_process_cmdline_by_pidfile(es_pidfile, cmd_pattern)
end

def verify_es_node_count(server_ip, tcp_port, expected_node_count)
  describe command("curl '#{server_ip}:#{tcp_port}/_cat/nodes' | wc -l") do
    its(:stdout) { should eq "#{expected_node_count}\n" }
  end
end

def verify_es_cluster_health(server_ip, es_port)
{'fraction_non_alphanumeric': 0.2639036486007793, 'fraction_numerical': 0.021962451292950762, 'mean_word_length': 3.1407624633431084, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '4804372', 'n_tokens_mistral': 852, 'n_tokens_neox': 807, 'n_words': 181}