This is an automated email from the ASF dual-hosted git repository. adoroszlai pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git
The following commit(s) were added to refs/heads/master by this push: new 9baaf64 HDDS-4158. Provide a class type for Java based configuration (#1407) 9baaf64 is described below commit 9baaf643bdb74bd8f2f76180436ba365faa4fa0f Author: maobaolong <baoloong...@tencent.com> AuthorDate: Mon Oct 19 23:33:44 2020 +0800 HDDS-4158. Provide a class type for Java based configuration (#1407) --- .../org/apache/hadoop/hdds/conf/SimpleConfiguration.java | 13 +++++++++++++ .../org/apache/hadoop/hdds/conf/TestOzoneConfiguration.java | 7 ++++++- .../main/java/org/apache/hadoop/hdds/conf/ConfigType.java | 3 ++- .../hadoop/hdds/conf/ConfigurationReflectionUtil.java | 12 ++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/SimpleConfiguration.java b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/SimpleConfiguration.java index 9a8702f..3288e56 100644 --- a/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/SimpleConfiguration.java +++ b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/SimpleConfiguration.java @@ -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) { @@ -93,4 +98,12 @@ public class SimpleConfiguration extends SimpleConfigurationParent { public long getWaitTime() { return waitTime; } + + public Class<?> getMyClass() { + return myClass; + } + + public void setMyClass(Class<?> aClass) { + this.myClass = aClass; + } } diff --git a/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/TestOzoneConfiguration.java b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/TestOzoneConfiguration.java index 47c73df..9263b5c 100644 --- a/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/TestOzoneConfiguration.java +++ b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/conf/TestOzoneConfiguration.java @@ -106,6 +106,7 @@ public class TestOzoneConfiguration { 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); @@ -115,6 +116,7 @@ public class TestOzoneConfiguration { Assert.assertTrue(configuration.isEnabled()); Assert.assertEquals(5555, configuration.getPort()); Assert.assertEquals(600, configuration.getWaitTime()); + Assert.assertEquals(Integer.class, configuration.getMyClass()); } @Test @@ -126,6 +128,7 @@ public class TestOzoneConfiguration { Assert.assertTrue(configuration.isEnabled()); Assert.assertEquals(9878, configuration.getPort()); + Assert.assertEquals(Object.class, configuration.getMyClass()); } @Test @@ -137,6 +140,7 @@ public class TestOzoneConfiguration { object.setEnabled(true); object.setPort(5555); object.setWaitTime(600); + object.setMyClass(this.getClass()); OzoneConfiguration subject = new OzoneConfiguration(); @@ -154,6 +158,8 @@ public class TestOzoneConfiguration { 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 @@ -208,7 +214,6 @@ public class TestOzoneConfiguration { ozoneConfiguration.getObject(SimpleConfiguration.class); } - private void appendProperty(BufferedWriter out, String name, String val) throws IOException { this.appendProperty(out, name, val, false); diff --git a/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigType.java b/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigType.java index 23a8104..fd3e958 100644 --- a/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigType.java +++ b/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigType.java @@ -30,5 +30,6 @@ public enum ConfigType { INT, LONG, TIME, - SIZE + SIZE, + CLASS } diff --git a/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java b/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java index 0cd4260..653300e 100644 --- a/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java +++ b/hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java @@ -94,6 +94,10 @@ public final class ConfigurationReflectionUtil { 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); @@ -135,6 +139,8 @@ public final class ConfigurationReflectionUtil { } 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 " @@ -227,6 +233,12 @@ public final class ConfigurationReflectionUtil { 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); --------------------------------------------------------------------- To unsubscribe, e-mail: ozone-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: ozone-commits-h...@hadoop.apache.org