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

导读:本篇文章讲解 springboot项目集成dolphinscheduler调度器 项目管理,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

在这里插入图片描述

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/106270.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!