embulk-output-sftp 0.0.5 → 0.0.6

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: 865291280d7c6936d0e4f12655a00b854f880153
4
- data.tar.gz: dfe086b9210d16e7da2e21d5f77e42c38bd7f23b
3
+ metadata.gz: f5c4bbee5ba87ccfee03e1423e182ea29279fd33
4
+ data.tar.gz: 04c0f1a8048c4240ed7156195e8a3e307db4fd92
5
5
  SHA512:
6
- metadata.gz: b226b3a68c6e81ddf17ff22577ffd80cae2b58201b18a38bae681b0729e531769426e3f760694d36121e1885a6dfc21383a91c4fe5664203aafb58ad8c00c0fd
7
- data.tar.gz: 6bdda04f1ba31689656896323098be6e43e34c88cec3ea7922c6e0c55c6d8bc3b593f89ea863fcefb8a537da2ae38e6a2ebf159008e44e5d475cc025014fe80d
6
+ metadata.gz: e550bcf13c15c094de8d157fccaec8e0fc33eb04b963ced46e7ad68a6140816cf0b64389607e8929efabdd8c5ff8fe2b41f6d84be1946a5c6d776a889f09c5e1
7
+ data.tar.gz: 85d0eefa677889b005c6d50f719b185e7d0a32269518b541326135ad18b5d35c044a72daa6929c0953f96472820cb938ff99e053a2e02f4f869fc2fe3d03739f
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ build/
8
8
  .idea
9
9
  *.iml
10
10
  example/config.yml
11
+ .vagrant
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.0.6 (2016-03-16)
2
+ ==================
3
+ - Fix: Avoid some connection errors
4
+ - https://github.com/civitaspo/embulk-output-sftp/pull/17
5
+
1
6
  0.0.5 (2016-03-09)
2
7
  ==================
3
8
  - Add: Support MapReduce executor
data/README.md CHANGED
@@ -103,10 +103,21 @@ out:
103
103
  ```
104
104
 
105
105
  ## Run Example
106
- replace settings in `example/sample.yml` before running.
107
106
 
108
107
  ```
109
108
  $ ./gradlew classpath
109
+ ```
110
+
111
+ Use `vagrant` to start a remote sshd server:
112
+
113
+ ```
114
+ $ vagrant up
115
+ ```
116
+
117
+ Run:
118
+
119
+
120
+ ```
110
121
  $ embulk run -Ilib example/sample.yml
