embulk-output-elasticsearch_using_url 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 685d2edcad17b21ddc3ed1513b21d0eb60a65fbd
4
- data.tar.gz: b2f159f1f335d2b702505a5ebec892fc3f3462fc
3
+ metadata.gz: e4a5986c1af27abb86d96bd9120cd2fee4b046e6
4
+ data.tar.gz: f39faffc87645aa2a74978979716893d8dca2330
5
5
  SHA512:
6
- metadata.gz: f951209582d56ebbc82cf13e92e9bd52b49abf17cafd7bdea36d64fdb7f58254e103d69665f40a2f6a8282faadc7084cf1a56cc81024578fda37d49f19c47237
7
- data.tar.gz: 0461770d6eedf3ab7f00204f7e31d06288768eb47a2453c20fb539695d2ff1c82fd387c476e27460ae56c5280bcabffa10453b7b43050cc47023f796de4c91aa
6
+ metadata.gz: f60977206fc590459fc7b6792d21b6cdbd1ff61d0e8eb217dacd13a1b132915da6b4f3c9e5ef8819de323698cc98f4b8311d5089dd6ac5968ec75ce1f4477d5e
7
+ data.tar.gz: 04a89192a107b50b66904dc4f97c74849c78df45c460422f4c5a75b9a8499d76c57b7488bab5d5d29f50aedbcf50495029e7477fe13056c2346e473ebbe40f8e
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /Gemfile.lock
2
+ /pkg/
data/README.md CHANGED
@@ -6,7 +6,7 @@ This plugin is forked from https://github.com/ipros-team/embulk-output-elasticse
6
6
  * **Plugin type**: output
7
7
  * **Load all or nothing**: no
8
8
  * **Resume supported**: no
9
- * **Cleanup supported**: no
9
+ * **Cleanup supported**: yes
10
10
 
11
11
  ## Configuration
12
12
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-output-elasticsearch_using_url"
4
- spec.version = "0.1.0"
4
+ spec.version = "0.1.1"
5
5
  spec.authors = ["Yuma Murata"]
6
6
  spec.summary = "Elasticsearch Using Url output plugin for Embulk"
7
7
  spec.description = "Dumps records to Elasticsearch Using Url."
Binary file
data/example/seed.yml ADDED
@@ -0,0 +1,10 @@
1
+ in:
2
+ type: file
3
+ path_prefix: "./csv/sample_"
4
+ out:
5
+ type: elasticsearch_using_url
6
+ mode: normal
7
+ nodes:
8
+ - url: "http://localhost:9200"
9
+ index: "sample"
10
+ index_type: "test"
@@ -1,9 +1,12 @@
1
+ require 'excon'
2
+ require 'elasticsearch'
3
+
1
4
  module Embulk
2
5
  module Output
3
6
 
4
- class ElasticsearchUsingUrl < OutputPlugin
7
+ class Elasticsearch < OutputPlugin
5
8
  Plugin.register_output("elasticsearch_using_url", self)
6
- ENABLE_MODE = %w[normal update]
9
+ ENABLE_MODE = %w[normal update replace]
7
10
 
8
11
  def self.transaction(config, schema, count, &control)
9
12
  task = {
@@ -37,15 +40,66 @@ module Embulk
37
40
  client.indices.put_template name: task['before_template_name'], body: task['before_template']
38
41
  end
39
42
 
40
- return self.resume(task, schema, count, &control)
41
- end
42
-
43
- def self.resume(task, schema, count, &control)
44
43
  task_reports = yield(task)
45
44
  next_config_diff = {}
46
45
  return next_config_diff
47
46
  end
48
47
 
48
+ def self.cleanup(task, schema, count, task_reports)
49
+ if task['mode'] == 'replace'
50
+ client = create_client(task)
51
+ create_aliases(client, task['index'], get_index(task))
52
+ delete_aliases(client, task)
53
+ end
54
+ end
55
+
56
+ def self.create_client(task)
57
+ return ::Elasticsearch::Client.new urls: task['nodes'].map{|v| v['url']}.join(','),
58
+ reload_connections: task['reload_connections'],
59
+ reload_on_failure: task['reload_on_failure'],
60
+ retry_on_failure: task['retry_on_failure'],
61
+ transport_options: {
62
+ request: { timeout: task['request_timeout'] }
63
+ }
64
+ end
65
+
66
+ def self.create_aliases(client, als, index)
67
+ client.indices.update_aliases body: {
68
+ actions: [{ add: { index: index, alias: als } }]
69
+ }
70
+ Embulk.logger.info "created alias: #{als}, index: #{index}"
71
+ end
72
+
73
+ def self.delete_aliases(client, task)
74
+ indices = client.indices.get_aliases.select { |key, value| value['aliases'].include? task['index'] }.keys
75
+ indices = indices.select { |index| /^#{get_index_prefix(task)}-(\d*)/ =~ index }
76
+ indices.each { |index|
77
+ if index != get_index(task)
78
+ client.indices.delete_alias index: index, name: task['index']
79
+ Embulk.logger.info "deleted alias: #{task['index']}, index: #{index}"
80
+ if task['delete_old_index']
81
+ client.indices.delete index: index
82
+ Embulk.logger.info "deleted index: #{index}"
83
+ end
84
+ end
85
+ }
86
+ end
87
+
88
+ def self.get_index(task)
89
+ task['mode'] == 'replace' ? "#{get_index_prefix(task)}-#{task['time_value']}" : task['index']
90
+ end
91
+
92
+ def self.get_index_prefix(task)
93
+ "#{task['index']}-#{task['index_type']}"
94
+ end
95
+
96
+ #def self.resume(task, schema, count, &control)
97
+ # task_reports = yield(task)
98
+ #
99
+ # next_config_diff = {}
100
+ # return next_config_diff
101
+ #end
102
+
49
103
  def init
50
104
  @nodes = task["nodes"]
51
105
  @index_type = task["index_type"]
@@ -55,9 +109,9 @@ module Embulk
55
109
  @array_columns = task["array_columns"]
56
110
  @retry_on_failure = task["retry_on_failure"]
57
111
  @mode = task["mode"]
58
- @index = task['index']
112
+ @index = self.class.get_index(task)
59
113
 
60
- @client = create_client(task)
114
+ @client = self.class.create_client(task)
61
115
  @bulk_message = []
62
116
  end
63
117
 
@@ -96,16 +150,6 @@ module Embulk
96
150
 
97
151
  private
98
152
 
99
- def create_client(task)
100
- return ::Elasticsearch::Client.new urls: task['nodes'].map{|v| v['url']}.join(','),
101
- reload_connections: task['reload_connections'],
102
- reload_on_failure: task['reload_on_failure'],
103
- retry_on_failure: task['retry_on_failure'],
104
- transport_options: {
105
- request: { timeout: task['request_timeout'] }
106
- }
107
- end
108
-
109
153
  def generate_array(record)
110
154
  result = {}
111
155
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-elasticsearch_using_url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuma Murata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch
@@ -87,11 +87,14 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".gitignore"
90
91
  - Gemfile
91
92
  - LICENSE.txt
92
93
  - README.md
93
94
  - Rakefile
94
95
  - embulk-output-elasticsearch_using_url.gemspec
96
+ - example/csv/sample_01.csv.gz
97
+ - example/seed.yml
95
98
  - lib/embulk/output/elasticsearch_using_url.rb
96
99
  homepage: https://github.com/ymurata/embulk-output-elasticsearch_using_url
97
100
  licenses: