2013-11-19 18:21:00 -05:00
|
|
|
#!/usr/bin/env ruby
|
2014-01-06 16:48:02 -05:00
|
|
|
# Licensed to Elasticsearch under one or more contributor
|
|
|
|
# license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright
|
|
|
|
# ownership. Elasticsearch 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
|
2013-11-19 18:21:00 -05:00
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
2014-01-06 16:48:02 -05:00
|
|
|
# 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
|
|
|
|
|
2013-11-19 18:21:00 -05:00
|
|
|
#
|
|
|
|
# generate property file for the jdk randomization test
|
|
|
|
#
|
|
|
|
#
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
class JDKSelector
|
|
|
|
attr_reader :directory, :jdk_list
|
|
|
|
|
|
|
|
def initialize(directory)
|
|
|
|
@directory = directory
|
|
|
|
end
|
|
|
|
|
|
|
|
# get selection of available jdks from jenkins automatic install directory
|
|
|
|
def get_jdk
|
|
|
|
@jdk_list = Dir.entries(directory).select do |x|
|
|
|
|
x.chars.first == 'J'
|
|
|
|
end.map do |y|
|
|
|
|
File.join(directory, y)
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# do ranomize selection from a given array
|
|
|
|
def select_one(selection_array = nil)
|
|
|
|
selection_array ||= @jdk_list
|
|
|
|
selection_array[rand(selection_array.size)]
|
2013-11-21 14:03:22 -05:00
|
|
|
get_random_one(selection_array)
|
2013-11-19 18:21:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-21 14:03:22 -05:00
|
|
|
def get_random_one(data_array)
|
|
|
|
data_array[rand(data_array.size)]
|
|
|
|
end
|
|
|
|
|
2013-11-26 05:00:28 -05:00
|
|
|
# given a jdk directory selection, generate relevant environment variables
|
2013-11-19 18:21:00 -05:00
|
|
|
def get_env_matrix(data_array)
|
2013-11-21 14:03:22 -05:00
|
|
|
|
2013-11-21 15:08:04 -05:00
|
|
|
#refactoring target
|
2013-11-26 05:00:28 -05:00
|
|
|
es_test_jvm_option1 = get_random_one(['-server']) #only server for now get_random_one(['-client', '-server'])
|
|
|
|
greater_than_six = File.basename([*data_array].first).split(/[^0-9]/)[-1].to_i > 6
|
|
|
|
es_test_jvm_option2 = greater_than_six ? get_random_one(['-XX:+UseConcMarkSweepGC', '-XX:+UseParallelGC', '-XX:+UseSerialGC',
|
|
|
|
'-XX:+UseG1GC']) :
|
|
|
|
get_random_one(['-XX:+UseConcMarkSweepGC', '-XX:+UseParallelGC', '-XX:+UseSerialGC'])
|
|
|
|
|
2013-11-21 15:08:04 -05:00
|
|
|
es_test_jvm_option3 = get_random_one(['-XX:+UseCompressedOops', '-XX:-UseCompressedOops'])
|
2013-11-21 14:03:22 -05:00
|
|
|
es_node_mode = get_random_one(['local', 'network'])
|
|
|
|
tests_nightly = get_random_one([true, false])
|
2013-11-26 05:00:28 -05:00
|
|
|
tests_nightly = get_random_one([false]) #bug
|
2013-11-21 14:03:22 -05:00
|
|
|
|
2014-01-15 19:27:46 -05:00
|
|
|
test_assert_off = (rand(10) == 9) #10 percent chance turning it off
|
|
|
|
|
2013-11-19 18:21:00 -05:00
|
|
|
[*data_array].map do |x|
|
2014-01-15 19:27:46 -05:00
|
|
|
data_hash = {
|
2013-11-19 18:21:00 -05:00
|
|
|
'PATH' => File.join(x,'bin') + ':' + ENV['PATH'],
|
2013-11-19 22:04:44 -05:00
|
|
|
'JAVA_HOME' => x,
|
2014-01-15 19:27:46 -05:00
|
|
|
'BUILD_DESC' => "%s,%s,%s%s,%s %s%s"%[File.basename(x), es_node_mode, tests_nightly ? 'nightly,':'',
|
|
|
|
es_test_jvm_option1[1..-1], es_test_jvm_option2[4..-1], es_test_jvm_option3[4..-1],
|
|
|
|
test_assert_off ? ',assert off' : ''],
|
2013-11-21 14:03:22 -05:00
|
|
|
'es.node.mode' => es_node_mode,
|
2013-11-21 15:08:04 -05:00
|
|
|
'tests.nightly' => tests_nightly,
|
2014-01-15 19:27:46 -05:00
|
|
|
'tests.jvm.argline' => "%s %s %s"%[es_test_jvm_option1, es_test_jvm_option2, es_test_jvm_option3],
|
2013-11-19 18:21:00 -05:00
|
|
|
}
|
2014-01-15 19:27:46 -05:00
|
|
|
data_hash['tests.assertion.disabled'] = 'org.elasticsearch' if test_assert_off
|
|
|
|
data_hash
|
2013-11-19 18:21:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# pick first element out of array of hashes, generate write java property file
|
|
|
|
def generate_property_file(directory, data)
|
|
|
|
#array transformation
|
|
|
|
content = data.first.map do |key, value|
|
|
|
|
"%s=%s"%[key, value]
|
|
|
|
end
|
2013-11-21 14:03:22 -05:00
|
|
|
file_name = (ENV['BUILD_ID'] + ENV['BUILD_NUMBER']) || 'prop' rescue 'prop'
|
2013-11-19 22:04:44 -05:00
|
|
|
file_name = file_name.split(File::SEPARATOR).first + '.txt'
|
|
|
|
File.open(File.join(directory, file_name), 'w') do |file|
|
2013-11-19 18:21:00 -05:00
|
|
|
file.write(content.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-19 22:04:44 -05:00
|
|
|
# jenkins sets pwd prior to execution
|
|
|
|
jdk_selector = JDKSelector.new(File.join(ENV['PWD'],'tools','hudson.model.JDK'))
|
|
|
|
environment_matrix = get_env_matrix(jdk_selector.get_jdk.select_one)
|
2013-11-19 18:21:00 -05:00
|
|
|
|
|
|
|
working_directory = ENV['WORKSPACE'] || '/var/tmp'
|
2013-11-19 22:04:44 -05:00
|
|
|
generate_property_file(working_directory, environment_matrix)
|