Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/log4j2_client.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rootLogger.appenderRef.consoleStderr.ref = consoleStderrAppender

appender.consoleStdout.name = consoleStdoutAppender
appender.consoleStdout.type = CONSOLE
appender.consoleStdout.target = SYSTEM_OUT
appender.consoleStdout.target = ${sys:seatunnel.console.target:-SYSTEM_OUT}
appender.consoleStdout.layout.type = PatternLayout
appender.consoleStdout.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%-30.30c{1.}] [%t] - %m%n
appender.consoleStdout.filter.acceptLtWarn.type = ThresholdFilter
Expand Down Expand Up @@ -78,4 +78,4 @@ appender.consoleStderr.filter.acceptGteWarn.onMismatch = DENY
#appender.file.strategy.action.condition.nested_condition.lastModify.type = IfLastModified
#appender.file.strategy.action.condition.nested_condition.lastModify.age = ${file_ttl}
#appender.file.strategy.action.condition.nested_condition.fileCount.type = IfAccumulatedFileCount
#appender.file.strategy.action.condition.nested_condition.fileCount.exceeds = ${file_count}
#appender.file.strategy.action.condition.nested_condition.fileCount.exceeds = ${file_count}
11 changes: 11 additions & 0 deletions docs/en/engines/zeta/user-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Usage: seatunnel.sh [options]
-d, --dry-run Validate or preview without running sinks. Supported modes: [static, connect, sample].
-m, --master, -e, --deploy-mode SeaTunnel job submit master, support [local, cluster] (default: cluster).
--encrypt Encrypt the config file. When both --decrypt and --encrypt are specified, only --encrypt will take effect (default: false).
--format Validation output format. Supported values: [text, json] (default: text).
--get_running_job_metrics Get metrics for running jobs (default: false).
-h, --help Show the usage message.
-j, --job-id Get the job status by JobId.
Expand Down Expand Up @@ -81,6 +82,16 @@ sh bin/seatunnel.sh --config $SEATUNNEL_HOME/config/v2.batch.config.template --d

The `--dry-run static` (or `--check`) option validates the configuration file **without submitting a job** (for example HOCON/YAML syntax, plugin loadability, DAG topology, missing required options, and unknown connector keys). It does not run the full data pipeline. Plugin loading may read local JARs, so this is offline validation of the configuration file, not a strict zero-I/O sandbox.

For machine-readable validation, add `--format json` to `--check`, `--dry-run static`, or `--dry-run connect`. The validation result is written as one JSON document to standard output on both success and validation failure; a failed validation exits with status 1. The supplied Bash launcher and client logging configuration send diagnostics to standard error in this mode. Other launchers must set `-Dseatunnel.console.target=SYSTEM_ERR` before starting the JVM; custom logging configurations must also keep diagnostics off standard output.

The JSON stdout contract is covered by the Bash launcher integration test; native Windows launchers are not covered by that test. In both text and JSON modes, validation failures use sanitized messages and omit the original exception cause to avoid exposing credentials through stack traces. A missing exception message is reported as `Validation failed`.

The JSON contract contains `schemaVersion`, `valid`, `phase` (`static` or `connectivity`), and `errors`. Each entry in `errors` has `location`, `plugin`, `optionPath`, `ruleCategory`, and a sanitized `message`; unavailable fields are `null`.

```shell
sh bin/seatunnel.sh --config $SEATUNNEL_HOME/config/v2.batch.config.template --check --format json
```

```shell
sh bin/seatunnel.sh --config $SEATUNNEL_HOME/config/v2.batch.config.template --dry-run connect
```
Expand Down
11 changes: 11 additions & 0 deletions docs/zh/engines/zeta/user-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Usage: seatunnel.sh [options]
and --encrypt are specified, only
--encrypt will take effect (default:
false)
--format 校验输出格式。支持:[text, json](默认:text)
--get_running_job_metrics Gets metrics for running jobs (default:
false)
-h, --help Show the usage message
Expand Down Expand Up @@ -96,6 +97,16 @@ bin/seatunnel.sh --config $SEATUNNEL_HOME/config/v2.batch.config.template --dry-

