summaryrefslogtreecommitdiff
path: root/calamus-engine/src/main/java/io
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2014-04-12 17:55:28 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2014-04-12 17:55:28 +0200
commitbfcfcf5e3b4301bc94c27f47bfda61693edf3595 (patch)
treed6eedd800b1b34fd66ccbd86e5f215aaa40ccd3d /calamus-engine/src/main/java/io
downloadcalamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.gz
calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.bz2
calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.xz
calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.zip
wip
Diffstat (limited to 'calamus-engine/src/main/java/io')
-rw-r--r--calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java69
-rw-r--r--calamus-engine/src/main/java/io/trygvis/engine/Main.java13
-rw-r--r--calamus-engine/src/main/java/io/trygvis/engine/MqClient.java73
-rw-r--r--calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java24
-rw-r--r--calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java24
-rw-r--r--calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java7
-rw-r--r--calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java15
7 files changed, 225 insertions, 0 deletions
diff --git a/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java b/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java
new file mode 100644
index 0000000..0a7be62
--- /dev/null
+++ b/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java
@@ -0,0 +1,69 @@
+package io.trygvis.engine;
+
+import bitronix.tm.TransactionManagerServices;
+import bitronix.tm.resource.jdbc.PoolingDataSource;
+import org.jbpm.bpmn2.handler.ServiceTaskHandler;
+import org.jbpm.process.audit.AuditLoggerFactory;
+import org.kie.api.KieBase;
+import org.kie.api.runtime.Environment;
+import org.kie.api.runtime.EnvironmentName;
+import org.kie.api.runtime.process.ProcessInstance;
+import org.kie.internal.KnowledgeBaseFactory;
+import org.kie.internal.io.ResourceFactory;
+import org.kie.internal.persistence.jpa.JPAKnowledgeService;
+import org.kie.internal.runtime.StatefulKnowledgeSession;
+import org.kie.internal.utils.KieHelper;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+public class CalamusJbpm {
+ private final StatefulKnowledgeSession session;
+
+ public static enum CalamusProcess {
+ DEPLOY("io.trygvis.bpm.Deploy");
+
+ private String name;
+
+ CalamusProcess(String name) {
+ this.name = name;
+ }
+ }
+
+ public CalamusJbpm() {
+ PoolingDataSource ds = new PoolingDataSource();
+ ds.setUniqueName("jdbc/jbpm-ds");
+ ds.setClassName(bitronix.tm.resource.jdbc.lrc.LrcXADataSource.class.getCanonicalName());
+ ds.setMaxPoolSize(3);
+ ds.setAllowLocalTransactions(true);
+ ds.getDriverProperties().put("user", "jbpm");
+ ds.getDriverProperties().put("password", "jbpm");
+ ds.getDriverProperties().put("url", "jdbc:postgresql://localhost/jbpm");
+ ds.getDriverProperties().put("driverClassName", org.postgresql.Driver.class.getCanonicalName());
+ ds.init();
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
+ Environment env = KnowledgeBaseFactory.newEnvironment();
+ env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
+ env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
+
+ KieBase kieBase = new KieHelper()
+ .addResource(ResourceFactory.newClassPathResource("Deploy.bpmn2"))
+ .build();
+
+ session = JPAKnowledgeService.newStatefulKnowledgeSession(kieBase, null, env);
+ session.addEventListener(AuditLoggerFactory.newJPAInstance(env));
+
+ session.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
+ session.getWorkItemManager().registerWorkItemHandler("Upgrade App", new UpgradeAppWorkItemHandler());
+ session.getWorkItemManager().registerWorkItemHandler("Restart App", new RestartAppWorkItemHandler());
+ }
+
+ public StatefulKnowledgeSession getSession() {
+ return session;
+ }
+
+ public void startProcess(CalamusProcess process) {
+ ProcessInstance processInstance = session.startProcess(process.name);
+ }
+}
diff --git a/calamus-engine/src/main/java/io/trygvis/engine/Main.java b/calamus-engine/src/main/java/io/trygvis/engine/Main.java
new file mode 100644
index 0000000..bc322e8
--- /dev/null
+++ b/calamus-engine/src/main/java/io/trygvis/engine/Main.java
@@ -0,0 +1,13 @@
+package io.trygvis.engine;
+
+import static io.trygvis.engine.CalamusJbpm.CalamusProcess.DEPLOY;
+
+public class Main {
+ public static void main(String[] args) {
+ CalamusJbpm jbpm = new CalamusJbpm();
+
+ MqClient mqClient = new MqClient(jbpm.getSession(), "tcp://localhost:61616");
+
+ jbpm.startProcess(DEPLOY);
+ }
+}
diff --git a/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java b/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java
new file mode 100644
index 0000000..b609c9f
--- /dev/null
+++ b/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java
@@ -0,0 +1,73 @@
+package io.trygvis.engine;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.kie.internal.runtime.StatefulKnowledgeSession;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+
+import static javax.jms.Session.AUTO_ACKNOWLEDGE;
+
+public class MqClient implements AutoCloseable {
+
+ private Connection connection;
+// private final ActiveMQConnectionFactory connectionFactory;
+// private final StatefulKnowledgeSession jbpm;
+
+ public MqClient(final StatefulKnowledgeSession jbpm, String brukerUrl) {
+// this.jbpm = jbpm;
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brukerUrl);
+
+ try {
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(false, AUTO_ACKNOWLEDGE);
+
+ Destination destination = session.createQueue("jenkins.build-result");
+
+ MessageConsumer consumer = session.createConsumer(destination);
+ consumer.setMessageListener(new MessageListener() {
+ @Override
+ public void onMessage(Message message) {
+ if (!(message instanceof MapMessage)) {
+ return;
+ }
+
+ MapMessage m = (MapMessage) message;
+
+ try {
+ String jobName = m.getString("jobName");
+ int buildNumber = m.getInt("buildNumber");
+ String result = m.getString("result");
+
+/*
+ String type;
+ Object event;
+ long processInstanceId;
+ jbpm.signalEvent(type, event, processInstanceId);
+*/
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (connection != null) {
+ connection.close();
+ this.connection = null;
+ }
+ }
+}
diff --git a/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java b/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java
new file mode 100644
index 0000000..98733c7
--- /dev/null
+++ b/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java
@@ -0,0 +1,24 @@
+package io.trygvis.engine;
+
+import org.kie.api.runtime.process.WorkItem;
+import org.kie.api.runtime.process.WorkItemHandler;
+import org.kie.api.runtime.process.WorkItemManager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class RestartAppWorkItemHandler implements WorkItemHandler {
+
+ @Override
+ public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
+ System.out.println("RestartAppWorkItemHandler.executeWorkItem");
+
+ Map<String, Object> results = new HashMap<>();
+ manager.completeWorkItem(workItem.getId(), results);
+ }
+
+ @Override
+ public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
+ System.out.println("RestartAppWorkItemHandler.abortWorkItem");
+ }
+}
diff --git a/calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java b/calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java
new file mode 100644
index 0000000..6202d6b
--- /dev/null
+++ b/calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java
@@ -0,0 +1,24 @@
+package io.trygvis.engine;
+
+import org.kie.api.runtime.process.WorkItem;
+import org.kie.api.runtime.process.WorkItemHandler;
+import org.kie.api.runtime.process.WorkItemManager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class UpgradeAppWorkItemHandler implements WorkItemHandler {
+
+ @Override
+ public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
+ System.out.println("UpgradeAppWorkItemHandler.executeWorkItem");
+
+ Map<String, Object> results = new HashMap<>();
+ manager.completeWorkItem(workItem.getId(), results);
+ }
+
+ @Override
+ public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
+ System.out.println("UpgradeAppWorkItemHandler.abortWorkItem");
+ }
+}
diff --git a/calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java b/calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java
new file mode 100644
index 0000000..0badb8c
--- /dev/null
+++ b/calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java
@@ -0,0 +1,7 @@
+package io.trygvis.engine.service;
+
+public class AppInstance {
+ private String name;
+ private String host;
+ private String path;
+}
diff --git a/calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java b/calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java
new file mode 100644
index 0000000..3ccde2b
--- /dev/null
+++ b/calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java
@@ -0,0 +1,15 @@
+package io.trygvis.engine.service;
+
+public class AppService {
+ public void installApp(AppInstance instance) {
+ System.out.println("AppService.installApp");
+ }
+
+ public void restartApp(AppInstance instance) {
+ System.out.println("AppService.restartApp");
+ }
+
+ public void waitForUp(AppInstance instance) {
+ System.out.println("AppService.waitForAppUp");
+ }
+}