embulk-output-multi 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/classpath/embulk-output-multi-0.2.1.jar +0 -0
- data/gradle.properties +1 -1
- data/src/main/java/org/embulk/output/multi/{RunControlTask.java → AsyncRunControl.java} +24 -14
- data/src/main/java/org/embulk/output/multi/MultiOutputPlugin.java +4 -4
- data/src/main/java/org/embulk/output/multi/OutputPluginDelegate.java +38 -6
- data/src/main/java/org/embulk/output/multi/TransactionalPageOutputDelegate.java +1 -2
- metadata +3 -4
- data/classpath/embulk-output-multi-0.2.0.jar +0 -0
- data/src/main/java/org/embulk/output/multi/ControlDelegate.java +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40d2c979fbce0853ed920cae18f0f867284e9491
|
4
|
+
data.tar.gz: e02bef302e6b8061f9029dc4d7077a00b7563623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba665f2f4108d65c1cf48ad5a94789e6d719443bb0e8bc7f579f05357407918ab275b41cd55aa96af0ae0854e572427f55039a8502e332c8ab22d6707d6118f9
|
7
|
+
data.tar.gz: 7fa76fd0c1a8c06e89b2b0eff90e6b16e00985db269444a37812da6af0f40e3a74a748b00c7e3dfc675b35f7c60875e5f57efd87bf6963eacf57f05cc04a9e79
|
data/README.md
CHANGED
@@ -18,7 +18,6 @@ This plugin can copies an output to multiple destinations.
|
|
18
18
|
## Configuration
|
19
19
|
|
20
20
|
- **outputs**: Configuration of output plugins (array, required)
|
21
|
-
- **stop_on_failed_output**: Set true if you want to immediately stop outputting of all plugins with a plugin's error (boolean, default "false")
|
22
21
|
|
23
22
|
## Example
|
24
23
|
|
Binary file
|
data/gradle.properties
CHANGED
@@ -1 +1 @@
|
|
1
|
-
version=0.2.
|
1
|
+
version=0.2.1
|
@@ -15,7 +15,7 @@ import java.util.concurrent.Executors;
|
|
15
15
|
import java.util.concurrent.Future;
|
16
16
|
import java.util.concurrent.atomic.AtomicReferenceArray;
|
17
17
|
|
18
|
-
class
|
18
|
+
class AsyncRunControl {
|
19
19
|
private static final String THREAD_NAME_FORMAT = "multi-run-control-%d";
|
20
20
|
private final MultiOutputPlugin.PluginTask task;
|
21
21
|
private final OutputPlugin.Control control;
|
@@ -24,7 +24,11 @@ class RunControlTask implements Callable<List<TaskReport>> {
|
|
24
24
|
private final ExecutorService executorService;
|
25
25
|
private Future<List<TaskReport>> result;
|
26
26
|
|
27
|
-
|
27
|
+
static AsyncRunControl start(MultiOutputPlugin.PluginTask task, OutputPlugin.Control control) {
|
28
|
+
return new AsyncRunControl(task, control).start();
|
29
|
+
}
|
30
|
+
|
31
|
+
private AsyncRunControl(MultiOutputPlugin.PluginTask task, OutputPlugin.Control control) {
|
28
32
|
this.task = task;
|
29
33
|
this.control = control;
|
30
34
|
this.latch = new CountDownLatch(task.getOutputConfigs().size());
|
@@ -32,18 +36,6 @@ class RunControlTask implements Callable<List<TaskReport>> {
|
|
32
36
|
this.executorService = Executors.newSingleThreadExecutor(
|
33
37
|
new ThreadFactoryBuilder().setNameFormat(THREAD_NAME_FORMAT).build()
|
34
38
|
);
|
35
|
-
this.result = executorService.submit(this);
|
36
|
-
}
|
37
|
-
|
38
|
-
@Override
|
39
|
-
public List<TaskReport> call() throws Exception {
|
40
|
-
latch.await();
|
41
|
-
List<TaskSource> taskSources = new ArrayList<>(this.taskSources.length());
|
42
|
-
for (int i = 0; i < this.taskSources.length(); i++) {
|
43
|
-
taskSources.add(this.taskSources.get(i));
|
44
|
-
}
|
45
|
-
task.setTaskSources(taskSources);
|
46
|
-
return control.run(task.dump());
|
47
39
|
}
|
48
40
|
|
49
41
|
void cancel() {
|
@@ -62,4 +54,22 @@ class RunControlTask implements Callable<List<TaskReport>> {
|
|
62
54
|
executorService.shutdown();
|
63
55
|
}
|
64
56
|
}
|
57
|
+
|
58
|
+
private AsyncRunControl start() {
|
59
|
+
this.result = executorService.submit(new RunControl());
|
60
|
+
return this;
|
61
|
+
}
|
62
|
+
|
63
|
+
private class RunControl implements Callable<List<TaskReport>> {
|
64
|
+
@Override
|
65
|
+
public List<TaskReport> call() throws Exception {
|
66
|
+
latch.await();
|
67
|
+
List<TaskSource> taskSources = new ArrayList<>(AsyncRunControl.this.taskSources.length());
|
68
|
+
for (int i = 0; i < AsyncRunControl.this.taskSources.length(); i++) {
|
69
|
+
taskSources.add(AsyncRunControl.this.taskSources.get(i));
|
70
|
+
}
|
71
|
+
task.setTaskSources(taskSources);
|
72
|
+
return control.run(task.dump());
|
73
|
+
}
|
74
|
+
}
|
65
75
|
}
|
@@ -48,9 +48,9 @@ public class MultiOutputPlugin implements OutputPlugin {
|
|
48
48
|
throw new ConfigException("'outputs' must have more than than or equals to 1 element.");
|
49
49
|
}
|
50
50
|
final ExecSession session = Exec.session();
|
51
|
-
final
|
51
|
+
final AsyncRunControl runControl = AsyncRunControl.start(task, control);
|
52
52
|
return buildConfigDiff(mapWithPluginDelegate(task, session, delegate ->
|
53
|
-
delegate.transaction(schema, taskCount,
|
53
|
+
delegate.transaction(schema, taskCount, runControl)
|
54
54
|
));
|
55
55
|
}
|
56
56
|
|
@@ -58,9 +58,9 @@ public class MultiOutputPlugin implements OutputPlugin {
|
|
58
58
|
public ConfigDiff resume(TaskSource taskSource, Schema schema, int taskCount, OutputPlugin.Control control) {
|
59
59
|
final PluginTask task = taskSource.loadTask(PluginTask.class);
|
60
60
|
final ExecSession session = Exec.session();
|
61
|
-
final
|
61
|
+
final AsyncRunControl runControl = AsyncRunControl.start(task, control);
|
62
62
|
return buildConfigDiff(mapWithPluginDelegate(task, session, delegate ->
|
63
|
-
delegate.resume(schema, taskCount,
|
63
|
+
delegate.resume(schema, taskCount, runControl)
|
64
64
|
));
|
65
65
|
}
|
66
66
|
|
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
|
15
15
|
import java.util.ArrayList;
|
16
16
|
import java.util.List;
|
17
17
|
import java.util.concurrent.CancellationException;
|
18
|
+
import java.util.concurrent.ExecutionException;
|
18
19
|
import java.util.concurrent.ExecutorService;
|
19
20
|
import java.util.concurrent.Executors;
|
20
21
|
import java.util.concurrent.Future;
|
@@ -46,17 +47,17 @@ class OutputPluginDelegate {
|
|
46
47
|
);
|
47
48
|
}
|
48
49
|
|
49
|
-
Future<ConfigDiff> transaction(Schema schema, int taskCount,
|
50
|
+
Future<ConfigDiff> transaction(Schema schema, int taskCount, AsyncRunControl runControl) {
|
50
51
|
return executorService.submit(() -> {
|
51
52
|
try {
|
52
53
|
LOGGER.debug("Run #transaction for {}", getPluginCode());
|
53
|
-
return plugin.transaction(config, schema, taskCount, new
|
54
|
+
return plugin.transaction(config, schema, taskCount, new Control(pluginIndex, runControl));
|
54
55
|
} catch (CancellationException e) {
|
55
56
|
LOGGER.error("Canceled #transaction for {} by other plugin's error", getPluginCode());
|
56
57
|
throw e;
|
57
58
|
} catch (Exception e) {
|
58
59
|
LOGGER.error("Transaction for {} failed.", getPluginCode(), e);
|
59
|
-
|
60
|
+
runControl.cancel();
|
60
61
|
throw e;
|
61
62
|
} finally {
|
62
63
|
executorService.shutdown();
|
@@ -64,17 +65,17 @@ class OutputPluginDelegate {
|
|
64
65
|
});
|
65
66
|
}
|
66
67
|
|
67
|
-
Future<ConfigDiff> resume(Schema schema, int taskCount,
|
68
|
+
Future<ConfigDiff> resume(Schema schema, int taskCount, AsyncRunControl runControl) {
|
68
69
|
return executorService.submit(() -> {
|
69
70
|
try {
|
70
71
|
LOGGER.debug("Run #resume for {}", getPluginCode());
|
71
|
-
return plugin.resume(taskSource, schema, taskCount, new
|
72
|
+
return plugin.resume(taskSource, schema, taskCount, new Control(pluginIndex, runControl));
|
72
73
|
} catch (CancellationException e) {
|
73
74
|
LOGGER.error("Canceled #resume for {} by other plugin's error", getPluginCode());
|
74
75
|
throw e;
|
75
76
|
} catch (Exception e) {
|
76
77
|
LOGGER.error("Resume for {} failed.", getPluginCode(), e);
|
77
|
-
|
78
|
+
runControl.cancel();
|
78
79
|
throw e;
|
79
80
|
} finally {
|
80
81
|
executorService.shutdown();
|
@@ -108,4 +109,35 @@ class OutputPluginDelegate {
|
|
108
109
|
private static String generatePluginCode(PluginType type, int pluginIndex) {
|
109
110
|
return String.format("%s-%d", type.getName(), pluginIndex);
|
110
111
|
}
|
112
|
+
|
113
|
+
private static class Control implements OutputPlugin.Control {
|
114
|
+
private final int pluginIndex;
|
115
|
+
private final AsyncRunControl runControl;
|
116
|
+
|
117
|
+
Control(int index, AsyncRunControl runControl) {
|
118
|
+
this.pluginIndex = index;
|
119
|
+
this.runControl = runControl;
|
120
|
+
}
|
121
|
+
|
122
|
+
@Override
|
123
|
+
public List<TaskReport> run(TaskSource taskSource) {
|
124
|
+
runControl.addTaskSource(pluginIndex, taskSource);
|
125
|
+
List<TaskReport> reports;
|
126
|
+
try {
|
127
|
+
reports = runControl.waitAndGetResult();
|
128
|
+
} catch (InterruptedException e) {
|
129
|
+
Thread.currentThread().interrupt();
|
130
|
+
throw new RuntimeException(e);
|
131
|
+
} catch (ExecutionException e) {
|
132
|
+
throw new RuntimeException(e.getCause());
|
133
|
+
}
|
134
|
+
|
135
|
+
final List<TaskReport> result = new ArrayList<>();
|
136
|
+
for (TaskReport taskReport : reports) {
|
137
|
+
final TaskReport report = taskReport.get(TaskReports.class, MultiOutputPlugin.CONFIG_NAME_OUTPUT_TASK_REPORTS).get(pluginIndex);
|
138
|
+
result.add(report);
|
139
|
+
}
|
140
|
+
return result;
|
141
|
+
}
|
142
|
+
}
|
111
143
|
}
|
@@ -82,8 +82,7 @@ class TransactionalPageOutputDelegate {
|
|
82
82
|
@Override
|
83
83
|
public TaskReport call() throws InterruptedException {
|
84
84
|
while (true) {
|
85
|
-
final
|
86
|
-
final Object result = task.get();
|
85
|
+
final Object result = taskQueue.take().get();
|
87
86
|
if (result instanceof TaskReport) {
|
88
87
|
return (TaskReport) result;
|
89
88
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-multi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinichi ISHIMURA
|
@@ -50,7 +50,7 @@ files:
|
|
50
50
|
- LICENSE
|
51
51
|
- README.md
|
52
52
|
- build.gradle
|
53
|
-
- classpath/embulk-output-multi-0.2.
|
53
|
+
- classpath/embulk-output-multi-0.2.1.jar
|
54
54
|
- gradle.properties
|
55
55
|
- gradle/dependency-locks/compileClasspath.lockfile
|
56
56
|
- gradle/dependency-locks/testCompileClasspath.lockfile
|
@@ -60,11 +60,10 @@ files:
|
|
60
60
|
- gradlew.bat
|
61
61
|
- lib/embulk/output/multi.rb
|
62
62
|
- settings.gradle
|
63
|
-
- src/main/java/org/embulk/output/multi/
|
63
|
+
- src/main/java/org/embulk/output/multi/AsyncRunControl.java
|
64
64
|
- src/main/java/org/embulk/output/multi/MultiOutputPlugin.java
|
65
65
|
- src/main/java/org/embulk/output/multi/OutputPluginDelegate.java
|
66
66
|
- src/main/java/org/embulk/output/multi/PluginExecutionException.java
|
67
|
-
- src/main/java/org/embulk/output/multi/RunControlTask.java
|
68
67
|
- src/main/java/org/embulk/output/multi/TaskReports.java
|
69
68
|
- src/main/java/org/embulk/output/multi/TransactionalPageOutputDelegate.java
|
70
69
|
- src/test/java/org/embulk/output/multi/TestMultiOutputPlugin.java
|
Binary file
|
@@ -1,40 +0,0 @@
|
|
1
|
-
package org.embulk.output.multi;
|
2
|
-
|
3
|
-
import org.embulk.config.TaskReport;
|
4
|
-
import org.embulk.config.TaskSource;
|
5
|
-
import org.embulk.spi.OutputPlugin;
|
6
|
-
|
7
|
-
import java.util.ArrayList;
|
8
|
-
import java.util.List;
|
9
|
-
import java.util.concurrent.ExecutionException;
|
10
|
-
|
11
|
-
class ControlDelegate implements OutputPlugin.Control {
|
12
|
-
private final int pluginIndex;
|
13
|
-
private final RunControlTask controlTask;
|
14
|
-
|
15
|
-
ControlDelegate(int index, RunControlTask controlTask) {
|
16
|
-
this.pluginIndex = index;
|
17
|
-
this.controlTask = controlTask;
|
18
|
-
}
|
19
|
-
|
20
|
-
@Override
|
21
|
-
public List<TaskReport> run(TaskSource taskSource) {
|
22
|
-
controlTask.addTaskSource(pluginIndex, taskSource);
|
23
|
-
List<TaskReport> reports;
|
24
|
-
try {
|
25
|
-
reports = controlTask.waitAndGetResult();
|
26
|
-
} catch (InterruptedException e) {
|
27
|
-
Thread.currentThread().interrupt();
|
28
|
-
throw new RuntimeException(e);
|
29
|
-
} catch (ExecutionException e) {
|
30
|
-
throw new RuntimeException(e.getCause());
|
31
|
-
}
|
32
|
-
|
33
|
-
final List<TaskReport> result = new ArrayList<>();
|
34
|
-
for (TaskReport taskReport : reports) {
|
35
|
-
final TaskReport report = taskReport.get(TaskReports.class, MultiOutputPlugin.CONFIG_NAME_OUTPUT_TASK_REPORTS).get(pluginIndex);
|
36
|
-
result.add(report);
|
37
|
-
}
|
38
|
-
return result;
|
39
|
-
}
|
40
|
-
}
|