Skip to content

Commit

Permalink
[CODE_GEN] Added remote_store.restore action
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <theotr@amazon.com>
  • Loading branch information
nhtruong committed Jul 10, 2023
1 parent cb179a8 commit f4b93d3
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 21 deletions.
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
44 changes: 23 additions & 21 deletions lib/opensearch/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
46 changes: 46 additions & 0 deletions lib/opensearch/api/actions/remote_store/restore.rb
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions lib/opensearch/api/namespace/remote_store.rb
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 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,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

0 comments on commit f4b93d3

Please sign in to comment.