[rules-users] Integration of Drools with Hadoop

Roger Smith rogersmith1711 at gmail.com
Sun Oct 31 01:35:32 EDT 2010


We are working on a project to integrate Drools with Apache Hadoop,
http://hadoop.apache.org/, and run into some road blocks. We would very much
appreciate any suggestions/help from this list.

We have an app where we call drools rule engine inside the reducer task of a
Hadoop map reduce job. It throws a NullPointerException when we the rule
package resource to the knowledge builder. The same code works fine when
run as part of a stand alone app.

Code:

    private static Map<String, StatefulKnowledgeSession> sessions =
            new HashMap<String, StatefulKnowledgeSession>();
    private static final String RULE_PACK_DIR = "
file:///home/roger/Projects/gridx/ <file:///\\home\pranab\Projects\gridx\>";
    private static final String RULE_PACK_EXT = ".drl";


    public int process(String rulePackage, String dateTime, String type)
throws TException {
        int rate = 0;
        StatefulKnowledgeSession session = sessions.get(rulePackage);
        if (null == session){
            KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
            String rulePackPath = RULE_PACK_DIR + rulePackage +
RULE_PACK_EXT;
            kbuilder.add( ResourceFactory.newFileResource(rulePackPath ),
ResourceType.DRL);
            if ( kbuilder.hasErrors() ) {
                System.err.println( kbuilder.getErrors().toString() );
            }
            KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

            session = kbase.newStatefulKnowledgeSession();
            sessions.put(rulePackage, session);
        }

        ContractRule contractRule = new ContractRule();
        contractRule.prepare(dateTime, type);;
        FactHandle ruleHandle = session.insert(contractRule);
        session.fireAllRules();
        System.out.println("" + contractRule);
        rate = contractRule.getRate();
        session.retract(ruleHandle);

        return rate;
    }

This line throws the exception:
kbuilder.add( ResourceFactory.newFileResource(rulePackPath ),
ResourceType.DRL);

It works fine as a stand alone app, outside hadoop

Roger Smith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101030/29e80d9a/attachment.html 


More information about the rules-users mailing list