deepdata: core product code (backend, frontend, runtime, deepflow module)

This commit is contained in:
figmar
2026-08-30 19:23:38 +08:00
commit bd3db30be9
1405 changed files with 271727 additions and 0 deletions
+151
View File
@@ -0,0 +1,151 @@
# DataX 框架
## 概述
DataX 是一个数据传输框架,支持多种数据源和数据目标之间的数据传输,用于数据收集和同步。
## 架构
```
runtime/datax/
├── core/ # DataX 核心组件
├── transformer/ # 数据转换器
├── readers/ # 数据读取器
│ ├── mysqlreader/
│ ├── postgresqlreader/
│ ├── oracleReader/
│ ├── mongodbreader/
│ ├── hdfsreader/
│ ├── s3rader/
│ ├── nfsreader/
│ ├── glusterfsreader/
│ └── apireader/
└── writers/ # 数据写入器
├── mysqlwriter/
├── postgresqlwriter/
├── oraclewriter/
├── mongodbwriter/
├── hdfswriter/
├── s3writer/
├── nfswriter/
├── glusterfswriter/
└── txtfilewriter/
```
## 支持的数据源
### 关系型数据库
- MySQL
- PostgreSQL
- Oracle
- SQL Server
- DB2
- KingbaseES
- GaussDB
### NoSQL 数据库
- MongoDB
- Elasticsearch
- Cassandra
- HBase
- Redis
### 文件系统
- HDFS
- S3 (AWS S3, MinIO, 阿里云 OSS)
- NFS
- GlusterFS
- 本地文件系统
### 其他
- API 接口
- Kafka
- Pulsar
- DataHub
- LogHub
## 使用
### 基本配置
```json
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root",
"password": "password",
"column": ["id", "name", "email"],
"connection": [
{
"jdbcUrl": "jdbc:mysql://localhost:3306/database",
"table": ["users"]
}
]
}
},
"writer": {
"name": "txtfilewriter",
"parameter": {
"path": "/output/users.txt",
"fileName": "users",
"writeMode": "truncate"
}
}
}
]
}
}
```
### 运行 DataX
```bash
# 构建 DataX
cd runtime/datax
mvn clean package
# 运行
python datax.py -j job.json
```
## 快速开始
### 前置条件
- JDK 8+
- Maven 3.8+
- Python 3.6+
### 构建
```bash
cd runtime/datax
mvn clean package
```
### 运行示例
```bash
python datax.py -j examples/mysql2text.json
```
## 开发
### 添加新的 Reader
1. 在 `readers/` 创建新模块
2. 实现 Reader 接口
3. 配置 reader 参数
4. 添加到 package.xml
### 添加新的 Writer
1. 在 `writers/` 创建新模块
2. 实现 Writer 接口
3. 配置 writer 参数
4. 添加到 package.xml
## 文档
- [DataX 官方文档](https://github.com/alibaba/DataX)
## 相关链接
- [运行时 README](../README.md)
+151
View File
@@ -0,0 +1,151 @@
# DataX Framework
## Overview
DataX is a data transfer framework that supports data transmission between various data sources and targets, used for data collection and synchronization.
## Architecture
```
runtime/datax/
├── core/ # DataX core components
├── transformer/ # Data transformers
├── readers/ # Data readers
│ ├── mysqlreader/
│ ├── postgresqlreader/
│ ├── oracleReader/
│ ├── mongodbreader/
│ ├── hdfsreader/
│ ├── s3rader/
│ ├── nfsreader/
│ ├── glusterfsreader/
│ └── apireader/
└── writers/ # Data writers
├── mysqlwriter/
├── postgresqlwriter/
├── oraclewriter/
├── mongodbwriter/
├── hdfswriter/
├── s3writer/
├── nfswriter/
├── glusterfswriter/
└── txtfilewriter/
```
## Supported Data Sources
### Relational Databases
- MySQL
- PostgreSQL
- Oracle
- SQL Server
- DB2
- KingbaseES
- GaussDB
### NoSQL Databases
- MongoDB
- Elasticsearch
- Cassandra
- HBase
- Redis
### File Systems
- HDFS
- S3 (AWS S3, MinIO, Alibaba Cloud OSS)
- NFS
- GlusterFS
- Local file system
### Others
- API interfaces
- Kafka
- Pulsar
- DataHub
- LogHub
## Usage
### Basic Configuration
```json
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root",
"password": "password",
"column": ["id", "name", "email"],
"connection": [
{
"jdbcUrl": "jdbc:mysql://localhost:3306/database",
"table": ["users"]
}
]
}
},
"writer": {
"name": "txtfilewriter",
"parameter": {
"path": "/output/users.txt",
"fileName": "users",
"writeMode": "truncate"
}
}
}
]
}
}
```
### Run DataX
```bash
# Build DataX
cd runtime/datax
mvn clean package
# Run
python datax.py -j job.json
```
## Quick Start
### Prerequisites
- JDK 8+
- Maven 3.8+
- Python 3.6+
### Build
```bash
cd runtime/datax
mvn clean package
```
### Run Example
```bash
python datax.py -j examples/mysql2text.json
```
## Development
### Adding a New Reader
1. Create new module in `readers/`
2. Implement Reader interface
3. Configure reader parameters
4. Add to package.xml
### Adding a New Writer
1. Create new module in `writers/`
2. Implement Writer interface
3. Configure writer parameters
4. Add to package.xml
## Documentation
- [DataX Official Documentation](https://github.com/alibaba/DataX)
## Related Links
- [Runtime README](../README.md)
+86
View File
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-all</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>apireader</artifactId>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-core</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83_noneautotype</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
<include>plugin_job_template.json</include>
</includes>
<outputDirectory>plugin/reader/apireader</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>apireader-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/reader/apireader</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/reader/apireader/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,275 @@
package com.deepdata.plugin.reader.apireader;
import com.alibaba.datax.common.element.*;
import com.alibaba.datax.common.plugin.RecordSender;
import com.alibaba.datax.common.spi.Reader;
import com.alibaba.datax.common.util.Configuration;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import java.net.URI;
import java.util.Collections;
import java.util.List;
/**
* API读取器
* 支持符合restful api的接口
*/
public class APIReader extends Reader {
private static final Logger LOG = LoggerFactory.getLogger(APIReader.class);
public static class Job extends Reader.Job {
private Configuration jobConfig = null;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
}
@Override
public void prepare() {
String api = this.jobConfig.getString("api");
Object schema = this.jobConfig.get("schema");
HttpEndpointSecurity.validateExternalHttpUri(api, "api");
if (schema == null) {
throw new RuntimeException("schema configuration is required for APIReader");
}
}
@Override
public List<Configuration> split(int adviceNumber) {
// API通常不支持并行分片读取,除非有分页参数逻辑,此处暂按单通道处理
return Collections.singletonList(this.jobConfig);
}
@Override
public void destroy() {
}
}
public static class Task extends Reader.Task {
private Configuration jobConfig;
private String api;
private String method;
private String dataPath; // 用于指定返回json中哪个节点是数据列表,例如 "data.list"
private List<Configuration> schemaFields;
private String requestBody;
private Configuration requestHeaders;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
this.api = this.jobConfig.getString("api");
this.method = this.jobConfig.getString("method", "GET");
this.requestBody = this.jobConfig.getString("body", "");
this.requestHeaders = this.jobConfig.getConfiguration("headers");
parseSchema();
}
private void parseSchema() {
Configuration schemaConfig = this.jobConfig.getConfiguration("schema");
if (schemaConfig != null && !schemaConfig.getKeys().isEmpty()) {
this.dataPath = schemaConfig.getString("dataPath", "");
this.schemaFields = schemaConfig.getListConfiguration("fields");
return;
}
if (this.schemaFields == null || this.schemaFields.isEmpty()) {
throw new RuntimeException("schema.fields is required and cannot be empty");
}
for (Configuration fieldConfig : this.schemaFields) {
String name = fieldConfig.getString("name"); // JSON中的字段名
String path = fieldConfig.getString("path"); // 可选:支持深层提取
if (StringUtils.isBlank(name) && StringUtils.isBlank(path)) {
throw new RuntimeException("schema.fields must contain name or path");
}
}
}
@Override
public void startRead(RecordSender recordSender) {
LOG.info("Start reading from API: [{}]", this.api);
try {
// 1. 发起HTTP请求
String responseBody = doHttpRequest(this.api, this.method, this.requestBody, this.requestHeaders);
// 2. 解析响应
JSONArray dataArray = parseResponse(responseBody);
if (dataArray.isEmpty()) {
LOG.warn("API returned empty data.");
return;
}
// 3. 添加文件表头
addDataHeader(recordSender);
// 4. 遍历数据并转换为DataX Record
addData(recordSender, dataArray);
} catch (Exception e) {
LOG.error("Error occurred while reading from API", e);
throw new RuntimeException(e);
}
}
private void addData(RecordSender recordSender, JSONArray dataArray) {
for (Object itemObj : dataArray) {
JSONObject item = (JSONObject) itemObj;
Record record = recordSender.createRecord();
for (Configuration fieldConfig : this.schemaFields) {
String name = fieldConfig.getString("name"); // JSON中的字段名
String path = fieldConfig.getString("path"); // 可选:支持深层提取
if (StringUtils.isBlank(name) && StringUtils.isBlank(path)) {
throw new RuntimeException("schema.fields must contain name or path");
}
Object val;
if (StringUtils.isNotBlank(path)) {
val = JSONPath.eval(item, path);
} else {
val = item.get(name);
}
if (val == null) {
record.addColumn(new StringColumn(""));
continue;
}
record.addColumn(new StringColumn(val.toString()));
}
recordSender.sendToWriter(record);
}
}
private void addDataHeader(RecordSender recordSender) {
Record recordHeader = recordSender.createRecord();
for (Configuration fieldConfig : this.schemaFields) {
String name = fieldConfig.getString("name"); // JSON中的字段名
String alias = fieldConfig.getString("alias"); // 自定义的字段别名
if (StringUtils.isNotBlank(alias)) {
recordHeader.addColumn(new StringColumn(alias));
} else {
recordHeader.addColumn(new StringColumn(name));
}
}
recordSender.sendToWriter(recordHeader);
}
private JSONArray parseResponse(String responseBody) {
Object responseJson = JSON.parse(responseBody);
JSONArray dataArray;
// 定位数据节点
if (StringUtils.isNotBlank(this.dataPath)) {
// 使用 JSONPath 提取
Object extracted = JSONPath.eval(responseJson, this.dataPath);
if (extracted instanceof JSONArray) {
dataArray = (JSONArray) extracted;
} else {
throw new RuntimeException("The dataPath configured [" + this.dataPath + "] does not point to a JSON Array.");
}
} else {
if (responseJson instanceof JSONArray) {
dataArray = (JSONArray) responseJson;
} else if (responseJson instanceof JSONObject) {
throw new RuntimeException("Response is an Object, please configure schema.dataPath to point to the list.");
} else {
throw new RuntimeException("Unknown response format.");
}
}
return dataArray;
}
/**
* 简单的HTTP请求实现
*/
private String doHttpRequest(String urlStr, String method, String body, Configuration headers) throws Exception {
URI safeUri = HttpEndpointSecurity.validateExternalHttpUri(urlStr, "api");
RequestConfig requestConfig = RequestConfig.custom()
.setRedirectsEnabled(false)
.build();
try (CloseableHttpClient client = HttpClients.custom()
.disableRedirectHandling()
.setDefaultRequestConfig(requestConfig)
.build()) {
HttpUriRequestBase request = buildRequest(safeUri, method, body);
if (headers != null && !headers.getKeys().isEmpty()) {
for (String key : headers.getKeys()) {
String value = headers.getString(key);
if (StringUtils.isNotBlank(key) && value != null) {
request.addHeader(key, value);
}
}
}
try (CloseableHttpResponse response = client.execute(request)) {
int status = response.getCode();
if (status >= 200 && status < 300) {
return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
}
throw new RuntimeException("API Call failed. Http Code: " + status);
}
}
}
private HttpUriRequestBase buildRequest(URI uri, String method, String body) {
String verb = StringUtils.defaultIfBlank(method, "GET").toUpperCase();
HttpUriRequestBase request;
switch (verb) {
case "POST":
request = new HttpPost(uri);
break;
case "PUT":
request = new HttpPut(uri);
break;
case "DELETE":
request = new HttpDelete(uri);
break;
default:
request = new HttpGet(uri);
break;
}
if (request instanceof HttpPost || request instanceof HttpPut) {
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON));
}
}
return request;
}
@Override
public void destroy() {
}
}
}
@@ -0,0 +1,175 @@
package com.deepdata.plugin.reader.apireader;
import java.net.IDN;
import java.net.InetAddress;
import java.net.URI;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
final class HttpEndpointSecurity {
private static final String ALLOWED_HOSTS_PROPERTY = "deepdata.ssrf.allowedHosts";
private static final String ALLOWED_HOSTS_ENV = "DEEPDATA_SSRF_ALLOWED_HOSTS";
private HttpEndpointSecurity() {
}
static URI validateExternalHttpUri(String rawUri, String fieldName) {
if (isBlank(rawUri)) {
throw new IllegalArgumentException(fieldName + " is required");
}
if (rawUri.indexOf('\r') >= 0 || rawUri.indexOf('\n') >= 0) {
throw new IllegalArgumentException(fieldName + " contains invalid control characters");
}
URI uri = URI.create(rawUri.trim()).normalize();
String scheme = uri.getScheme() == null ? null : uri.getScheme().toLowerCase(Locale.ROOT);
if (!"http".equals(scheme) && !"https".equals(scheme)) {
throw new IllegalArgumentException(fieldName + " only supports http or https");
}
if (!isBlank(uri.getUserInfo())) {
throw new IllegalArgumentException(fieldName + " must not contain user info");
}
if (uri.getFragment() != null) {
throw new IllegalArgumentException(fieldName + " must not contain fragment");
}
int port = uri.getPort();
if (port == 0 || port < -1 || port > 65535) {
throw new IllegalArgumentException(fieldName + " contains invalid port");
}
String asciiHost = toAsciiHost(uri.getHost(), fieldName);
if (isAllowedHost(asciiHost)) {
return uri;
}
InetAddress[] addresses;
try {
addresses = InetAddress.getAllByName(asciiHost);
} catch (Exception e) {
throw new IllegalArgumentException(fieldName + " host cannot be resolved", e);
}
if (addresses.length == 0) {
throw new IllegalArgumentException(fieldName + " host cannot be resolved");
}
for (InetAddress address : addresses) {
if (!isPublicRoutableAddress(address)) {
throw new IllegalArgumentException(fieldName + " points to a restricted network address");
}
}
return uri;
}
private static String toAsciiHost(String host, String fieldName) {
if (isBlank(host)) {
throw new IllegalArgumentException(fieldName + " must contain a valid host");
}
try {
String normalized = host.endsWith(".") ? host.substring(0, host.length() - 1) : host;
return IDN.toASCII(normalized, IDN.USE_STD3_ASCII_RULES).toLowerCase(Locale.ROOT);
} catch (Exception e) {
throw new IllegalArgumentException(fieldName + " contains invalid host", e);
}
}
private static boolean isAllowedHost(String host) {
return configuredAllowedHosts().contains(host);
}
private static Set<String> configuredAllowedHosts() {
Set<String> hosts = new HashSet<String>();
addConfiguredHosts(hosts, System.getProperty(ALLOWED_HOSTS_PROPERTY));
addConfiguredHosts(hosts, System.getenv(ALLOWED_HOSTS_ENV));
return hosts;
}
private static void addConfiguredHosts(Set<String> hosts, String rawHosts) {
if (isBlank(rawHosts)) {
return;
}
String[] parts = rawHosts.split(",");
for (String part : parts) {
if (!isBlank(part)) {
hosts.add(toAsciiHost(part.trim(), "allowed host"));
}
}
}
private static boolean isPublicRoutableAddress(InetAddress address) {
if (address.isAnyLocalAddress() || address.isLoopbackAddress() || address.isLinkLocalAddress()
|| address.isSiteLocalAddress() || address.isMulticastAddress()) {
return false;
}
byte[] bytes = address.getAddress();
if (bytes.length == 4) {
return isPublicRoutableIpv4(bytes);
}
if (bytes.length == 16) {
return isPublicRoutableIpv6(bytes);
}
return false;
}
private static boolean isPublicRoutableIpv4(byte[] bytes) {
int first = bytes[0] & 0xff;
int second = bytes[1] & 0xff;
int third = bytes[2] & 0xff;
if (first == 0 || first == 10 || first == 127 || first >= 224) {
return false;
}
if (first == 100 && second >= 64 && second <= 127) {
return false;
}
if (first == 169 && second == 254) {
return false;
}
if (first == 172 && second >= 16 && second <= 31) {
return false;
}
if (first == 192 && second == 168) {
return false;
}
if (first == 192 && second == 0 && (third == 0 || third == 2)) {
return false;
}
if (first == 198 && (second == 18 || second == 19 || (second == 51 && third == 100))) {
return false;
}
if (first == 203 && second == 0 && third == 113) {
return false;
}
return true;
}
private static boolean isPublicRoutableIpv6(byte[] bytes) {
int first = bytes[0] & 0xff;
int second = bytes[1] & 0xff;
if ((first & 0xfe) == 0xfc) {
return false;
}
if (first == 0xfe && (second & 0xc0) == 0x80) {
return false;
}
if (first == 0x20 && second == 0x01 && (bytes[2] & 0xff) == 0x0d && (bytes[3] & 0xff) == 0xb8) {
return false;
}
return !isIpv4MappedPrivateAddress(bytes);
}
private static boolean isIpv4MappedPrivateAddress(byte[] bytes) {
for (int i = 0; i < 10; i++) {
if (bytes[i] != 0) {
return false;
}
}
if ((bytes[10] & 0xff) != 0xff || (bytes[11] & 0xff) != 0xff) {
return false;
}
byte[] ipv4 = new byte[] {bytes[12], bytes[13], bytes[14], bytes[15]};
return !isPublicRoutableIpv4(ipv4);
}
private static boolean isBlank(String value) {
return value == null || value.trim().isEmpty();
}
}
@@ -0,0 +1,6 @@
{
"name": "apireader",
"class": "com.deepdata.plugin.reader.apireader.APIReader",
"description": "Read the structured data returned by the api",
"developer": "deepdata"
}
@@ -0,0 +1,20 @@
{
"name": "apireader",
"parameter": {
"api": "https://api.example.com/data",
"method": "GET",
"body": "{\"name\": \"value\"}",
"headers": {
"Content-Type": "application/json"
},
"schema": {
"dataPath": "$.data",
"fields": [
{
"name": "name",
"path": "alias"
}
]
}
}
}
@@ -0,0 +1,83 @@
package com.deepdata.plugin.reader.apireader;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class HttpEndpointSecurityTest {
@Test(expected = IllegalArgumentException.class)
public void shouldRejectLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://127.0.0.1:8080/internal", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectLocalhost() {
HttpEndpointSecurity.validateExternalHttpUri("http://localhost:8080/internal", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectIpv6LoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://[::1]:8080/internal", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectIpv4MappedIpv6LoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://[::ffff:127.0.0.1]:8080/internal", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectIntegerEncodedLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://2130706433/internal", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectHexEncodedLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://0x7f000001/internal", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectOctalEncodedLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://017700000001/internal", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectMetadataServiceAddress() {
HttpEndpointSecurity.validateExternalHttpUri("http://169.254.169.254/latest/meta-data", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectPrivateNetworkAddress() {
HttpEndpointSecurity.validateExternalHttpUri("http://10.0.0.1/admin", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectUnsupportedScheme() {
HttpEndpointSecurity.validateExternalHttpUri("file:///etc/passwd", "api");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectUserInfo() {
HttpEndpointSecurity.validateExternalHttpUri("http://user@8.8.8.8/path", "api");
}
@Test
public void shouldAllowPublicHttpAddress() {
assertEquals("8.8.8.8", HttpEndpointSecurity.validateExternalHttpUri("https://8.8.8.8/data", "api").getHost());
}
@Test
public void shouldAllowExplicitlyConfiguredHost() {
String previous = System.getProperty("deepdata.ssrf.allowedHosts");
try {
System.setProperty("deepdata.ssrf.allowedHosts", "localhost");
assertEquals("localhost",
HttpEndpointSecurity.validateExternalHttpUri("http://localhost:9000/data", "api").getHost());
} finally {
if (previous == null) {
System.clearProperty("deepdata.ssrf.allowedHosts");
} else {
System.setProperty("deepdata.ssrf.allowedHosts", previous);
}
}
}
}
+80
View File
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datax-all</artifactId>
<groupId>com.alibaba.datax</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>glusterfsreader</artifactId>
<name>glusterfsreader</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-core</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- assembly plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
<include>plugin_job_template.json</include>
</includes>
<outputDirectory>plugin/reader/glusterfsreader</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>glusterfsreader-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/reader/glusterfsreader</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/reader/glusterfsreader/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,119 @@
package com.deepdata.plugin.reader.glusterfsreader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
/**
* GlusterFS 挂载工具类
* 通过系统命令 mount -t glusterfs 进行挂载
*/
public final class GlusterfsMountUtil {
private static final Logger LOG = LoggerFactory.getLogger(GlusterfsMountUtil.class);
private GlusterfsMountUtil() {
}
/**
* 挂载 GlusterFS 卷
*
* @param remote 远程地址,格式: ip:/volume
* @param mountPoint 本地挂载点
* @param subPath 卷内子路径(可选,用于后续读取)
*/
public static void mount(String remote, String mountPoint, String subPath) {
try {
Path mp = Paths.get(mountPoint);
if (isMounted(mountPoint)) {
throw new IOException("Already mounted: " + mountPoint);
}
Files.createDirectories(mp);
ProcessBuilder pb = new ProcessBuilder();
pb.command("mount", "-t", "glusterfs", remote, mountPoint);
LOG.info("Mounting GlusterFS: {}", pb.command());
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("GlusterFS mount failed, exit=" + rc + ", output: " + output);
}
LOG.info("GlusterFS mounted successfully: {} -> {}", remote, mountPoint);
} catch (IOException | InterruptedException e) {
throw new RuntimeException("Failed to mount GlusterFS: " + remote, e);
}
}
/**
* 卸载挂载点
*
* @param mountPoint 挂载点路径
* @throws IOException 卸载失败
* @throws InterruptedException 进程等待中断
*/
public static void umount(String mountPoint) throws IOException, InterruptedException {
if (!isMounted(mountPoint)) {
return;
}
ProcessBuilder pb = new ProcessBuilder("umount", "-l", mountPoint);
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("GlusterFS umount failed, exit=" + rc + ", output: " + output);
}
// 清理空目录
try {
Files.deleteIfExists(Paths.get(mountPoint));
} catch (DirectoryNotEmptyException ignore) {
// 目录非空,保留
}
LOG.info("GlusterFS unmounted: {}", mountPoint);
}
/**
* 判断挂载点是否已挂载
*
* @param mountPoint 挂载点路径
* @return true 表示已挂载
* @throws IOException 读取 /proc/mounts 失败
*/
public static boolean isMounted(String mountPoint) throws IOException {
Path procMounts = Paths.get("/proc/mounts");
if (!Files.exists(procMounts)) {
throw new IOException("/proc/mounts not found");
}
String expected = mountPoint.trim();
List<String> lines = Files.readAllLines(procMounts);
return lines.stream()
.map(l -> l.split("\\s+"))
.filter(a -> a.length >= 2)
.anyMatch(a -> a[1].equals(expected));
}
}
@@ -0,0 +1,142 @@
package com.deepdata.plugin.reader.glusterfsreader;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.alibaba.datax.common.element.Record;
import com.alibaba.datax.common.element.StringColumn;
import com.alibaba.datax.common.plugin.RecordSender;
import com.alibaba.datax.common.spi.Reader;
import com.alibaba.datax.common.util.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* GlusterFS Reader 插件
* 通过 mount -t glusterfs 挂载 GlusterFS 卷,读取文件列表
*/
public class GlusterfsReader extends Reader {
private static final Logger LOG = LoggerFactory.getLogger(GlusterfsReader.class);
public static class Job extends Reader.Job {
private Configuration jobConfig = null;
private String mountPoint;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
}
@Override
public void prepare() {
this.mountPoint = "/dataset/mount/" + UUID.randomUUID();
this.jobConfig.set("mountPoint", this.mountPoint);
String ip = this.jobConfig.getString("ip");
String volume = this.jobConfig.getString("volume");
String subPath = this.jobConfig.getString("path", "");
// GlusterFS mount 格式: mount -t glusterfs ip:/volume /mountpoint
String remote = ip + ":/" + volume;
GlusterfsMountUtil.mount(remote, mountPoint, subPath);
}
@Override
public List<Configuration> split(int adviceNumber) {
return Collections.singletonList(this.jobConfig);
}
@Override
public void post() {
try {
GlusterfsMountUtil.umount(this.mountPoint);
new File(this.mountPoint).deleteOnExit();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
@Override
public void destroy() {
}
}
public static class Task extends Reader.Task {
private Configuration jobConfig;
private String mountPoint;
private String subPath;
private Set<String> fileType;
private List<String> files;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
this.mountPoint = this.jobConfig.getString("mountPoint");
this.subPath = this.jobConfig.getString("path", "");
this.fileType = new HashSet<>(this.jobConfig.getList("fileType", Collections.emptyList(), String.class));
this.files = this.jobConfig.getList("files", Collections.emptyList(), String.class);
}
@Override
public void startRead(RecordSender recordSender) {
String readPath = this.mountPoint;
if (StringUtils.isNotBlank(this.subPath)) {
readPath = this.mountPoint + "/" + this.subPath.replaceFirst("^/+", "");
}
// 防止路径穿越:规范化后校验读取路径仍在 mount 点下
Path normalizedReadPath = Paths.get(readPath).normalize().toAbsolutePath();
Path normalizedMount = Paths.get(this.mountPoint).normalize().toAbsolutePath();
if (!normalizedReadPath.startsWith(normalizedMount)) {
LOG.error("Path traversal detected in reader: readPath={} outside mountPoint={}",
normalizedReadPath, normalizedMount);
throw new RuntimeException("Read path outside mount point: " + readPath);
}
try (Stream<Path> stream = Files.list(normalizedReadPath)) {
List<String> fileList = stream.filter(Files::isRegularFile)
.filter(file -> fileType.isEmpty() || fileType.contains(getFileSuffix(file)))
.map(path -> path.getFileName().toString())
.filter(fileName -> this.files.isEmpty() || this.files.contains(fileName))
.collect(Collectors.toList());
fileList.forEach(filePath -> {
Record record = recordSender.createRecord();
record.addColumn(new StringColumn(filePath));
recordSender.sendToWriter(record);
});
this.jobConfig.set("columnNumber", 1);
} catch (IOException e) {
LOG.error("Error reading files from GlusterFS mount point: {}", readPath, e);
throw new RuntimeException(e);
}
}
private String getFileSuffix(Path path) {
String fileName = path.getFileName().toString();
int lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex == -1 || lastDotIndex == fileName.length() - 1) {
return "";
}
return fileName.substring(lastDotIndex + 1);
}
@Override
public void destroy() {
}
}
}
@@ -0,0 +1,6 @@
{
"name": "glusterfsreader",
"class": "com.deepdata.plugin.reader.glusterfsreader.GlusterfsReader",
"description": "read file list from GlusterFS distributed file system",
"developer": "deepdata"
}
@@ -0,0 +1,10 @@
{
"name": "glusterfsreader",
"parameter": {
"ip": "",
"volume": "",
"path": "",
"fileType": [],
"files": []
}
}
+80
View File
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datax-all</artifactId>
<groupId>com.alibaba.datax</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>glusterfswriter</artifactId>
<name>glusterfswriter</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-core</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- assembly plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
<include>plugin_job_template.json</include>
</includes>
<outputDirectory>plugin/writer/glusterfswriter</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>glusterfswriter-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/writer/glusterfswriter</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/writer/glusterfswriter/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,118 @@
package com.deepdata.plugin.writer.glusterfswriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
/**
* GlusterFS 挂载工具类
* 通过系统命令 mount -t glusterfs 进行挂载
*/
public final class GlusterfsMountUtil {
private static final Logger LOG = LoggerFactory.getLogger(GlusterfsMountUtil.class);
private GlusterfsMountUtil() {
}
/**
* 挂载 GlusterFS 卷
*
* @param remote 远程地址,格式: ip:/volume
* @param mountPoint 本地挂载点
*/
public static void mount(String remote, String mountPoint) {
try {
Path mp = Paths.get(mountPoint);
if (isMounted(mountPoint)) {
throw new IOException("Already mounted: " + mountPoint);
}
Files.createDirectories(mp);
ProcessBuilder pb = new ProcessBuilder();
pb.command("mount", "-t", "glusterfs", remote, mountPoint);
LOG.info("Mounting GlusterFS: {}", pb.command());
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("GlusterFS mount failed, exit=" + rc + ", output: " + output);
}
LOG.info("GlusterFS mounted successfully: {} -> {}", remote, mountPoint);
} catch (IOException | InterruptedException e) {
throw new RuntimeException("Failed to mount GlusterFS: " + remote, e);
}
}
/**
* 卸载挂载点
*
* @param mountPoint 挂载点路径
* @throws IOException 卸载失败
* @throws InterruptedException 进程等待中断
*/
public static void umount(String mountPoint) throws IOException, InterruptedException {
if (!isMounted(mountPoint)) {
return;
}
ProcessBuilder pb = new ProcessBuilder("umount", "-l", mountPoint);
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("GlusterFS umount failed, exit=" + rc + ", output: " + output);
}
// 清理空目录
try {
Files.deleteIfExists(Paths.get(mountPoint));
} catch (DirectoryNotEmptyException ignore) {
// 目录非空,保留
}
LOG.info("GlusterFS unmounted: {}", mountPoint);
}
/**
* 判断挂载点是否已挂载
*
* @param mountPoint 挂载点路径
* @return true 表示已挂载
* @throws IOException 读取 /proc/mounts 失败
*/
public static boolean isMounted(String mountPoint) throws IOException {
Path procMounts = Paths.get("/proc/mounts");
if (!Files.exists(procMounts)) {
throw new IOException("/proc/mounts not found");
}
String expected = mountPoint.trim();
List<String> lines = Files.readAllLines(procMounts);
return lines.stream()
.map(l -> l.split("\\s+"))
.filter(a -> a.length >= 2)
.anyMatch(a -> a[1].equals(expected));
}
}
@@ -0,0 +1,163 @@
package com.deepdata.plugin.writer.glusterfswriter;
import com.alibaba.datax.common.element.Record;
import com.alibaba.datax.common.exception.CommonErrorCode;
import com.alibaba.datax.common.exception.DataXException;
import com.alibaba.datax.common.plugin.RecordReceiver;
import com.alibaba.datax.common.spi.Writer;
import com.alibaba.datax.common.util.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
/**
* GlusterFS Writer 插件
* 通过 mount -t glusterfs 挂载 GlusterFS 卷,将文件写入到目标位置
*/
public class GlusterfsWriter extends Writer {
private static final Logger LOG = LoggerFactory.getLogger(GlusterfsWriter.class);
/** 允许的目标路径基础目录 */
private static final String ALLOWED_DEST_BASE = "/dataset";
public static class Job extends Writer.Job {
private Configuration jobConfig;
private String mountPoint;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
}
@Override
public void prepare() {
this.mountPoint = "/dataset/mount/" + UUID.randomUUID();
this.jobConfig.set("mountPoint", this.mountPoint);
new File(this.mountPoint).mkdirs();
String ip = this.jobConfig.getString("ip");
String volume = this.jobConfig.getString("volume");
// GlusterFS mount 格式: mount -t glusterfs ip:/volume /mountpoint
String remote = ip + ":/" + volume;
GlusterfsMountUtil.mount(remote, mountPoint);
String destPath = this.jobConfig.getString("destPath");
// 防止路径穿越:规范化后校验目标路径在允许目录内
Path normalizedDest = Paths.get(destPath).normalize().toAbsolutePath();
if (!normalizedDest.startsWith(ALLOWED_DEST_BASE)) {
throw new IllegalArgumentException(
"destPath is outside allowed directory: " + destPath);
}
new File(normalizedDest.toString()).mkdirs();
}
@Override
public List<Configuration> split(int mandatoryNumber) {
return Collections.singletonList(this.jobConfig);
}
@Override
public void post() {
try {
GlusterfsMountUtil.umount(this.mountPoint);
new File(this.mountPoint).deleteOnExit();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
@Override
public void destroy() {
}
}
public static class Task extends Writer.Task {
private Configuration jobConfig;
private String mountPoint;
private String subPath;
private String destPath;
private List<String> files;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
this.destPath = this.jobConfig.getString("destPath");
this.mountPoint = this.jobConfig.getString("mountPoint");
this.subPath = this.jobConfig.getString("path", "");
this.files = this.jobConfig.getList("files", Collections.emptyList(), String.class);
// 防止路径穿越:subPath 不能包含 ..
if (StringUtils.isNotBlank(this.subPath) && this.subPath.contains("..")) {
throw new IllegalArgumentException(
"Invalid subPath (path traversal): " + this.subPath);
}
}
@Override
public void startWrite(RecordReceiver lineReceiver) {
String sourcePath = this.mountPoint;
if (StringUtils.isNotBlank(this.subPath)) {
sourcePath = this.mountPoint + "/" + this.subPath.replaceFirst("^/+", "");
}
// 防止路径穿越:规范化后校验源路径仍在 mount 点下
Path normalizedSourcePath = Paths.get(sourcePath).normalize().toAbsolutePath();
Path normalizedMount = Paths.get(this.mountPoint).normalize().toAbsolutePath();
if (!normalizedSourcePath.startsWith(normalizedMount)) {
LOG.error("Path traversal detected: sourcePath={} outside mountPoint={}",
normalizedSourcePath, normalizedMount);
throw DataXException.asDataXException(CommonErrorCode.RUNTIME_ERROR,
"Source path outside mount point: " + sourcePath);
}
// 防止路径穿越:校验目标路径在允许目录内
Path normalizedDest = Paths.get(this.destPath).normalize().toAbsolutePath();
if (!normalizedDest.startsWith(ALLOWED_DEST_BASE)) {
throw DataXException.asDataXException(CommonErrorCode.RUNTIME_ERROR,
"destPath outside allowed directory: " + this.destPath);
}
try {
Record record;
while ((record = lineReceiver.getFromReader()) != null) {
String fileName = record.getColumn(0).asString();
if (StringUtils.isBlank(fileName)) {
continue;
}
if (!files.isEmpty() && !files.contains(fileName)) {
continue;
}
// 防止路径穿越:fileName 不能包含路径分隔符或 ..
if (fileName.contains("..") || fileName.contains("/") || fileName.contains("\\")) {
LOG.warn("Skipping file with suspicious name: {}", fileName);
continue;
}
String filePath = normalizedSourcePath + "/" + fileName;
ShellUtil.runCommand("rsync", Arrays.asList("--no-links", "--chmod=754", "--", filePath,
normalizedDest + "/" + fileName));
}
} catch (Exception e) {
LOG.error("Error writing files from GlusterFS: {}", e.getMessage(), e);
throw DataXException.asDataXException(CommonErrorCode.RUNTIME_ERROR, e);
}
}
@Override
public void destroy() {
}
}
}
@@ -0,0 +1,46 @@
package com.deepdata.plugin.writer.glusterfswriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
* Shell 命令执行工具类
*/
public class ShellUtil {
/**
* 执行 shell 命令
*
* @param cmd 命令
* @param extraArgs 额外参数,可为空
* @return 命令完整输出(stdout + stderr)
* @throws Exception 如果命令返回非 0 或发生 IO 异常
*/
public static String runCommand(String cmd, List<String> extraArgs) throws Exception {
List<String> commands = new ArrayList<>();
commands.add(cmd);
if (extraArgs != null && !extraArgs.isEmpty()) {
commands.addAll(extraArgs);
}
ProcessBuilder pb = new ProcessBuilder(commands);
pb.redirectErrorStream(true); // 合并 stdout & stderr
Process p = pb.start();
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append(System.lineSeparator());
}
}
int exit = p.waitFor();
if (exit != 0) {
throw new RuntimeException("Command exited with code " + exit + System.lineSeparator() + sb);
}
return sb.toString();
}
}
@@ -0,0 +1,6 @@
{
"name": "glusterfswriter",
"class": "com.deepdata.plugin.writer.glusterfswriter.GlusterfsWriter",
"description": "write files to GlusterFS distributed file system",
"developer": "deepdata"
}
@@ -0,0 +1,10 @@
{
"name": "glusterfswriter",
"parameter": {
"ip": "",
"volume": "",
"path": "",
"destPath": "",
"files": []
}
}
+80
View File
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datax-all</artifactId>
<groupId>com.alibaba.datax</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>nfsreader</artifactId>
<name>nfsreader</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-core</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- assembly plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
<include>plugin_job_template.json</include>
</includes>
<outputDirectory>plugin/reader/nfsreader</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>nfsreader-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/reader/nfsreader</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/reader/nfsreader/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,121 @@
package com.deepdata.edeepdata.plugin.reader.nfsreader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
/**
* 一个简单的 Linux NAS 挂载工具类
* 仅适用于 Linux,需具备 sudo 权限或 root。
*/
public final class MountUtil {
private static final Logger LOG = LoggerFactory.getLogger(MountUtil.class);
private MountUtil() {
}
/**
* 挂载远程目录
*
* @param remote 远程地址,如 192.168.1.1:/test
* @param mountPoint 本地挂载点,如 /mnt/nas
* @param type 文件系统类型:nfs、cifs ...
* @param options 额外挂载参数,如 ro,vers=3 或 username=xxx,password=xxx
*/
public static void mount(String remote, String mountPoint, String type, String options) {
try {
Path mp = Paths.get(mountPoint);
if (isMounted(mountPoint)) {
throw new IOException("Already mounted: " + mountPoint);
}
Files.createDirectories(mp);
ProcessBuilder pb = new ProcessBuilder();
if (options == null || options.isEmpty()) {
pb.command("mount", "-t", type, remote, mountPoint);
} else {
pb.command("mount", "-t", type, "-o", options, remote, mountPoint);
}
LOG.info(pb.command().toString());
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("Mount failed, exit=" + rc + ", output: " + output);
}
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
/**
* 卸载挂载点
*
* @param mountPoint 挂载点路径
* @throws IOException 卸载失败
* @throws InterruptedException 进程等待中断
*/
public static void umount(String mountPoint) throws IOException, InterruptedException {
if (!isMounted(mountPoint)) {
return;
}
ProcessBuilder pb = new ProcessBuilder("umount", "-l", mountPoint);
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("Mount failed, exit=" + rc + ", output: " + output);
}
// 清理空目录
try {
Files.deleteIfExists(Paths.get(mountPoint));
} catch (DirectoryNotEmptyException ignore) {
// 目录非空,保留
}
}
/**
* 判断挂载点是否已挂载
*
* @param mountPoint 挂载点路径
* @return true 表示已挂载
* @throws IOException 读取 /proc/mounts 失败
*/
public static boolean isMounted(String mountPoint) throws IOException {
Path procMounts = Paths.get("/proc/mounts");
if (!Files.exists(procMounts)) {
throw new IOException("/proc/mounts not found");
}
String expected = mountPoint.trim();
List<String> lines = Files.readAllLines(procMounts);
return lines.stream()
.map(l -> l.split("\\s+"))
.filter(a -> a.length >= 2)
.anyMatch(a -> a[1].equals(expected));
}
}
@@ -0,0 +1,115 @@
package com.deepdata.edeepdata.plugin.reader.nfsreader;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.alibaba.datax.common.element.Record;
import com.alibaba.datax.common.element.StringColumn;
import com.alibaba.datax.common.plugin.RecordSender;
import com.alibaba.datax.common.spi.Reader;
import com.alibaba.datax.common.util.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NfsReader extends Reader {
private static final Logger LOG = LoggerFactory.getLogger(NfsReader.class);
public static class Job extends Reader.Job {
private Configuration jobConfig = null;
private String mountPoint;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
}
@Override
public void prepare() {
this.mountPoint = "/dataset/mount/" + UUID.randomUUID();
this.jobConfig.set("mountPoint", this.mountPoint);
MountUtil.mount(this.jobConfig.getString("ip") + ":" + this.jobConfig.getString("path"),
mountPoint, "nfs", StringUtils.EMPTY);
}
@Override
public List<Configuration> split(int adviceNumber) {
return Collections.singletonList(this.jobConfig);
}
@Override
public void post() {
try {
MountUtil.umount(this.mountPoint);
new File(this.mountPoint).deleteOnExit();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
@Override
public void destroy() {
}
}
public static class Task extends Reader.Task {
private Configuration jobConfig;
private String mountPoint;
private Set<String> fileType;
private List<String> files;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
this.mountPoint = this.jobConfig.getString("mountPoint");
this.fileType = new HashSet<>(this.jobConfig.getList("fileType", Collections.emptyList(), String.class));
this.files = this.jobConfig.getList("files", Collections.emptyList(), String.class);
}
@Override
public void startRead(RecordSender recordSender) {
try (Stream<Path> stream = Files.list(Paths.get(this.mountPoint))) {
List<String> files = stream.filter(Files::isRegularFile)
.filter(file -> fileType.isEmpty() || fileType.contains(getFileSuffix(file)))
.map(path -> path.getFileName().toString())
.filter(fileName -> this.files.isEmpty() || this.files.contains(fileName))
.collect(Collectors.toList());
files.forEach(filePath -> {
Record record = recordSender.createRecord();
record.addColumn(new StringColumn(filePath));
recordSender.sendToWriter(record);
});
this.jobConfig.set("columnNumber", 1);
} catch (IOException e) {
LOG.error("Error reading files from mount point: {}", this.mountPoint, e);
throw new RuntimeException(e);
}
}
private String getFileSuffix(Path path) {
String fileName = path.getFileName().toString();
int lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex == -1 || lastDotIndex == fileName.length() - 1) {
return "";
}
return fileName.substring(lastDotIndex + 1);
}
@Override
public void destroy() {
}
}
}
@@ -0,0 +1,6 @@
{
"name": "nfsreader",
"class": "com.deepdata.edeepdata.plugin.reader.nfsreader.NfsReader",
"description": "read from nas file system",
"developer": "deepdata"
}
@@ -0,0 +1,7 @@
{
"name": "nfsreader",
"parameter": {
"ip": "127.0.0.1",
"path": "/test"
}
}
+77
View File
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datax-all</artifactId>
<groupId>com.alibaba.datax</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>nfswriter</artifactId>
<name>nfswriter</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-core</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- assembly plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
<include>plugin_job_template.json</include>
</includes>
<outputDirectory>plugin/writer/nfswriter</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>nfswriter-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/writer/nfswriter</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/writer/nfswriter/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,121 @@
package com.deepdata.edeepdata.plugin.writer.nfswriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
/**
* 一个简单的 Linux NAS 挂载工具类
* 仅适用于 Linux,需具备 sudo 权限或 root。
*/
public final class MountUtil {
private static final Logger LOG = LoggerFactory.getLogger(MountUtil.class);
private MountUtil() {
}
/**
* 挂载远程目录
*
* @param remote 远程地址,如 192.168.1.1:/test
* @param mountPoint 本地挂载点,如 /mnt/nas
* @param type 文件系统类型:nfs、cifs ...
* @param options 额外挂载参数,如 ro,vers=3 或 username=xxx,password=xxx
*/
public static void mount(String remote, String mountPoint, String type, String options) {
try {
Path mp = Paths.get(mountPoint);
if (isMounted(mountPoint)) {
throw new IOException("Already mounted: " + mountPoint);
}
Files.createDirectories(mp);
ProcessBuilder pb = new ProcessBuilder();
if (options == null || options.isEmpty()) {
pb.command("mount", "-t", type, remote, mountPoint);
} else {
pb.command("mount", "-t", type, "-o", options, remote, mountPoint);
}
LOG.info(pb.command().toString());
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("Mount failed, exit=" + rc + ", output: " + output);
}
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
/**
* 卸载挂载点
*
* @param mountPoint 挂载点路径
* @throws IOException 卸载失败
* @throws InterruptedException 进程等待中断
*/
public static void umount(String mountPoint) throws IOException, InterruptedException {
if (!isMounted(mountPoint)) {
return;
}
ProcessBuilder pb = new ProcessBuilder("umount", "-l", mountPoint);
pb.redirectErrorStream(true);
Process p = pb.start();
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(System.lineSeparator());
}
}
int rc = p.waitFor();
if (rc != 0) {
throw new RuntimeException("Mount failed, exit=" + rc + ", output: " + output);
}
// 清理空目录
try {
Files.deleteIfExists(Paths.get(mountPoint));
} catch (DirectoryNotEmptyException ignore) {
// 目录非空,保留
}
}
/**
* 判断挂载点是否已挂载
*
* @param mountPoint 挂载点路径
* @return true 表示已挂载
* @throws IOException 读取 /proc/mounts 失败
*/
public static boolean isMounted(String mountPoint) throws IOException {
Path procMounts = Paths.get("/proc/mounts");
if (!Files.exists(procMounts)) {
throw new IOException("/proc/mounts not found");
}
String expected = mountPoint.trim();
List<String> lines = Files.readAllLines(procMounts);
return lines.stream()
.map(l -> l.split("\\s+"))
.filter(a -> a.length >= 2)
.anyMatch(a -> a[1].equals(expected));
}
}
@@ -0,0 +1,100 @@
package com.deepdata.edeepdata.plugin.writer.nfswriter;
import com.alibaba.datax.common.element.Record;
import com.alibaba.datax.common.exception.CommonErrorCode;
import com.alibaba.datax.common.exception.DataXException;
import com.alibaba.datax.common.plugin.RecordReceiver;
import com.alibaba.datax.common.spi.Writer;
import com.alibaba.datax.common.util.Configuration;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class NfsWriter extends Writer {
public static class Job extends Writer.Job {
private Configuration jobConfig;
private String mountPoint;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
}
@Override
public void prepare() {
this.mountPoint = "/dataset/mount/" + UUID.randomUUID();
this.jobConfig.set("mountPoint", this.mountPoint);
new File(this.mountPoint).mkdirs();
MountUtil.mount(this.jobConfig.getString("ip") + ":" + this.jobConfig.getString("path"),
mountPoint, "nfs", StringUtils.EMPTY);
String destPath = this.jobConfig.getString("destPath");
new File(destPath).mkdirs();
}
@Override
public List<Configuration> split(int mandatoryNumber) {
return Collections.singletonList(this.jobConfig);
}
@Override
public void post() {
try {
MountUtil.umount(this.mountPoint);
new File(this.mountPoint).deleteOnExit();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
@Override
public void destroy() {
}
}
public static class Task extends Writer.Task {
private Configuration jobConfig;
private String mountPoint;
private String destPath;
private List<String> files;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
this.destPath = this.jobConfig.getString("destPath");
this.mountPoint = this.jobConfig.getString("mountPoint");
this.files = this.jobConfig.getList("files", Collections.emptyList(), String.class);
}
@Override
public void startWrite(RecordReceiver lineReceiver) {
try {
Record record;
while ((record = lineReceiver.getFromReader()) != null) {
String fileName = record.getColumn(0).asString();
if (StringUtils.isBlank(fileName)) {
continue;
}
if (!files.isEmpty() && !files.contains(fileName)) {
continue;
}
String filePath = this.mountPoint + "/" + fileName;
ShellUtil.runCommand("rsync", Arrays.asList("--no-links", "--chmod=754", "--", filePath,
this.destPath + "/" + fileName));
}
} catch (Exception e) {
throw DataXException.asDataXException(CommonErrorCode.RUNTIME_ERROR, e);
}
}
@Override
public void destroy() {
}
}
}
@@ -0,0 +1,43 @@
package com.deepdata.edeepdata.plugin.writer.nfswriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class ShellUtil {
/**
* 执行 rsync 命令
*
* @param cmd 命令
* @param extraArgs 额外参数,可为空
* @return 命令完整输出(stdout + stderr)
* @throws Exception 如果 rsync 返回非 0 或发生 IO 异常
*/
public static String runCommand(String cmd, List<String> extraArgs) throws Exception {
List<String> commands = new ArrayList<>();
commands.add(cmd);
if (extraArgs != null && !extraArgs.isEmpty()) {
commands.addAll(extraArgs);
}
ProcessBuilder pb = new ProcessBuilder(commands);
pb.redirectErrorStream(true); // 合并 stdout & stderr
Process p = pb.start();
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append(System.lineSeparator());
}
}
int exit = p.waitFor();
if (exit != 0) {
throw new RuntimeException("rsync exited with code " + exit + System.lineSeparator() + sb);
}
return sb.toString();
}
}
@@ -0,0 +1,6 @@
{
"name": "nfswriter",
"class": "com.deepdata.edeepdata.plugin.writer.nfswriter.NfsWriter",
"description": "write to local",
"developer": "deepdata"
}
@@ -0,0 +1,8 @@
{
"name": "nfswriter",
"parameter": {
"ip": "127.0.0.1",
"path": "/test",
"destPath": ""
}
}
+620
View File
@@ -0,0 +1,620 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>transformer/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<fileSet>
<directory>core/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<!-- reader -->
<fileSet>
<directory>mysqlreader/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<!-- <fileSet>-->
<!-- <directory>oceanbasev10reader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>obhbasereader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>drdsreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>oraclereader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>sqlserverreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>postgresqlreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>kingbaseesreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<fileSet>
<directory>rdbmsreader/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<!-- <fileSet>-->
<!-- <directory>odpsreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>otsreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>otsstreamreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>txtfilereader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>ossreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>mongodbreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>tdenginereader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>streamreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>ftpreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>clickhousereader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hdfsreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase11xreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase094xreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>opentsdbreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>cassandrareader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>gdbreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase11xsqlreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase20xsqlreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>tsdbreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>datahubreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>loghubreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<fileSet>
<directory>starrocksreader/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<!-- <fileSet>-->
<!-- <directory>dorisreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>sybasereader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>gaussdbreader/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<fileSet>
<directory>nfsreader/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<fileSet>
<directory>glusterfsreader/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<fileSet>
<directory>s3reader/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<fileSet>
<directory>apireader/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<!-- writer -->
<!-- <fileSet>-->
<!-- <directory>mysqlwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>tdenginewriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<fileSet>
<directory>starrockswriter/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<!-- <fileSet>-->
<!-- <directory>drdswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>odpswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>doriswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<fileSet>
<directory>txtfilewriter/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<!-- <fileSet>-->
<!-- <directory>ftpwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>osswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>adswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>streamwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>otswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>mongodbwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>oraclewriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>sqlserverwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>postgresqlwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>kingbaseeswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>rdbmswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>ocswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hdfswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase11xwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase094xwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase11xsqlwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>elasticsearchwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hbase20xsqlwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>tsdbwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>adbpgwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>cassandrawriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>clickhousewriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>databendwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>oscarwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>oceanbasev10writer/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>obhbasewriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>gdbwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>kuduwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>hologresjdbcwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>datahubwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>loghubwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>selectdbwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>neo4jwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>sybasewriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>gaussdbwriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<!-- <fileSet>-->
<!-- <directory>milvuswriter/target/datax/</directory>-->
<!-- <includes>-->
<!-- <include>**/*.*</include>-->
<!-- </includes>-->
<!-- <outputDirectory>datax</outputDirectory>-->
<!-- </fileSet>-->
<fileSet>
<directory>nfswriter/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<fileSet>
<directory>glusterfswriter/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
<fileSet>
<directory>s3writer/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
</fileSets>
</assembly>
+319
View File
@@ -0,0 +1,319 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-all</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<name>datax-all</name>
<packaging>pom</packaging>
<properties>
<jdk-version>1.8</jdk-version>
<datax-project-version>0.0.1-SNAPSHOT</datax-project-version>
<commons-lang3-version>3.3.2</commons-lang3-version>
<commons-configuration-version>1.10</commons-configuration-version>
<commons-cli-version>1.2</commons-cli-version>
<fastjson-version>2.0.23</fastjson-version>
<guava-version>16.0.1</guava-version>
<diamond.version>3.7.2.1-SNAPSHOT</diamond.version>
<!--slf4j 1.7.10 和 logback-classic 1.0.13 是好基友 -->
<slf4j-api-version>1.7.10</slf4j-api-version>
<logback-classic-version>1.0.13</logback-classic-version>
<commons-io-version>2.4</commons-io-version>
<junit-version>4.13.1</junit-version>
<tddl.version>5.1.22-1</tddl.version>
<swift-version>1.0.0</swift-version>
<amazon.awssdk-version>2.20.0</amazon.awssdk-version>
<project-sourceEncoding>UTF-8</project-sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<mysql.driver.version>8.0.33</mysql.driver.version>
</properties>
<modules>
<module>common</module>
<module>core</module>
<module>transformer</module>
<!-- reader -->
<module>mysqlreader</module>
<!-- <module>drdsreader</module>-->
<!-- <module>sqlserverreader</module>-->
<!-- <module>postgresqlreader</module>-->
<!-- <module>kingbaseesreader</module>-->
<!-- <module>oraclereader</module>-->
<!-- <module>cassandrareader</module>-->
<!-- <module>oceanbasev10reader</module>-->
<!-- <module>obhbasereader</module>-->
<module>rdbmsreader</module>
<!-- <module>odpsreader</module>-->
<!-- <module>otsreader</module>-->
<!-- <module>otsstreamreader</module>-->
<!-- <module>hbase11xreader</module>-->
<!-- <module>hbase094xreader</module>-->
<!-- <module>hbase11xsqlreader</module>-->
<!-- <module>hbase20xsqlreader</module>-->
<!-- <module>ossreader</module>-->
<!-- <module>hdfsreader</module>-->
<!-- <module>ftpreader</module>-->
<!-- <module>txtfilereader</module>-->
<!-- <module>streamreader</module>-->
<!-- <module>clickhousereader</module>-->
<!-- <module>mongodbreader</module>-->
<!-- <module>tdenginereader</module>-->
<!-- <module>gdbreader</module>-->
<!-- <module>tsdbreader</module>-->
<!-- <module>opentsdbreader</module>-->
<!-- <module>loghubreader</module>-->
<!-- <module>datahubreader</module>-->
<module>starrocksreader</module>
<!-- <module>sybasereader</module>-->
<!-- <module>dorisreader</module>-->
<module>nfsreader</module>
<module>glusterfsreader</module>
<module>s3reader</module>
<!-- writer -->
<!-- <module>mysqlwriter</module>-->
<module>starrockswriter</module>
<!-- <module>drdswriter</module>-->
<!-- <module>databendwriter</module>-->
<!-- <module>oraclewriter</module>-->
<!-- <module>sqlserverwriter</module>-->
<!-- <module>postgresqlwriter</module>-->
<!-- <module>kingbaseeswriter</module>-->
<!-- <module>adswriter</module>-->
<!-- <module>oceanbasev10writer</module>-->
<!-- <module>obhbasewriter</module>-->
<!-- <module>adbpgwriter</module>-->
<!-- <module>hologresjdbcwriter</module>-->
<!-- <module>rdbmswriter</module>-->
<!-- <module>odpswriter</module>-->
<!-- <module>osswriter</module>-->
<!-- <module>otswriter</module>-->
<!-- <module>hbase11xwriter</module>-->
<!-- <module>hbase094xwriter</module>-->
<!-- <module>hbase11xsqlwriter</module>-->
<!-- <module>hbase20xsqlwriter</module>-->
<!-- <module>kuduwriter</module>-->
<!-- <module>ftpwriter</module>-->
<!-- <module>hdfswriter</module>-->
<module>txtfilewriter</module>
<!-- <module>streamwriter</module>-->
<!-- <module>elasticsearchwriter</module>-->
<!-- <module>mongodbwriter</module>-->
<!-- <module>tdenginewriter</module>-->
<!-- <module>ocswriter</module>-->
<!-- <module>tsdbwriter</module>-->
<!-- <module>gdbwriter</module>-->
<!-- <module>oscarwriter</module>-->
<!-- <module>loghubwriter</module>-->
<!-- <module>datahubwriter</module>-->
<!-- <module>cassandrawriter</module>-->
<!-- <module>clickhousewriter</module>-->
<!-- <module>doriswriter</module>-->
<!-- <module>selectdbwriter</module>-->
<!-- <module>adbmysqlwriter</module>-->
<!-- <module>sybasewriter</module>-->
<!-- <module>neo4jwriter</module>-->
<!-- <module>milvuswriter</module>-->
<module>nfswriter</module>
<module>glusterfswriter</module>
<module>s3writer</module>
<!-- <module>gaussdbreader</module>-->
<!-- <module>gaussdbwriter</module>-->
<module>apireader</module>
<!-- common support module -->
<module>plugin-rdbms-util</module>
<module>plugin-unstructured-storage-util</module>
<!-- <module>datax-example</module>-->
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>${fastjson-version}</version>
</dependency>
<!--<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava-version}</version>
</dependency>-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api-version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-classic-version}</version>
</dependency>
<dependency>
<groupId>com.taobao.tddl</groupId>
<artifactId>tddl-client</artifactId>
<version>${tddl.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>com.taobao.diamond</groupId>
<artifactId>diamond-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.taobao.diamond</groupId>
<artifactId>diamond-client</artifactId>
<version>${diamond.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.search.swift</groupId>
<artifactId>swift_client</artifactId>
<version>${swift-version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>${amazon.awssdk-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>central</id>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/repository/central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring</id>
<name>spring</name>
<url>https://maven.aliyun.com/repository/spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/repository/central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<finalName>datax</finalName>
<descriptors>
<descriptor>package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
+132
View File
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datax-all</artifactId>
<groupId>com.alibaba.datax</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rdbmsreader</artifactId>
<name>rdbmsreader</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- dm7 dm8 driver -->
<dependency>
<groupId>com.dameng</groupId>
<artifactId>Dm7JdbcDriver17</artifactId>
<version>7.6.0.142</version>
</dependency>
<!-- sybase driver -->
<dependency>
<groupId>com.sybase</groupId>
<artifactId>jconn3</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/libs/jconn3-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<!-- ppas driver -->
<dependency>
<groupId>ppas</groupId>
<artifactId>ppas</artifactId>
<version>16</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/libs/edb-jdbc16.jar</systemPath>
</dependency>
<!-- db2 driver -->
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>db2jcc4</version>
</dependency>
<!-- sqlserver driver -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<!-- postgresql driver -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.3</version>
</dependency>
<!-- mysql driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.driver.version}</version>
</dependency>
<!-- opengauss driver -->
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>plugin-rdbms-util</artifactId>
<version>${datax-project-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- assembly plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,7 @@
{
"name": "rdbmsreader",
"class": "com.alibaba.datax.plugin.reader.rdbmsreader.RdbmsReader",
"description": "useScene: prod. mechanism: Jdbc connection using the database, execute select sql, retrieve data from the ResultSet. warn: The more you know about the database, the less problems you encounter.",
"developer": "alibaba",
"drivers":["dm.jdbc.driver.DmDriver", "com.sybase.jdbc3.jdbc.SybDriver", "com.edb.Driver", "com.ibm.db2.jcc.DB2Driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "org.postgresql.Driver", "org.opengauss.Driver", "com.mysql.cj.jdbc.Driver"]
}
+84
View File
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-all</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>s3reader</artifactId>
<name>s3reader</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-core</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
<include>plugin_job_template.json</include>
</includes>
<outputDirectory>plugin/reader/s3reader</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>s3reader-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/reader/s3reader</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/reader/s3reader/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,175 @@
package com.deepdata.plugin.reader.s3reader;
import java.net.IDN;
import java.net.InetAddress;
import java.net.URI;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
final class HttpEndpointSecurity {
private static final String ALLOWED_HOSTS_PROPERTY = "deepdata.ssrf.allowedHosts";
private static final String ALLOWED_HOSTS_ENV = "DEEPDATA_SSRF_ALLOWED_HOSTS";
private HttpEndpointSecurity() {
}
static URI validateExternalHttpUri(String rawUri, String fieldName) {
if (isBlank(rawUri)) {
throw new IllegalArgumentException(fieldName + " is required");
}
if (rawUri.indexOf('\r') >= 0 || rawUri.indexOf('\n') >= 0) {
throw new IllegalArgumentException(fieldName + " contains invalid control characters");
}
URI uri = URI.create(rawUri.trim()).normalize();
String scheme = uri.getScheme() == null ? null : uri.getScheme().toLowerCase(Locale.ROOT);
if (!"http".equals(scheme) && !"https".equals(scheme)) {
throw new IllegalArgumentException(fieldName + " only supports http or https");
}
if (!isBlank(uri.getUserInfo())) {
throw new IllegalArgumentException(fieldName + " must not contain user info");
}
if (uri.getFragment() != null) {
throw new IllegalArgumentException(fieldName + " must not contain fragment");
}
int port = uri.getPort();
if (port == 0 || port < -1 || port > 65535) {
throw new IllegalArgumentException(fieldName + " contains invalid port");
}
String asciiHost = toAsciiHost(uri.getHost(), fieldName);
if (isAllowedHost(asciiHost)) {
return uri;
}
InetAddress[] addresses;
try {
addresses = InetAddress.getAllByName(asciiHost);
} catch (Exception e) {
throw new IllegalArgumentException(fieldName + " host cannot be resolved", e);
}
if (addresses.length == 0) {
throw new IllegalArgumentException(fieldName + " host cannot be resolved");
}
for (InetAddress address : addresses) {
if (!isPublicRoutableAddress(address)) {
throw new IllegalArgumentException(fieldName + " points to a restricted network address");
}
}
return uri;
}
private static String toAsciiHost(String host, String fieldName) {
if (isBlank(host)) {
throw new IllegalArgumentException(fieldName + " must contain a valid host");
}
try {
String normalized = host.endsWith(".") ? host.substring(0, host.length() - 1) : host;
return IDN.toASCII(normalized, IDN.USE_STD3_ASCII_RULES).toLowerCase(Locale.ROOT);
} catch (Exception e) {
throw new IllegalArgumentException(fieldName + " contains invalid host", e);
}
}
private static boolean isAllowedHost(String host) {
return configuredAllowedHosts().contains(host);
}
private static Set<String> configuredAllowedHosts() {
Set<String> hosts = new HashSet<String>();
addConfiguredHosts(hosts, System.getProperty(ALLOWED_HOSTS_PROPERTY));
addConfiguredHosts(hosts, System.getenv(ALLOWED_HOSTS_ENV));
return hosts;
}
private static void addConfiguredHosts(Set<String> hosts, String rawHosts) {
if (isBlank(rawHosts)) {
return;
}
String[] parts = rawHosts.split(",");
for (String part : parts) {
if (!isBlank(part)) {
hosts.add(toAsciiHost(part.trim(), "allowed host"));
}
}
}
private static boolean isPublicRoutableAddress(InetAddress address) {
if (address.isAnyLocalAddress() || address.isLoopbackAddress() || address.isLinkLocalAddress()
|| address.isSiteLocalAddress() || address.isMulticastAddress()) {
return false;
}
byte[] bytes = address.getAddress();
if (bytes.length == 4) {
return isPublicRoutableIpv4(bytes);
}
if (bytes.length == 16) {
return isPublicRoutableIpv6(bytes);
}
return false;
}
private static boolean isPublicRoutableIpv4(byte[] bytes) {
int first = bytes[0] & 0xff;
int second = bytes[1] & 0xff;
int third = bytes[2] & 0xff;
if (first == 0 || first == 10 || first == 127 || first >= 224) {
return false;
}
if (first == 100 && second >= 64 && second <= 127) {
return false;
}
if (first == 169 && second == 254) {
return false;
}
if (first == 172 && second >= 16 && second <= 31) {
return false;
}
if (first == 192 && second == 168) {
return false;
}
if (first == 192 && second == 0 && (third == 0 || third == 2)) {
return false;
}
if (first == 198 && (second == 18 || second == 19 || (second == 51 && third == 100))) {
return false;
}
if (first == 203 && second == 0 && third == 113) {
return false;
}
return true;
}
private static boolean isPublicRoutableIpv6(byte[] bytes) {
int first = bytes[0] & 0xff;
int second = bytes[1] & 0xff;
if ((first & 0xfe) == 0xfc) {
return false;
}
if (first == 0xfe && (second & 0xc0) == 0x80) {
return false;
}
if (first == 0x20 && second == 0x01 && (bytes[2] & 0xff) == 0x0d && (bytes[3] & 0xff) == 0xb8) {
return false;
}
return !isIpv4MappedPrivateAddress(bytes);
}
private static boolean isIpv4MappedPrivateAddress(byte[] bytes) {
for (int i = 0; i < 10; i++) {
if (bytes[i] != 0) {
return false;
}
}
if ((bytes[10] & 0xff) != 0xff || (bytes[11] & 0xff) != 0xff) {
return false;
}
byte[] ipv4 = new byte[] {bytes[12], bytes[13], bytes[14], bytes[15]};
return !isPublicRoutableIpv4(ipv4);
}
private static boolean isBlank(String value) {
return value == null || value.trim().isEmpty();
}
}
@@ -0,0 +1,224 @@
package com.deepdata.plugin.reader.s3reader;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import com.alibaba.datax.common.element.Record;
import com.alibaba.datax.common.element.StringColumn;
import com.alibaba.datax.common.exception.CommonErrorCode;
import com.alibaba.datax.common.exception.DataXException;
import com.alibaba.datax.common.plugin.RecordSender;
import com.alibaba.datax.common.spi.Reader;
import com.alibaba.datax.common.util.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
import software.amazon.awssdk.services.s3.model.S3Object;
import software.amazon.awssdk.services.s3.S3Configuration;
/**
* S3兼容对象存储读取器
* 支持自定义 S3 兼容对象存储(如 MinIO、Ceph 等)
*/
public class S3Reader extends Reader {
private static final Logger LOG = LoggerFactory.getLogger(S3Reader.class);
public static class Job extends Reader.Job {
private Configuration jobConfig = null;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
}
@Override
public void prepare() {
String endpoint = this.jobConfig.getString("endpoint");
String bucket = this.jobConfig.getString("bucket");
String accessKey = this.jobConfig.getString("accessKey");
String secretKey = this.jobConfig.getString("secretKey");
if (StringUtils.isBlank(endpoint)) {
throw new RuntimeException("endpoint is required for s3reader");
}
HttpEndpointSecurity.validateExternalHttpUri(endpoint, "endpoint");
if (StringUtils.isBlank(bucket)) {
throw new RuntimeException("bucket is required for s3reader");
}
if (StringUtils.isBlank(accessKey)) {
throw new RuntimeException("accessKey is required for s3reader");
}
if (StringUtils.isBlank(secretKey)) {
throw new RuntimeException("secretKey is required for s3reader");
}
}
@Override
public List<Configuration> split(int adviceNumber) {
return Collections.singletonList(this.jobConfig);
}
@Override
public void post() {
}
@Override
public void destroy() {
}
}
public static class Task extends Reader.Task {
private Configuration jobConfig;
private Set<String> fileType;
private String endpoint;
private String accessKey;
private String secretKey;
private String bucket;
private String prefix;
private String region;
private S3Client s3;
private String effectivePrefix;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
this.fileType = new HashSet<>(this.jobConfig.getList("fileType", Collections.emptyList(), String.class));
this.endpoint = this.jobConfig.getString("endpoint");
this.accessKey = this.jobConfig.getString("accessKey");
this.secretKey = this.jobConfig.getString("secretKey");
this.bucket = this.jobConfig.getString("bucket");
this.prefix = this.jobConfig.getString("prefix");
// OBS也是默认us-east-1,这里保留默认值
this.region = this.jobConfig.getString("region", "us-east-1");
HttpEndpointSecurity.validateExternalHttpUri(this.endpoint, "endpoint");
this.s3 = getS3Client();
this.effectivePrefix = getEffectivePrefix();
}
@Override
public void startRead(RecordSender recordSender) {
try {
List<String> files = listFiles().stream()
.filter(file -> fileType.isEmpty() || fileType.contains(getFileSuffix(file)))
.collect(Collectors.toList());
files.forEach(filePath -> {
Record record = recordSender.createRecord();
record.addColumn(new StringColumn(filePath));
recordSender.sendToWriter(record);
});
this.jobConfig.set("columnNumber", 1);
} catch (Exception e) {
LOG.error("Error reading files from S3 compatible storage: {}", this.endpoint, e);
throw new RuntimeException(e);
}
}
/**
* 列举 S3 对象
* 非递归:只列举 prefix 当前目录下的对象(通过 delimiter="/" 实现)
*/
private List<String> listFiles() {
if (StringUtils.isBlank(endpoint) || StringUtils.isBlank(bucket)) {
throw new IllegalArgumentException("endpoint and bucket must be provided");
}
List<String> keys = new ArrayList<>();
String continuationToken = null;
try {
do {
ListObjectsV2Request.Builder reqBuilder = ListObjectsV2Request.builder()
.bucket(bucket)
.prefix(effectivePrefix)
/*.delimiter("/")*/ /* xuhuanqing 将其设置为递归 */;
if (continuationToken != null) {
reqBuilder.continuationToken(continuationToken);
}
ListObjectsV2Response res = s3.listObjectsV2(reqBuilder.build());
for (S3Object obj : res.contents()) {
String key = obj.key();
if (isInValid(key)) {
continue;
}
keys.add(key);
}
continuationToken = res.isTruncated() ? res.nextContinuationToken() : null;
} while (continuationToken != null);
} catch (Exception e) {
LOG.warn("Failed to list S3 objects: {}", e.getMessage(), e);
}
return keys;
}
private boolean isInValid(String key) {
if (!effectivePrefix.isEmpty() && !key.startsWith(effectivePrefix)) {
return true;
}
if (key.equals(effectivePrefix) || key.endsWith("/")) {
return true;
}
return false;
}
private String getEffectivePrefix() {
String effectivePrefix = "";
if (prefix != null) {
effectivePrefix = prefix.startsWith("/") ? prefix.substring(1) : prefix;
if (!effectivePrefix.isEmpty() && !effectivePrefix.endsWith("/")) {
effectivePrefix = effectivePrefix + "/";
}
}
return effectivePrefix;
}
private S3Client getS3Client() {
try {
AwsBasicCredentials creds = AwsBasicCredentials.create(accessKey, secretKey);
S3Configuration serviceConfig = S3Configuration.builder()
.pathStyleAccessEnabled(true)
.build();
return S3Client.builder()
.endpointOverride(HttpEndpointSecurity.validateExternalHttpUri(endpoint, "endpoint"))
.region(Region.of(region))
.serviceConfiguration(serviceConfig)
.credentialsProvider(StaticCredentialsProvider.create(creds))
.build();
} catch (Exception e) {
LOG.error("Error init S3 client: {}", this.endpoint, e);
throw DataXException.asDataXException(CommonErrorCode.RUNTIME_ERROR, e);
}
}
private String getFileSuffix(String key) {
String fileName = Paths.get(key).getFileName().toString();
int lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex == -1 || lastDotIndex == fileName.length() - 1) {
return "";
}
return fileName.substring(lastDotIndex + 1);
}
@Override
public void destroy() {
if (s3 != null) {
try {
s3.close();
} catch (Exception ignore) {
}
}
}
}
}
@@ -0,0 +1,6 @@
{
"name": "s3reader",
"class": "com.deepdata.plugin.reader.s3reader.S3Reader",
"description": "read from S3 compatible object storage",
"developer": "deepdata"
}
@@ -0,0 +1,11 @@
{
"name": "s3reader",
"parameter": {
"endpoint": "https://s3.example.com",
"bucket": "test-bucket",
"accessKey": "ak-xxx",
"secretKey": "sk-xxx",
"prefix": "/test",
"region": "us-east-1"
}
}
@@ -0,0 +1,84 @@
package com.deepdata.plugin.reader.s3reader;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class HttpEndpointSecurityTest {
@Test(expected = IllegalArgumentException.class)
public void shouldRejectLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://127.0.0.1:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectLocalhost() {
HttpEndpointSecurity.validateExternalHttpUri("http://localhost:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectIpv6LoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://[::1]:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectIpv4MappedIpv6LoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://[::ffff:127.0.0.1]:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectIntegerEncodedLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://2130706433:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectHexEncodedLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://0x7f000001:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectOctalEncodedLoopbackHost() {
HttpEndpointSecurity.validateExternalHttpUri("http://017700000001:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectMetadataServiceAddress() {
HttpEndpointSecurity.validateExternalHttpUri("http://169.254.169.254/latest/meta-data", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectPrivateNetworkAddress() {
HttpEndpointSecurity.validateExternalHttpUri("http://192.168.1.10:9000", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectUnsupportedScheme() {
HttpEndpointSecurity.validateExternalHttpUri("gopher://8.8.8.8:70", "endpoint");
}
@Test(expected = IllegalArgumentException.class)
public void shouldRejectUserInfo() {
HttpEndpointSecurity.validateExternalHttpUri("http://user@8.8.8.8:9000", "endpoint");
}
@Test
public void shouldAllowPublicHttpAddress() {
assertEquals("8.8.8.8",
HttpEndpointSecurity.validateExternalHttpUri("https://8.8.8.8:9000", "endpoint").getHost());
}
@Test
public void shouldAllowExplicitlyConfiguredHost() {
String previous = System.getProperty("deepdata.ssrf.allowedHosts");
try {
System.setProperty("deepdata.ssrf.allowedHosts", "localhost");
assertEquals("localhost",
HttpEndpointSecurity.validateExternalHttpUri("http://localhost:9000", "endpoint").getHost());
} finally {
if (previous == null) {
System.clearProperty("deepdata.ssrf.allowedHosts");
} else {
System.setProperty("deepdata.ssrf.allowedHosts", previous);
}
}
}
}
+79
View File
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-all</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>s3writer</artifactId>
<name>s3writer</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-core</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>${datax-project-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<finalName>datax</finalName>
</configuration>
<executions>
<execution>
<id>dwzip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
<include>plugin_job_template.json</include>
</includes>
<outputDirectory>plugin/writer/s3writer</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>s3writer-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/writer/s3writer</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/writer/s3writer/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,181 @@
package com.deepdata.plugin.writer.s3writer;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.alibaba.datax.common.element.Record;
import com.alibaba.datax.common.exception.CommonErrorCode;
import com.alibaba.datax.common.exception.DataXException;
import com.alibaba.datax.common.plugin.RecordReceiver;
import com.alibaba.datax.common.spi.Writer;
import com.alibaba.datax.common.util.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.sync.ResponseTransformer;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
/**
* S3兼容对象存储写入器
* 从S3兼容存储下载文件到本地目标目录
*/
public class S3Writer extends Writer {
private static final Logger LOG = LoggerFactory.getLogger(S3Writer.class);
public static class Job extends Writer.Job {
private Configuration jobConfig = null;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
}
@Override
public void prepare() {
String destPath = this.jobConfig.getString("destPath");
if (StringUtils.isBlank(destPath)) {
throw new RuntimeException("destPath is required for s3writer");
}
try {
Files.createDirectories(Paths.get(destPath));
} catch (IOException e) {
throw new RuntimeException("Failed to create destination directory: " + destPath, e);
}
}
@Override
public List<Configuration> split(int adviceNumber) {
return Collections.singletonList(this.jobConfig);
}
@Override
public void post() {
}
@Override
public void destroy() {
}
}
public static class Task extends Writer.Task {
private Configuration jobConfig;
private Set<String> fileType;
private String endpoint;
private String accessKey;
private String secretKey;
private String bucket;
private String destPath;
private String region;
private S3Client s3;
@Override
public void init() {
this.jobConfig = super.getPluginJobConf();
this.fileType = new HashSet<>(this.jobConfig.getList("fileType", Collections.emptyList(), String.class));
this.endpoint = this.jobConfig.getString("endpoint");
this.accessKey = this.jobConfig.getString("accessKey");
this.secretKey = this.jobConfig.getString("secretKey");
this.bucket = this.jobConfig.getString("bucket");
this.destPath = this.jobConfig.getString("destPath");
this.region = this.jobConfig.getString("region", "us-east-1");
this.s3 = getS3Client();
}
private S3Client getS3Client() {
try {
AwsBasicCredentials creds = AwsBasicCredentials.create(accessKey, secretKey);
S3Configuration serviceConfig = S3Configuration.builder()
.pathStyleAccessEnabled(true)
.build();
return S3Client.builder()
.endpointOverride(new URI(endpoint))
.region(Region.of(region))
.serviceConfiguration(serviceConfig)
.credentialsProvider(StaticCredentialsProvider.create(creds))
.build();
} catch (Exception e) {
LOG.error("Error init S3 client: {}", this.endpoint, e);
throw DataXException.asDataXException(CommonErrorCode.RUNTIME_ERROR, e);
}
}
@Override
public void startWrite(RecordReceiver lineReceiver) {
try {
Record record;
while ((record = lineReceiver.getFromReader()) != null) {
String key = record.getColumn(0).asString();
if (StringUtils.isBlank(key)) {
continue;
}
copyFileFromS3(key);
}
} catch (Exception e) {
LOG.error("Error writing files from S3 compatible storage: {}", this.endpoint, e);
throw DataXException.asDataXException(CommonErrorCode.RUNTIME_ERROR, e);
}
}
private void copyFileFromS3(String key) throws IOException {
if (StringUtils.isBlank(endpoint) || StringUtils.isBlank(bucket)) {
throw new IllegalArgumentException("endpoint and bucket must be provided");
}
try {
Path targetDir = Paths.get(destPath);
try {
Files.createDirectories(targetDir);
} catch (IOException e) {
LOG.warn("Create dest dir {} failed: {}", targetDir, e.getMessage(), e);
}
String fileName = Paths.get(key).getFileName().toString();
if (StringUtils.isBlank(fileName)) {
LOG.warn("Skip object with empty file name for key {}", key);
return;
}
Path target = targetDir.resolve(fileName);
try {
if (Files.exists(target)) {
Files.delete(target);
}
GetObjectRequest getReq = GetObjectRequest.builder()
.bucket(bucket)
.key(key)
.build();
s3.getObject(getReq, ResponseTransformer.toFile(target));
LOG.info("Downloaded S3 object {} to {}", key, target.toString());
} catch (Exception ex) {
LOG.warn("Failed to download object {}: {}", key, ex.getMessage(), ex);
}
} catch (Exception e) {
LOG.warn("Failed to download object {}: {}", key, e.getMessage(), e);
}
}
@Override
public void destroy() {
if (s3 != null) {
try {
s3.close();
} catch (Exception ignore) {
}
}
}
}
}
@@ -0,0 +1,6 @@
{
"name": "s3writer",
"class": "com.deepdata.plugin.writer.s3writer.S3Writer",
"description": "write S3 compatible object storage files to local",
"developer": "deepdata"
}
@@ -0,0 +1,12 @@
{
"name": "s3writer",
"parameter": {
"endpoint": "http://127.0.0.1:9000",
"bucket": "test-bucket",
"accessKey": "ak-xxx",
"secretKey": "sk-xxx",
"prefix": "/test",
"region": "us-east-1",
"destPath": "/data/dest"
}
}