diff --git a/spec/es_spec_helper.rb b/spec/es_spec_helper.rb index 4255d3cd..79157688 100644 --- a/spec/es_spec_helper.rb +++ b/spec/es_spec_helper.rb @@ -1,11 +1,6 @@ require_relative './spec_helper' require 'elasticsearch' -require_relative "support/elasticsearch/api/actions/delete_ilm_policy" -require_relative "support/elasticsearch/api/actions/get_alias" -require_relative "support/elasticsearch/api/actions/put_alias" -require_relative "support/elasticsearch/api/actions/get_ilm_policy" -require_relative "support/elasticsearch/api/actions/put_ilm_policy" require 'json' require 'cabin' @@ -130,31 +125,20 @@ def get_cluster_settings(client) end def get_policy(client, policy_name) - client.get_ilm_policy(name: policy_name) + client.index_lifecycle_management.get_lifecycle(policy: policy_name) end def put_policy(client, policy_name, policy) - client.put_ilm_policy({:name => policy_name, :body=> policy}) - end - - def put_alias(client, the_alias, index) - body = { - "aliases" => { - index => { - "is_write_index"=> true - } - } - } - client.put_alias({name: the_alias, body: body}) + client.index_lifecycle_management.put_lifecycle({:policy => policy_name, :body=> policy}) end def clean_ilm(client) - client.get_ilm_policy.each_key { |key| client.delete_ilm_policy(name: key) if key =~ /logstash-policy/ } + client.index_lifecycle_management.get_lifecycle.each_key { |key| client.index_lifecycle_management.delete_lifecycle(policy: key) if key =~ /logstash-policy/ } end def supports_ilm?(client) begin - client.get_ilm_policy + client.index_lifecycle_management.get_lifecycle true rescue false diff --git a/spec/integration/outputs/ilm_spec.rb b/spec/integration/outputs/ilm_spec.rb index e288e539..0262ab42 100644 --- a/spec/integration/outputs/ilm_spec.rb +++ b/spec/integration/outputs/ilm_spec.rb @@ -282,7 +282,7 @@ subject.register sleep(1) expect(@es.indices.exists_alias(name: "logstash")).to be_truthy - expect(@es.get_alias(name: "logstash")).to include("logstash-000001") + expect(@es.indices.get_alias(name: "logstash")).to include("logstash-000001") end end @@ -298,7 +298,7 @@ subject.register sleep(1) expect(@es.indices.exists_alias(name: "logstash")).to be_truthy - expect(@es.get_alias(name: "logstash")).to include("logstash-#{todays_date}-000001") + expect(@es.indices.get_alias(name: "logstash")).to include("logstash-#{todays_date}-000001") end it 'should ingest into a single index' do @@ -374,7 +374,7 @@ subject.register sleep(1) expect(@es.indices.exists_alias(name: expected_index)).to be_truthy - expect(@es.get_alias(name: expected_index)).to include("#{expected_index}-#{todays_date}-000001") + expect(@es.indices.get_alias(name: expected_index)).to include("#{expected_index}-#{todays_date}-000001") end it 'should write the ILM settings into the template' do @@ -443,17 +443,18 @@ subject.register sleep(1) expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy - expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001") + expect(@es.indices.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001") end context 'when the custom rollover alias already exists' do it 'should ignore the already exists error' do expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey - put_alias(@es, "#{ilm_rollover_alias}-#{todays_date}-000001", ilm_rollover_alias) + @es.indices.create(index: "#{ilm_rollover_alias}-#{todays_date}-000001") + @es.indices.put_alias(name: ilm_rollover_alias, index: "#{ilm_rollover_alias}-#{todays_date}-000001") expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy subject.register sleep(1) - expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001") + expect(@es.indices.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001") end end @@ -536,4 +537,4 @@ def get_expected_error_class return Elastic::Transport::Transport::Errors::NotFound if elastic_ruby_v8_client_available? Elasticsearch::Transport::Transport::Errors::NotFound -end \ No newline at end of file +end diff --git a/spec/support/elasticsearch/api/actions/delete_ilm_policy.rb b/spec/support/elasticsearch/api/actions/delete_ilm_policy.rb deleted file mode 100644 index 83c66f3c..00000000 --- a/spec/support/elasticsearch/api/actions/delete_ilm_policy.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License; -# you may not use this file except in compliance with the Elastic License. - -module Elasticsearch - module API - module Actions - - # Update the password of the specified user - def delete_ilm_policy(arguments={}) - method = HTTP_DELETE - path = Utils.__pathify '_ilm/policy/', - Utils.__escape(arguments[:name]) - params = {} - perform_request(method, path, params, nil).body - end - end - end -end diff --git a/spec/support/elasticsearch/api/actions/get_alias.rb b/spec/support/elasticsearch/api/actions/get_alias.rb deleted file mode 100644 index ef4ebbd4..00000000 --- a/spec/support/elasticsearch/api/actions/get_alias.rb +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License; -# you may not use this file except in compliance with the Elastic License. - -module Elasticsearch - module API - module Actions - - # Retrieve the list of index lifecycle management policies - def get_alias(arguments={}) - method = HTTP_GET - path = Utils.__pathify '_alias', Utils.__escape(arguments[:name]) - params = {} - perform_request(method, path, params, nil).body - end - end - end -end \ No newline at end of file diff --git a/spec/support/elasticsearch/api/actions/get_ilm_policy.rb b/spec/support/elasticsearch/api/actions/get_ilm_policy.rb deleted file mode 100644 index accf9846..00000000 --- a/spec/support/elasticsearch/api/actions/get_ilm_policy.rb +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License; -# you may not use this file except in compliance with the Elastic License. - -module Elasticsearch - module API - module Actions - - # Retrieve the list of index lifecycle management policies - def get_ilm_policy(arguments={}) - method = HTTP_GET - path = Utils.__pathify '_ilm/policy', Utils.__escape(arguments[:name]) - params = {} - perform_request(method, path, params, nil).body - end - end - end -end \ No newline at end of file diff --git a/spec/support/elasticsearch/api/actions/put_alias.rb b/spec/support/elasticsearch/api/actions/put_alias.rb deleted file mode 100644 index 92afe9b2..00000000 --- a/spec/support/elasticsearch/api/actions/put_alias.rb +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License; -# you may not use this file except in compliance with the Elastic License. - -module Elasticsearch - module API - module Actions - - # @option arguments [String] :name The name of the alias (*Required*) - # @option arguments [Hash] :The alias definition(*Required*) - - def put_alias(arguments={}) - raise ArgumentError, "Required argument 'name' missing" unless arguments[:name] - raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] - method = HTTP_PUT - path = Utils.__pathify Utils.__escape(arguments[:name]) - - params = __extract_params(arguments) - body = arguments[:body] - perform_request(method, path, params, body.to_json).body - end - end - end -end diff --git a/spec/support/elasticsearch/api/actions/put_ilm_policy.rb b/spec/support/elasticsearch/api/actions/put_ilm_policy.rb deleted file mode 100644 index 7268c191..00000000 --- a/spec/support/elasticsearch/api/actions/put_ilm_policy.rb +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License; -# you may not use this file except in compliance with the Elastic License. - -module Elasticsearch - module API - module Actions - - COMMON_QUERY_PARAMS = [ - :ignore, # Client specific parameters - :format, # Search, Cat, ... - :pretty, # Pretty-print the response - :human, # Return numeric values in human readable format - :filter_path # Filter the JSON response - ] - - # @option arguments [String] :name The name of the policy (*Required*) - # @option arguments [Hash] :body The policy definition (*Required*) - - def put_ilm_policy(arguments={}) - raise ArgumentError, "Required argument 'name' missing" unless arguments[:name] - raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] - method = HTTP_PUT - path = Utils.__pathify '_ilm/policy/', Utils.__escape(arguments[:name]) - params = __extract_params(arguments) - body = arguments[:body] - perform_request(method, path, params, body.to_json).body - end - - # This method was removed from elasticsearch-ruby client v8 - # Copied from elasticsearch-ruby v7 client to make it available - # - def __extract_params(arguments, params=[], options={}) - result = arguments.select { |k,v| COMMON_QUERY_PARAMS.include?(k) || params.include?(k) } - result = Hash[result] unless result.is_a?(Hash) # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour - result = Hash[result.map { |k,v| v.is_a?(Array) ? [k, Utils.__listify(v, options)] : [k,v] }] # Listify Arrays - result - end - end - end -end