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
96a0a910
Unverified
Commit
96a0a910
authored
Sep 19, 2023
by
ZackYoung
Committed by
GitHub
Sep 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] [Flink]support_add_jar_other_url (#2330)
parent
b45541fd
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
212 additions
and
20 deletions
+212
-20
SystemInit.java
dinky-admin/src/main/java/org/dinky/init/SystemInit.java
+13
-2
BaseResourceManager.java
.../java/org/dinky/service/resource/BaseResourceManager.java
+5
-1
HdfsResourceManager.java
.../org/dinky/service/resource/impl/HdfsResourceManager.java
+10
-4
OssResourceManager.java
...a/org/dinky/service/resource/impl/OssResourceManager.java
+15
-8
RsURLConnection.java
dinky-admin/src/main/java/org/dinky/url/RsURLConnection.java
+60
-0
RsURLStreamHandler.java
...admin/src/main/java/org/dinky/url/RsURLStreamHandler.java
+33
-0
RsURLStreamHandlerFactory.java
...rc/main/java/org/dinky/url/RsURLStreamHandlerFactory.java
+42
-0
URLUtils.java
dinky-common/src/main/java/org/dinky/utils/URLUtils.java
+28
-0
AddJarSqlParser.java
...src/main/java/org/dinky/parser/check/AddJarSqlParser.java
+6
-5
No files found.
dinky-admin/src/main/java/org/dinky/init/SystemInit.java
View file @
96a0a910
...
...
@@ -44,10 +44,12 @@ import org.dinky.service.TaskService;
import
org.dinky.service.TenantService
;
import
org.dinky.service.resource.impl.HdfsResourceManager
;
import
org.dinky.service.resource.impl.OssResourceManager
;
import
org.dinky.url.RsURLStreamHandlerFactory
;
import
org.dinky.utils.JSONUtil
;
import
org.dinky.utils.OssTemplate
;
import
org.dinky.utils.UDFUtils
;
import
org.apache.catalina.webresources.TomcatURLStreamHandlerFactory
;
import
org.apache.hadoop.conf.Configuration
;
import
org.apache.hadoop.fs.FileSystem
;
...
...
@@ -104,6 +106,11 @@ public class SystemInit implements ApplicationRunner {
initDolphinScheduler
();
registerUDF
();
updateGitBuildState
();
registerURL
();
}
private
void
registerURL
()
{
TomcatURLStreamHandlerFactory
.
getInstance
().
addUserFactory
(
new
RsURLStreamHandlerFactory
());
}
private
void
initResources
()
{
...
...
@@ -162,7 +169,9 @@ public class SystemInit implements ApplicationRunner {
}));
}
/** init task monitor */
/**
* init task monitor
*/
private
void
initTaskMonitor
()
{
List
<
JobInstance
>
jobInstances
=
jobInstanceService
.
listJobInstanceActive
();
List
<
DaemonTaskConfig
>
configList
=
new
ArrayList
<>();
...
...
@@ -173,7 +182,9 @@ public class SystemInit implements ApplicationRunner {
DaemonFactory
.
start
(
configList
);
}
/** init DolphinScheduler */
/**
* init DolphinScheduler
*/
private
void
initDolphinScheduler
()
{
systemConfiguration
.
getAllConfiguration
()
...
...
dinky-admin/src/main/java/org/dinky/service/resource/BaseResourceManager.java
View file @
96a0a910
...
...
@@ -23,6 +23,8 @@ import org.dinky.data.model.SystemConfiguration;
import
org.dinky.service.resource.impl.HdfsResourceManager
;
import
org.dinky.service.resource.impl.OssResourceManager
;
import
java.io.InputStream
;
import
org.springframework.web.multipart.MultipartFile
;
import
cn.hutool.core.io.FileUtil
;
...
...
@@ -39,6 +41,8 @@ public interface BaseResourceManager {
String
getFileContent
(
String
path
);
InputStream
getFile
(
String
path
);
static
BaseResourceManager
getInstance
()
{
switch
(
SystemConfiguration
.
getInstances
().
getResourcesModel
().
getValue
())
{
case
HDFS:
...
...
@@ -50,7 +54,7 @@ public interface BaseResourceManager {
}
}
default
String
getFile
(
String
path
)
{
default
String
getFile
Path
(
String
path
)
{
return
FileUtil
.
normalize
(
FileUtil
.
file
(
instances
.
getResourcesUploadBasePath
().
getValue
(),
path
)
.
toString
());
...
...
dinky-admin/src/main/java/org/dinky/service/resource/impl/HdfsResourceManager.java
View file @
96a0a910
...
...
@@ -27,6 +27,7 @@ import org.apache.hadoop.fs.FileSystem;
import
org.apache.hadoop.fs.Path
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -38,7 +39,7 @@ public class HdfsResourceManager implements BaseResourceManager {
@Override
public
void
remove
(
String
path
)
{
try
{
getHdfs
().
delete
(
new
Path
(
getFile
(
path
)),
true
);
getHdfs
().
delete
(
new
Path
(
getFile
Path
(
path
)),
true
);
}
catch
(
IOException
e
)
{
throw
BusException
.
valueOf
(
"file.delete.failed"
,
e
);
}
...
...
@@ -47,7 +48,7 @@ public class HdfsResourceManager implements BaseResourceManager {
@Override
public
void
rename
(
String
path
,
String
newPath
)
{
try
{
getHdfs
().
rename
(
new
Path
(
getFile
(
path
)),
new
Path
(
getFile
(
newPath
)));
getHdfs
().
rename
(
new
Path
(
getFile
Path
(
path
)),
new
Path
(
getFilePath
(
newPath
)));
}
catch
(
IOException
e
)
{
throw
BusException
.
valueOf
(
"file.rename.failed"
,
e
);
}
...
...
@@ -56,7 +57,7 @@ public class HdfsResourceManager implements BaseResourceManager {
@Override
public
void
putFile
(
String
path
,
MultipartFile
file
)
{
try
{
FSDataOutputStream
stream
=
getHdfs
().
create
(
new
Path
(
getFile
(
path
)),
true
);
FSDataOutputStream
stream
=
getHdfs
().
create
(
new
Path
(
getFile
Path
(
path
)),
true
);
stream
.
write
(
file
.
getBytes
());
stream
.
flush
();
stream
.
close
();
...
...
@@ -67,8 +68,13 @@ public class HdfsResourceManager implements BaseResourceManager {
@Override
public
String
getFileContent
(
String
path
)
{
return
IoUtil
.
readUtf8
(
getFile
(
path
));
}
@Override
public
InputStream
getFile
(
String
path
)
{
try
{
return
IoUtil
.
readUtf8
(
getHdfs
().
open
(
new
Path
(
getFile
(
path
)
)));
return
getHdfs
().
open
(
new
Path
(
getFilePath
(
path
)));
}
catch
(
IOException
e
)
{
throw
BusException
.
valueOf
(
"file.read.failed"
,
e
);
}
...
...
dinky-admin/src/main/java/org/dinky/service/resource/impl/OssResourceManager.java
View file @
96a0a910
...
...
@@ -24,6 +24,8 @@ import org.dinky.process.exception.DinkyException;
import
org.dinky.service.resource.BaseResourceManager
;
import
org.dinky.utils.OssTemplate
;
import
java.io.InputStream
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.amazonaws.services.s3.model.CopyObjectRequest
;
...
...
@@ -36,26 +38,26 @@ public class OssResourceManager implements BaseResourceManager {
@Override
public
void
remove
(
String
path
)
{
getOssTemplate
().
removeObject
(
getOssTemplate
().
getBucketName
(),
getFile
(
path
));
getOssTemplate
().
removeObject
(
getOssTemplate
().
getBucketName
(),
getFile
Path
(
path
));
}
@Override
public
void
rename
(
String
path
,
String
newPath
)
{
CopyObjectRequest
copyObjectRequest
=
new
CopyObjectRequest
(
getOssTemplate
().
getBucketName
(),
getFile
(
path
),
getFile
Path
(
path
),
getOssTemplate
().
getBucketName
(),
getFile
(
newPath
));
getFile
Path
(
newPath
));
getOssTemplate
().
getAmazonS3
().
copyObject
(
copyObjectRequest
);
DeleteObjectRequest
deleteObjectRequest
=
new
DeleteObjectRequest
(
getOssTemplate
().
getBucketName
(),
getFile
(
path
));
new
DeleteObjectRequest
(
getOssTemplate
().
getBucketName
(),
getFile
Path
(
path
));
getOssTemplate
().
getAmazonS3
().
deleteObject
(
deleteObjectRequest
);
}
@Override
public
void
putFile
(
String
path
,
MultipartFile
file
)
{
try
{
getOssTemplate
().
putObject
(
getOssTemplate
().
getBucketName
(),
getFile
(
path
),
file
.
getInputStream
());
getOssTemplate
().
putObject
(
getOssTemplate
().
getBucketName
(),
getFile
Path
(
path
),
file
.
getInputStream
());
}
catch
(
Exception
e
)
{
throw
new
DinkyException
(
e
);
}
...
...
@@ -63,9 +65,14 @@ public class OssResourceManager implements BaseResourceManager {
@Override
public
String
getFileContent
(
String
path
)
{
return
IoUtil
.
readUtf8
(
getOssTemplate
()
.
getObject
(
getOssTemplate
().
getBucketName
(),
getFile
(
path
))
.
getObjectContent
());
return
IoUtil
.
readUtf8
(
getFile
(
path
));
}
@Override
public
InputStream
getFile
(
String
path
)
{
return
getOssTemplate
()
.
getObject
(
getOssTemplate
().
getBucketName
(),
getFilePath
(
path
))
.
getObjectContent
();
}
public
OssTemplate
getOssTemplate
()
{
...
...
dinky-admin/src/main/java/org/dinky/url/RsURLConnection.java
0 → 100644
View file @
96a0a910
/*
*
* 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.
*
*/
package
org
.
dinky
.
url
;
import
org.dinky.data.exception.BusException
;
import
org.dinky.function.constant.PathConstant
;
import
org.dinky.service.resource.BaseResourceManager
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
public
class
RsURLConnection
extends
URLConnection
{
private
InputStream
inputStream
;
@Override
public
void
connect
()
{
BaseResourceManager
instance
=
BaseResourceManager
.
getInstance
();
if
(
instance
==
null
)
{
throw
BusException
.
valueOf
(
"ResourceManager is disabled"
);
}
}
@Override
public
InputStream
getInputStream
()
{
connect
();
return
inputStream
;
}
public
RsURLConnection
(
URL
url
)
{
super
(
url
);
}
public
File
toFile
()
{
connect
();
String
path
=
StrUtil
.
join
(
File
.
separator
,
PathConstant
.
TMP_PATH
,
"rs"
,
getURL
().
getPath
());
return
FileUtil
.
writeFromStream
(
inputStream
,
path
);
}
}
dinky-admin/src/main/java/org/dinky/url/RsURLStreamHandler.java
0 → 100644
View file @
96a0a910
/*
*
* 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.
*
*/
package
org
.
dinky
.
url
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.net.URLStreamHandler
;
public
class
RsURLStreamHandler
extends
URLStreamHandler
{
@Override
protected
URLConnection
openConnection
(
URL
u
)
throws
IOException
{
return
new
RsURLConnection
(
u
);
}
}
dinky-admin/src/main/java/org/dinky/url/RsURLStreamHandlerFactory.java
0 → 100644
View file @
96a0a910
/*
*
* 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.
*
*/
package
org
.
dinky
.
url
;
import
org.apache.hadoop.fs.FsUrlStreamHandlerFactory
;
import
java.net.URLStreamHandler
;
import
java.net.URLStreamHandlerFactory
;
import
cn.hutool.core.lang.Singleton
;
public
class
RsURLStreamHandlerFactory
implements
URLStreamHandlerFactory
{
@Override
public
URLStreamHandler
createURLStreamHandler
(
String
protocol
)
{
if
(
"rs"
.
equals
(
protocol
))
{
return
new
RsURLStreamHandler
();
}
try
{
Class
.
forName
(
"org.apache.hadoop.fs.FsUrlStreamHandlerFactory"
);
}
catch
(
Exception
e
)
{
return
null
;
}
return
Singleton
.
get
(
FsUrlStreamHandlerFactory
.
class
).
createURLStreamHandler
(
protocol
);
}
}
dinky-common/src/main/java/org/dinky/utils/URLUtils.java
View file @
96a0a910
...
...
@@ -22,12 +22,40 @@ package org.dinky.utils;
import
java.io.File
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.Arrays
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
/** @since 0.7.0 */
public
class
URLUtils
{
private
static
final
String
TMP_PATH
=
StrUtil
.
join
(
File
.
separator
,
System
.
getProperty
(
"user.dir"
),
"tmp"
);
/**
* url download file to local
* @param urlPath urlPath
* @return file
*/
public
static
File
toFile
(
String
urlPath
)
{
try
{
URL
url
=
new
URL
(
urlPath
);
URLConnection
urlConnection
=
url
.
openConnection
();
if
(
"http"
.
equals
(
url
.
getProtocol
())
||
"https"
.
equals
(
url
.
getProtocol
())
||
"hdfs"
.
equals
(
url
.
getProtocol
())
||
"rs"
.
equals
(
url
.
getProtocol
()))
{
String
path
=
StrUtil
.
join
(
File
.
separator
,
TMP_PATH
,
"downloadFile"
,
url
.
getPath
());
return
FileUtil
.
writeFromStream
(
urlConnection
.
getInputStream
(),
path
);
}
else
if
(
"file"
.
equals
(
url
.
getProtocol
()))
{
return
new
File
(
url
.
getPath
());
}
return
null
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* 获得URL,常用于使用绝对路径时的情况
...
...
dinky-executor/src/main/java/org/dinky/parser/check/AddJarSqlParser.java
View file @
96a0a910
...
...
@@ -20,6 +20,7 @@
package
org
.
dinky
.
parser
.
check
;
import
org.dinky.process.exception.DinkyException
;
import
org.dinky.utils.URLUtils
;
import
java.io.File
;
import
java.util.HashSet
;
...
...
@@ -29,7 +30,6 @@ import java.util.regex.Pattern;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.ReUtil
;
import
cn.hutool.core.util.StrUtil
;
...
...
@@ -51,11 +51,12 @@ public class AddJarSqlParser {
patternStatements
(
statements
).
stream
()
.
map
(
x
->
ReUtil
.
findAll
(
ADD_JAR_PATTERN
,
x
,
2
).
get
(
0
))
.
distinct
()
.
forEach
(
path
->
{
if
(!
FileUtil
.
exist
(
path
))
{
throw
new
DinkyException
(
StrUtil
.
format
(
"file : {} not exists!"
,
path
));
.
forEach
(
urlPath
->
{
File
file
=
URLUtils
.
toFile
(
urlPath
);
if
(
file
==
null
||
!
file
.
exists
())
{
throw
new
DinkyException
(
StrUtil
.
format
(
"file : {} not exists!"
,
urlPath
));
}
fileSet
.
add
(
FileUtil
.
file
(
path
)
);
fileSet
.
add
(
file
);
});
return
fileSet
;
}
...
...
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