embulk-output-sftp 0.1.6 → 0.1.7

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: 64ff7608df9289a70721a9c4bf7685a66929e197
4
- data.tar.gz: 14fbf8a0b136c44e999f1aa15b333c19f32eca24
3
+ metadata.gz: bec4dd06576bca7c200d5abf77f0e195c28d998d
4
+ data.tar.gz: 8ded1287e06e19b4adb8696b4bf6550a4a1ee47e
5
5
  SHA512:
6
- metadata.gz: e58d44d3f650e31e3a5a88405299b66148e0ca8507330e4ebe093978f275504b48d6969d773394c251ed1653971d051077b5a38119f81b0540d5504514678141
7
- data.tar.gz: f2735c0c06d09cdaf6539c96133ffe06b001e3ec4d2a1f3e0f1f690b3898136bfd76f8aae09f0401a5cc4b9545b6112abc6ae2377739c3f55aff26b8688626af
6
+ metadata.gz: 87a454091a32f4f69c52eabd50a092638bf944edd763d857d2a357c7d11a1375d8bcd92204adeae5cda278549634b6ccfd8b8f7c4ccadd17a8aa89ca4c0c28c6
7
+ data.tar.gz: 06a421bcea79c0c438f108c20a49a400bac18a1ec914d11d1b4bc5dff182a09401cfeeb31471c70aa861a76baa5374ce2d21d0a8007b2f25aba7910f899391b9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.1.7 (2018-03-14)
2
+ - Enhance: Upload with ".tmp" suffix and rename file name after upload
3
+ - https://github.com/embulk/embulk-output-sftp/pull/43
4
+ - https://github.com/embulk/embulk-output-sftp/pull/44
5
+
1
6
  0.1.6 (2018-03-13)
2
7
  - Fix: Change input stream buffer size to 4MB to fix hanging issue
3
8
  - https://github.com/embulk/embulk-output-sftp/pull/46
data/build.gradle CHANGED
@@ -17,7 +17,7 @@ configurations {
17
17
  }
18
18
 
19
19
  group = "org.embulk.output.sftp"
20
- version = "0.1.6"
20
+ version = "0.1.7"
21
21
  sourceCompatibility = 1.7
22
22
  targetCompatibility = 1.7
23
23
 
@@ -30,6 +30,7 @@ public class SftpFileOutput
30
30
  private final String pathPrefix;
31
31
  private final String sequenceFormat;
32
32
  private final String fileNameExtension;
33
+ private final boolean renameFileAfterUpload;
33
34
 
34
35
  private final int taskIndex;
35
36
  private final SftpUtils sftpUtils;
@@ -45,6 +46,7 @@ public class SftpFileOutput
45
46
  this.pathPrefix = task.getPathPrefix();
46
47
  this.sequenceFormat = task.getSequenceFormat();
47
48
  this.fileNameExtension = task.getFileNameExtension();
49
+ this.renameFileAfterUpload = task.getRenameFileAfterUpload();
48
50
  this.taskIndex = taskIndex;
49
51
  this.sftpUtils = new SftpUtils(task);
50
52
  }
@@ -84,12 +86,12 @@ public class SftpFileOutput
84
86
  closeCurrentFile();
85
87
  String fileName = getOutputFilePath();
86
88
  String temporaryFileName = fileName + temporaryFileSuffix;
87
- /*
88
- #37 causes permission failure while renaming remote file.
89
- https://github.com/embulk/embulk-output-sftp/issues/40
90
- */
91
- //sftpUtils.uploadFile(tempFile, temporaryFileName);
92
- sftpUtils.uploadFile(tempFile, fileName);
89
+ if (renameFileAfterUpload) {
90
+ sftpUtils.uploadFile(tempFile, temporaryFileName);
91
+ }
92
+ else {
93
+ sftpUtils.uploadFile(tempFile, fileName);
94
+ }
93
95
 
94
96
  Map<String, String> executedFiles = new HashMap<>();
95
97
  executedFiles.put("temporary_filename", temporaryFileName);
@@ -14,6 +14,7 @@ import org.embulk.spi.TransactionalFileOutput;
14
14
  import org.embulk.spi.unit.LocalFile;
15
15
 
16
16
  import java.util.List;
17
+ import java.util.Map;
17
18
 
18
19
  public class SftpFileOutputPlugin
