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

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

Github user clockfly commented on a diff in the pull request:

    https://github.com/apache/storm/pull/495#discussion_r27561927
  
    --- Diff: storm-core/src/jvm/backtype/storm/utils/Utils.java ---
    @@ -135,35 +137,68 @@ public static void sleep(long millis) {
         }
     
         public static Map findAndReadConfigFile(String name, boolean 
mustExist) {
    +        InputStream in = null;
    +        Boolean confFileEmpty = false;
             try {
    -            HashSet<URL> resources = new HashSet<URL>(findResources(name));
    -            if(resources.isEmpty()) {
    -                if(mustExist) throw new RuntimeException("Could not find 
config file on classpath " + name);
    -                else return new HashMap();
    -            }
    -            if(resources.size() > 1) {
    -                throw new RuntimeException("Found multiple " + name + " 
resources. You're probably bundling the Storm jars with your topology jar. "
    -                  + resources);
    -            }
    -            URL resource = resources.iterator().next();
    -            Yaml yaml = new Yaml(new SafeConstructor());
    -            Map ret = null;
    -            InputStream input = resource.openStream();
    -            try {
    -                ret = (Map) yaml.load(new InputStreamReader(input));
    -            } finally {
    -                input.close();
    +            in = getConfigFileInputStream(name);
    +            if (null != in) {
    +                Yaml yaml = new Yaml(new SafeConstructor());
    +                Map ret = (Map) yaml.load(new InputStreamReader(in));
    +                if (null != ret) {
    +                    return new HashMap(ret);
    +                } else {
    +                    confFileEmpty = true;
    +                }
                 }
    -            if(ret==null) ret = new HashMap();
    -            
     
    -            return new HashMap(ret);
    -            
    +            if (mustExist) {
    +                if(confFileEmpty)
    +                    throw new RuntimeException("Config file " + name + " 
doesn't have any valid storm configs");
    +                else
    +                    throw new RuntimeException("Could not find config file 
on classpath " + name);
    +            } else {
    +                return new HashMap();
    +            }
             } catch (IOException e) {
                 throw new RuntimeException(e);
    +        } finally {
    +            if (null != in) {
    +                try {
    +                    in.close();
    +                } catch (IOException e) {
    +                    throw new RuntimeException(e);
    +                }
    +            }
             }
         }
     
    +    private static InputStream getConfigFileInputStream(String 
configFilePath)
    +            throws IOException {
    +        if (null == configFilePath) {
    +            throw new IOException(
    +                    "Could not find config file, name not specified");
    +        }
    +
    +        HashSet<URL> resources = new 
HashSet<URL>(findResources(configFilePath));
    +        if (resources.isEmpty()) {
    +            File configFile = new File(configFilePath);
    +            if (configFile.exists()) {
    +                return new FileInputStream(configFile);
    +            }
    --- End diff --
    
    @lazyval 
    
    mustExist flag will control whether we should fail the method.
    ···public static Map findAndReadConfigFile(String name, boolean mustExist) 
···
    
    When we cannot find a resource, we will return null; then we check whether 
mustExist flag is enabled to determine whether we should throw RuntimeException.


> Allow user to specify full configuration path when running storm command
> ------------------------------------------------------------------------
>
>                 Key: STORM-188
>                 URL: https://issues.apache.org/jira/browse/STORM-188
>             Project: Apache Storm
>          Issue Type: Bug
>            Reporter: Sean Zhong
>            Priority: Minor
>         Attachments: search_local_path_for_config.patch, storm-188.patch
>
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> Currently, storm will only look up configuration path in java classpath. We 
> should also allow user to specify full configuration path. This is very 
> important for a shared cluster environment, like YARN. Multiple storm cluster 
> may runs with different configuration, but share same binary folder.



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

Reply via email to