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

    https://github.com/apache/storm/pull/495#discussion_r27584483
  
    --- 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 there are cases where storm wants to use defaults.yaml if there is 
not storm.yaml. If one wants to do a quick test they can just run the storm 
cluster by not having any storm.yaml . Hence the reason we have mustexist as a 
flag to indicate if we want to throw an error or not.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to