Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Dynamic resources #15

Merged
merged 3 commits into from

2 participants

@sotty
Owner

No description provided.

@Salaboy Salaboy merged commit 439f0f3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2012
  1. @sotty

    Dynamic resource addition

    sotty authored
Commits on Jul 31, 2012
  1. @sotty
  2. @sotty

    Fix test

    sotty authored
This page is out of date. Refresh to see the latest.
View
2  drools-mas-acl/pom.xml
@@ -58,7 +58,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
- <version>1.2.2</version>
+ <version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
View
12 drools-mas-core/src/main/java/org/drools/mas/core/DroolsAgentFactory.java
@@ -110,12 +110,12 @@ public DroolsAgent spawn( DroolsAgentConfiguration config ) {
SessionManager sm = SessionManager.create( config, descr, grid, true );
StatefulKnowledgeSession mindSet = sm.getStatefulKnowledgeSession();
- try{
- mindSet.setGlobal( "grid", grid );
- } catch (Exception e){
- //maybe 'grid' is not even defined in subsession
- logger.debug("Global 'grid' not set on session '"+descr.getSessionId()+"' due to "+e.getMessage());
- }
+// try{
+// mindSet.setGlobal( "grid", grid );
+// } catch (Exception e){
+// //maybe 'grid' is not even defined in subsession
+// logger.debug("Global 'grid' not set on session '"+descr.getSessionId()+"' due to "+e.getMessage());
+// }
mindSet.fireAllRules();
View
9 drools-mas-core/src/main/java/org/drools/mas/core/SessionManager.java
@@ -119,6 +119,10 @@ public static SessionManager create( String sessionId, DroolsAgentConfiguration
// should indicate that someone else left an orphan row in the WP
node = grid.claimGridNode( nodeId );
grid.get( SocketService.class ).addService( nodeId, port, node );
+
+ if ( forceRemote && ! node.isRemote() ) {
+ node = grid.asRemoteNode( node );
+ }
}
@@ -127,8 +131,11 @@ public static SessionManager create( String sessionId, DroolsAgentConfiguration
logger.debug( " ### Session Manager: Creating a new Local Node" );
}
node = createLocalNode( grid, nodeId );
-
grid.get( SocketService.class ).addService( nodeId, port, node );
+
+ if ( forceRemote && ! node.isRemote() ) {
+ node = grid.asRemoteNode( node );
+ }
}
} else {
View
20 drools-mas-core/src/main/resources/org/drools/mas/acl_common.drl
@@ -30,6 +30,7 @@ import org.drools.mas.util.LoggerHelper;
import org.drools.mas.util.helper.SessionLocator;
import org.drools.grid.Grid;
+import org.drools.grid.helper.GridHelper;
import org.drools.grid.api.impl.ResourceDescriptorImpl;
import org.drools.grid.api.ResourceDescriptor;
@@ -39,8 +40,8 @@ import org.drools.builder.ResourceType;
global Grid grid;
declare ResourceAdditionRequest
- URL: URL
- type: ResourceType
+ URL : URL
+ type : ResourceType
end
query queryIf( Object $o )
@@ -77,6 +78,16 @@ end
//end
+rule "Init Grid"
+salience 999
+when
+then
+ // need to initialize Grid in remote nodes
+ if ( kcontext.getKnowledgeRuntime().getGlobal( "grid" ) == null ) {
+ kcontext.getKnowledgeRuntime().setGlobal( "grid", GridHelper.createGrid() );
+ }
+end
+
rule "Add Resource"
when
$rar: ResourceAdditionRequest($url: URL, $type: type)
@@ -88,10 +99,7 @@ then
rd.setResourceURL($url);
rd.setType($type);
- //SessionManager.addResource(grid, $nodeId, $sessionId, rd);
-
- SessionManager.addResource(drools.getWorkingMemory(), rd);
+ SessionManager.addResource( grid, $nodeId, $sessionId, rd );
-
retract($rar);
end
View
21 drools-mas-core/src/main/resources/org/drools/mas/acl_internal.drl
@@ -45,12 +45,12 @@ import org.drools.mas.util.helper.SessionLocator;
import org.drools.grid.remote.command.*;
import org.drools.command.*;
-rule "Response content inserted"
- when
- $r: ResponseContent()
- then
- LoggerHelper.debug("CONTENT = "+$r);
-end
+//rule "Response content inserted"
+// when
+// $r: ResponseContent()
+// then
+// LoggerHelper.debug("CONTENT = "+$r);
+//end
rule "Invoke"
when
@@ -65,7 +65,7 @@ then
LoggerHelper.debug(" ### INTERNAL: \t commands " + $cmd);
}
- retract($cmd);
+ retract( $cmd );
StatefulKnowledgeSession kSession = GridHelper.getStatefulKnowledgeSession( grid, $nodeId, $sessionId, true );
if ( LoggerHelper.isDebugEnabled() ) {
@@ -370,4 +370,11 @@ end
+rule "Clean Destinations"
+when
+ $dst : Destination( $id ; )
+ not ACLMessage( id == $id )
+then
+ retract( $dst );
+end
View
10 drools-mas-core/src/test/java/org/drools/mas/core/tests/TestAgent.java
@@ -79,9 +79,9 @@ public void createAgents() {
DroolsAgentConfiguration mainConfig = new DroolsAgentConfiguration();
mainConfig.setAgentId( "Mock Test Agent" );
mainConfig.setChangeset( "mainTestAgent_changeset.xml" );
- DroolsAgentConfiguration.SubSessionDescriptor subDescr1 = new DroolsAgentConfiguration.SubSessionDescriptor( "session1", "sub1.xml", "local-mock-test-agent" );
+ DroolsAgentConfiguration.SubSessionDescriptor subDescr1 = new DroolsAgentConfiguration.SubSessionDescriptor( "session1", "sub1.xml", "mock-test-agent" );
mainConfig.addSubSession( subDescr1 );
- DroolsAgentConfiguration.SubSessionDescriptor subDescr2 = new DroolsAgentConfiguration.SubSessionDescriptor( "session2", "sub2.xml", "local-mock-test-agent" );
+ DroolsAgentConfiguration.SubSessionDescriptor subDescr2 = new DroolsAgentConfiguration.SubSessionDescriptor( "session2", "sub2.xml", "mock-test-agent" );
mainConfig.addSubSession( subDescr2 );
mainConfig.setMindNodeLocation( "local-mock-test-agent" );
mainConfig.setPort( 7000 );
@@ -610,15 +610,15 @@ public void testDynamicResourceAddition() throws Exception{
ACLMessage info = factory.newInformMessage("me", "you", uRLResourceLocator);
mainAgent.tell(info);
- waitForAnswers( info.getId(), 0, 250, 50 );
+ waitForAnswers( info.getId(), 0, 1000, 50 );
for (Object o : target.getObjects()) {
System.err.println("\t Assets AFTER the inform : " + o);
}
//This string comes from newResource.drl
- Assert.assertTrue(target.getObjects().contains("--------@@ It's alive!! @@--------------"));
- Assert.assertNotNull(target.getKnowledgeBase().getRule("org.drools.mas.test", "Test this"));
+ Assert.assertTrue( target.getObjects().contains("--------@@ It's alive!! @@--------------") );
+ Assert.assertNotNull( target.getKnowledgeBase().getRule( "org.drools.mas.test", "Test this") );
View
32 drools-mas-util/src/main/java/org/drools/mas/util/helper/ResponseContent.java
@@ -26,40 +26,48 @@
private static Logger logger = LoggerFactory.getLogger( ResponseContent.class );
- public static void deliverResponse( String $nodeId, String $sessionId, String $msgId, Object $return, Fault $fault ) {
- deliverResponse( $nodeId, $sessionId, $msgId, $return, $fault, false );
+ public static void deliverResponse( String nodeId, String sessionId, String msgId, Object ret, Fault fault ) {
+ deliverResponse( nodeId, sessionId, msgId, ret, fault, false );
}
- public static void deliverResponse( String $nodeId, String $sessionId, String $msgId, Object $return, Fault $fault, boolean needEncoding ) {
+ public static void deliverResponse( Grid grid, String nodeId, String sessionId, String msgId, Object ret, Fault fault ) {
+ deliverResponse( grid, nodeId, sessionId, msgId, ret, fault, false );
+ }
+
+ public static void deliverResponse( String nodeId, String sessionId, String msgId, Object ret, Fault fault, boolean needEncoding ) {
Grid grid = GridHelper.createGrid();
+ deliverResponse( grid, nodeId, sessionId, msgId, ret, fault, needEncoding );
+ }
+
+ public static void deliverResponse( Grid grid, String nodeId, String sessionId, String msgId, Object ret, Fault fault, boolean needEncoding ) {
try {
if ( logger.isDebugEnabled() ) {
logger.debug( "(" + Thread.currentThread().getId() + ")"+Thread.currentThread().getName() + "Content helper is now active" );
}
Map results = null;
- if ( $return != null ) {
+ if ( ret != null ) {
results = new HashMap();
- if ( $return instanceof String ) {
- results.put( "?return", $return );
+ if ( ret instanceof String ) {
+ results.put( "?return", ret );
} else {
if ( needEncoding ) {
- $return = MessageContentEncoder.encode( $return, Encodings.XML );
+ ret = MessageContentEncoder.encode( ret, Encodings.XML );
}
- results.put( "?return", $return );
+ results.put( "?return", ret );
}
if ( logger.isDebugEnabled() ) {
logger.debug("(" + Thread.currentThread().getId() + ")" + Thread.currentThread().getName() + "Content helper would like to return" + results.get("?return"));
}
}
- ResponseContent response = new ResponseContent( $nodeId, $sessionId, $msgId, results );
- response.setFault( $fault );
+ ResponseContent response = new ResponseContent( nodeId, sessionId, msgId, results );
+ response.setFault( fault );
if ( logger.isDebugEnabled() ) {
- logger.debug( "(" + Thread.currentThread().getId() + ")" + Thread.currentThread().getName() + "Content helper fault is expected to be null " + $fault );
+ logger.debug( "(" + Thread.currentThread().getId() + ")" + Thread.currentThread().getName() + "Content helper fault is expected to be null " + fault );
}
- StatefulKnowledgeSession kSession = GridHelper.getStatefulKnowledgeSession( grid, $nodeId, $sessionId, true );
+ StatefulKnowledgeSession kSession = GridHelper.getStatefulKnowledgeSession( grid, nodeId, sessionId, true );
if ( logger.isDebugEnabled() ) {
logger.debug( "(" + Thread.currentThread().getId() + ")"+Thread.currentThread().getName() +"Content helper ksession found!" );
View
2  examples/drools-mas-emergency-agent/src/main/resources/META-INF/applicationContext.xml
@@ -21,7 +21,7 @@ http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="async-agent-service" class="org.drools.mas.AsyncDroolsAgentServiceImpl" destroy-method="dispose">
<property name="agent" ref="agent"/>
</bean>
- <bean id="agent-service" class="org.drools.mas.SynchronousDroolsAgentServiceImpl" destroy-method="dispose">
+ <bean id="agent-service" class="org.drools.mas.SynchronousDroolsAgentServiceImpl" >
<property name="agent" ref="agent"/>
</bean>
Something went wrong with that request. Please try again.