19
20
  implements FileOutputPlugin
@@ -69,6 +70,10 @@ public class SftpFileOutputPlugin
69
70
  @Config("proxy")
70
71
  @ConfigDefault("null")
71
72
  public Optional<ProxyTask> getProxy();
73
+
74
+ @Config("rename_file_after_upload")
75
+ @ConfigDefault("false")
76
+ public Boolean getRenameFileAfterUpload();
72
77
  }
73
78
 
74
79
  @Override
@@ -98,21 +103,28 @@ public class SftpFileOutputPlugin
98
103
  int taskCount,
99
104
  List<TaskReport> successTaskReports)
100
105
  {
101
- /*
102
- #37 causes permission failure while renaming remote file.
103
- https://github.com/embulk/embulk-output-sftp/issues/40
104
- */
105
- // SftpUtils sftpUtils = new SftpUtils(taskSource.loadTask(PluginTask.class));
106
- // for (TaskReport report : successTaskReports) {
107
- // List<Map<String, String>> moveFileList = report.get(List.class, "file_list");
108
- // for (Map<String, String> pairFiles : moveFileList) {
109
- // String temporaryFileName = pairFiles.get("temporary_filename");
110
- // String realFileName = pairFiles.get("real_filename");
111
- //
112
- // sftpUtils.renameFile(temporaryFileName, realFileName);
113
- // }
114
- // }
115
- // sftpUtils.close();
106
+ PluginTask task = taskSource.loadTask(PluginTask.class);
107
+
108
+ if (task.getRenameFileAfterUpload()) {
109
+ SftpUtils sftpUtils = null;
110
+ try {
111
+ sftpUtils = new SftpUtils(task);
112
+ for (TaskReport report : successTaskReports) {
113
+ List<Map<String, String>> moveFileList = report.get(List.class, "file_list");
114
+ for (Map<String, String> pairFiles : moveFileList) {
115
+ String temporaryFileName = pairFiles.get("temporary_filename");
116
+ String realFileName = pairFiles.get("real_filename");
117
+
118
+ sftpUtils.renameFile(temporaryFileName, realFileName);
119
+ }
120
+ }
121
+ }
122
+ finally {
123
+ if (sftpUtils != null) {
124
+ sftpUtils.close();
125
+ }
126
+ }
127
+ }
116
128
  }
117
129
 
118
130
  @Override
@@ -5,7 +5,7 @@ import com.google.common.base.Throwables;
5
5
  import org.apache.commons.vfs2.FileObject;
6
6
  import org.apache.commons.vfs2.FileSystemException;
7
7
  import org.apache.commons.vfs2.FileSystemOptions;
8
- import org.apache.commons.vfs2.impl.StandardFileSystemManager;
8
+ import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
9
9
  import org.apache.commons.vfs2.provider.sftp.IdentityInfo;
10
10
  import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
11
11
  import org.embulk.config.ConfigException;
@@ -32,22 +32,29 @@ import static org.embulk.spi.util.RetryExecutor.retryExecutor;
32
32
  public class SftpUtils
