embulk-output-azure_blob_storage 0.1.0
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 +7 -0
- data/.gitignore +14 -0
- data/README.md +52 -0
- data/build.gradle +77 -0
- data/classpath/azure-storage-4.0.0.jar +0 -0
- data/classpath/commons-lang3-3.4.jar +0 -0
- data/classpath/embulk-output-azure_blob_storage-0.1.0.jar +0 -0
- data/classpath/jackson-core-2.6.0.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +164 -0
- data/gradlew.bat +90 -0
- data/lib/embulk/output/azure_blob_storage.rb +3 -0
- data/src/main/java/org/embulk/output/azure_blob_storage/AzureBlobStorageFileOutputPlugin.java +199 -0
- data/src/test/java/org/embulk/output/azure_blob_storage/TestAzureBlobStorageFileOutputPlugin.java +5 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c606ebbfa50cbbc803f2ff2f47d6f4dd445eb9d3
|
4
|
+
data.tar.gz: e36fc67a7ce53216367c0c5fb8e0c1aa629fb8d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: beb7e8ec55ce584f88de927aa6fedf75dc62513636e71d60604b1440d525f04e93b196c95518e1f1d132c1a42d0bdd52090f30facb6a59683b7ce45ece2ac2ce
|
7
|
+
data.tar.gz: b45f0a27f6024c703c3297962dcb7c8957588df0be1f8a8ba27ac17e57385518bd1aa387bbf9e5e560dfd977f1c91af230ea3e4b76019720281881eff13a3cef
|
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Azure blob Storage file output plugin for Embulk
|
2
|
+
|
3
|
+
[Embulk](http://www.embulk.org/) file output plugin stores files on [Microsoft Azure](https://azure.microsoft.com/) [blob Storage](https://azure.microsoft.com/en-us/documentation/articles/storage-introduction/#blob-storage)
|
4
|
+
|
5
|
+
|
6
|
+
## Overview
|
7
|
+
|
8
|
+
* **Plugin type**: file output
|
9
|
+
* **Resume supported**: no
|
10
|
+
* **Cleanup supported**: no
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
|
14
|
+
First, create Azure [Storage Account](https://azure.microsoft.com/en-us/documentation/articles/storage-create-storage-account/).
|
15
|
+
|
16
|
+
- **account_name**: storage account name (string, required)
|
17
|
+
- **account_key**: primary access key (string, required)
|
18
|
+
- **container**: container name (string, required)
|
19
|
+
- **path_prefix**: prefix of target keys (string, required) (string, required)
|
20
|
+
- **file_ext**: e.g. "csv.gz, json.gz" (string, required)
|
21
|
+
|
22
|
+
|
23
|
+
### Auto create container
|
24
|
+
|
25
|
+
container will create automatically when container isn't exists.
|
26
|
+
|
27
|
+
When a container is deleted, a container with the same name cannot be created for at least 30 seconds.
|
28
|
+
It's a [service specification](https://technet.microsoft.com/en-us/library/dd179408.aspx#Anchor_3) of Azure blob Storage.
|
29
|
+
|
30
|
+
## Example
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
out:
|
34
|
+
type: azure_blob_storage
|
35
|
+
account_name: myaccount
|
36
|
+
account_key: myaccount_key
|
37
|
+
container: my-container
|
38
|
+
path_prefix: logs/csv-
|
39
|
+
file_ext: csv.gz
|
40
|
+
formatter:
|
41
|
+
type: csv
|
42
|
+
header_line: false
|
43
|
+
encoders:
|
44
|
+
- {type: gzip}
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
## Build
|
49
|
+
|
50
|
+
```
|
51
|
+
$ ./gradlew gem # -t to watch change of files and rebuild continuously
|
52
|
+
```
|
data/build.gradle
ADDED
@@ -0,0 +1,77 @@
|
|
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
|
+
sourceCompatibility = 1.7
|
16
|
+
targetCompatibility = 1.7
|
17
|
+
|
18
|
+
version = "0.1.0"
|
19
|
+
|
20
|
+
dependencies {
|
21
|
+
compile "org.embulk:embulk-core:0.7.5"
|
22
|
+
provided "org.embulk:embulk-core:0.7.5"
|
23
|
+
|
24
|
+
compile "com.microsoft.azure:azure-storage:4.0.0"
|
25
|
+
|
26
|
+
testCompile "junit:junit:4.+"
|
27
|
+
}
|
28
|
+
|
29
|
+
task classpath(type: Copy, dependsOn: ["jar"]) {
|
30
|
+
doFirst { file("classpath").deleteDir() }
|
31
|
+
from (configurations.runtime - configurations.provided + files(jar.archivePath))
|
32
|
+
into "classpath"
|
33
|
+
}
|
34
|
+
clean { delete "classpath" }
|
35
|
+
|
36
|
+
task gem(type: JRubyExec, dependsOn: ["gemspec", "classpath"]) {
|
37
|
+
jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
|
38
|
+
script "${project.name}.gemspec"
|
39
|
+
doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
|
40
|
+
}
|
41
|
+
|
42
|
+
task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
|
43
|
+
jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "push"
|
44
|
+
script "pkg/${project.name}-${project.version}.gem"
|
45
|
+
}
|
46
|
+
|
47
|
+
task "package"(dependsOn: ["gemspec", "classpath"]) << {
|
48
|
+
println "> Build succeeded."
|
49
|
+
println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
|
50
|
+
}
|
51
|
+
|
52
|
+
task gemspec {
|
53
|
+
ext.gemspecFile = file("${project.name}.gemspec")
|
54
|
+
inputs.file "build.gradle"
|
55
|
+
outputs.file gemspecFile
|
56
|
+
doLast { gemspecFile.write($/
|
57
|
+
Gem::Specification.new do |spec|
|
58
|
+
spec.name = "${project.name}"
|
59
|
+
spec.version = "${project.version}"
|
60
|
+
spec.authors = ["Satoshi Akama"]
|
61
|
+
spec.summary = %[Microsoft Azure blob Storage file output plugin for Embulk]
|
62
|
+
spec.description = %[Stores files on Microsoft Azure blob Storage.]
|
63
|
+
spec.email = ["satoshiakama@gmail.com"]
|
64
|
+
spec.licenses = ["Apache-2.0"]
|
65
|
+
spec.homepage = "https://github.com/sakama/embulk-output-azure_blob_storage"
|
66
|
+
|
67
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
68
|
+
spec.test_files = spec.files.grep(%r"^(test|spec)/")
|
69
|
+
spec.require_paths = ["lib"]
|
70
|
+
|
71
|
+
spec.add_development_dependency 'bundler', ['~> 1.0']
|
72
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
73
|
+
end
|
74
|
+
/$)
|
75
|
+
}
|
76
|
+
}
|
77
|
+
clean { delete "${project.name}.gemspec" }
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
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,199 @@
|
|
1
|
+
package org.embulk.output.azure_blob_storage;
|
2
|
+
|
3
|
+
import java.io.File;
|
4
|
+
import java.io.BufferedOutputStream;
|
5
|
+
import java.io.FileInputStream;
|
6
|
+
import java.io.FileOutputStream;
|
7
|
+
import java.io.FileNotFoundException;
|
8
|
+
import java.io.IOException;
|
9
|
+
import java.net.URISyntaxException;
|
10
|
+
import java.security.InvalidKeyException;
|
11
|
+
import java.util.List;
|
12
|
+
import com.google.common.base.Throwables;
|
13
|
+
import org.embulk.config.Config;
|
14
|
+
import org.embulk.config.ConfigException;
|
15
|
+
import org.embulk.config.ConfigDefault;
|
16
|
+
import org.embulk.config.ConfigSource;
|
17
|
+
import org.embulk.config.ConfigDiff;
|
18
|
+
import org.embulk.config.TaskReport;
|
19
|
+
import org.embulk.config.Task;
|
20
|
+
import org.embulk.config.TaskSource;
|
21
|
+
import org.embulk.spi.Exec;
|
22
|
+
import org.embulk.spi.FileOutputPlugin;
|
23
|
+
import org.embulk.spi.TransactionalFileOutput;
|
24
|
+
import org.embulk.spi.Buffer;
|
25
|
+
import com.microsoft.azure.storage.*;
|
26
|
+
import com.microsoft.azure.storage.blob.*;
|
27
|
+
import org.slf4j.Logger;
|
28
|
+
|
29
|
+
public class AzureBlobStorageFileOutputPlugin
|
30
|
+
implements FileOutputPlugin
|
31
|
+
{
|
32
|
+
public interface PluginTask
|
33
|
+
extends Task
|
34
|
+
{
|
35
|
+
@Config("account_name")
|
36
|
+
String getAccountName();
|
37
|
+
|
38
|
+
@Config("account_key")
|
39
|
+
String getAccountKey();
|
40
|
+
|
41
|
+
@Config("container")
|
42
|
+
String getContainer();
|
43
|
+
|
44
|
+
@Config("path_prefix")
|
45
|
+
String getPathPrefix();
|
46
|
+
|
47
|
+
@Config("file_ext")
|
48
|
+
String getFileNameExtension();
|
49
|
+
|
50
|
+
@Config("sequence_format")
|
51
|
+
@ConfigDefault("\"%03d.%02d\"")
|
52
|
+
String getSequenceFormat();
|
53
|
+
}
|
54
|
+
|
55
|
+
private static final Logger log = Exec.getLogger(AzureBlobStorageFileOutputPlugin.class);
|
56
|
+
private static CloudBlobClient blobClient;
|
57
|
+
private static CloudBlobContainer container;
|
58
|
+
|
59
|
+
@Override
|
60
|
+
public ConfigDiff transaction(ConfigSource config, int taskCount,
|
61
|
+
FileOutputPlugin.Control control)
|
62
|
+
{
|
63
|
+
PluginTask task = config.loadConfig(PluginTask.class);
|
64
|
+
blobClient = newAzureClient(task.getAccountName(), task.getAccountKey());
|
65
|
+
String containerName = task.getContainer();
|
66
|
+
|
67
|
+
try {
|
68
|
+
container = blobClient.getContainerReference(containerName);
|
69
|
+
if (!container.exists()) {
|
70
|
+
log.info(String.format("container [%s] is not exists and created.", containerName));
|
71
|
+
container.createIfNotExists();
|
72
|
+
}
|
73
|
+
} catch (StorageException | URISyntaxException ex) {
|
74
|
+
Throwables.propagate(ex);
|
75
|
+
}
|
76
|
+
|
77
|
+
return resume(task.dump(), taskCount, control);
|
78
|
+
}
|
79
|
+
|
80
|
+
@Override
|
81
|
+
public ConfigDiff resume(TaskSource taskSource, int taskCount, FileOutputPlugin.Control control)
|
82
|
+
{
|
83
|
+
control.run(taskSource);
|
84
|
+
|
85
|
+
return Exec.newConfigDiff();
|
86
|
+
}
|
87
|
+
|
88
|
+
@Override
|
89
|
+
public void cleanup(TaskSource taskSource, int taskCount, List<TaskReport> successTaskReports)
|
90
|
+
{
|
91
|
+
}
|
92
|
+
|
93
|
+
private static CloudBlobClient newAzureClient(String accountName, String accountKey)
|
94
|
+
{
|
95
|
+
String connectionString = "DefaultEndpointsProtocol=https;" +
|
96
|
+
"AccountName=" + accountName + ";" +
|
97
|
+
"AccountKey=" + accountKey;
|
98
|
+
|
99
|
+
CloudStorageAccount account;
|
100
|
+
try {
|
101
|
+
account = CloudStorageAccount.parse(connectionString);
|
102
|
+
} catch (InvalidKeyException | URISyntaxException ex) {
|
103
|
+
throw new ConfigException(ex.getMessage());
|
104
|
+
}
|
105
|
+
return account.createCloudBlobClient();
|
106
|
+
}
|
107
|
+
|
108
|
+
@Override
|
109
|
+
public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
|
110
|
+
{
|
111
|
+
final PluginTask task = taskSource.loadTask(PluginTask.class);
|
112
|
+
|
113
|
+
final String pathPrefix = task.getPathPrefix();
|
114
|
+
final String sequenceFormat = task.getSequenceFormat();
|
115
|
+
final String pathSuffix = task.getFileNameExtension();
|
116
|
+
|
117
|
+
return new TransactionalFileOutput() {
|
118
|
+
private int fileIndex = 0;
|
119
|
+
private BufferedOutputStream output = null;
|
120
|
+
private File file;
|
121
|
+
private String filePath;
|
122
|
+
|
123
|
+
public void nextFile()
|
124
|
+
{
|
125
|
+
closeFile();
|
126
|
+
|
127
|
+
try {
|
128
|
+
String suffix = pathSuffix;
|
129
|
+
if (!suffix.startsWith(".")) {
|
130
|
+
suffix = "." + suffix;
|
131
|
+
}
|
132
|
+
filePath = pathPrefix + String.format(sequenceFormat, taskIndex, fileIndex) + suffix;
|
133
|
+
file = new File(filePath);
|
134
|
+
|
135
|
+
String parentPath = file.getParent();
|
136
|
+
File dir = new File(parentPath);
|
137
|
+
if (!dir.exists()) {
|
138
|
+
dir.mkdir();
|
139
|
+
}
|
140
|
+
log.info(String.format("Writing local file [%s]", filePath));
|
141
|
+
output = new BufferedOutputStream(new FileOutputStream(filePath));
|
142
|
+
} catch (FileNotFoundException ex) {
|
143
|
+
throw Throwables.propagate(ex);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
private void closeFile()
|
148
|
+
{
|
149
|
+
if (output != null) {
|
150
|
+
try {
|
151
|
+
output.close();
|
152
|
+
} catch (IOException ex) {
|
153
|
+
throw Throwables.propagate(ex);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
public void add(Buffer buffer)
|
159
|
+
{
|
160
|
+
try {
|
161
|
+
output.write(buffer.array(), buffer.offset(), buffer.limit());
|
162
|
+
} catch (IOException ex) {
|
163
|
+
throw Throwables.propagate(ex);
|
164
|
+
} finally {
|
165
|
+
buffer.release();
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
public void finish()
|
170
|
+
{
|
171
|
+
closeFile();
|
172
|
+
if (filePath != null) {
|
173
|
+
try {
|
174
|
+
CloudBlockBlob blob = container.getBlockBlobReference(filePath);
|
175
|
+
log.info(String.format("Upload start [%s]", filePath));
|
176
|
+
blob.upload(new FileInputStream(file), file.length());
|
177
|
+
log.info(String.format("Upload completed [%s]", filePath));
|
178
|
+
file.delete();
|
179
|
+
log.info(String.format("Delete completed local file [%s]", filePath));
|
180
|
+
} catch (StorageException | URISyntaxException | IOException ex) {
|
181
|
+
Throwables.propagate(ex);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
public void close()
|
187
|
+
{
|
188
|
+
closeFile();
|
189
|
+
}
|
190
|
+
|
191
|
+
public void abort() {}
|
192
|
+
|
193
|
+
public TaskReport commit()
|
194
|
+
{
|
195
|
+
return Exec.newTaskReport();
|
196
|
+
}
|
197
|
+
};
|
198
|
+
}
|
199
|
+
}
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-output-azure_blob_storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Satoshi Akama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-11 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: Stores files on Microsoft Azure blob Storage.
|
42
|
+
email:
|
43
|
+
- satoshiakama@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- README.md
|
50
|
+
- build.gradle
|
51
|
+
- gradle/wrapper/gradle-wrapper.jar
|
52
|
+
- gradle/wrapper/gradle-wrapper.properties
|
53
|
+
- gradlew
|
54
|
+
- gradlew.bat
|
55
|
+
- lib/embulk/output/azure_blob_storage.rb
|
56
|
+
- src/main/java/org/embulk/output/azure_blob_storage/AzureBlobStorageFileOutputPlugin.java
|
57
|
+
- src/test/java/org/embulk/output/azure_blob_storage/TestAzureBlobStorageFileOutputPlugin.java
|
58
|
+
- classpath/azure-storage-4.0.0.jar
|
59
|
+
- classpath/commons-lang3-3.4.jar
|
60
|
+
- classpath/embulk-output-azure_blob_storage-0.1.0.jar
|
61
|
+
- classpath/jackson-core-2.6.0.jar
|
62
|
+
homepage: https://github.com/sakama/embulk-output-azure_blob_storage
|
63
|
+
licenses:
|
64
|
+
- Apache-2.0
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.1.9
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Microsoft Azure blob Storage file output plugin for Embulk
|
86
|
+
test_files: []
|