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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +13 -1
- data/Vagrantfile +20 -0
- data/build.gradle +1 -1
- data/classpath/embulk-output-sftp-0.0.6.jar +0 -0
- data/example/{sample.yml → sample.yml.liquid} +7 -6
- data/src/main/java/org/embulk/output/sftp/SftpFileOutput.java +83 -24
- metadata +5 -4
- data/classpath/embulk-output-sftp-0.0.5.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5c4bbee5ba87ccfee03e1423e182ea29279fd33
|
4
|
+
data.tar.gz: 04c0f1a8048c4240ed7156195e8a3e307db4fd92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e550bcf13c15c094de8d157fccaec8e0fc33eb04b963ced46e7ad68a6140816cf0b64389607e8929efabdd8c5ff8fe2b41f6d84be1946a5c6d776a889f09c5e1
|
7
|
+
data.tar.gz: 85d0eefa677889b005c6d50f719b185e7d0a32269518b541326135ad18b5d35c044a72daa6929c0953f96472820cb938ff99e053a2e02f4f869fc2fe3d03739f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
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
Binary file
|
@@ -16,11 +16,11 @@ in:
|
|
16
16
|
out:
|
17
17
|
type: sftp
|
18
18
|
host: 127.0.0.1
|
19
|
-
port:
|
20
|
-
user:
|
21
|
-
password:
|
22
|
-
secret_key_file:
|
23
|
-
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
|
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
|
-
|
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.
|
212
|
-
Throwables.propagate(e);
|
222
|
+
logger.info(e.getMessage());
|
213
223
|
}
|
214
|
-
|
215
|
-
|
216
|
-
currentFile
|
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
|
-
|
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
|
-
|
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
|
254
|
-
if (++count
|
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.
|
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-
|
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.
|
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
|