Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1191#discussion_r55303331
--- Diff: storm-core/src/jvm/org/apache/storm/security/auth/AuthUtils.java
---
@@ -81,35 +80,88 @@ public static Configuration GetConfiguration(Map
storm_conf) {
}
/**
- * Pull a set of keys out of a Configuration.
- * @param conf The config to pull the key/value pairs out of.
- * @param conf_entry The app configuration entry name to get stuff
from.
- * @return Return a map of the configs in conf.
+ * Get configurations for a section
+ * @param configuration The config to pull the key/value pairs out of.
+ * @param section The app configuration entry name to get stuff from.
+ * @return Return array of config entries or null if configuration is
null
*/
- public static SortedMap<String, ?> PullConfig(Configuration conf,
- String conf_entry) throws
IOException {
- if(conf == null) {
+ public static AppConfigurationEntry[] getEntries(Configuration
configuration,
+ String section) throws
IOException {
+ if (configuration == null) {
return null;
}
- AppConfigurationEntry configurationEntries[] =
conf.getAppConfigurationEntry(conf_entry);
- if(configurationEntries == null) {
- String errorMessage = "Could not find a '" + conf_entry
- + "' entry in this configuration: Client cannot start.";
+
+ AppConfigurationEntry configurationEntries[] =
configuration.getAppConfigurationEntry(section);
+ if (configurationEntries == null) {
+ String errorMessage = "Could not find a '"+ section + "' entry
in this configuration.";
throw new IOException(errorMessage);
}
+ return configurationEntries;
+ }
+ /**
+ * Pull a set of keys out of a Configuration.
+ * @param configuration The config to pull the key/value pairs out of.
+ * @param section The app configuration entry name to get stuff from.
+ * @return Return a map of the configs in conf.
+ */
+ public static SortedMap<String, ?> pullConfig(Configuration
configuration,
+ String section) throws
IOException {
+ AppConfigurationEntry[] configurationEntries =
AuthUtils.getEntries(configuration, section);
+
+ if (configurationEntries == null) {
+ return null;
+ }
+
TreeMap<String, Object> results = new TreeMap<>();
- for(AppConfigurationEntry entry: configurationEntries) {
+ for (AppConfigurationEntry entry: configurationEntries) {
Map<String, ?> options = entry.getOptions();
- for(String key : options.keySet()) {
+ for (String key : options.keySet()) {
results.put(key, options.get(key));
}
}
+
return results;
}
/**
+ * Pull a the value given section and key from Configuration
+ * @param configuration The config to pull the key/value pairs out of.
+ * @param section The app configuration entry name to get stuff from.
+ * @param key The key to look up inside of the section
+ * @return Return a the String value of the configuration value
+ */
+ public static String get(Configuration configuration, String section,
String key) throws IOException {
+ AppConfigurationEntry[] configurationEntries =
AuthUtils.getEntries(configuration, section);
+
+ if (configurationEntries == null){
+ return null;
+ }
+
+ for (AppConfigurationEntry entry: configurationEntries) {
+ Object val = entry.getOptions().get(key);
+ if (val != null)
+ return (String)val;
+ }
+ return null;
+ }
+
+ /**
+ * Instantiate class with klassName and return instance
+ * @param klassName The class name
+ * @return Instance of type T
+ */
+ private static <T> T makeClass(String klassName) {
+ try {
+ Class klass = Class.forName(klassName);
+ return (T)klass.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
--- End diff --
I think it's better to replace this method by Utils.newInstance
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---