使用 `--dry-run static`(或者 `--check`)参数可以在**不提交作业**的前提下静态校验配置文件(包括 HOCON/YAML 语法、插件可加载性、DAG 拓扑、必填项与未知配置键等)。它不会执行完整的数据管道。插件加载可能读取本地 JAR,因此这是配置文件的离线校验,不是严格的零 I/O 沙箱。

需要机器可读的校验结果时,可在 `--check`、`--dry-run static` 或 `--dry-run connect` 后添加 `--format json`。无论校验成功还是失败,标准输出都只写入一份 JSON 文档;校验失败以状态码 1 退出。随发行版提供的 Bash 启动脚本和客户端日志配置会在该模式下将诊断信息写入标准错误。其他启动入口需要在 JVM 启动前设置 `-Dseatunnel.console.target=SYSTEM_ERR`;自定义日志配置也必须避免向标准输出写入诊断信息。

JSON 标准输出契约由 Bash 启动脚本集成测试覆盖;该测试不覆盖原生 Windows 启动入口。文本与 JSON 模式的校验失败均使用脱敏后的消息,并省略原始异常原因,避免通过堆栈泄露凭据。异常没有消息时,使用 `Validation failed`。

JSON 契约包含 `schemaVersion`、`valid`、`phase`(`static` 或 `connectivity`)和 `errors`。`errors` 的每一项包含 `location`、`plugin`、`optionPath`、`ruleCategory` 与已脱敏的 `message`;无法提供的字段为 `null`。

```shell
bin/seatunnel.sh --config $SEATUNNEL_HOME/config/v2.batch.config.template --check --format json
```

