[ 
https://issues.apache.org/jira/browse/STORM-1233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15184166#comment-15184166
 ] 

ASF GitHub Bot commented on STORM-1233:
---------------------------------------

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


> port backtype.storm.security.auth.AuthUtils-test to java
> --------------------------------------------------------
>
>                 Key: STORM-1233
>                 URL: https://issues.apache.org/jira/browse/STORM-1233
>             Project: Apache Storm
>          Issue Type: New Feature
>            Reporter: Robert Joseph Evans
>            Assignee: Alessandro Bellina
>              Labels: java-migration, jstorm-merger
>
> Just a test moving to junit



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to