Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
6b5c1734
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6b5c1734
编写于
5月 15, 2020
作者:
Y
Yangze Guo
提交者:
Till Rohrmann
5月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[hotfix] Extract PluginManager interface
上级
6075ed70
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
94 addition
and
54 deletion
+94
-54
flink-core/src/main/java/org/apache/flink/core/plugin/DefaultPluginManager.java
...va/org/apache/flink/core/plugin/DefaultPluginManager.java
+84
-0
flink-core/src/main/java/org/apache/flink/core/plugin/PluginManager.java
...main/java/org/apache/flink/core/plugin/PluginManager.java
+4
-49
flink-core/src/main/java/org/apache/flink/core/plugin/PluginUtils.java
...c/main/java/org/apache/flink/core/plugin/PluginUtils.java
+2
-2
flink-tests/src/test/java/org/apache/flink/test/plugin/DefaultPluginManagerTest.java
...rg/apache/flink/test/plugin/DefaultPluginManagerTest.java
+4
-3
未找到文件。
flink-core/src/main/java/org/apache/flink/core/plugin/DefaultPluginManager.java
0 → 100644
浏览文件 @
6b5c1734
/*
* 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.apache.flink.core.plugin
;
import
org.apache.flink.annotation.Internal
;
import
org.apache.flink.annotation.VisibleForTesting
;
import
org.apache.flink.shaded.guava18.com.google.common.collect.Iterators
;
import
javax.annotation.concurrent.ThreadSafe
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Iterator
;
/**
* Default implementation of {@link PluginManager}.
*/
@Internal
@ThreadSafe
public
class
DefaultPluginManager
implements
PluginManager
{
/** Parent-classloader to all classloader that are used for plugin loading. We expect that this is thread-safe. */
private
final
ClassLoader
parentClassLoader
;
/** A collection of descriptions of all plugins known to this plugin manager. */
private
final
Collection
<
PluginDescriptor
>
pluginDescriptors
;
/** List of patterns for classes that should always be resolved from the parent ClassLoader. */
private
final
String
[]
alwaysParentFirstPatterns
;
@VisibleForTesting
DefaultPluginManager
()
{
parentClassLoader
=
null
;
pluginDescriptors
=
null
;
alwaysParentFirstPatterns
=
null
;
}
public
DefaultPluginManager
(
Collection
<
PluginDescriptor
>
pluginDescriptors
,
String
[]
alwaysParentFirstPatterns
)
{
this
(
pluginDescriptors
,
DefaultPluginManager
.
class
.
getClassLoader
(),
alwaysParentFirstPatterns
);
}
public
DefaultPluginManager
(
Collection
<
PluginDescriptor
>
pluginDescriptors
,
ClassLoader
parentClassLoader
,
String
[]
alwaysParentFirstPatterns
)
{
this
.
pluginDescriptors
=
pluginDescriptors
;
this
.
parentClassLoader
=
parentClassLoader
;
this
.
alwaysParentFirstPatterns
=
alwaysParentFirstPatterns
;
}
@Override
public
<
P
>
Iterator
<
P
>
load
(
Class
<
P
>
service
)
{
ArrayList
<
Iterator
<
P
>>
combinedIterators
=
new
ArrayList
<>(
pluginDescriptors
.
size
());
for
(
PluginDescriptor
pluginDescriptor
:
pluginDescriptors
)
{
PluginLoader
pluginLoader
=
PluginLoader
.
create
(
pluginDescriptor
,
parentClassLoader
,
alwaysParentFirstPatterns
);
combinedIterators
.
add
(
pluginLoader
.
load
(
service
));
}
return
Iterators
.
concat
(
combinedIterators
.
iterator
());
}
@Override
public
String
toString
()
{
return
"PluginManager{"
+
"parentClassLoader="
+
parentClassLoader
+
", pluginDescriptors="
+
pluginDescriptors
+
", alwaysParentFirstPatterns="
+
Arrays
.
toString
(
alwaysParentFirstPatterns
)
+
'}'
;
}
}
flink-core/src/main/java/org/apache/flink/core/plugin/PluginManager.java
浏览文件 @
6b5c1734
...
@@ -18,42 +18,13 @@
...
@@ -18,42 +18,13 @@
package
org.apache.flink.core.plugin
;
package
org.apache.flink.core.plugin
;
import
org.apache.flink.annotation.Internal
;
import
org.apache.flink.shaded.guava18.com.google.common.collect.Iterators
;
import
javax.annotation.concurrent.ThreadSafe
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.Iterator
;
/**
/**
* Manager class and entry-point for the plugin mechanism in Flink.
* PluginManager is responsible for managing cluster plugins which are loaded using separate class loaders so that their dependencies
* don't interfere with Flink's dependencies.
*/
*/
@Internal
public
interface
PluginManager
{
@ThreadSafe
public
class
PluginManager
{
/** Parent-classloader to all classloader that are used for plugin loading. We expect that this is thread-safe. */
private
final
ClassLoader
parentClassLoader
;
/** A collection of descriptions of all plugins known to this plugin manager. */
private
final
Collection
<
PluginDescriptor
>
pluginDescriptors
;
/** List of patterns for classes that should always be resolved from the parent ClassLoader. */
private
final
String
[]
alwaysParentFirstPatterns
;
public
PluginManager
(
Collection
<
PluginDescriptor
>
pluginDescriptors
,
String
[]
alwaysParentFirstPatterns
)
{
this
(
pluginDescriptors
,
PluginManager
.
class
.
getClassLoader
(),
alwaysParentFirstPatterns
);
}
public
PluginManager
(
Collection
<
PluginDescriptor
>
pluginDescriptors
,
ClassLoader
parentClassLoader
,
String
[]
alwaysParentFirstPatterns
)
{
this
.
pluginDescriptors
=
pluginDescriptors
;
this
.
parentClassLoader
=
parentClassLoader
;
this
.
alwaysParentFirstPatterns
=
alwaysParentFirstPatterns
;
}
/**
/**
* Returns in iterator over all available implementations of the given service interface (SPI) in all the plugins
* Returns in iterator over all available implementations of the given service interface (SPI) in all the plugins
...
@@ -63,21 +34,5 @@ public class PluginManager {
...
@@ -63,21 +34,5 @@ public class PluginManager {
* @param <P> Type of the requested plugin service.
* @param <P> Type of the requested plugin service.
* @return Iterator over all implementations of the given service that could be loaded from all known plugins.
* @return Iterator over all implementations of the given service that could be loaded from all known plugins.
*/
*/
public
<
P
>
Iterator
<
P
>
load
(
Class
<
P
>
service
)
{
<
P
>
Iterator
<
P
>
load
(
Class
<
P
>
service
);
ArrayList
<
Iterator
<
P
>>
combinedIterators
=
new
ArrayList
<>(
pluginDescriptors
.
size
());
for
(
PluginDescriptor
pluginDescriptor
:
pluginDescriptors
)
{
PluginLoader
pluginLoader
=
PluginLoader
.
create
(
pluginDescriptor
,
parentClassLoader
,
alwaysParentFirstPatterns
);
combinedIterators
.
add
(
pluginLoader
.
load
(
service
));
}
return
Iterators
.
concat
(
combinedIterators
.
iterator
());
}
@Override
public
String
toString
()
{
return
"PluginManager{"
+
"parentClassLoader="
+
parentClassLoader
+
", pluginDescriptors="
+
pluginDescriptors
+
", alwaysParentFirstPatterns="
+
Arrays
.
toString
(
alwaysParentFirstPatterns
)
+
'}'
;
}
}
}
flink-core/src/main/java/org/apache/flink/core/plugin/PluginUtils.java
浏览文件 @
6b5c1734
...
@@ -43,13 +43,13 @@ public final class PluginUtils {
...
@@ -43,13 +43,13 @@ public final class PluginUtils {
try
{
try
{
Collection
<
PluginDescriptor
>
pluginDescriptors
=
Collection
<
PluginDescriptor
>
pluginDescriptors
=
new
DirectoryBasedPluginFinder
(
pluginConfig
.
getPluginsPath
().
get
()).
findPlugins
();
new
DirectoryBasedPluginFinder
(
pluginConfig
.
getPluginsPath
().
get
()).
findPlugins
();
return
new
PluginManager
(
pluginDescriptors
,
pluginConfig
.
getAlwaysParentFirstPatterns
());
return
new
Default
PluginManager
(
pluginDescriptors
,
pluginConfig
.
getAlwaysParentFirstPatterns
());
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
FlinkRuntimeException
(
"Exception when trying to initialize plugin system."
,
e
);
throw
new
FlinkRuntimeException
(
"Exception when trying to initialize plugin system."
,
e
);
}
}
}
}
else
{
else
{
return
new
PluginManager
(
Collections
.
emptyList
(),
pluginConfig
.
getAlwaysParentFirstPatterns
());
return
new
Default
PluginManager
(
Collections
.
emptyList
(),
pluginConfig
.
getAlwaysParentFirstPatterns
());
}
}
}
}
}
}
flink-tests/src/test/java/org/apache/flink/test/plugin/PluginManagerTest.java
→
flink-tests/src/test/java/org/apache/flink/test/plugin/
Default
PluginManagerTest.java
浏览文件 @
6b5c1734
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
package
org.apache.flink.test.plugin
;
package
org.apache.flink.test.plugin
;
import
org.apache.flink.core.plugin.DefaultPluginManager
;
import
org.apache.flink.core.plugin.DirectoryBasedPluginFinder
;
import
org.apache.flink.core.plugin.DirectoryBasedPluginFinder
;
import
org.apache.flink.core.plugin.PluginDescriptor
;
import
org.apache.flink.core.plugin.PluginDescriptor
;
import
org.apache.flink.core.plugin.PluginFinder
;
import
org.apache.flink.core.plugin.PluginFinder
;
...
@@ -43,9 +44,9 @@ import java.util.List;
...
@@ -43,9 +44,9 @@ import java.util.List;
import
java.util.Set
;
import
java.util.Set
;
/**
/**
* Test for {@link PluginManager}.
* Test for {@link
Default
PluginManager}.
*/
*/
public
class
PluginManagerTest
extends
PluginTestBase
{
public
class
Default
PluginManagerTest
extends
PluginTestBase
{
@Rule
@Rule
public
TemporaryFolder
temporaryFolder
=
new
TemporaryFolder
();
public
TemporaryFolder
temporaryFolder
=
new
TemporaryFolder
();
...
@@ -84,7 +85,7 @@ public class PluginManagerTest extends PluginTestBase {
...
@@ -84,7 +85,7 @@ public class PluginManagerTest extends PluginTestBase {
public
void
testPluginLoading
()
{
public
void
testPluginLoading
()
{
String
[]
parentPatterns
=
{
TestSpi
.
class
.
getName
(),
OtherTestSpi
.
class
.
getName
()
};
String
[]
parentPatterns
=
{
TestSpi
.
class
.
getName
(),
OtherTestSpi
.
class
.
getName
()
};
final
PluginManager
pluginManager
=
new
PluginManager
(
descriptors
,
PARENT_CLASS_LOADER
,
parentPatterns
);
final
PluginManager
pluginManager
=
new
Default
PluginManager
(
descriptors
,
PARENT_CLASS_LOADER
,
parentPatterns
);
final
List
<
TestSpi
>
serviceImplList
=
Lists
.
newArrayList
(
pluginManager
.
load
(
TestSpi
.
class
));
final
List
<
TestSpi
>
serviceImplList
=
Lists
.
newArrayList
(
pluginManager
.
load
(
TestSpi
.
class
));
Assert
.
assertEquals
(
2
,
serviceImplList
.
size
());
Assert
.
assertEquals
(
2
,
serviceImplList
.
size
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录