lib/elasticsearch/extensions/test/cluster.rb in elasticsearch-extensions-0.0.31 vs lib/elasticsearch/extensions/test/cluster.rb in elasticsearch-extensions-0.0.32
- old
+ new
@@ -1,5 +1,22 @@
+# Licensed to Elasticsearch B.V. under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Elasticsearch B.V. licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
require 'timeout'
require 'net/http'
require 'fileutils'
require 'socket'
require 'uri'
@@ -19,11 +36,10 @@
end
module Elasticsearch
module Extensions
module Test
-
# A convenience Ruby class for starting and stopping an Elasticsearch cluster,
# eg. for integration tests
#
# @example Start a cluster with default configuration,
# assuming `elasticsearch` is on $PATH.
@@ -41,40 +57,39 @@
# Elasticsearch::Extensions::Test::Cluster.start command: 'elasticsearch-5.1.1/bin/elasticsearch'
#
# @see Cluster#initialize
#
module Cluster
-
# Starts a cluster
#
# @see Cluster#start
#
- def start(arguments={})
+ def start(arguments = {})
Cluster.new(arguments).start
end
# Stops a cluster
#
# @see Cluster#stop
#
- def stop(arguments={})
+ def stop(arguments = {})
Cluster.new(arguments).stop
end
# Returns true when a specific test node is running within the cluster
#
# @see Cluster#running?
#
- def running?(arguments={})
+ def running?(arguments = {})
Cluster.new(arguments).running?
end
# Waits until the cluster is green and prints information
#
# @see Cluster#wait_for_green
#
- def wait_for_green(arguments={})
+ def wait_for_green(arguments = {})
Cluster.new(arguments).wait_for_green
end
module_function :start, :stop, :running?, :wait_for_green
@@ -188,17 +203,19 @@
-E network.host=#{arguments[:network_host]} \
-E node.attr.testattr=test \
-E path.repo=/tmp \
-E repositories.url.allowed_urls=http://snapshot.test* \
-E discovery.zen.minimum_master_nodes=#{arguments[:number_of_nodes]-1} \
+ -E xpack.security.enabled=false \
-E node.max_local_storage_nodes=#{arguments[:number_of_nodes]} \
-E logger.level=#{ENV['DEBUG'] ? 'DEBUG' : 'INFO'} \
#{arguments[:es_params]}
COMMAND
}
}
COMMANDS['7.0'] = COMMANDS['6.0'].clone
+ COMMANDS['8.0'] = COMMANDS['7.0'].clone
COMMANDS.freeze
# Create a new instance of the Cluster class
#
# @option arguments [String] :cluster_name Cluster name (default: `elasticsearch_test`)
@@ -236,11 +253,15 @@
@arguments[:timeout_version] ||= ENV.fetch('TEST_CLUSTER_TIMEOUT_VERSION', 15).to_i
@arguments[:number_of_nodes] ||= ENV.fetch('TEST_CLUSTER_NODES', 2).to_i
@arguments[:network_host] ||= ENV.fetch('TEST_CLUSTER_NETWORK_HOST', __default_network_host)
@arguments[:quiet] ||= ! ENV.fetch('QUIET', '').empty?
- @clear_cluster = !!@arguments[:clear_cluster] || (ENV.fetch('TEST_CLUSTER_CLEAR', 'true') != 'false')
+ @clear_cluster = if @arguments[:clear_cluster].nil?
+ (ENV.fetch('TEST_CLUSTER_CLEAR', 'true') != 'false')
+ else
+ !!@arguments[:clear_cluster]
+ end
# Make sure `cluster_name` is not dangerous
raise ArgumentError, "The `cluster_name` argument cannot be empty string or a slash" \
if @arguments[:cluster_name] =~ /^[\/\\]?$/
end
@@ -406,11 +427,11 @@
case version
when /^0|^1/
'0.0.0.0'
when /^2/
'_local_'
- when /^5|^6|^7/
+ when /^5|^6|^7|^8/
'_local_'
else
raise RuntimeError, "Cannot determine default network host from version [#{version}]"
end
end
@@ -449,16 +470,17 @@
#
# @return String
#
def __determine_version
path_to_lib = File.dirname(arguments[:command]) + '/../lib/'
+
version = if arguments[:version]
arguments[:version]
elsif File.exist?(path_to_lib) && !(jar = Dir.entries(path_to_lib).select { |f| f =~ /^elasticsearch\-\d/ }.first).nil?
__log "Determining version from [#{jar}]" if ENV['DEBUG']
- if m = jar.match(/elasticsearch\-(\S+-)?(?<version>\d+\.\d+\.\d+).*/)
- m[:version]
+ if m = jar.match(/elasticsearch\-(\d+\.\d+\.\d+).*/)
+ m[1]
else
raise RuntimeError, "Cannot determine Elasticsearch version from jar [#{jar}]"
end
else
__log "[!] Cannot find Elasticsearch .jar from path to command [#{arguments[:command]}], using `#{arguments[:command]} --version`" if ENV['DEBUG']
@@ -506,11 +528,11 @@
if output.empty?
raise RuntimeError, "Cannot determine Elasticsearch version from [#{arguments[:command]} --version] or [#{arguments[:command]} -v]"
end
- if m = output.match(/Version: (\d\.\d.\d).*,/)
+ if(m = output.match(/Version: (\d+\.\d+.\d+).*,/))
m[1]
else
raise RuntimeError, "Cannot determine Elasticsearch version from elasticsearch --version output [#{output}]"
end
end
@@ -526,9 +548,11 @@
'5.0'
when /^6\..*/
'6.0'
when /^7\..*/
'7.0'
+ when /^8\..*/
+ '8.0'
else
raise RuntimeError, "Cannot determine major version from [#{version}]"
end
end