mirror of
https://github.com/WeiYe-Jing/datax-web.git
synced 2026-07-03 21:08:58 +08:00
add:
1.mybatis and swagger init
This commit is contained in:
parent
c824c8d273
commit
58af580f84
12
README.md
12
README.md
@ -10,13 +10,13 @@ jdk1.8
|
||||
* [x] springboot重构项目
|
||||
* [x] 通过restful接口调度datax完成抽取数据作业
|
||||
* [x] 通过restful接口传入job配置json生成临时文件,根据文件配置调度datax执行该作业
|
||||
* [ ] 集成swagger,方便调试
|
||||
* [ ] 实现datax分布式作业
|
||||
* [ ] 网页端修改job配置的json
|
||||
* [ ] 网页端实时查看抽取日志
|
||||
* [ ] 网页端各种插件模板生成
|
||||
* [ ] job配置持久化到db
|
||||
* [x] 集成swagger,方便调试
|
||||
* [x] 集成mybatis plus和h2数据库存放应用数据
|
||||
* [ ] 网页端修改并持久化job配置的json到数据库
|
||||
* [ ] 网页端实时查看抽取日志,类似Jenkins的日志控制台输出功能
|
||||
* [ ] 网页端各种读写插件模板生成,可以在页面组装使用
|
||||
* [ ] 精简assembly打包结构
|
||||
* [ ] 实现datax分布式作业
|
||||
|
||||
|
||||
## how to run
|
||||
|
||||
@ -33,6 +33,11 @@
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
<version>${commons-configuration-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
|
||||
@ -251,7 +251,8 @@ public class Engine {
|
||||
}
|
||||
}
|
||||
|
||||
//todo 都是用同一个文件,是否需要考虑线程安全问题
|
||||
// todo 都是用同一个文件,是否需要考虑线程安全问题
|
||||
// 需要做成异步的,否则前端会一直loading等待完成作业
|
||||
public static void startJobByJsonStr(String jobJson) {
|
||||
String tmpFilePath = "jobTmp.conf-"+ System.currentTimeMillis();
|
||||
// 根据json写入到临时本地文件
|
||||
@ -285,7 +286,6 @@ public class Engine {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//删除临时文件
|
||||
FileUtil.del(new File("jobTmp.conf"));
|
||||
}
|
||||
|
||||
@ -16,9 +16,40 @@
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<mybatisplus.version>3.0.7.1</mybatisplus.version>
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Mybatis Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatisplus.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>${mybatisplus.version}</version>
|
||||
</dependency>
|
||||
<!-- 接口管理 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
||||
@ -2,7 +2,9 @@ package com.wugui.dataxweb;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@EnableSwagger2
|
||||
@SpringBootApplication
|
||||
public class DataxWebApplication{
|
||||
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package com.wugui.dataxweb.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 通用的字段填充,如createBy createDate这些字段的自动填充
|
||||
* @author huzekang
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MybatisMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
log.debug("start insert fill ....");
|
||||
//todo createBy
|
||||
Date date = new Date();
|
||||
this.setInsertFieldValByName("createDate", date, metaObject);
|
||||
this.setInsertFieldValByName("updateDate", date, metaObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
//todo updateBY
|
||||
log.debug("start update fill ....");
|
||||
Date date = new Date();
|
||||
this.setUpdateFieldValByName("updateDate", date, metaObject);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.wugui.dataxweb.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* MybatisPlus配置类 Spring boot方式
|
||||
* @author huzekang
|
||||
*/
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
@MapperScan("com.wugui.dataxweb.dao")
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
|
||||
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
|
||||
return paginationInterceptor.setOverflow(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* MyBatisPlus逻辑删除 ,需要在 yml 中配置开启
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ISqlInjector sqlInjector() {
|
||||
return new LogicSqlInjector();
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
package com.wugui.dataxweb.controller;
|
||||
|
||||
import com.alibaba.datax.core.Engine;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@ -13,7 +15,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @create: 2019-05-05 14:21
|
||||
**/
|
||||
@RestController
|
||||
public class JobContentController {
|
||||
@Api(tags = "datax作业接口")
|
||||
public class JobController {
|
||||
|
||||
@GetMapping("/testStartJob")
|
||||
public void testStartJob() {
|
||||
@ -77,6 +80,7 @@ public class JobContentController {
|
||||
}
|
||||
|
||||
@GetMapping("/mock_stream2stream")
|
||||
@ApiOperation("提供stream2stream的配置")
|
||||
public String mock2() {
|
||||
return "{\n" +
|
||||
" \"job\": {\n" +
|
||||
@ -121,6 +125,7 @@ public class JobContentController {
|
||||
* @param jobJson
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("通过传入json配置启动一个datax作业")
|
||||
@PostMapping("/runJob")
|
||||
public String runJob(@RequestBody String jobJson) {
|
||||
Engine.startJobByJsonStr(jobJson);
|
||||
@ -0,0 +1,7 @@
|
||||
package com.wugui.dataxweb.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.wugui.dataxweb.entity.JobConfig;
|
||||
|
||||
public interface JobConfigMapper extends BaseMapper<JobConfig> {
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.wugui.dataxweb.dao.JobConfigMapper">
|
||||
<resultMap id="BaseResultMap" type="com.wugui.dataxweb.entity.JobConfig">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
-->
|
||||
<id column="ID" jdbcType="INTEGER" property="id" />
|
||||
<result column="CONFIG" jdbcType="VARCHAR" property="config" />
|
||||
<result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate" />
|
||||
<result column="CREATE_BY" jdbcType="INTEGER" property="createBy" />
|
||||
<result column="UPDATE_BY" jdbcType="INTEGER" property="updateBy" />
|
||||
<result column="UPDATE_DATE" jdbcType="TIMESTAMP" property="updateDate" />
|
||||
<result column="STATUS" jdbcType="INTEGER" property="status" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
-->
|
||||
ID, CONFIG, CREATE_DATE, CREATE_BY, UPDATE_BY, UPDATE_DATE, "STATUS"
|
||||
</sql>
|
||||
</mapper>
|
||||
@ -0,0 +1,37 @@
|
||||
package com.wugui.dataxweb.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName(value = "JOB_CONFIG")
|
||||
public class JobConfig {
|
||||
@TableId(value = "ID", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@TableField(value = "CONFIG")
|
||||
private String config;
|
||||
|
||||
@TableField(value = "CREATE_DATE")
|
||||
private Date createDate;
|
||||
|
||||
@TableField(value = "CREATE_BY")
|
||||
private Integer createBy;
|
||||
|
||||
@TableField(value = "UPDATE_BY")
|
||||
private Integer updateBy;
|
||||
|
||||
@TableField(value = "UPDATE_DATE")
|
||||
private Date updateDate;
|
||||
|
||||
@TableField(value = "STATUS")
|
||||
private Integer status;
|
||||
|
||||
@TableField(value = "USER_ID")
|
||||
private Integer userID;
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
package com.wugui.dataxweb.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.wugui.dataxweb.dao.JobConfigMapper;
|
||||
import com.wugui.dataxweb.entity.JobConfig;
|
||||
import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class JobConfigService extends ServiceImpl<JobConfigMapper, JobConfig>{
|
||||
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
|
||||
41
datax-web/src/main/resources/application.yml
Normal file
41
datax-web/src/main/resources/application.yml
Normal file
@ -0,0 +1,41 @@
|
||||
spring:
|
||||
#数据源
|
||||
datasource:
|
||||
username: root
|
||||
password: root
|
||||
url: jdbc:h2:file:~/H2Data/datax-web;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
|
||||
driver-class-name: org.h2.Driver
|
||||
h2:
|
||||
console:
|
||||
enabled: true
|
||||
path: /h2-console
|
||||
settings:
|
||||
web-allow-others: true
|
||||
|
||||
|
||||
mybatis-plus:
|
||||
# mapper.xml文件扫描
|
||||
mapper-locations: classpath*:com/wugui/**/dao/mapping/*.xml
|
||||
# 实体扫描,多个package用逗号或者分号分隔
|
||||
#typeAliasesPackage: com.yibo.essyncclient.*.entity
|
||||
global-config:
|
||||
# 数据库相关配置
|
||||
db-config:
|
||||
# 主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
|
||||
id-type: AUTO
|
||||
# 字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
|
||||
field-strategy: NOT_NULL
|
||||
# 驼峰下划线转换
|
||||
column-underline: true
|
||||
# 逻辑删除
|
||||
logic-delete-value: 0
|
||||
logic-not-delete-value: 1
|
||||
# 数据库类型
|
||||
db-type: h2
|
||||
banner: false
|
||||
# mybatis原生配置
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: false
|
||||
call-setters-on-nulls: true
|
||||
jdbc-type-for-null: 'null'
|
||||
@ -1,7 +1,10 @@
|
||||
package com.wugui.dataxweb;
|
||||
|
||||
import com.wugui.dataxweb.dao.JobConfigMapper;
|
||||
import com.wugui.dataxweb.entity.JobConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@ -9,8 +12,14 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
@SpringBootTest
|
||||
public class DataxWebApplicationTests {
|
||||
|
||||
@Autowired
|
||||
JobConfigMapper jobConfigMapper;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
JobConfig jobConfig = new JobConfig();
|
||||
jobConfig.setConfig("{}");
|
||||
jobConfigMapper.insert(jobConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user