embulk-input-azure_blob_storage 0.1.0

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: 5cba152c50dbcb32fdafe2a64b65f2c0a9e82558
4
+ data.tar.gz: 634d95bfb9102801640a57fd06ee4466d779439c
5
+ SHA512:
6
+ metadata.gz: 735c5cfe513d77d0d2f0b69b9d86f898742d2b1907968410ebecb56b9e58eda7e69fa4a03b747049006ba5e527c16fb482473e4b64731c6ae5c496760fa120a9
7
+ data.tar.gz: b8488a1dba1362a38f2b18b833d74312c1c760878b090bfea2824a836912a3775000743689f38fcc41efc45fc799dabbc408e94d3c0819ba7293433ef6aa741e
@@ -0,0 +1,14 @@
1
+ target/
2
+ build/
3
+ pkg/
4
+ *.iml
5
+ *~
6
+ ._*
7
+ .idea
8
+ tmp/
9
+ vendor/
10
+ /classpath/
11
+ /.bundle
12
+ .yardoc
13
+ /embulk-*.jar
14
+ /.gradle
@@ -0,0 +1,62 @@
1
+ # Azure blob Storage file input plugin for Embulk
2
+
3
+ [Embulk](http://www.embulk.org/) file input plugin read files stored on [Microsoft Azure](https://azure.microsoft.com/) [blob Storage](https://azure.microsoft.com/en-us/documentation/articles/storage-introduction/#blob-storage)
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: file input
8
+ * **Resume supported**: no
9
+ * **Cleanup supported**: yes
10
+
11
+ ## Configuration
12
+
13
+ First, create Azure [Storage Account](https://azure.microsoft.com/en-us/documentation/articles/storage-create-storage-account/).
14
+
15
+ - **account_name**: storage account name (string, required)
16
+ - **account_key**: primary access key (string, required)
17
+ - **container**: container name data stored (string, required)
18
+ - **path_prefix**: prefix of target keys (string, required) (string, required)
19
+
20
+ ## Example
21
+
22
+ ```yaml
23
+ in:
24
+ type: azure_blob_storage
25
+ account_name: myaccount
26
+ account_key: myaccount_key
27
+ container: my-container
28
+ path_prefix: logs/csv-
29
+ ```
30
+
31
+ Example for "sample_01.csv.gz" , generated by [embulk example](https://github.com/embulk/embulk#trying-examples)
32
+
33
+ ```yaml
34
+ in:
35
+ type: azure_blob_storage
36
+ account_name: myaccount
37
+ account_key: myaccount_key
38
+ container: my-container
39
+ path_prefix: logs/csv-
40
+ decoders:
41
+ - {type: gzip}
42
+ parser:
43
+ charset: UTF-8
44
+ newline: CRLF
45
+ type: csv
46
+ delimiter: ','
47
+ quote: '"'
48
+ header_line: true
49
+ columns:
50
+ - {name: id, type: long}
51
+ - {name: account, type: long}
52
+ - {name: time, type: timestamp, format: '%Y-%m-%d %H:%M:%S'}
53
+ - {name: purchase, type: timestamp, format: '%Y%m%d'}
54
+ - {name: comment, type: string}
55
+ out: {type: stdout}
56
+ ```
57
+
58
+ ## Build
59
+
60
+ ```
61
+ $ ./gradlew gem # -t to watch change of files and rebuild continuously
62
+ ```
@@ -0,0 +1,74 @@
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.7.5"
19
+ provided "org.embulk:embulk-core:0.7.5"
20
+
21
+ compile "com.microsoft.azure:azure-storage:4.0.0"
22
+
23
+ testCompile "junit:junit:4.+"
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 "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
35
+ script "${project.name}.gemspec"
36
+ doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
37
+ }
38
+
39
+ task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
40
+ jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "push"
41
+ script "pkg/${project.name}-${project.version}.gem"
42
+ }
43
+
44
+ task "package"(dependsOn: ["gemspec", "classpath"]) << {
45
+ println "> Build succeeded."
46
+ println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
47
+ }
48
+
49
+ task gemspec {
50
+ ext.gemspecFile = file("${project.name}.gemspec")
51
+ inputs.file "build.gradle"
52
+ outputs.file gemspecFile
53
+ doLast { gemspecFile.write($/
54
+ Gem::Specification.new do |spec|
55
+ spec.name = "${project.name}"
56
+ spec.version = "${project.version}"
57
+ spec.authors = ["Satoshi Akama"]
58
+ spec.summary = %[Microsoft Azure blob Storage file input plugin for Embulk]
59
+ spec.description = %[Reads files stored on Microsoft Azure blob Storage.]
60
+ spec.email = ["satoshiakama@gmail.com"]
61
+ spec.licenses = ["Apache-2.0"]
62
+ spec.homepage = "https://github.com/sakama/embulk-input-azure_blob_storage"
63
+
64
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
65
+ spec.test_files = spec.files.grep(%r"^(test|spec)/")
66
+ spec.require_paths = ["lib"]
67
+
68
+ spec.add_development_dependency 'bundler', ['~> 1.0']
69
+ spec.add_development_dependency 'rake', ['>= 10.0']
70
+ end
71
+ /$)
72
+ }
73
+ }
74
+ clean { delete "${project.name}.gemspec" }
@@ -0,0 +1,18 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-input-azure_blob_storage"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["Satoshi Akama"]
6
+ spec.summary = %[Microsoft Azure blob Storage file input plugin for Embulk]
7
+ spec.description = %[Reads files stored on Microsoft Azure blob Storage.]
8
+ spec.email = ["satoshiakama@gmail.com"]
9
+ spec.licenses = ["Apache-2.0"]
10
+ spec.homepage = "https://github.com/sakama/embulk-input-azure_blob_storage"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r"^(test|spec)/")
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_development_dependency 'bundler', ['~> 1.0']
17
+ spec.add_development_dependency 'rake', ['>= 10.0']
18
+ end
@@ -0,0 +1,6 @@
1
+ #Tue Aug 11 00:26:20 PDT 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.6-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 "$@"
@@ -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_input(
2
+ "azure_blob_storage", "org.embulk.input.azure_blob_storage.AzureBlobStorageFileInputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,220 @@
1
+ package org.embulk.input.azure_blob_storage;
2
+
3
+ import java.util.List;
4
+ import java.util.ArrayList;
5
+ import java.util.Collections;
6
+ import java.io.InputStream;
7
+ import java.io.IOException;
8
+ import java.security.InvalidKeyException;
9
+ import java.net.URISyntaxException;
10
+ import com.google.common.base.Optional;
11
+ import com.google.common.collect.ImmutableList;
12
+ import com.google.common.base.Throwables;
13
+ import org.embulk.config.Config;
14
+ import org.embulk.config.ConfigException;
15
+ import org.embulk.config.ConfigInject;
16
+ import org.embulk.config.ConfigDefault;
17
+ import org.embulk.config.Task;
18
+ import org.embulk.config.TaskSource;
19
+ import org.embulk.config.ConfigSource;
20
+ import org.embulk.config.ConfigDiff;
21
+ import org.embulk.config.TaskReport;
22
+ import org.embulk.spi.Exec;
23
+ import org.embulk.spi.FileInputPlugin;
24
+ import org.embulk.spi.BufferAllocator;
25
+ import org.embulk.spi.TransactionalFileInput;
26
+ import org.embulk.spi.util.InputStreamFileInput;
27
+ import com.microsoft.azure.storage.*;
28
+ import com.microsoft.azure.storage.blob.*;
29
+ import org.slf4j.Logger;
30
+
31
+ public class AzureBlobStorageFileInputPlugin
32
+ implements FileInputPlugin
33
+ {
34
+ public interface PluginTask
35
+ extends Task
36
+ {
37
+ @Config("account_name")
38
+ String getAccountName();
39
+
40
+ @Config("account_key")
41
+ String getAccountKey();
42
+
43
+ @Config("container")
44
+ String getContainer();
45
+
46
+ @Config("path_prefix")
47
+ String getPathPrefix();
48
+
49
+ @Config("last_path")
50
+ @ConfigDefault("null")
51
+ Optional<String> getLastPath();
52
+
53
+ @Config("max_results")
54
+ @ConfigDefault("5000")
55
+ int getMaxResults();
56
+
57
+ List<String> getFiles();
58
+
59
+ void setFiles(List<String> files);
60
+
61
+ @ConfigInject
62
+ BufferAllocator getBufferAllocator();
63
+ }
64
+
65
+ private static final Logger log = Exec.getLogger(AzureBlobStorageFileInputPlugin.class);
66
+
67
+ @Override
68
+ public ConfigDiff transaction(ConfigSource config, FileInputPlugin.Control control)
69
+ {
70
+ final PluginTask task = config.loadConfig(PluginTask.class);
71
+
72
+ CloudBlobClient blobClient = newAzureClient(task.getAccountName(), task.getAccountKey());
73
+ task.setFiles(listFiles(blobClient, task));
74
+
75
+ return resume(task.dump(), task.getFiles().size(), control);
76
+ }
77
+
78
+ @Override
79
+ public ConfigDiff resume(TaskSource taskSource, int taskCount, FileInputPlugin.Control control)
80
+ {
81
+ PluginTask task = taskSource.loadTask(PluginTask.class);
82
+
83
+ control.run(taskSource, taskCount);
84
+
85
+ ConfigDiff configDiff = Exec.newConfigDiff();
86
+
87
+ List<String> files = new ArrayList<> (task.getFiles());
88
+ if (files.isEmpty()) {
89
+ if (task.getLastPath().isPresent()) {
90
+ configDiff.set("last_path", task.getLastPath().get());
91
+ }
92
+ } else {
93
+ Collections.sort(files);
94
+ configDiff.set("last_path", files.get(files.size() - 1));
95
+ }
96
+ return configDiff;
97
+ }
98
+
99
+ @Override
100
+ public void cleanup(TaskSource taskSource, int taskCount, List<TaskReport> successTaskReports)
101
+ {
102
+ }
103
+
104
+ private static CloudBlobClient newAzureClient(String accountName, String accountKey)
105
+ {
106
+ String connectionString = "DefaultEndpointsProtocol=http;" +
107
+ "AccountName=" + accountName + ";" +
108
+ "AccountKey=" + accountKey;
109
+
110
+ CloudStorageAccount account;
111
+ try {
112
+ account = CloudStorageAccount.parse(connectionString);
113
+ } catch (InvalidKeyException | URISyntaxException ex) {
114
+ throw new ConfigException(ex);
115
+ }
116
+ return account.createCloudBlobClient();
117
+ }
118
+
119
+ private List<String> listFiles(CloudBlobClient client, PluginTask task)
120
+ {
121
+ if (task.getPathPrefix().equals("/")) {
122
+ log.info("Listing files with prefix \"/\". This doesn't mean all files in a bucket. If you intend to read all files, use \"path_prefix: ''\" (empty string) instead.");
123
+ }
124
+
125
+ return listFilesWithPrefix(client, task.getContainer(), task.getPathPrefix(), task.getLastPath(), task.getMaxResults());
126
+ }
127
+
128
+ private static List<String> listFilesWithPrefix(CloudBlobClient client, String containerName,
129
+ String prefix, Optional<String> lastPath, int maxResults)
130
+ {
131
+ ImmutableList.Builder<String> builder = ImmutableList.builder();
132
+ // It seems I can't cast lastKey<String> to token<ResultContinuation> by Azure SDK for Java
133
+ String lastKey = lastPath.orNull();
134
+ ResultContinuation token = null;
135
+
136
+ try {
137
+ CloudBlobContainer container = client.getContainerReference(containerName);
138
+ ResultSegment<ListBlobItem> blobs;
139
+ do {
140
+ blobs = container.listBlobsSegmented(prefix, true, null, maxResults, token, null, null);
141
+ log.debug(String.format("result count(include directory):%s continuationToken:%s", blobs.getLength() ,blobs.getContinuationToken()));
142
+ for (ListBlobItem blobItem : blobs.getResults()) {
143
+ if (blobItem instanceof CloudBlob) {
144
+ CloudBlob blob = (CloudBlob) blobItem;
145
+ if (blob.exists() && !blob.getUri().toString().endsWith("/")) {
146
+ builder.add(blob.getName());
147
+ log.debug(String.format("name:%s, class:%s, uri:%s", blob.getName(), blob.getClass(), blob.getUri()));
148
+ }
149
+ }
150
+ }
151
+ token = blobs.getContinuationToken();
152
+ } while (blobs.getContinuationToken() != null);
153
+ } catch (URISyntaxException | StorageException ex) {
154
+ throw Throwables.propagate(ex);
155
+ }
156
+ return builder.build();
157
+ }
158
+
159
+ @Override
160
+ public TransactionalFileInput open(TaskSource taskSource, int taskIndex)
161
+ {
162
+ PluginTask task = taskSource.loadTask(PluginTask.class);
163
+ return new AzureFileInput(task, taskIndex);
164
+ }
165
+
166
+ class AzureFileInput
167
+ extends InputStreamFileInput
168
+ implements TransactionalFileInput
169
+ {
170
+ public AzureFileInput (PluginTask task, int taskIndex)
171
+ {
172
+ super(task.getBufferAllocator(), new SingleFileProvider(task, taskIndex));
173
+ }
174
+ public void abort() {}
175
+
176
+ public TaskReport commit() {
177
+ return Exec.newTaskReport();
178
+ }
179
+
180
+ @Override
181
+ public void close() {}
182
+ }
183
+
184
+ class SingleFileProvider
185
+ implements InputStreamFileInput.Provider
186
+ {
187
+ private CloudBlobClient client;
188
+ private final String containerName;
189
+ private final String key;
190
+ private boolean opened = false;
191
+
192
+ public SingleFileProvider(PluginTask task, int taskIndex)
193
+ {
194
+ this.client = newAzureClient(task.getAccountName(), task.getAccountKey());
195
+ this.containerName = task.getContainer();
196
+ this.key = task.getFiles().get(taskIndex);
197
+ }
198
+
199
+ @Override
200
+ public InputStream openNext() throws IOException
201
+ {
202
+ if (opened) {
203
+ return null;
204
+ }
205
+ opened = true;
206
+ InputStream inputStream = null;
207
+ try {
208
+ CloudBlobContainer container = client.getContainerReference(containerName);
209
+ CloudBlob blob = container.getBlockBlobReference(key);
210
+ inputStream = blob.openInputStream();
211
+ } catch (StorageException | URISyntaxException ex) {
212
+ Throwables.propagate(ex);
213
+ }
214
+ return inputStream;
215
+ }
216
+
217
+ @Override
218
+ public void close() {}
219
+ }
220
+ }
@@ -0,0 +1,5 @@
1
+ package org.embulk.input.azure_blob_storage;
2
+
3
+ public class TestAzureBlobStorageFileInputPlugin
4
+ {
5
+ }
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-input-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-10 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: Reads files stored 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
+ - embulk-input-azure_blob_storage.gemspec
52
+ - gradle/wrapper/gradle-wrapper.jar
53
+ - gradle/wrapper/gradle-wrapper.properties
54
+ - gradlew
55
+ - gradlew.bat
56
+ - lib/embulk/input/azure_blob_storage.rb
57
+ - src/main/java/org/embulk/input/azure_blob_storage/AzureBlobStorageFileInputPlugin.java
58
+ - src/test/java/org/embulk/input/azure_blob_storage/TestAzureBlobStorageFileInputPlugin.java
59
+ - classpath/azure-storage-4.0.0.jar
60
+ - classpath/commons-lang3-3.4.jar
61
+ - classpath/embulk-input-azure_blob_storage-0.1.0.jar
62
+ - classpath/jackson-core-2.6.0.jar
63
+ homepage: https://github.com/sakama/embulk-input-azure_blob_storage
64
+ licenses:
65
+ - Apache-2.0
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.1.9
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Microsoft Azure blob Storage file input plugin for Embulk
87
+ test_files: []