Skip to content

Commit 221db5e

Browse files
authored
[server] Introduce plugin.classloader.parent-first-patterns.additional configuration (#1222)
1 parent 05458a3 commit 221db5e

File tree

4 files changed

+101
-26
lines changed

4 files changed

+101
-26
lines changed

fluss-common/src/main/java/org/apache/fluss/config/ConfigOptions.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,21 @@ public class ConfigOptions {
112112
.withDescription(
113113
"A (semicolon-separated) list of patterns that specifies which classes should always be"
114114
+ " resolved through the plugin parent ClassLoader first. A pattern is a simple prefix that is checked "
115-
+ " against the fully qualified class name. This setting should generally not be modified.");
115+
+ " against the fully qualified class name. This setting should generally not be modified. To add another "
116+
+ " pattern we recommend to use \"plugin.classloader.parent-first-patterns.additional\" instead.");
117+
118+
public static final ConfigOption<List<String>>
119+
PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL =
120+
key("plugin.classloader.parent-first-patterns.additional")
121+
.stringType()
122+
.asList()
123+
.defaultValues()
124+
.withDescription(
125+
"A (semicolon-separated) list of patterns that specifies which classes should always be"
126+
+ " resolved through the plugin parent ClassLoader first. A pattern is a simple prefix that is checked "
127+
+ " against the fully qualified class name. These patterns are appended to \""
128+
+ PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS.key()
129+
+ "\".");
116130

117131
public static final ConfigOption<Duration> AUTO_PARTITION_CHECK_INTERVAL =
118132
key("auto-partition.check.interval")

fluss-common/src/main/java/org/apache/fluss/plugin/PluginConfig.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717

1818
package org.apache.fluss.plugin;
1919

20-
import org.apache.fluss.config.ConfigOptions;
2120
import org.apache.fluss.config.Configuration;
21+
import org.apache.fluss.shaded.guava32.com.google.common.collect.Iterables;
2222

2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525

2626
import java.io.File;
2727
import java.nio.file.Path;
28+
import java.util.List;
2829
import java.util.Optional;
2930

31+
import static org.apache.fluss.config.ConfigOptions.PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS;
32+
import static org.apache.fluss.config.ConfigOptions.PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL;
33+
3034
/** Stores the configuration for plugins mechanism. */
3135
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
3236
public class PluginConfig {
@@ -62,9 +66,13 @@ public String[] getAlwaysParentFirstPatterns() {
6266
public static PluginConfig fromConfiguration(Configuration configuration) {
6367
return new PluginConfig(
6468
getPluginsDir().map(File::toPath),
65-
configuration
66-
.get(ConfigOptions.PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS)
67-
.toArray(new String[0]));
69+
getPluginParentFirstLoaderPatterns(configuration));
70+
}
71+
72+
private static String[] getPluginParentFirstLoaderPatterns(Configuration config) {
73+
List<String> base = config.get(PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS);
74+
List<String> append = config.get(PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL);
75+
return Iterables.toArray(Iterables.concat(base, append), String.class);
6876
}
6977

7078
public static Optional<File> getPluginsDir() {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.fluss.plugin;
19+
20+
import org.apache.fluss.config.Configuration;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import java.util.Arrays;
25+
import java.util.Collections;
26+
27+
import static org.apache.fluss.config.ConfigOptions.PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS;
28+
import static org.apache.fluss.config.ConfigOptions.PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL;
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
/** Test for {@link PluginConfig} . */
32+
class PluginConfigTest {
33+
34+
@Test
35+
void testFromConfig() {
36+
// only set parent-first-patterns.default
37+
Configuration config = new Configuration();
38+
config.set(
39+
PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS,
40+
Arrays.asList("org.apache.fluss.", "java."));
41+
PluginConfig pluginConfig = PluginConfig.fromConfiguration(config);
42+
assertThat(pluginConfig.getAlwaysParentFirstPatterns())
43+
.isEqualTo(new String[] {"org.apache.fluss.", "java."});
44+
// also set parent-first-patterns.additional
45+
config.set(
46+
PLUGIN_ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL,
47+
Collections.singletonList("org.apache.hadoop."));
48+
pluginConfig = PluginConfig.fromConfiguration(config);
49+
assertThat(pluginConfig.getAlwaysParentFirstPatterns())
50+
.isEqualTo(new String[] {"org.apache.fluss.", "java.", "org.apache.hadoop."});
51+
}
52+
}

0 commit comments

Comments
 (0)