embulk-output-s3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec5fe08d2ad38fad94f03679479e3653cfac20cb
4
+ data.tar.gz: 6d363a602b57f9b9315b68a16602ca6a0af294c6
5
+ SHA512:
6
+ metadata.gz: bd0d1aa10571f12e130040a5073a5b7fcc649576f81f5bb83f8f32e12aba031fa56061a8c78d1308cf52445921e50754ab4490ffae2cdfa0dd49a3990003247e
7
+ data.tar.gz: df38d944942edb611ff64ac85a243246a61c31ab03350baa811fd3f91fef77cc3f77b3024860f8ed9c73b4415b12c4aeb8ccf345e93f05db316cf8021de0e6f6
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ .gradle/
5
+ /classpath/
6
+ build/
7
+ .idea
8
+ .settings/
9
+ bin/
10
+ .classpath
11
+ .project
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # S3 file output plugin for Embulk
2
+
3
+ ## Overview
4
+
5
+ * **Plugin type**: file output
6
+ * **Load all or nothing**: no
7
+ * **Resume supported**: yes
8
+ * **Cleanup supported**: yes
9
+
10
+ ## Configuration
11
+
12
+ - **path_prefix**: prefix of target keys (string, required)
13
+ - **file_ext**: suffix of target keys (string, required)
14
+ - **sequence_format**: format for sequence part of target keys (string, default: '.%03d.%02d')
15
+ - **bucket**: S3 bucket name (string, required)
16
+ - **endpoint**: S3 endpoint login user name (string, optional)
17
+ - **access_key_id**: AWS access key id (string, required)
18
+ - **secret_access_key**: AWS secret key (string, required)
19
+ - **tmp_path_prefix**: prefix of temporary files (string, defualt: 'embulk-output-s3-')
20
+
21
+ ## Example
22
+
23
+ ```yaml
24
+ path_prefix: logs/out
25
+ file_ext: .csv
26
+ bucket: my-s3-bucket
27
+ endpoint: s3-us-west-1.amazonaws.com
28
+ access_key_id: ABCXYZ123ABCXYZ123
29
+ secret_access_key: AbCxYz123aBcXyZ123
30
+ formatter:
31
+ type: csv
32
+ ```
33
+
34
+
35
+ ## Build
36
+
37
+ ```
38
+ $ ./gradlew gem
39
+ ```
data/build.gradle ADDED
@@ -0,0 +1,56 @@
1
+ plugins {
2
+ id "com.jfrog.bintray" version "1.1"
3
+ id "com.github.jruby-gradle.base" version "0.1.5"
4
+ id "java"
5
+ }
6
+ import com.github.jrubygradle.JRubyExec
7
+ repositories {
8
+ mavenCentral()
9
+ jcenter()
10
+ }
11
+ configurations {
12
+ provided
13
+ }
14
+
15
+ version = "0.1.0"
16
+
17
+ dependencies {
18
+ compile "org.embulk:embulk-core:0.5.2"
19
+ provided "org.embulk:embulk-core:0.5.2"
20
+ compile "com.amazonaws:aws-java-sdk-s3:1.9.24"
21
+ testCompile "junit:junit:4.+"
22
+ }
23
+
24
+ task classpath(type: Copy, dependsOn: ["jar"]) {
25
+ doFirst { file("classpath").deleteDir() }
26
+ from (configurations.runtime - configurations.provided + files(jar.archivePath))
27
+ into "classpath"
28
+ }
29
+ clean { delete 'classpath' }
30
+
31
+ task gem(type: JRubyExec, dependsOn: ["build", "gemspec", "classpath"]) {
32
+ jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
33
+ script "build/gemspec"
34
+ doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
35
+ }
36
+
37
+ task gemspec << { file("build/gemspec").write($/
38
+ Gem::Specification.new do |spec|
39
+ spec.name = "${project.name}"
40
+ spec.version = "${project.version}"
41
+ spec.authors = ["Manabu Takayama"]
42
+ spec.summary = %[S3 file output plugin for Embulk]
43
+ spec.description = %["Stores files on S3."]
44
+ spec.email = ["learn.libra@gmail.com"]
45
+ spec.licenses = ["MIT"]
46
+ spec.homepage = "https://github.com/llibra/embulk-output-s3"
47
+
48
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
49
+ spec.test_files = spec.files.grep(%r"^(test|spec)/")
50
+ spec.require_paths = ["lib"]
51
+
52
+ spec.add_development_dependency 'bundler', ['~> 1.0']
53
+ spec.add_development_dependency 'rake', ['>= 10.0']
54
+ end
55
+ /$)
56
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,6 @@
1
+ #Wed Feb 04 13:46:12 PST 2015
2
+ distributionBase=GRADLE_USER_HOME
3
+ distributionPath=wrapper/dists
4
+ zipStoreBase=GRADLE_USER_HOME
5
+ zipStorePath=wrapper/dists
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
data/gradlew ADDED
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
4
+ ##
5
+ ## Gradle start up script for UN*X
6
+ ##
7
+ ##############################################################################
8
+
9
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10
+ DEFAULT_JVM_OPTS=""
11
+
12
+ APP_NAME="Gradle"
13
+ APP_BASE_NAME=`basename "$0"`
14
+
15
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
16
+ MAX_FD="maximum"
17
+
18
+ warn ( ) {
19
+ echo "$*"
20
+ }
21
+
22
+ die ( ) {
23
+ echo
24
+ echo "$*"
25
+ echo
26
+ exit 1
27
+ }
28
+
29
+ # OS specific support (must be 'true' or 'false').
30
+ cygwin=false
31
+ msys=false
32
+ darwin=false
33
+ case "`uname`" in
34
+ CYGWIN* )
35
+ cygwin=true
36
+ ;;
37
+ Darwin* )
38
+ darwin=true
39
+ ;;
40
+ MINGW* )
41
+ msys=true
42
+ ;;
43
+ esac
44
+
45
+ # For Cygwin, ensure paths are in UNIX format before anything is touched.
46
+ if $cygwin ; then
47
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48
+ fi
49
+
50
+ # Attempt to set APP_HOME
51
+ # Resolve links: $0 may be a link
52
+ PRG="$0"
53
+ # Need this for relative symlinks.
54
+ while [ -h "$PRG" ] ; do
55
+ ls=`ls -ld "$PRG"`
56
+ link=`expr "$ls" : '.*-> \(.*\)$'`
57
+ if expr "$link" : '/.*' > /dev/null; then
58
+ PRG="$link"
59
+ else
60
+ PRG=`dirname "$PRG"`"/$link"
61
+ fi
62
+ done
63
+ SAVED="`pwd`"
64
+ cd "`dirname \"$PRG\"`/" >&-
65
+ APP_HOME="`pwd -P`"
66
+ cd "$SAVED" >&-
67
+
68
+ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69
+
70
+ # Determine the Java command to use to start the JVM.
71
+ if [ -n "$JAVA_HOME" ] ; then
72
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73
+ # IBM's JDK on AIX uses strange locations for the executables
74
+ JAVACMD="$JAVA_HOME/jre/sh/java"
75
+ else
76
+ JAVACMD="$JAVA_HOME/bin/java"
77
+ fi
78
+ if [ ! -x "$JAVACMD" ] ; then
79
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80
+
81
+ Please set the JAVA_HOME variable in your environment to match the
82
+ location of your Java installation."
83
+ fi
84
+ else
85
+ JAVACMD="java"
86
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87
+
88
+ Please set the JAVA_HOME variable in your environment to match the
89
+ location of your Java installation."
90
+ fi
91
+
92
+ # Increase the maximum file descriptors if we can.
93
+ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94
+ MAX_FD_LIMIT=`ulimit -H -n`
95
+ if [ $? -eq 0 ] ; then
96
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97
+ MAX_FD="$MAX_FD_LIMIT"
98
+ fi
99
+ ulimit -n $MAX_FD
100
+ if [ $? -ne 0 ] ; then
101
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
102
+ fi
103
+ else
104
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105
+ fi
106
+ fi
107
+
108
+ # For Darwin, add options to specify how the application appears in the dock
109
+ if $darwin; then
110
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111
+ fi
112
+
113
+ # For Cygwin, switch paths to Windows format before running java
114
+ if $cygwin ; then
115
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117
+
118
+ # We build the pattern for arguments to be converted via cygpath
119
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120
+ SEP=""
121
+ for dir in $ROOTDIRSRAW ; do
122
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
123
+ SEP="|"
124
+ done
125
+ OURCYGPATTERN="(^($ROOTDIRS))"
126
+ # Add a user-defined pattern to the cygpath arguments
127
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129
+ fi
130
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
131
+ i=0
132
+ for arg in "$@" ; do
133
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135
+
136
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138
+ else
139
+ eval `echo args$i`="\"$arg\""
140
+ fi
141
+ i=$((i+1))
142
+ done
143
+ case $i in
144
+ (0) set -- ;;
145
+ (1) set -- "$args0" ;;
146
+ (2) set -- "$args0" "$args1" ;;
147
+ (3) set -- "$args0" "$args1" "$args2" ;;
148
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154
+ esac
155
+ fi
156
+
157
+ # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158
+ function splitJvmOpts() {
159
+ JVM_OPTS=("$@")
160
+ }
161
+ eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162
+ JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163
+
164
+ exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
data/gradlew.bat ADDED
@@ -0,0 +1,90 @@
1
+ @if "%DEBUG%" == "" @echo off
2
+ @rem ##########################################################################
3
+ @rem
4
+ @rem Gradle startup script for Windows
5
+ @rem
6
+ @rem ##########################################################################
7
+
8
+ @rem Set local scope for the variables with windows NT shell
9
+ if "%OS%"=="Windows_NT" setlocal
10
+
11
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12
+ set DEFAULT_JVM_OPTS=
13
+
14
+ set DIRNAME=%~dp0
15
+ if "%DIRNAME%" == "" set DIRNAME=.
16
+ set APP_BASE_NAME=%~n0
17
+ set APP_HOME=%DIRNAME%
18
+
19
+ @rem Find java.exe
20
+ if defined JAVA_HOME goto findJavaFromJavaHome
21
+
22
+ set JAVA_EXE=java.exe
23
+ %JAVA_EXE% -version >NUL 2>&1
24
+ if "%ERRORLEVEL%" == "0" goto init
25
+
26
+ echo.
27
+ echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
+ echo.
29
+ echo Please set the JAVA_HOME variable in your environment to match the
30
+ echo location of your Java installation.
31
+
32
+ goto fail
33
+
34
+ :findJavaFromJavaHome
35
+ set JAVA_HOME=%JAVA_HOME:"=%
36
+ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
+
38
+ if exist "%JAVA_EXE%" goto init
39
+
40
+ echo.
41
+ echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
+ echo.
43
+ echo Please set the JAVA_HOME variable in your environment to match the
44
+ echo location of your Java installation.
45
+
46
+ goto fail
47
+
48
+ :init
49
+ @rem Get command-line arguments, handling Windowz variants
50
+
51
+ if not "%OS%" == "Windows_NT" goto win9xME_args
52
+ if "%@eval[2+2]" == "4" goto 4NT_args
53
+
54
+ :win9xME_args
55
+ @rem Slurp the command line arguments.
56
+ set CMD_LINE_ARGS=
57
+ set _SKIP=2
58
+
59
+ :win9xME_args_slurp
60
+ if "x%~1" == "x" goto execute
61
+
62
+ set CMD_LINE_ARGS=%*
63
+ goto execute
64
+
65
+ :4NT_args
66
+ @rem Get arguments from the 4NT Shell from JP Software
67
+ set CMD_LINE_ARGS=%$
68
+
69
+ :execute
70
+ @rem Setup the command line
71
+
72
+ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73
+
74
+ @rem Execute Gradle
75
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76
+
77
+ :end
78
+ @rem End local scope for the variables with windows NT shell
79
+ if "%ERRORLEVEL%"=="0" goto mainEnd
80
+
81
+ :fail
82
+ rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83
+ rem the _cmd.exe /c_ return code!
84
+ if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85
+ exit /b 1
86
+
87
+ :mainEnd
88
+ if "%OS%"=="Windows_NT" endlocal
89
+
90
+ :omega
@@ -0,0 +1,3 @@
1
+ Embulk::JavaPlugin.register_output(
2
+ "s3", "org.embulk.output.S3FileOutputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,258 @@
1
+ package org.embulk.output;
2
+
3
+ import java.io.IOException;
4
+ import java.io.OutputStream;
5
+ import java.nio.file.Files;
6
+ import java.nio.file.Path;
7
+ import java.util.IllegalFormatException;
8
+ import java.util.List;
9
+ import java.util.Locale;
10
+
11
+ import org.embulk.config.CommitReport;
12
+ import org.embulk.config.Config;
13
+ import org.embulk.config.ConfigDefault;
14
+ import org.embulk.config.ConfigDiff;
15
+ import org.embulk.config.ConfigException;
16
+ import org.embulk.config.ConfigSource;
17
+ import org.embulk.config.Task;
18
+ import org.embulk.config.TaskSource;
19
+ import org.embulk.spi.Buffer;
20
+ import org.embulk.spi.Exec;
21
+ import org.embulk.spi.FileOutput;
22
+ import org.embulk.spi.FileOutputPlugin;
23
+ import org.embulk.spi.TransactionalFileOutput;
24
+ import org.slf4j.Logger;
25
+
26
+ import com.amazonaws.ClientConfiguration;
27
+ import com.amazonaws.auth.AWSCredentials;
28
+ import com.amazonaws.auth.AWSCredentialsProvider;
29
+ import com.amazonaws.auth.BasicAWSCredentials;
30
+ import com.amazonaws.services.s3.AmazonS3Client;
31
+ import com.amazonaws.services.s3.model.PutObjectRequest;
32
+
33
+ public class S3FileOutputPlugin implements FileOutputPlugin {
34
+ public interface PluginTask extends Task {
35
+ @Config("path_prefix")
36
+ public String getPathPrefix();
37
+
38
+ @Config("file_ext")
39
+ public String getFileNameExtension();
40
+
41
+ @Config("sequence_format")
42
+ @ConfigDefault("\".%03d.%02d\"")
43
+ public String getSequenceFormat();
44
+
45
+ @Config("bucket")
46
+ public String getBucket();
47
+
48
+ @Config("endpoint")
49
+ public String getEndpoint();
50
+
51
+ @Config("access_key_id")
52
+ public String getAccessKeyId();
53
+
54
+ @Config("secret_access_key")
55
+ public String getSecretAccessKey();
56
+
57
+ @Config("tmp_path_prefix")
58
+ @ConfigDefault("\"embulk-output-s3-\"")
59
+ public String getTempPathPrefix();
60
+ }
61
+
62
+ public static class S3FileOutput implements FileOutput,
63
+ TransactionalFileOutput {
64
+ private final Logger log = Exec.getLogger(S3FileOutputPlugin.class);
65
+
66
+ private final String bucket;
67
+ private final String pathPrefix;
68
+ private final String sequenceFormat;
69
+ private final String fileNameExtension;
70
+ private final String tempPathPrefix;
71
+
72
+ private int taskIndex;
73
+ private int fileIndex;
74
+ private AmazonS3Client client;
75
+ private OutputStream current;
76
+ private Path tempFilePath;
77
+
78
+ public static AWSCredentialsProvider getCredentialsProvider(
79
+ PluginTask task) {
80
+ final AWSCredentials cred = new BasicAWSCredentials(
81
+ task.getAccessKeyId(), task.getSecretAccessKey());
82
+ return new AWSCredentialsProvider() {
83
+ @Override
84
+ public AWSCredentials getCredentials() {
85
+ return cred;
86
+ }
87
+
88
+ @Override
89
+ public void refresh() {
90
+ }
91
+ };
92
+ }
93
+
94
+ private static AmazonS3Client newS3Client(PluginTask task) {
95
+ AWSCredentialsProvider credentials = getCredentialsProvider(task);
96
+
97
+ ClientConfiguration config = new ClientConfiguration();
98
+ // TODO: Support more configurations.
99
+
100
+ AmazonS3Client client = new AmazonS3Client(credentials, config);
101
+ client.setEndpoint(task.getEndpoint());
102
+
103
+ return client;
104
+ }
105
+
106
+ public S3FileOutput(PluginTask task, int taskIndex) {
107
+ this.taskIndex = taskIndex;
108
+ this.client = newS3Client(task);
109
+ this.bucket = task.getBucket();
110
+ this.pathPrefix = task.getPathPrefix();
111
+ this.sequenceFormat = task.getSequenceFormat();
112
+ this.fileNameExtension = task.getFileNameExtension();
113
+ this.tempPathPrefix = task.getTempPathPrefix();
114
+ }
115
+
116
+ private static Path newTempFile(String prefix) throws IOException {
117
+ return Files.createTempFile(prefix, null);
118
+ }
119
+
120
+ private void deleteTempFile() {
121
+ if (tempFilePath == null) {
122
+ return;
123
+ }
124
+
125
+ try {
126
+ Files.delete(tempFilePath);
127
+ tempFilePath = null;
128
+ } catch (IOException e) {
129
+ throw new RuntimeException(e);
130
+ }
131
+ }
132
+
133
+ private String buildCurrentKey() {
134
+ String sequence = String.format(sequenceFormat, taskIndex,
135
+ fileIndex);
136
+ return pathPrefix + sequence + fileNameExtension;
137
+ }
138
+
139
+ private void putFile(Path from, String key) {
140
+ PutObjectRequest request = new PutObjectRequest(bucket, key,
141
+ from.toFile());
142
+ client.putObject(request);
143
+ }
144
+
145
+ private void closeCurrent() {
146
+ if (current == null) {
147
+ return;
148
+ }
149
+
150
+ try {
151
+ putFile(tempFilePath, buildCurrentKey());
152
+ fileIndex++;
153
+ } finally {
154
+ try {
155
+ current.close();
156
+ current = null;
157
+ } catch (IOException e) {
158
+ throw new RuntimeException(e);
159
+ } finally {
160
+ deleteTempFile();
161
+ }
162
+ }
163
+ }
164
+
165
+ @Override
166
+ public void nextFile() {
167
+ closeCurrent();
168
+
169
+ try {
170
+ tempFilePath = newTempFile(tempPathPrefix);
171
+
172
+ log.info("Writing S3 file '{}'", buildCurrentKey());
173
+
174
+ current = Files.newOutputStream(tempFilePath);
175
+ } catch (IOException e) {
176
+ throw new RuntimeException(e);
177
+ }
178
+ }
179
+
180
+ @Override
181
+ public void add(Buffer buffer) {
182
+ if (current == null) {
183
+ throw new IllegalStateException(
184
+ "nextFile() must be called before poll()");
185
+ }
186
+
187
+ try {
188
+ current.write(buffer.array(), buffer.offset(), buffer.limit());
189
+ } catch (IOException ex) {
190
+ throw new RuntimeException(ex);
191
+ } finally {
192
+ buffer.release();
193
+ }
194
+ }
195
+
196
+ @Override
197
+ public void finish() {
198
+ closeCurrent();
199
+ }
200
+
201
+ @Override
202
+ public void close() {
203
+ closeCurrent();
204
+ }
205
+
206
+ @Override
207
+ public void abort() {
208
+ deleteTempFile();
209
+ }
210
+
211
+ @Override
212
+ public CommitReport commit() {
213
+ CommitReport report = Exec.newCommitReport();
214
+ return report;
215
+ }
216
+ }
217
+
218
+ private void validateSequenceFormat(PluginTask task) {
219
+ try {
220
+ @SuppressWarnings("unused")
221
+ String dontCare = String.format(Locale.ENGLISH,
222
+ task.getSequenceFormat(), 0, 0);
223
+ } catch (IllegalFormatException ex) {
224
+ throw new ConfigException(
225
+ "Invalid sequence_format: parameter for file output plugin",
226
+ ex);
227
+ }
228
+ }
229
+
230
+ @Override
231
+ public ConfigDiff transaction(ConfigSource config, int taskCount,
232
+ Control control) {
233
+ PluginTask task = config.loadConfig(PluginTask.class);
234
+
235
+ validateSequenceFormat(task);
236
+
237
+ return resume(task.dump(), taskCount, control);
238
+ }
239
+
240
+ @Override
241
+ public ConfigDiff resume(TaskSource taskSource, int taskCount,
242
+ Control control) {
243
+ control.run(taskSource);
244
+ return Exec.newConfigDiff();
245
+ }
246
+
247
+ @Override
248
+ public void cleanup(TaskSource taskSource, int taskCount,
249
+ List<CommitReport> successCommitReports) {
250
+ }
251
+
252
+ @Override
253
+ public TransactionalFileOutput open(TaskSource taskSource, int taskIndex) {
254
+ PluginTask task = taskSource.loadTask(PluginTask.class);
255
+
256
+ return new S3FileOutput(task, taskIndex);
257
+ }
258
+ }
@@ -0,0 +1,5 @@
1
+ package org.embulk.output;
2
+
3
+ public class TestS3FileOutputPlugin
4
+ {
5
+ }
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-output-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Takayama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
+ dependencies:
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'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.0'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '10.0'
39
+ prerelease: false
40
+ type: :development
41
+ description: '"Stores files on S3."'
42
+ email:
43
+ - learn.libra@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - LICENSE.txt
50
+ - README.md
51
+ - build.gradle
52
+ - gradle/wrapper/gradle-wrapper.jar
53
+ - gradle/wrapper/gradle-wrapper.properties
54
+ - gradlew
55
+ - gradlew.bat
56
+ - lib/embulk/output/s3.rb
57
+ - src/main/java/org/embulk/output/S3FileOutputPlugin.java
58
+ - src/test/java/org/embulk/output/TestS3FileOutputPlugin.java
59
+ - classpath/aws-java-sdk-core-1.9.24.jar
60
+ - classpath/aws-java-sdk-kms-1.9.24.jar
61
+ - classpath/aws-java-sdk-s3-1.9.24.jar
62
+ - classpath/commons-codec-1.6.jar
63
+ - classpath/commons-logging-1.1.3.jar
64
+ - classpath/embulk-output-s3-0.1.0.jar
65
+ - classpath/httpclient-4.3.4.jar
66
+ - classpath/httpcore-4.3.2.jar
67
+ homepage: https://github.com/llibra/embulk-output-s3
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.1.9
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: S3 file output plugin for Embulk
91
+ test_files: []