Skip to content

Commit da8210a

Browse files
committed
[API] Generate code from downloaded artifacts instead of checked out code
1 parent 69d7231 commit da8210a

File tree

7 files changed

+41
-51
lines changed

7 files changed

+41
-51
lines changed

elasticsearch-api/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ the library modules have been already included**, so you just call the API metho
5555
```ruby
5656
require 'elasticsearch'
5757

58-
client = Elasticsearch::Client.new log: true
58+
client = Elasticsearch::Client.new(log: true)
5959

60-
client.index index: 'myindex', type: 'mytype', id: 1, body: { title: 'Test' }
60+
client.index(index: 'myindex', type: 'mytype', id: 1, body: { title: 'Test' })
6161
# => {"_index"=>"myindex", ... "created"=>true}
6262

63-
client.search index: 'myindex', body: { query: { match: { title: 'test' } } }
63+
client.search(index: 'myindex', body: { query: { match: { title: 'test' } } })
6464
# => {"took"=>2, ..., "hits"=>{"total":5, ...}}
6565
```
6666

@@ -200,7 +200,7 @@ time rake test:integration
200200

201201
We run the test suite for Elasticsearch's Rest API tests. You can read more about this in [the test runner README](https://github.com/elastic/elasticsearch-ruby/tree/master/api-spec-testing#rest-api-yaml-test-runner).
202202

203-
The `rest_api` needs the test files from Elasticsearch. You can run the rake task to download the test artifacts in the root folder of the project. This task needs a running cluster to determine which version and build hash of Elasticsearch to use and test against. `TEST_ES_SERVER=http://localhost:9200 rake test:download_artifacts`. This will download the necessary files used for the integration tests to `./tmp`.
203+
The `rest_api` needs the test files from Elasticsearch. You can run the rake task to download the test artifacts in the root folder of the project. This task needs a running cluster to determine which version and build hash of Elasticsearch to use and test against. `TEST_ES_SERVER=http://localhost:9200 rake elasticsearch:download_artifacts`. This will download the necessary files used for the integration tests to `./tmp`.
204204

205205
## License
206206

elasticsearch-api/spec/elasticsearch/api/rest_api_yaml_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
if REST_API_YAML_FILES.empty?
2323
logger = Logger.new($stdout)
2424
logger.error 'No test files found!'
25-
logger.info 'Use rake rake test:download_artifacts in the root directory of the project to download the test artifacts.'
25+
logger.info 'Use rake rake elasticsearch:download_artifacts in the root directory of the project to download the test artifacts.'
2626
exit 1
2727
end
2828

elasticsearch-api/utils/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ This directory hosts The Generator, a tool that generates the classes for each A
66

77
### Generate
88

9-
To generate the code, you need to run (from this folder):
9+
To generate the code, you need to have the Elasticsearch REST API spec files in `tmp/rest-api-spec` in the root of the project. You can run a rake task from the root of the project to download the specs corresponding to the current running cluster:
10+
```bash
11+
$ rake elasticsearch:download_artifacts
12+
```
13+
14+
Once the JSON files have been downloaded, you need to run (from this folder):
1015
```bash
1116
$ thor api:code:generate
1217
```

elasticsearch-api/utils/thor/generator/files_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Elasticsearch
2222
module API
2323
module FilesHelper
2424
PROJECT_PATH = File.join(File.dirname(__FILE__), '..')
25-
SRC_PATH = File.join(PROJECT_PATH, '..', '..', '..', 'tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/api/')
25+
SRC_PATH = File.join(PROJECT_PATH, '..', '..', '..', 'tmp/rest-api-spec/api/')
2626
OSS_OUTPUT_DIR = '../../elasticsearch-api/lib/elasticsearch/api/actions'.freeze
2727
XPACK_OUTPUT_DIR = '../../elasticsearch-xpack/lib/elasticsearch/xpack/api/actions'.freeze
2828

elasticsearch-xpack/spec/xpack/rest_api_yaml_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
if REST_API_YAML_FILES.empty?
2323
logger = Logger.new($stdout)
2424
logger.error 'No test files found!'
25-
logger.info 'Use rake rake test:download_artifacts in the root directory of the project to download the test artifacts.'
25+
logger.info 'Use rake rake elasticsearch:download_artifacts in the root directory of the project to download the test artifacts.'
2626
exit 1
2727
end
2828

