Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CODE_GEN] Added remote_store.restore action #176

Merged
merged 5 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/license-header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ Layout/EmptyLineAfterGuardClause:

Naming/FileName:
Enabled: false

Layout/FirstArgumentIndentation:
Enabled: false

Layout/FirstArrayElementIndentation:
Enabled: false
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]
### Added
- 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
Expand Down
2 changes: 1 addition & 1 deletion guides/transport_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
42 changes: 22 additions & 20 deletions lib/opensearch/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions lib/opensearch/api/actions/remote_store/restore.rb
Original file line number Diff line number Diff line change
@@ -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.

# 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
30 changes: 30 additions & 0 deletions lib/opensearch/api/namespace/remote_store.rb
Original file line number Diff line number Diff line change
@@ -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.

# 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
43 changes: 43 additions & 0 deletions spec/opensearch/api/actions/remote_store/restore_spec.rb
Original file line number Diff line number Diff line change
@@ -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.

# 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