Skip to content

Commit

Permalink
[Feature][Tool] Add connector check script for issue 6199 (#6635)
Browse files Browse the repository at this point in the history
  • Loading branch information
dailai authored Apr 9, 2024
1 parent 9954d1e commit 65aedf6
Show file tree
Hide file tree
Showing 24 changed files with 1,173 additions and 15 deletions.
35 changes: 35 additions & 0 deletions docs/en/command/connector-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Connector check command usage

## Command Entrypoint

```shell
bin/seatunnel-connector.sh
```

## Options

```text
Usage: seatunnel-connector.sh [options]
Options:
-h, --help Show the usage message
-l, --list List all supported plugins(sources, sinks, transforms)
(default: false)
-o, --option-rule Get option rule of the plugin by the plugin
identifier(connector name or transform name)
-pt, --plugin-type SeaTunnel plugin type, support [source, sink,
transform]
```

## Example

```shell
# List all supported connectors(sources and sinks) and transforms
bin/seatunnel-connector.sh -l
# List all supported sinks
bin/seatunnel-connector.sh -l -pt sink
# Get option rule of the connector or transform by the name
bin/seatunnel-connector.sh -o Paimon
# Get option rule of paimon sink
bin/seatunnel-connector.sh -o Paimon -pt sink
```

3 changes: 2 additions & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ const sidebars = {
"type": "category",
"label": "Command",
"items": [
"command/usage"
"command/usage",
"command/connector-check"
]
},
{
Expand Down
35 changes: 35 additions & 0 deletions docs/zh/command/connector-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 连接器检查命令用法

## 命令入口

```shell
bin/seatunnel-connector.sh
```

## 命令选项

```text
Usage: seatunnel-connector.sh [options]
Options:
-h, --help Show the usage message
-l, --list List all supported plugins(sources, sinks, transforms)
(default: false)
-o, --option-rule Get option rule of the plugin by the plugin
identifier(connector name or transform name)
-pt, --plugin-type SeaTunnel plugin type, support [source, sink,
transform]
```

## 例子

```shell
# List all supported connectors(sources and sinks) and transforms
bin/seatunnel-connector.sh -l
# List all supported sinks
bin/seatunnel-connector.sh -l -pt sink
# Get option rule of the connector or transform by the name
bin/seatunnel-connector.sh -o Paimon
# Get option rule of paimon sink
bin/seatunnel-connector.sh -o Paimon -pt sink
```

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class CosFileSourceFactory implements TableSourceFactory {
@Override
public String factoryIdentifier() {
return FileSystemType.OSS.getFileSystemPluginName();
return FileSystemType.COS.getFileSystemPluginName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements. See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License. You may obtain a copy of the License at
rem
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

REM resolve links - %0 may be a softlink
for %%F in ("%~f0") do (
set "PRG=%%~fF"
set "PRG_DIR=%%~dpF"
set "APP_DIR=%%~dpF.."
)

set "APP_JAR=%APP_DIR%\starter\seatunnel-starter.jar"
set "LOAD_CLASS=org.apache.seatunnel.core.starter.seatunnel.SeaTunnelConnector"

if "%~1" == "" (
set "args=-h"
) else (
set "args=%*"
)

set "CLASS_PATH=%APP_DIR%\connectors\*;%APP_JAR%;%APP_DIR%\lib\seatunnel-transforms-v2.jar"

java -cp "%CLASS_PATH%" %LOAD_CLASS% %args% | findstr /v /c:"org.apache.seatunnel.plugin.discovery.AbstractPluginDiscovery"
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
#
# 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.
#

set -eu
# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
# shellcheck disable=SC2006
ls=`ls -ld "$PRG"`
# shellcheck disable=SC2006
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
# shellcheck disable=SC2006
PRG=`dirname "$PRG"`/"$link"
fi
done

PRG_DIR=$(dirname "$PRG")
APP_DIR=$(cd "$PRG_DIR/.." >/dev/null; pwd)
APP_JAR=${APP_DIR}/starter/seatunnel-starter.jar
LOAD_CLASS="org.apache.seatunnel.core.starter.seatunnel.SeaTunnelConnector"

if [ $# == 0 ]
then
args="-h"
else
args=$@
fi

set +u
CLASS_PATH=${APP_DIR}/connectors/*:${APP_JAR}:${APP_DIR}/lib/seatunnel-transforms-v2.jar

java -cp ${CLASS_PATH} ${LOAD_CLASS} ${args} | grep -v 'org\.apache\.seatunnel\.plugin\.discovery\.AbstractPluginDiscovery'
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.seatunnel;

import org.apache.seatunnel.core.starter.SeaTunnel;
import org.apache.seatunnel.core.starter.seatunnel.args.ConnectorCheckCommandArgs;
import org.apache.seatunnel.core.starter.utils.CommandLineUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SeaTunnelConnector {
private static final String SHELL_NAME = "seatunnel-connector.sh";

public static void main(String[] args) {
ConnectorCheckCommandArgs clientCommandArgs =
CommandLineUtils.parse(args, new ConnectorCheckCommandArgs(), SHELL_NAME, true);
SeaTunnel.run(clientCommandArgs.buildCommand());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.seatunnel.args;

import org.apache.seatunnel.common.constants.PluginType;
import org.apache.seatunnel.core.starter.command.Command;
import org.apache.seatunnel.core.starter.command.CommandArgs;
import org.apache.seatunnel.core.starter.seatunnel.command.ConnectorCheckCommand;

import com.beust.jcommander.IStringConverter;
import com.beust.jcommander.Parameter;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ConnectorCheckCommandArgs extends CommandArgs {
@Parameter(
names = {"-l", "--list"},
description = "List all supported plugins(sources, sinks, transforms)")
private boolean listConnectors = false;

@Parameter(
names = {"-o", "--option-rule"},
description =
"Get option rule of the plugin by the plugin identifier(connector name or transform name)")
private String pluginIdentifier;

@Parameter(
names = {"-pt", "--plugin-type"},
description = "SeaTunnel plugin type, support [source, sink, transform]",
converter = SeaTunnelPluginTypeConverter.class)
private PluginType pluginType;

@Override
public Command<?> buildCommand() {
return new ConnectorCheckCommand(this);
}

public static class SeaTunnelPluginTypeConverter implements IStringConverter<PluginType> {
@Override
public PluginType convert(String value) {
try {
return PluginType.valueOf(value.toUpperCase());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"The plugin type of seaTunnel only "
+ "support these options: [source, transform, sink]");
}
}
}
}
Loading

0 comments on commit 65aedf6

Please sign in to comment.