From f4b93d3a5ebdcfd0bd9e2df837223f2022deea03 Mon Sep 17 00:00:00 2001 From: Theo Truong Date: Mon, 10 Jul 2023 11:05:26 -0600 Subject: [PATCH 1/5] [CODE_GEN] Added `remote_store.restore` action Signed-off-by: Theo Truong --- .rubocop.yml | 6 +++ lib/opensearch/api.rb | 44 +++++++++--------- .../api/actions/remote_store/restore.rb | 46 +++++++++++++++++++ lib/opensearch/api/namespace/remote_store.rb | 33 +++++++++++++ .../api/actions/remote_store/restore_spec.rb | 46 +++++++++++++++++++ 5 files changed, 154 insertions(+), 21 deletions(-) create mode 100644 lib/opensearch/api/actions/remote_store/restore.rb create mode 100644 lib/opensearch/api/namespace/remote_store.rb create mode 100644 spec/opensearch/api/actions/remote_store/restore_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index a0e8585e2..90ed82cf3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -25,3 +25,9 @@ Layout/EmptyLineAfterGuardClause: Naming/FileName: Enabled: false + +Layout/FirstArgumentIndentation: + Enabled: false + +Layout/FirstArrayElementIndentation: + Enabled: false diff --git a/lib/opensearch/api.rb b/lib/opensearch/api.rb index d55d1b452..029b46934 100644 --- a/lib/opensearch/api.rb +++ b/lib/opensearch/api.rb @@ -6,7 +6,7 @@ # # 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 @@ -24,8 +24,10 @@ # specific language governing permissions and limitations # under the License. -require 'cgi' -require 'multi_json' +# This code was generated from OpenSearch API Spec. +# Update the code generation logic instead of modifying this file directly. + +# frozen_string_literal: true require 'opensearch/api/namespace/common' require 'opensearch/api/utils' @@ -57,42 +59,42 @@ module API :opaque_id # Use X-Opaque-Id ] - HTTP_GET = 'GET'.freeze - HTTP_HEAD = 'HEAD'.freeze - HTTP_POST = 'POST'.freeze - HTTP_PUT = 'PUT'.freeze - HTTP_DELETE = 'DELETE'.freeze - UNDERSCORE_SEARCH = '_search'.freeze - UNDERSCORE_ALL = '_all'.freeze - DEFAULT_DOC = '_doc'.freeze + HTTP_GET = 'GET' + HTTP_HEAD = 'HEAD' + HTTP_PATCH = 'PATCH' + HTTP_POST = 'POST' + HTTP_PUT = 'PUT' + HTTP_DELETE = 'DELETE' + + UNDERSCORE_SEARCH = '_search' + UNDERSCORE_ALL = '_all' + DEFAULT_DOC = '_doc' # Auto-include all namespaces in the receiver - # def self.included(base) base.send :include, OpenSearch::API::Common, OpenSearch::API::Actions, + OpenSearch::API::Cat, OpenSearch::API::Cluster, - OpenSearch::API::Nodes, + OpenSearch::API::DanglingIndices, + OpenSearch::API::Features, OpenSearch::API::Indices, OpenSearch::API::Ingest, - OpenSearch::API::Snapshot, - OpenSearch::API::Tasks, - OpenSearch::API::Cat, + OpenSearch::API::Nodes, OpenSearch::API::Remote, - OpenSearch::API::DanglingIndices, - OpenSearch::API::Features, - OpenSearch::API::Shutdown + OpenSearch::API::RemoteStore, + OpenSearch::API::Shutdown, + OpenSearch::API::Snapshot, + OpenSearch::API::Tasks end # The serializer class - # def self.serializer settings[:serializer] || DEFAULT_SERIALIZER end # Access the module settings - # def self.settings @settings ||= {} end diff --git a/lib/opensearch/api/actions/remote_store/restore.rb b/lib/opensearch/api/actions/remote_store/restore.rb new file mode 100644 index 000000000..5827580df --- /dev/null +++ b/lib/opensearch/api/actions/remote_store/restore.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. + +# This code was generated from OpenSearch API Spec. +# Update the code generation logic instead of modifying this file directly. + +# frozen_string_literal: true + +module OpenSearch + module API + module RemoteStore + module Actions + RESTORE_QUERY_PARAMS = Set.new(%i[ + cluster_manager_timeout + wait_for_completion + ]).freeze + + # Restores from remote store. + # + # @option arguments [Time] :cluster_manager_timeout Operation timeout for connection to cluster-manager node. + # @option arguments [Boolean] :wait_for_completion Should this request wait until the operation has completed before returning. + # @option arguments [Hash] :body *Required* Comma-separated list of index IDs + # + # {API Reference}[https://opensearch.org/docs/latest/opensearch/remote/#restoring-from-a-backup] + def restore(arguments = {}) + raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] + + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + body = arguments.delete(:body) + url = Utils.__pathify '_remotestore', '_restore' + method = OpenSearch::API::HTTP_POST + params = Utils.__validate_and_extract_params arguments, RESTORE_QUERY_PARAMS + + perform_request(method, url, params, body, headers).body + end + end + end + end +end diff --git a/lib/opensearch/api/namespace/remote_store.rb b/lib/opensearch/api/namespace/remote_store.rb new file mode 100644 index 000000000..313581318 --- /dev/null +++ b/lib/opensearch/api/namespace/remote_store.rb @@ -0,0 +1,33 @@ +# 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. + +# This code was generated from OpenSearch API Spec. +# Update the code generation logic instead of modifying this file directly. + +# frozen_string_literal: true + +module OpenSearch + module API + module RemoteStore + module Actions; end + + # Client for the "remote_store" namespace (includes the RemoteStore::Actions methods) + class RemoteStoreClient + include RemoteStore::Actions + include Common::Client + include Common::Client::Base + end + + # Proxy method for RemoteStoreClient, available in the receiving object + def remote_store + @remote_store ||= RemoteStoreClient.new(self) + end + end + end +end diff --git a/spec/opensearch/api/actions/remote_store/restore_spec.rb b/spec/opensearch/api/actions/remote_store/restore_spec.rb new file mode 100644 index 000000000..3e5c3b2e5 --- /dev/null +++ b/spec/opensearch/api/actions/remote_store/restore_spec.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. + +# This code was generated from OpenSearch API Spec. +# Update the code generation logic instead of modifying this file directly. + +# frozen_string_literal: true + +require_relative '../../../../spec_helper' + +describe 'client.remote_store#restore' do + let(:expected_args) do + [ + 'POST', + '_remotestore/_restore', + { cluster_manager_timeout: '1m', + wait_for_completion: true }, + {}, + {} + ] + end + + let(:client) do + Class.new { include OpenSearch::API }.new + end + + it 'requires the :body argument' do + expect do + client.remote_store.restore + end.to raise_exception(ArgumentError) + end + + it 'performs the request with all optional params' do + expect(client_double.remote_store.restore( + cluster_manager_timeout: '1m', + wait_for_completion: true, + body: {} + )).to eq({}) + end +end From 0752b2c209765e192d4dfbe6276fcfaa2e20b8cb Mon Sep 17 00:00:00 2001 From: Theo Truong Date: Mon, 10 Jul 2023 11:27:00 -0600 Subject: [PATCH 2/5] Added CHANGELOG.md Signed-off-by: Theo Truong --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbf922bdb..23a73eaca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added +- `remote_store.restore` action ([#176](https://github.com/opensearch-project/opensearch-ruby/pull/176)) ### Changed - Merged `opensearch-transport`, `opensearch-api`, and `opensearch-dsl` into `opensearch-ruby` ([#133](https://github.com/opensearch-project/opensearch-ruby/issues/133)) ### Deprecated From cc41734075828254e1f17233338033939230d133 Mon Sep 17 00:00:00 2001 From: Theo Truong Date: Mon, 10 Jul 2023 11:34:06 -0600 Subject: [PATCH 3/5] Corrected Link in transport_options.md Signed-off-by: Theo Truong --- guides/transport_options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/transport_options.md b/guides/transport_options.md index cd793e439..1f986303f 100644 --- a/guides/transport_options.md +++ b/guides/transport_options.md @@ -389,7 +389,7 @@ The serialization component is pluggable, though, so you can write your own by i ### Exception Handling -The library defines a [number of exception classes](https://github.com/opensearch-project/opensearch-ruby/blob/main/opensearch-transport/lib/opensearch/transport/transport/errors.rb) for various client and server errors, as well as unsuccessful HTTP responses, making it possible to `rescue` specific exceptions with desired granularity. +The library defines a [number of exception classes](../lib/opensearch/transport/transport/errors.rb) for various client and server errors, as well as unsuccessful HTTP responses, making it possible to `rescue` specific exceptions with desired granularity. The highest-level exception is {OpenSearch::Transport::Transport::Error} and will be raised for any generic client *or* server errors. From 961fe98493eba39612de3c639a88b1127ff2d8b4 Mon Sep 17 00:00:00 2001 From: Theo Truong Date: Thu, 13 Jul 2023 10:25:44 -0600 Subject: [PATCH 4/5] Corrected License Header Signed-off-by: Theo Truong --- CHANGELOG.md | 2 +- lib/opensearch/api.rb | 2 +- lib/opensearch/api/actions/remote_store/restore.rb | 3 --- lib/opensearch/api/namespace/remote_store.rb | 3 --- spec/opensearch/api/actions/remote_store/restore_spec.rb | 3 --- 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a73eaca..ac1b9a7b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added -- `remote_store.restore` action ([#176](https://github.com/opensearch-project/opensearch-ruby/pull/176)) +- Added `remote_store.restore` action ([#176](https://github.com/opensearch-project/opensearch-ruby/pull/176)) ### Changed - Merged `opensearch-transport`, `opensearch-api`, and `opensearch-dsl` into `opensearch-ruby` ([#133](https://github.com/opensearch-project/opensearch-ruby/issues/133)) ### Deprecated diff --git a/lib/opensearch/api.rb b/lib/opensearch/api.rb index 029b46934..6e0c597fa 100644 --- a/lib/opensearch/api.rb +++ b/lib/opensearch/api.rb @@ -6,7 +6,7 @@ # # 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 diff --git a/lib/opensearch/api/actions/remote_store/restore.rb b/lib/opensearch/api/actions/remote_store/restore.rb index 5827580df..6513d2397 100644 --- a/lib/opensearch/api/actions/remote_store/restore.rb +++ b/lib/opensearch/api/actions/remote_store/restore.rb @@ -3,9 +3,6 @@ # 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. # This code was generated from OpenSearch API Spec. # Update the code generation logic instead of modifying this file directly. diff --git a/lib/opensearch/api/namespace/remote_store.rb b/lib/opensearch/api/namespace/remote_store.rb index 313581318..255fef121 100644 --- a/lib/opensearch/api/namespace/remote_store.rb +++ b/lib/opensearch/api/namespace/remote_store.rb @@ -3,9 +3,6 @@ # 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. # This code was generated from OpenSearch API Spec. # Update the code generation logic instead of modifying this file directly. diff --git a/spec/opensearch/api/actions/remote_store/restore_spec.rb b/spec/opensearch/api/actions/remote_store/restore_spec.rb index 3e5c3b2e5..753b5789d 100644 --- a/spec/opensearch/api/actions/remote_store/restore_spec.rb +++ b/spec/opensearch/api/actions/remote_store/restore_spec.rb @@ -3,9 +3,6 @@ # 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. # This code was generated from OpenSearch API Spec. # Update the code generation logic instead of modifying this file directly. From fe1fa972834971a16357633282be631f2533a990 Mon Sep 17 00:00:00 2001 From: Theo Truong Date: Thu, 13 Jul 2023 10:32:15 -0600 Subject: [PATCH 5/5] Corrected License Header Signed-off-by: Theo Truong --- .github/license-header.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/license-header.txt b/.github/license-header.txt index 6c0097cd1..ff4fd04d1 100644 --- a/.github/license-header.txt +++ b/.github/license-header.txt @@ -3,6 +3,3 @@ # 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.