From 2782defe83eefbcdc125bab9c9fa993a622c356e Mon Sep 17 00:00:00 2001 From: Theo Nam Truong Date: Tue, 28 Mar 2023 18:05:29 -0600 Subject: [PATCH] Added PIT actions (#155) Removed Legacy X-Pack Point-In-Time API Signed-off-by: Theo Truong --- USER_GUIDE.md | 38 +++++++++- opensearch-api/.gitignore | 1 + opensearch-api/CHANGELOG.md | 2 + .../api/actions/cat/all_pit_segments.rb | 46 ++++++++++++ .../api/actions/cat/pit_segments.rb | 49 +++++++++++++ .../api/actions/close_point_in_time.rb | 50 ------------- .../lib/opensearch/api/actions/create_pit.rb | 45 ++++++++++++ .../opensearch/api/actions/delete_all_pits.rb | 26 +++++++ .../lib/opensearch/api/actions/delete_pit.rb | 30 ++++++++ .../opensearch/api/actions/get_all_pits.rb | 26 +++++++ .../api/actions/open_point_in_time.rb | 72 ------------------- .../api/actions/cat/all_pit_segments_spec.rb | 36 ++++++++++ .../api/actions/cat/pit_segments_spec.rb | 43 +++++++++++ .../api/actions/close_point_in_time_spec.rb | 43 ----------- .../opensearch/api/actions/create_pit_spec.rb | 58 +++++++++++++++ .../api/actions/delete_all_pits_spec.rb | 35 +++++++++ .../opensearch/api/actions/delete_pit_spec.rb | 41 +++++++++++ .../api/actions/get_all_pits_spec.rb | 35 +++++++++ .../api/actions/open_point_in_time_spec.rb | 53 -------------- 19 files changed, 509 insertions(+), 220 deletions(-) create mode 100644 opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb create mode 100644 opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb delete mode 100644 opensearch-api/lib/opensearch/api/actions/close_point_in_time.rb create mode 100644 opensearch-api/lib/opensearch/api/actions/create_pit.rb create mode 100644 opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb create mode 100644 opensearch-api/lib/opensearch/api/actions/delete_pit.rb create mode 100644 opensearch-api/lib/opensearch/api/actions/get_all_pits.rb delete mode 100644 opensearch-api/lib/opensearch/api/actions/open_point_in_time.rb create mode 100644 opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb create mode 100644 opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb delete mode 100644 opensearch-api/spec/opensearch/api/actions/close_point_in_time_spec.rb create mode 100644 opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb create mode 100644 opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb create mode 100644 opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb create mode 100644 opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb delete mode 100644 opensearch-api/spec/opensearch/api/actions/open_point_in_time_spec.rb diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 43f2a6ec1..7a72d51d3 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -1,6 +1,8 @@ - [User Guide](#user-guide) - [Setup](#setup) - [Sample code](#sample-code) + - [Basic Usage](#basic-usage) + - [Point in Time](#point-in-time) - [Amazon OpenSearch Service](#amazon-opensearch-service) # User Guide @@ -24,7 +26,8 @@ Import the client: `require 'opensearch'` ## Sample code - + +### Basic Usage ```ruby require 'opensearch' @@ -106,8 +109,39 @@ response = client.indices.delete( puts response ``` +### Point in Time +Refer to OpenSearch [documentation](https://opensearch.org/docs/latest/point-in-time-api/) for more information on point in time. +```ruby +require 'opensearch-ruby' +client = OpenSearch::Client.new({ host: 'localhost' }) +index = :movies +client.indices.create(index: 'movies') + +# CREATE 3 PITS +client.create_pit index: index, keep_alive: '1m' +client.create_pit index: index, keep_alive: '1m' +client.create_pit index: index, keep_alive: '1m' + +# GET ALL PITS +pits = client.get_all_pits +puts pits + +# DELETE FIRST PIT +client.delete_pit body: { pit_id: [pits.dig('pits', 0, 'pit_id')] } + +# ALL PITS SEGMENTS +puts client.cat.all_pit_segments + +# SEGMENTS FOR A SPECIFIC PIT +puts client.cat.pit_segments body: { pit_id: [pits.dig('pits', 1, 'pit_id')] } + + +# DELETE ALL PITS +puts client.delete_all_pits +``` + ## Amazon OpenSearch Service Requests to [OpenSearch Service and OpenSearch Serverless](https://docs.aws.amazon.com/opensearch-service/index.html) must be signed using the AWS signing protocol. Use `opensearch-aws-sigv4` gem in place of `opensearch-ruby` gem. -For more information, checkout the [USER_GUIDE](opensearch-aws-sigv4/USER_GUIDE.md) of [opensearch-aws-sigv4](opensearch-aws-sigv4). \ No newline at end of file +For more information, checkout the [USER_GUIDE](opensearch-aws-sigv4/USER_GUIDE.md) of [opensearch-aws-sigv4](opensearch-aws-sigv4). diff --git a/opensearch-api/.gitignore b/opensearch-api/.gitignore index d87d4be66..69e476459 100644 --- a/opensearch-api/.gitignore +++ b/opensearch-api/.gitignore @@ -3,6 +3,7 @@ .bundle .config .yardoc +.ruby-version Gemfile.lock InstalledFiles _yardoc diff --git a/opensearch-api/CHANGELOG.md b/opensearch-api/CHANGELOG.md index 46e1fbd09..49fb8bba4 100644 --- a/opensearch-api/CHANGELOG.md +++ b/opensearch-api/CHANGELOG.md @@ -3,9 +3,11 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added +- Added Point-In-Time API ([#136](https://github.com/opensearch-project/opensearch-ruby/issues/136)) ### Changed ### Deprecated ### Removed +- Removed Legacy X-Pack Point-In-Time API ([#136](https://github.com/opensearch-project/opensearch-ruby/issues/136)) ### Fixed ### Security diff --git a/opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb b/opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb new file mode 100644 index 000000000..edeccc85d --- /dev/null +++ b/opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +module OpenSearch + module API + module Cat + module Actions + # Retrieves info of all PIT segments + # + # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml + # @option arguments [List] :h Comma-separated list of column names to display + # @option arguments [Boolean] :help Return help information + # @option arguments [List] :s Comma-separated list of column names or column aliases to sort by + # @option arguments [Boolean] :v Verbose mode. Display column headers + # @option arguments [Hash] :headers Custom HTTP headers + def all_pit_segments(arguments = {}) + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + + + method = OpenSearch::API::HTTP_GET + path = '_cat/pit_segments/_all' + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) + params[:h] = Utils.__listify(params[:h]) if params[:h] + + body = nil + perform_request(method, path, params, body, headers).body + end + + ParamsRegistry.register(:all_pit_segments, [ + :format, + :h, + :help, + :s, + :v + ].freeze) + end + end + end +end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb b/opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb new file mode 100644 index 000000000..70baba9e5 --- /dev/null +++ b/opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +module OpenSearch + module API + module Cat + module Actions + # Retrieves info of certain PIT segments + # + # @option arguments [Hash] body: Must include `pit_id`, which is an array of PIT IDs. (required) + # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml + # @option arguments [List] :h Comma-separated list of column names to display + # @option arguments [Boolean] :help Return help information + # @option arguments [List] :s Comma-separated list of column names or column aliases to sort by + # @option arguments [Boolean] :v Verbose mode. Display column headers + # @option arguments [Hash] :headers Custom HTTP headers + def pit_segments(arguments = {}) + raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] + + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + + + method = OpenSearch::API::HTTP_GET + path = '_cat/pit_segments' + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) + params[:h] = Utils.__listify(params[:h]) if params[:h] + + body = arguments[:body] + perform_request(method, path, params, body, headers).body + end + + ParamsRegistry.register(:pit_segments, [ + :format, + :h, + :help, + :s, + :v + ].freeze) + end + end + end +end diff --git a/opensearch-api/lib/opensearch/api/actions/close_point_in_time.rb b/opensearch-api/lib/opensearch/api/actions/close_point_in_time.rb deleted file mode 100644 index 25fa10209..000000000 --- a/opensearch-api/lib/opensearch/api/actions/close_point_in_time.rb +++ /dev/null @@ -1,50 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# -# Modifications Copyright OpenSearch Contributors. See -# GitHub history for details. -# -# 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. - -module OpenSearch - module API - module Actions - # Close a point in time - # - # @option arguments [Hash] :headers Custom HTTP headers - # @option arguments [Hash] :body a point-in-time id to close - # - # - def close_point_in_time(arguments = {}) - headers = arguments.delete(:headers) || {} - - arguments = arguments.clone - - method = OpenSearch::API::HTTP_DELETE - path = "_pit" - params = {} - - body = arguments[:body] - perform_request(method, path, params, body, headers).body - end - end - end -end diff --git a/opensearch-api/lib/opensearch/api/actions/create_pit.rb b/opensearch-api/lib/opensearch/api/actions/create_pit.rb new file mode 100644 index 000000000..2822805c8 --- /dev/null +++ b/opensearch-api/lib/opensearch/api/actions/create_pit.rb @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +module OpenSearch + module API + module Actions + # Creates a point in time. + # + # @option arguments [String] :index The name(s) of the target index(es) for the PIT. May contain a comma-separated list or a wildcard index pattern. (required) + # @option arguments [String] :keep_alive The amount of time to keep the PIT. (required) + # @option arguments [String] :preference The node or the shard used to perform the search. (default: random) + # @option arguments [String] :routing Specifies to route search requests to a specific shard. + # @option arguments [String] :expand_wildcards The type of index that can match the wildcard pattern. Supports comma-separated values. (default: open) + # @option arguments [String] :allow_partial_pit_creation Specifies whether to create a PIT with partial failures. (default: false) + def create_pit(arguments = {}) + raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] + raise ArgumentError, "Required argument 'keep_alive' missing" unless arguments[:keep_alive] + + arguments = arguments.clone + _index = arguments.delete(:index) + + method = OpenSearch::API::HTTP_POST + path = "#{Utils.__listify(_index)}/_search/point_in_time" + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) + body = nil + + perform_request(method, path, params, body).body + end + + ParamsRegistry.register(:create_pit, [ + :keep_alive, + :preference, + :routing, + :expand_wildcards, + :allow_partial_pit_creation + ].freeze) + end + end +end diff --git a/opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb b/opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb new file mode 100644 index 000000000..8a54084a5 --- /dev/null +++ b/opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +module OpenSearch + module API + module Actions + # Deletes all PITs. + def delete_all_pits(arguments = {}) + method = OpenSearch::API::HTTP_DELETE + path = "_search/point_in_time/_all" + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) + body = nil + + perform_request(method, path, params, body).body + end + + ParamsRegistry.register(:delete_all_pits, [].freeze) + end + end +end diff --git a/opensearch-api/lib/opensearch/api/actions/delete_pit.rb b/opensearch-api/lib/opensearch/api/actions/delete_pit.rb new file mode 100644 index 000000000..19c15ffa6 --- /dev/null +++ b/opensearch-api/lib/opensearch/api/actions/delete_pit.rb @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +module OpenSearch + module API + module Actions + # Deletes one or several PITs. + # + # @option arguments [Hash] body: Must include `pit_id`, which is an array of PIT IDs to be deleted. (required) + def delete_pit(arguments = {}) + raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] + + method = OpenSearch::API::HTTP_DELETE + path = "_search/point_in_time" + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) + body = arguments[:body] + + perform_request(method, path, params, body).body + end + + ParamsRegistry.register(:delete_pit, [].freeze) + end + end +end diff --git a/opensearch-api/lib/opensearch/api/actions/get_all_pits.rb b/opensearch-api/lib/opensearch/api/actions/get_all_pits.rb new file mode 100644 index 000000000..f4cda7f20 --- /dev/null +++ b/opensearch-api/lib/opensearch/api/actions/get_all_pits.rb @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +module OpenSearch + module API + module Actions + # Gets all PITs. + def get_all_pits(arguments = {}) + method = OpenSearch::API::HTTP_GET + path = "_search/point_in_time/_all" + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) + body = nil + + perform_request(method, path, params, body).body + end + + ParamsRegistry.register(:get_all_pits, [].freeze) + end + end +end diff --git a/opensearch-api/lib/opensearch/api/actions/open_point_in_time.rb b/opensearch-api/lib/opensearch/api/actions/open_point_in_time.rb deleted file mode 100644 index 95b1e98bd..000000000 --- a/opensearch-api/lib/opensearch/api/actions/open_point_in_time.rb +++ /dev/null @@ -1,72 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# -# Modifications Copyright OpenSearch Contributors. See -# GitHub history for details. -# -# 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. - -module OpenSearch - module API - module Actions - # Open a point in time that can be used in subsequent searches - # - # @option arguments [List] :index A comma-separated list of index names to open point in time; use `_all` or empty string to perform the operation on all indices - # @option arguments [String] :preference Specify the node or shard the operation should be performed on (default: random) - # @option arguments [String] :routing Specific routing value - # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed) - # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all) - # @option arguments [String] :keep_alive Specific the time to live for the point in time - # @option arguments [Hash] :headers Custom HTTP headers - # - # - def open_point_in_time(arguments = {}) - headers = arguments.delete(:headers) || {} - - arguments = arguments.clone - - _index = arguments.delete(:index) - - method = OpenSearch::API::HTTP_POST - path = if _index - "#{Utils.__listify(_index)}/_pit" - else - "_pit" - end - params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) - - body = nil - perform_request(method, path, params, body, headers).body - end - - # Register this action with its valid params when the module is loaded. - # - # @since 6.2.0 - ParamsRegistry.register(:open_point_in_time, [ - :preference, - :routing, - :ignore_unavailable, - :expand_wildcards, - :keep_alive - ].freeze) - end - end -end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb new file mode 100644 index 000000000..43befe0f2 --- /dev/null +++ b/opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +require 'spec_helper' + +describe 'client.cat#all_pit_segments' do + + let(:expected_args) do + [ + 'GET', + '_cat/pit_segments/_all', + {}, + nil, + {} + ] + end + let(:client) do + Class.new { include OpenSearch::API }.new + end + + it 'does not accept unregistered params' do + expect { + client.cat.all_pit_segments(something: :else) + }.to raise_exception(ArgumentError) + end + + it 'performs the request' do + expect(client_double.cat.all_pit_segments).to eq({}) + end +end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb new file mode 100644 index 000000000..3235737e0 --- /dev/null +++ b/opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +require 'spec_helper' + +describe 'client.cat#pit_segments' do + + let(:expected_args) do + [ + 'GET', + '_cat/pit_segments', + {}, + { pit_id: ['abc'] }, + {} + ] + end + + let(:client) do + Class.new { include OpenSearch::API }.new + end + + it 'requires the :body argument' do + expect { + client.cat.pit_segments + }.to raise_exception(ArgumentError) + end + + it 'does not accept unregistered params' do + expect { + client.cat.pit_segments(body: {}, something: :else) + }.to raise_exception(ArgumentError) + end + + it 'performs the request' do + expect(client_double.cat.pit_segments(body: { pit_id: ['abc'] })).to eq({}) + end +end diff --git a/opensearch-api/spec/opensearch/api/actions/close_point_in_time_spec.rb b/opensearch-api/spec/opensearch/api/actions/close_point_in_time_spec.rb deleted file mode 100644 index 8248a01c0..000000000 --- a/opensearch-api/spec/opensearch/api/actions/close_point_in_time_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# -# Modifications Copyright OpenSearch Contributors. See -# GitHub history for details. -# -# 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 'spec_helper' - -describe 'client#close_point_in_time' do - let(:expected_args) do - [ - 'DELETE', - '_pit', - {}, - nil, - {} - ] - end - - it 'performs the request' do - expect(client_double.close_point_in_time).to eq({}) - end -end diff --git a/opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb b/opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb new file mode 100644 index 000000000..31397f78e --- /dev/null +++ b/opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb @@ -0,0 +1,58 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +require 'spec_helper' + +describe 'client#create_pit' do + let(:expected_args) do + [ + 'POST', + 'movies,books/_search/point_in_time', + { keep_alive: '1m', + preference: :random, + routing: :route, + expand_wildcards: :open, + allow_partial_pit_creation: false }, + nil + ] + end + + let(:client) do + Class.new { include OpenSearch::API }.new + end + + it 'requires the :index argument' do + expect { + client.create_pit(keep_alive: '1m') + }.to raise_exception(ArgumentError) + end + + it 'requires the :index argument' do + expect { + client.create_pit(index: 'movies') + }.to raise_exception(ArgumentError) + end + + it 'does not accept unregistered params' do + expect { + client.create_pit(index: 'movies', keep_alive: '1m', something: 42) + }.to raise_exception(ArgumentError) + end + + it 'performs the request with all optional params' do + expect(client_double.create_pit( + index: %w[movies books], + keep_alive: '1m', + preference: :random, + routing: :route, + expand_wildcards: :open, + allow_partial_pit_creation: false + )).to eq({}) + end +end diff --git a/opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb b/opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb new file mode 100644 index 000000000..1329e7f2f --- /dev/null +++ b/opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +require 'spec_helper' + +describe 'client#delete_all_pits' do + let(:expected_args) do + [ + 'DELETE', + '_search/point_in_time/_all', + {}, + nil + ] + end + + let(:client) do + Class.new { include OpenSearch::API }.new + end + + it 'does not accept unregistered params' do + expect { + client.delete_all_pits(something: :else) + }.to raise_exception(ArgumentError) + end + + it 'performs the request with all optional params' do + expect(client_double.delete_all_pits).to eq({}) + end +end diff --git a/opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb b/opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb new file mode 100644 index 000000000..fc3f55680 --- /dev/null +++ b/opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +require 'spec_helper' + +describe 'client#delete_pit' do + let(:expected_args) do + [ + 'DELETE', + '_search/point_in_time', + {}, + { pit_id: ['abc'] } + ] + end + + let(:client) do + Class.new { include OpenSearch::API }.new + end + + it 'requires the :body argument' do + expect { + client.delete_pit + }.to raise_exception(ArgumentError) + end + + it 'does not accept unregistered params' do + expect { + client.delete_pit(body: {}, something: :else) + }.to raise_exception(ArgumentError) + end + + it 'performs the request with all optional params' do + expect(client_double.delete_pit(body: { pit_id: ['abc'] })).to eq({}) + end +end diff --git a/opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb b/opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb new file mode 100644 index 000000000..2abfb96ea --- /dev/null +++ b/opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +require 'spec_helper' + +describe 'client#get_all_pits' do + let(:expected_args) do + [ + 'GET', + '_search/point_in_time/_all', + {}, + nil + ] + end + + let(:client) do + Class.new { include OpenSearch::API }.new + end + + it 'does not accept unregistered params' do + expect { + client.get_all_pits(something: :else) + }.to raise_exception(ArgumentError) + end + + it 'performs the request with all optional params' do + expect(client_double.get_all_pits).to eq({}) + end +end diff --git a/opensearch-api/spec/opensearch/api/actions/open_point_in_time_spec.rb b/opensearch-api/spec/opensearch/api/actions/open_point_in_time_spec.rb deleted file mode 100644 index 3aaa3cab3..000000000 --- a/opensearch-api/spec/opensearch/api/actions/open_point_in_time_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# -# Modifications Copyright OpenSearch Contributors. See -# GitHub history for details. -# -# 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 'spec_helper' - -describe 'client#open_point_in_time' do - let(:expected_args) do - [ - 'POST', - url, - {}, - nil, - {} - ] - end - - let (:url) { '_pit'} - - it 'performs the request' do - expect(client_double.open_point_in_time).to eq({}) - end - - context 'with index' do - let (:url) { 'foo/_pit'} - - it 'performs the request' do - expect(client_double.open_point_in_time(index: 'foo')).to eq({}) - end - end -end