Skip to content

Commit 5c0356b

Browse files
committed
Refactor SparkAuronConfiguration and remove deprecated AuronConf classes
1 parent 4964053 commit 5c0356b

25 files changed

Lines changed: 904 additions & 1510 deletions

File tree

auron-core/src/main/java/org/apache/auron/configuration/AuronConfiguration.java

Lines changed: 13 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,24 @@
2323
*/
2424
public abstract class AuronConfiguration {
2525

26-
public static final ConfigOption<Integer> BATCH_SIZE = ConfigOptions.key("auron.batchSize")
27-
.description("Suggested batch size for arrow batches.")
28-
.intType()
29-
.defaultValue(10000);
30-
31-
public static final ConfigOption<Double> MEMORY_FRACTION = ConfigOptions.key("auron.memoryFraction")
32-
.description("Suggested fraction of off-heap memory used in native execution. "
26+
public static final ConfigOption<Integer> BATCH_SIZE = new ConfigOption<>(Integer.class)
27+
.withKey("auron.batchSize")
28+
.withDescription("Suggested batch size for arrow batches.")
29+
.withDefaultValue(10000);
30+
31+
public static final ConfigOption<Double> MEMORY_FRACTION = new ConfigOption<>(Double.class)
32+
.withKey("auron.memoryFraction")
33+
.withDescription("Suggested fraction of off-heap memory used in native execution. "
3334
+ "actual off-heap memory usage is expected to be spark.executor.memoryOverhead * fraction.")
34-
.doubleType()
35-
.defaultValue(0.6);
35+
.withDefaultValue(0.6);
3636

37-
public static final ConfigOption<String> NATIVE_LOG_LEVEL = ConfigOptions.key("auron.native.log.level")
38-
.description("Log level for native execution.")
39-
.stringType()
40-
.defaultValue("info");
37+
public static final ConfigOption<String> NATIVE_LOG_LEVEL = new ConfigOption<>(String.class)
38+
.withKey("auron.native.log.level")
39+
.withDescription("Log level for native execution.")
40+
.withDefaultValue("info");
4141

4242
public abstract <T> Optional<T> getOptional(ConfigOption<T> option);
4343

44-
public abstract <T> Optional<T> getOptional(String key);
45-
4644
public <T> T get(ConfigOption<T> option) {
4745
return getOptional(option).orElseGet(() -> getOptionDefaultValue(option));
4846
}
@@ -57,18 +55,6 @@ public String getString(ConfigOption<String> configOption) {
5755
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
5856
}
5957

60-
/**
61-
* Returns the value associated with the given config option as a string. If no value is mapped
62-
* under any key of the option, it returns the specified default instead of the option's default
63-
* value.
64-
*
65-
* @param configOption The configuration option
66-
* @return the (default) value associated with the given config option
67-
*/
68-
public String getString(ConfigOption<String> configOption, String overrideDefault) {
69-
return getOptional(configOption).orElse(overrideDefault);
70-
}
71-
7258
/**
7359
* Returns the value associated with the given config option as an integer.
7460
*
@@ -79,19 +65,6 @@ public int getInteger(ConfigOption<Integer> configOption) {
7965
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
8066
}
8167

82-
/**
83-
* Returns the value associated with the given config option as an integer. If no value is
84-
* mapped under any key of the option, it returns the specified default instead of the option's
85-
* default value.
86-
*
87-
* @param configOption The configuration option
88-
* @param overrideDefault The value to return if no value was mapped for any key of the option
89-
* @return the configured value associated with the given config option, or the overrideDefault
90-
*/
91-
public int getInteger(ConfigOption<Integer> configOption, int overrideDefault) {
92-
return getOptional(configOption).orElse(overrideDefault);
93-
}
94-
9568
/**
9669
* Returns the value associated with the given config option as a long integer.
9770
*
@@ -102,19 +75,6 @@ public long getLong(ConfigOption<Long> configOption) {
10275
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
10376
}
10477

105-
/**
106-
* Returns the value associated with the given config option as a long integer. If no value is
107-
* mapped under any key of the option, it returns the specified default instead of the option's
108-
* default value.
109-
*
110-
* @param configOption The configuration option
111-
* @param overrideDefault The value to return if no value was mapped for any key of the option
112-
* @return the configured value associated with the given config option, or the overrideDefault
113-
*/
114-
public long getLong(ConfigOption<Long> configOption, long overrideDefault) {
115-
return getOptional(configOption).orElse(overrideDefault);
116-
}
117-
11878
/**
11979
* Returns the value associated with the given config option as a boolean.
12080
*
@@ -148,19 +108,6 @@ public float getFloat(ConfigOption<Float> configOption) {
148108
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
149109
}
150110

151-
/**
152-
* Returns the value associated with the given config option as a float. If no value is mapped
153-
* under any key of the option, it returns the specified default instead of the option's default
154-
* value.
155-
*
156-
* @param configOption The configuration option
157-
* @param overrideDefault The value to return if no value was mapped for any key of the option
158-
* @return the configured value associated with the given config option, or the overrideDefault
159-
*/
160-
public float getFloat(ConfigOption<Float> configOption, float overrideDefault) {
161-
return getOptional(configOption).orElse(overrideDefault);
162-
}
163-
164111
/**
165112
* Returns the value associated with the given config option as a {@code double}.
166113
*
@@ -171,19 +118,6 @@ public double getDouble(ConfigOption<Double> configOption) {
171118
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
172119
}
173120

174-
/**
175-
* Returns the value associated with the given config option as a {@code double}. If no value is
176-
* mapped under any key of the option, it returns the specified default instead of the option's
177-
* default value.
178-
*
179-
* @param configOption The configuration option
180-
* @param overrideDefault The value to return if no value was mapped for any key of the option
181-
* @return the configured value associated with the given config option, or the overrideDefault
182-
*/
183-
public double getDouble(ConfigOption<Double> configOption, double overrideDefault) {
184-
return getOptional(configOption).orElse(overrideDefault);
185-
}
186-
187121
/**
188122
* Returns the value associated with the given config option as a {@code double}.
189123
*

auron-core/src/main/java/org/apache/auron/configuration/ConfigOption.java

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*/
1717
package org.apache.auron.configuration;
1818

19-
import static org.apache.auron.util.Preconditions.checkNotNull;
20-
19+
import java.util.ArrayList;
20+
import java.util.List;
2121
import java.util.function.Function;
22+
import org.apache.auron.jni.AuronAdaptor;
2223

2324
/**
2425
* A {@code ConfigOption} describes a configuration parameter. It encapsulates the configuration
@@ -35,16 +36,22 @@ public class ConfigOption<T> {
3536
public static final String EMPTY_DESCRIPTION = "";
3637

3738
/** The current key for that config option. */
38-
private final String key;
39+
private String key;
40+
41+
/** The current key for that config option. */
42+
private List<String> altKeys = new ArrayList<>();
3943

4044
/** The default value for this option. */
41-
private final T defaultValue;
45+
private T defaultValue;
46+
47+
/** The current category for that config option. */
48+
private String category = "Uncategorized";
4249

4350
/** The description for this option. */
44-
private final String description;
51+
private String description;
4552

4653
/** The function to compute the default value. */
47-
private final Function<AuronConfiguration, T> dynamicDefaultValueFunction;
54+
private Function<AuronConfiguration, T> dynamicDefaultValueFunction;
4855

4956
/**
5057
* Type of the value that this ConfigOption describes.
@@ -55,27 +62,40 @@ public class ConfigOption<T> {
5562
* <li>typeClass == atomic class and isList == true for {@code ConfigOption<List<Integer>>}
5663
* </ul>
5764
*/
58-
private final Class<?> clazz;
65+
private Class<T> clazz;
5966

60-
/**
61-
* Creates a new config option with fallback keys.
62-
*
63-
* @param key The current key for that config option
64-
* @param clazz describes type of the ConfigOption, see description of the clazz field
65-
* @param description Description for that option
66-
* @param defaultValue The default value for this option
67-
*/
68-
ConfigOption(
69-
String key,
70-
Class<?> clazz,
71-
T defaultValue,
72-
String description,
73-
Function<AuronConfiguration, T> dynamicDefaultValueFunction) {
74-
this.key = checkNotNull(key);
75-
this.description = description;
67+
public ConfigOption(Class<T> clazz) {
68+
this.clazz = clazz;
69+
}
70+
71+
public ConfigOption<T> withKey(String key) {
72+
this.key = key;
73+
return this;
74+
}
75+
76+
public ConfigOption<T> addAltKey(String altKey) {
77+
this.altKeys.add(altKey);
78+
return this;
79+
}
80+
81+
public ConfigOption<T> withDefaultValue(T defaultValue) {
7682
this.defaultValue = defaultValue;
77-
this.clazz = checkNotNull(clazz);
83+
return this;
84+
}
85+
86+
public ConfigOption<T> withCategory(String category) {
87+
this.category = category;
88+
return this;
89+
}
90+
91+
public ConfigOption<T> withDescription(String description) {
92+
this.description = description;
93+
return this;
94+
}
95+
96+
public ConfigOption<T> withDynamicDefaultValue(Function<AuronConfiguration, T> dynamicDefaultValueFunction) {
7897
this.dynamicDefaultValueFunction = dynamicDefaultValueFunction;
98+
return this;
7999
}
80100

81101
/**
@@ -88,21 +108,24 @@ public String key() {
88108
}
89109

90110
/**
91-
* Gets the description of configuration key
92-
*
93-
* @return
111+
* Gets the alternative configuration keys.
94112
*/
95-
public String description() {
96-
return description;
113+
public List<String> altKeys() {
114+
return altKeys;
97115
}
98116

99117
/**
100-
* Checks if this option has a default value.
101-
*
102-
* @return True if it has a default value, false if not.
118+
* Gets the category of configuration key
103119
*/
104-
public boolean hasDefaultValue() {
105-
return defaultValue != null;
120+
public String category() {
121+
return category;
122+
}
123+
124+
/**
125+
* Gets the description of configuration key
126+
*/
127+
public String description() {
128+
return description;
106129
}
107130

108131
/**
@@ -131,4 +154,22 @@ public boolean hasDynamicDefaultValue() {
131154
public Function<AuronConfiguration, T> dynamicDefaultValueFunction() {
132155
return dynamicDefaultValueFunction;
133156
}
157+
158+
/**
159+
* Gets the type class of the value that this ConfigOption describes.
160+
*
161+
* @return The type class of the value that this ConfigOption describes.
162+
*/
163+
public Class<T> getValueClass() {
164+
return clazz;
165+
}
166+
167+
/**
168+
* Retrieves the current value of this configuration option.
169+
*
170+
* @return the current value associated with this configuration option.
171+
*/
172+
public T get() {
173+
return AuronAdaptor.getInstance().getAuronConfiguration().get(this);
174+
}
134175
}

0 commit comments

Comments
 (0)