antbird 0.4.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af75afbbb6d09da0a80a3ef3c15c12eca61410975581dd6f26997fa3f70272d0
4
- data.tar.gz: 5327fae6beaaecb226dea3ab8b04b3a88de6b47d3be77d23651f5c3840d4f26f
3
+ metadata.gz: b0f0ed1c7dabf81835ef85e0a5a105b19c233ade75532df0462228277f447e11
4
+ data.tar.gz: c56cf7841b8309571e54e03cb13ce006d9a17e04222ed5afda7921aa89c468a1
5
5
  SHA512:
6
- metadata.gz: ac456d024f7ad570b8dc3243a65895c74706ae9453bcdea5e0a8a52c98dcd38e2b3ca0c9f34290ed9483613d8facf50971c3dbde5d816bc011c37c9854141e1a
7
- data.tar.gz: 3266fefa55330b1a4180d16dfd54ac40b0bc91208b2253933d3648ed7bb7a02eab4eef49c41d173675a1c36932ca5b5391e3cb086df6df7b26f0a9ec1ad04467
6
+ metadata.gz: fee97bce77ff300cd14b51fd4de70214a7521bd5f58e19b1473a97612951a25ba7632287c8889263708b1566b8a963b172f060a9782379445458f83a46072dc6
7
+ data.tar.gz: 57fb63974675572ff7222a0a9af53f4c2b00258a7f0c6ec69647a09f1a68aba8120f05448bc4caa35ddb5232b9a389e21ecc4e0298aeab787ca4b11c284ac51b
@@ -0,0 +1,41 @@
1
+ name: build-os
2
+
3
+ on: [push]
4
+ env:
5
+ ENGINE_NAME: opensearch
6
+ REST_API_SPEC_REPO: opensearch-project/OpenSearch
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ # https://github.com/opensearch-project/OpenSearch/releases
15
+ search_versions:
16
+ - 1.2.0
17
+ - 1.1.0
18
+ - 1.0.0
19
+ services:
20
+ opensearch:
21
+ image: opensearchproject/opensearch:${{matrix.search_versions}}
22
+ ports:
23
+ - 9200:9200
24
+ env:
25
+ discovery.type: single-node
26
+ plugins.security.disabled: true
27
+ steps:
28
+ - name: Configure sysctl limits
29
+ run: |
30
+ sudo swapoff -a
31
+ sudo sysctl -w vm.swappiness=1
32
+ sudo sysctl -w fs.file-max=262144
33
+ sudo sysctl -w vm.max_map_count=262144
34
+ - uses: actions/checkout@v2
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: 2.7
38
+ bundler-cache: true
39
+ - name: Wait for OpenSearch
40
+ run: timeout 60 bash -c "until curl --silent --output /dev/null localhost:9200/_cat/health?h=st; do printf '.'; sleep 5; done; printf '\n'"
41
+ - run: bundle exec rspec
@@ -1,6 +1,9 @@
1
1
  name: build
2
2
 
3
3
  on: [push]
4
+ env:
5
+ ENGINE_NAME: elasticsearch
6
+ REST_API_SPEC_REPO: elastic/elasticsearch
4
7
 
5
8
  jobs:
6
9
  build:
@@ -10,15 +13,15 @@ jobs:
10
13
  matrix:
11
14
  # 1. Run script/list_versions
12
15
  # 2. Check https://www.elastic.co/jp/support/eol
13
- elasticsearch:
14
- - 7.14.0
16
+ search_versions:
17
+ - 7.15.2
18
+ - 7.14.2
15
19
  - 7.13.4
16
20
  - 7.12.1
17
21
  - 7.11.2
18
22
  - 7.10.2
19
23
  - 7.9.3
20
24
  - 7.8.1
21
- - 7.7.1
22
25
  - 6.8.18
23
26
  steps:
24
27
  # @see https://github.com/elastic/elastic-github-actions/tree/master/elasticsearch
@@ -31,13 +34,12 @@ jobs:
31
34
  - name: Runs Elasticsearch
32
35
  uses: elastic/elastic-github-actions/elasticsearch@master
33
36
  with:
34
- stack-version: ${{matrix.elasticsearch}}
37
+ stack-version: ${{matrix.search_versions}}
35
38
  - uses: actions/checkout@v2
36
39
  - uses: ruby/setup-ruby@v1
37
40
  with:
38
41
  ruby-version: 2.7
39
42
  bundler-cache: true
40
- - run: bundle install --jobs 4 --retry 3
41
43
  - name: Wait for elasticsearch
42
44
  run: timeout 60 bash -c "until curl --silent --output /dev/null localhost:9200/_cat/health?h=st; do printf '.'; sleep 5; done; printf '\n'"
43
45
  - run: bundle exec rspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Antbird
2
2
 
3
- Nearly auto-generated Elasticsearch client
3
+ Nearly auto-generated Elasticsearch/OpenSearch client
4
4
 
