<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 31/10/2010 05:35, Roger Smith wrote:
<blockquote
cite="mid:AANLkTinvbBFzGruVRV6-FLzvOgsweZnRqLWCjBj=+8Kr@mail.gmail.com"
type="cite">
<div><br>
</div>
We are working on a project to integrate Drools with Apache
Hadoop, <a moz-do-not-send="true"
href="http://hadoop.apache.org/">http://hadoop.apache.org/</a>,
and run into some road blocks. We would very much appreciate any
suggestions/help from this list.
<div>
<br>
</div>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><span style="">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. <br>
<br>
Code:<br>
<br>
private static Map<String,
StatefulKnowledgeSession>
sessions =<br>
new
HashMap<String, StatefulKnowledgeSession>();<br>
private static final String RULE_PACK_DIR = "<a
moz-do-not-send="true"
href="file:///%5C%5Chome%5Cpranab%5CProjects%5Cgridx%5C">file:///home/roger/Projects/gridx/</a>";<br>
private static final String RULE_PACK_EXT =
".drl";<br>
<br>
<br>
public int process(String rulePackage, String dateTime,
String type) throws TException {<br>
int rate = 0;<br>
StatefulKnowledgeSession session =
sessions.get(rulePackage);<br>
if (null == session){<br>
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
String
rulePackPath = RULE_PACK_DIR + rulePackage + RULE_PACK_EXT;<br>
kbuilder.add( ResourceFactory.newFileResource(rulePackPath
),
ResourceType.DRL);<br>
if (
kbuilder.hasErrors() ) {<br>
System.err.println( kbuilder.getErrors().toString() );<br>
}<br>
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();<br>
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
<br>
session =
kbase.newStatefulKnowledgeSession();<br>
sessions.put(rulePackage,
session);<br>
}<br>
<br>
ContractRule contractRule = new
ContractRule();<br>
contractRule.prepare(dateTime,
type);;<br>
FactHandle ruleHandle =
session.insert(contractRule);<br>
session.fireAllRules();<br>
System.out.println("" +
contractRule);<br>
rate = contractRule.getRate();<br>
session.retract(ruleHandle);<br>
<br>
return rate;<br>
}</span></p>
<p class="MsoNormal" style="margin-bottom: 12pt;"><span style=""><span
style="font-size: 12pt; font-family: 'Times New
Roman',serif;">This line throws the exception:<br>
kbuilder.add( ResourceFactory.newFileResource(rulePackPath
), ResourceType.DRL);<br>
</span></span></p>
</div>
</blockquote>
<span style=""><span style="font-size: 12pt; font-family: 'Times New
Roman',serif;">ResourceFactory.newFileResource just creates a
file object but cleaning up the paths.<br>
public FileSystemResource(File file) {<br>
if ( file == null ) {<br>
throw new IllegalArgumentException( "File must not
be null" );<br>
}<br>
this.file = new File(
StringUtils.cleanPath(file.getPath()) );<br>
}<br>
The code is borrowed from Spring and uses the sme cleanPath
logic. Once the file is created it just creates the stream as
so:<br>
public InputStream getInputStream() throws IOException {<br>
this.lastRead = getLastModified();<br>
return new FileInputStream(this.file);<br>
}<br>
<br>
So it's pretty basic, the stack trace with line numbers may
help. But I suspect you'll need to do a debug and step into the
drools code at the point where you get the nullpointer and see
what's going on.<br>
<br>
Mark<br>
<br>
</span></span>
<blockquote
cite="mid:AANLkTinvbBFzGruVRV6-FLzvOgsweZnRqLWCjBj=+8Kr@mail.gmail.com"
type="cite">
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><span style=""><span
style="font-size: 12pt; font-family: 'Times New
Roman',serif;">
<br>
It works fine as a stand alone app, outside hadoop<br>
<br>
Roger Smith<br>
</span></span></p>
<div><span style=""><span style="font-size: 12pt; font-family:
'Times New Roman',serif;"><br>
</span></span></div>
<span style="font-size: 12pt; font-family: "Times New
Roman","serif";"><br>
</span>
<div><br>
</div>
<div> </div>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</body>
</html>