use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.
the class RuntimeManagerWithDescriptorTest method testDeployWithFullCustomDeploymentDescriptor.
@Test
public void testDeployWithFullCustomDeploymentDescriptor() throws Exception {
Map<String, String> resources = new HashMap<String, String>();
String scriptString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ScriptTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ScriptTask.bpmn2", scriptString);
String manualString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ManualTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ManualTask.bpmn2", manualString);
String userString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-UserTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-UserTask.bpmn2", userString);
String callString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivity.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivity.bpmn2", callString);
String subProcessString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivitySubProcess.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivitySubProcess.bpmn2", subProcessString);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")).addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[] { DefaultSignalManagerFactory.class.getName() })).addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")).addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")).addGlobal(new NamedObjectModel("service", "java.util.ArrayList")).addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")).addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler"));
resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
String drl = "package org.jbpm; global java.util.List service; " + " rule \"Start Hello1\"" + " when" + " then" + " System.out.println(\"Hello\");" + " end";
resources.put("src/main/resources/simple.drl", drl);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.dd", "-kjar-with-dd", "1.0.0");
InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
installKjar(releaseId, kJar1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
InternalRuntimeManager internalManager = (InternalRuntimeManager) manager;
RegisterableItemsFactory factory = internalManager.getEnvironment().getRegisterableItemsFactory();
assertNotNull(factory);
assertTrue(factory instanceof InternalRegisterableItemsFactory);
assertNotNull(((InternalRegisterableItemsFactory) factory).getRuntimeManager());
DeploymentDescriptor descriptor = internalManager.getDeploymentDescriptor();
assertNotNull(descriptor);
assertEquals("org.jbpm.persistence.jpa", descriptor.getPersistenceUnit());
assertEquals("org.jbpm.persistence.jpa", descriptor.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, descriptor.getAuditMode());
assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
assertEquals(1, descriptor.getMarshallingStrategies().size());
// assertEquals(1, descriptor.getConfiguration().size());
assertEquals(1, descriptor.getEnvironmentEntries().size());
assertEquals(1, descriptor.getEventListeners().size());
assertEquals(1, descriptor.getGlobals().size());
assertEquals(1, descriptor.getTaskEventListeners().size());
assertEquals(1, descriptor.getWorkItemHandlers().size());
assertEquals(0, descriptor.getRequiredRoles().size());
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
KieSession kieSession = engine.getKieSession();
// configuration
assertEquals(((SessionConfiguration) kieSession.getSessionConfiguration()).getSignalManagerFactory(), DefaultSignalManagerFactory.class.getName());
BusinessCalendar bc = (BusinessCalendar) kieSession.getEnvironment().get("jbpm.business.calendar");
assertNotNull(bc);
assertTrue(bc instanceof TestBusinessCalendar);
// globals
Object service = kieSession.getGlobal("service");
assertNotNull(service);
assertTrue(service instanceof ArrayList);
// work item handler
ProcessInstance processInstance = kieSession.startProcess("ManualTask");
long processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
kieSession.getWorkItemManager().completeWorkItem(TestWorkItemHandler.getWorkItem().getId(), null);
assertNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// process event listener
assertArrayEquals(new String[] { "beforeProcessStarted", "afterProcessStarted", "beforeProcessCompleted", "afterProcessCompleted" }, processEvents.toArray());
processEvents.clear();
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// task event listener
processInstance = kieSession.startProcess("UserTask");
processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
TaskService taskService = engine.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
assertArrayEquals(new String[] { "beforeTaskAddedEvent", "afterTaskAddedEvent", "beforeTaskStartedEvent", "afterTaskStartedEvent", "beforeTaskCompletedEvent", "afterTaskCompletedEvent" }, taskEvents.toArray());
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// marshalling strategy
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "marshal");
processInstance = kieSession.startProcess("ParentProcess", params);
processInstanceId = processInstance.getId();
ProcessInstance pi = kieSession.getProcessInstance(processInstanceId);
assertNotNull(pi);
String varX = (String) ((WorkflowProcessInstance) pi).getVariable("x");
assertEquals(TestMarshallingStrategy.ALWAYS_RESPOND_WITH, varX);
manager.disposeRuntimeEngine(engine);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.
the class MBeansMonitoringWithJBpmTest method testRulesAndProcesses.
@Test
public void testRulesAndProcesses() throws Exception {
String drl = "package org.drools.droolsjbpm_integration_testmgt\n" + "rule S\n" + "when\n" + " $s: String() \n" + "then\n" + " try { Thread.sleep(10); } catch (Exception e) { }\n" + " System.out.println($s); \n" + "end\n";
String process = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" + "<definitions id=\"Definition\"\n" + " targetNamespace=\"http://www.example.org/MinimalExample\"\n" + " typeLanguage=\"http://www.java.com/javaTypes\"\n" + " expressionLanguage=\"http://www.mvel.org/2.0\"\n" + " xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\"\n" + " xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"\n" + " xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"\n" + " xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"\n" + " xmlns:tns=\"http://www.jboss.org/drools\">\n" + "\n" + " <process processType=\"Private\" isExecutable=\"true\" id=\"com.sample.HelloWorld\" name=\"Hello World\" >\n" + "\n" + " <!-- nodes -->\n" + " <startEvent id=\"_a1\" name=\"StartProcess\" />\n" + " <scriptTask id=\"_a2\" name=\"Hello\" >\n" + " <script>System.out.println(\"Hello World\");</script>\n" + " </scriptTask>\n" + " <endEvent id=\"_a3\" name=\"EndProcess\" >\n" + " <terminateEventDefinition/>\n" + " </endEvent>\n" + "\n" + " <!-- connections -->\n" + " <sequenceFlow id=\"_a1-_a2\" sourceRef=\"_a1\" targetRef=\"_a2\" />\n" + " <sequenceFlow id=\"_a2-_a3\" sourceRef=\"_a2\" targetRef=\"_a3\" />\n" + "\n" + " </process>" + " <process processType=\"Private\" isExecutable=\"true\" id=\"com.sample.CiaoWorld\" name=\"Ciao World\" >\n" + "\n" + " <!-- nodes -->\n" + " <startEvent id=\"_b1\" name=\"StartProcess\" />\n" + " <scriptTask id=\"_b2\" name=\"Ciao\" >\n" + " <script>System.out.println(\"Ciao World\");</script>\n" + " </scriptTask>\n" + " <endEvent id=\"_b3\" name=\"EndProcess\" >\n" + " <terminateEventDefinition/>\n" + " </endEvent>\n" + "\n" + " <!-- connections -->\n" + " <sequenceFlow id=\"_b1-_b2\" sourceRef=\"_b1\" targetRef=\"_b2\" />\n" + " <sequenceFlow id=\"_b2-_b3\" sourceRef=\"_b2\" targetRef=\"_b3\" />\n" + "\n" + " </process>" + "</definitions>";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(KBASE1).setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel(KSESSION1).setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSessionModel ksessionModel2 = kieBaseModel1.newKieSessionModel(KSESSION2).setDefault(false).setType(KieSessionModel.KieSessionType.STATELESS);
ReleaseId releaseId1 = ks.newReleaseId("org.kie.test", "mbeans", "1.0.0");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
kfs.generateAndWritePomXML(releaseId1);
kfs.write("src/main/resources/r" + 1 + ".drl", drl);
kfs.write("src/main/resources/p" + 1 + ".bpmn2", process);
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
if (kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
for (org.kie.api.builder.Message result : kb.getResults().getMessages()) {
LOG.error(result.getText());
}
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId1);
KieContainer kc = ks.newKieContainer(KCONTAINER1, releaseId1);
KieBase kiebase = kc.getKieBase(KBASE1);
Properties ksessionConfigProps = new Properties();
ksessionConfigProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
ksessionConfigProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
KieSessionConfiguration sessionConf = ks.newKieSessionConfiguration(ksessionConfigProps);
sessionConf.setOption(ForceEagerActivationOption.YES);
KieSession ksession = kc.newKieSession(KSESSION1, sessionConf);
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
KieSessionMonitoringMXBean aggrMonitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(KCONTAINER1, KBASE1, KieSessionType.STATEFUL, KSESSION1), KieSessionMonitoringMXBean.class);
long tft = 0;
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 0, 0, 0);
checkTotalFactCount(aggrMonitor, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft);
checkTotalSessions(aggrMonitor, 1);
assertNull(aggrMonitor.getStatsForProcess("com.sample.HelloWorld"));
assertNull(aggrMonitor.getStatsForProcess("com.sample.CiaoWorld"));
assertFalse(aggrMonitor.getStatsByProcess().containsKey("com.sample.HelloWorld"));
assertFalse(aggrMonitor.getStatsByProcess().containsKey("com.sample.CiaoWorld"));
ksession.insert("Ciao");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.CiaoWorld");
ksession.fireAllRules();
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 1, 0, 1);
checkTotalFactCount(aggrMonitor, 1);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft + 1);
checkTotalSessions(aggrMonitor, 1);
checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 2, 2, 6);
checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 1, 1, 3);
ksession.fireAllRules();
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 1, 0, 1);
checkTotalFactCount(aggrMonitor, 1);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft);
checkTotalSessions(aggrMonitor, 1);
checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 2, 2, 6);
checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 1, 1, 3);
LOG.debug("---");
KieSession ksession2 = kc.newKieSession(KSESSION1, sessionConf);
ksession2.insert("Ciao");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.CiaoWorld");
ksession2.fireAllRules();
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 2, 0, 2);
checkTotalFactCount(aggrMonitor, 2);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft + 1);
checkTotalSessions(aggrMonitor, 2);
checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 4, 4, 12);
checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 2, 2, 6);
LOG.debug("--- NOW for the STATELESS ---");
tft = 0;
StatelessKieSession stateless = kc.newStatelessKieSession(KSESSION2, sessionConf);
StatelessKieSessionMonitoringMXBean aggrMonitor2 = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(KCONTAINER1, KBASE1, KieSessionType.STATELESS, KSESSION2), StatelessKieSessionMonitoringMXBean.class);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 0, 0, 0);
checkRuleRuntimeTotals(aggrMonitor2, 0, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft);
checkTotalSessions(aggrMonitor2, 0);
List<Command> cmds = new ArrayList<Command>();
cmds.add(CommandFactory.newInsert("Ciao"));
cmds.add(CommandFactory.newStartProcess("com.sample.HelloWorld"));
cmds.add(CommandFactory.newStartProcess("com.sample.HelloWorld"));
cmds.add(CommandFactory.newStartProcess("com.sample.CiaoWorld"));
BatchExecutionCommand batch = CommandFactory.newBatchExecution(cmds);
stateless.execute(batch);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 1, 0, 1);
checkRuleRuntimeTotals(aggrMonitor2, 1, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
checkTotalSessions(aggrMonitor2, 1);
checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 2, 2, 6);
checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 1, 1, 3);
stateless.execute(batch);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 2, 0, 2);
checkRuleRuntimeTotals(aggrMonitor2, 2, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
checkTotalSessions(aggrMonitor2, 2);
checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 4, 4, 12);
checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 2, 2, 6);
StatelessKieSession stateless2 = kc.newStatelessKieSession(KSESSION2, sessionConf);
LOG.debug(stateless + " " + stateless2);
checkTotalSessions(aggrMonitor2, 2);
stateless2.execute(batch);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 3, 0, 3);
checkRuleRuntimeTotals(aggrMonitor2, 3, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
checkTotalSessions(aggrMonitor2, 3);
checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 6, 6, 18);
checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 3, 3, 9);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.
the class EJBService method createKieJar.
private static InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, List<String> resources, Map<String, String> extraResources) {
KieFileSystem kfs = createKieFileSystemWithKProject(ks);
kfs.writePomXML(getPom(releaseId));
for (String resource : resources) {
kfs.write("src/main/resources/KBase-test/" + resource, ResourceFactory.newClassPathResource(EJB_SERVICES_ASSETS_PATH + resource));
}
if (extraResources != null) {
for (Map.Entry<String, String> entry : extraResources.entrySet()) {
kfs.write(entry.getKey(), ResourceFactory.newByteArrayResource(entry.getValue().getBytes()));
}
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {
for (Message message : kieBuilder.buildAll().getResults().getMessages()) {
LOGGER.error("Error Message: ({}) {}", message.getPath(), message.getText());
}
throw new RuntimeException("There are errors building the package, please check your knowledge assets!");
}
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.
the class RuntimeDataServiceImplTest method prepare.
@Before
public void prepare() {
configureServices();
logger.debug("Preparing kjar");
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
List<String> processes = new ArrayList<String>();
processes.add("repo/processes/general/EmptyHumanTask.bpmn");
processes.add("repo/processes/general/humanTask.bpmn");
processes.add("repo/processes/general/BPMN2-UserTask.bpmn2");
processes.add("repo/processes/general/SimpleHTProcess.bpmn2");
processes.add("repo/processes/general/AdHocSubProcess.bpmn2");
InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
File pom = new File("target/kmodule", "pom.xml");
pom.getParentFile().mkdir();
try {
FileOutputStream fs = new FileOutputStream(pom);
fs.write(getPom(releaseId).getBytes());
fs.close();
} catch (Exception e) {
}
KieMavenRepository repository = getKieMavenRepository();
repository.deployArtifact(releaseId, kJar1, pom);
assertNotNull(deploymentService);
deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
assertNotNull(processService);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.
the class TaskQueryBuilderTest method prepare.
@Before
public void prepare() {
this.dataSourceJNDIname = getDataSourceJNDI();
configureServices();
logger.debug("Preparing kjar");
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
List<String> processes = new ArrayList<String>();
processes.add("repo/processes/general/humanTask.bpmn");
processes.add("repo/processes/hr/hiring.bpmn2");
InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
File pom = new File("target/kmodule", "pom.xml");
pom.getParentFile().mkdir();
try {
FileOutputStream fs = new FileOutputStream(pom);
fs.write(getPom(releaseId).getBytes());
fs.close();
} catch (Exception e) {
}
KieMavenRepository repository = getKieMavenRepository();
repository.deployArtifact(releaseId, kJar1, pom);
assertNotNull(deploymentService);
deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
prepareJPAModule(ks, repository);
assertNotNull(processService);
}
Aggregations