5
5
  [![Build Status](https://github.com/fukayatsu/antbird/workflows/build/badge.svg)](https://github.com/fukayatsu/antbird/actions)
6
6
 
@@ -113,9 +113,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
113
113
 
114
114
  Bug reports and pull requests are welcome on GitHub at https://github.com/fukayatsu/antbird. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
115
115
 
116
- ### How to support newer version of Elasticsearch
116
+ ### How to support newer version of Elasticsearch/OpenSearch
117
117
 
118
- 1. Add Elasticsearch version to `jobs.build.strategy.matrix.elasticsearch` on `.github/workflows/build.yml`
118
+ 1. Add Elasticsearch version to `jobs.build.strategy.matrix.search_versions` on `.github/workflows/build.yml` / `.github/workflows/build-os.yml`
119
119
  - Only one line for `x.y.*` version
120
120
  1. `script/generate_api_methods`
121
121
  - Set `GITHUB_TOKEN=***` env for GitHub API Limit
@@ -8,6 +8,7 @@ module Antbird
8
8
  scope: {},
9
9
  url: "http://localhost:9200",
10
10
  version: nil,
11
+ distribution: nil,
11
12
  read_timeout: 5,
12
13
  open_timeout: 2,
13
14
  adapter: ::Faraday.default_adapter,
@@ -19,12 +20,16 @@ module Antbird
19
20
  @block = block
20
21
  @url = url
21
22
 
22
- @scope = scope.transform_keys(&:to_sym)
23
- @version = version
23
+ @scope = scope.transform_keys(&:to_sym)
24
+
25
+ if version
26
+ @version = version
27
+ @distribution = distribution
28
+ end
24
29
 
25
30
  @api_specs = {}
26
31
  end
27
- attr_reader :scope, :url, :version
32
+ attr_reader :scope, :url, :distribution
28
33
  attr_reader :read_timeout, :open_timeout, :adapter
29
34
  attr_reader :api_specs, :last_request
30
35
 
@@ -33,6 +38,7 @@ module Antbird
33
38
  scope: new_scope,
34
39
  url: url,
35
40
  version: version,
41
+ distribution: distribution,
36
42
  read_timeout: read_timeout,
37
43
  open_timeout: open_timeout
38
44
  )
@@ -190,6 +196,35 @@ module Antbird
190
196
  end
191
197
  end
192
198
 
199
+ def elasticsearch?
200
+ !opensearch?
201
+ end
202
+
203
+ def opensearch?
204
+ ensure_version_and_distribution
205
+
206
+ distribution == 'opensearch'
207
+ end
208
+
209
+ def elasticsearch_v7_0_compatible?
210
+ return true if opensearch?
211
+
212
+ elasticsearch? && Gem::Version.new(version) >= Gem::Version.new('7.0.0')
213
+ end
214
+
215
+ def elasticsearch_v7_6_compatible?
216
+ return true if opensearch?
217
+
218
+ elasticsearch? && Gem::Version.new(version) >= Gem::Version.new('7.6.0')
219
+ end
220
+
221
+ def version
222
+ return @version if @version
223
+
224
+ ensure_version_and_distribution
225
+ @version
226
+ end
227
+
193
228
  private
194
229
 
195
230
  # NOTE: stable sort
@@ -221,17 +256,35 @@ module Antbird
221
256
  end
222
257
  end
223
258
 
224
- def fetch_version
225
- connection.get('/').body.dig('version', 'number')
259
+ def ensure_version_and_distribution
260
+ return if @version
261
+
262
+ response = connection.get('/')
263
+ if response.status == 401
264
+ raise Antbird::Client::RequestError.new(response)
265
+ end
266
+
267
+ version_hash = response.body.dig('version')
268
+ @version = version_hash['number']
269
+ @distribution = version_hash['distribution']
270
+ end
271
+
272
+ def class_version
273
+ version.split('.')[0, 2].join('_')
226
274
  end
227
275
 
228
276
  def ensure_api_spec_loaded
229
277
  return if api_specs_loaded?
230
278
 
231
- @version ||= fetch_version
232
- class_version = @version.split('.')[0, 2].join('_')
233
- require "antbird/rest_api/rest_api_v#{class_version}"
234
- extend Antbird::RestApi.const_get "RestApiV#{class_version}"
279
+ ensure_version_and_distribution
280
+
281
+ if opensearch?
282
+ require "antbird/rest_api/rest_api_opensearch_v#{class_version}"
283
+ extend Antbird::RestApi.const_get "RestApiOpensearchV#{class_version}"
284
+ else
285
+ require "antbird/rest_api/rest_api_v#{class_version}"
286
+ extend Antbird::RestApi.const_get "RestApiV#{class_version}"
287
+ end
235
288
 
236
289
  @api_specs_loaded = true
237
290
  end