33
33
  {
34
34
  private final Logger logger = Exec.getLogger(SftpUtils.class);
35
- private final StandardFileSystemManager manager;
35
+ private final DefaultFileSystemManager manager;
36
36
  private final FileSystemOptions fsOptions;
37
37
  private final String userInfo;
38
38
  private final String host;
39
39
  private final int port;
40
40
  private final int maxConnectionRetry;
41
41
 
42
- private StandardFileSystemManager initializeStandardFileSystemManager()
42
+ private DefaultFileSystemManager initializeStandardFileSystemManager()
43
43
  {
44
44
  if (!logger.isDebugEnabled()) {
45
45
  // TODO: change logging format: org.apache.commons.logging.Log
46
46
  System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
47
47
  }
48
- StandardFileSystemManager manager = new StandardFileSystemManager();
49
- manager.setClassLoader(SftpUtils.class.getClassLoader());
48
+ /*
49
+ * We can use StandardFileSystemManager instead of DefaultFileSystemManager
50
+ * when Apache Commons VFS2 removes permission check logic when remote file renaming.
51
+ * https://github.com/embulk/embulk-output-sftp/issues/40
52
+ * https://github.com/embulk/embulk-output-sftp/pull/44
53
+ * https://issues.apache.org/jira/browse/VFS-590
54
+ */
55
+ DefaultFileSystemManager manager = new DefaultFileSystemManager();
50
56
  try {
57
+ manager.addProvider("sftp", new org.embulk.output.sftp.provider.sftp.SftpFileProvider());
51
58
  manager.init();
52
59
  }
53
60
  catch (FileSystemException e) {
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.embulk.output.sftp.provider.sftp;
18
+
19
+ import org.apache.commons.vfs2.FileSystemException;
20
+ import org.apache.commons.vfs2.provider.AbstractFileName;
21
+ import org.apache.commons.vfs2.provider.sftp.SftpFileSystem;
22
+
23
+ /*
24
+ * We can remove this file when Apache Commons VFS2 removes permission check logic when remote file renaming.
25
+ * https://github.com/embulk/embulk-output-sftp/issues/40
26
+ * https://github.com/embulk/embulk-output-sftp/pull/44
27
+ * https://issues.apache.org/jira/browse/VFS-590
28
+ */
29
+ /**
30
+ * An SFTP file.
31
+ */
32
+ public class SftpFileObject extends org.apache.commons.vfs2.provider.sftp.SftpFileObject
33
+ {
34
+ protected SftpFileObject(final AbstractFileName name, final SftpFileSystem fileSystem) throws FileSystemException
35
+ {
36
+ super(name, fileSystem);
37
+ }
38
+
39
+ @Override
40
+ protected boolean doIsWriteable() throws Exception
41
+ {
42
+ return true;
43
+ }
44
+ }
@@ -0,0 +1,81 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.embulk.output.sftp.provider.sftp;
18
+
19
+ import com.jcraft.jsch.Session;
20
+ import org.apache.commons.vfs2.FileName;
21
+ import org.apache.commons.vfs2.FileSystem;
22
+ import org.apache.commons.vfs2.FileSystemException;
23
+ import org.apache.commons.vfs2.FileSystemOptions;
24
+ import org.apache.commons.vfs2.UserAuthenticationData;
25
+ import org.apache.commons.vfs2.provider.GenericFileName;
26
+ import org.apache.commons.vfs2.provider.sftp.SftpClientFactory;
27
+ import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
28
+
29
+ /*
30
+ * We can remove this file when Apache Commons VFS2 removes permission check logic when remote file renaming.
31
+ * https://github.com/embulk/embulk-output-sftp/issues/40
32
+ * https://github.com/embulk/embulk-output-sftp/pull/44
33
+ * https://issues.apache.org/jira/browse/VFS-590
34
+ */
35
+ /**
36
+ * A provider for accessing files over SFTP.
37
+ */
38
+ public class SftpFileProvider extends org.apache.commons.vfs2.provider.sftp.SftpFileProvider
39
+ {
40
+ /**
41
+ * Constructs a new provider.
42
+ */
43
+ public SftpFileProvider()
44
+ {
45
+ super();
46
+ }
47
+
48
+ /**
49
+ * Creates a {@link FileSystem}.
50
+ */
51
+ @Override
52
+ protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
53
+ throws FileSystemException
54
+ {
55
+ // JSch jsch = createJSch(fileSystemOptions);
56
+
57
+ // Create the file system
58
+ final GenericFileName rootName = (GenericFileName) name;
59
+
60
+ Session session;
61
+ UserAuthenticationData authData = null;
62
+ try {
63
+ authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
64
+
65
+ session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
66
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
67
+ UserAuthenticatorUtils.toChar(rootName.getUserName())),
68
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
69
+ UserAuthenticatorUtils.toChar(rootName.getPassword())),
70
+ fileSystemOptions);
71
+ }
72
+ catch (final Exception e) {
73
+ throw new FileSystemException("vfs.provider.sftp/connect.error", name, e);
74
+ }
75
+ finally {
76
+ UserAuthenticatorUtils.cleanup(authData);
77
+ }
78
+
79
+ return new SftpFileSystem(rootName, session, fileSystemOptions);
80
+ }
81
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.embulk.output.sftp.provider.sftp;
18
+
19
+ import com.jcraft.jsch.Session;
20
+ import org.apache.commons.vfs2.FileObject;
21
+ import org.apache.commons.vfs2.FileSystemException;
22
+ import org.apache.commons.vfs2.FileSystemOptions;
23
+ import org.apache.commons.vfs2.provider.AbstractFileName;
24
+ import org.apache.commons.vfs2.provider.GenericFileName;
25
+
26
+ /*
27
+ * We can remove this file when Apache Commons VFS2 removes permission check logic when remote file renaming.
28
+ * https://github.com/embulk/embulk-output-sftp/issues/40
29
+ * https://github.com/embulk/embulk-output-sftp/pull/44
30
+ * https://issues.apache.org/jira/browse/VFS-590
31
+ */
32
+ /**
33
+ * Represents the files on an SFTP server.
34
+ */
35
+ public class SftpFileSystem extends org.apache.commons.vfs2.provider.sftp.SftpFileSystem
36
+ {
37
+ protected SftpFileSystem(final GenericFileName rootName, final Session session,
38
+ final FileSystemOptions fileSystemOptions)
39
+ {
40
+ super(rootName, null, fileSystemOptions);
41
+ }
42
+
43
+ /**
44
+ * Creates a file object. This method is called only if the requested file is not cached.
45
+ */
46
+ @Override
47
+ protected FileObject createFile(final AbstractFileName name) throws FileSystemException
48
+ {
49
+ return new SftpFileObject(name, this);
50
+ }
51
+ }
@@ -0,0 +1,19 @@
1
+ <!--
2
+ Licensed to the Apache Software Foundation (ASF) under one or more
3
+ contributor license agreements. See the NOTICE file distributed with
4
+ this work for additional information regarding copyright ownership.
5
+ The ASF licenses this file to You under the Apache License, Version 2.0
6
+ (the "License"); you may not use this file except in compliance with
7
+ the License. You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ -->
17
+ <body>
18
+ <p>The SFTP Provider.</p>
19
+ </body>
@@ -0,0 +1,29 @@
1
+ <!--
2
+ Licensed to the Apache Software Foundation (ASF) under one or more
3
+ contributor license agreements. See the NOTICE file distributed with
4
+ this work for additional information regarding copyright ownership.
5
+ The ASF licenses this file to You under the Apache License, Version 2.0
6
+ (the "License"); you may not use this file except in compliance with
7
+ the License. You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ -->
17
+ <!--
18
+ We can remove this file when Apache Commons VFS2 removes permission check logic when remote file renaming.
19
+ https://github.com/embulk/embulk-output-sftp/issues/40
20
+ https://github.com/embulk/embulk-output-sftp/pull/44
21
+ https://issues.apache.org/jira/browse/VFS-590
22
+ -->
23
+ <providers>
24
+ <provider class-name="org.embulk.output.sftp.provider.sftp.SftpFileProvider">
25
+ <scheme name="sftp"/>
26
+ <if-available class-name="javax.crypto.Cipher"/>
27
+ <if-available class-name="com.jcraft.jsch.JSch"/>
28
+ </provider>
29
+ </providers>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-sftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Civitaspo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-03-13 00:00:00.000000000 Z
12
+ date: 2018-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -67,13 +67,18 @@ files:
67
67
  - src/main/java/org/embulk/output/sftp/SftpFileOutput.java
68
68
  - src/main/java/org/embulk/output/sftp/SftpFileOutputPlugin.java
69
69
  - src/main/java/org/embulk/output/sftp/SftpUtils.java
70
+ - src/main/java/org/embulk/output/sftp/provider/sftp/SftpFileObject.java
71
+ - src/main/java/org/embulk/output/sftp/provider/sftp/SftpFileProvider.java
72
+ - src/main/java/org/embulk/output/sftp/provider/sftp/SftpFileSystem.java
73
+ - src/main/java/org/embulk/output/sftp/provider/sftp/package.html
74
+ - src/main/resources/providers.xml
70
75
  - src/test/java/org/embulk/output/sftp/TestSftpFileOutputPlugin.java
71
76
  - src/test/resources/id_rsa
72
77
  - src/test/resources/id_rsa.pub
73
78
  - classpath/commons-io-2.6.jar
74
79
  - classpath/commons-logging-1.2.jar
75
80
  - classpath/commons-vfs2-2.2.jar
76
- - classpath/embulk-output-sftp-0.1.6.jar
81
+ - classpath/embulk-output-sftp-0.1.7.jar
77
82
  - classpath/jsch-0.1.54.jar
78
83
  homepage: https://github.com/embulk/embulk-output-sftp
79
84
  licenses:
Binary file