Github user james-sirota commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/2#discussion_r47837339
  
    --- Diff: 
opensoc-streaming/OpenSOC-Alerts/src/main/java/com/opensoc/alerts/adapters/AllAlertAdapter.java
 ---
    @@ -23,64 +21,96 @@
     import org.apache.hadoop.hbase.client.Scan;
     import org.apache.hadoop.hbase.util.Bytes;
     import org.json.simple.JSONObject;
    -import org.slf4j.Logger;
    -import org.slf4j.LoggerFactory;
    -
    +import org.apache.log4j.Logger;
     import com.google.common.cache.Cache;
     import com.google.common.cache.CacheBuilder;
     import com.opensoc.alerts.interfaces.AlertsAdapter;
     
    +@SuppressWarnings("serial")
     public class AllAlertAdapter implements AlertsAdapter, Serializable {
     
    +   HTableInterface blacklist_table;
        HTableInterface whitelist_table;
        InetAddressValidator ipvalidator = new InetAddressValidator();
        String _whitelist_table_name;
    -   // String _blacklist_table_name;
    +   String _blacklist_table_name;
        String _quorum;
        String _port;
        String _topologyname;
        Configuration conf = null;
     
    -   protected  Cache<String, String> cache;
    -
    -   Map<String, String> id_list = new HashMap<String, String>();
    +   Cache<String, String> cache;
    +   String _topology_name;
     
        Set<String> loaded_whitelist = new HashSet<String>();
        Set<String> loaded_blacklist = new HashSet<String>();
     
    -   String _topology_name;
    -
    -   protected static final Logger LOG = LoggerFactory
    +   protected static final Logger LOG = Logger
                        .getLogger(AllAlertAdapter.class);
     
    -   public AllAlertAdapter(String whitelist_table_name,
    -                   String blacklist_table_name, String quorum, String port,
    -                   int _MAX_TIME_RETAIN, int _MAX_CACHE_SIZE) {
    -
    -           _whitelist_table_name = whitelist_table_name;
    -
    -           _quorum = quorum;
    -           _port = port;
    -
    -           cache = CacheBuilder.newBuilder().maximumSize(_MAX_CACHE_SIZE)
    -                           .expireAfterWrite(_MAX_TIME_RETAIN, 
TimeUnit.MINUTES).build();
    +   public AllAlertAdapter(Map<String, String> config) {
    +           try {
    +                   if(!config.containsKey("whitelist_table_name"))
    +                           throw new Exception("Whitelist table name is 
missing");
    +                           
    +                   _whitelist_table_name = 
config.get("whitelist_table_name");
    +                   
    +                   if(!config.containsKey("blacklist_table_name"))
    +                           throw new Exception("Blacklist table name is 
missing");
    +                   
    +                   _blacklist_table_name = 
config.get("blacklist_table_name");
    +                   
    +                   if(!config.containsKey("quorum"))
    +                           throw new Exception("Quorum name is missing");
    +                   
    +                   _quorum = config.get("quorum");
    +                   
    +                   if(!config.containsKey("port"))
    +                           throw new Exception("port name is missing");
    +                   
    +                   _port = config.get("port");
     
    +                   if(!config.containsKey("_MAX_CACHE_SIZE_OBJECTS_NUM"))
    +                           throw new 
Exception("_MAX_CACHE_SIZE_OBJECTS_NUM name is missing");
    +                   
    +                   int _MAX_CACHE_SIZE_OBJECTS_NUM = 
Integer.parseInt(config
    +                                   .get("_MAX_CACHE_SIZE_OBJECTS_NUM"));
    +                   
    +                   if(!config.containsKey("_MAX_TIME_RETAIN_MINUTES"))
    +                           throw new Exception("_MAX_TIME_RETAIN_MINUTES 
name is missing");
    +                   
    +                   int _MAX_TIME_RETAIN_MINUTES = Integer.parseInt(config
    +                                   .get("_MAX_TIME_RETAIN_MINUTES"));
     
    +                   cache = 
CacheBuilder.newBuilder().maximumSize(_MAX_CACHE_SIZE_OBJECTS_NUM)
    +                                   
.expireAfterWrite(_MAX_TIME_RETAIN_MINUTES, TimeUnit.MINUTES)
    +                                   .build();
    +           } catch (Exception e) {
    +                   System.out.println("Could not initialize Alerts 
Adapter");
    +                   e.printStackTrace();
    +                   System.exit(0);
    --- End diff --
    
    The reason this was done is because this bolt has dependencies on Hbase and 
Zookeeper.  If something went wrong in the initialization the bolt didn't 
explicitly fail, but timed out instead.  So the topology would half start and 
then started blasting packets into a bolt that wasn't fully initialized or had 
an error.  Having it explicitly exit like this failed the whole topology right 
away so you immediately knew you had a problem and didn't have to go looking 
for it in the logs when the topology blew up 5 minutes later 


---
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