Search in sources :

Example 1 with ExecutionResult

use of org.embulk.exec.ExecutionResult in project embulk by embulk.

the class EmbulkEmbed method runResumable.

public ResumableResult runResumable(ConfigSource config) {
    this.logger.info("Started Embulk v" + EmbulkVersion.VERSION);
    ExecSession exec = newExecSession(config);
    try {
        ExecutionResult result;
        try {
            result = bulkLoader.run(exec, config);
        } catch (PartialExecutionException partial) {
            return new ResumableResult(partial);
        }
        return new ResumableResult(result);
    } finally {
        try {
            exec.cleanup();
        } catch (Exception ex) {
            // TODO add this exception to ExecutionResult.getIgnoredExceptions
            // or partial.addSuppressed
            ex.printStackTrace(System.err);
        }
    }
}
Also used : PartialExecutionException(org.embulk.exec.PartialExecutionException) ExecutionResult(org.embulk.exec.ExecutionResult) ExecSession(org.embulk.spi.ExecSession) PartialExecutionException(org.embulk.exec.PartialExecutionException)

Example 2 with ExecutionResult

use of org.embulk.exec.ExecutionResult in project embulk by embulk.

the class EmbulkRunner method runInternal.

private void runInternal(final ConfigSource originalConfigSource, final Path configDiffPath, // deprecated
final Path outputPath, final Path resumeStatePath) throws IOException {
    try {
        checkFileWritable(outputPath);
    } catch (IOException ex) {
        throw new RuntimeException("Not writable: " + outputPath.toString());
    }
    try {
        checkFileWritable(configDiffPath);
    } catch (IOException ex) {
        throw new RuntimeException("Not writable: " + configDiffPath.toString());
    }
    try {
        checkFileWritable(resumeStatePath);
    } catch (IOException ex) {
        throw new RuntimeException("Not writable: " + resumeStatePath.toString());
    }
    final ConfigSource configSource;
    if (configDiffPath != null && Files.size(configDiffPath) > 0L) {
        configSource = originalConfigSource.merge(readConfig(configDiffPath, Collections.<String, Object>emptyMap(), null));
    } else {
        configSource = originalConfigSource;
    }
    final ConfigSource resumeConfig;
    if (resumeStatePath != null) {
        ConfigSource resumeConfigTemp = null;
        try {
            resumeConfigTemp = readYamlConfigFile(resumeStatePath);
        } catch (Throwable ex) {
            // TODO log?
            resumeConfigTemp = null;
        }
        if (resumeConfigTemp == null || resumeConfigTemp.isEmpty()) {
            resumeConfig = null;
        } else {
            resumeConfig = resumeConfigTemp;
        }
    } else {
        resumeConfig = null;
    }
    final EmbulkEmbed.ResumableResult resumableResult;
    final ExecutionResult executionResultTemp;
    if (resumeConfig != null) {
        resumableResult = this.embed.resumeState(configSource, resumeConfig).resume();
        executionResultTemp = null;
    } else if (resumeStatePath != null) {
        resumableResult = this.embed.runResumable(configSource);
        executionResultTemp = null;
    } else {
        resumableResult = null;
        executionResultTemp = this.embed.run(configSource);
    }
    final ExecutionResult executionResult;
    if (executionResultTemp == null) {
        if (!resumableResult.isSuccessful()) {
            if (resumableResult.getTransactionStage().isBefore(TransactionStage.RUN)) {
                // delete resume file
                if (resumeStatePath != null) {
                    try {
                        Files.deleteIfExists(resumeStatePath);
                    } catch (Throwable ex) {
                        System.err.println("Failed to delete: " + resumeStatePath.toString());
                    }
                }
            } else {
                rootLogger.info("Writing resume state to '" + resumeStatePath.toString() + "'");
                try {
                    writeResumeState(resumeStatePath, resumableResult.getResumeState());
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
                rootLogger.info("Resume state is written. Run the transaction again with -r option to resume or use \"cleanup\" subcommand to delete intermediate data.");
            }
            throw new RuntimeException(resumableResult.getCause());
        }
        executionResult = resumableResult.getSuccessfulResult();
    } else {
        executionResult = executionResultTemp;
    }
    // delete resume file
    if (resumeStatePath != null) {
        try {
            Files.deleteIfExists(resumeStatePath);
        } catch (Throwable ex) {
            System.err.println("Failed to delete: " + resumeStatePath.toString());
        }
    }
    final ConfigDiff configDiff = executionResult.getConfigDiff();
    rootLogger.info("Committed.");
    rootLogger.info("Next config diff: " + configDiff.toString());
    writeConfig(configDiffPath, configDiff);
    // deprecated
    writeConfig(outputPath, configSource.merge(configDiff));
}
Also used : ConfigSource(org.embulk.config.ConfigSource) ExecutionResult(org.embulk.exec.ExecutionResult) IOException(java.io.IOException) ConfigDiff(org.embulk.config.ConfigDiff)

Aggregations

ExecutionResult (org.embulk.exec.ExecutionResult)2 IOException (java.io.IOException)1 ConfigDiff (org.embulk.config.ConfigDiff)1 ConfigSource (org.embulk.config.ConfigSource)1 PartialExecutionException (org.embulk.exec.PartialExecutionException)1 ExecSession (org.embulk.spi.ExecSession)1