embulk-output-s3-compatible 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 235c63b362c35235189308d7842bf04f965eda5a
4
+ data.tar.gz: e5ccdb8c5678e09aafec0cc48db7f5daa3cbf09f
5
+ SHA512:
6
+ metadata.gz: '062594a3e4866a799f5931522f7599a881865e6a9674187db08deac19b1f470529cb8122b47f44787974750728c70a3639372b40322a81b50d73bbec85b3ab3a'
7
+ data.tar.gz: 07f300758b75774b482a1ff45640337011a1992ea4ec1847761f8e18b58cb6f5d69cfa9d1e29fbf9065b2e43b034c2d997fc66a763e9e684207264b9dd783a01
@@ -0,0 +1,13 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ .gradle/
5
+ /classpath/
6
+ build/
7
+ .idea
8
+ .settings/
9
+ bin/
10
+ .classpath
11
+ .project
12
+ *.gemspec
13
+ *.iml
@@ -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.
@@ -0,0 +1,70 @@
1
+ # S3-Compatible file output plugin for Embulk
2
+
3
+ This plugin is developed based on [https://github.com/llibra/embulk-output-s3](https://github.com/llibra/embulk-output-s3)
4
+
5
+ ## Developers
6
+
7
+ * Manabu Takayama <learn.libra@gmail.com>
8
+ * toyama hiroshi <toyama0919@gmail.com>
9
+ * Civitaspo <civitaspo@gmail.com>
10
+ * Floyd LAM <code@floydev.com>
11
+
12
+ ## Overview
13
+
14
+ * **Plugin type**: file output
15
+ * **Load all or nothing**: no
16
+ * **Resume supported**: yes
17
+ * **Cleanup supported**: yes
18
+
19
+ ## Configuration
20
+
21
+ - **path_prefix**: prefix of target keys (string, required)
22
+ - **file_ext**: suffix of target keys (string, required)
23
+ - **sequence_format**: format for sequence part of target keys (string, default: '.%03d.%02d')
24
+ - **bucket**: S3 bucket name (string, required)
25
+ - **region**: S3 region (string, default: 'us-east-1')
26
+ - **endpoint**: S3 endpoint login user name (string, optional)
27
+ - **access_key_id**: AWS access key id. This parameter is required when your agent is not running on EC2 instance with an IAM Role. (string, defualt: null)
28
+ - **secret_access_key**: AWS secret key. This parameter is required when your agent is not running on EC2 instance with an IAM Role. (string, defualt: null)
29
+ - **tmp_path**: temporary file directory. If null, it is associated with the default FileSystem. (string, default: null)
30
+ - **tmp_path_prefix**: prefix of temporary files (string, default: 'embulk-output-s3-')
31
+ - **canned_acl**: canned access control list for created objects ([enum](#cannedaccesscontrollist), default: null)
32
+ - **proxy_host**: proxy host to use when accessing AWS S3 via proxy. (string, default: null )
33
+ - **proxy_port**: proxy port to use when accessing AWS S3 via proxy. (string, default: null )
34
+ - **path_style_access**: whether to enable path style access, enable it if you are on minio. (boolean, default: false )
35
+ - **signer**: AWS S3 signer type to override. (string, default: null )
36
+
37
+ ### CannedAccessControlList
38
+ you can choose one of the below list.
39
+
40
+ - AuthenticatedRead
41
+ - AwsExecRead
42
+ - BucketOwnerFullControl
43
+ - BucketOwnerRead
44
+ - LogDeliveryWrite
45
+ - Private
46
+ - PublicRead
47
+ - PublicReadWrite
48
+
49
+ cf. http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/CannedAccessControlList.html
50
+
51
+ ## Example
52
+
53
+ ```yaml
54
+ path_prefix: logs/out
55
+ file_ext: .csv
56
+ bucket: my-s3-bucket
57
+ region: us-east-1
58
+ endpoint: s3-us-west-1.amazonaws.com
59
+ access_key_id: ABCXYZ123ABCXYZ123
60
+ secret_access_key: AbCxYz123aBcXyZ123
61
+ formatter:
62
+ type: csv
63
+ ```
64
+
65
+
66
+ ## Build
67
+
68
+ ```
69
+ $ ./gradlew gem
70
+ ```
@@ -0,0 +1,76 @@
1
+ plugins {
2
+ id "com.jfrog.bintray" version "1.6"
3
+ id "com.github.jruby-gradle.base" version "1.5.0"
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.0.1"
16
+ sourceCompatibility = 1.8
17
+ targetCompatibility = 1.8
18
+
19
+ dependencies {
20
+ compile "org.embulk:embulk-core:0.9.12"
21
+ provided "org.embulk:embulk-core:0.9.12"
22
+ compile "com.amazonaws:aws-java-sdk-s3:1.11.486"
23
+ compile "net.lingala.zip4j:zip4j:1.3.2"
24
+ }
25
+
26
+ task classpath(type: Copy, dependsOn: ["jar"]) {
27
+ doFirst { file("classpath").deleteDir() }
28
+ from (configurations.runtime - configurations.provided + files(jar.archivePath))
29
+ into "classpath"
30
+ }
31
+ clean { delete "classpath" }
32
+
33
+ task gem(type: JRubyExec, dependsOn: ["gemspec", "classpath"]) {
34
+ jrubyArgs "-S"
35
+ script "gem"
36
+ scriptArgs "build", "${project.name}.gemspec"
37
+ doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
38
+ }
39
+
40
+ task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
41
+ jrubyArgs "-S"
42
+ script "gem"
43
+ scriptArgs "push", "pkg/${project.name}-${project.version}.gem"
44
+ }
45
+
46
+ task "package"(dependsOn: ["gemspec", "classpath"]) << {
47
+ println "> Build succeeded."
48
+ println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
49
+ }
50
+
51
+ task gemspec {
52
+ ext.gemspecFile = file("${project.name}.gemspec")
53
+ inputs.file "build.gradle"
54
+ outputs.file gemspecFile
55
+ doLast { gemspecFile.write($/
56
+ Gem::Specification.new do |spec|
57
+ spec.name = "${project.name}"
58
+ spec.version = "${project.version}"
59
+ spec.authors = ["Floyd"]
60
+ spec.summary = %[S3-Compatible file output plugin for Embulk]
61
+ spec.description = %[S3-Compatible file output plugin is an Embulk plugin that output the files to the specified S3-Compatible storage.]
62
+ spec.email = ["code@floydev.com"]
63
+ spec.licenses = ["MIT"]
64
+ spec.homepage = ""
65
+
66
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
67
+ spec.test_files = spec.files.grep(%r"^(test|spec)/")
68
+ spec.require_paths = ["lib"]
69
+
70
+ spec.add_development_dependency 'bundler', ['~> 1.0']
71
+ spec.add_development_dependency 'rake', ['~> 10.0']
72
+ end
73
+ /$)
74
+ }
75
+ }
76
+ clean { delete "${project.name}.gemspec" }
@@ -0,0 +1,6 @@
1
+ #Mon Jan 21 17:18:05 JST 2019
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.10-all.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 "$@"
@@ -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-compatible", "org.embulk.output.S3CompatibleFileOutputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1 @@
1
+ rootProject.name = 'embulk-output-s3-compatible'
@@ -0,0 +1,309 @@
1
+ package org.embulk.output;
2
+
3
+ import com.amazonaws.ClientConfiguration;
4
+ import com.amazonaws.auth.AWSStaticCredentialsProvider;
5
+ import com.amazonaws.auth.BasicAWSCredentials;
6
+ import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
7
+ import com.amazonaws.services.s3.AmazonS3;
8
+ import com.amazonaws.services.s3.AmazonS3ClientBuilder;
9
+ import com.amazonaws.services.s3.model.CannedAccessControlList;
10
+ import com.amazonaws.services.s3.model.PutObjectRequest;
11
+ import com.google.common.base.Optional;
12
+ import org.embulk.config.*;
13
+ import org.embulk.spi.*;
14
+ import org.slf4j.Logger;
15
+
16
+ import java.io.IOException;
17
+ import java.io.OutputStream;
18
+ import java.nio.file.Files;
19
+ import java.nio.file.Path;
20
+ import java.nio.file.Paths;
21
+ import java.util.IllegalFormatException;
22
+ import java.util.List;
23
+ import java.util.Locale;
24
+
25
+ public class S3CompatibleFileOutputPlugin implements FileOutputPlugin {
26
+ public interface PluginTask extends Task {
27
+ @Config("path_prefix")
28
+ String getPathPrefix();
29
+
30
+ @Config("file_ext")
31
+ String getFileNameExtension();
32
+
33
+ @Config("sequence_format")
34
+ @ConfigDefault("\".%03d.%02d\"")
35
+ String getSequenceFormat();
36
+
37
+ @Config("bucket")
38
+ String getBucket();
39
+
40
+ @Config("region")
41
+ @ConfigDefault("\"us-east-1\"")
42
+ String getRegion();
43
+
44
+ @Config("endpoint")
45
+ @ConfigDefault("null")
46
+ Optional<String> getEndpoint();
47
+
48
+ @Config("access_key_id")
49
+ @ConfigDefault("null")
50
+ Optional<String> getAccessKeyId();
51
+
52
+ @Config("secret_access_key")
53
+ @ConfigDefault("null")
54
+ Optional<String> getSecretAccessKey();
55
+
56
+ @Config("proxy_host")
57
+ @ConfigDefault("null")
58
+ Optional<String> getProxyHost();
59
+
60
+ @Config("proxy_port")
61
+ @ConfigDefault("null")
62
+ Optional<Integer> getProxyPort();
63
+
64
+ @Config("tmp_path")
65
+ @ConfigDefault("null")
66
+ Optional<String> getTempPath();
67
+
68
+ @Config("tmp_path_prefix")
69
+ @ConfigDefault("\"embulk-output-s3-\"")
70
+ String getTempPathPrefix();
71
+
72
+ @Config("canned_acl")
73
+ @ConfigDefault("null")
74
+ Optional<CannedAccessControlList> getCannedAccessControlList();
75
+
76
+ @Config("path_style_access")
77
+ @ConfigDefault("false")
78
+ Optional<Boolean> getPathStyleAccess();
79
+
80
+ @Config("signer")
81
+ @ConfigDefault("null")
82
+ Optional<String> getSigner();
83
+ }
84
+
85
+ public static class S3FileOutput
86
+ implements FileOutput,
87
+ TransactionalFileOutput {
88
+ private final Logger log = Exec.getLogger(S3CompatibleFileOutputPlugin.class);
89
+
90
+ private final String bucket;
91
+ private final String pathPrefix;
92
+ private final String sequenceFormat;
93
+ private final String fileNameExtension;
94
+ private final String tempPathPrefix;
95
+ private final Optional<CannedAccessControlList> cannedAccessControlListOptional;
96
+
97
+ private int taskIndex;
98
+ private int fileIndex;
99
+ private AmazonS3 client;
100
+ private OutputStream current;
101
+ private Path tempFilePath;
102
+ private String tempPath = null;
103
+
104
+ private static AmazonS3 newS3Client(PluginTask task) {
105
+ AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();
106
+
107
+ // TODO: Support more configurations.
108
+ ClientConfiguration config = new ClientConfiguration();
109
+
110
+ if (task.getProxyHost().isPresent()) {
111
+ config.setProxyHost(task.getProxyHost().get());
112
+ }
113
+
114
+ if (task.getProxyPort().isPresent()) {
115
+ config.setProxyPort(task.getProxyPort().get());
116
+ }
117
+
118
+ if (task.getAccessKeyId().isPresent() && task.getSecretAccessKey().isPresent()) {
119
+ BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(
120
+ task.getAccessKeyId().get(), task.getSecretAccessKey().get());
121
+ clientBuilder = clientBuilder.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials));
122
+ }
123
+
124
+ if (task.getEndpoint().isPresent()) {
125
+ clientBuilder.setEndpointConfiguration(new EndpointConfiguration(task.getEndpoint().get(), task.getRegion()));
126
+ } else {
127
+ clientBuilder.setRegion(task.getRegion());
128
+ }
129
+
130
+ if (task.getPathStyleAccess().isPresent() && task.getPathStyleAccess().get()) {
131
+ clientBuilder = clientBuilder.withPathStyleAccessEnabled(true);
132
+ }
133
+
134
+ if (task.getSigner().isPresent()) {
135
+ config.setSignerOverride(task.getSigner().get());
136
+ }
137
+
138
+ AmazonS3 client = clientBuilder
139
+ .withClientConfiguration(config)
140
+ .build();
141
+
142
+ return client;
143
+ }
144
+
145
+ S3FileOutput(PluginTask task, int taskIndex) {
146
+ this.taskIndex = taskIndex;
147
+ this.client = newS3Client(task);
148
+ this.bucket = task.getBucket();
149
+ this.pathPrefix = task.getPathPrefix();
150
+ this.sequenceFormat = task.getSequenceFormat();
151
+ this.fileNameExtension = task.getFileNameExtension();
152
+ this.tempPathPrefix = task.getTempPathPrefix();
153
+ if (task.getTempPath().isPresent()) {
154
+ this.tempPath = task.getTempPath().get();
155
+ }
156
+ this.cannedAccessControlListOptional = task.getCannedAccessControlList();
157
+ }
158
+
159
+ private static Path newTempFile(String tmpDir, String prefix)
160
+ throws IOException {
161
+ if (tmpDir == null) {
162
+ return Files.createTempFile(prefix, null);
163
+ } else {
164
+ return Files.createTempFile(Paths.get(tmpDir), prefix, null);
165
+ }
166
+ }
167
+
168
+ private void deleteTempFile() {
169
+ if (tempFilePath == null) {
170
+ return;
171
+ }
172
+
173
+ try {
174
+ Files.delete(tempFilePath);
175
+ tempFilePath = null;
176
+ } catch (IOException e) {
177
+ throw new RuntimeException(e);
178
+ }
179
+ }
180
+
181
+ private String buildCurrentKey() {
182
+ String sequence = String.format(sequenceFormat, taskIndex,
183
+ fileIndex);
184
+ return pathPrefix + sequence + fileNameExtension;
185
+ }
186
+
187
+ private void putFile(Path from, String key) {
188
+ PutObjectRequest request = new PutObjectRequest(bucket, key, from.toFile());
189
+ if (cannedAccessControlListOptional.isPresent()) {
190
+ request.withCannedAcl(cannedAccessControlListOptional.get());
191
+ }
192
+ client.putObject(request);
193
+ }
194
+
195
+ private void closeCurrent() {
196
+ if (current == null) {
197
+ return;
198
+ }
199
+
200
+ try {
201
+ putFile(tempFilePath, buildCurrentKey());
202
+ fileIndex++;
203
+ } finally {
204
+ try {
205
+ current.close();
206
+ current = null;
207
+ } catch (IOException e) {
208
+ throw new RuntimeException(e);
209
+ } finally {
210
+ deleteTempFile();
211
+ }
212
+ }
213
+ }
214
+
215
+ @Override
216
+ public void nextFile() {
217
+ closeCurrent();
218
+
219
+ try {
220
+ tempFilePath = newTempFile(tempPath, tempPathPrefix);
221
+
222
+ log.info("Writing S3 file '{}'", buildCurrentKey());
223
+
224
+ current = Files.newOutputStream(tempFilePath);
225
+ } catch (IOException e) {
226
+ throw new RuntimeException(e);
227
+ }
228
+ }
229
+
230
+ @Override
231
+ public void add(Buffer buffer) {
232
+ if (current == null) {
233
+ throw new IllegalStateException(
234
+ "nextFile() must be called before poll()");
235
+ }
236
+
237
+ try {
238
+ current.write(buffer.array(), buffer.offset(), buffer.limit());
239
+ } catch (IOException ex) {
240
+ deleteTempFile();
241
+ throw new RuntimeException(ex);
242
+ } finally {
243
+ buffer.release();
244
+ }
245
+ }
246
+
247
+ @Override
248
+ public void finish() {
249
+ closeCurrent();
250
+ }
251
+
252
+ @Override
253
+ public void close() {
254
+ closeCurrent();
255
+ }
256
+
257
+ @Override
258
+ public void abort() {
259
+ deleteTempFile();
260
+ }
261
+
262
+ @Override
263
+ public TaskReport commit() {
264
+ TaskReport report = Exec.newTaskReport();
265
+ return report;
266
+ }
267
+ }
268
+
269
+ private void validateSequenceFormat(PluginTask task) {
270
+ try {
271
+ @SuppressWarnings("unused")
272
+ String dontCare = String.format(Locale.ENGLISH,
273
+ task.getSequenceFormat(), 0, 0);
274
+ } catch (IllegalFormatException ex) {
275
+ throw new ConfigException(
276
+ "Invalid sequence_format: parameter for file output plugin",
277
+ ex);
278
+ }
279
+ }
280
+
281
+ @Override
282
+ public ConfigDiff transaction(ConfigSource config, int taskCount,
283
+ Control control) {
284
+ PluginTask task = config.loadConfig(PluginTask.class);
285
+
286
+ validateSequenceFormat(task);
287
+
288
+ return resume(task.dump(), taskCount, control);
289
+ }
290
+
291
+ @Override
292
+ public ConfigDiff resume(TaskSource taskSource, int taskCount,
293
+ Control control) {
294
+ control.run(taskSource);
295
+ return Exec.newConfigDiff();
296
+ }
297
+
298
+ @Override
299
+ public void cleanup(TaskSource taskSource, int taskCount,
300
+ List<TaskReport> successTaskReports) {
301
+ }
302
+
303
+ @Override
304
+ public TransactionalFileOutput open(TaskSource taskSource, int taskIndex) {
305
+ PluginTask task = taskSource.loadTask(PluginTask.class);
306
+
307
+ return new S3FileOutput(task, taskIndex);
308
+ }
309
+ }
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-output-s3-compatible
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Floyd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: S3-Compatible file output plugin is an Embulk plugin that output the files to the specified S3-Compatible storage.
42
+ email:
43
+ - code@floydev.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - LICENSE.txt
50
+ - README.md
51
+ - build.gradle
52
+ - classpath/aws-java-sdk-core-1.11.486.jar
53
+ - classpath/aws-java-sdk-kms-1.11.486.jar
54
+ - classpath/aws-java-sdk-s3-1.11.486.jar
55
+ - classpath/commons-codec-1.10.jar
56
+ - classpath/commons-logging-1.2.jar
57
+ - classpath/embulk-output-s3-compatible-0.0.1.jar
58
+ - classpath/httpclient-4.5.5.jar
59
+ - classpath/httpcore-4.4.9.jar
60
+ - classpath/ion-java-1.0.2.jar
61
+ - classpath/jackson-databind-2.6.7.2.jar
62
+ - classpath/jackson-dataformat-cbor-2.6.7.jar
63
+ - classpath/jmespath-java-1.11.486.jar
64
+ - classpath/zip4j-1.3.2.jar
65
+ - gradle/wrapper/gradle-wrapper.jar
66
+ - gradle/wrapper/gradle-wrapper.properties
67
+ - gradlew
68
+ - gradlew.bat
69
+ - lib/embulk/output/s3-compatible.rb
70
+ - settings.gradle
71
+ - src/main/java/org/embulk/output/S3CompatibleFileOutputPlugin.java
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.6.8
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: S3-Compatible file output plugin for Embulk
96
+ test_files: []