embulk-output-aerospike 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8780e59a53948dd4e2cff92443464abe410f0ef0
4
+ data.tar.gz: c83b6b5257932f69fcb438fe4d554fde4763ba12
5
+ SHA512:
6
+ metadata.gz: 84a5902bc21a65ffdcc3438bf926ec5b44f91bdbc0a4e3ab7fc4bbdf994bc5e4f080aeac8178c8a947c06d65a0415e353b871225a77d10732a6eb2ca7995028d
7
+ data.tar.gz: 4261add7207fa9cdaf6683981724066de243c38b20055078f06b542d02867b321af6f03e947f9a84541d8dae9c2807b2e71008330cd94d8bb793b6b0a4fadef9
@@ -0,0 +1,14 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ *.gemspec
5
+ .gradle/
6
+ /classpath/
7
+ build/
8
+ .idea
9
+ /.settings/
10
+ /.metadata/
11
+ .classpath
12
+ .project
13
+
14
+ *.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,87 @@
1
+ # Aerospike output plugin for Embulk
2
+
3
+ Aerospike output plugins for Embulk loads records to databases using AerospikeJavaClient.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: output
8
+ * **Load all or nothing**: no
9
+ * **Resume supported**: no
10
+ * **Cleanup supported**: yes
11
+
12
+ ## Configuration
13
+
14
+ - **hosts**: (list, required)
15
+ - **name**: hostname (string, required)
16
+ - **port**: port number (int, required)
17
+ - **command**: aerospike command(now supported put and delete only) (string, required)
18
+ - **namespace**: destination namespace (string, required)
19
+ - **set_name**: destination set name (string, required)
20
+ - **key_name**: corresponding column name for create destination key. specified column will be excluded from destinations. (hash, default: `key`)
21
+ - **client_policy**: (hash, default: `conform to aerospike`)
22
+ - **user**: user name (string, default: `null`)
23
+ - **password**: user password (string, default: `null`)
24
+ - **timeout**: command timeout (int, default: `conform to aerospike`)
25
+ - **max_threads**: max thread numbers (int, default: `conform to aerospike`)
26
+ - **max_socket_idle**: max socket idel numbers (int, default: `conform to aerospike`)
27
+ - **tend_interval**: tend interval numbers (int, default: `conform to aerospike`)
28
+ - **fail_if_not_connected**: fail if not connected (boolean, default: `conform to aerospike`)
29
+ - **write_policy**: (hash, default: `conform to aerospike`)
30
+ - **generation**: generation (string, default: `conform to aerospike`)
31
+ - **expiration**: expiration time (int, default: `conform to aerospike`)
32
+ - **max_retries**: max retry numbers (int, default: `conform to aerospike`)
33
+ - **send_key**: send real key (int, default: `conform to aerospike`)
34
+ - **sleep_between_retries**: sleepp between retry numbers (int, default: `conform to aerospike`)
35
+ - **single_bin_name**: bin name (string, default: `null`)
36
+ - **splitters**: key is column_name (hash, required)
37
+ - **separator**: regexp for splitting separator (string, default: `,`)
38
+ - **element_type**: to type of conversions for each elements. now supported type is string, long and double (string, default: `string`)
39
+ - **parallel**: use parallel execute (boolean, default: `false`)
40
+
41
+ ## Example
42
+
43
+ ### single bin mode
44
+
45
+ ```yaml
46
+ out:
47
+ type: aerospike
48
+ hosts:
49
+ - {name: '192.168.99.100', port: 3000}
50
+ command: put
51
+ namespace: test
52
+ set_name: set
53
+ single_bin_name: record
54
+ parallel: true
55
+ splitters:
56
+ column1: {separator: '\.*', element_type: string}
57
+ column2: {separator: '\t', element_type: long}
58
+
59
+ ```
60
+
61
+ ### multi bin mode
62
+
63
+ ```yaml
64
+ out:
65
+ type: aerospike
66
+ hosts:
67
+ - {name: '192.168.99.100', port: 3000}
68
+ command: put
69
+ namespace: test
70
+ set_name: set
71
+ key_name: column0
72
+ client_policy:
73
+ max_retries: 3
74
+ write_policy:
75
+ generation: 0
76
+ expiration: 64000
77
+ send_key: true
78
+ parallel: true
79
+ ```
80
+
81
+
82
+
83
+ ## Build
84
+
85
+ ```sh
86
+ ./gradlew gem # -t to watch change of files and rebuild continuously
87
+ ```
@@ -0,0 +1,72 @@
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
+ compile 'com.aerospike:aerospike-client:3.1.6'
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: ["gemspec", "classpath"]) {
32
+ jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
33
+ script "${project.name}.gemspec"
34
+ doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
35
+ }
36
+
37
+ task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
38
+ jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "push"
39
+ script "pkg/${project.name}-${project.version}.gem"
40
+ }
41
+
42
+ task "package"(dependsOn: ["gemspec", "classpath"]) << {
43
+ println "> Build succeeded."
44
+ println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
45
+ }
46
+
47
+ task gemspec {
48
+ ext.gemspecFile = file("${project.name}.gemspec")
49
+ inputs.file "build.gradle"
50
+ outputs.file gemspecFile
51
+ doLast { gemspecFile.write($/
52
+ Gem::Specification.new do |spec|
53
+ spec.name = "${project.name}"
54
+ spec.version = "${project.version}"
55
+ spec.authors = ["Takeru Sato"]
56
+ spec.summary = %[Aerospike output plugin for Embulk]
57
+ spec.description = %[Dumps records to Aerospike.]
58
+ spec.email = ["midium.size@gmail.com"]
59
+ spec.licenses = ["MIT"]
60
+ spec.homepage = "https://github.com/tkrs/embulk-output-aerospike"
61
+
62
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
63
+ spec.test_files = spec.files.grep(%r"^(test|spec)/")
64
+ spec.require_paths = ["lib"]
65
+
66
+ spec.add_development_dependency 'bundler', ['~> 1.0']
67
+ spec.add_development_dependency 'rake', ['>= 10.0']
68
+ end
69
+ /$)
70
+ }
71
+ }
72
+ clean { delete "${project.name}.gemspec" }
@@ -0,0 +1,6 @@
1
+ #Tue Oct 13 15:46:01 JST 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-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
+ "aerospike", "org.embulk.output.aerospike.AerospikeOutputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,168 @@
1
+ package org.embulk.output.aerospike;
2
+
3
+ import com.google.common.base.Optional;
4
+ import org.embulk.config.*;
5
+ import org.embulk.spi.Exec;
6
+ import org.embulk.spi.OutputPlugin;
7
+ import org.embulk.spi.Schema;
8
+ import org.embulk.spi.TransactionalPageOutput;
9
+
10
+ import java.util.List;
11
+ import java.util.Map;
12
+
13
+ public class AerospikeOutputPlugin
14
+ implements OutputPlugin
15
+ {
16
+ @Override
17
+ public ConfigDiff transaction(ConfigSource config,
18
+ Schema schema, int taskCount,
19
+ OutputPlugin.Control control) {
20
+ PluginTask task = config.loadConfig(PluginTask.class);
21
+
22
+ // retryable (idempotent) output:
23
+ // return resume(task.dump(), schema, taskCount, control);
24
+
25
+ // non-retryable (non-idempotent) output:
26
+ control.run(task.dump());
27
+ return Exec.newConfigDiff();
28
+ }
29
+
30
+ @Override
31
+ public ConfigDiff resume(TaskSource taskSource,
32
+ Schema schema, int taskCount,
33
+ OutputPlugin.Control control)
34
+ {
35
+ throw new UnsupportedOperationException("aerospike output plugin does not support resuming");
36
+ }
37
+
38
+ @Override
39
+ public void cleanup(TaskSource taskSource,
40
+ Schema schema, int taskCount,
41
+ List<TaskReport> successTaskReports) {
42
+ }
43
+
44
+ @Override
45
+ public TransactionalPageOutput open(TaskSource taskSource, final Schema schema, int taskIndex) {
46
+ return new AerospikePageOutput(taskSource, schema, taskIndex);
47
+ }
48
+
49
+ public interface PluginTask
50
+ extends Task {
51
+ @Config("hosts")
52
+ List<HostTask> getHost();
53
+
54
+ @Config("command")
55
+ String getCommand();
56
+
57
+ @Config("namespace")
58
+ String getNamespace();
59
+
60
+ @Config("set_name")
61
+ String getSetName();
62
+
63
+ @Config("key_name")
64
+ @ConfigDefault("key")
65
+ Optional<String> getKeyName();
66
+
67
+ @Config("client_policy")
68
+ @ConfigDefault("null")
69
+ Optional<ClientPolicyTask> getClientPolicy();
70
+
71
+ @Config("write_policy")
72
+ @ConfigDefault("null")
73
+ Optional<WritePolicyTask> getWritePolicy();
74
+
75
+ @Config("single_bin_name")
76
+ @ConfigDefault("null")
77
+ Optional<String> getSingleBinName();
78
+
79
+ @Config("splitters")
80
+ @ConfigDefault("null")
81
+ Optional<Map<String, SplitterTask>> getSplitters();
82
+
83
+ @Config("parallel")
84
+ @ConfigDefault("false")
85
+ Boolean getParallel();
86
+
87
+ }
88
+
89
+ public interface SplitterTask
90
+ extends Task {
91
+
92
+ @Config("separator")
93
+ @ConfigDefault(",")
94
+ String getSeparator();
95
+
96
+ @Config("element_type")
97
+ @ConfigDefault("string")
98
+ String getElementType();
99
+ }
100
+
101
+ public interface HostTask
102
+ extends Task {
103
+
104
+ @Config("name")
105
+ String getName();
106
+
107
+ @Config("port")
108
+ int getPort();
109
+ }
110
+
111
+ public interface ClientPolicyTask
112
+ extends Task {
113
+
114
+ @Config("user")
115
+ @ConfigDefault("null")
116
+ Optional<String> getUser();
117
+
118
+ @Config("password")
119
+ @ConfigDefault("null")
120
+ Optional<String> getPassword();
121
+
122
+ @Config("timeout")
123
+ @ConfigDefault("null")
124
+ Optional<Integer> getTimeout();
125
+
126
+ @Config("max_threads")
127
+ @ConfigDefault("null")
128
+ Optional<Integer> getMaxThreads();
129
+
130
+ @Config("max_socket_idle")
131
+ @ConfigDefault("null")
132
+ Optional<Integer> getMaxSocketIdle();
133
+
134
+ @Config("tend_interval")
135
+ @ConfigDefault("null")
136
+ Optional<Integer> getTendInterval();
137
+
138
+ @Config("fail_if_not_connected")
139
+ @ConfigDefault("null")
140
+ Optional<Boolean> getFailIfNotConnected();
141
+
142
+ }
143
+
144
+ public interface WritePolicyTask
145
+ extends Task {
146
+
147
+ @Config("generation")
148
+ @ConfigDefault("null")
149
+ Optional<Integer> getGeneration();
150
+
151
+ @Config("expiration")
152
+ @ConfigDefault("null")
153
+ Optional<Integer> getExpiration();
154
+
155
+ @Config("max_retries")
156
+ @ConfigDefault("null")
157
+ Optional<Integer> getMaxRetries();
158
+
159
+ @Config("send_key")
160
+ @ConfigDefault("null")
161
+ Optional<Boolean> getSendKey();
162
+
163
+ @Config("sleep_between_retries")
164
+ @ConfigDefault("null")
165
+ Optional<Integer> getSleepBetweenRetries();
166
+
167
+ }
168
+ }
@@ -0,0 +1,218 @@
1
+ package org.embulk.output.aerospike;
2
+
3
+ import com.aerospike.client.*;
4
+ import com.aerospike.client.async.AsyncClient;
5
+ import com.aerospike.client.async.AsyncClientPolicy;
6
+ import com.aerospike.client.listener.DeleteListener;
7
+ import com.aerospike.client.listener.WriteListener;
8
+ import com.aerospike.client.policy.WritePolicy;
9
+ import com.google.common.base.Optional;
10
+ import org.embulk.config.TaskReport;
11
+ import org.embulk.config.TaskSource;
12
+ import org.embulk.spi.*;
13
+ import org.embulk.spi.type.Type;
14
+ import org.jruby.ir.Tuple;
15
+ import org.slf4j.Logger;
16
+
17
+ import java.util.*;
18
+ import java.util.concurrent.atomic.AtomicLong;
19
+ import java.util.function.Consumer;
20
+ import java.util.stream.Collectors;
21
+ import java.util.stream.Stream;
22
+ import java.util.stream.StreamSupport;
23
+
24
+ public class AerospikePageOutput implements TransactionalPageOutput {
25
+
26
+ private final Logger log = Exec.getLogger(AerospikePageOutput.class);
27
+ private final AerospikeOutputPlugin.PluginTask task;
28
+ private final AtomicLong counter = new AtomicLong();
29
+ private final AsyncClient aerospike;
30
+ private final PageReader reader;
31
+
32
+ public AerospikePageOutput(TaskSource taskSource, final Schema schema, int taskIndex) {
33
+ reader = new PageReader(schema);
34
+ task = taskSource.loadTask(AerospikeOutputPlugin.PluginTask.class);
35
+ List<Host> hosts = task.getHost().stream()
36
+ .map(host -> new Host(host.getName(), host.getPort()))
37
+ .collect(Collectors.toList());
38
+
39
+ AsyncClientPolicy policy = new AsyncClientPolicy();
40
+ if (task.getClientPolicy().isPresent()) {
41
+ AerospikeOutputPlugin.ClientPolicyTask cpTask = task.getClientPolicy().get();
42
+ policy.failIfNotConnected = cpTask.getFailIfNotConnected().or(policy.failIfNotConnected);
43
+ policy.maxThreads = cpTask.getMaxThreads().or(policy.maxThreads);
44
+ policy.maxSocketIdle = cpTask.getMaxSocketIdle().or(policy.maxSocketIdle);
45
+ policy.password = cpTask.getPassword().orNull();
46
+ policy.user = cpTask.getUser().orNull();
47
+ policy.timeout = cpTask.getTimeout().or(policy.timeout);
48
+ policy.tendInterval = cpTask.getTendInterval().or(policy.tendInterval);
49
+ }
50
+
51
+ WritePolicy wp = new WritePolicy();
52
+ if (task.getWritePolicy().isPresent()) {
53
+ AerospikeOutputPlugin.WritePolicyTask wpTask = task.getWritePolicy().get();
54
+ wp.sendKey = wpTask.getSendKey().or(wp.sendKey);
55
+ wp.expiration = wpTask.getExpiration().or(wp.expiration);
56
+ wp.maxRetries = wpTask.getMaxRetries().or(wp.maxRetries);
57
+ wp.generation = wpTask.getGeneration().or(wp.generation);
58
+ wp.sleepBetweenRetries = wpTask.getSleepBetweenRetries().or(wp.sleepBetweenRetries);
59
+ }
60
+
61
+ policy.asyncWritePolicyDefault = wp;
62
+ aerospike = new AsyncClient(policy, hosts.toArray(new Host[hosts.size()]));
63
+ }
64
+
65
+ @Override
66
+ public void add(Page page) {
67
+
68
+ if (!aerospike.isConnected()) {
69
+ System.out.println("not connected");
70
+ return;
71
+ }
72
+
73
+ reader.setPage(page);
74
+
75
+ Iterator<Tuple<Key, Map<String, Object>>> it = new Iterator<Tuple<Key, Map<String, Object>>>() {
76
+ @Override public boolean hasNext() { return reader.nextRecord(); }
77
+ @Override public Tuple<Key, Map<String, Object>> next() {
78
+ Schema sc = reader.getSchema();
79
+ Map<String, Object> bins = new HashMap<>();
80
+ Object keyObj = "";
81
+
82
+ for (Column column : sc.getColumns()) {
83
+ String name = column.getName();
84
+ String keyName = task.getKeyName().get();
85
+ Type type = column.getType();
86
+ switch (type.getName()) {
87
+ case "string": {
88
+ if (reader.isNull(column)) break;
89
+ final String value = reader.getString(column);
90
+ if (name.equals(keyName)) {
91
+ keyObj = value;
92
+ break;
93
+ }
94
+ final Optional<Object> v = task.getSplitters().transform(stMap -> {
95
+ if (stMap.containsKey(name)) {
96
+
97
+ List<String> values = Arrays.asList(value.split(stMap.get(name).getSeparator()));
98
+ switch (stMap.get(name).getElementType()) {
99
+ case "long":
100
+ return values.stream().map(s -> s.isEmpty() ? "0" : s).map(Long::valueOf).collect(Collectors.toList());
101
+ case "double":
102
+ return values.stream().map(s -> s.isEmpty() ? "0.0" : s).map(Double::valueOf).collect(Collectors.toList());
103
+ case "string":
104
+ default:
105
+ return values;
106
+ }
107
+ } else {
108
+ return value;
109
+ }
110
+ });
111
+ bins.put(name, v.or(value));
112
+ break;
113
+ }
114
+ case "long": {
115
+ if (reader.isNull(column)) break;
116
+ Long value = reader.getLong(column);
117
+ if (name.equals(keyName)) {
118
+ keyObj = value;
119
+ break;
120
+ }
121
+ bins.put(name, value);
122
+ break;
123
+ }
124
+ case "double": {
125
+ if (reader.isNull(column)) break;
126
+ Double value = reader.getDouble(column);
127
+ if (name.equals(keyName)) {
128
+ keyObj = value;
129
+ break;
130
+ }
131
+ bins.put(name, value);
132
+ break;
133
+ }
134
+ case "boolean": {
135
+ if (reader.isNull(column)) break;
136
+ Boolean value = reader.getBoolean(column);
137
+ if (name.equals(keyName)) {
138
+ keyObj = value;
139
+ break;
140
+ }
141
+ bins.put(name, value);
142
+ break;
143
+ }
144
+ case "timestamp": {
145
+ if (reader.isNull(column)) break;
146
+ Long value = reader.getTimestamp(column).toEpochMilli();
147
+ if (name.equals(keyName)) {
148
+ keyObj = value;
149
+ break;
150
+ }
151
+ bins.put(name, value);
152
+ break;
153
+ }
154
+ default:
155
+ break;
156
+ }
157
+ }
158
+
159
+ if (log.isDebugEnabled()) log.debug(keyObj.toString());
160
+ Key key = new Key(task.getNamespace(), task.getSetName(), Value.get(keyObj));
161
+ return new Tuple<>(key, bins);
162
+ }
163
+ };
164
+
165
+ Spliterator<Tuple<Key, Map<String, Object>>> spliterator = Spliterators.spliteratorUnknownSize(it, Spliterator.IMMUTABLE);
166
+
167
+ Stream<Tuple<Key, Map<String, Object>>> stream = StreamSupport.stream(spliterator, task.getParallel());
168
+
169
+ Consumer<Tuple<Key, List<Bin>>> action;
170
+ switch (task.getCommand()) {
171
+ case "put":
172
+ action = rec -> aerospike.put(null, new WriteListener() {
173
+ @Override public void onSuccess(Key key) { counter.addAndGet(1L); }
174
+ @Override public void onFailure(AerospikeException e) { log.error(e.getMessage(), e); }
175
+ }, rec.a, rec.b.toArray(new Bin[rec.b.size()]));
176
+ break;
177
+ case "delete":
178
+ action = rec -> aerospike.delete(null, new DeleteListener() {
179
+ @Override public void onSuccess(Key key, boolean existed) { counter.addAndGet(1L); }
180
+ @Override public void onFailure(AerospikeException e) { log.error(e.getMessage(), e); }
181
+ }, rec.a);
182
+ break;
183
+ default:
184
+ return;
185
+ }
186
+
187
+ stream.map(t -> {
188
+ List<Bin> bins = new ArrayList<>();
189
+ if (task.getSingleBinName().isPresent())
190
+ bins.add(new Bin(task.getSingleBinName().get(), t.b));
191
+ else
192
+ t.b.entrySet().forEach(rec -> bins.add(new Bin(rec.getKey(), rec.getValue())));
193
+ return new Tuple<>(t.a, bins);
194
+ }).forEach(action);
195
+ }
196
+
197
+ @Override
198
+ public void finish() {
199
+ log.info("finish %s [%l]", task.getCommand(), counter.longValue());
200
+ }
201
+
202
+ @Override
203
+ public void close() {
204
+ reader.close();
205
+ aerospike.close();
206
+ }
207
+
208
+ @Override
209
+ public void abort() {
210
+ log.warn("abort");
211
+ }
212
+
213
+ @Override
214
+ public TaskReport commit() {
215
+ return Exec.newTaskReport();
216
+ }
217
+
218
+ }
@@ -0,0 +1,5 @@
1
+ package org.embulk.output.aerospike;
2
+
3
+ public class TestAerospikeOutputPlugin
4
+ {
5
+ }
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-output-aerospike
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takeru Sato
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-14 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: Dumps records to Aerospike.
42
+ email:
43
+ - midium.size@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - LICENSE.txt
50
+ - README.md
51
+ - build.gradle
52
+ - embulk-output-aerospike.iml
53
+ - gradle/wrapper/gradle-wrapper.jar
54
+ - gradle/wrapper/gradle-wrapper.properties
55
+ - gradlew
56
+ - gradlew.bat
57
+ - lib/embulk/output/aerospike.rb
58
+ - src/main/java/org/embulk/output/aerospike/AerospikeOutputPlugin.java
59
+ - src/main/java/org/embulk/output/aerospike/AerospikePageOutput.java
60
+ - src/test/java/org/embulk/output/aerospike/TestAerospikeOutputPlugin.java
61
+ - classpath/aerospike-client-3.1.6.jar
62
+ - classpath/embulk-output-aerospike-0.1.0.jar
63
+ - classpath/gnu-crypto-2.0.1.jar
64
+ - classpath/jbcrypt-0.3m.jar
65
+ - classpath/luaj-jse-3.0.jar
66
+ homepage: https://github.com/tkrs/embulk-output-aerospike
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.1.9
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Aerospike output plugin for Embulk
90
+ test_files: []