Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
ab555936
Unverified
Commit
ab555936
authored
Jan 18, 2023
by
ZackYoung
Committed by
GitHub
Jan 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor admin hdfs file upload (#1574)
* optimize hdfs upload module & i18 exception optimize * optimize hdfs upload module & i18 exception optimize
parent
e0a1b2f6
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
300 additions
and
259 deletions
+300
-259
docs.yml
.github/workflows/docs.yml
+1
-0
WebExceptionHandler.java
...dmin/src/main/java/org/dinky/aop/WebExceptionHandler.java
+7
-2
Result.java
...y-admin/src/main/java/org/dinky/common/result/Result.java
+8
-0
AppConfig.java
dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
+1
-1
CacheConfig.java
...-admin/src/main/java/org/dinky/configure/CacheConfig.java
+1
-1
Knife4jConfig.java
...dmin/src/main/java/org/dinky/configure/Knife4jConfig.java
+1
-1
FileUploadController.java
.../main/java/org/dinky/controller/FileUploadController.java
+7
-5
BusException.java
...admin/src/main/java/org/dinky/exception/BusException.java
+58
-0
FileUploadService.java
...in/src/main/java/org/dinky/service/FileUploadService.java
+8
-13
FileUploadServiceImpl.java
...in/java/org/dinky/service/impl/FileUploadServiceImpl.java
+51
-73
HdfsUtil.java
dinky-admin/src/main/java/org/dinky/utils/HdfsUtil.java
+35
-63
MessageResolverUtils.java
...n/src/main/java/org/dinky/utils/MessageResolverUtils.java
+3
-6
messages.properties
dinky-admin/src/main/resources/i18n/messages.properties
+54
-46
messages_en_US.properties
...y-admin/src/main/resources/i18n/messages_en_US.properties
+11
-2
messages_zh_CN.properties
...y-admin/src/main/resources/i18n/messages_zh_CN.properties
+54
-46
No files found.
.github/workflows/docs.yml
View file @
ab555936
...
...
@@ -21,6 +21,7 @@ on:
jobs
:
build-documentation
:
if
:
github.repository == 'DataLinkDC/dinky'
runs-on
:
ubuntu-latest
steps
:
-
uses
:
actions/checkout@v3
...
...
dinky-admin/src/main/java/org/dinky/
exception
/WebExceptionHandler.java
→
dinky-admin/src/main/java/org/dinky/
aop
/WebExceptionHandler.java
View file @
ab555936
...
...
@@ -17,9 +17,10 @@
*
*/
package
org
.
dinky
.
exception
;
package
org
.
dinky
.
aop
;
import
org.dinky.common.result.Result
;
import
org.dinky.exception.BusException
;
import
org.dinky.model.CodeEnum
;
import
org.dinky.utils.MessageResolverUtils
;
...
...
@@ -44,6 +45,7 @@ import org.springframework.web.context.request.RequestContextHolder;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
cn.dev33.satoken.exception.NotLoginException
;
import
cn.hutool.core.util.StrUtil
;
/**
* WebExceptionHandler
...
...
@@ -59,7 +61,10 @@ public class WebExceptionHandler {
@ExceptionHandler
public
Result
<
Void
>
busException
(
BusException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
if
(
StrUtil
.
isNotEmpty
(
e
.
getMsg
()))
{
return
Result
.
failed
(
MessageResolverUtils
.
getMessages
(
e
.
getCode
(),
e
.
getErrorArgs
()));
}
return
Result
.
failed
(
e
.
getMsg
());
}
@ExceptionHandler
...
...
dinky-admin/src/main/java/org/dinky/common/result/Result.java
View file @
ab555936
...
...
@@ -21,6 +21,7 @@ package org.dinky.common.result;
import
org.dinky.enums.Status
;
import
org.dinky.model.CodeEnum
;
import
org.dinky.utils.MessageResolverUtils
;
import
java.io.Serializable
;
import
java.text.MessageFormat
;
...
...
@@ -69,6 +70,13 @@ public class Result<T> implements Serializable {
return
of
(
null
,
CodeEnum
.
SUCCESS
.
getCode
(),
msg
);
}
public
static
<
T
>
Result
<
T
>
succeed
()
{
return
of
(
null
,
CodeEnum
.
SUCCESS
.
getCode
(),
MessageResolverUtils
.
getMessage
(
"operate.success"
));
}
public
static
<
T
>
Result
<
T
>
succeed
(
T
model
,
String
msg
)
{
return
of
(
model
,
CodeEnum
.
SUCCESS
.
getCode
(),
msg
);
}
...
...
dinky-admin/src/main/java/org/dinky/configure/AppConfig
uration
.java
→
dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
View file @
ab555936
...
...
@@ -41,7 +41,7 @@ import cn.dev33.satoken.interceptor.SaInterceptor;
* @since 2021/11/28 19:35
*/
@Configuration
public
class
AppConfig
uration
implements
WebMvcConfigurer
{
public
class
AppConfig
implements
WebMvcConfigurer
{
/**
* Cookie
...
...
dinky-admin/src/main/java/org/dinky/configure/CacheConfig
ure
.java
→
dinky-admin/src/main/java/org/dinky/configure/CacheConfig.java
View file @
ab555936
...
...
@@ -33,7 +33,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @since 2022/09/24 11:23
*/
@Configuration
public
class
CacheConfig
ure
{
public
class
CacheConfig
{
/** 配置Redis缓存注解的value序列化方式 */
@Bean
...
...
dinky-admin/src/main/java/org/dinky/configure/Knife4jConfig
uration
.java
→
dinky-admin/src/main/java/org/dinky/configure/Knife4jConfig.java
View file @
ab555936
...
...
@@ -32,7 +32,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public
class
Knife4jConfig
uration
{
public
class
Knife4jConfig
{
@Bean
(
value
=
"defaultApi2"
)
public
Docket
defaultApi2
()
{
...
...
dinky-admin/src/main/java/org/dinky/controller/FileUploadController.java
View file @
ab555936
...
...
@@ -54,7 +54,7 @@ public class FileUploadController {
* @return {@link Result}
*/
@PostMapping
public
Result
upload
(
public
Result
<
Void
>
upload
(
@RequestPart
(
"files"
)
MultipartFile
[]
files
,
@RequestParam
(
value
=
"dir"
,
defaultValue
=
""
,
required
=
false
)
String
dir
,
@RequestParam
(
value
=
"fileType"
,
defaultValue
=
"-1"
,
required
=
false
)
...
...
@@ -66,10 +66,11 @@ public class FileUploadController {
}
if
(
StringUtils
.
isEmpty
(
dir
))
{
return
fileUploadService
.
upload
(
files
,
fileType
);
fileUploadService
.
upload
(
files
,
fileType
);
}
else
{
return
fileUploadService
.
upload
(
files
,
dir
,
fileType
);
fileUploadService
.
upload
(
files
,
dir
,
fileType
);
}
return
Result
.
succeed
();
}
/**
...
...
@@ -82,10 +83,11 @@ public class FileUploadController {
* @return {@link Result}
*/
@PostMapping
(
value
=
"hdfs"
)
public
Result
uploadHdfs
(
public
Result
<
Void
>
uploadHdfs
(
@RequestPart
(
"files"
)
MultipartFile
[]
files
,
@RequestParam
(
value
=
"dir"
,
defaultValue
=
""
,
required
=
false
)
String
dir
,
@RequestParam
(
value
=
"hadoopConfigPath"
,
required
=
false
)
String
hadoopConfigPath
)
{
return
fileUploadService
.
uploadHdfs
(
files
,
dir
,
hadoopConfigPath
);
fileUploadService
.
uploadHdfs
(
files
,
dir
,
hadoopConfigPath
);
return
Result
.
succeed
();
}
}
dinky-admin/src/main/java/org/dinky/exception/BusException.java
View file @
ab555936
...
...
@@ -19,17 +19,75 @@
package
org
.
dinky
.
exception
;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.extern.slf4j.Slf4j
;
/**
* BusException
*
* @author wenmo
* @since 2021/5/28 14:21
*/
@Slf4j
@Getter
@Setter
public
class
BusException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
-
2955156471454043812L
;
/** 异常信息的code码 */
private
String
code
;
/** 如果有值得话,将不会取i18n里面的错误信息 */
private
String
msg
;
/** 异常信息的参数 */
private
Object
[]
errorArgs
;
public
BusException
(
String
message
)
{
super
(
message
);
setMsg
(
message
);
}
public
BusException
(
String
message
,
Object
...
args
)
{
super
();
setCode
(
message
);
setErrorArgs
(
args
);
}
/**
* An exception that gets the error message through i 18n
*
* @param code code
* @param e e
* @return {@link BusException}
*/
public
static
BusException
valueOf
(
String
code
,
Throwable
e
)
{
String
errMsg
=
ExceptionUtil
.
stacktraceToString
(
e
);
log
.
error
(
errMsg
);
return
new
BusException
(
code
,
errMsg
);
}
/**
* An exception that gets the error message through i 18n
*
* @param code code
* @param errorArgs errorArgs
* @return {@link BusException}
*/
public
static
BusException
valueOf
(
String
code
,
Object
...
errorArgs
)
{
return
new
BusException
(
code
,
errorArgs
);
}
/**
* Without passing the exception to i 18n, it is directly returned to the msg past
*
* @param msg msg
* @return {@link BusException}
*/
public
static
BusException
valueOfMsg
(
String
msg
)
{
return
new
BusException
(
msg
);
}
}
dinky-admin/src/main/java/org/dinky/service/FileUploadService.java
View file @
ab555936
...
...
@@ -19,7 +19,6 @@
package
org
.
dinky
.
service
;
import
org.dinky.common.result.Result
;
import
org.dinky.constant.UploadFileConstant
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -32,18 +31,16 @@ public interface FileUploadService {
*
* @param file {@link MultipartFile} instance
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
* @return {@link Result}
*/
Result
upload
(
MultipartFile
file
,
Byte
fileType
);
void
upload
(
MultipartFile
file
,
Byte
fileType
);
/**
* Upload multy file, if target file exists, will delete it first
*
* @param files {@link MultipartFile} instance
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
* @return {@link Result}
*/
Result
upload
(
MultipartFile
[]
files
,
Byte
fileType
);
void
upload
(
MultipartFile
[]
files
,
Byte
fileType
);
/**
* Upload one file, if target file exists, will delete it first
...
...
@@ -51,9 +48,8 @@ public interface FileUploadService {
* @param file {@link MultipartFile} instance
* @param dir Local absolute dir
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
* @return {@link Result}
*/
Result
upload
(
MultipartFile
file
,
String
dir
,
Byte
fileType
);
void
upload
(
MultipartFile
file
,
String
dir
,
Byte
fileType
);
/**
* Upload multy file, if target file exists, will delete it first
...
...
@@ -61,25 +57,24 @@ public interface FileUploadService {
* @param files {@link MultipartFile} instance
* @param dir Local absolute dir
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
* @return {@link Result}
*/
Result
upload
(
MultipartFile
[]
files
,
String
dir
,
Byte
fileType
);
void
upload
(
MultipartFile
[]
files
,
String
dir
,
Byte
fileType
);
/**
* Upload one hdfs file, if target file exists, will delete it first
*
* @param file {@link MultipartFile} instance
* @param hadoopConfigPath core-site.xml,hdfs-site.xml,yarn-site.xml
* @
return {@link Result}
* @
param dir dir
*/
Result
uploadHdfs
(
MultipartFile
file
,
String
dir
,
String
hadoopConfigPath
);
void
uploadHdfs
(
MultipartFile
file
,
String
dir
,
String
hadoopConfigPath
);
/**
* Upload multy hdfs file, if target file exists, will delete it first
*
* @param files {@link MultipartFile} instance
* @param hadoopConfigPath core-site.xml,hdfs-site.xml,yarn-site.xml
* @
return {@link Result}
* @
param dir dir
*/
Result
uploadHdfs
(
MultipartFile
[]
files
,
String
dir
,
String
hadoopConfigPath
);
void
uploadHdfs
(
MultipartFile
[]
files
,
String
dir
,
String
hadoopConfigPath
);
}
dinky-admin/src/main/java/org/dinky/service/impl/FileUploadServiceImpl.java
View file @
ab555936
...
...
@@ -20,9 +20,8 @@
package
org
.
dinky
.
service
.
impl
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.common.result.Result
;
import
org.dinky.constant.UploadFileConstant
;
import
org.dinky.
model.CodeEnum
;
import
org.dinky.
exception.BusException
;
import
org.dinky.service.FileUploadService
;
import
org.dinky.service.UploadFileRecordService
;
import
org.dinky.utils.FilePathUtil
;
...
...
@@ -39,7 +38,6 @@ import javax.annotation.Resource;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
cn.hutool.core.io.FileUtil
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -51,7 +49,7 @@ public class FileUploadServiceImpl implements FileUploadService {
@Resource
private
UploadFileRecordService
uploadFileRecordService
;
@Override
public
Result
<
Void
>
upload
(
MultipartFile
file
,
String
dir
,
Byte
fileType
)
{
public
void
upload
(
MultipartFile
file
,
String
dir
,
Byte
fileType
)
{
byte
target
=
getTarget
(
dir
,
fileType
);
if
(
Objects
.
equals
(
target
,
UploadFileConstant
.
TARGET_LOCAL
))
{
FileUtil
.
mkdir
(
dir
);
...
...
@@ -69,118 +67,98 @@ public class FileUploadServiceImpl implements FileUploadService {
filePath
,
fileType
,
UploadFileConstant
.
TARGET_LOCAL
))
{
return
Result
.
succeed
(
"上传成功"
)
;
return
;
}
else
{
return
Result
.
failed
(
"数据库异常"
);
throw
BusException
.
valueOfMsg
(
"数据库异常"
);
}
}
catch
(
IOException
e
)
{
log
.
error
(
"File "
+
file
.
getOriginalFilename
()
+
" upload to local dir fail, exception is:\n"
+
ExceptionUtil
.
stacktraceToString
(
e
));
return
Result
.
failed
(
"上传失败"
);
throw
BusException
.
valueOf
(
"file.upload.failed"
,
e
);
}
}
case
UploadFileConstant
.
TARGET_HDFS
:
{
Result
result
=
HdfsUtil
.
uploadFile
(
filePath
,
file
);
if
(
Objects
.
equals
(
result
.
getCode
(),
CodeEnum
.
SUCCESS
.
getCode
()))
{
if
(
uploadFileRecordService
.
saveOrUpdateFile
(
file
.
getOriginalFilename
(),
dir
,
filePath
,
fileType
,
UploadFileConstant
.
TARGET_HDFS
))
{
return
Result
.
succeed
(
"上传成功"
);
}
else
{
return
Result
.
failed
(
"数据库异常"
);
}
HdfsUtil
.
uploadFile
(
filePath
,
file
);
if
(
uploadFileRecordService
.
saveOrUpdateFile
(
file
.
getOriginalFilename
(),
dir
,
filePath
,
fileType
,
UploadFileConstant
.
TARGET_HDFS
))
{
return
;
}
else
{
return
result
;
throw
BusException
.
valueOfMsg
(
"数据库异常"
)
;
}
}
default
:
return
Result
.
failed
(
"非法的上传文件目的地"
);
throw
BusException
.
valueOfMsg
(
"非法的上传文件目的地"
);
}
}
@Override
public
Result
upload
(
MultipartFile
file
,
Byte
fileType
)
{
public
void
upload
(
MultipartFile
file
,
Byte
fileType
)
{
String
dir
=
UploadFileConstant
.
getDirPath
(
fileType
);
if
(
StringUtils
.
isEmpty
(
dir
))
{
return
Result
.
failed
(
"非法的上传文件类型"
);
throw
BusException
.
valueOfMsg
(
"非法的上传文件类型"
);
}
return
upload
(
file
,
dir
,
fileType
);
upload
(
file
,
dir
,
fileType
);
}
@Override
public
Result
upload
(
MultipartFile
[]
files
,
String
dir
,
Byte
fileType
)
{
public
void
upload
(
MultipartFile
[]
files
,
String
dir
,
Byte
fileType
)
{
if
(
StringUtils
.
isEmpty
(
dir
))
{
throw
BusException
.
valueOfMsg
(
"非法的上传文件类型"
);
}
if
(
files
.
length
>
0
)
{
for
(
MultipartFile
file
:
files
)
{
Result
uploadResult
=
upload
(
file
,
dir
,
fileType
);
if
(
Objects
.
equals
(
uploadResult
.
getCode
(),
CodeEnum
.
ERROR
.
getCode
()))
{
return
uploadResult
;
}
upload
(
file
,
dir
,
fileType
);
}
if
(!
uploadFileRecordService
.
saveOrUpdateDir
(
dir
,
fileType
,
getTarget
(
dir
,
fileType
)))
{
return
Result
.
failed
(
"数据库异常"
);
throw
BusException
.
valueOfMsg
(
"数据库异常"
);
}
return
Result
.
succeed
(
"全部上传成功"
);
}
else
{
return
Result
.
succeed
(
"没有检测到要上传的文件"
);
throw
BusException
.
valueOfMsg
(
"没有检测到要上传的文件"
);
}
}
@Override
public
Result
uploadHdfs
(
MultipartFile
file
,
String
dir
,
String
hadoopConfigPath
)
{
public
void
uploadHdfs
(
MultipartFile
file
,
String
dir
,
String
hadoopConfigPath
)
{
if
(
Asserts
.
isNullString
(
dir
))
{
dir
=
UploadFileConstant
.
getDirPath
(
UploadFileConstant
.
FLINK_LIB_ID
);
}
String
filePath
=
FilePathUtil
.
addFileSeparator
(
dir
)
+
file
.
getOriginalFilename
();
Result
result
=
HdfsUtil
.
uploadFile
(
filePath
,
file
,
hadoopConfigPath
);
if
(
Objects
.
equals
(
result
.
getCode
(),
CodeEnum
.
SUCCESS
.
getCode
()))
{
if
(
uploadFileRecordService
.
saveOrUpdateFile
(
file
.
getOriginalFilename
(),
dir
,
filePath
,
UploadFileConstant
.
FLINK_LIB_ID
,
UploadFileConstant
.
TARGET_HDFS
))
{
return
Result
.
succeed
(
"上传成功"
);
}
else
{
return
Result
.
failed
(
"数据库异常"
);
}
}
else
{
return
result
;
HdfsUtil
.
uploadFile
(
filePath
,
file
,
hadoopConfigPath
);
if
(!
uploadFileRecordService
.
saveOrUpdateFile
(
file
.
getOriginalFilename
(),
dir
,
filePath
,
UploadFileConstant
.
FLINK_LIB_ID
,
UploadFileConstant
.
TARGET_HDFS
))
{
throw
BusException
.
valueOfMsg
(
"数据库异常"
);
}
}
@Override
public
Result
uploadHdfs
(
MultipartFile
[]
files
,
String
dir
,
String
hadoopConfigPath
)
{
if
(
Asserts
.
isNullString
(
dir
))
{
dir
=
UploadFileConstant
.
getDirPath
(
UploadFileConstant
.
FLINK_LIB_ID
);
}
if
(
files
.
length
>
0
)
{
for
(
MultipartFile
file
:
files
)
{
Result
uploadResult
=
uploadHdfs
(
file
,
dir
,
hadoopConfigPath
);
if
(
Objects
.
equals
(
uploadResult
.
getCode
(),
CodeEnum
.
ERROR
.
getCode
()))
{
return
uploadResult
;
public
void
uploadHdfs
(
MultipartFile
[]
files
,
String
dir
,
String
hadoopConfigPath
)
{
if
(
Asserts
.
isNotNull
(
files
))
{
try
{
for
(
MultipartFile
file
:
files
)
{
uploadHdfs
(
file
,
dir
,
hadoopConfigPath
);
}
if
(!
uploadFileRecordService
.
saveOrUpdateDir
(
dir
,
UploadFileConstant
.
FLINK_LIB_ID
,
UploadFileConstant
.
TARGET_HDFS
))
{
throw
BusException
.
valueOfMsg
(
"数据库异常"
);
}
}
catch
(
Exception
e
)
{
throw
BusException
.
valueOf
(
"unknown.error"
,
e
);
}
if
(!
uploadFileRecordService
.
saveOrUpdateDir
(
dir
,
UploadFileConstant
.
FLINK_LIB_ID
,
UploadFileConstant
.
TARGET_HDFS
))
{
return
Result
.
failed
(
"数据库异常"
);
}
return
Result
.
succeed
(
"全部上传成功"
);
}
else
{
return
Result
.
succeed
(
"没有检测到要上传的文件"
);
}
}
@Override
public
Result
upload
(
MultipartFile
[]
files
,
Byte
fileType
)
{
public
void
upload
(
MultipartFile
[]
files
,
Byte
fileType
)
{
String
dir
=
UploadFileConstant
.
getDirPath
(
fileType
);
if
(
StringUtils
.
isEmpty
(
dir
))
{
return
Result
.
failed
(
"非法的上传文件类型"
);
}
return
upload
(
files
,
dir
,
fileType
);
upload
(
files
,
dir
,
fileType
);
}
/**
...
...
dinky-admin/src/main/java/org/dinky/utils/HdfsUtil.java
View file @
ab555936
...
...
@@ -20,9 +20,8 @@
package
org
.
dinky
.
utils
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.common.result.Result
;
import
org.dinky.constant.UploadFileConstant
;
import
org.dinky.
model.CodeEnum
;
import
org.dinky.
exception.BusException
;
import
org.apache.hadoop.conf.Configuration
;
import
org.apache.hadoop.fs.FSDataOutputStream
;
...
...
@@ -31,7 +30,6 @@ import org.apache.hadoop.fs.Path;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Objects
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -42,48 +40,33 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public
class
HdfsUtil
{
private
static
FileSystem
hdfs
=
null
;
/**
* Init internal hdfs client
*
* @param hadoopConfigPath HDFS config path
*/
private
static
Result
init
(
String
hadoopConfigPath
)
{
if
(
hdfs
==
null
)
{
if
(
Asserts
.
isNullString
(
hadoopConfigPath
))
{
hadoopConfigPath
=
FilePathUtil
.
removeFileSeparator
(
UploadFileConstant
.
HADOOP_CONF_DIR
);
}
String
coreSiteFilePath
=
hadoopConfigPath
+
"/core-site.xml"
;
String
hdfsSiteFilePath
=
hadoopConfigPath
+
"/hdfs-site.xml"
;
if
(!
new
File
(
coreSiteFilePath
).
exists
()
||
!
new
File
(
hdfsSiteFilePath
).
exists
())
{
return
Result
.
failed
(
"在项目根目录下没有找到 core-site.xml/hdfs-site.xml/yarn-site.xml 文件,请先上传这些文件"
);
}
try
{
final
Configuration
configuration
=
new
Configuration
();
configuration
.
addResource
(
new
Path
(
coreSiteFilePath
));
configuration
.
addResource
(
new
Path
(
hdfsSiteFilePath
));
hdfs
=
FileSystem
.
get
(
configuration
);
}
catch
(
IOException
e
)
{
log
.
error
(
ExceptionUtil
.
stacktraceToString
(
e
));
return
Result
.
failed
(
"内部 hdfs 客户端初始化错误"
);
}
return
Result
.
succeed
(
"hdfs 客户端初始化成功"
);
private
static
FileSystem
init
(
String
hadoopConfigPath
)
{
FileSystem
hdfs
;
if
(
Asserts
.
isNullString
(
hadoopConfigPath
))
{
hadoopConfigPath
=
FilePathUtil
.
removeFileSeparator
(
UploadFileConstant
.
HADOOP_CONF_DIR
);
}
return
Result
.
succeed
(
""
);
}
/**
* Upload file byte content to HDFS
*
* @param path HDFS path
* @param bytes File byte content
* @return {@link Result}
*/
public
static
Result
uploadFile
(
String
path
,
byte
[]
bytes
)
{
return
uploadFile
(
path
,
bytes
,
null
);
String
coreSiteFilePath
=
hadoopConfigPath
+
"/core-site.xml"
;
String
hdfsSiteFilePath
=
hadoopConfigPath
+
"/hdfs-site.xml"
;
if
(!
new
File
(
coreSiteFilePath
).
exists
()
||
!
new
File
(
hdfsSiteFilePath
).
exists
())
{
throw
BusException
.
valueOf
(
"hdfs.file.lose"
);
}
try
{
final
Configuration
configuration
=
new
Configuration
();
configuration
.
addResource
(
new
Path
(
coreSiteFilePath
));
configuration
.
addResource
(
new
Path
(
hdfsSiteFilePath
));
hdfs
=
FileSystem
.
get
(
configuration
);
}
catch
(
IOException
e
)
{
String
msg
=
ExceptionUtil
.
stacktraceToString
(
e
);
log
.
error
(
msg
);
throw
BusException
.
valueOf
(
"hdfs.init.failed"
,
e
);
}
log
.
info
(
"hdfs client initialized successfully"
);
return
hdfs
;
}
/**
...
...
@@ -92,21 +75,14 @@ public class HdfsUtil {
* @param path HDFS path
* @param bytes File byte content
* @param hadoopConfigPath hdfs config path
* @return {@link Result}
*/
public
static
Result
uploadFile
(
String
path
,
byte
[]
bytes
,
String
hadoopConfigPath
)
{
Result
initResult
=
init
(
hadoopConfigPath
);
if
(
Objects
.
equals
(
initResult
.
getCode
(),
CodeEnum
.
SUCCESS
.
getCode
()))
{
try
(
FSDataOutputStream
stream
=
hdfs
.
create
(
new
Path
(
path
),
true
))
{
stream
.
write
(
bytes
);
stream
.
flush
();
return
Result
.
succeed
(
""
);
}
catch
(
IOException
e
)
{
log
.
error
(
ExceptionUtil
.
stacktraceToString
(
e
));
return
Result
.
failed
(
"文件上传失败"
);
}
}
else
{
return
initResult
;
public
static
void
uploadFile
(
String
path
,
byte
[]
bytes
,
String
hadoopConfigPath
)
{
try
(
FileSystem
hdfs
=
init
(
hadoopConfigPath
);
FSDataOutputStream
stream
=
hdfs
.
create
(
new
Path
(
path
),
true
))
{
stream
.
write
(
bytes
);
stream
.
flush
();
}
catch
(
IOException
e
)
{
throw
BusException
.
valueOf
(
"file.upload.failed"
,
e
);
}
}
...
...
@@ -115,14 +91,12 @@ public class HdfsUtil {
*
* @param path HDFS path
* @param file MultipartFile instance
* @return {@link Result}
*/
public
static
Result
uploadFile
(
String
path
,
MultipartFile
file
)
{
public
static
void
uploadFile
(
String
path
,
MultipartFile
file
)
{
try
{
return
uploadFile
(
path
,
file
.
getBytes
()
);
uploadFile
(
path
,
file
.
getBytes
(),
null
);
}
catch
(
IOException
e
)
{
log
.
error
(
ExceptionUtil
.
stacktraceToString
(
e
));
return
Result
.
failed
(
"文件上传失败"
);
throw
BusException
.
valueOf
(
"file.upload.failed"
,
e
);
}
}
...
...
@@ -132,14 +106,12 @@ public class HdfsUtil {
* @param path HDFS path
* @param file MultipartFile instance
* @param hadoopConfigPath hdfs config path
* @return {@link Result}
*/
public
static
Result
uploadFile
(
String
path
,
MultipartFile
file
,
String
hadoopConfigPath
)
{
public
static
void
uploadFile
(
String
path
,
MultipartFile
file
,
String
hadoopConfigPath
)
{
try
{
return
uploadFile
(
path
,
file
.
getBytes
(),
hadoopConfigPath
);
uploadFile
(
path
,
file
.
getBytes
(),
hadoopConfigPath
);
}
catch
(
IOException
e
)
{
log
.
error
(
ExceptionUtil
.
stacktraceToString
(
e
));
return
Result
.
failed
(
"文件上传失败"
);
throw
BusException
.
valueOf
(
"file.upload.failed"
,
e
);
}
}
}
dinky-admin/src/main/java/org/dinky/utils/MessageResolverUtils.java
View file @
ab555936
...
...
@@ -21,7 +21,6 @@ package org.dinky.utils;
import
java.util.Arrays
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.i18n.LocaleContextHolder
;
...
...
@@ -30,7 +29,7 @@ import cn.hutool.extra.spring.SpringUtil;
/** desc: 获取i18n资源文件 */
public
class
MessageResolverUtils
{
@Autowired
private
static
MessageSource
messageSource
=
SpringUtil
.
getBean
(
MessageSource
.
class
);
private
static
MessageSource
messageSource
=
SpringUtil
.
getBean
(
MessageSource
.
class
);
public
MessageResolverUtils
()
{}
...
...
@@ -54,9 +53,7 @@ public class MessageResolverUtils {
*/
public
static
String
getMessages
(
Object
code
,
Object
...
messageArgs
)
{
Object
[]
objs
=
Arrays
.
stream
(
messageArgs
).
map
(
MessageResolverUtils:
:
getMessage
).
toArray
();
String
message
=
messageSource
.
getMessage
(
code
.
toString
(),
objs
,
code
.
toString
(),
LocaleContextHolder
.
getLocale
());
return
message
;
return
messageSource
.
getMessage
(
code
.
toString
(),
objs
,
code
.
toString
(),
LocaleContextHolder
.
getLocale
());
}
}
dinky-admin/src/main/resources/i18n/messages.properties
View file @
ab555936
...
...
@@ -16,65 +16,73 @@
#
#
unknown.i18n
=
未知的国际化信息,请检查。。。
unknown.i18n
=
\u
672A
\u
77E5
\u7684\u
56FD
\u9645\u5316\u
4FE1
\u
606F
\u
FF0C
\u
8BF7
\u
68C0
\u
67E5
\u3002\u3002\u3002
# base crud messages
modify.success
=
修改成功
modify.failed
=
修改失败
delete.success
=
删除成功
delete.failed
=
删除失败
delete.partially.success
=
删除部分成功,但 {0} 删除失败,共 {1} 次失败。
delete.placeholder
=
请选择要删除的记录
create.success
=
新增成功
create.failed
=
新增失败
modify.success
=
\u
4FEE
\u6539\u6210\u
529F
modify.failed
=
\u
4FEE
\u6539\u5931\u
8D25
delete.success
=
\u5220\u9664\u6210\u
529F
delete.failed
=
\u5220\u9664\u5931\u
8D25
delete.partially.success
=
\u5220\u9664\u
90E8
\u5206\u6210\u
529F
\u
FF0C
\u
4F46 {0}
\u5220\u9664\u5931\u
8D25
\u
FF0C
\u5171
{1}
\u
6B21
\u5931\u
8D25
\u3002
delete.placeholder
=
\u
8BF7
\u9009\u
62E9
\u8981\u5220\u9664\u7684\u
8BB0
\u
5F55
create.success
=
\u
65B0
\u
589E
\u6210\u
529F
create.failed
=
\u
65B0
\u
589E
\u5931\u
8D25
# response messages
request.params.error
=
请求参数错误
response.get.success
=
获取成功
response.get.failed
=
获取失败
response.send.success
=
发送成功
response.send.failed
=
发送失败
response.execute.success
=
执行成功
response.execute.failed
=
执行失败
response.restart.success
=
重启成功
response.restart.failed
=
重启失败
response.test.connect.success
=
测试链接成功
response.test.connect.failed
=
测试链接失败
request.params.error
=
\u
8BF7
\u
6C42
\u
53C2
\u6570\u9519\u
8BEF
response.get.success
=
\u
83B7
\u
53D6
\u6210\u
529F
response.get.failed
=
\u
83B7
\u
53D6
\u5931\u
8D25
response.send.success
=
\u
53D1
\u9001\u6210\u
529F
response.send.failed
=
\u
53D1
\u9001\u5931\u
8D25
response.execute.success
=
\u6267\u
884C
\u6210\u
529F
response.execute.failed
=
\u6267\u
884C
\u5931\u
8D25
response.restart.success
=
\u
91CD
\u
542F
\u6210\u
529F
response.restart.failed
=
\u
91CD
\u
542F
\u5931\u
8D25
response.test.connect.success
=
\u
6D4B
\u
8BD5
\u
94FE
\u
63A5
\u6210\u
529F
response.test.connect.failed
=
\u
6D4B
\u
8BD5
\u
94FE
\u
63A5
\u5931\u
8D25
# validation messages
error.param.empty
=
{0}
不能为空
error.param.invalid
=
{0}
无效
error.param.occupied
=
{0}
已被占用
error.param.empty
=
{0}
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
error.param.invalid
=
{0}
\u
65E0
\u6548
error.param.occupied
=
{0}
\u
5DF2
\u
88AB
\u5360\u7528
# login messages
login.fail
=
登录失败,用户名或密码错误
login.not.login
=
用户未登录,请先登录
login.session.timeout
=
会话已过期,请重新登录。
login.success
=
登录成功
login.password.notnull
=
密码不能为空
login.user.not.exists
=
账号不存在
login.user.disabled
=
账号已被禁用
outlogin.success
=
退出成功
login.fail
=
\u
767B
\u
5F55
\u5931\u
8D25,
\u7528\u6237\u
540D
\u6216\u
5BC6
\u7801\u9519\u
8BEF
login.not.login
=
\u7528\u6237\u
672A
\u
767B
\u
5F55
\u
FF0C
\u
8BF7
\u5148\u
767B
\u
5F55
login.session.timeout
=
\u
4F1A
\u
8BDD
\u
5DF2
\u
8FC7
\u
671F
\u
FF0C
\u
8BF7
\u
91CD
\u
65B0
\u
767B
\u
5F55
\u3002
login.success
=
\u
767B
\u
5F55
\u6210\u
529F
login.password.notnull
=
\u
5BC6
\u7801\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
login.user.not.exists
=
\u
8D26
\u
53F7
\u
4E0D
\u
5B58
\u5728
login.user.disabled
=
\u
8D26
\u
53F7
\u
5DF2
\u
88AB
\u7981\u7528
outlogin.success
=
\u9000\u
51FA
\u6210\u
529F
# user messages
user.oldpassword.incorrect
=
旧密码不正确
user.change.password.success
=
密码修改成功
user.change.password.failed
=
密码修改失败
user.register.account.exists
=
该账户已存在
user.register.success
=
注册成功
user.oldpassword.incorrect
=
\u
65E7
\u
5BC6
\u7801\u
4E0D
\u
6B63
\u
786E
user.change.password.success
=
\u
5BC6
\u7801\u
4FEE
\u6539\u6210\u
529F
user.change.password.failed
=
\u
5BC6
\u7801\u
4FEE
\u6539\u5931\u
8D25
user.register.account.exists
=
\u
8BE5
\u
8D26
\u6237\u
5DF2
\u
5B58
\u5728
user.register.success
=
\u
6CE8
\u
518C
\u6210\u
529F
message.welcome
=
\u
6B22
\u
8FCE
\u
4F7F
\u7528
Dinky
message.task.running
=
\u
4EFB
\u
52A1
\u
5DF2
\u5728\u
8FD0
\u
884C
base.not.exists
=
{0}
\u
4E0D
\u
5B58
\u5728
task.project.exists
=
\u
5DE5
\u
7A0B
\u
5DF2
\u
5B58
\u5728
task.project.upload.success
=
\u
4E0A
\u
4F20zip
\u5305\u
5E76
\u
521B
\u
5EFA
\u
5DE5
\u
7A0B
\u6210\u
529F
task.delete.partially.success
=
\u5220\u9664\u5931\u
8D25
\u
FF0C
\u
8BF7
\u
68C0
\u
67E5
\u
4F5C
\u
4E1A {0}
\u
72B6
\u6001\u3002
task.move.success
=
\u
79FB
\u
52A8
\u6210\u
529F
task.move.failed
=
\u
79FB
\u
52A8
\u5931\u
8D25
task.copy.success
=
\u
590D
\u5236\u
4F5C
\u
4E1A
\u6210\u
529F
task.copy.failed
=
\u
590D
\u5236\u
4F5C
\u
4E1A
\u5931\u
8D25
message.welcome
=
欢迎使用 Dinky
message.task.running
=
任务已在运行
base.not.exists
=
{0} 不存在
file.upload.failed
=
\u6587\u
4EF6
\u
4E0A
\u
4F20
\u5931\u
8D25
\u
FF0C
\u
539F
\u
56E0
\u
FF1A{0}
task.project.exists
=
工程已存在
task.project.upload.success
=
上传zip包并创建工程成功
task.delete.partially.success
=
删除失败,请检查作业 {0} 状态。
task.move.success
=
移动成功
task.move.failed
=
移动失败
task.copy.success
=
复制作业成功
task.copy.failed
=
复制作业失败
hdfs.init.failed
=
\u5185\u
90E8 hdfs
\u
5BA2
\u6237\u
7AEF
\u
521D
\u
59CB
\u5316\u9519\u
8BEF
\u
FF0C
\u
539F
\u
56E0
\u
FF1A{0}
hdfs.file.lose
=
\u5728\u9879\u
76EE
\u6839\u
76EE
\u
5F55
\u
4E0B
\u
6CA1
\u6709\u
627E
\u5230
core-site.xml/hdfs-site.xml/yarn-site.xml
\u6587\u
4EF6
\u
FF0C
\u
8BF7
\u5148\u
4E0A
\u
4F20
\u
8FD9
\u
4E9B
\u6587\u
4EF6
unknown.error
=
\u
672A
\u
77E5
\u
5F02
\u
5E38
\u
FF1A{0}
operate.success
=
\u
64CD
\u
4F5C
\u6210\u
529F
dinky-admin/src/main/resources/i18n/messages_en_US.properties
View file @
ab555936
...
...
@@ -75,4 +75,13 @@ task.delete.partially.success=Delete failed, please check job {0} status.
task.move.success
=
Move successfully
task.move.failed
=
Move failed
task.copy.success
=
Copy job succeeded
task.copy.failed
=
Copy job failed
\ No newline at end of file
task.copy.failed
=
Copy job failed
file.upload.failed
=
File upload failed because: {0}
hdfs.init.failed
=
Internal HDFS client initialization error due to:{0}
hdfs.file.lose
=
If you can't find the core-site.xml/hdfs-site.xml/yarn-site.xml file in the root directory of the project, upload them first
unknown.error
=
Unknown error: {0}
operate.success
=
operate success
\ No newline at end of file
dinky-admin/src/main/resources/i18n/messages_zh_CN.properties
View file @
ab555936
...
...
@@ -16,65 +16,73 @@
#
#
unknown.i18n
=
未知的国际化信息,请检查。。。
unknown.i18n
=
\u
672A
\u
77E5
\u7684\u
56FD
\u9645\u5316\u
4FE1
\u
606F
\u
FF0C
\u
8BF7
\u
68C0
\u
67E5
\u3002\u3002\u3002
# base crud messages
modify.success
=
修改成功
modify.failed
=
修改失败
delete.success
=
删除成功
delete.failed
=
删除失败
delete.partially.success
=
删除部分成功,但 {0} 删除失败,共 {1} 次失败。
delete.placeholder
=
请选择要删除的记录
create.success
=
新增成功
create.failed
=
新增失败
modify.success
=
\u
4FEE
\u6539\u6210\u
529F
modify.failed
=
\u
4FEE
\u6539\u5931\u
8D25
delete.success
=
\u5220\u9664\u6210\u
529F
delete.failed
=
\u5220\u9664\u5931\u
8D25
delete.partially.success
=
\u5220\u9664\u
90E8
\u5206\u6210\u
529F
\u
FF0C
\u
4F46 {0}
\u5220\u9664\u5931\u
8D25
\u
FF0C
\u5171
{1}
\u
6B21
\u5931\u
8D25
\u3002
delete.placeholder
=
\u
8BF7
\u9009\u
62E9
\u8981\u5220\u9664\u7684\u
8BB0
\u
5F55
create.success
=
\u
65B0
\u
589E
\u6210\u
529F
create.failed
=
\u
65B0
\u
589E
\u5931\u
8D25
# response messages
request.params.error
=
请求参数错误
response.get.success
=
获取成功
response.get.failed
=
获取失败
response.send.success
=
发送成功
response.send.failed
=
发送失败
response.execute.success
=
执行成功
response.execute.failed
=
执行失败
response.restart.success
=
重启成功
response.restart.failed
=
重启失败
response.test.connect.success
=
测试链接成功
response.test.connect.failed
=
测试链接失败
request.params.error
=
\u
8BF7
\u
6C42
\u
53C2
\u6570\u9519\u
8BEF
response.get.success
=
\u
83B7
\u
53D6
\u6210\u
529F
response.get.failed
=
\u
83B7
\u
53D6
\u5931\u
8D25
response.send.success
=
\u
53D1
\u9001\u6210\u
529F
response.send.failed
=
\u
53D1
\u9001\u5931\u
8D25
response.execute.success
=
\u6267\u
884C
\u6210\u
529F
response.execute.failed
=
\u6267\u
884C
\u5931\u
8D25
response.restart.success
=
\u
91CD
\u
542F
\u6210\u
529F
response.restart.failed
=
\u
91CD
\u
542F
\u5931\u
8D25
response.test.connect.success
=
\u
6D4B
\u
8BD5
\u
94FE
\u
63A5
\u6210\u
529F
response.test.connect.failed
=
\u
6D4B
\u
8BD5
\u
94FE
\u
63A5
\u5931\u
8D25
# validation messages
error.param.empty
=
{0}
不能为空
error.param.invalid
=
{0}
无效
error.param.occupied
=
{0}
已被占用
error.param.empty
=
{0}
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
error.param.invalid
=
{0}
\u
65E0
\u6548
error.param.occupied
=
{0}
\u
5DF2
\u
88AB
\u5360\u7528
# login messages
login.fail
=
登录失败,用户名或密码错误
login.not.login
=
用户未登录,请先登录
login.session.timeout
=
会话已过期,请重新登录。
login.success
=
登录成功
login.password.notnull
=
密码不能为空
login.user.not.exists
=
账号不存在
login.user.disabled
=
账号已被禁用
outlogin.success
=
退出成功
login.fail
=
\u
767B
\u
5F55
\u5931\u
8D25,
\u7528\u6237\u
540D
\u6216\u
5BC6
\u7801\u9519\u
8BEF
login.not.login
=
\u7528\u6237\u
672A
\u
767B
\u
5F55
\u
FF0C
\u
8BF7
\u5148\u
767B
\u
5F55
login.session.timeout
=
\u
4F1A
\u
8BDD
\u
5DF2
\u
8FC7
\u
671F
\u
FF0C
\u
8BF7
\u
91CD
\u
65B0
\u
767B
\u
5F55
\u3002
login.success
=
\u
767B
\u
5F55
\u6210\u
529F
login.password.notnull
=
\u
5BC6
\u7801\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
login.user.not.exists
=
\u
8D26
\u
53F7
\u
4E0D
\u
5B58
\u5728
login.user.disabled
=
\u
8D26
\u
53F7
\u
5DF2
\u
88AB
\u7981\u7528
outlogin.success
=
\u9000\u
51FA
\u6210\u
529F
# user messages
user.oldpassword.incorrect
=
旧密码不正确
user.change.password.success
=
密码修改成功
user.change.password.failed
=
密码修改失败
user.register.account.exists
=
该账户已存在
user.register.success
=
注册成功
user.oldpassword.incorrect
=
\u
65E7
\u
5BC6
\u7801\u
4E0D
\u
6B63
\u
786E
user.change.password.success
=
\u
5BC6
\u7801\u
4FEE
\u6539\u6210\u
529F
user.change.password.failed
=
\u
5BC6
\u7801\u
4FEE
\u6539\u5931\u
8D25
user.register.account.exists
=
\u
8BE5
\u
8D26
\u6237\u
5DF2
\u
5B58
\u5728
user.register.success
=
\u
6CE8
\u
518C
\u6210\u
529F
message.welcome
=
\u
6B22
\u
8FCE
\u
4F7F
\u7528
Dinky
message.task.running
=
\u
4EFB
\u
52A1
\u
5DF2
\u5728\u
8FD0
\u
884C
base.not.exists
=
{0}
\u
4E0D
\u
5B58
\u5728
task.project.exists
=
\u
5DE5
\u
7A0B
\u
5DF2
\u
5B58
\u5728
task.project.upload.success
=
\u
4E0A
\u
4F20zip
\u5305\u
5E76
\u
521B
\u
5EFA
\u
5DE5
\u
7A0B
\u6210\u
529F
task.delete.partially.success
=
\u5220\u9664\u5931\u
8D25
\u
FF0C
\u
8BF7
\u
68C0
\u
67E5
\u
4F5C
\u
4E1A {0}
\u
72B6
\u6001\u3002
task.move.success
=
\u
79FB
\u
52A8
\u6210\u
529F
task.move.failed
=
\u
79FB
\u
52A8
\u5931\u
8D25
task.copy.success
=
\u
590D
\u5236\u
4F5C
\u
4E1A
\u6210\u
529F
task.copy.failed
=
\u
590D
\u5236\u
4F5C
\u
4E1A
\u5931\u
8D25
message.welcome
=
欢迎使用 Dinky
message.task.running
=
任务已在运行
base.not.exists
=
{0} 不存在
file.upload.failed
=
\u6587\u
4EF6
\u
4E0A
\u
4F20
\u5931\u
8D25
\u
FF0C
\u
539F
\u
56E0
\u
FF1A{0}
task.project.exists
=
工程已存在
task.project.upload.success
=
上传zip包并创建工程成功
task.delete.partially.success
=
删除失败,请检查作业 {0} 状态。
task.move.success
=
移动成功
task.move.failed
=
移动失败
task.copy.success
=
复制作业成功
task.copy.failed
=
复制作业失败
hdfs.init.failed
=
\u5185\u
90E8 hdfs
\u
5BA2
\u6237\u
7AEF
\u
521D
\u
59CB
\u5316\u9519\u
8BEF
\u
FF0C
\u
539F
\u
56E0
\u
FF1A{0}
hdfs.file.lose
=
\u5728\u9879\u
76EE
\u6839\u
76EE
\u
5F55
\u
4E0B
\u
6CA1
\u6709\u
627E
\u5230
core-site.xml/hdfs-site.xml/yarn-site.xml
\u6587\u
4EF6
\u
FF0C
\u
8BF7
\u5148\u
4E0A
\u
4F20
\u
8FD9
\u
4E9B
\u6587\u
4EF6
unknown.error
=
\u
672A
\u
77E5
\u
5F02
\u
5E38
\u
FF1A{0}
operate.success
=
\u
64CD
\u
4F5C
\u6210\u
529F
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment