springboot项目集成dolphinscheduler调度器 项目管理

在这里插入图片描述

dolphinscheduler调度器接入注意事项等信息可参考我的上一篇博客进行了解,地址在这里 ->

一、功能清单

在这里插入图片描述

二、项目管理

说明:项目管理统一用dolphinscheduler调度器的admin用户token执行

共用的依赖

<!--httpclient-->
<dependency>
    <groupId>commons-httpclient</groupId>
    <artifactId>commons-httpclient</artifactId>
    <version>3.1</version>
</dependency>

共用配置文件

dolphinscheduler.token=xxx
dolphinscheduler.address=http://IP:12345

共用代码

@Autowired
private RestTemplate restTemplate;
@Value("${dolphinscheduler.token}")
String token;
@Value("${dolphinscheduler.address}")
String address;
public static final int ZERO = 0;
public static final int SUCCESS = 200;
@Autowired
private DragSparkTaskService dragSparkTaskService;
@Value("${spark.main.class}")
String mainClass;
public static final String CREATE = "create";
public static final String UPDATE = "update";
public static final String ADD = "add";
public static final String DELETE = "delete";
public static final String ONLINE = "ONLINE";
public static final String OFFLINE = "OFFLINE";
public static final int ONE_THOUSAND_AND_FIVE_HUNDRED = 1500;
public static final int SIX = 6;
public static final int EIGHTY = 80;
public static final int THREE = 3;
@Autowired
private StringRedisTemplate redisTemplate;
@Value("${drag.task.state}")
String dragTaskState;
@Autowired
private DragSparkTaskMapper dragSparkTaskMapper;

1.查询项目列表

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码

/**
     * 查询项目列表
     * @param pageNo 当前页
     * @param pageSize 每页显示数量
     * @param searchVal 模糊搜索值
     * @author liudz
     * @date 2021/5/7
     * @return 执行结果
     **/
    @GetMapping("/project/list")
    public Response getProjectList(@RequestParam int pageNo, @RequestParam int pageSize,
        @RequestParam(required = false) String searchVal) {
        HttpHeaders headers = new HttpHeaders();
        headers.set("token", token);
        headers.set("Content-Type", "application/json");
        HttpEntity requestEntity = new HttpEntity(headers);
        String url = "";
        if (StringUtils.isEmpty(searchVal)) {
            url = address + "/dolphinscheduler/projects/list-paging?pageNo=" + pageNo + "&pageSize=" + pageSize;
        } else {
            url = address + "/dolphinscheduler/projects/list-paging?pageNo=" + pageNo + "&pageSize=" + pageSize
                + "&searchVal=" + searchVal;
        }
        ResponseEntity<DolphinschedulerResponse> response =
            restTemplate.exchange(url, HttpMethod.GET, requestEntity, DolphinschedulerResponse.class);
        return Response.success(response.getBody().getData());
    }

2.创建项目

在这里插入图片描述
代码

/**
     * 创建项目
     * @param projectDto 项目参数
     * @author liudz
     * @date 2021/5/7
     * @return 执行结果
     **/
    @PostMapping("/project/creat")
    public Response creatProject(@RequestBody ProjectDto projectDto) {
        try {
            String postURL = address + "/dolphinscheduler/projects/create";
            PostMethod postMethod = new PostMethod(postURL);
            postMethod.setRequestHeader("Content-Type",
                    "application/x-www-form-urlencoded;charset=utf-8");
            postMethod.setRequestHeader("token", token);
            // 参数设置,需要注意的就是里边不能传NULL,要传空字符串
            NameValuePair[] data = {new NameValuePair("projectName", projectDto.getProjectName()),
                new NameValuePair("description", projectDto.getDescription())};
            postMethod.setRequestBody(data);
            org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
            httpClient.executeMethod(postMethod);
            JSONObject result = JSONObject.parseObject(postMethod.getResponseBodyAsString());
            if (!result.get(DictionaryEnum.CODE.getFiledString()).equals(ZERO)) {
                return Response.error(result.getInteger("code"), result.getString("msg"));
            }
        } catch (Exception e) {
            log.info("请求异常:{}", e);
        }
        return Response.success();
    }

3.更新项目

在这里插入图片描述
代码

/**
     * 更新项目
     * @param projectDto 项目参数
     * @author liudz
     * @date 2021/5/7
     * @return 执行结果
     **/
    @PutMapping("/project/update")
    public Response updateProject(@RequestBody ProjectDto projectDto) {
        try {
            String postURL = address + "/dolphinscheduler/projects/update";
            PostMethod postMethod = new PostMethod(postURL);
            postMethod.setRequestHeader("Content-Type",
                    "application/x-www-form-urlencoded;charset=utf-8");
            postMethod.setRequestHeader("token", token);
            // 参数设置,需要注意的就是里边不能传NULL,要传空字符串
            NameValuePair[] data = {
                new NameValuePair("projectName", projectDto.getProjectName()),
                new NameValuePair("projectId", projectDto.getProjectId().toString()),
                new NameValuePair("description", projectDto.getDescription())};
            postMethod.setRequestBody(data);
            org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
            httpClient.executeMethod(postMethod);
            JSONObject result = JSONObject.parseObject(postMethod.getResponseBodyAsString());
            if (!result.get(DictionaryEnum.CODE.getFiledString()).equals(ZERO)) {
                return Response.error(result.getInteger("code"), result.getString("msg"));
            }
        } catch (Exception e) {
            log.info("请求异常:{}", e);
        }
        return Response.success();
    }

4.删除项目

在这里插入图片描述
代码

/**
     * 删除项目
     * @param projectId 项目id
     * @author liudz
     * @date 2021/5/7
     * @return 执行结果
     **/
    @DeleteMapping("/project/delete")
    public Response deleteProject(@RequestParam String projectId) {
        HttpHeaders headers = new HttpHeaders();
        headers.set("token", token);
        headers.set("Content-Type", "application/json");
        HttpEntity requestEntity = new HttpEntity(headers);
        ResponseEntity<DolphinschedulerResponse> response = restTemplate.exchange(
                address + "/dolphinscheduler/projects/delete?projectId=" + projectId, HttpMethod.GET,
                requestEntity, DolphinschedulerResponse.class);
        if (response.getBody().getCode() != ZERO) {
            return Response.error(response.getBody().getCode(), response.getBody().getMsg());
        }
        return Response.success();
    }

三、本人相关其他文章链接

1.springboot项目集成dolphinscheduler调度器 可拖拽spark任务管理:
https://blog.csdn.net/a924382407/article/details/117119831

2.springboot项目集成dolphinscheduler调度器 实现datax数据同步任务:
https://blog.csdn.net/a924382407/article/details/120951230

3.springboot项目集成dolphinscheduler调度器 项目管理:
https://blog.csdn.net/a924382407/article/details/117118931

4.springboot项目集成大数据第三方dolphinscheduler调度器 执行/停止任务
https://blog.csdn.net/a924382407/article/details/117121181

5.springboot项目集成大数据第三方dolphinscheduler调度器
https://blog.csdn.net/a924382407/article/details/117113848

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘大猫.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值