@ -18,10 +18,13 @@ package cn.escheduler.api.controller;
import cn.escheduler.api.enums.Status ;
import cn.escheduler.api.enums.Status ;
import cn.escheduler.api.service.DataSourceService ;
import cn.escheduler.api.service.DataSourceService ;
import cn.escheduler.api.utils.CheckUtils ;
import cn.escheduler.api.utils.Constants ;
import cn.escheduler.api.utils.Constants ;
import cn.escheduler.api.utils.Result ;
import cn.escheduler.api.utils.Result ;
import cn.escheduler.common.enums.DbType ;
import cn.escheduler.common.enums.DbType ;
import cn.escheduler.common.enums.ResUploadType ;
import cn.escheduler.common.utils.ParameterUtils ;
import cn.escheduler.common.utils.ParameterUtils ;
import cn.escheduler.common.utils.PropertyUtils ;
import cn.escheduler.dao.model.User ;
import cn.escheduler.dao.model.User ;
import io.swagger.annotations.Api ;
import io.swagger.annotations.Api ;
import io.swagger.annotations.ApiImplicitParam ;
import io.swagger.annotations.ApiImplicitParam ;
@ -56,12 +59,16 @@ public class DataSourceController extends BaseController {
/ * *
/ * *
* create data source
* create data source
* 创建数据源
*
* @param loginUser
* @param loginUser
* @param name
* @param name
* @param note
* @param note
* @param type
* @param type
* @param host
* @param port
* @param database
* @param principal
* @param userName
* @param password
* @param other
* @param other
* @return
* @return
* /
* /
@ -86,13 +93,14 @@ public class DataSourceController extends BaseController {
@RequestParam ( value = "host" ) String host ,
@RequestParam ( value = "host" ) String host ,
@RequestParam ( value = "port" ) String port ,
@RequestParam ( value = "port" ) String port ,
@RequestParam ( value = "database" ) String database ,
@RequestParam ( value = "database" ) String database ,
@RequestParam ( value = "principal" ) String principal ,
@RequestParam ( value = "userName" ) String userName ,
@RequestParam ( value = "userName" ) String userName ,
@RequestParam ( value = "password" ) String password ,
@RequestParam ( value = "password" ) String password ,
@RequestParam ( value = "other" ) String other ) {
@RequestParam ( value = "other" ) String other ) {
logger . info ( "login user {} create datasource ame: {}, note: {}, type: {}, other: {}" ,
logger . info ( "login user {} create datasource n ame: {}, note: {}, type: {}, host: {},port: {},database : {},principal: {},userName : {} other: {}" ,
loginUser . getUserName ( ) , name , note , type , other ) ;
loginUser . getUserName ( ) , name , note , type , host , port , database , principal , userName , other ) ;
try {
try {
String parameter = dataSourceService . buildParameter ( name , note , type , host , port , database , userName , password , other ) ;
String parameter = dataSourceService . buildParameter ( name , note , type , host , port , database , principal , userName , password , other ) ;
Map < String , Object > result = dataSourceService . createDataSource ( loginUser , name , note , type , parameter ) ;
Map < String , Object > result = dataSourceService . createDataSource ( loginUser , name , note , type , parameter ) ;
return returnDataList ( result ) ;
return returnDataList ( result ) ;
@ -136,13 +144,14 @@ public class DataSourceController extends BaseController {
@RequestParam ( value = "host" ) String host ,
@RequestParam ( value = "host" ) String host ,
@RequestParam ( value = "port" ) String port ,
@RequestParam ( value = "port" ) String port ,
@RequestParam ( value = "database" ) String database ,
@RequestParam ( value = "database" ) String database ,
@RequestParam ( value = "principal" ) String principal ,
@RequestParam ( value = "userName" ) String userName ,
@RequestParam ( value = "userName" ) String userName ,
@RequestParam ( value = "password" ) String password ,
@RequestParam ( value = "password" ) String password ,
@RequestParam ( value = "other" ) String other ) {
@RequestParam ( value = "other" ) String other ) {
logger . info ( "login user {} updateProcessInstance datasource name: {}, note: {}, type: {}, other: {}" ,
logger . info ( "login user {} updateProcessInstance datasource name: {}, note: {}, type: {}, other: {}" ,
loginUser . getUserName ( ) , name , note , type , other ) ;
loginUser . getUserName ( ) , name , note , type , other ) ;
try {
try {
String parameter = dataSourceService . buildParameter ( name , note , type , host , port , database , userName , password , other ) ;
String parameter = dataSourceService . buildParameter ( name , note , type , host , port , database , principal , userName , password , other ) ;
Map < String , Object > dataSource = dataSourceService . updateDataSource ( id , loginUser , name , note , type , parameter ) ;
Map < String , Object > dataSource = dataSourceService . updateDataSource ( id , loginUser , name , note , type , parameter ) ;
return returnDataList ( dataSource ) ;
return returnDataList ( dataSource ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
@ -271,13 +280,14 @@ public class DataSourceController extends BaseController {
@RequestParam ( value = "host" ) String host ,
@RequestParam ( value = "host" ) String host ,
@RequestParam ( value = "port" ) String port ,
@RequestParam ( value = "port" ) String port ,
@RequestParam ( value = "database" ) String database ,
@RequestParam ( value = "database" ) String database ,
@RequestParam ( value = "principal" ) String principal ,
@RequestParam ( value = "userName" ) String userName ,
@RequestParam ( value = "userName" ) String userName ,
@RequestParam ( value = "password" ) String password ,
@RequestParam ( value = "password" ) String password ,
@RequestParam ( value = "other" ) String other ) {
@RequestParam ( value = "other" ) String other ) {
logger . info ( "login user {}, connect datasource: {} failure, note: {}, type: {}, other: {}" ,
logger . info ( "login user {}, connect datasource: {} failure, note: {}, type: {}, other: {}" ,
loginUser . getUserName ( ) , name , note , type , other ) ;
loginUser . getUserName ( ) , name , note , type , other ) ;
try {
try {
String parameter = dataSourceService . buildParameter ( name , note , type , host , port , database , userName , password , other ) ;
String parameter = dataSourceService . buildParameter ( name , note , type , host , port , database , principal , userName , password , other ) ;
Boolean isConnection = dataSourceService . checkConnection ( type , parameter ) ;
Boolean isConnection = dataSourceService . checkConnection ( type , parameter ) ;
Result result = new Result ( ) ;
Result result = new Result ( ) ;
@ -442,10 +452,10 @@ public class DataSourceController extends BaseController {
@GetMapping ( value = "/kerberos-startup-state" )
@GetMapping ( value = "/kerberos-startup-state" )
@ResponseStatus ( HttpStatus . OK )
@ResponseStatus ( HttpStatus . OK )
public Result getKerberosStartupState ( @ApiIgnore @RequestAttribute ( value = Constants . SESSION_USER ) User loginUser ) {
public Result getKerberosStartupState ( @ApiIgnore @RequestAttribute ( value = Constants . SESSION_USER ) User loginUser ) {
logger . info ( "login user {},get user info : {}" , loginUser . getUserName ( ) ) ;
logger . info ( "login user {},get kerberos start up stat e : {}" , loginUser . getUserName ( ) ) ;
try {
try {
Boolean kerberosStartupState = getBoolean ( cn . escheduler . common . Constants . HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE ) ;
// if upload resource is HDFS and kerberos startup is true , else false
return success ( Status . SUCCESS . getMsg ( ) , kerberosStartupState ) ;
return success ( Status . SUCCESS . getMsg ( ) , Chec kUtils . getK erberosStartupState( ) ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( KERBEROS_STARTUP_STATE . getMsg ( ) , e ) ;
logger . error ( KERBEROS_STARTUP_STATE . getMsg ( ) , e ) ;
return error ( Status . KERBEROS_STARTUP_STATE . getCode ( ) , Status . KERBEROS_STARTUP_STATE . getMsg ( ) ) ;
return error ( Status . KERBEROS_STARTUP_STATE . getCode ( ) , Status . KERBEROS_STARTUP_STATE . getMsg ( ) ) ;