Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -47,6 +47,11 @@ public class SimpleConfiguration extends SimpleConfigurationParent {
+ "test TIME config type)", tags = ConfigTag.MANAGEMENT)
private long waitTime;

@Config(key = "class", type = ConfigType.CLASS,
defaultValue = "java.lang.Object", description = "",
tags = ConfigTag.OZONE)
private Class<?> myClass = Object.class;

@PostConstruct
public void validate() {
if (port < 0) {
Expand Down Expand Up @@ -93,4 +98,12 @@ public int getPort() {
public long getWaitTime() {
return waitTime;
}

public Class<? extends Object> getMyClass() {
return myClass;
}

public void setMyClass(Class<?> aClass) {
this.myClass = aClass;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void getConfigurationObject() {
ozoneConfig.setBoolean("test.scm.client.enabled", true);
ozoneConfig.setInt("test.scm.client.port", 5555);
ozoneConfig.setTimeDuration("test.scm.client.wait", 10, TimeUnit.MINUTES);
ozoneConfig.set("test.scm.client.class", Integer.class.getName());

SimpleConfiguration configuration =
ozoneConfig.getObject(SimpleConfiguration.class);
Expand All @@ -115,6 +116,7 @@ public void getConfigurationObject() {
Assert.assertTrue(configuration.isEnabled());
Assert.assertEquals(5555, configuration.getPort());
Assert.assertEquals(600, configuration.getWaitTime());
Assert.assertEquals(Integer.class, configuration.getMyClass());
}

@Test
Expand All @@ -126,6 +128,7 @@ public void getConfigurationObjectWithDefault() {

Assert.assertTrue(configuration.isEnabled());
Assert.assertEquals(9878, configuration.getPort());
Assert.assertEquals(Object.class, configuration.getMyClass());
}

@Test
Expand All @@ -137,6 +140,7 @@ public void setConfigFromObject() {
object.setEnabled(true);
object.setPort(5555);
object.setWaitTime(600);
object.setMyClass(this.getClass());

OzoneConfiguration subject = new OzoneConfiguration();

Expand All @@ -154,6 +158,8 @@ public void setConfigFromObject() {
subject.getInt("test.scm.client.port", 0));
Assert.assertEquals(TimeUnit.SECONDS.toMinutes(object.getWaitTime()),
subject.getTimeDuration("test.scm.client.wait", 0, TimeUnit.MINUTES));
Assert.assertEquals(this.getClass(),
subject.getClass("test.scm.client.class", null));
}

@Test
Expand Down Expand Up @@ -208,7 +214,6 @@ public void postConstructValidation() {
ozoneConfiguration.getObject(SimpleConfiguration.class);
}


private void appendProperty(BufferedWriter out, String name, String val)
throws IOException {
this.appendProperty(out, name, val, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ public enum ConfigType {
INT,
LONG,
TIME,
SIZE
SIZE,
CLASS
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public static <T> void injectConfigurationToObject(ConfigurationSource from,
forcedFieldSet(field, configuration,
from.getTimeDuration(key, "0s", configAnnotation.timeUnit()));
break;
case CLASS:
forcedFieldSet(field, configuration,
from.getClass(key, Object.class));
break;
default:
throw new ConfigurationException(
"Unsupported ConfigType " + type + " on " + fieldLocation);
Expand Down Expand Up @@ -133,6 +137,8 @@ private static ConfigType detectConfigType(Class<?> parameterType,
} else if (parameterType == Boolean.class
|| parameterType == boolean.class) {
type = ConfigType.BOOLEAN;
} else if (parameterType == Class.class) {
type = ConfigType.CLASS;
} else {
throw new ConfigurationException(
"Unsupported configuration type " + parameterType + " in "
Expand Down Expand Up @@ -225,6 +231,12 @@ private static <T> void updateConfigurationFromObject(
config.setTimeDuration(key, field.getLong(configObject),
configAnnotation.timeUnit());
break;
case CLASS:
Object valueClass = field.get(configObject);
if (valueClass instanceof Class<?>) {
config.set(key, ((Class<?>) valueClass).getName());
}
break;
default:
throw new ConfigurationException(
"Unsupported ConfigType " + type + " on " + fieldLocation);
Expand Down