WorkFlowLineageController.java 4.8 KB
Newer Older
L
LiemLin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
17

L
LiemLin 已提交
18 19
package org.apache.dolphinscheduler.api.controller;

20 21
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_LINEAGE_ERROR;
import static org.apache.dolphinscheduler.common.Constants.SESSION_USER;
22

23
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
L
LiemLin 已提交
24 25 26
import org.apache.dolphinscheduler.api.service.WorkFlowLineageService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
27
import org.apache.dolphinscheduler.dao.entity.User;
L
LiemLin 已提交
28
import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage;
29

L
LiemLin 已提交
30 31 32 33 34
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

35 36 37 38 39 40 41 42 43 44 45
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
L
LiemLin 已提交
46

47 48 49 50 51 52 53 54
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * work flow lineage controller
 */
@Api(tags = "WORK_FLOW_LINEAGE_TAG")
L
LiemLin 已提交
55 56 57 58 59 60 61 62
@RestController
@RequestMapping("lineages/{projectId}")
public class WorkFlowLineageController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(WorkFlowLineageController.class);

    @Autowired
    private WorkFlowLineageService workFlowLineageService;

63
    @GetMapping(value = "/list-name")
L
LiemLin 已提交
64
    @ResponseStatus(HttpStatus.OK)
65
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
66 67 68
    public Result<List<WorkFlowLineage>> queryWorkFlowLineageByName(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
                                                                    @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId,
                                                                    @ApiIgnore @RequestParam(value = "searchVal", required = false) String searchVal) {
L
LiemLin 已提交
69 70 71 72
        try {
            searchVal = ParameterUtils.handleEscapes(searchVal);
            Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal,projectId);
            return returnDataList(result);
73
        } catch (Exception e) {
L
LiemLin 已提交
74 75 76 77 78
            logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e);
            return error(QUERY_WORKFLOW_LINEAGE_ERROR.getCode(), QUERY_WORKFLOW_LINEAGE_ERROR.getMsg());
        }
    }

79
    @GetMapping(value = "/list-ids")
L
LiemLin 已提交
80
    @ResponseStatus(HttpStatus.OK)
81
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
82 83 84
    public Result<Map<String, Object>> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
                                                                 @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId,
                                                                 @ApiIgnore @RequestParam(value = "ids", required = false) String ids) {
L
LiemLin 已提交
85 86 87
        try {
            ids = ParameterUtils.handleEscapes(ids);
            Set<Integer> idsSet = new HashSet<>();
88
            if (ids != null) {
L
LiemLin 已提交
89
                String[] idsStr = ids.split(",");
90
                for (String id : idsStr) {
L
LiemLin 已提交
91 92 93 94 95 96
                    idsSet.add(Integer.parseInt(id));
                }
            }

            Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectId);
            return returnDataList(result);
97
        } catch (Exception e) {
L
LiemLin 已提交
98 99 100 101 102
            logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e);
            return error(QUERY_WORKFLOW_LINEAGE_ERROR.getCode(), QUERY_WORKFLOW_LINEAGE_ERROR.getMsg());
        }
    }
}