Unverified Commit 4769bce0 authored by Han Gao's avatar Han Gao Committed by GitHub
Browse files

update controllers with ApiException annotation (#2401)

parent f5a8b566
Loading
Loading
Loading
Loading
+73 −92
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
 */
package org.apache.dolphinscheduler.api.controller;

import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AlertGroupService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
@@ -37,6 +38,8 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.HashMap;
import java.util.Map;

import static org.apache.dolphinscheduler.api.enums.Status.*;

/**
 * alert group controller
 */
@@ -53,6 +56,7 @@ public class AlertGroupController extends BaseController{

    /**
     * create alert group
     *
     * @param loginUser   login user
     * @param groupName   group name
     * @param groupType   group type
@@ -67,39 +71,32 @@ public class AlertGroupController extends BaseController{
    })
    @PostMapping(value = "/create")
    @ResponseStatus(HttpStatus.CREATED)
    @ApiException(CREATE_ALERT_GROUP_ERROR)
    public Result createAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                   @RequestParam(value = "groupName") String groupName,
                                   @RequestParam(value = "groupType") AlertType groupType,
                                   @RequestParam(value = "description", required = false) String description) {
        logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}",
                loginUser.getUserName(), groupName, groupType, description);
        try {
        Map<String, Object> result = alertGroupService.createAlertgroup(loginUser, groupName, groupType, description);
        return returnDataList(result);
        }catch (Exception e){
            logger.error(Status.CREATE_ALERT_GROUP_ERROR.getMsg(),e);
            return error(Status.CREATE_ALERT_GROUP_ERROR.getCode(), Status.CREATE_ALERT_GROUP_ERROR.getMsg());
        }
    }

    /**
     * alert group list
     *
     * @param loginUser login user
     * @return alert group list
     */
    @ApiOperation(value = "list", notes = "QUERY_ALERT_GROUP_LIST_NOTES")
    @GetMapping(value = "/list")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUERY_ALL_ALERTGROUP_ERROR)
    public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
        logger.info("login  user {}, query all alertGroup",
                loginUser.getUserName());
        try {
        HashMap<String, Object> result = alertGroupService.queryAlertgroup();
        return returnDataList(result);
        } catch (Exception e) {
            logger.error(Status.QUERY_ALL_ALERTGROUP_ERROR.getMsg(), e);
            return error(Status.QUERY_ALL_ALERTGROUP_ERROR.getCode(), Status.QUERY_ALL_ALERTGROUP_ERROR.getMsg());
        }
    }

    /**
@@ -119,13 +116,13 @@ public class AlertGroupController extends BaseController{
    })
    @GetMapping(value = "/list-paging")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(LIST_PAGING_ALERT_GROUP_ERROR)
    public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                             @RequestParam("pageNo") Integer pageNo,
                             @RequestParam(value = "searchVal", required = false) String searchVal,
                             @RequestParam("pageSize") Integer pageSize) {
        logger.info("login  user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}",
                loginUser.getUserName(), pageNo, searchVal, pageSize);
        try{
        Map<String, Object> result = checkPageParams(pageNo, pageSize);
        if (result.get(Constants.STATUS) != Status.SUCCESS) {
            return returnDataListPaging(result);
@@ -134,14 +131,11 @@ public class AlertGroupController extends BaseController{
        searchVal = ParameterUtils.handleEscapes(searchVal);
        result = alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize);
        return returnDataListPaging(result);
        }catch (Exception e){
            logger.error(Status.LIST_PAGING_ALERT_GROUP_ERROR.getMsg(),e);
            return error(Status.LIST_PAGING_ALERT_GROUP_ERROR.getCode(), Status.LIST_PAGING_ALERT_GROUP_ERROR.getMsg());
        }
    }

    /**
     * updateProcessInstance alert group
     *
     * @param loginUser   login user
     * @param id          alert group id
     * @param groupName   group name
@@ -158,6 +152,7 @@ public class AlertGroupController extends BaseController{
    })
    @PostMapping(value = "/update")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(UPDATE_ALERT_GROUP_ERROR)
    public Result updateAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                   @RequestParam(value = "id") int id,
                                   @RequestParam(value = "groupName") String groupName,
@@ -165,18 +160,13 @@ public class AlertGroupController extends BaseController{
                                   @RequestParam(value = "description", required = false) String description) {
        logger.info("login  user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}",
                loginUser.getUserName(), groupName, groupType, description);
        try {
        Map<String, Object> result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description);
        return returnDataList(result);

        }catch (Exception e){
            logger.error(Status.UPDATE_ALERT_GROUP_ERROR.getMsg(),e);
            return error(Status.UPDATE_ALERT_GROUP_ERROR.getCode(), Status.UPDATE_ALERT_GROUP_ERROR.getMsg());
        }
    }

    /**
     * delete alert group by id
     *
     * @param loginUser login user
     * @param id        alert group id
     * @return delete result code
@@ -187,22 +177,18 @@ public class AlertGroupController extends BaseController{
    })
    @PostMapping(value = "/delete")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(DELETE_ALERT_GROUP_ERROR)
    public Result delAlertgroupById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                    @RequestParam(value = "id") int id) {
        logger.info("login user {}, delete AlertGroup, id: {},", loginUser.getUserName(), id);
        try {
        Map<String, Object> result = alertGroupService.delAlertgroupById(loginUser, id);
        return returnDataList(result);

        }catch (Exception e){
            logger.error(Status.DELETE_ALERT_GROUP_ERROR.getMsg(),e);
            return error(Status.DELETE_ALERT_GROUP_ERROR.getCode(), Status.DELETE_ALERT_GROUP_ERROR.getMsg());
        }
    }


    /**
     * check alert group exist
     *
     * @param loginUser login user
     * @param groupName group name
     * @return check result code
@@ -245,17 +231,12 @@ public class AlertGroupController extends BaseController{
    })
    @PostMapping(value = "/grant-user")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(ALERT_GROUP_GRANT_USER_ERROR)
    public Result grantUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                            @RequestParam(value = "alertgroupId") int alertgroupId,
                            @RequestParam(value = "userIds") String userIds) {
        logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId, userIds);
        try {
        Map<String, Object> result = alertGroupService.grantUser(loginUser, alertgroupId, userIds);
        return returnDataList(result);

        }catch (Exception e){
            logger.error(Status.ALERT_GROUP_GRANT_USER_ERROR.getMsg(),e);
            return error(Status.ALERT_GROUP_GRANT_USER_ERROR.getCode(), Status.ALERT_GROUP_GRANT_USER_ERROR.getMsg());
        }
    }
}
+61 −79
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.controller;


import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.DataAnalysisService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
@@ -25,7 +26,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dolphinscheduler.api.enums.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +35,8 @@ import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

import static org.apache.dolphinscheduler.api.enums.Status.*;

/**
 * data analysis controller
 */
