embulk-executor-remoteserver 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +42 -0
  3. data/.gitignore +14 -0
  4. data/Dockerfile +14 -0
  5. data/LICENSE +21 -0
  6. data/README.md +30 -0
  7. data/build.gradle +70 -0
  8. data/docker-compose.yml +24 -0
  9. data/docker/run_embulk_server.sh +3 -0
  10. data/gradle.properties +1 -0
  11. data/gradle/dependency-locks/compileClasspath.lockfile +40 -0
  12. data/gradle/dependency-locks/testCompileClasspath.lockfile +49 -0
  13. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  14. data/gradle/wrapper/gradle-wrapper.properties +5 -0
  15. data/gradlew +172 -0
  16. data/gradlew.bat +84 -0
  17. data/lib/embulk/executor/remoteserver.rb +3 -0
  18. data/settings.gradle +1 -0
  19. data/src/main/java/org/embulk/executor/remoteserver/EmbulkClient.java +111 -0
  20. data/src/main/java/org/embulk/executor/remoteserver/EmbulkServer.java +32 -0
  21. data/src/main/java/org/embulk/executor/remoteserver/Host.java +32 -0
  22. data/src/main/java/org/embulk/executor/remoteserver/InitializeSessionCommand.java +94 -0
  23. data/src/main/java/org/embulk/executor/remoteserver/Launcher.java +25 -0
  24. data/src/main/java/org/embulk/executor/remoteserver/NotifyTaskStateCommand.java +23 -0
  25. data/src/main/java/org/embulk/executor/remoteserver/PluginArchive.java +170 -0
  26. data/src/main/java/org/embulk/executor/remoteserver/RemoteServerExecutor.java +131 -0
  27. data/src/main/java/org/embulk/executor/remoteserver/RemoveSessionCommand.java +24 -0
  28. data/src/main/java/org/embulk/executor/remoteserver/Session.java +177 -0
  29. data/src/main/java/org/embulk/executor/remoteserver/SessionManager.java +37 -0
  30. data/src/main/java/org/embulk/executor/remoteserver/SessionState.java +143 -0
  31. data/src/main/java/org/embulk/executor/remoteserver/StartTaskCommand.java +51 -0
  32. data/src/main/java/org/embulk/executor/remoteserver/TaskExecutionException.java +11 -0
  33. data/src/main/java/org/embulk/executor/remoteserver/TaskState.java +5 -0
  34. data/src/main/java/org/embulk/executor/remoteserver/UpdateTaskStateData.java +55 -0
  35. data/src/main/resources/logback.xml +11 -0
  36. data/src/test/java/org/embulk/executor/remoteserver/TestRemoteServerExecutor.java +80 -0
  37. data/src/test/resources/json/test1.json +1 -0
  38. data/src/test/resources/json/test2.json +1 -0
  39. data/test/Gemfile +4 -0
  40. data/test/Gemfile.lock +20 -0
  41. data/test/setup.sh +8 -0
  42. metadata +119 -0