```shell
bin/seatunnel.sh --config $SEATUNNEL_HOME/config/v2.batch.config.template --dry-run connect
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

public class ConfigValidationResultTest {

@Test
Expand Down Expand Up @@ -63,4 +65,19 @@ void serializesFailureAndPreservesNullableFields() throws Exception {
.at("/errors/0/ruleCategory")
.asText());
}

@Test
void escapesSpecialCharactersInErrorMessages() throws Exception {
String message = "Invalid value: \"quoted\"\nnext line\tcontrol";
ConfigValidationResult result =
ConfigValidationResult.failure(
"static",
new ConfigValidationError(null, null, null, "validation", message));

Assertions.assertEquals(
message,
JsonUtils.readTree(result.toJson().getBytes(StandardCharsets.UTF_8))
.at("/errors/0/message")
.asText());
}
}
8 changes: 8 additions & 0 deletions seatunnel-core/seatunnel-starter/src/main/bin/seatunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ JAVA_OPTS="${JAVA_OPTS} -Dhazelcast.config=${HAZELCAST_CONFIG}"
# JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=5000,suspend=n"

# Log4j2 Config
# Keep validation diagnostics off the JSON protocol's stdout. Set the target before Log4j starts.
previous_arg=""
for arg in "${args[@]}"; do
if [[ ( "$previous_arg" == "--format" && "$arg" == [Jj][Ss][Oo][Nn] ) || "$arg" == --format=[Jj][Ss][Oo][Nn] ]]; then
JAVA_OPTS="${JAVA_OPTS} -Dseatunnel.console.target=SYSTEM_ERR"
fi
previous_arg="$arg"
done
JAVA_OPTS="${JAVA_OPTS} -Dlog4j2.isThreadContextMapInheritable=true"
if [ -e "${CONF_DIR}/log4j2_client.properties" ]; then
JAVA_OPTS="${JAVA_OPTS} -Dhazelcast.logging.type=log4j2 -Dlog4j2.configurationFile=${CONF_DIR}/log4j2_client.properties"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.core.starter.enums;

/**
* Selects the validation command response format. Text remains the default while JSON exposes a
* stable result schema for programmatic consumers without changing the validation outcome.
*/
public enum OutputFormat {
TEXT,
JSON
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import org.apache.seatunnel.common.constants.EngineType;
import org.apache.seatunnel.core.starter.SeaTunnel;
import org.apache.seatunnel.core.starter.command.Command;
import org.apache.seatunnel.core.starter.enums.OutputFormat;
import org.apache.seatunnel.core.starter.exception.CommandException;
import org.apache.seatunnel.core.starter.seatunnel.args.ClientCommandArgs;
import org.apache.seatunnel.core.starter.seatunnel.command.SeaTunnelConfValidateCommand;
import org.apache.seatunnel.core.starter.utils.CommandLineUtils;

import lombok.extern.slf4j.Slf4j;
Expand All @@ -41,7 +44,16 @@ public static void main(String[] args) throws CommandException {
ClientCommandArgs::validateCommandOptions,
HELP_EXIT_CODE);
try {
SeaTunnel.run(clientCommandArgs.buildCommand());
Command<?> command = clientCommandArgs.buildCommand();
if (clientCommandArgs.getOutputFormat() == OutputFormat.JSON
&& command instanceof SeaTunnelConfValidateCommand) {
int exitCode = ((SeaTunnelConfValidateCommand) command).executeForExitCode();
if (exitCode != 0) {
System.exit(exitCode);
}
return;
}
SeaTunnel.run(command);
} catch (Error e) {
log.error("Exception StackTrace: {}", ExceptionUtils.getStackTrace(e));
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.seatunnel.core.starter.command.ConfEncryptCommand;
import org.apache.seatunnel.core.starter.enums.DryRun;
import org.apache.seatunnel.core.starter.enums.MasterType;
import org.apache.seatunnel.core.starter.enums.OutputFormat;
import org.apache.seatunnel.core.starter.seatunnel.command.ClientExecuteCommand;
import org.apache.seatunnel.core.starter.seatunnel.command.SeaTunnelConfValidateCommand;
import org.apache.seatunnel.engine.common.config.DryRunSampleConfig;
Expand All @@ -51,6 +52,12 @@ public class ClientCommandArgs extends AbstractCommandArgs {
converter = DryRunConverter.class)
protected DryRun dryRun = null;

@Parameter(
names = {"--format"},
description = "Validation output format. Supported values: [text, json].",
converter = OutputFormatConverter.class)
private OutputFormat outputFormat = OutputFormat.TEXT;

@Parameter(
names = {"--sample-limit"},
description =
Expand Down Expand Up @@ -249,6 +256,28 @@ public DryRun convert(String value) {
}
}

/**
* Parses the supported CLI response formats without changing the default text behavior. Invalid
* values fail argument parsing before validation or job submission can begin.
*/
public static class OutputFormatConverter implements IStringConverter<OutputFormat> {
@Override
public OutputFormat convert(String value) {
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Output format must not be empty.");
}
try {
return OutputFormat.valueOf(value.trim().toUpperCase());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Unsupported output format '"
+ value
+ "'. Currently only [text, json] are supported.",
e);
}
}
}

/** Returns the configured sample limit, or the default limit when it was not specified. */
public int getSampleLimit() {
return sampleLimit == null ? DryRunSampleConfig.DEFAULT_LIMIT : sampleLimit;
Expand All @@ -257,6 +286,11 @@ public int getSampleLimit() {
/** Validates options that depend on other command-line arguments. */
public void validateCommandOptions() {
validateSampleOptions();
if (outputFormat == OutputFormat.JSON
&& ((!checkConfig && dryRun == null) || dryRun == DryRun.SAMPLE)) {
throw new ParameterException(
"--format json requires --check, --dry-run static, or --dry-run connect.");
}
if (dryRun == DryRun.SAMPLE) {
validateSampleMode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.seatunnel.common.utils.DryRunConnectFailureMessageSanitizer;
import org.apache.seatunnel.core.starter.command.Command;
import org.apache.seatunnel.core.starter.enums.DryRun;
import org.apache.seatunnel.core.starter.enums.OutputFormat;
import org.apache.seatunnel.core.starter.exception.ConfigCheckException;
import org.apache.seatunnel.core.starter.seatunnel.args.ClientCommandArgs;
import org.apache.seatunnel.core.starter.utils.ConfigBuilder;
Expand Down Expand Up @@ -101,8 +102,26 @@ public SeaTunnelConfValidateCommand(ClientCommandArgs clientCommandArgs) {

@Override
public void execute() throws ConfigCheckException {
Path configPath = FileUtils.getConfigPath(clientCommandArgs);
executeForExitCode();
}

/**
* Runs the CLI adapter and returns its exit status. JSON validation failures are represented by
* the result and status, not by an exception that the launcher would log as text.
*/
public int executeForExitCode() throws ConfigCheckException {
if (clientCommandArgs.getOutputFormat() == OutputFormat.JSON) {
ConfigValidationResult result = validateResult();
System.out.println(result.toJson());
return result.isValid() ? 0 : 1;
}
validateConfig();
return 0;
}

private void validateConfig() throws ConfigCheckException {
// Preserve the original path-resolution exception contract in default text mode.
Path configPath = FileUtils.getConfigPath(clientCommandArgs);
try {
Config config = ConfigBuilder.of(configPath, clientCommandArgs.getVariables());

Expand Down Expand Up @@ -184,16 +203,10 @@ public void execute() throws ConfigCheckException {
}

} catch (Exception e) {
String validationMode =
clientCommandArgs.getDryRun() == DryRun.CONNECT
? "Connectivity check"
: "Static analysis";
String message = e.getMessage();
if (clientCommandArgs.getDryRun() == DryRun.CONNECT) {
message = DryRunConnectFailureMessageSanitizer.sanitize(message);
throw new ConfigCheckException(validationMode + " failed: " + message);
}
throw new ConfigCheckException(validationMode + " failed: " + message, e);
String message = safeMessage(e.getMessage());
// The launcher logs the complete exception chain in text mode too.
// Do not reattach a cause that can contain the unredacted configuration.
throw new ConfigCheckException(validationMode() + " failed: " + message);
}
}

Expand All @@ -204,23 +217,26 @@ public void execute() throws ConfigCheckException {
*/
public ConfigValidationResult validateResult() {
try {
execute();
validateConfig();
return ConfigValidationResult.success(validationPhase());
} catch (ConfigCheckException e) {
} catch (Exception e) {
String message = e.getMessage();
String prefix = validationMode() + " failed: ";
if (message != null && message.startsWith(prefix)) {
message = message.substring(prefix.length());
}
// The result is intended for programmatic consumers, so never expose credentials
// even when the underlying validation phase is static.
message = DryRunConnectFailureMessageSanitizer.sanitize(message);
return ConfigValidationResult.failure(
validationPhase(),
toValidationError(message == null ? "Validation failed" : message));
validationPhase(), toValidationError(safeMessage(message)));
}
}

private static String safeMessage(String message) {
return DryRunConnectFailureMessageSanitizer.sanitize(
message == null ? "Validation failed" : message);
}

private String validationPhase() {
return clientCommandArgs.getDryRun() == DryRun.CONNECT ? "connectivity" : "static";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.seatunnel.core.starter.SeaTunnel;
import org.apache.seatunnel.core.starter.enums.DryRun;
import org.apache.seatunnel.core.starter.enums.MasterType;
import org.apache.seatunnel.core.starter.enums.OutputFormat;
import org.apache.seatunnel.core.starter.exception.CommandExecuteException;
import org.apache.seatunnel.core.starter.seatunnel.SeaTunnelClient;
import org.apache.seatunnel.core.starter.seatunnel.command.ClientExecuteCommand;
Expand All @@ -29,6 +30,8 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.beust.jcommander.ParameterException;

import java.io.FileNotFoundException;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand Down Expand Up @@ -81,6 +84,28 @@ public void testDryRunParam() {
Assertions.assertEquals(DryRun.STATIC, clientCommandArgs.getDryRun());
}

@Test
public void testJsonFormatRequiresValidationCommand() {
ClientCommandArgs args =
CommandLineUtils.parse(
new String[] {"-c", "app.conf", "--format", "json"},
new ClientCommandArgs(),
"seatunnel-client",
true);
Assertions.assertThrows(ParameterException.class, args::buildCommand);
}

@Test
public void testJsonFormatIsAcceptedForCheck() {
ClientCommandArgs args =
CommandLineUtils.parse(
new String[] {"-c", "app.conf", "--check", "--format", "json"},
new ClientCommandArgs(),
"seatunnel-client",
true);
Assertions.assertEquals(OutputFormat.JSON, args.getOutputFormat());
}

@Test
public void testConnectDryRunParam() {
String[] args = {"-c", "app.conf", "--dry-run", "connect"};
Expand Down
Loading