@@ -66,19 +68,15 @@ public class DataAnalysisController extends BaseController{
    })
    @GetMapping(value = "/task-state-count")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(TASK_INSTANCE_STATE_COUNT_ERROR)
    public Result countTaskState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                 @RequestParam(value = "startDate", required = false) String startDate,
                                 @RequestParam(value = "endDate", required = false) String endDate,
                                 @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
        try{
        logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}",
                loginUser.getUserName(), startDate, endDate, projectId);
        Map<String, Object> result = dataAnalysisService.countTaskStateByProject(loginUser, projectId, startDate, endDate);
        return returnDataList(result);
        }catch (Exception e){
            logger.error(Status.TASK_INSTANCE_STATE_COUNT_ERROR.getMsg(),e);
            return error(Status.TASK_INSTANCE_STATE_COUNT_ERROR.getCode(), Status.TASK_INSTANCE_STATE_COUNT_ERROR.getMsg());
        }
    }

    /**
@@ -98,19 +96,15 @@ public class DataAnalysisController extends BaseController{
    })
    @GetMapping(value = "/process-state-count")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR)
    public Result countProcessInstanceState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                            @RequestParam(value = "startDate", required = false) String startDate,
                                            @RequestParam(value = "endDate", required = false) String endDate,
                                            @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
        try{
        logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id:{}",
                loginUser.getUserName(), startDate, endDate, projectId);
        Map<String, Object> result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectId, startDate, endDate);
        return returnDataList(result);
        }catch (Exception e){
            logger.error(Status.COUNT_PROCESS_INSTANCE_STATE_ERROR.getMsg(),e);
            return error(Status.COUNT_PROCESS_INSTANCE_STATE_ERROR.getCode(), Status.COUNT_PROCESS_INSTANCE_STATE_ERROR.getMsg());
        }
    }

    /**
@@ -126,17 +120,13 @@ public class DataAnalysisController extends BaseController{
    })
    @GetMapping(value = "/define-user-count")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
    public Result countDefinitionByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                        @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
        try{
        logger.info("count process definition , user:{}, project id:{}",
                loginUser.getUserName(), projectId);
        Map<String, Object> result = dataAnalysisService.countDefinitionByUser(loginUser, projectId);
        return returnDataList(result);
        }catch (Exception e){
            logger.error(Status.COUNT_PROCESS_DEFINITION_USER_ERROR.getMsg(),e);
            return error(Status.COUNT_PROCESS_DEFINITION_USER_ERROR.getCode(), Status.COUNT_PROCESS_DEFINITION_USER_ERROR.getMsg());
        }
    }


@@ -157,19 +147,15 @@ public class DataAnalysisController extends BaseController{
    })
    @GetMapping(value = "/command-state-count")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(COMMAND_STATE_COUNT_ERROR)
    public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                    @RequestParam(value = "startDate", required = false) String startDate,
                                    @RequestParam(value = "endDate", required = false) String endDate,
                                    @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
        try{
        logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}",
                loginUser.getUserName(), startDate, endDate, projectId);
        Map<String, Object> result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate);
        return returnDataList(result);
        }catch (Exception e){
            logger.error(Status.COMMAND_STATE_COUNT_ERROR.getMsg(),e);
            return error(Status.COMMAND_STATE_COUNT_ERROR.getCode(), Status.COMMAND_STATE_COUNT_ERROR.getMsg());
        }
    }

    /**
@@ -185,17 +171,13 @@ public class DataAnalysisController extends BaseController{
    })
    @GetMapping(value = "/queue-count")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUEUE_COUNT_ERROR)
    public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                  @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) {
        try{
        logger.info("count command state, user:{}, project id {}",
                loginUser.getUserName(), projectId);
        Map<String, Object> result = dataAnalysisService.countQueueState(loginUser, projectId);
        return returnDataList(result);
        }catch (Exception e){
            logger.error(Status.QUEUE_COUNT_ERROR.getMsg(),e);
            return error(Status.QUEUE_COUNT_ERROR.getCode(), Status.QUEUE_COUNT_ERROR.getMsg());
        }
    }


+144 −196
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.DataSourceService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
@@ -39,6 +40,7 @@ import springfox.documentation.annotations.ApiIgnore;
import java.util.Map;

import static org.apache.dolphinscheduler.api.enums.Status.*;

/**
 * data source controller
 */
