You've already forked DataMate
feature:数据集导入数据集支持选择归集任务导入 (#92)
* feature: 实现obs归集 * feature: 增加数据集中出现同名文件时的处理方式 * feature: 前端数据集导入数据时增加可以选择归集任务导入
This commit is contained in:
@@ -6,6 +6,7 @@ import com.datamate.collection.domain.model.entity.CollectionTask;
|
||||
import com.datamate.collection.domain.process.ProcessRunner;
|
||||
import com.datamate.collection.infrastructure.datax.config.MysqlConfig;
|
||||
import com.datamate.collection.infrastructure.datax.config.NasConfig;
|
||||
import com.datamate.collection.infrastructure.datax.config.ObsConfig;
|
||||
import com.datamate.common.infrastructure.exception.BusinessException;
|
||||
import com.datamate.common.infrastructure.exception.SystemErrorCode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -92,18 +93,21 @@ public class DataxProcessRunner implements ProcessRunner {
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
TemplateType templateType = task.getTaskType();
|
||||
switch (templateType) {
|
||||
case NAS:
|
||||
return switch (templateType) {
|
||||
case NAS -> {
|
||||
// NAS 特殊处理
|
||||
NasConfig nasConfig = objectMapper.readValue(task.getConfig(), NasConfig.class);
|
||||
return nasConfig.toJobConfig(objectMapper, task);
|
||||
case OBS:
|
||||
case MYSQL:
|
||||
yield nasConfig.toJobConfig(objectMapper, task);
|
||||
}
|
||||
case OBS -> {
|
||||
ObsConfig obsConfig = objectMapper.readValue(task.getConfig(), ObsConfig.class);
|
||||
yield obsConfig.toJobConfig(objectMapper, task);
|
||||
}
|
||||
case MYSQL -> {
|
||||
MysqlConfig mysqlConfig = objectMapper.readValue(task.getConfig(), MysqlConfig.class);
|
||||
return mysqlConfig.toJobConfig(objectMapper, task);
|
||||
default:
|
||||
throw BusinessException.of(SystemErrorCode.UNKNOWN_ERROR, "Unsupported template type: " + templateType);
|
||||
}
|
||||
yield mysqlConfig.toJobConfig(objectMapper, task);
|
||||
}
|
||||
};
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to parse task config", e);
|
||||
throw new RuntimeException("Failed to parse task config", e);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.datamate.collection.infrastructure.datax.config;
|
||||
|
||||
import com.datamate.collection.domain.model.entity.CollectionTask;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* OBS 归集配置类
|
||||
*
|
||||
* @since 2025/11/18
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ObsConfig implements BaseConfig{
|
||||
private String endpoint;
|
||||
private String bucket;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* 将当前 OBS 配置构造成 DataX 所需的 job JSON 字符串。
|
||||
*/
|
||||
public String toJobConfig(ObjectMapper objectMapper, CollectionTask task) throws Exception {
|
||||
Map<String, Object> parameter = new HashMap<>();
|
||||
if (endpoint != null) parameter.put("endpoint", endpoint);
|
||||
if (bucket != null) parameter.put("bucket", bucket);
|
||||
if (accessKey != null) parameter.put("accessKey", accessKey);
|
||||
if (secretKey != null) parameter.put("secretKey", secretKey);
|
||||
if (prefix != null) parameter.put("prefix", prefix);
|
||||
parameter.put("destPath", task.getTargetPath());
|
||||
|
||||
Map<String, Object> job = new HashMap<>();
|
||||
Map<String, Object> content = new HashMap<>();
|
||||
Map<String, Object> reader = new HashMap<>();
|
||||
reader.put("name", "obsreader");
|
||||
reader.put("parameter", parameter);
|
||||
content.put("reader", reader);
|
||||
|
||||
Map<String, Object> writer = new HashMap<>();
|
||||
writer.put("name", "obswriter");
|
||||
writer.put("parameter", parameter);
|
||||
content.put("writer", writer);
|
||||
|
||||
job.put("content", List.of(content));
|
||||
Map<String, Object> setting = new HashMap<>();
|
||||
Map<String, Object> channel = new HashMap<>();
|
||||
channel.put("channel", 2);
|
||||
setting.put("speed", channel);
|
||||
job.put("setting", setting);
|
||||
|
||||
Map<String, Object> jobConfig = new HashMap<>();
|
||||
jobConfig.put("job", job);
|
||||
return objectMapper.writeValueAsString(jobConfig);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user