@@ -0,0 +1,51 @@
1
+ package org.embulk.executor.remoteserver;
2
+
3
+ import com.fasterxml.jackson.annotation.JsonCreator;
4
+ import com.fasterxml.jackson.annotation.JsonProperty;
5
+ import com.github.kamatama41.nsocket.Command;
6
+ import com.github.kamatama41.nsocket.Connection;
7
+
8
+ class StartTaskCommand implements Command<StartTaskCommand.Data> {
9
+ static final String ID = "start_task";
10
+ private final SessionManager sessionManager;
11
+
12
+ StartTaskCommand(SessionManager sessionManager) {
13
+ this.sessionManager = sessionManager;
14
+ }
15
+
16
+ @Override
17
+ public void execute(Data data, Connection connection) {
18
+ Session session = sessionManager.getSession(data.getSessionId());
19
+ if (session == null) {
20
+ throw new IllegalStateException("Session is not created.");
21
+ }
22
+ session.runTaskAsynchronously(data.getTaskIndex());
23
+ }
24
+
25
+ @Override
26
+ public String getId() {
27
+ return ID;
28
+ }
29
+
30
+ static class Data {
31
+ private String sessionId;
32
+ private int taskIndex;
33
+
34
+ @JsonCreator
35
+ Data(@JsonProperty("sessionId") String sessionId,
36
+ @JsonProperty("taskIndex") int taskIndex) {
37
+ this.sessionId = sessionId;
38
+ this.taskIndex = taskIndex;
39
+ }
40
+
41
+ @JsonProperty
42
+ String getSessionId() {
43
+ return sessionId;
44
+ }
45
+
46
+ @JsonProperty
47
+ int getTaskIndex() {
48
+ return taskIndex;
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,11 @@
1
+ package org.embulk.executor.remoteserver;
2
+
3
+ class TaskExecutionException extends RuntimeException {
4
+ TaskExecutionException(String message) {
5
+ super(message);
6
+ }
7
+
8
+ TaskExecutionException(Throwable cause) {
9
+ super(cause);
10
+ }
11
+ }
@@ -0,0 +1,5 @@
1
+ package org.embulk.executor.remoteserver;
2
+
3
+ public enum TaskState {
4
+ STARTED, INPUT_COMMITTED, OUTPUT_COMMITTED, FINISHED, FAILED
5
+ }
@@ -0,0 +1,55 @@
1
+ package org.embulk.executor.remoteserver;
2
+
3
+ import com.fasterxml.jackson.annotation.JsonCreator;
4
+ import com.fasterxml.jackson.annotation.JsonProperty;
5
+
6
+ class UpdateTaskStateData {
7
+ private String sessionId;
8
+ private int taskIndex;
9
+ private TaskState taskState;
10
+ private String taskReport;
11
+ private String errorMessage;
12
+
13
+ @JsonCreator
14
+ UpdateTaskStateData(
15
+ @JsonProperty("sessionId") String sessionId,
16
+ @JsonProperty("taskIndex") int taskIndex,
17
+ @JsonProperty("taskState") TaskState taskState) {
18
+ this.sessionId = sessionId;
19
+ this.taskIndex = taskIndex;
20
+ this.taskState = taskState;
21
+ }
22
+
23
+ @JsonProperty
24
+ String getSessionId() {
25
+ return sessionId;
26
+ }
27
+
28
+ @JsonProperty
29
+ int getTaskIndex() {
30
+ return taskIndex;
31
+ }
32
+
33
+ @JsonProperty
34
+ TaskState getTaskState() {
35
+ return taskState;
36
+ }
37
+
38
+ @JsonProperty
39
+ String getTaskReport() {
40
+ return taskReport;
41
+ }
42
+
43
+ void setTaskReport(String taskReport) {
44
+ this.taskReport = taskReport;
45
+ }
46
+
47
+ @JsonProperty
48
+ String getErrorMessage() {
49
+ return errorMessage;
50
+ }
51
+
52
+ void setErrorMessage(String errorMessage) {
53
+ this.errorMessage = errorMessage;
54
+ }
55
+ }
@@ -0,0 +1,11 @@
1
+ <configuration>
2
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3
+ <encoder>
4
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
5
+ </encoder>
6
+ </appender>
7
+
8
+ <root level="debug">
9
+ <appender-ref ref="STDOUT"/>
10
+ </root>
11
+ </configuration>
@@ -0,0 +1,80 @@
1
+ package org.embulk.executor.remoteserver;
2
+
3
+ import org.embulk.config.ConfigSource;
4
+ import org.embulk.test.EmbulkPluginTest;
5
+ import org.embulk.test.EmbulkTest;
6
+ import org.junit.jupiter.api.Test;
7
+
8
+ import java.io.File;
9
+ import java.io.IOException;
10
+ import java.io.UncheckedIOException;
11
+ import java.nio.file.Files;
12
+ import java.nio.file.Path;
13
+ import java.nio.file.Paths;
14
+ import java.util.Arrays;
15
+ import java.util.Collections;
16
+ import java.util.HashSet;
17
+ import java.util.List;
18
+ import java.util.Set;
19
+ import java.util.stream.Collectors;
20
+
21
+ import static org.junit.jupiter.api.Assertions.assertEquals;
22
+
23
+ @EmbulkTest(value = RemoteServerExecutor.class, name = "remoteserver")
24
+ class TestRemoteServerExecutor extends EmbulkPluginTest {
25
+ private static final List<Host> HOSTS = Arrays.asList(new Host("localhost", 24224), new Host("localhost", 24225));
26
+ private static final Path OUTPUT_DIR = Paths.get("tmp", "output");
27
+ private static final Path TEST_DIR = Paths.get("test");
28
+
29
+ @Test
30
+ void testSimpleCase() {
31
+ setSystemConfig(config().set("jruby_global_bundler_plugin_source_directory", TEST_DIR.toFile().getAbsolutePath()));
32
+
33
+ ConfigSource inConfig = config().set("type", "file")
34
+ .set("path_prefix", "src/test/resources/json/test")
35
+ .set("parser", config().set("type", "json")
36
+ .set("columns", Collections.singletonList(config()
37
+ .set("name", "a").set("type", "long")
38
+ ))
39
+ );
40
+
41
+ ConfigSource execConfig = config().set("type", "remoteserver")
42
+ .set("hosts", HOSTS)
43
+ .set("timeout_seconds", 5);
44
+
45
+ ConfigSource filterConfig = config().set("type", "hash")
46
+ .set("columns", Collections.singletonList(config()
47
+ .set("name", "a").set("algorithm", "MD5")
48
+ ));
49
+
50
+ ConfigSource outConfig = config().set("type", "file")
51
+ .set("path_prefix", "/output/out_file_")
52
+ .set("file_ext", "json")
53
+ .set("formatter", config()
54
+ .set("type", "csv")
55
+ .set("header_line", false)
56
+ .set("quote_policy", "NONE")
57
+ );
58
+
59
+ runConfig(inConfig)
60
+ .execConfig(execConfig)
61
+ .filterConfig(filterConfig)
62
+ .outConfig(outConfig).run();
63
+
64
+ File[] files = OUTPUT_DIR.toFile().listFiles();
65
+ assertEquals(2, files.length);
66
+ Set<String> outputs = Arrays.stream(files).map(f -> {
67
+ try {
68
+ return String.join("", Files.readAllLines(f.toPath()));
69
+ } catch (IOException e) {
70
+ throw new UncheckedIOException(e);
71
+ }
72
+ }).collect(Collectors.toSet());
73
+
74
+ Set<String> expected = new HashSet<String>(){{
75
+ add("c4ca4238a0b923820dcc509a6f75849b"); // "1" of MD5
76
+ add("c81e728d9d4c2f636f067f89cc14862c"); // "2" of MD5
77
+ }};
78
+ assertEquals(expected, outputs);
79
+ }
80
+ }
@@ -0,0 +1 @@
1
+ {"a": 1}
@@ -0,0 +1 @@
1
+ {"a": 2}
data/test/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gem 'embulk'
4
+ gem 'embulk-filter-hash', '= 0.5.0'
data/test/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ embulk (0.9.16-java)
5
+ bundler (>= 1.10.6)
6
+ liquid (~> 4.0.0)
7
+ msgpack (~> 1.1.0)
8
+ embulk-filter-hash (0.5.0)
9
+ liquid (4.0.0)
10
+ msgpack (1.1.0-java)
11
+
12
+ PLATFORMS
13
+ java
14
+
15
+ DEPENDENCIES
16
+ embulk
17
+ embulk-filter-hash (= 0.5.0)
18
+
19
+ BUNDLED WITH
20
+ 1.16.0
data/test/setup.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ project_root="$(cd $(dirname $0)/..; pwd -P)"
4
+ cd ${project_root}
5
+
6
+ rm -rf tmp/output && mkdir -p tmp/output
7
+ ./gradlew embulk_bundle_--clean -Pgemfile=test/Gemfile -PbundlePath=${project_root}/tmp/vendor/bundle
8
+ docker-compose up -d --build
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-executor-remoteserver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shinichi Ishimura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-31 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: Embulk executor plugin to run plugins on remote server.
42
+ email:
43
+ - shiketaudonko41@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".circleci/config.yml"
49
+ - ".gitignore"
50
+ - Dockerfile
51
+ - LICENSE
52
+ - README.md
53
+ - build.gradle
54
+ - classpath/embulk-executor-remoteserver-0.1.0.jar
55
+ - classpath/msgpack-core-0.8.16.jar
56
+ - classpath/nsocket-0.2.10.jar
57
+ - classpath/slf4j-api-1.7.26.jar
58
+ - docker-compose.yml
59
+ - docker/run_embulk_server.sh
60
+ - gradle.properties
61
+ - gradle/dependency-locks/compileClasspath.lockfile
62
+ - gradle/dependency-locks/testCompileClasspath.lockfile
63
+ - gradle/wrapper/gradle-wrapper.jar
64
+ - gradle/wrapper/gradle-wrapper.properties
65
+ - gradlew
66
+ - gradlew.bat
67
+ - lib/embulk/executor/remoteserver.rb
68
+ - settings.gradle
69
+ - src/main/java/org/embulk/executor/remoteserver/EmbulkClient.java
70
+ - src/main/java/org/embulk/executor/remoteserver/EmbulkServer.java
71
+ - src/main/java/org/embulk/executor/remoteserver/Host.java
72
+ - src/main/java/org/embulk/executor/remoteserver/InitializeSessionCommand.java
73
+ - src/main/java/org/embulk/executor/remoteserver/Launcher.java
74
+ - src/main/java/org/embulk/executor/remoteserver/NotifyTaskStateCommand.java
75
+ - src/main/java/org/embulk/executor/remoteserver/PluginArchive.java
76
+ - src/main/java/org/embulk/executor/remoteserver/RemoteServerExecutor.java
77
+ - src/main/java/org/embulk/executor/remoteserver/RemoveSessionCommand.java
78
+ - src/main/java/org/embulk/executor/remoteserver/Session.java
79
+ - src/main/java/org/embulk/executor/remoteserver/SessionManager.java
80
+ - src/main/java/org/embulk/executor/remoteserver/SessionState.java
81
+ - src/main/java/org/embulk/executor/remoteserver/StartTaskCommand.java
82
+ - src/main/java/org/embulk/executor/remoteserver/TaskExecutionException.java
83
+ - src/main/java/org/embulk/executor/remoteserver/TaskState.java
84
+ - src/main/java/org/embulk/executor/remoteserver/UpdateTaskStateData.java
85
+ - src/main/resources/logback.xml
86
+ - src/test/java/org/embulk/executor/remoteserver/TestRemoteServerExecutor.java
87
+ - src/test/resources/json/test1.json
88
+ - src/test/resources/json/test2.json
89
+ - test/Gemfile
90
+ - test/Gemfile.lock
91
+ - test/setup.sh
92
+ homepage: https://github.com/kamatama41/embulk-executor-remoteserver
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Docker executor plugin for Embulk
116
+ test_files:
117
+ - test/Gemfile
118
+ - test/Gemfile.lock
119
+ - test/setup.sh