@@ -54,6 +56,7 @@ public class DataSourceController extends BaseController {

    /**
     * create data source
     *
     * @param loginUser login user
     * @param name      data source name
     * @param note      data source description
@@ -82,6 +85,7 @@ public class DataSourceController extends BaseController {
    })
    @PostMapping(value = "/create")
    @ResponseStatus(HttpStatus.CREATED)
    @ApiException(CREATE_DATASOURCE_ERROR)
    public Result createDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                   @RequestParam("name") String name,
                                   @RequestParam(value = "note", required = false) String note,
@@ -96,15 +100,9 @@ public class DataSourceController extends BaseController {
                                   @RequestParam(value = "other") String other) {
        logger.info("login user {} create datasource name: {}, note: {}, type: {}, host: {}, port: {}, database : {}, principal: {}, userName : {}, connectType: {}, other: {}",
                loginUser.getUserName(), name, note, type, host, port, database, principal, userName, connectType, other);
        try {
        String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other);
        Map<String, Object> result = dataSourceService.createDataSource(loginUser, name, note, type, parameter);
        return returnDataList(result);

        } catch (Exception e) {
            logger.error(CREATE_DATASOURCE_ERROR.getMsg(),e);
            return error(Status.CREATE_DATASOURCE_ERROR.getCode(), Status.CREATE_DATASOURCE_ERROR.getMsg());
        }
    }


@@ -141,6 +139,7 @@ public class DataSourceController extends BaseController {
    })
    @PostMapping(value = "/update")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(UPDATE_DATASOURCE_ERROR)
    public Result updateDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                   @RequestParam("id") int id,
                                   @RequestParam("name") String name,
@@ -156,16 +155,9 @@ public class DataSourceController extends BaseController {
                                   @RequestParam(value = "other") String other) {
        logger.info("login user {} updateProcessInstance datasource name: {}, note: {}, type: {}, connectType: {}, other: {}",
                loginUser.getUserName(), name, note, type, connectType, other);
        try {
        String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other);
        Map<String, Object> dataSource = dataSourceService.updateDataSource(id, loginUser, name, note, type, parameter);
        return returnDataList(dataSource);
        } catch (Exception e) {
            logger.error(UPDATE_DATASOURCE_ERROR.getMsg(),e);
            return error(UPDATE_DATASOURCE_ERROR.getCode(), UPDATE_DATASOURCE_ERROR.getMsg());
        }


    }

    /**
@@ -182,19 +174,13 @@ public class DataSourceController extends BaseController {
    })
    @PostMapping(value = "/update-ui")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUERY_DATASOURCE_ERROR)
    public Result queryDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                  @RequestParam("id") int id) {
        logger.info("login user {}, query datasource: {}",
                loginUser.getUserName(), id);
        try {
        Map<String, Object> result = dataSourceService.queryDataSource(id);
        return returnDataList(result);
        } catch (Exception e) {
            logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e);
            return error(Status.QUERY_DATASOURCE_ERROR.getCode(), Status.QUERY_DATASOURCE_ERROR.getMsg());
        }


    }

    /**
@@ -210,15 +196,11 @@ public class DataSourceController extends BaseController {
    })
    @GetMapping(value = "/list")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUERY_DATASOURCE_ERROR)
    public Result queryDataSourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                      @RequestParam("type") DbType type) {
        try {
        Map<String, Object> result = dataSourceService.queryDataSourceList(loginUser, type.ordinal());
        return returnDataList(result);
        } catch (Exception e) {
            logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e);
            return error(Status.QUERY_DATASOURCE_ERROR.getCode(), Status.QUERY_DATASOURCE_ERROR.getMsg());
        }
    }

    /**
@@ -238,11 +220,11 @@ public class DataSourceController extends BaseController {
    })
    @GetMapping(value = "/list-paging")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(QUERY_DATASOURCE_ERROR)
    public Result queryDataSourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                            @RequestParam(value = "searchVal", required = false) String searchVal,
                                            @RequestParam("pageNo") Integer pageNo,
                                            @RequestParam("pageSize") Integer pageSize) {
        try {
        Map<String, Object> result = checkPageParams(pageNo, pageSize);
        if (result.get(Constants.STATUS) != Status.SUCCESS) {
            return returnDataListPaging(result);
@@ -250,10 +232,6 @@ public class DataSourceController extends BaseController {
        searchVal = ParameterUtils.handleEscapes(searchVal);
        result = dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize);
        return returnDataListPaging(result);
        } catch (Exception e) {
            logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e);
            return error(QUERY_DATASOURCE_ERROR.getCode(), QUERY_DATASOURCE_ERROR.getMsg());
        }
    }

    /**
@@ -287,6 +265,7 @@ public class DataSourceController extends BaseController {
    })
    @PostMapping(value = "/connect")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(CONNECT_DATASOURCE_FAILURE)
    public Result connectDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                    @RequestParam("name") String name,
                                    @RequestParam(value = "note", required = false) String note,
@@ -301,7 +280,6 @@ public class DataSourceController extends BaseController {
                                    @RequestParam(value = "other") String other) {
        logger.info("login user {}, connect datasource: {} failure, note: {}, type: {}, connectType: {}, other: {}",
                loginUser.getUserName(), name, note, type, connectType, other);
        try {
        String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other);
        Boolean isConnection = dataSourceService.checkConnection(type, parameter);
        Result result = new Result();
@@ -312,10 +290,6 @@ public class DataSourceController extends BaseController {
            putMsg(result, CONNECT_DATASOURCE_FAILURE);
        }
        return result;
        } catch (Exception e) {
            logger.error(CONNECT_DATASOURCE_FAILURE.getMsg(),e);
            return error(CONNECT_DATASOURCE_FAILURE.getCode(), CONNECT_DATASOURCE_FAILURE.getMsg());
        }
    }

    /**
@@ -331,11 +305,11 @@ public class DataSourceController extends BaseController {
    })
    @GetMapping(value = "/connect-by-id")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(CONNECTION_TEST_FAILURE)
    public Result connectionTest(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                 @RequestParam("id") int id) {
        logger.info("connection test, login user:{}, id:{}", loginUser.getUserName(), id);

        try {
        Boolean isConnection = dataSourceService.connectionTest(loginUser, id);
        Result result = new Result();

@@ -345,11 +319,6 @@ public class DataSourceController extends BaseController {
            putMsg(result, CONNECTION_TEST_FAILURE);
        }
        return result;
        } catch (Exception e) {
            logger.error(CONNECTION_TEST_FAILURE.getMsg(),e);
            return error(CONNECTION_TEST_FAILURE.getCode(), CONNECTION_TEST_FAILURE.getMsg());
        }

    }

    /**
@@ -365,15 +334,11 @@ public class DataSourceController extends BaseController {
    })
    @GetMapping(value = "/delete")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(DELETE_DATA_SOURCE_FAILURE)
    public Result delete(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                         @RequestParam("id") int id) {
        try {
        logger.info("delete datasource,login user:{}, id:{}", loginUser.getUserName(), id);
        return dataSourceService.delete(loginUser, id);
        } catch (Exception e) {
            logger.error(DELETE_DATA_SOURCE_FAILURE.getMsg(),e);
            return error(DELETE_DATA_SOURCE_FAILURE.getCode(), DELETE_DATA_SOURCE_FAILURE.getMsg());
        }
    }

    /**
@@ -389,20 +354,15 @@ public class DataSourceController extends BaseController {
    })
    @GetMapping(value = "/verify-name")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(VERIFY_DATASOURCE_NAME_FAILURE)
    public Result verifyDataSourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                       @RequestParam(value = "name") String name
    ) {
        logger.info("login user {}, verfiy datasource name: {}",
                loginUser.getUserName(), name);

        try {
        return dataSourceService.verifyDataSourceName(loginUser, name);
        } catch (Exception e) {
            logger.error(VERIFY_DATASOURCE_NAME_FAILURE.getMsg(), e);
            return error(VERIFY_DATASOURCE_NAME_FAILURE.getCode(), VERIFY_DATASOURCE_NAME_FAILURE.getMsg());
    }
    }



    /**
@@ -418,17 +378,13 @@ public class DataSourceController extends BaseController {
    })
    @GetMapping(value = "/unauth-datasource")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(UNAUTHORIZED_DATASOURCE)
    public Result unauthDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                   @RequestParam("userId") Integer userId) {
        try {
        logger.info("unauthorized datasource, login user:{}, unauthorized userId:{}",
                loginUser.getUserName(), userId);
        Map<String, Object> result = dataSourceService.unauthDatasource(loginUser, userId);
        return returnDataList(result);
        } catch (Exception e) {
            logger.error(UNAUTHORIZED_DATASOURCE.getMsg(),e);
            return error(UNAUTHORIZED_DATASOURCE.getCode(), UNAUTHORIZED_DATASOURCE.getMsg());
        }
    }


@@ -445,17 +401,13 @@ public class DataSourceController extends BaseController {
    })
    @GetMapping(value = "/authed-datasource")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(AUTHORIZED_DATA_SOURCE)
    public Result authedDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                   @RequestParam("userId") Integer userId) {
        try {
        logger.info("authorized data source, login user:{}, authorized useId:{}",
                loginUser.getUserName(), userId);
        Map<String, Object> result = dataSourceService.authedDatasource(loginUser, userId);
        return returnDataList(result);
        } catch (Exception e) {
            logger.error(AUTHORIZED_DATA_SOURCE.getMsg(),e);
            return error(AUTHORIZED_DATA_SOURCE.getCode(), AUTHORIZED_DATA_SOURCE.getMsg());
        }
    }

    /**
@@ -467,14 +419,10 @@ public class DataSourceController extends BaseController {
    @ApiOperation(value = "getKerberosStartupState", notes = "GET_USER_INFO_NOTES")
    @GetMapping(value = "/kerberos-startup-state")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(KERBEROS_STARTUP_STATE)
    public Result getKerberosStartupState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
        logger.info("login user {}", loginUser.getUserName());
        try{
        // if upload resource is HDFS and kerberos startup is true , else false
        return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState());
        }catch (Exception e){
            logger.error(KERBEROS_STARTUP_STATE.getMsg(),e);
            return error(Status.KERBEROS_STARTUP_STATE.getCode(), Status.KERBEROS_STARTUP_STATE.getMsg());
        }
    }
}
+72 −85

File changed.

Preview size limit exceeded, changes collapsed.

+23 −29

File changed.

Preview size limit exceeded, changes collapsed.

Loading