rake_tasks/elasticsearch_tasks.rake

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,34 @@ namespace :elasticsearch do
5050
end
5151
end
5252

53-
desc 'Update the submodule with Elasticsearch core repository'
54-
task update: :setup do
55-
sh "git --git-dir=#{CURRENT_PATH.join('tmp/elasticsearch/.git')} --work-tree=#{CURRENT_PATH.join('tmp/elasticsearch')} fetch origin --quiet"
56-
begin
57-
%x[git --git-dir=#{CURRENT_PATH.join('tmp/elasticsearch/.git')} --work-tree=#{CURRENT_PATH.join('tmp/elasticsearch')} pull]
58-
rescue Exception => @e
59-
@failed = true
60-
end
61-
62-
STDERR.puts '', "[!] Error while pulling -- #{@e}" if @failed || !$?.success?
63-
64-
puts "\n", "CHANGES:", '-' * 80
65-
sh "git --git-dir=#{CURRENT_PATH.join('tmp/elasticsearch/.git')} --work-tree=#{CURRENT_PATH.join('tmp/elasticsearch')} log --oneline ORIG_HEAD..HEAD | cat", :verbose => false
53+
desc 'Download artifacts (tests and REST spec) for currently running cluster'
54+
task :download_artifacts do
55+
json_filename = CURRENT_PATH.join('tmp/artifacts.json')
56+
57+
# Get version number and build hash of running cluster:
58+
es_info = cluster_info
59+
version_number = cluster_info['number']
60+
build_hash = cluster_info['build_hash']
61+
62+
puts "Build hash: #{build_hash}"
63+
# Create ./tmp if it doesn't exist
64+
Dir.mkdir(CURRENT_PATH.join('tmp'), 0700) unless File.directory?(CURRENT_PATH.join('tmp'))
65+
66+
# Download json file with package information for version:
67+
json_url = "https://artifacts-api.elastic.co/v1/versions/#{version_number}"
68+
download_file!(json_url, json_filename)
69+
70+
# Get the package url from the json file given the build hash
71+
zip_url = package_url(json_filename, build_hash)
72+
73+
# Download the zip file
74+
filename = CURRENT_PATH.join("tmp/#{zip_url.split('/').last}")
75+
download_file!(zip_url, filename)
76+
77+
puts "Unzipping file #{filename}"
78+
`unzip -o #{filename} -d tmp/`
79+
`rm #{filename}`
80+
puts 'Artifacts downloaded in ./tmp'
6681
end
6782

6883
desc <<-DESC

rake_tasks/test_tasks.rake

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,6 @@ namespace :test do
8585
end
8686
end
8787

88-
desc 'Download test artifacts for running cluster'
89-
task :download_artifacts do
90-
json_filename = CURRENT_PATH.join('tmp/artifacts.json')
91-
92-
# Get version number and build hash of running cluster:
93-
es_info = cluster_info
94-
version_number = cluster_info['number']
95-
build_hash = cluster_info['build_hash']
96-
97-
puts "Build hash: #{build_hash}"
98-
# Create ./tmp if it doesn't exist
99-
Dir.mkdir(CURRENT_PATH.join('tmp'), 0700) unless File.directory?(CURRENT_PATH.join('tmp'))
100-
101-
# Download json file with package information for version:
102-
json_url = "https://artifacts-api.elastic.co/v1/versions/#{version_number}"
103-
download_file!(json_url, json_filename)
104-
105-
# Get the package url from the json file given the build hash
106-
zip_url = package_url(json_filename, build_hash)
107-
108-
# Download the zip file
109-
filename = CURRENT_PATH.join("tmp/#{zip_url.split('/').last}")
110-
download_file!(zip_url, filename)
111-
112-
puts "Unzipping file #{filename}"
113-
`unzip -o #{filename} -d tmp/`
114-
`rm #{filename}`
115-
puts 'Artifacts downloaded in ./tmp'
116-
end
117-
11888
# Returns: version_number, build_hash
11989
def cluster_info
12090
require 'elasticsearch'

0 commit comments

Comments
 (0)