Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][Tool] Add connector check script for issue 6199 #6635

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
@@ -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]");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.command;

import org.apache.seatunnel.common.constants.PluginType;
import org.apache.seatunnel.core.starter.command.Command;
import org.apache.seatunnel.core.starter.exception.CommandExecuteException;
import org.apache.seatunnel.core.starter.exception.ConfigCheckException;
import org.apache.seatunnel.core.starter.seatunnel.args.ConnectorCheckCommandArgs;
import org.apache.seatunnel.plugin.discovery.PluginDiscovery;
import org.apache.seatunnel.plugin.discovery.seatunnel.SeaTunnelSinkPluginDiscovery;
import org.apache.seatunnel.plugin.discovery.seatunnel.SeaTunnelSourcePluginDiscovery;
import org.apache.seatunnel.plugin.discovery.seatunnel.SeaTunnelTransformPluginDiscovery;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ConnectorCheckCommand implements Command<ConnectorCheckCommandArgs> {

private static final Map<PluginType, PluginDiscovery> DISCOVERY_MAP = new HashMap();
private ConnectorCheckCommandArgs connectorCheckCommandArgs;

public ConnectorCheckCommand(ConnectorCheckCommandArgs connectorCheckCommandArgs) {
this.connectorCheckCommandArgs = connectorCheckCommandArgs;
this.DISCOVERY_MAP.put(PluginType.SOURCE, new SeaTunnelSourcePluginDiscovery());
this.DISCOVERY_MAP.put(PluginType.SINK, new SeaTunnelSinkPluginDiscovery());
this.DISCOVERY_MAP.put(PluginType.TRANSFORM, new SeaTunnelTransformPluginDiscovery());
}

@Override
public void execute() throws CommandExecuteException, ConfigCheckException {
PluginType pluginType = connectorCheckCommandArgs.getPluginType();

// Print plugins(connectors and transforms)
if (connectorCheckCommandArgs.isListConnectors()) {
if (Objects.isNull(pluginType)) {
DISCOVERY_MAP
.values()
.forEach(pluginDiscovery -> pluginDiscovery.printSupportedPlugins());
} else {
DISCOVERY_MAP.get(pluginType).printSupportedPlugins();
}
}

String pluginIdentifier = connectorCheckCommandArgs.getPluginIdentifier();
// print option rule of the connector
if (StringUtils.isNoneBlank(pluginIdentifier)) {
if (Objects.isNull(pluginType)) {
DISCOVERY_MAP
.values()
.forEach(
pluginDiscovery ->
pluginDiscovery.printOptionRules(pluginIdentifier));
} else {
DISCOVERY_MAP.get(pluginType).printOptionRules(pluginIdentifier);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.utils.CommandLineUtils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ConnectorCheckCommandArgsTest {
@Test
public void testConnectorCheckCommandArgs() {
String[] args = {"-l", "-pt", "source", "-o", "Paimon"};
ConnectorCheckCommandArgs connectorCheckCommandArgs =
CommandLineUtils.parse(
args, new ConnectorCheckCommandArgs(), "seatunnel-connector.sh", false);
Assertions.assertTrue(connectorCheckCommandArgs.isListConnectors());
Assertions.assertEquals(connectorCheckCommandArgs.getPluginType(), PluginType.SOURCE);
Assertions.assertEquals(connectorCheckCommandArgs.getPluginIdentifier(), "Paimon");

String[] illegalArgs = {"-l", "-pt", "**"};
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
CommandLineUtils.parse(
illegalArgs,
new ConnectorCheckCommandArgs(),
"seatunnel-connector.sh",
false));
}
}
Loading
Loading