Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull out conf loading to a util function #39

Merged
merged 1 commit into from
Dec 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@

package com.digitalpebble.storm.crawler;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.yaml.snakeyaml.Yaml;

import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.StormSubmitter;
import backtype.storm.topology.TopologyBuilder;

import com.digitalpebble.storm.crawler.util.ConfUtils;

public abstract class ConfigurableTopology {

public static void start(ConfigurableTopology topology, String args[]) {
Expand Down Expand Up @@ -84,27 +79,15 @@ private String[] parse(String args[]) {
}
iter.remove();
String resource = iter.next();
Yaml yaml = new Yaml();
Map ret = null;
try {
ret = (Map) yaml.load(new InputStreamReader(
new FileInputStream(resource)));
} catch (FileNotFoundException e) {
System.err
.println("Conf file does not exist : " + resource);
System.exit(-1);
}
if (ret == null)
ret = new HashMap();
conf.putAll(ret);
conf = ConfUtils.loadConf(resource);
iter.remove();
} else if (param.equals("-local")) {
isLocal = true;
iter.remove();
}
}

return (String[]) newArgs.toArray(new String[newArgs.size()]);
return newArgs.toArray(new String[newArgs.size()]);
}

}
23 changes: 23 additions & 0 deletions src/main/java/com/digitalpebble/storm/crawler/util/ConfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@

package com.digitalpebble.storm.crawler.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import backtype.storm.Config;
import backtype.storm.utils.Utils;

import org.yaml.snakeyaml.Yaml;

/** TODO replace by calls to backtype.storm.utils.Utils **/

public class ConfUtils {
Expand Down Expand Up @@ -59,4 +66,20 @@ public static String getString(Map<String, Object> conf, String key,
return (String) Utils.get(conf, key, defaultValue);
}

public static Config loadConf(String resource) {
Config conf = new Config();
Yaml yaml = new Yaml();
Map ret = null;
try {
ret = (Map) yaml.load(new InputStreamReader(new FileInputStream(resource)));
} catch (FileNotFoundException e) {
System.err.println("Conf file does not exist : " + resource);
System.exit(-1);
}
if (ret == null) {
ret = new HashMap();
}
conf.putAll(ret);
return conf;
}
}