Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,40 @@ public static <T> void injectConfigurationToObject(ConfigurationSource from,

String key = prefix + "." + configAnnotation.key();

String defaultValue = configAnnotation.defaultValue();

ConfigType type = configAnnotation.type();

if (type == ConfigType.AUTO) {
type = detectConfigType(field.getType(), fieldLocation);
}

//Note: default value is handled by ozone-default.xml. Here we can
//use any default.
try {
switch (type) {
case STRING:
forcedFieldSet(field, configuration, from.get(key));
forcedFieldSet(field, configuration, from.get(key, defaultValue));
break;
case INT:
forcedFieldSet(field, configuration, from.getInt(key, 0));
forcedFieldSet(field, configuration,
from.getInt(key, Integer.parseInt(defaultValue)));
break;
case BOOLEAN:
forcedFieldSet(field, configuration, from.getBoolean(key, false));
forcedFieldSet(field, configuration,
from.getBoolean(key, Boolean.parseBoolean(defaultValue)));
break;
case LONG:
forcedFieldSet(field, configuration, from.getLong(key, 0));
forcedFieldSet(field, configuration,
from.getLong(key, Long.parseLong(defaultValue)));
break;
case TIME:
forcedFieldSet(field, configuration,
from.getTimeDuration(key, "0s", configAnnotation.timeUnit()));
from.getTimeDuration(key, defaultValue,
configAnnotation.timeUnit()));
break;
case SIZE:
final long value =
Math.round(from.getStorageSize(key, "0b", StorageUnit.BYTES));
Math.round(from.getStorageSize(key,
defaultValue, StorageUnit.BYTES));
if (field.getType() == int.class) {
forcedFieldSet(field, configuration, (int) value);
} else {
Expand All @@ -106,13 +111,13 @@ public static <T> void injectConfigurationToObject(ConfigurationSource from,
break;
case CLASS:
forcedFieldSet(field, configuration,
from.getClass(key, Object.class));
from.getClass(key, Class.forName(defaultValue)));
break;
default:
throw new ConfigurationException(
"Unsupported ConfigType " + type + " on " + fieldLocation);
}
} catch (IllegalAccessException e) {
} catch (IllegalAccessException | ClassNotFoundException e) {
throw new ConfigurationException(
"Can't inject configuration to " + fieldLocation, e);
}
Expand Down