embulk-output-elasticsearch 0.4.2 → 0.4.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
  SHA1:
3
- metadata.gz: 820af0df51a3e46cfd59a26c60e1fd219134b685
4
- data.tar.gz: c6fdea4eaa6fe4a26e85c2ee1b5c623224daa317
3
+ metadata.gz: 3be5c4aa4a859ab429375abbbb219665ea4036c0
4
+ data.tar.gz: 75f3d82aa911310d760f8669ab6c27ae6b8aa65d
5
5
  SHA512:
6
- metadata.gz: 81a1fe781d1e176fd8da2c3af19d3ddb1dd5a5dec519f887d072be420224d0168a0ea54f2621a7e50417740320b28f056b0504228bdc826c68e8173bc3bb13b7
7
- data.tar.gz: d18bc4da9ea81201e72e21d02ec859b5f2a1e2078fd8c1c3a90bd4a01d361746b2b75aedc3baf50098f0b93d2f1ae4993b31eba2cbdd2d8f99d61194220c6a41
6
+ metadata.gz: e606d402f49e8b7945e220e7a3fbdda72b4a86dc9a012155dc7bd2c94808ebd870b96af7fd551e8c9360e1ff4a707cb2b5f48f032ab69324347b1b431b3d007c
7
+ data.tar.gz: fb66e9cce399d2aa864330526524c2c4de8ed5ea48296fae0a89b7565e68cf653da3ecfc901e0317008e208714ac4321333d1962a9d4a79fd0c503814573f9a3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.4.3 - 2017-06-12
2
+
3
+ * [maintenance] Improve exception handling [#38](https://github.com/muga/embulk-output-elasticsearch/pull/38)
4
+ * [maintenance] Fix ElasticsearchRecordBuffer to call retryHelper.close() [#39](https://github.com/muga/embulk-output-elasticsearch/pull/39)
5
+
1
6
  ## 0.4.2 - 2017-05-31
2
7
 
3
8
  * [maintenance] Update embulk-base-restclient to fix ArrayIndexOutOfBoundsException [#37](https://github.com/muga/embulk-output-elasticsearch/pull/37)
data/build.gradle CHANGED
@@ -18,7 +18,7 @@ configurations {
18
18
  provided
19
19
  }
20
20
 
21
- version = "0.4.2"
21
+ version = "0.4.3"
22
22
 
23
23
  compileJava.options.encoding = 'UTF-8' // source encoding
24
24
  sourceCompatibility = 1.7
@@ -310,50 +310,51 @@ public class ElasticsearchHttpClient
310
310
  return sendRequest(path, method, task, retryHelper, "");
311
311
  }
312
312
 
313
- private JsonNode sendRequest(String path, final HttpMethod method, PluginTask task, Jetty92RetryHelper retryHelper, final String content)
313
+ private JsonNode sendRequest(String path, final HttpMethod method, final PluginTask task, Jetty92RetryHelper retryHelper, final String content)
314
314
  {
315
315
  final String uri = createRequestUri(task, path);
316
316
  final String authorizationHeader = getAuthorizationHeader(task);
317
317
 
318
- try {
319
- String responseBody = retryHelper.requestWithRetry(
320
- new StringJetty92ResponseEntityReader(task.getTimeoutMills()),
321
- new Jetty92SingleRequester() {
322
- @Override
323
- public void requestOnce(org.eclipse.jetty.client.HttpClient client, org.eclipse.jetty.client.api.Response.Listener responseListener)
324
- {
325
- org.eclipse.jetty.client.api.Request request = client
326
- .newRequest(uri)
327
- .accept("application/json")
328
- .method(method);
329
- if (method == HttpMethod.POST) {
330
- request.content(new StringContentProvider(content), "application/json");
331
- }
332
-
333
- if (!authorizationHeader.isEmpty()) {
334
- request.header("Authorization", authorizationHeader);
335
- }
336
- request.send(responseListener);
318
+ String responseBody = retryHelper.requestWithRetry(
319
+ new StringJetty92ResponseEntityReader(task.getTimeoutMills()),
320
+ new Jetty92SingleRequester() {
321
+ @Override
322
+ public void requestOnce(org.eclipse.jetty.client.HttpClient client, org.eclipse.jetty.client.api.Response.Listener responseListener)
323
+ {
324
+ org.eclipse.jetty.client.api.Request request = client
325
+ .newRequest(uri)
326
+ .accept("application/json")
327
+ .method(method);
328
+ if (method == HttpMethod.POST) {
329
+ request.content(new StringContentProvider(content), "application/json");
337
330
  }
338
331
 
339
- @Override
340
- public boolean isResponseStatusToRetry(org.eclipse.jetty.client.api.Response response)
341
- {
342
- int status = response.getStatus();
343
- if (status == 429) {
344
- return true; // Retry if 429.
345
- }
346
- return status / 100 != 4; // Retry unless 4xx except for 429.
332
+ if (!authorizationHeader.isEmpty()) {
333
+ request.header("Authorization", authorizationHeader);
347
334
  }
348
- });
349
- return parseJson(responseBody);
350
- }
351
- catch (HttpResponseException ex) {
352
- if (ex.getMessage().startsWith("Response not 2xx: 404 Not Found")) {
353
- throw new ResourceNotFoundException(ex);
354
- }
355
- throw ex;
356
- }
335
+ request.send(responseListener);
336
+ }
337
+
338
+ @Override
339
+ public boolean isExceptionToRetry(Exception exception)
340
+ {
341
+ return task.getId().isPresent();
342
+ }
343
+
344
+ @Override
345
+ public boolean isResponseStatusToRetry(org.eclipse.jetty.client.api.Response response)
346
+ {
347
+ int status = response.getStatus();
348
+ if (status == 404) {
349
+ throw new ResourceNotFoundException("Requested resource was not found");
350
+ }
351
+ else if (status == 429) {
352
+ return true; // Retry if 429.
353
+ }
354
+ return status / 100 != 4; // Retry unless 4xx except for 429.
355
+ }
356
+ });
357
+ return parseJson(responseBody);
357
358
  }
358
359
 
359
360
  private String createRequestUri(PluginTask task, String path)
@@ -403,6 +404,11 @@ public class ElasticsearchHttpClient
403
404
  {
404
405
  }
405
406
 
407
+ public ResourceNotFoundException(String message)
408
+ {
409
+ super(message);
410
+ }
411
+
406
412
  public ResourceNotFoundException(Throwable cause)
407
413
  {
408
414
  super(cause);
@@ -88,12 +88,15 @@ public class ElasticsearchRecordBuffer
88
88
  @Override
89
89
  public TaskReport commitWithTaskReportUpdated(TaskReport taskReport)
90
90
  {
91
- if (records.size() > 0) {
92
- client.push(records, task, retryHelper);
93
- log.info("Inserted {} records", records.size());
91
+ try {
92
+ if (records.size() > 0) {
93
+ client.push(records, task, retryHelper);
94
+ log.info("Inserted {} records", records.size());
95
+ }
96
+ return Exec.newTaskReport().set("inserted", totalCount);
97
+ }
98
+ finally {
99
+ this.retryHelper.close();
94
100
  }
95
-
96
- this.retryHelper.close();
97
- return Exec.newTaskReport().set("inserted", totalCount);
98
101
  }
99
102
  }
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muga Nishizawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
14
20
  requirement: !ruby/object:Gem::Requirement
15
21
  requirements:
16
22
  - - '>='
17
23
  - !ruby/object:Gem::Version
18
24
  version: '1.0'
19
- name: bundler
20
25
  prerelease: false
21
26
  type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
31
  - - '>='
25
32
  - !ruby/object:Gem::Version
26
- version: '1.0'
27
- - !ruby/object:Gem::Dependency
33
+ version: '10.0'
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
36
  - - '>='
31
37
  - !ruby/object:Gem::Version
32
38
  version: '10.0'
33
- name: rake
34
39
  prerelease: false
35
40
  type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - '>='
45
+ - - ~>
39
46
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
47
+ version: 3.0.2
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
50
  - - ~>
45
51
  - !ruby/object:Gem::Version
46
52
  version: 3.0.2
47
- name: test-unit
48
53
  prerelease: false
49
54
  type: :development
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 3.0.2
55
55
  description: Elasticsearch output plugin is an Embulk plugin that loads records to Elasticsearch read by any input plugins. Search the input plugins by "embulk-input" keyword.
56
56
  email:
57
57
  - muga.nishizawa@gmail.com
@@ -83,7 +83,7 @@ files:
83
83
  - src/test/java/org/embulk/output/elasticsearch/TestElasticsearchOutputPlugin.java
84
84
  - src/test/resources/sample_01.csv
85
85
  - classpath/embulk-base-restclient-0.5.2.jar
86
- - classpath/embulk-output-elasticsearch-0.4.2.jar
86
+ - classpath/embulk-output-elasticsearch-0.4.3.jar
87
87
  - classpath/embulk-util-retryhelper-jetty92-0.5.2.jar
88
88
  - classpath/jetty-client-9.2.14.v20151106.jar
89
89
  - classpath/jetty-http-9.2.14.v20151106.jar