embulk 0.6.27 → 0.7.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 +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +6 -1
- data/README.md +4 -4
- data/bin/embulk +39 -17
- data/build.gradle +23 -8
- data/embulk-cli/src/main/java/org/embulk/cli/Main.java +11 -2
- data/embulk-core/build.gradle +9 -4
- data/embulk-core/src/main/java/org/embulk/EmbulkEmbed.java +160 -61
- data/embulk-core/src/main/java/org/embulk/EmbulkService.java +1 -0
- data/embulk-core/src/main/java/org/embulk/command/TablePreviewPrinter.java +0 -1
- data/embulk-core/src/main/java/org/embulk/config/CommitReport.java +5 -1
- data/embulk-core/src/main/java/org/embulk/config/ConfigLoader.java +28 -7
- data/embulk-core/src/main/java/org/embulk/config/DataSourceImpl.java +1 -4
- data/embulk-core/src/main/java/org/embulk/config/DataSourceSerDe.java +6 -3
- data/embulk-core/src/main/java/org/embulk/config/ModelManager.java +0 -2
- data/embulk-core/src/main/java/org/embulk/config/TaskReport.java +29 -0
- data/embulk-core/src/main/java/org/embulk/exec/BulkLoader.java +42 -45
- data/embulk-core/src/main/java/org/embulk/exec/ExecModule.java +0 -1
- data/embulk-core/src/main/java/org/embulk/exec/GuessExecutor.java +4 -7
- data/embulk-core/src/main/java/org/embulk/exec/LocalExecutorPlugin.java +5 -6
- data/embulk-core/src/main/java/org/embulk/exec/LoggerProvider.java +0 -1
- data/embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java +0 -3
- data/embulk-core/src/main/java/org/embulk/exec/PreviewExecutor.java +2 -2
- data/embulk-core/src/main/java/org/embulk/exec/ResumeState.java +26 -9
- data/embulk-core/src/main/java/org/embulk/exec/SamplingParserPlugin.java +2 -4
- data/embulk-core/src/main/java/org/embulk/guice/Bootstrap.java +12 -5
- data/embulk-core/src/main/java/org/embulk/guice/CloseableInjector.java +1 -1
- data/embulk-core/src/main/java/org/embulk/guice/LifeCycleInjector.java +26 -0
- data/embulk-core/src/main/java/org/embulk/guice/{CloseableInjectorProxy.java → LifeCycleInjectorProxy.java} +20 -6
- data/embulk-core/src/main/java/org/embulk/jruby/JRubyScriptingModule.java +10 -12
- data/embulk-core/src/main/java/org/embulk/plugin/PluginClassLoaderModule.java +0 -1
- data/embulk-core/src/main/java/org/embulk/plugin/PluginManager.java +14 -1
- data/embulk-core/src/main/java/org/embulk/plugin/compat/InputPluginWrapper.java +102 -0
- data/embulk-core/src/main/java/org/embulk/plugin/compat/PluginWrappers.java +30 -0
- data/embulk-core/src/main/java/org/embulk/plugin/compat/TransactionalFileInputWrapper.java +96 -0
- data/embulk-core/src/main/java/org/embulk/plugin/compat/TransactionalFileOutputWrapper.java +102 -0
- data/embulk-core/src/main/java/org/embulk/plugin/compat/TransactionalPageOutputWrapper.java +95 -0
- data/embulk-core/src/main/java/org/embulk/spi/ColumnConfig.java +0 -2
- data/embulk-core/src/main/java/org/embulk/spi/Exec.java +8 -2
- data/embulk-core/src/main/java/org/embulk/spi/ExecSession.java +7 -1
- data/embulk-core/src/main/java/org/embulk/spi/Extension.java +2 -2
- data/embulk-core/src/main/java/org/embulk/spi/FileInputPlugin.java +3 -3
- data/embulk-core/src/main/java/org/embulk/spi/FileInputRunner.java +12 -10
- data/embulk-core/src/main/java/org/embulk/spi/FileOutputPlugin.java +3 -3
- data/embulk-core/src/main/java/org/embulk/spi/FileOutputRunner.java +11 -9
- data/embulk-core/src/main/java/org/embulk/spi/FilterPlugin.java +0 -3
- data/embulk-core/src/main/java/org/embulk/spi/InputPlugin.java +4 -4
- data/embulk-core/src/main/java/org/embulk/spi/OutputPlugin.java +3 -3
- data/embulk-core/src/main/java/org/embulk/spi/PageReader.java +0 -1
- data/embulk-core/src/main/java/org/embulk/spi/ProcessTask.java +0 -5
- data/embulk-core/src/main/java/org/embulk/spi/SchemaConfig.java +0 -1
- data/embulk-core/src/main/java/org/embulk/spi/TaskState.java +19 -4
- data/embulk-core/src/main/java/org/embulk/spi/TempFileSpace.java +0 -3
- data/embulk-core/src/main/java/org/embulk/spi/Transactional.java +2 -2
- data/embulk-core/src/main/java/org/embulk/spi/TransactionalFileInput.java +2 -2
- data/embulk-core/src/main/java/org/embulk/spi/TransactionalFileOutput.java +2 -2
- data/embulk-core/src/main/java/org/embulk/spi/TransactionalPageOutput.java +2 -2
- data/embulk-core/src/main/java/org/embulk/spi/time/DateTimeZoneSerDe.java +0 -2
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampFormat.java +0 -3
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampFormatter.java +0 -1
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampParser.java +0 -1
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java +0 -1
- data/embulk-core/src/main/java/org/embulk/spi/type/TypeDeserializer.java +0 -3
- data/embulk-core/src/main/java/org/embulk/spi/unit/LocalFileSerDe.java +0 -3
- data/embulk-core/src/main/java/org/embulk/spi/unit/ToStringMap.java +0 -1
- data/embulk-core/src/main/java/org/embulk/spi/util/Executors.java +15 -12
- data/embulk-core/src/main/java/org/embulk/spi/util/Filters.java +0 -1
- data/embulk-core/src/test/java/org/embulk/spi/TestFileInputRunner.java +7 -7
- data/embulk-core/src/test/java/org/embulk/spi/TestFileOutputRunner.java +8 -8
- data/embulk-docs/src/built-in.rst +27 -30
- data/embulk-docs/src/conf.py +2 -2
- data/embulk-docs/src/release.rst +1 -2
- data/embulk-docs/src/release/release-0.7.0.rst +96 -0
- data/embulk-standards/src/main/java/org/embulk/standards/CsvFormatterPlugin.java +0 -4
- data/embulk-standards/src/main/java/org/embulk/standards/CsvParserPlugin.java +0 -10
- data/embulk-standards/src/main/java/org/embulk/standards/CsvTokenizer.java +1 -5
- data/embulk-standards/src/main/java/org/embulk/standards/LocalFileInputPlugin.java +4 -5
- data/embulk-standards/src/main/java/org/embulk/standards/LocalFileOutputPlugin.java +4 -5
- data/embulk-standards/src/main/java/org/embulk/standards/NullOutputPlugin.java +4 -4
- data/embulk-standards/src/main/java/org/embulk/standards/StandardPluginModule.java +0 -3
- data/embulk-standards/src/main/java/org/embulk/standards/StdoutOutputPlugin.java +4 -6
- data/embulk.gemspec +14 -1
- data/lib/embulk.rb +59 -4
- data/lib/embulk/command/embulk_bundle.rb +56 -0
- data/lib/embulk/command/embulk_main.rb +2 -0
- data/lib/embulk/command/embulk_migrate_plugin.rb +170 -0
- data/lib/embulk/command/embulk_new_plugin.rb +4 -1
- data/lib/embulk/command/embulk_run.rb +188 -227
- data/lib/embulk/data/bundle/.ruby-version +1 -0
- data/lib/embulk/data/bundle/Gemfile +4 -1
- data/lib/embulk/data/bundle/embulk/input/example.rb +4 -4
- data/lib/embulk/data/bundle/embulk/output/example.rb +4 -4
- data/lib/embulk/data/new/README.md.erb +1 -1
- data/lib/embulk/data/new/java/file_input.java.erb +4 -4
- data/lib/embulk/data/new/java/file_output.java.erb +2 -2
- data/lib/embulk/data/new/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/lib/embulk/data/new/java/gradle/wrapper/gradle-wrapper.properties +2 -2
- data/lib/embulk/data/new/java/input.java.erb +3 -3
- data/lib/embulk/data/new/java/output.java.erb +2 -2
- data/lib/embulk/data/new/ruby/.ruby-version +1 -0
- data/lib/embulk/data/new/ruby/gemspec.erb +1 -0
- data/lib/embulk/data/new/ruby/input.rb.erb +3 -3
- data/lib/embulk/data/new/ruby/output.rb.erb +4 -4
- data/lib/embulk/data/package_data.rb +1 -15
- data/lib/embulk/guess/charset.rb +10 -1
- data/lib/embulk/input_plugin.rb +12 -12
- data/lib/embulk/java/bootstrap.rb +7 -4
- data/lib/embulk/java/imports.rb +34 -2
- data/lib/embulk/logger.rb +2 -0
- data/lib/embulk/output_plugin.rb +12 -12
- data/lib/embulk/page_builder.rb +1 -1
- data/lib/embulk/plugin.rb +0 -1
- data/lib/embulk/runner.rb +184 -0
- data/lib/embulk/version.rb +1 -1
- metadata +76 -55
- data/embulk-core/src/main/java/org/embulk/command/LiquidTemplate.java +0 -8
- data/embulk-core/src/main/java/org/embulk/command/Runner.java +0 -369
- data/embulk-docs/src/release/release-0.6.26.rst +0 -17
- data/embulk-docs/src/release/release-0.6.27.rst +0 -11
- data/lib/embulk/command/embulk.rb +0 -47
- data/lib/embulk/data/bundle/Gemfile.lock +0 -8
- data/lib/embulk/exec.rb +0 -8
- data/lib/embulk/gems.rb +0 -29
- data/lib/embulk/java/liquid_helper.rb +0 -16
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
package org.embulk.command;
|
|
2
|
-
|
|
3
|
-
import java.util.List;
|
|
4
|
-
import java.util.ArrayList;
|
|
5
|
-
import java.util.Map;
|
|
6
|
-
import java.util.HashMap;
|
|
7
|
-
import java.io.File;
|
|
8
|
-
import java.io.IOException;
|
|
9
|
-
import java.io.FileOutputStream;
|
|
10
|
-
import java.io.BufferedWriter;
|
|
11
|
-
import java.io.OutputStreamWriter;
|
|
12
|
-
import java.io.Writer;
|
|
13
|
-
import java.io.ByteArrayInputStream;
|
|
14
|
-
import java.nio.charset.StandardCharsets;
|
|
15
|
-
import org.yaml.snakeyaml.Yaml;
|
|
16
|
-
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
17
|
-
import com.google.common.base.Function;
|
|
18
|
-
import com.google.common.collect.ImmutableMap;
|
|
19
|
-
import com.google.common.io.Files;
|
|
20
|
-
import com.google.inject.Injector;
|
|
21
|
-
import org.jruby.embed.ScriptingContainer;
|
|
22
|
-
import org.embulk.config.ConfigSource;
|
|
23
|
-
import org.embulk.config.DataSource;
|
|
24
|
-
import org.embulk.config.ConfigLoader;
|
|
25
|
-
import org.embulk.config.ConfigDiff;
|
|
26
|
-
import org.embulk.config.ModelManager;
|
|
27
|
-
import org.embulk.config.ConfigException;
|
|
28
|
-
import org.embulk.plugin.PluginType;
|
|
29
|
-
import org.embulk.exec.BulkLoader;
|
|
30
|
-
import org.embulk.exec.ExecutionResult;
|
|
31
|
-
import org.embulk.exec.GuessExecutor;
|
|
32
|
-
import org.embulk.exec.PreviewExecutor;
|
|
33
|
-
import org.embulk.exec.PreviewResult;
|
|
34
|
-
import org.embulk.exec.ResumeState;
|
|
35
|
-
import org.embulk.exec.PartialExecutionException;
|
|
36
|
-
import org.embulk.spi.time.Timestamp;
|
|
37
|
-
import org.embulk.spi.ExecSession;
|
|
38
|
-
import org.embulk.EmbulkEmbed;
|
|
39
|
-
|
|
40
|
-
public class Runner
|
|
41
|
-
{
|
|
42
|
-
private static class Options
|
|
43
|
-
{
|
|
44
|
-
private String nextConfigOutputPath;
|
|
45
|
-
public String getNextConfigOutputPath() { return nextConfigOutputPath; }
|
|
46
|
-
|
|
47
|
-
private String resumeStatePath;
|
|
48
|
-
public String getResumeStatePath() { return resumeStatePath; }
|
|
49
|
-
|
|
50
|
-
private String logLevel;
|
|
51
|
-
public String getLogLevel() { return logLevel; }
|
|
52
|
-
|
|
53
|
-
private String previewOutputFormat;
|
|
54
|
-
public String getPreviewOutputFormat() { return previewOutputFormat; };
|
|
55
|
-
|
|
56
|
-
private List<PluginType> guessPlugins;
|
|
57
|
-
public List<PluginType> getGuessPlugins() { return guessPlugins; }
|
|
58
|
-
|
|
59
|
-
private boolean useGlobalRubyRuntime;
|
|
60
|
-
public boolean getUseGlobalRubyRuntime() { return useGlobalRubyRuntime; }
|
|
61
|
-
|
|
62
|
-
private Map<String, String> systemProperty;
|
|
63
|
-
public Map<String, String> getSystemProperty() { return systemProperty; }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private final Options options;
|
|
67
|
-
private final ConfigSource systemConfig;
|
|
68
|
-
|
|
69
|
-
private EmbulkEmbed embed;
|
|
70
|
-
private Injector injector;
|
|
71
|
-
|
|
72
|
-
public Runner(String optionJson)
|
|
73
|
-
{
|
|
74
|
-
ModelManager bootstrapModelManager = new ModelManager(null, new ObjectMapper());
|
|
75
|
-
this.options = bootstrapModelManager.readObject(Options.class, optionJson);
|
|
76
|
-
|
|
77
|
-
ConfigLoader configLoader = new ConfigLoader(bootstrapModelManager);
|
|
78
|
-
ConfigSource systemConfig = configLoader.fromPropertiesYamlLiteral(System.getProperties(), "embulk.");
|
|
79
|
-
mergeOptionsToSystemConfig(options, configLoader, systemConfig);
|
|
80
|
-
|
|
81
|
-
this.systemConfig = systemConfig;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@SuppressWarnings("unchecked")
|
|
85
|
-
private static void mergeOptionsToSystemConfig(Options options, ConfigLoader configLoader, ConfigSource systemConfig)
|
|
86
|
-
{
|
|
87
|
-
systemConfig.merge(configLoader.fromPropertiesYamlLiteral(options.getSystemProperty(), ""));
|
|
88
|
-
|
|
89
|
-
String logLevel = options.getLogLevel();
|
|
90
|
-
if (logLevel != null) {
|
|
91
|
-
// used by LoggerProvider
|
|
92
|
-
systemConfig.set("log_level", logLevel);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
List<PluginType> guessPlugins = options.getGuessPlugins();
|
|
96
|
-
if (guessPlugins != null && !guessPlugins.isEmpty()) {
|
|
97
|
-
// used by GuessExecutor
|
|
98
|
-
List<PluginType> list = new ArrayList<PluginType>() { };
|
|
99
|
-
list = systemConfig.get((Class<List<PluginType>>) list.getClass(), "guess_plugins", list);
|
|
100
|
-
list.addAll(guessPlugins);
|
|
101
|
-
systemConfig.set("guess_plugins", list);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (options.getUseGlobalRubyRuntime()) {
|
|
105
|
-
// used by JRubyScriptingModule
|
|
106
|
-
systemConfig.set("use_global_ruby_runtime", true);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public void main(String command, String[] args)
|
|
111
|
-
{
|
|
112
|
-
try (EmbulkEmbed embed = new EmbulkEmbed(systemConfig)) {
|
|
113
|
-
this.injector = embed.getInjector();
|
|
114
|
-
|
|
115
|
-
switch (command) {
|
|
116
|
-
case "run":
|
|
117
|
-
run(args[0]);
|
|
118
|
-
break;
|
|
119
|
-
case "cleanup":
|
|
120
|
-
cleanup(args[0]);
|
|
121
|
-
break;
|
|
122
|
-
case "guess":
|
|
123
|
-
guess(args[0]);
|
|
124
|
-
break;
|
|
125
|
-
case "preview":
|
|
126
|
-
preview(args[0]);
|
|
127
|
-
break;
|
|
128
|
-
default:
|
|
129
|
-
throw new RuntimeException("Unsupported command: "+command);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public void run(String configPath)
|
|
135
|
-
{
|
|
136
|
-
ConfigSource config = loadConfig(configPath);
|
|
137
|
-
checkFileWritable(options.getNextConfigOutputPath());
|
|
138
|
-
checkFileWritable(options.getResumeStatePath());
|
|
139
|
-
|
|
140
|
-
// load resume state file
|
|
141
|
-
ResumeState resume = null;
|
|
142
|
-
String resumePath = options.getResumeStatePath();
|
|
143
|
-
if (resumePath != null) {
|
|
144
|
-
ConfigSource resumeConfig = null;
|
|
145
|
-
try {
|
|
146
|
-
resumeConfig = loadYamlConfig(resumePath);
|
|
147
|
-
if (resumeConfig.isEmpty()) {
|
|
148
|
-
resumeConfig = null;
|
|
149
|
-
}
|
|
150
|
-
} catch (RuntimeException ex) {
|
|
151
|
-
// leave resumeConfig == null
|
|
152
|
-
}
|
|
153
|
-
if (resumeConfig != null) {
|
|
154
|
-
resume = resumeConfig.loadConfig(ResumeState.class);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
ExecSession exec = newExecSession(config);
|
|
159
|
-
BulkLoader loader = injector.getInstance(BulkLoader.class);
|
|
160
|
-
ExecutionResult result;
|
|
161
|
-
try {
|
|
162
|
-
if (resume != null) {
|
|
163
|
-
// exec is not used here
|
|
164
|
-
result = loader.resume(config, resume);
|
|
165
|
-
} else {
|
|
166
|
-
result = loader.run(exec, config);
|
|
167
|
-
}
|
|
168
|
-
} catch (PartialExecutionException partial) {
|
|
169
|
-
if (options.getResumeStatePath() == null) {
|
|
170
|
-
// resume state path is not set. cleanup the transaction
|
|
171
|
-
exec.getLogger(Runner.class).info("Transaction partially failed. Cleaning up the intermediate data. Use -r option to make it resumable.");
|
|
172
|
-
try {
|
|
173
|
-
loader.cleanup(config, partial.getResumeState());
|
|
174
|
-
} catch (Throwable ex) {
|
|
175
|
-
partial.addSuppressed(ex);
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
exec.cleanup();
|
|
179
|
-
} catch (Throwable ex) {
|
|
180
|
-
partial.addSuppressed(ex);
|
|
181
|
-
}
|
|
182
|
-
throw partial;
|
|
183
|
-
}
|
|
184
|
-
// save the resume state
|
|
185
|
-
exec.getLogger(Runner.class).info("Writing resume state to '{}'", options.getResumeStatePath());
|
|
186
|
-
writeYaml(options.getResumeStatePath(), partial.getResumeState());
|
|
187
|
-
exec.getLogger(Runner.class).info("Resume state is written. Run the transaction again with -r option to resume or use \"cleanup\" subcommand to delete intermediate data.");
|
|
188
|
-
throw partial;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// delete resume file
|
|
192
|
-
if (options.getResumeStatePath() != null) {
|
|
193
|
-
boolean dontCare = new File(options.getResumeStatePath()).delete();
|
|
194
|
-
}
|
|
195
|
-
exec.cleanup();
|
|
196
|
-
|
|
197
|
-
// write next config
|
|
198
|
-
ConfigDiff configDiff = result.getConfigDiff();
|
|
199
|
-
exec.getLogger(Runner.class).info("Committed.");
|
|
200
|
-
exec.getLogger(Runner.class).info("Next config diff: {}", configDiff.toString());
|
|
201
|
-
writeNextConfig(options.getNextConfigOutputPath(), config, configDiff);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public void cleanup(String configPath)
|
|
205
|
-
{
|
|
206
|
-
String resumePath = options.getResumeStatePath();
|
|
207
|
-
if (resumePath == null) {
|
|
208
|
-
throw new IllegalArgumentException("Resume path is required for cleanup");
|
|
209
|
-
}
|
|
210
|
-
ConfigSource config = loadConfig(configPath);
|
|
211
|
-
ConfigSource resumeConfig = loadYamlConfig(resumePath);
|
|
212
|
-
ResumeState resume = resumeConfig.loadConfig(ResumeState.class);
|
|
213
|
-
|
|
214
|
-
BulkLoader loader = injector.getInstance(BulkLoader.class);
|
|
215
|
-
loader.cleanup(config, resume);
|
|
216
|
-
|
|
217
|
-
// delete resume file
|
|
218
|
-
boolean dontCare = new File(options.getResumeStatePath()).delete();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public void guess(String partialConfigPath)
|
|
222
|
-
{
|
|
223
|
-
ConfigSource config = loadConfig(partialConfigPath);
|
|
224
|
-
checkFileWritable(options.getNextConfigOutputPath());
|
|
225
|
-
|
|
226
|
-
ConfigDiff configDiff;
|
|
227
|
-
{
|
|
228
|
-
ExecSession exec = newExecSession(config);
|
|
229
|
-
try {
|
|
230
|
-
GuessExecutor guess = injector.getInstance(GuessExecutor.class);
|
|
231
|
-
configDiff = guess.guess(exec, config);
|
|
232
|
-
} finally {
|
|
233
|
-
exec.cleanup();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
String yml = writeNextConfig(options.getNextConfigOutputPath(), config, configDiff);
|
|
238
|
-
System.err.println(yml);
|
|
239
|
-
if (options.getNextConfigOutputPath() == null) {
|
|
240
|
-
System.out.println("Use -o PATH option to write the guessed config file to a file.");
|
|
241
|
-
} else {
|
|
242
|
-
System.out.println("Created '"+options.getNextConfigOutputPath()+"' file.");
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
private void checkFileWritable(String path)
|
|
247
|
-
{
|
|
248
|
-
if (path != null) {
|
|
249
|
-
try (FileOutputStream in = new FileOutputStream(path, true)) {
|
|
250
|
-
// open with append mode and do nothing. just check availability of the path to not cause exceptiosn later
|
|
251
|
-
} catch (IOException ex) {
|
|
252
|
-
throw new RuntimeException(ex);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private String writeNextConfig(String path, ConfigSource originalConfig, ConfigDiff configDiff)
|
|
258
|
-
{
|
|
259
|
-
return writeYaml(path, originalConfig.merge(configDiff));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
private String writeYaml(String path, Object obj)
|
|
263
|
-
{
|
|
264
|
-
String yml = dumpYaml(obj);
|
|
265
|
-
if (path != null) {
|
|
266
|
-
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"))) {
|
|
267
|
-
writer.write(yml);
|
|
268
|
-
} catch (IOException ex) {
|
|
269
|
-
throw new RuntimeException(ex);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return yml;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
public void preview(String partialConfigPath)
|
|
276
|
-
{
|
|
277
|
-
PreviewResult result;
|
|
278
|
-
{
|
|
279
|
-
ConfigSource config = loadConfig(partialConfigPath);
|
|
280
|
-
ExecSession exec = newExecSession(config);
|
|
281
|
-
try {
|
|
282
|
-
PreviewExecutor preview = injector.getInstance(PreviewExecutor.class);
|
|
283
|
-
result = preview.preview(exec, config);
|
|
284
|
-
} finally {
|
|
285
|
-
exec.cleanup();
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
ModelManager modelManager = injector.getInstance(ModelManager.class);
|
|
289
|
-
|
|
290
|
-
PreviewPrinter printer;
|
|
291
|
-
|
|
292
|
-
String format = options.getPreviewOutputFormat();
|
|
293
|
-
if (format == null) {
|
|
294
|
-
format = "table";
|
|
295
|
-
}
|
|
296
|
-
switch (format) {
|
|
297
|
-
case "table":
|
|
298
|
-
printer = new TablePreviewPrinter(System.out, modelManager, result.getSchema());
|
|
299
|
-
break;
|
|
300
|
-
case "vertical":
|
|
301
|
-
printer = new VerticalPreviewPrinter(System.out, modelManager, result.getSchema());
|
|
302
|
-
break;
|
|
303
|
-
default:
|
|
304
|
-
throw new IllegalArgumentException(String.format("Unknown preview output format '%s'. Supported formats: table, vertical", format));
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
try {
|
|
308
|
-
printer.printAllPages(result.getPages());
|
|
309
|
-
printer.finish();
|
|
310
|
-
} catch (IOException ex) {
|
|
311
|
-
throw new RuntimeException(ex);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
private ConfigSource loadConfig(String path)
|
|
316
|
-
{
|
|
317
|
-
if (path.endsWith(".yml") || path.endsWith(".yaml")) {
|
|
318
|
-
return loadYamlConfig(path);
|
|
319
|
-
}
|
|
320
|
-
else if (path.endsWith(".yml.liquid") || path.endsWith(".yaml.liquid")) {
|
|
321
|
-
return loadLiquidYamlConfig(path);
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
throw new ConfigException("Unknown file extension. Supported file extentions are .yml and .yml.liquid: "+path);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
private ConfigSource loadYamlConfig(String path)
|
|
329
|
-
{
|
|
330
|
-
try {
|
|
331
|
-
return injector.getInstance(ConfigLoader.class).fromYamlFile(new File(path));
|
|
332
|
-
}
|
|
333
|
-
catch (IOException ex) {
|
|
334
|
-
throw new ConfigException(ex);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
private ConfigSource loadLiquidYamlConfig(String path)
|
|
339
|
-
{
|
|
340
|
-
LiquidTemplate helper = (LiquidTemplate) injector.getInstance(ScriptingContainer.class).runScriptlet("Embulk::Java::LiquidTemplateHelper.new");
|
|
341
|
-
try {
|
|
342
|
-
String source = Files.toString(new File(path), StandardCharsets.UTF_8);
|
|
343
|
-
String data = helper.render(source, ImmutableMap.<String,String>of());
|
|
344
|
-
try (ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))) {
|
|
345
|
-
return injector.getInstance(ConfigLoader.class).fromYaml(in);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
catch (IOException ex) {
|
|
349
|
-
throw new ConfigException(ex);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
private String dumpYaml(Object config)
|
|
354
|
-
{
|
|
355
|
-
ModelManager model = injector.getInstance(ModelManager.class);
|
|
356
|
-
Map<String, Object> map = model.readObject(MapType.class, model.writeObject(config));
|
|
357
|
-
return new Yaml().dump(map);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
private ExecSession newExecSession(ConfigSource config)
|
|
361
|
-
{
|
|
362
|
-
ConfigSource execConfig = config.deepCopy().getNestedOrSetEmpty("exec");
|
|
363
|
-
return ExecSession.builder(injector).fromExecConfig(execConfig).build();
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
private static class MapType extends HashMap<String, Object> {
|
|
367
|
-
public MapType() { }
|
|
368
|
-
};
|
|
369
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Release 0.6.26
|
|
2
|
-
==================================
|
|
3
|
-
|
|
4
|
-
Built-in plugins
|
|
5
|
-
------------------
|
|
6
|
-
|
|
7
|
-
* Added ``stop_on_invalid_record`` option to ``parser-csv`` plugin. This option stops bulkloading if it finds a broken record such as invalid timestamp or invalid integer format rathar than skipping it.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Ruby Plugin API
|
|
11
|
-
------------------
|
|
12
|
-
|
|
13
|
-
* Added ``Embulk::Exec.preview?`` which returns true if plugins are running in preview.
|
|
14
|
-
|
|
15
|
-
Release Date
|
|
16
|
-
------------------
|
|
17
|
-
2015-08-20
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# reset context class loader set by org.jruby.Main.main to nil. embulk manages
|
|
2
|
-
# multiple classloaders. default classloader should be Plugin.class.getClassloader().
|
|
3
|
-
java.lang.Thread.current_thread.set_context_class_loader(nil)
|
|
4
|
-
|
|
5
|
-
bundle_path = ENV['EMBULK_BUNDLE_PATH'].to_s
|
|
6
|
-
bundle_path = nil if bundle_path.empty?
|
|
7
|
-
|
|
8
|
-
# search -b, --bundle BUNDLE_DIR
|
|
9
|
-
bundle_path_index = ARGV.find_index {|arg| arg == '-b' || arg == '--bundle' }
|
|
10
|
-
if bundle_path_index
|
|
11
|
-
bundle_path = ARGV.slice!(bundle_path_index, 2)[1]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
if bundle_path
|
|
15
|
-
# use bundler installed at bundle_path
|
|
16
|
-
ENV['GEM_HOME'] = File.expand_path File.join(bundle_path, Gem.ruby_engine, RbConfig::CONFIG['ruby_version'])
|
|
17
|
-
ENV['GEM_PATH'] = ''
|
|
18
|
-
Gem.clear_paths # force rubygems to reload GEM_HOME
|
|
19
|
-
|
|
20
|
-
ENV['BUNDLE_GEMFILE'] = File.expand_path File.join(bundle_path, "Gemfile")
|
|
21
|
-
begin
|
|
22
|
-
require 'bundler'
|
|
23
|
-
rescue LoadError => e
|
|
24
|
-
raise "#{e}\nBundler is not installed. Did you run \`$ embulk bundle #{bundle_path}\` ?"
|
|
25
|
-
end
|
|
26
|
-
Bundler.load.setup_environment
|
|
27
|
-
require 'bundler/setup'
|
|
28
|
-
# since here, `require` may load files of different (newer) embulk versions
|
|
29
|
-
# especially following 'embulk/command/embulk_run'.
|
|
30
|
-
|
|
31
|
-
$LOAD_PATH << File.expand_path(bundle_path) # for local plugins
|
|
32
|
-
|
|
33
|
-
begin
|
|
34
|
-
require 'embulk/command/embulk_run'
|
|
35
|
-
rescue LoadError
|
|
36
|
-
require_relative 'embulk_run'
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
else
|
|
40
|
-
# GEM_HOME is set by embulk_run.rb
|
|
41
|
-
ENV.delete('GEM_HOME')
|
|
42
|
-
ENV.delete('GEM_PATH')
|
|
43
|
-
ENV.delete('BUNDLE_GEMFILE')
|
|
44
|
-
require_relative 'embulk_run'
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
Embulk.run(ARGV)
|