111
122
  ```
112
123
 
@@ -123,3 +134,4 @@ This plugin uses "org.apache.commons:commons-vfs" and the library uses the logge
123
134
  ## Contributors
124
135
  - Satoshi Akama (@sakama)
125
136
  - Rudolph Miller (@Rudolph-Miller)
137
+ - Naotoshi Seo (@sonots)
data/Vagrantfile ADDED
@@ -0,0 +1,20 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ # All Vagrant configuration is done here. The most common configuration
9
+ # options are documented and commented below. For a complete reference,
10
+ # please see the online documentation at vagrantup.com.
11
+
12
+ # Every Vagrant virtual environment requires a box to build off of.
13
+ config.vm.box = "centos6.5.3"
14
+ config.vm.box_url = 'https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box'
15
+
16
+ # name
17
+ config.vm.define "vagrant-centos"
18
+ config.ssh.forward_agent = true
19
+ config.vm.network "forwarded_port", guest: 22, host: 2210
20
+ end
data/build.gradle CHANGED
@@ -15,7 +15,7 @@ configurations {
15
15
  provided
16
16
  }
17
17
 
18
- version = "0.0.5"
18
+ version = "0.0.6"
19
19
  sourceCompatibility = 1.7
20
20
  targetCompatibility = 1.7
21
21
 
@@ -16,11 +16,11 @@ in:
16
16
  out:
17
17
  type: sftp
18
18
  host: 127.0.0.1
19
- port: 22
20
- user: your_name
21
- password: your_password
22
- secret_key_file: your_secret_key_file
23
- secret_key_passphrase: your_secret_key_passphrase
19
+ port: 2210
20
+ user: vagrant
21
+ # password:
22
+ secret_key_file: {{ env.PWD }}/.vagrant/machines/vagrant-centos/virtualbox/private_key
23
+ # secret_key_passphrase:
24
24
  user_directory_is_root: true
25
25
  path_prefix: /tmp/embulk_output_sftp/data
26
26
  file_ext: .tsv
@@ -36,4 +36,5 @@ out:
36
36
  quote: "\""
37
37
  escape: "\\"
38
38
  null_string: ""
39
- default_timezone: 'UTC'
39
+ default_timezone: 'UTC'
40
+
@@ -17,6 +17,7 @@ import org.embulk.spi.TransactionalFileOutput;
17
17
  import org.embulk.spi.unit.LocalFile;
18
18
  import org.slf4j.Logger;
19
19
 
20
+ import java.lang.Void;
20
21
  import java.io.File;
21
22
  import java.io.IOException;
22
23
  import java.io.OutputStream;
@@ -144,7 +145,7 @@ public class SftpFileOutput
144
145
 
145
146
  try {
146
147
  currentFile = newSftpFile(getSftpFileUri(getOutputFilePath()));
147
- currentFileOutputStream = currentFile.getContent().getOutputStream();
148
+ currentFileOutputStream = newSftpOutputStream(currentFile);
148
149
  logger.info("new sftp file: {}", currentFile.getPublicURIString());
149
150
  }
150
151
  catch (FileSystemException e) {
@@ -154,14 +155,26 @@ public class SftpFileOutput
154
155
  }
155
156
 
156
157
  @Override
157
- public void add(Buffer buffer)
158
+ public void add(final Buffer buffer)
158
159
  {
159
160
  if (currentFile == null) {
160
161
  throw new IllegalStateException("nextFile() must be called before poll()");
161
162
  }
162
163
 
163
164
  try {
164
- currentFileOutputStream.write(buffer.array(), buffer.offset(), buffer.limit());
165
+ Retriable<Void> retriable = new Retriable<Void>() {
166
+ public Void execute() throws IOException
167
+ {
168
+ currentFileOutputStream.write(buffer.array(), buffer.offset(), buffer.limit());
169
+ return null;
170
+ }
171
+ };
172
+ try {
173
+ withConnectionRetry(retriable);
174
+ }
175
+ catch (Exception e) {
176
+ throw (IOException)e;
177
+ }
165
178
  }
166
179
  catch (IOException e) {
167
180
  logger.error(e.getMessage());
@@ -204,18 +217,21 @@ public class SftpFileOutput
204
217
 
205
218
  try {
206
219
  currentFileOutputStream.close();
207
- currentFile.getContent().close();
208
- currentFile.close();
209
220
  }
210
221
  catch (IOException e) {
211
- logger.error(e.getMessage());
212
- Throwables.propagate(e);
222
+ logger.info(e.getMessage());
213
223
  }
214
- finally {
215
- fileIndex++;
216
- currentFile = null;
217
- currentFileOutputStream = null;
224
+
225
+ try {
226
+ currentFile.close();
218
227
  }
228
+ catch (FileSystemException e) {
229
+ logger.warn(e.getMessage());
230
+ }
231
+
232
+ fileIndex++;
233
+ currentFile = null;
234
+ currentFileOutputStream = null;
219
235
  }
220
236
 
221
237
  private URI getSftpFileUri(String remoteFilePath)
@@ -234,24 +250,25 @@ public class SftpFileOutput
234
250
  return pathPrefix + String.format(sequenceFormat, taskIndex, fileIndex) + fileNameExtension;
235
251
  }
236
252
 
237
- private FileObject newSftpFile(URI sftpUri)
238
- throws FileSystemException
253
+ interface Retriable<T>
239
254
  {
255
+ /**
256
+ * Execute the operation with the given (or null) return value.
257
+ *
258
+ * @return any return value from the operation
259
+ * @throws Exception
260
+ */
261
+ public T execute() throws Exception;
262
+ }
263
+
264
+ private <T> T withConnectionRetry( final Retriable<T> op ) throws Exception {
240
265
  int count = 0;
241
266
  while (true) {
242
267
  try {
243
- FileObject file = manager.resolveFile(sftpUri.toString(), fsOptions);
244
- if (file.getParent().exists()) {
245
- logger.info("parent directory {} exists there", file.getParent());
246
- return file;
247
- }
248
- else {
249
- logger.info("trying to create parent directory {}", file.getParent());
250
- file.getParent().createFolder();
251
- }
268
+ return op.execute();
252
269
  }
253
- catch (FileSystemException e) {
254
- if (++count == maxConnectionRetry) {
270
+ catch(final Exception e) {
271
+ if (++count > maxConnectionRetry) {
255
272
  throw e;
256
273
  }
257
274
  logger.warn("failed to connect sftp server: " + e.getMessage(), e);
@@ -270,6 +287,48 @@ public class SftpFileOutput
270
287
  }
271
288
  }
272
289
 
290
+ private FileObject newSftpFile(final URI sftpUri)
291
+ throws FileSystemException
292
+ {
293
+ Retriable<FileObject> retriable = new Retriable<FileObject>() {
294
+ public FileObject execute() throws FileSystemException
295
+ {
296
+ FileObject file = manager.resolveFile(sftpUri.toString(), fsOptions);
297
+ if (file.getParent().exists()) {
298
+ logger.info("parent directory {} exists there", file.getParent());
299
+ }
300
+ else {
301
+ logger.info("trying to create parent directory {}", file.getParent());
302
+ file.getParent().createFolder();
303
+ }
304
+ return file;
305
+ }
306
+ };
307
+ try {
308
+ return withConnectionRetry(retriable);
309
+ }
310
+ catch (Exception e) {
311
+ throw (FileSystemException)e;
312
+ }
313
+ }
314
+
315
+ private OutputStream newSftpOutputStream(final FileObject file)
316
+ throws FileSystemException
317
+ {
318
+ Retriable<OutputStream> retriable = new Retriable<OutputStream>() {
319
+ public OutputStream execute() throws FileSystemException
320
+ {
321
+ return file.getContent().getOutputStream();
322
+ }
323
+ };
324
+ try {
325
+ return withConnectionRetry(retriable);
326
+ }
327
+ catch (Exception e) {
328
+ throw (FileSystemException)e;
329
+ }
330
+ }
331
+
273
332
  private Function<LocalFile, String> localFileToPathString()
274
333
  {
275
334
  return new Function<LocalFile, String>()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-sftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Civitaspo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,11 +50,12 @@ files:
50
50
  - CHANGELOG.md
51
51
  - LICENSE.txt
52
52
  - README.md
53
+ - Vagrantfile
53
54
  - build.gradle
54
55
  - config/checkstyle/checkstyle.xml
55
56
  - config/checkstyle/default.xml
56
57
  - example/data.csv
57
- - example/sample.yml
58
+ - example/sample.yml.liquid
58
59
  - gradle/wrapper/gradle-wrapper.jar
59
60
  - gradle/wrapper/gradle-wrapper.properties
60
61
  - gradlew
@@ -68,7 +69,7 @@ files:
68
69
  - src/test/resources/id_rsa.pub
69
70
  - classpath/commons-logging-1.2.jar
70
71
  - classpath/commons-vfs2-2.1.1660580.2.jar
71
- - classpath/embulk-output-sftp-0.0.5.jar
72
+ - classpath/embulk-output-sftp-0.0.6.jar
72
73
  - classpath/jsch-0.1.53.jar
73
74
  homepage: https://github.com/civitaspo/embulk-output-sftp
74
75
  licenses:
Binary file