diff --git a/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EPContext.java b/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EPContext.java index 297dcdd2..44da8efc 100644 --- a/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EPContext.java +++ b/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EPContext.java @@ -62,4 +62,12 @@ public interface EPContext { */ public Service getService(String name); + /** + * This method returns the named parameter if available. + * + * @param name The parameter name + * @return The parameter value, or null if not found + */ + public Object getParameter(String name); + } diff --git a/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EventProcessor.java b/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EventProcessor.java index 13b67964..2891a6f0 100644 --- a/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EventProcessor.java +++ b/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/ep/EventProcessor.java @@ -31,7 +31,9 @@ public abstract class EventProcessor { private java.util.Map _services= new java.util.HashMap(); private boolean _async=false; - + private java.util.Map _parameters= + new java.util.HashMap(); + private ResultHandler _handler=null; /** @@ -52,6 +54,24 @@ public void setServices(java.util.Map services) { _services = services; } + /** + * This method returns the map of names to parameters. + * + * @return The parameters + */ + public java.util.Map getParameters() { + return (_parameters); + } + + /** + * This method sets the map of names to parameters. + * + * @param parameters The parameters + */ + public void setParameters(java.util.Map parameters) { + _parameters = parameters; + } + /** * This method indicates whether an asynchronous results listener will be required * for this event processor. diff --git a/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/internal/ep/DefaultEPContext.java b/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/internal/ep/DefaultEPContext.java index e5a217ae..2e2d705e 100644 --- a/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/internal/ep/DefaultEPContext.java +++ b/modules/event-processor/ep-core/src/main/java/org/overlord/rtgov/internal/ep/DefaultEPContext.java @@ -36,6 +36,7 @@ public class DefaultEPContext implements EPContext { private static final ThreadLocal RESULT=new ThreadLocal(); private java.util.Map _services=null; + private java.util.Map _parameters=null; private ResultHandler _handler=null; /** @@ -53,6 +54,17 @@ public DefaultEPContext(java.util.Map services) { _services = services; } + /** + * This constructor initializes the service map. + * + * @param services The map of services available + * @param parameters The map of parameters avaiable + */ + public DefaultEPContext(java.util.Map services, java.util.Map parameters) { + _services = services; + _parameters = parameters; + } + /** * This method sets the result handler. * @@ -144,4 +156,17 @@ public Service getService(String name) { return (ret); } + + /** + * {@inheritDoc} + */ + public Object getParameter(String name) { + Object ret=null; + + if (_parameters != null) { + ret = _parameters.get(name); + } + + return (ret); + } } diff --git a/modules/event-processor/ep-core/src/test/java/org/overlord/rtgov/ep/EventProcessorTest.java b/modules/event-processor/ep-core/src/test/java/org/overlord/rtgov/ep/EventProcessorTest.java new file mode 100644 index 00000000..70d2bccf --- /dev/null +++ b/modules/event-processor/ep-core/src/test/java/org/overlord/rtgov/ep/EventProcessorTest.java @@ -0,0 +1,125 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2008-13, Red Hat Middleware LLC, and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.overlord.rtgov.ep; + +import static org.junit.Assert.*; + +import java.io.Serializable; + +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Test; + +public class EventProcessorTest { + + @Test + public void testEventProcessorSerialization() { + ObjectMapper mapper=new ObjectMapper(); + + TestEventProcessor ep=new TestEventProcessor(); + ep.getParameters().put("testparam1", "hello"); + ep.getParameters().put("testparam2", 5); + + try { + String result=mapper.writeValueAsString(ep); + + TestEventProcessor epresult=mapper.readValue(result, TestEventProcessor.class); + + if (epresult == null) { + fail("Result is null"); + } + + if (!epresult.getParameters().get("testparam1").equals("hello")) { + fail("Test param 1 is incorrect: "+epresult.getParameters().get("testparam1")); + } + + int val=(Integer)epresult.getParameters().get("testparam2"); + + if (val != 5) { + fail("Test param 2 is not 5: "+val); + } + + } catch (Exception e) { + fail("Failed to serialize ep: "+e); + } + } + + @Test + public void testEventProcessorSerializationUnknownType() { + ObjectMapper mapper=new ObjectMapper(); + + TestEventProcessor ep=new TestEventProcessor(); + ep.getParameters().put("testparam1", "hello"); + ep.getParameters().put("testparam2", new TestObject()); + + try { + String result=mapper.writeValueAsString(ep); + + TestEventProcessor epresult=mapper.readValue(result, TestEventProcessor.class); + + if (epresult == null) { + fail("Result 1 is null"); + } + + if (!epresult.getParameters().get("testparam1").equals("hello")) { + fail("Test param 1 is incorrect: "+epresult.getParameters().get("testparam1")); + } + + Object obj=epresult.getParameters().get("testparam2"); + + if (obj == null) { + fail("Result 2 is null"); + } + + @SuppressWarnings("unchecked") + java.util.Map map=(java.util.Map)obj; + + String val2=(String)map.get("val"); + + if (!val2.equals("TestValue")) { + fail("Incorrect value: "+val2); + } + + } catch (Exception e) { + fail("Failed to serialize ep: "+e); + } + } + + public static class TestEventProcessor extends EventProcessor { + + @Override + public Serializable process(String source, Serializable event, + int retriesLeft) throws Exception { + // TODO Auto-generated method stub + return null; + } + + } + + public static class TestObject { + + private String _val="TestValue"; + + public String getVal() { + return (_val); + } + + public void setVal(String val) { + _val = val; + } + } +} diff --git a/modules/event-processor/ep-drools/src/main/java/org/overlord/rtgov/ep/drools/DroolsEventProcessor.java b/modules/event-processor/ep-drools/src/main/java/org/overlord/rtgov/ep/drools/DroolsEventProcessor.java index f2c92061..d5629f96 100644 --- a/modules/event-processor/ep-drools/src/main/java/org/overlord/rtgov/ep/drools/DroolsEventProcessor.java +++ b/modules/event-processor/ep-drools/src/main/java/org/overlord/rtgov/ep/drools/DroolsEventProcessor.java @@ -85,7 +85,7 @@ public void init() throws Exception { +"' must NOT be configured as 'asynchronous' when using 'cloud' eventProcessingMode"); } - _context = new DefaultEPContext(getServices()); + _context = new DefaultEPContext(getServices(), getParameters()); _session = createSession(); diff --git a/modules/event-processor/ep-drools/src/test/java/org/overlord/rtgov/ep/drools/DroolsEventProcessorTest.java b/modules/event-processor/ep-drools/src/test/java/org/overlord/rtgov/ep/drools/DroolsEventProcessorTest.java index 310f24d5..02e35cf1 100644 --- a/modules/event-processor/ep-drools/src/test/java/org/overlord/rtgov/ep/drools/DroolsEventProcessorTest.java +++ b/modules/event-processor/ep-drools/src/test/java/org/overlord/rtgov/ep/drools/DroolsEventProcessorTest.java @@ -386,6 +386,35 @@ public void testCloudEventProcessingModeAsync() { } } + @Test + public void testAccessParameter() { + DroolsEventProcessor ep=new DroolsEventProcessor(); + ep.setRuleName("AccessParameter"); + ep.getParameters().put("param", "testParamValue"); + + try { + ep.init(); + + RequestReceived me1=new RequestReceived(); + me1.setTimestamp(System.currentTimeMillis()); + me1.getProperties().put("customer", "Ivan"); + me1.setMessageId("me1"); + + Object result1=ep.process("Event", me1, 0); + + if (result1 == null) { + fail("Result 1 is null"); + } + + if (!result1.equals("testParamValue")) { + fail("Paramater value incorrect: "+result1); + } + } catch(Exception e) { + e.printStackTrace(); + fail("Exception: "+e); + } + } + public class TestResultHandler implements ResultHandler { private java.util.List _results=new java.util.ArrayList(); diff --git a/modules/event-processor/ep-drools/src/test/resources/AccessParameter.drl b/modules/event-processor/ep-drools/src/test/resources/AccessParameter.drl new file mode 100644 index 00000000..f7b62135 --- /dev/null +++ b/modules/event-processor/ep-drools/src/test/resources/AccessParameter.drl @@ -0,0 +1,15 @@ +import org.overlord.rtgov.activity.model.soa.RequestReceived + +global org.overlord.rtgov.ep.EPContext epc + +declare RequestReceived + @role( event ) + @expires( 20s ) +end + +rule "Access parameter rule" +when + $r: RequestReceived() from entry-point "Event" +then + epc.handle(epc.getParameter("param")); +end \ No newline at end of file diff --git a/modules/event-processor/ep-keyvaluestore/src/main/java/org/overlord/rtgov/ep/keyvaluestore/KeyValueStoreEventProcessor.java b/modules/event-processor/ep-keyvaluestore/src/main/java/org/overlord/rtgov/ep/keyvaluestore/KeyValueStoreEventProcessor.java index 07c92cb8..9487c20b 100644 --- a/modules/event-processor/ep-keyvaluestore/src/main/java/org/overlord/rtgov/ep/keyvaluestore/KeyValueStoreEventProcessor.java +++ b/modules/event-processor/ep-keyvaluestore/src/main/java/org/overlord/rtgov/ep/keyvaluestore/KeyValueStoreEventProcessor.java @@ -90,7 +90,7 @@ public void init() throws Exception { _idScriptExpression = null; } - _context = new DefaultEPContext(getServices()); + _context = new DefaultEPContext(getServices(), getParameters()); /** * expect type SimpleDocumentRepo; diff --git a/modules/event-processor/ep-mvel/src/main/java/org/overlord/rtgov/ep/mvel/MVELEventProcessor.java b/modules/event-processor/ep-mvel/src/main/java/org/overlord/rtgov/ep/mvel/MVELEventProcessor.java index fe69fc4d..fbcee730 100644 --- a/modules/event-processor/ep-mvel/src/main/java/org/overlord/rtgov/ep/mvel/MVELEventProcessor.java +++ b/modules/event-processor/ep-mvel/src/main/java/org/overlord/rtgov/ep/mvel/MVELEventProcessor.java @@ -61,7 +61,7 @@ public void init() throws Exception { } } - _context = new DefaultEPContext(getServices()); + _context = new DefaultEPContext(getServices(), getParameters()); } /** diff --git a/samples/jbossas/ordermgmt/epn/pom.xml b/samples/jbossas/ordermgmt/epn/pom.xml index 51a46560..43460404 100644 --- a/samples/jbossas/ordermgmt/epn/pom.xml +++ b/samples/jbossas/ordermgmt/epn/pom.xml @@ -47,6 +47,12 @@ ordermgmt-epn + + + src/main/resources + true + + maven-war-plugin diff --git a/samples/jbossas/ordermgmt/epn/src/main/resources/epn.json b/samples/jbossas/ordermgmt/epn/src/main/resources/epn.json index 251557da..85baf281 100644 --- a/samples/jbossas/ordermgmt/epn/src/main/resources/epn.json +++ b/samples/jbossas/ordermgmt/epn/src/main/resources/epn.json @@ -1,5 +1,6 @@ { "name" : "OrderManagementEPN", + "version" : "${project.version}", "subscriptions" : [ { "nodeName" : "CheckForException", "subject" : "ActivityUnits" @@ -23,6 +24,5 @@ "subject" : "Situations" } ] } - ], - "version" : "1" + ] } diff --git a/samples/jbossas/ordermgmt/ip/pom.xml b/samples/jbossas/ordermgmt/ip/pom.xml index 64a59d66..ef5c6379 100644 --- a/samples/jbossas/ordermgmt/ip/pom.xml +++ b/samples/jbossas/ordermgmt/ip/pom.xml @@ -37,6 +37,12 @@ ordermgmt-ip + + + src/main/resources + true + + maven-war-plugin diff --git a/samples/jbossas/ordermgmt/ip/src/main/resources/ip.json b/samples/jbossas/ordermgmt/ip/src/main/resources/ip.json index b45d658b..774538ef 100644 --- a/samples/jbossas/ordermgmt/ip/src/main/resources/ip.json +++ b/samples/jbossas/ordermgmt/ip/src/main/resources/ip.json @@ -1,6 +1,6 @@ [{ "name":"OrderManagementIP", - "version":"1", + "version":"${project.version}", "typeProcessors":{ "{urn:switchyard-quickstart-demo:orders:1.0}submitOrder":{ "contexts":[{ diff --git a/samples/jbossas/policy/async/pom.xml b/samples/jbossas/policy/async/pom.xml index f660be94..d6f41d6b 100644 --- a/samples/jbossas/policy/async/pom.xml +++ b/samples/jbossas/policy/async/pom.xml @@ -116,6 +116,12 @@ policy-async + + + src/main/resources + true + + maven-war-plugin diff --git a/samples/jbossas/policy/async/src/main/resources/AssessCredit.mvel b/samples/jbossas/policy/async/src/main/resources/AssessCredit.mvel index a526570d..c8b3bd37 100644 --- a/samples/jbossas/policy/async/src/main/resources/AssessCredit.mvel +++ b/samples/jbossas/policy/async/src/main/resources/AssessCredit.mvel @@ -6,6 +6,8 @@ if (customer == null) { cm = epc.getService("CacheManager"); +creditLimit = epc.getParameter("creditLimit"); + // Attempt to lock the entry if (!cm.lock("Principals", customer)) { epc.handle(new Exception("Unable to lock entry for principal '"+customer+"'")); @@ -34,7 +36,7 @@ if (event.operation == "submitOrder") { int newtotal=current+total; - if (newtotal > 150 && current <= 150) { + if (newtotal > creditLimit && current <= creditLimit) { principal.put("suspended", Boolean.TRUE); } @@ -46,7 +48,7 @@ if (event.operation == "submitOrder") { int newamount=current-amount; - if (newamount <= 150 && current > 150) { + if (newamount <= creditLimit && current > creditLimit) { principal.put("suspended", Boolean.FALSE); } diff --git a/samples/jbossas/policy/async/src/main/resources/epn.json b/samples/jbossas/policy/async/src/main/resources/epn.json index 150aaa28..fd738cd1 100644 --- a/samples/jbossas/policy/async/src/main/resources/epn.json +++ b/samples/jbossas/policy/async/src/main/resources/epn.json @@ -1,6 +1,6 @@ { "name" : "AssessCreditPolicyEPN", - "version" : "1", + "version" : "${project.version}", "subscriptions" : [ { "nodeName" : "AssessCredit", "subject" : "SOAEvents" @@ -23,6 +23,9 @@ "CacheManager" : { "@class" : "org.overlord.rtgov.common.infinispan.service.InfinispanCacheManager" } + }, + "parameters" : { + "creditLimit" : 150 } } } diff --git a/samples/jbossas/policy/sync/pom.xml b/samples/jbossas/policy/sync/pom.xml index e2ebeefa..a5776292 100644 --- a/samples/jbossas/policy/sync/pom.xml +++ b/samples/jbossas/policy/sync/pom.xml @@ -106,6 +106,12 @@ policy-sync + + + src/main/resources + true + + maven-war-plugin diff --git a/samples/jbossas/policy/sync/src/main/resources/av.json b/samples/jbossas/policy/sync/src/main/resources/av.json index ab96efa1..a122c151 100644 --- a/samples/jbossas/policy/sync/src/main/resources/av.json +++ b/samples/jbossas/policy/sync/src/main/resources/av.json @@ -1,6 +1,6 @@ [{ "name" : "RestrictUsage", - "version" : "1", + "version" : "${project.version}", "predicate" : { "@class" : "org.overlord.rtgov.ep.mvel.MVELPredicate", "expression" : "event instanceof org.overlord.rtgov.activity.model.soa.RequestReceived && event.serviceType == \"{urn:switchyard-quickstart-demo:orders:0.1.0}OrderService\"" diff --git a/samples/jbossas/sla/epn/pom.xml b/samples/jbossas/sla/epn/pom.xml index ababca92..444194cb 100644 --- a/samples/jbossas/sla/epn/pom.xml +++ b/samples/jbossas/sla/epn/pom.xml @@ -47,6 +47,12 @@ sla-epn + + + src/main/resources + true + + maven-war-plugin diff --git a/samples/jbossas/sla/epn/src/main/resources/epn.json b/samples/jbossas/sla/epn/src/main/resources/epn.json index eac640e0..2007647f 100644 --- a/samples/jbossas/sla/epn/src/main/resources/epn.json +++ b/samples/jbossas/sla/epn/src/main/resources/epn.json @@ -1,5 +1,6 @@ { "name" : "SLAMonitorEPN", + "version" : "${project.version}", "subscriptions" : [ { "nodeName" : "SLAViolations", "subject" : "ServiceResponseTimes" @@ -24,6 +25,5 @@ "subject" : "Situations" } ] } - ], - "version" : "1" + ] } \ No newline at end of file diff --git a/samples/karaf/ordermgmt/epn/pom.xml b/samples/karaf/ordermgmt/epn/pom.xml index be2c197a..25ac521f 100644 --- a/samples/karaf/ordermgmt/epn/pom.xml +++ b/samples/karaf/ordermgmt/epn/pom.xml @@ -47,6 +47,12 @@ ordermgmt-epn + + + src/main/resources + true + + org.apache.felix diff --git a/samples/karaf/ordermgmt/epn/src/main/resources/epn.json b/samples/karaf/ordermgmt/epn/src/main/resources/epn.json index 251557da..85baf281 100644 --- a/samples/karaf/ordermgmt/epn/src/main/resources/epn.json +++ b/samples/karaf/ordermgmt/epn/src/main/resources/epn.json @@ -1,5 +1,6 @@ { "name" : "OrderManagementEPN", + "version" : "${project.version}", "subscriptions" : [ { "nodeName" : "CheckForException", "subject" : "ActivityUnits" @@ -23,6 +24,5 @@ "subject" : "Situations" } ] } - ], - "version" : "1" + ] } diff --git a/samples/karaf/ordermgmt/ip/pom.xml b/samples/karaf/ordermgmt/ip/pom.xml index e0574101..dd2b9e1b 100644 --- a/samples/karaf/ordermgmt/ip/pom.xml +++ b/samples/karaf/ordermgmt/ip/pom.xml @@ -37,6 +37,12 @@ ordermgmt-ip + + + src/main/resources + true + + org.apache.felix diff --git a/samples/karaf/ordermgmt/ip/src/main/resources/ip.json b/samples/karaf/ordermgmt/ip/src/main/resources/ip.json index 4e260044..7470cbad 100644 --- a/samples/karaf/ordermgmt/ip/src/main/resources/ip.json +++ b/samples/karaf/ordermgmt/ip/src/main/resources/ip.json @@ -1,6 +1,6 @@ [{ "name":"OrderManagementIP", - "version":"1", + "version":"${project.version}", "typeProcessors":{ "org.overlord.rtgov.quickstarts.demos.ordermgmt.model.Order":{ "contexts":[{ diff --git a/samples/karaf/policy/async/pom.xml b/samples/karaf/policy/async/pom.xml index acead049..8b248854 100644 --- a/samples/karaf/policy/async/pom.xml +++ b/samples/karaf/policy/async/pom.xml @@ -116,6 +116,12 @@ policy-async + + + src/main/resources + true + + org.apache.felix diff --git a/samples/karaf/policy/async/src/main/resources/AssessCredit.mvel b/samples/karaf/policy/async/src/main/resources/AssessCredit.mvel index a526570d..c8b3bd37 100644 --- a/samples/karaf/policy/async/src/main/resources/AssessCredit.mvel +++ b/samples/karaf/policy/async/src/main/resources/AssessCredit.mvel @@ -6,6 +6,8 @@ if (customer == null) { cm = epc.getService("CacheManager"); +creditLimit = epc.getParameter("creditLimit"); + // Attempt to lock the entry if (!cm.lock("Principals", customer)) { epc.handle(new Exception("Unable to lock entry for principal '"+customer+"'")); @@ -34,7 +36,7 @@ if (event.operation == "submitOrder") { int newtotal=current+total; - if (newtotal > 150 && current <= 150) { + if (newtotal > creditLimit && current <= creditLimit) { principal.put("suspended", Boolean.TRUE); } @@ -46,7 +48,7 @@ if (event.operation == "submitOrder") { int newamount=current-amount; - if (newamount <= 150 && current > 150) { + if (newamount <= creditLimit && current > creditLimit) { principal.put("suspended", Boolean.FALSE); } diff --git a/samples/karaf/policy/async/src/main/resources/epn.json b/samples/karaf/policy/async/src/main/resources/epn.json index 4aa692d4..9d871e44 100644 --- a/samples/karaf/policy/async/src/main/resources/epn.json +++ b/samples/karaf/policy/async/src/main/resources/epn.json @@ -1,6 +1,6 @@ { "name" : "AssessCreditPolicyEPN", - "version" : "1", + "version" : "${project.version}", "subscriptions" : [ { "nodeName" : "AssessCredit", "subject" : "SOAEvents" @@ -23,6 +23,9 @@ "CacheManager" : { "@class" : "org.overlord.rtgov.common.infinispan.service.InfinispanCacheManager" } + }, + "parameters" : { + "creditLimit" : 150 } } } diff --git a/samples/karaf/policy/sync/pom.xml b/samples/karaf/policy/sync/pom.xml index 6e45666d..d733d26f 100644 --- a/samples/karaf/policy/sync/pom.xml +++ b/samples/karaf/policy/sync/pom.xml @@ -106,6 +106,12 @@ policy-sync + + + src/main/resources + true + + org.apache.felix diff --git a/samples/karaf/policy/sync/src/main/resources/av.json b/samples/karaf/policy/sync/src/main/resources/av.json index 9e2d6957..b48fbc52 100644 --- a/samples/karaf/policy/sync/src/main/resources/av.json +++ b/samples/karaf/policy/sync/src/main/resources/av.json @@ -1,6 +1,6 @@ [{ "name" : "RestrictUsage", - "version" : "1", + "version" : "${project.version}", "predicate" : { "@class" : "org.overlord.rtgov.ep.mvel.MVELPredicate", "expression" : "event instanceof org.overlord.rtgov.activity.model.soa.RequestReceived && event.serviceType == \"org.overlord.rtgov.quickstarts.demos.ordermgmt.orderservice.OrderServiceBean\"" diff --git a/samples/karaf/sla/epn/pom.xml b/samples/karaf/sla/epn/pom.xml index 77c8e664..015c1ad5 100644 --- a/samples/karaf/sla/epn/pom.xml +++ b/samples/karaf/sla/epn/pom.xml @@ -47,6 +47,12 @@ sla-epn + + + src/main/resources + true + + org.apache.felix diff --git a/samples/karaf/sla/epn/src/main/resources/epn.json b/samples/karaf/sla/epn/src/main/resources/epn.json index eac640e0..2007647f 100644 --- a/samples/karaf/sla/epn/src/main/resources/epn.json +++ b/samples/karaf/sla/epn/src/main/resources/epn.json @@ -1,5 +1,6 @@ { "name" : "SLAMonitorEPN", + "version" : "${project.version}", "subscriptions" : [ { "nodeName" : "SLAViolations", "subject" : "ServiceResponseTimes" @@ -24,6 +25,5 @@ "subject" : "Situations" } ] } - ], - "version" : "1" + ] } \ No newline at end of file