From fd681e2c6663652be02a31f7b40da4cd283ab37e Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 21 Apr 2014 09:01:00 +0200 Subject: wip --- .../io/trygvis/calamus/engine/CalamusDbConfig.java | 123 +++ .../io/trygvis/calamus/engine/CalamusJbpm.java | 80 ++ .../trygvis/calamus/engine/CalamusJbpmConfig.java | 68 ++ .../engine/JenkinsBuildResultMessageListener.java | 53 ++ .../main/java/io/trygvis/calamus/engine/Main.java | 28 + .../java/io/trygvis/calamus/engine/MqClient.java | 44 + .../engine/NexusNewArtifactMessageListener.java | 111 +++ .../calamus/engine/RestartAppWorkItemHandler.java | 24 + .../calamus/engine/UpgradeAppWorkItemHandler.java | 24 + .../calamus/engine/domain/AbstractEntity.java | 19 + .../trygvis/calamus/engine/domain/AppInstance.java | 7 + .../trygvis/calamus/engine/domain/AppService.java | 15 + .../io/trygvis/calamus/engine/domain/Artifact.java | 89 ++ .../io/trygvis/calamus/engine/domain/Process.java | 40 + .../calamus/engine/domain/ProcessTrigger.java | 51 ++ .../java/io/trygvis/engine/CalamusDbConfig.java | 129 --- .../main/java/io/trygvis/engine/CalamusJbpm.java | 74 -- .../java/io/trygvis/engine/CalamusJbpmConfig.java | 63 -- .../engine/JenkinsBuildResultMessageListener.java | 53 -- .../src/main/java/io/trygvis/engine/Main.java | 28 - .../src/main/java/io/trygvis/engine/MqClient.java | 50 -- .../engine/NexusNewArtifactMessageListener.java | 106 --- .../trygvis/engine/RestartAppWorkItemHandler.java | 24 - .../trygvis/engine/UpgradeAppWorkItemHandler.java | 24 - .../io/trygvis/engine/domain/AbstractEntity.java | 19 - .../java/io/trygvis/engine/domain/Artifact.java | 89 -- .../java/io/trygvis/engine/domain/Process.java | 25 - .../io/trygvis/engine/domain/ProcessTrigger.java | 47 -- .../io/trygvis/engine/service/AppInstance.java | 7 - .../java/io/trygvis/engine/service/AppService.java | 15 - calamus-engine/src/main/resources/Deploy.bpmn2 | 22 +- .../src/main/resources/META-INF/persistence.xml | 11 +- .../main/resources/db/public/V001_000__jbpm.sql | 929 ++++++++------------- .../resources/db/public/V001_001__baseline.sql | 41 - calamus-engine/src/main/resources/logback.xml | 7 +- .../java/io/trygvis/calamus/engine/MyTest.java | 73 ++ .../src/test/java/io/trygvis/engine/MyTest.java | 90 -- 37 files changed, 1223 insertions(+), 1479 deletions(-) create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusDbConfig.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpm.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpmConfig.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/JenkinsBuildResultMessageListener.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/Main.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/MqClient.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/NexusNewArtifactMessageListener.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/RestartAppWorkItemHandler.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/UpgradeAppWorkItemHandler.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AbstractEntity.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppInstance.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppService.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Artifact.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Process.java create mode 100644 calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/ProcessTrigger.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/CalamusDbConfig.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpmConfig.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/JenkinsBuildResultMessageListener.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/Main.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/MqClient.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/NexusNewArtifactMessageListener.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/domain/AbstractEntity.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/domain/Artifact.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/domain/Process.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/domain/ProcessTrigger.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java delete mode 100644 calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java delete mode 100644 calamus-engine/src/main/resources/db/public/V001_001__baseline.sql create mode 100644 calamus-engine/src/test/java/io/trygvis/calamus/engine/MyTest.java delete mode 100644 calamus-engine/src/test/java/io/trygvis/engine/MyTest.java (limited to 'calamus-engine/src') diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusDbConfig.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusDbConfig.java new file mode 100644 index 0000000..ad0e5a9 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusDbConfig.java @@ -0,0 +1,123 @@ +package io.trygvis.calamus.engine; + +import bitronix.tm.BitronixTransactionManager; +import bitronix.tm.TransactionManagerServices; +import bitronix.tm.resource.jdbc.PoolingDataSource; +import com.googlecode.flyway.core.Flyway; +import com.googlecode.flyway.core.api.MigrationInfo; +import com.googlecode.flyway.core.api.MigrationInfoService; +import org.jbpm.process.audit.JPAAuditLogService; +import org.slf4j.Logger; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; +import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; +import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.jta.JtaTransactionManager; +import org.springframework.transaction.support.TransactionTemplate; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.Date; + +import static java.lang.String.format; +import static org.slf4j.LoggerFactory.getLogger; + +/** + * http://planet.jboss.org/post/jbpm_6_with_spring + */ +@Configuration +@EnableTransactionManagement +public class CalamusDbConfig { + private final Logger log = getLogger(getClass()); + + @Bean + public PoolingDataSource innerDataSource() { + PoolingDataSource ds = new PoolingDataSource(); + ds.setUniqueName("jdbc/jbpm-ds"); + ds.setClassName(bitronix.tm.resource.jdbc.lrc.LrcXADataSource.class.getCanonicalName()); + ds.setMaxPoolSize(10); + 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(); + return ds; + } + + @Bean + public DataSource dataSource(PoolingDataSource ds) { + return new TransactionAwareDataSourceProxy(new LazyConnectionDataSourceProxy(ds)); + } + + public static class DbMigrations { + } + + @Bean + public DbMigrations dbMigrations(DataSource dataSource) { + runFlyway(log, dataSource, "", "public"); + return new DbMigrations(); + } + + private static void runFlyway(Logger log, DataSource dataSource, String prefix, String schema) { + log.info("Running migrations for {}", schema); + + Flyway flyway = new Flyway(); + flyway.setDataSource(dataSource); + flyway.setSchemas(schema); + flyway.setLocations("db/" + prefix); + flyway.setInitOnMigrate(true); + MigrationInfoService info = flyway.info(); + log.info(format("%-15s %-10s %-19s %s", "Version", "State", "Installed on", "Description")); + for (MigrationInfo mi : info.all()) { + Date installedOn = mi.getInstalledOn(); + log.info(format("%-15s %-10s %-19s %s", + mi.getVersion(), + trimToEmpty(mi.getState().getDisplayName()), + installedOn != null ? new Date(installedOn.getTime()).toString() : "", + trimToEmpty(mi.getDescription()))); + } + flyway.migrate(); + } + + private static String trimToEmpty(String string) { + if (string == null) { + return ""; + } + + return string.trim(); + } + + @Bean(destroyMethod = "shutdown") + public BitronixTransactionManager bitronixTransactionManager() { +// bitronix.tm.Configuration configuration = TransactionManagerServices.getConfiguration(); + return TransactionManagerServices.getTransactionManager(); + } + + @Bean + public PlatformTransactionManager platformTransactionManager(BitronixTransactionManager transactionManager) { + return new JtaTransactionManager(transactionManager, transactionManager); + } + + @Bean + public TransactionTemplate transactionTemplate(PlatformTransactionManager platformTransactionManager) { + return new TransactionTemplate(platformTransactionManager); + } + + @Bean + @DependsOn("dbMigrations") + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + LocalContainerEntityManagerFactoryBean x = new LocalContainerEntityManagerFactoryBean(); + x.setPersistenceUnitName("org.jbpm.persistence.jpa"); + return x; + } + + @Bean + public JPAAuditLogService jpaAuditLogService(EntityManagerFactory entityManagerFactory) { + return new JPAAuditLogService(entityManagerFactory); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpm.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpm.java new file mode 100644 index 0000000..af6f489 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpm.java @@ -0,0 +1,80 @@ +package io.trygvis.calamus.engine; + +import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.manager.RuntimeEngine; +import org.kie.api.runtime.manager.RuntimeManager; +import org.kie.api.runtime.process.ProcessInstance; +import org.kie.internal.runtime.manager.context.ProcessInstanceIdContext; +import org.slf4j.Logger; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.transaction.support.TransactionTemplate; + +import javax.persistence.EntityManagerFactory; + +import static org.slf4j.LoggerFactory.getLogger; + +public class CalamusJbpm { + private final Logger log = getLogger(getClass()); + + private final TransactionTemplate transactionTemplate; + + private final EntityManagerFactory emf; + + private final KieSession session; + + public static enum CalamusProcess { + DEPLOY("io.trygvis.bpm.Deploy"); + + private String name; + + CalamusProcess(String name) { + this.name = name; + } + } + + public CalamusJbpm() { + AnnotationConfigApplicationContext spring = new AnnotationConfigApplicationContext(CalamusDbConfig.class, CalamusJbpmConfig.class); + +// 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(); + +// RuntimeEnvironment runtimeEnvironment = spring.getBean(RuntimeEnvironment.class); +// +// KieBase kieBase = runtimeEnvironment.getKieBase(); + + transactionTemplate = spring.getBean(TransactionTemplate.class); + emf = spring.getBean(EntityManagerFactory.class); + + RuntimeManager runtimeManager = spring.getBean(RuntimeManager.class); + RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get()); + session = engine.getKieSession(); +// 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 TransactionTemplate getTransactionTemplate() { + return transactionTemplate; + } + + public EntityManagerFactory getEntityManagerFactory() { + return emf; + } + + public KieSession getSession() { + return session; + } + + public void startProcess(CalamusProcess process) { + ProcessInstance processInstance = session.startProcess(process.name); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpmConfig.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpmConfig.java new file mode 100644 index 0000000..edfda28 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/CalamusJbpmConfig.java @@ -0,0 +1,68 @@ +package io.trygvis.calamus.engine; + +import org.jbpm.process.audit.JPAAuditLogService; +import org.kie.api.io.Resource; +import org.kie.api.io.ResourceType; +import org.kie.api.runtime.manager.RuntimeEnvironment; +import org.kie.api.runtime.manager.RuntimeManager; +import org.kie.internal.io.ResourceFactory; +import org.kie.spring.factorybeans.RuntimeEnvironmentFactoryBean; +import org.kie.spring.factorybeans.RuntimeManagerFactoryBean; +import org.slf4j.Logger; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; + +import static org.slf4j.LoggerFactory.getLogger; + +/** + * http://planet.jboss.org/post/jbpm_6_with_spring + */ +@Configuration +public class CalamusJbpmConfig { + private final Logger log = getLogger(getClass()); + + @Bean + @Lazy + public RuntimeEnvironmentFactoryBean runtimeEnvironment(DataSource dataSource, CalamusDbConfig.DbMigrations dbMigrations, EntityManagerFactory entityManagerFactory, PlatformTransactionManager platformTransactionManager) { + System.out.println("CalamusConfig.runtimeEnvironmentFactoryBean"); + System.out.println("dataSource = " + dataSource); + System.out.println("dbMigrations = " + dbMigrations); + System.out.println("entityManagerFactory = " + entityManagerFactory); + System.out.println("platformTransactionManager = " + platformTransactionManager); + RuntimeEnvironmentFactoryBean x = new RuntimeEnvironmentFactoryBean(); + x.setType("DEFAULT"); + + Map assets = new HashMap<>(); + System.out.println("getClass().getClassLoader() = " + getClass().getClassLoader()); + assets.put(ResourceFactory.newClassPathResource("Deploy.bpmn2", getClass()), ResourceType.BPMN2); + x.setAssets(assets); +// x.setClassLoader(getClass().getClassLoader()); + + x.setEntityManagerFactory(entityManagerFactory); + x.setTransactionManager(platformTransactionManager); + + return x; + } + + @Bean + @Lazy + public RuntimeManager runtimeManagerFactoryBean(RuntimeEnvironment runtimeEnvironment) throws Exception { + RuntimeManagerFactoryBean x = new RuntimeManagerFactoryBean(); + x.setIdentifier("spring-rm"); + x.setRuntimeEnvironment(runtimeEnvironment); + x.afterPropertiesSet(); + return (RuntimeManager) x.getObject(); + } + + @Bean + public JPAAuditLogService jpaAuditLogService(EntityManagerFactory entityManagerFactory) { + return new JPAAuditLogService(entityManagerFactory); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/JenkinsBuildResultMessageListener.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/JenkinsBuildResultMessageListener.java new file mode 100644 index 0000000..39ac6e3 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/JenkinsBuildResultMessageListener.java @@ -0,0 +1,53 @@ +package io.trygvis.calamus.engine; + +import org.kie.api.runtime.KieSession; +import org.slf4j.Logger; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.TextMessage; +import java.io.IOException; +import java.io.StringReader; +import java.util.Properties; + +import static java.lang.Integer.parseInt; +import static org.slf4j.LoggerFactory.getLogger; + +public class JenkinsBuildResultMessageListener implements MessageListener { + private final Logger log = getLogger(getClass()); + + private KieSession session; + + public JenkinsBuildResultMessageListener(KieSession session) { + this.session = session; + } + + @Override + public void onMessage(Message message) { + if (!(message instanceof TextMessage)) { + return; + } + + try { + TextMessage m = (TextMessage) message; + Properties p = new Properties(); + p.load(new StringReader(m.getText())); + + String jobName = p.getProperty("jobName"); + int buildNumber = parseInt(p.getProperty("buildNumber")); + String result = p.getProperty("result"); + + log.info("New build: jobName={}, buildNumber={}, result={}", jobName, buildNumber, result); + + /* + String type; + Object event; + long processInstanceId; + jbpm.signalEvent(type, event, processInstanceId); + */ + } catch (JMSException | IOException e) { + e.printStackTrace(); + } + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/Main.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/Main.java new file mode 100644 index 0000000..daa4886 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/Main.java @@ -0,0 +1,28 @@ +package io.trygvis.calamus.engine; + +import org.kie.api.runtime.KieSession; + +public class Main { + public static void main(String[] args) throws Exception { + + CalamusJbpm calamus = new CalamusJbpm(); + + String brokerUrl = "tcp://localhost:61616"; + + KieSession session = calamus.getSession(); + +// EntityManager entityManager = calamus.getEntityManagerFactory().createEntityManager(); +// EntityTransaction transaction = entityManager.getTransaction(); +// transaction.begin(); +// entityManager.createQuery("FROM Process"); +// transaction.commit(); + + try (MqClient buildResultClient = new MqClient(brokerUrl, "jenkins.build-result", new JenkinsBuildResultMessageListener(session)); + MqClient newDeployClient = new MqClient(brokerUrl, "nexus.new-artifact", new NexusNewArtifactMessageListener(calamus.getTransactionTemplate(), calamus.getEntityManagerFactory(), session))) { + + while (true) { + Thread.sleep(1000); + } + } + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/MqClient.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/MqClient.java new file mode 100644 index 0000000..0cb33ad --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/MqClient.java @@ -0,0 +1,44 @@ +package io.trygvis.calamus.engine; + +import org.apache.activemq.ActiveMQConnectionFactory; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.Session; + +import static java.lang.Integer.parseInt; +import static javax.jms.Session.AUTO_ACKNOWLEDGE; + +public class MqClient implements AutoCloseable { + + private Connection connection; + + public MqClient(String brokerUrl, String queueName, MessageListener messageListener) { + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); + + try { + connection = connectionFactory.createConnection(); + connection.start(); + + Session session = connection.createSession(false, AUTO_ACKNOWLEDGE); + + Destination destination = session.createQueue(queueName); + + MessageConsumer consumer = session.createConsumer(destination); + consumer.setMessageListener(messageListener); + } 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/calamus/engine/NexusNewArtifactMessageListener.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/NexusNewArtifactMessageListener.java new file mode 100644 index 0000000..ab111d7 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/NexusNewArtifactMessageListener.java @@ -0,0 +1,111 @@ +package io.trygvis.calamus.engine; + +import io.trygvis.calamus.engine.domain.Artifact; +import io.trygvis.calamus.engine.domain.Process; +import io.trygvis.calamus.engine.domain.ProcessTrigger; +import org.kie.api.runtime.KieSession; +import org.slf4j.Logger; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.TransactionCallbackWithoutResult; +import org.springframework.transaction.support.TransactionTemplate; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.TextMessage; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.NoResultException; +import javax.persistence.TypedQuery; +import java.io.IOException; +import java.io.StringReader; +import java.util.Map; +import java.util.Properties; + +import static java.util.Collections.singletonMap; +import static org.slf4j.LoggerFactory.getLogger; + +public class NexusNewArtifactMessageListener implements MessageListener { + private final Logger log = getLogger(getClass()); + + private final TransactionTemplate transactionTemplate; + private final EntityManagerFactory entityManagerFactory; + private final KieSession session; + + public NexusNewArtifactMessageListener(TransactionTemplate transactionTemplate, EntityManagerFactory entityManagerFactory, KieSession session) { + this.transactionTemplate = transactionTemplate; + this.entityManagerFactory = entityManagerFactory; + this.session = session; + } + + @Override + public void onMessage(Message message) { + if (!(message instanceof TextMessage)) { + return; + } + + try { + TextMessage m = (TextMessage) message; + Properties p = new Properties(); + p.load(new StringReader(m.getText())); + + String repository = p.getProperty("repository"); + String groupId = p.getProperty("groupId"); + String artifactId = p.getProperty("artifactId"); + String version = p.getProperty("version"); + String classifier = p.getProperty("classifier"); + String extension = p.getProperty("extension"); + + log.info("Artifact event: groupId={}, artifactId={}, version={}, classifier={}, extension={}", groupId, artifactId, version, classifier, extension); + + transactionTemplate.execute(new TransactionCallbackWithoutResult() { + @Override + protected void doInTransactionWithoutResult(TransactionStatus status) { + processMessage(groupId, artifactId, version, classifier, extension); + } + }); + } catch (JMSException | IOException e) { + e.printStackTrace(); + } + } + + private void processMessage(String groupId, String artifactId, String version, String classifier, String extension) { + // Check for any processes that will be started because of this + EntityManager entityManager = entityManagerFactory.createEntityManager(); + + TypedQuery query = entityManager.createQuery("FROM Artifact WHERE groupId=:groupId AND artifactId=:artifactId AND version=:version AND extension=:extension", Artifact.class); + query.setParameter("groupId", groupId); + query.setParameter("artifactId", artifactId); + query.setParameter("version", version); + query.setParameter("extension", extension); + Artifact artifact; + try { + artifact = query.getSingleResult(); + log.info("Existing artifact: {}", artifact); + } catch (NoResultException e) { + artifact = new Artifact(groupId, artifactId, version, classifier, extension); + log.info("New artifact: {}", artifact); + entityManager.persist(artifact); + } + + for (Process process : entityManager.createQuery("FROM Process", Process.class).getResultList()) { + System.out.println("process.name = " + process.getName()); + + for (ProcessTrigger trigger : process.getProcessTriggers()) { + System.out.println("trigger.getMvel() = " + trigger.getMvel()); + boolean match = trigger.matches(artifact); + System.out.println("match = " + match); + + Map parameters = singletonMap("artifact", artifact); + session.startProcess(process.getJbpmProcessId(), parameters); + } + } + + /* + String type; + Object event; + long processInstanceId; + jbpm.signalEvent(type, event, processInstanceId); + */ + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/RestartAppWorkItemHandler.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/RestartAppWorkItemHandler.java new file mode 100644 index 0000000..0706cf1 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/RestartAppWorkItemHandler.java @@ -0,0 +1,24 @@ +package io.trygvis.calamus.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 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/calamus/engine/UpgradeAppWorkItemHandler.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/UpgradeAppWorkItemHandler.java new file mode 100644 index 0000000..32da945 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/UpgradeAppWorkItemHandler.java @@ -0,0 +1,24 @@ +package io.trygvis.calamus.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 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/calamus/engine/domain/AbstractEntity.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AbstractEntity.java new file mode 100644 index 0000000..655b1cc --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AbstractEntity.java @@ -0,0 +1,19 @@ +package io.trygvis.calamus.engine.domain; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.SequenceGenerator; + +@MappedSuperclass +public abstract class AbstractEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO, generator = "calamusSeq") + @SequenceGenerator(name = "calamusSeq", sequenceName = "calamus_seq") + private Long id; + + public Long getId() { + return id; + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppInstance.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppInstance.java new file mode 100644 index 0000000..aa2ea14 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppInstance.java @@ -0,0 +1,7 @@ +package io.trygvis.calamus.engine.domain; + +public class AppInstance { + private String name; + private String host; + private String path; +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppService.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppService.java new file mode 100644 index 0000000..da606a4 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/AppService.java @@ -0,0 +1,15 @@ +package io.trygvis.calamus.engine.domain; + +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"); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Artifact.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Artifact.java new file mode 100644 index 0000000..34631ab --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Artifact.java @@ -0,0 +1,89 @@ +package io.trygvis.calamus.engine.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import java.util.Optional; + +import static io.trygvis.calamus.engine.domain.Artifact.Level.UNTESTED; +import static java.util.Optional.ofNullable; + +@Entity +public class Artifact extends AbstractEntity { + @Column(length = 100, nullable = false) + private String groupId; + + @Column(length = 100, nullable = false) + private String artifactId; + + @Column(length = 100, nullable = false) + private String version; + + @Column(length = 100) + private String classifier; + + @Column(length = 100, nullable = false) + private String extension; + + @Column(nullable = false) + private Level level; + + @Column(length = 40) + private String gitHash; + + public enum Level { + UNTESTED + } + + protected Artifact() { + } + + public Artifact(String groupId, String artifactId, String version, String classifier, String extension) { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.classifier = classifier; + this.extension = extension; + this.level = UNTESTED; + } + + public String getGroupId() { + return groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public String getVersion() { + return version; + } + + public Optional getClassifier() { + return ofNullable(classifier); + } + + public String getExtension() { + return extension; + } + + public Level getLevel() { + return level; + } + + public String getGitHash() { + return gitHash; + } + + @Override + public String toString() { + return "Artifact{" + + "groupId='" + groupId + '\'' + + ", artifactId='" + artifactId + '\'' + + ", version='" + version + '\'' + + ", classifier='" + classifier + '\'' + + ", extension='" + extension + '\'' + + ", level='" + level + '\'' + + ", gitHash='" + gitHash + '\'' + + "} " + super.toString(); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Process.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Process.java new file mode 100644 index 0000000..c1f0b49 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/Process.java @@ -0,0 +1,40 @@ +package io.trygvis.calamus.engine.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.OneToMany; +import java.util.ArrayList; +import java.util.List; + +@Entity +public class Process extends AbstractEntity { + + @Column(length = 100, nullable = false) + private String name; + + @Column(length = 100, nullable = false) + private String jbpmProcessId; + + @OneToMany(mappedBy = "process") + private List processTriggers = new ArrayList<>(); + + public String getName() { + return name; + } + + public String getJbpmProcessId() { + return jbpmProcessId; + } + + public List getProcessTriggers() { + return processTriggers; + } + + @Override + public String toString() { + return "Process{" + + "name='" + name + '\'' + + ", jbpmProcessId='" + jbpmProcessId + '\'' + + "} " + super.toString(); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/ProcessTrigger.java b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/ProcessTrigger.java new file mode 100644 index 0000000..b26f6ca --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/calamus/engine/domain/ProcessTrigger.java @@ -0,0 +1,51 @@ +package io.trygvis.calamus.engine.domain; + +import org.mvel2.MVEL; +import org.mvel2.ParserContext; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ManyToOne; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +@Entity +public class ProcessTrigger extends AbstractEntity { + + @ManyToOne + private Process process; + + @Column(length = 1000) + private String mvel; + + transient Serializable expression; + + public Process getProcess() { + return process; + } + + public String getMvel() { + return mvel; + } + + // ----------------------------------------------------------------------- + // + // ----------------------------------------------------------------------- + + private Serializable getExpression() { + if (expression != null) { + return expression; + } + ParserContext ctx = new ParserContext(); + ctx.setStrongTyping(true); + ctx.addInput("artifact", Artifact.class); + return expression = MVEL.compileExpression(mvel, ctx); + } + + public boolean matches(Artifact artifact) { + Map vars = new HashMap<>(); + vars.put("artifact", artifact); + return MVEL.executeExpression(getExpression(), vars, Boolean.class); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/CalamusDbConfig.java b/calamus-engine/src/main/java/io/trygvis/engine/CalamusDbConfig.java deleted file mode 100644 index 39772c8..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/CalamusDbConfig.java +++ /dev/null @@ -1,129 +0,0 @@ -package io.trygvis.engine; - -import bitronix.tm.BitronixTransactionManager; -import bitronix.tm.TransactionManagerServices; -import bitronix.tm.resource.jdbc.PoolingDataSource; -import com.googlecode.flyway.core.Flyway; -import com.googlecode.flyway.core.api.MigrationInfo; -import com.googlecode.flyway.core.api.MigrationInfoService; -import org.jbpm.process.audit.JPAAuditLogService; -import org.kie.api.io.Resource; -import org.kie.api.io.ResourceType; -import org.kie.api.runtime.manager.RuntimeEnvironment; -import org.kie.internal.io.ResourceFactory; -import org.kie.spring.factorybeans.RuntimeEnvironmentFactoryBean; -import org.kie.spring.factorybeans.RuntimeManagerFactoryBean; -import org.slf4j.Logger; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; -import org.springframework.context.annotation.Lazy; -import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; -import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; -import org.springframework.transaction.jta.JtaTransactionManager; -import org.springframework.transaction.support.TransactionTemplate; - -import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import static java.lang.String.format; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * http://planet.jboss.org/post/jbpm_6_with_spring - */ -@Configuration -@EnableTransactionManagement -public class CalamusDbConfig { - private final Logger log = getLogger(getClass()); - - @Bean - public DataSource dataSource() { - 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(); - - return new TransactionAwareDataSourceProxy(new LazyConnectionDataSourceProxy(ds)); -// return ds; - } - - public static class DbMigrations { - } - - @Bean - public DbMigrations dbMigrations(DataSource dataSource) { - runFlyway(log, dataSource, "", "public"); - return new DbMigrations(); - } - - private static void runFlyway(Logger log, DataSource dataSource, String prefix, String schema) { - log.info("Running migrations for {}", schema); - - Flyway flyway = new Flyway(); - flyway.setDataSource(dataSource); - flyway.setSchemas(schema); - flyway.setLocations("db/" + prefix); - flyway.setInitOnMigrate(true); - MigrationInfoService info = flyway.info(); - log.info(format("%-15s %-10s %-19s %s", "Version", "State", "Installed on", "Description")); - for (MigrationInfo mi : info.all()) { - Date installedOn = mi.getInstalledOn(); - log.info(format("%-15s %-10s %-19s %s", - mi.getVersion(), - trimToEmpty(mi.getState().getDisplayName()), - installedOn != null ? new Date(installedOn.getTime()).toString() : "", - trimToEmpty(mi.getDescription()))); - } - flyway.migrate(); - } - - private static String trimToEmpty(String string) { - if (string == null) { - return ""; - } - - return string.trim(); - } - - @Bean(destroyMethod = "shutdown") - public BitronixTransactionManager bitronixTransactionManager() { -// bitronix.tm.Configuration configuration = TransactionManagerServices.getConfiguration(); - return TransactionManagerServices.getTransactionManager(); - } - - @Bean - public PlatformTransactionManager platformTransactionManager(BitronixTransactionManager transactionManager) { - return new JtaTransactionManager(transactionManager, transactionManager); - } - - @Bean - public TransactionTemplate transactionTemplate(PlatformTransactionManager platformTransactionManager) { - return new TransactionTemplate(platformTransactionManager); - } - - @Bean - @DependsOn("dbMigrations") - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { - LocalContainerEntityManagerFactoryBean x = new LocalContainerEntityManagerFactoryBean(); - x.setPersistenceUnitName("org.jbpm.persistence.jpa"); - return x; - } - - @Bean - public JPAAuditLogService jpaAuditLogService(EntityManagerFactory entityManagerFactory) { - return new JPAAuditLogService(entityManagerFactory); - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java b/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java deleted file mode 100644 index 5b0e8ec..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.trygvis.engine; - -import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.runtime.StatefulKnowledgeSession; -import org.slf4j.Logger; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.transaction.support.TransactionTemplate; - -import javax.persistence.EntityManagerFactory; - -import static org.slf4j.LoggerFactory.getLogger; - -public class CalamusJbpm { - private final Logger log = getLogger(getClass()); - - private final TransactionTemplate transactionTemplate; - - private final EntityManagerFactory emf; - - private final StatefulKnowledgeSession session; - - public static enum CalamusProcess { - DEPLOY("io.trygvis.bpm.Deploy"); - - private String name; - - CalamusProcess(String name) { - this.name = name; - } - } - - public CalamusJbpm() { - AnnotationConfigApplicationContext spring = new AnnotationConfigApplicationContext(CalamusDbConfig.class, CalamusJbpmConfig.class); - -// 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(); - -// RuntimeEnvironment runtimeEnvironment = spring.getBean(RuntimeEnvironment.class); -// -// KieBase kieBase = runtimeEnvironment.getKieBase(); - - transactionTemplate = spring.getBean(TransactionTemplate.class); - emf = spring.getBean(EntityManagerFactory.class); - session = null; -// 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 TransactionTemplate getTransactionTemplate() { - return transactionTemplate; - } - - public EntityManagerFactory getEntityManagerFactory() { - return emf; - } - - 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/CalamusJbpmConfig.java b/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpmConfig.java deleted file mode 100644 index 98ba550..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpmConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.trygvis.engine; - -import org.jbpm.process.audit.JPAAuditLogService; -import org.kie.api.io.Resource; -import org.kie.api.io.ResourceType; -import org.kie.api.runtime.manager.RuntimeEnvironment; -import org.kie.internal.io.ResourceFactory; -import org.kie.spring.factorybeans.RuntimeEnvironmentFactoryBean; -import org.kie.spring.factorybeans.RuntimeManagerFactoryBean; -import org.slf4j.Logger; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; -import org.springframework.transaction.PlatformTransactionManager; - -import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; -import java.util.HashMap; -import java.util.Map; - -import static org.slf4j.LoggerFactory.getLogger; - -/** - * http://planet.jboss.org/post/jbpm_6_with_spring - */ -@Configuration -public class CalamusJbpmConfig { - private final Logger log = getLogger(getClass()); - - @Bean - @Lazy - public RuntimeEnvironmentFactoryBean runtimeEnvironment(DataSource dataSource, CalamusDbConfig.DbMigrations dbMigrations, EntityManagerFactory entityManagerFactory, PlatformTransactionManager platformTransactionManager) { - System.out.println("CalamusConfig.runtimeEnvironmentFactoryBean"); - System.out.println("dataSource = " + dataSource); - System.out.println("dbMigrations = " + dbMigrations); - System.out.println("entityManagerFactory = " + entityManagerFactory); - System.out.println("platformTransactionManager = " + platformTransactionManager); - RuntimeEnvironmentFactoryBean x = new RuntimeEnvironmentFactoryBean(); - x.setType("DEFAULT"); - - Map assets = new HashMap<>(); - assets.put(ResourceFactory.newClassPathResource("/Deploy.bpmn2"), ResourceType.BPMN2); - x.setAssets(assets); - - x.setEntityManagerFactory(entityManagerFactory); - x.setTransactionManager(platformTransactionManager); - - return x; - } - -// @Bean -// public RuntimeManagerFactoryBean runtimeManagerFactoryBean(RuntimeEnvironment runtimeEnvironment) { -// RuntimeManagerFactoryBean x = new RuntimeManagerFactoryBean(); -// x.setIdentifier("spring-rm"); -// x.setRuntimeEnvironment(runtimeEnvironment); -// return x; -// } - - @Bean - public JPAAuditLogService jpaAuditLogService(EntityManagerFactory entityManagerFactory) { - return new JPAAuditLogService(entityManagerFactory); - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/JenkinsBuildResultMessageListener.java b/calamus-engine/src/main/java/io/trygvis/engine/JenkinsBuildResultMessageListener.java deleted file mode 100644 index 08b5e5b..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/JenkinsBuildResultMessageListener.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.trygvis.engine; - -import org.kie.internal.runtime.StatefulKnowledgeSession; -import org.slf4j.Logger; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.TextMessage; -import java.io.IOException; -import java.io.StringReader; -import java.util.Properties; - -import static java.lang.Integer.parseInt; -import static org.slf4j.LoggerFactory.getLogger; - -public class JenkinsBuildResultMessageListener implements MessageListener { - private final Logger log = getLogger(getClass()); - - private StatefulKnowledgeSession session; - - public JenkinsBuildResultMessageListener(StatefulKnowledgeSession session) { - this.session = session; - } - - @Override - public void onMessage(Message message) { - if (!(message instanceof TextMessage)) { - return; - } - - try { - TextMessage m = (TextMessage) message; - Properties p = new Properties(); - p.load(new StringReader(m.getText())); - - String jobName = p.getProperty("jobName"); - int buildNumber = parseInt(p.getProperty("buildNumber")); - String result = p.getProperty("result"); - - log.info("New build: jobName={}, buildNumber={}, result={}", jobName, buildNumber, result); - - /* - String type; - Object event; - long processInstanceId; - jbpm.signalEvent(type, event, processInstanceId); - */ - } catch (JMSException | IOException e) { - e.printStackTrace(); - } - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/Main.java b/calamus-engine/src/main/java/io/trygvis/engine/Main.java deleted file mode 100644 index c5916e0..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/Main.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.trygvis.engine; - -import org.kie.internal.runtime.StatefulKnowledgeSession; - -public class Main { - public static void main(String[] args) throws Exception { - - CalamusJbpm calamus = new CalamusJbpm(); - - String brokerUrl = "tcp://localhost:61616"; - - StatefulKnowledgeSession session = calamus.getSession(); - -// EntityManager entityManager = calamus.getEntityManagerFactory().createEntityManager(); -// EntityTransaction transaction = entityManager.getTransaction(); -// transaction.begin(); -// entityManager.createQuery("FROM Process"); -// transaction.commit(); - - try (MqClient buildResultClient = new MqClient(brokerUrl, "jenkins.build-result", new JenkinsBuildResultMessageListener(session)); - MqClient newDeployClient = new MqClient(brokerUrl, "nexus.new-artifact", new NexusNewArtifactMessageListener(calamus.getTransactionTemplate(), calamus.getEntityManagerFactory(), session))) { - - while (true) { - Thread.sleep(1000); - } - } - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java b/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java deleted file mode 100644 index 91eec37..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java +++ /dev/null @@ -1,50 +0,0 @@ -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.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.Session; -import javax.jms.TextMessage; -import java.io.IOException; -import java.io.StringReader; -import java.util.Properties; - -import static java.lang.Integer.parseInt; -import static javax.jms.Session.AUTO_ACKNOWLEDGE; - -public class MqClient implements AutoCloseable { - - private Connection connection; - - public MqClient(String brokerUrl, String queueName, MessageListener messageListener) { - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); - - try { - connection = connectionFactory.createConnection(); - connection.start(); - - Session session = connection.createSession(false, AUTO_ACKNOWLEDGE); - - Destination destination = session.createQueue(queueName); - - MessageConsumer consumer = session.createConsumer(destination); - consumer.setMessageListener(messageListener); - } 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/NexusNewArtifactMessageListener.java b/calamus-engine/src/main/java/io/trygvis/engine/NexusNewArtifactMessageListener.java deleted file mode 100644 index 0813c27..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/NexusNewArtifactMessageListener.java +++ /dev/null @@ -1,106 +0,0 @@ -package io.trygvis.engine; - -import io.trygvis.engine.domain.Artifact; -import io.trygvis.engine.domain.Process; -import io.trygvis.engine.domain.ProcessTrigger; -import org.kie.internal.runtime.StatefulKnowledgeSession; -import org.slf4j.Logger; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.TransactionCallbackWithoutResult; -import org.springframework.transaction.support.TransactionTemplate; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.TextMessage; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.NoResultException; -import javax.persistence.TypedQuery; -import java.io.IOException; -import java.io.StringReader; -import java.util.Properties; - -import static org.slf4j.LoggerFactory.getLogger; - -public class NexusNewArtifactMessageListener implements MessageListener { - private final Logger log = getLogger(getClass()); - - private final TransactionTemplate transactionTemplate; - private final EntityManagerFactory entityManagerFactory; - private final StatefulKnowledgeSession session; - - public NexusNewArtifactMessageListener(TransactionTemplate transactionTemplate, EntityManagerFactory entityManagerFactory, StatefulKnowledgeSession session) { - this.transactionTemplate = transactionTemplate; - this.entityManagerFactory = entityManagerFactory; - this.session = session; - } - - @Override - public void onMessage(Message message) { - if (!(message instanceof TextMessage)) { - return; - } - - try { - TextMessage m = (TextMessage) message; - Properties p = new Properties(); - p.load(new StringReader(m.getText())); - - String repository = p.getProperty("repository"); - String groupId = p.getProperty("groupId"); - String artifactId = p.getProperty("artifactId"); - String version = p.getProperty("version"); - String classifier = p.getProperty("classifier"); - String extension = p.getProperty("extension"); - - log.info("Artifact event: groupId={}, artifactId={}, version={}, classifier={}, extension={}", groupId, artifactId, version, classifier, extension); - - transactionTemplate.execute(new TransactionCallbackWithoutResult() { - @Override - protected void doInTransactionWithoutResult(TransactionStatus status) { - processMessage(groupId, artifactId, version, classifier, extension); - } - }); - } catch (JMSException | IOException e) { - e.printStackTrace(); - } - } - - private void processMessage(String groupId, String artifactId, String version, String classifier, String extension) { - // Check for any processes that will be started because of this - EntityManager entityManager = entityManagerFactory.createEntityManager(); - - TypedQuery query = entityManager.createQuery("FROM Artifact WHERE groupId=:groupId AND artifactId=:artifactId AND version=:version AND extension=:extension", Artifact.class); - query.setParameter("groupId", groupId); - query.setParameter("artifactId", artifactId); - query.setParameter("version", version); - query.setParameter("extension", extension); - Artifact artifact; - try { - artifact = query.getSingleResult(); - log.info("Existing artifact: {}", artifact); - } catch (NoResultException e) { - artifact = new Artifact(groupId, artifactId, version, classifier, extension); - log.info("New artifact: {}", artifact); - entityManager.persist(artifact); - } - - for (Process process : entityManager.createQuery("FROM Process", Process.class).getResultList()) { - System.out.println("process.name = " + process.getName()); - - for (ProcessTrigger trigger : process.getProcessTriggers()) { - System.out.println("trigger.getMvel() = " + trigger.getMvel()); - boolean match = trigger.matches(artifact); - System.out.println("match = " + match); - } - } - - /* - String type; - Object event; - long processInstanceId; - jbpm.signalEvent(type, event, processInstanceId); - */ - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java b/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java deleted file mode 100644 index 98733c7..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -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 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 deleted file mode 100644 index 6202d6b..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -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 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/domain/AbstractEntity.java b/calamus-engine/src/main/java/io/trygvis/engine/domain/AbstractEntity.java deleted file mode 100644 index e8b1faa..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/domain/AbstractEntity.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.trygvis.engine.domain; - -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; -import javax.persistence.SequenceGenerator; - -@MappedSuperclass -public abstract class AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.AUTO, generator = "calamusSeq") - @SequenceGenerator(name = "calamusSeq", sequenceName = "calamus_seq") - private Long id; - - public Long getId() { - return id; - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/domain/Artifact.java b/calamus-engine/src/main/java/io/trygvis/engine/domain/Artifact.java deleted file mode 100644 index 8e01d92..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/domain/Artifact.java +++ /dev/null @@ -1,89 +0,0 @@ -package io.trygvis.engine.domain; - -import javax.persistence.Column; -import javax.persistence.Entity; -import java.util.Optional; - -import static io.trygvis.engine.domain.Artifact.Level.UNTESTED; -import static java.util.Optional.ofNullable; - -@Entity -public class Artifact extends AbstractEntity { - @Column(length = 100, nullable = false) - private String groupId; - - @Column(length = 100, nullable = false) - private String artifactId; - - @Column(length = 100, nullable = false) - private String version; - - @Column(length = 100) - private String classifier; - - @Column(length = 100, nullable = false) - private String extension; - - @Column(nullable = false) - private Level level; - - @Column(length = 40) - private String gitHash; - - public enum Level { - UNTESTED - } - - protected Artifact() { - } - - public Artifact(String groupId, String artifactId, String version, String classifier, String extension) { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.classifier = classifier; - this.extension = extension; - this.level = UNTESTED; - } - - public String getGroupId() { - return groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public String getVersion() { - return version; - } - - public Optional getClassifier() { - return ofNullable(classifier); - } - - public String getExtension() { - return extension; - } - - public Level getLevel() { - return level; - } - - public String getGitHash() { - return gitHash; - } - - @Override - public String toString() { - return "Artifact{" + - "groupId='" + groupId + '\'' + - ", artifactId='" + artifactId + '\'' + - ", version='" + version + '\'' + - ", classifier='" + classifier + '\'' + - ", extension='" + extension + '\'' + - ", level='" + level + '\'' + - ", gitHash='" + gitHash + '\'' + - "} " + super.toString(); - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/domain/Process.java b/calamus-engine/src/main/java/io/trygvis/engine/domain/Process.java deleted file mode 100644 index ccd96cf..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/domain/Process.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.trygvis.engine.domain; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.OneToMany; -import java.util.ArrayList; -import java.util.List; - -@Entity -public class Process extends AbstractEntity { - - @Column(length = 100, nullable = false) - private String name; - - @OneToMany(mappedBy = "process") - private List processTriggers = new ArrayList<>(); - - public String getName() { - return name; - } - - public List getProcessTriggers() { - return processTriggers; - } -} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/domain/ProcessTrigger.java b/calamus-engine/src/main/java/io/trygvis/engine/domain/ProcessTrigger.java deleted file mode 100644 index 00b1603..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/domain/ProcessTrigger.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.trygvis.engine.domain; - -import org.mvel2.MVEL; -import org.mvel2.ParserContext; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.ManyToOne; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -@Entity -public class ProcessTrigger extends AbstractEntity { - - @ManyToOne - private Process process; - - @Column(length = 1000) - private String mvel; - - transient Serializable expression; - - public String getMvel() { - return mvel; - } - - // ----------------------------------------------------------------------- - // - // ----------------------------------------------------------------------- - - private Serializable getExpression() { - if (expression != null) { - return expression; - } - ParserContext ctx = new ParserContext(); - ctx.setStrongTyping(true); - ctx.addInput("artifact", Artifact.class); - return expression = MVEL.compileExpression(mvel, ctx); - } - - public boolean matches(Artifact artifact) { - Map vars = new HashMap<>(); - vars.put("artifact", artifact); - return MVEL.executeExpression(getExpression(), vars, Boolean.class); - } -} 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 deleted file mode 100644 index 0badb8c..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 3ccde2b..0000000 --- a/calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java +++ /dev/null @@ -1,15 +0,0 @@ -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"); - } -} diff --git a/calamus-engine/src/main/resources/Deploy.bpmn2 b/calamus-engine/src/main/resources/Deploy.bpmn2 index 2e29859..14fa1fb 100644 --- a/calamus-engine/src/main/resources/Deploy.bpmn2 +++ b/calamus-engine/src/main/resources/Deploy.bpmn2 @@ -1,11 +1,11 @@ - - + + - + AppInstance @@ -16,18 +16,18 @@ AppInstance - + asd - - + + SequenceFlow_1 - + SequenceFlow_1 SequenceFlow_3 @@ -47,7 +47,7 @@ _DataInput_19 - + SequenceFlow_3 SequenceFlow_4 @@ -67,7 +67,7 @@ _DataInput_21 - + SequenceFlow_4 SequenceFlow_5 @@ -81,13 +81,13 @@ - + SequenceFlow_5 - + diff --git a/calamus-engine/src/main/resources/META-INF/persistence.xml b/calamus-engine/src/main/resources/META-INF/persistence.xml index 0150ad9..1c28491 100644 --- a/calamus-engine/src/main/resources/META-INF/persistence.xml +++ b/calamus-engine/src/main/resources/META-INF/persistence.xml @@ -7,6 +7,9 @@ org.hibernate.ejb.HibernatePersistence jdbc/jbpm-ds META-INF/JBPMorm.xml + org.drools.persistence.info.SessionInfo org.drools.persistence.info.WorkItemInfo org.jbpm.persistence.processinstance.ProcessInstanceInfo @@ -16,12 +19,16 @@ org.jbpm.process.audit.NodeInstanceLog org.jbpm.process.audit.VariableInstanceLog org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo - io.trygvis.engine.domain.Artifact + + io.trygvis.calamus.engine.domain.Artifact - + diff --git a/calamus-engine/src/main/resources/db/public/V001_000__jbpm.sql b/calamus-engine/src/main/resources/db/public/V001_000__jbpm.sql index e13e6fb..981074a 100644 --- a/calamus-engine/src/main/resources/db/public/V001_000__jbpm.sql +++ b/calamus-engine/src/main/resources/db/public/V001_000__jbpm.sql @@ -1,633 +1,402 @@ -CREATE TABLE Attachment ( - AttachmentId INT8 NOT NULL, - accessType INT4, - attachedAt TIMESTAMP, - attachmentContentId INT8 NOT NULL, - contentType VARCHAR(255), - name VARCHAR(255), - attachment_size INT4, - attachedBy_id VARCHAR(255), - TaskData_Attachments_Id INT8, - PRIMARY KEY (AttachmentId) -); - -CREATE TABLE BAMTaskSummary ( - BAMTaskId INT8 NOT NULL, - createdDate TIMESTAMP, - duration INT8, - endDate TIMESTAMP, - processInstanceId INT8 NOT NULL, - startDate TIMESTAMP, - status VARCHAR(255), - taskId INT8 NOT NULL, - taskName VARCHAR(255), - userId VARCHAR(255), - PRIMARY KEY (BAMTaskId) -); - -CREATE TABLE BooleanExpression ( - id INT8 NOT NULL, - expression TEXT, - type VARCHAR(255), - Escalation_Constraints_Id INT8, - PRIMARY KEY (id) -); - -CREATE TABLE Content ( - id INT8 NOT NULL, - content OID, --- content BYTEA, - PRIMARY KEY (id) -); - -CREATE TABLE ContextMappingInfo ( - mappingId INT8 NOT NULL, - CONTEXT_ID VARCHAR(255) NOT NULL, - KSESSION_ID INT4 NOT NULL, - OPTLOCK INT4, - PRIMARY KEY (mappingId) -); - -CREATE TABLE CorrelationKeyInfo ( - keyId INT8 NOT NULL, - name VARCHAR(255), - processInstanceId INT8 NOT NULL, - OPTLOCK INT4, - PRIMARY KEY (keyId) -); - -CREATE TABLE CorrelationPropertyInfo ( - propertyId INT8 NOT NULL, - name VARCHAR(255), - value VARCHAR(255), - OPTLOCK INT4, - correlationKey_keyId INT8, - PRIMARY KEY (propertyId) -); - -CREATE TABLE Deadline ( - id INT8 NOT NULL, - deadline_date TIMESTAMP, - escalated INT2, - Deadlines_StartDeadLine_Id INT8, - Deadlines_EndDeadLine_Id INT8, - PRIMARY KEY (id) -); - -CREATE TABLE Delegation_delegates ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); - -CREATE TABLE ErrorInfo ( - id INT8 NOT NULL, - message VARCHAR(255), - stacktrace VARCHAR(5000), - timestamp TIMESTAMP, - REQUEST_ID INT8 NOT NULL, - PRIMARY KEY (id) -); - -CREATE TABLE Escalation ( - id INT8 NOT NULL, - name VARCHAR(255), - Deadline_Escalation_Id INT8, - PRIMARY KEY (id) -); - -CREATE TABLE EventTypes ( - InstanceId INT8 NOT NULL, - eventTypes VARCHAR(255) -); - -CREATE TABLE I18NText ( - I18NTextId INT8 NOT NULL, - language VARCHAR(255), - shortText VARCHAR(255), - text TEXT, - Task_Subjects_Id INT8, - Task_Names_Id INT8, - Task_Descriptions_Id INT8, - Reassignment_Documentation_Id INT8, - Notification_Subjects_Id INT8, - Notification_Names_Id INT8, - Notification_Documentation_Id INT8, - Notification_Descriptions_Id INT8, - Deadline_Documentation_Id INT8, - PRIMARY KEY (I18NTextId) -); - -CREATE TABLE NodeInstanceLog ( - id INT8 NOT NULL, - connection VARCHAR(255), - log_date TIMESTAMP, - externalId VARCHAR(255), - nodeId VARCHAR(255), - nodeInstanceId VARCHAR(255), - nodeName VARCHAR(255), - nodeType VARCHAR(255), - processId VARCHAR(255), - processInstanceId INT8 NOT NULL, - type INT4 NOT NULL, - workItemId INT8, - PRIMARY KEY (id) -); - -CREATE TABLE Notification ( - DTYPE VARCHAR(31) NOT NULL, - NotificationId INT8 NOT NULL, - priority INT4 NOT NULL, - Escalation_Notifications_Id INT8, - PRIMARY KEY (NotificationId) -); - -CREATE TABLE Notification_BAs ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); - -CREATE TABLE Notification_Recipients ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); - -CREATE TABLE Notification_email_header ( - Notification_NotificationId INT8 NOT NULL, - emailHeaders_id INT8 NOT NULL, - mapkey VARCHAR(255) NOT NULL, - PRIMARY KEY (Notification_NotificationId, mapkey) -); - -CREATE TABLE OrganizationalEntity ( - DTYPE VARCHAR(31) NOT NULL, - id VARCHAR(255) NOT NULL, - PRIMARY KEY (id) -); - -CREATE TABLE PeopleAssignments_BAs ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); - -CREATE TABLE PeopleAssignments_ExclOwners ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); - -CREATE TABLE PeopleAssignments_PotOwners ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); - -CREATE TABLE PeopleAssignments_Recipients ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); +-- +-- Name: artifact; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE artifact ( + id bigint NOT NULL, + artifact_id character varying(100) NOT NULL, + classifier character varying(100), + extension character varying(100) NOT NULL, + git_hash character varying(40), + group_id character varying(100) NOT NULL, + level integer NOT NULL, + version character varying(100) NOT NULL +); + +-- +-- Name: calamus_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE calamus_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- Name: context_mapping_info; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE context_mapping_info ( + mapping_id bigint NOT NULL, + context_id character varying(255) NOT NULL, + ksession_id integer NOT NULL, + owner_id character varying(255), + optlock integer +); + +-- +-- Name: context_mapping_info_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE context_mapping_info_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- Name: correlation_key_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE correlation_key_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- Name: correlation_key_info; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE correlation_key_info ( + key_id bigint NOT NULL, + name character varying(255), + process_instance_id bigint NOT NULL, + optlock integer +); + +-- +-- Name: correlation_prop_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE correlation_prop_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- Name: correlation_property_info; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE correlation_property_info ( + property_id bigint NOT NULL, + name character varying(255), + value character varying(255), + optlock integer, + correlation_key bigint +); + +-- +-- Name: event_types; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE event_types ( + instance_id bigint NOT NULL, + element character varying(255) +); + +-- +-- Name: node_inst_log_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE node_inst_log_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- Name: node_instance_log; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE node_instance_log ( + id bigint NOT NULL, + connection character varying(255), + log_date timestamp without time zone, + external_id character varying(255), + node_id character varying(255), + node_instance_id character varying(255), + node_name character varying(255), + node_type character varying(255), + process_id character varying(255), + process_instance_id bigint NOT NULL, + type integer NOT NULL, + work_item_id bigint +); + +-- +-- Name: proc_inst_log_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE proc_inst_log_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- Name: process; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE process ( + id bigint NOT NULL, + jbpm_process_id character varying(100) NOT NULL, + name character varying(100) NOT NULL +); + +-- +-- Name: process_instance_info; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE process_instance_info ( + instance_id bigint NOT NULL, + last_modification_date timestamp without time zone, + last_read_date timestamp without time zone, + process_id character varying(255), + process_instance_byte_array oid, + start_date timestamp without time zone, + state integer NOT NULL, + optlock integer +); + +-- +-- Name: process_instance_info_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE process_instance_info_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- Name: process_instance_log; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE process_instance_log ( + id bigint NOT NULL, + duration bigint, + end_date timestamp without time zone, + external_id character varying(255), + user_identity character varying(255), + outcome character varying(255), + parent_process_instance_id bigint, + process_id character varying(255), + process_instance_id bigint NOT NULL, + process_name character varying(255), + process_version character varying(255), + start_date timestamp without time zone, + status integer +); + +-- +-- Name: process_trigger; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE process_trigger ( + id bigint NOT NULL, + mvel character varying(1000), + process bigint +); + +-- +-- Name: session_info; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- + +CREATE TABLE session_info ( + id integer NOT NULL, + last_modification_date timestamp without time zone, + rules_byte_array oid, + start_date timestamp without time zone, + optlock integer +); + +-- +-- Name: sessioninfo_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- + +CREATE SEQUENCE sessioninfo_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -CREATE TABLE PeopleAssignments_Stakeholders ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); +-- +-- Name: var_inst_log_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- -CREATE TABLE ProcessInstanceInfo ( - InstanceId INT8 NOT NULL, - lastModificationDate TIMESTAMP, - lastReadDate TIMESTAMP, - processId VARCHAR(255), - processInstanceByteArray OID, --- processInstanceByteArray BYTEA, - startDate TIMESTAMP, - state INT4 NOT NULL, - OPTLOCK INT4, - PRIMARY KEY (InstanceId) -); +CREATE SEQUENCE var_inst_log_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -CREATE TABLE ProcessInstanceLog ( - id INT8 NOT NULL, - duration INT8, - end_date TIMESTAMP, - externalId VARCHAR(255), - user_identity VARCHAR(255), - outcome VARCHAR(255), - parentProcessInstanceId INT8, - processId VARCHAR(255), - processInstanceId INT8 NOT NULL, - processName VARCHAR(255), - processVersion VARCHAR(255), - start_date TIMESTAMP, - status INT4, - PRIMARY KEY (id) -); +-- +-- Name: variable_instance_log; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE TABLE Reassignment ( - id INT8 NOT NULL, - Escalation_Reassignments_Id INT8, - PRIMARY KEY (id) +CREATE TABLE variable_instance_log ( + id bigint NOT NULL, + log_date timestamp without time zone, + external_id character varying(255), + old_value character varying(255), + process_id character varying(255), + process_instance_id bigint NOT NULL, + value character varying(255), + variable_id character varying(255), + variable_instance_id character varying(255) ); -CREATE TABLE Reassignment_potentialOwners ( - task_id INT8 NOT NULL, - entity_id VARCHAR(255) NOT NULL -); +-- +-- Name: work_item_info; Type: TABLE; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE TABLE RequestInfo ( - id INT8 NOT NULL, - commandName VARCHAR(255), - deploymentId VARCHAR(255), - executions INT4 NOT NULL, - businessKey VARCHAR(255), - message VARCHAR(255), - requestData OID, --- requestData BYTEA, - responseData OID, --- responseData BYTEA, - retries INT4 NOT NULL, - status VARCHAR(255), - timestamp TIMESTAMP, - PRIMARY KEY (id) +CREATE TABLE work_item_info ( + work_item_id bigint NOT NULL, + creation_date timestamp without time zone, + name character varying(255), + process_instance_id bigint NOT NULL, + state bigint NOT NULL, + optlock integer, + work_item_byte_array oid ); -CREATE TABLE SessionInfo ( - id INT4 NOT NULL, - lastModificationDate TIMESTAMP, - rulesByteArray OID, --- rulesByteArray BYTEA, - startDate TIMESTAMP, - OPTLOCK INT4, - PRIMARY KEY (id) -); +-- +-- Name: workiteminfo_id_seq; Type: SEQUENCE; Schema: public; Owner: jbpm +-- -CREATE TABLE Task ( - TaskId INT8 NOT NULL, - archived INT2, - allowedToDelegate VARCHAR(255), - formName VARCHAR(255), - priority INT4 NOT NULL, - subTaskStrategy VARCHAR(255), - activationTime TIMESTAMP, - createdOn TIMESTAMP, - deploymentId VARCHAR(255), - documentAccessType INT4, - documentContentId INT8 NOT NULL, - documentType VARCHAR(255), - expirationTime TIMESTAMP, - faultAccessType INT4, - faultContentId INT8 NOT NULL, - faultName VARCHAR(255), - faultType VARCHAR(255), - outputAccessType INT4, - outputContentId INT8 NOT NULL, - outputType VARCHAR(255), - parentId INT8 NOT NULL, - previousStatus INT4, - processId VARCHAR(255), - processInstanceId INT8 NOT NULL, - processSessionId INT4 NOT NULL, - skipable BOOLEAN NOT NULL, - status VARCHAR(255), - workItemId INT8 NOT NULL, - taskType VARCHAR(255), - OPTLOCK INT4, - taskInitiator_id VARCHAR(255), - actualOwner_id VARCHAR(255), - createdBy_id VARCHAR(255), - PRIMARY KEY (TaskId) -); +CREATE SEQUENCE workiteminfo_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -CREATE TABLE TaskDef ( - TaskDefId INT8 NOT NULL, - name VARCHAR(255), - priority INT4 NOT NULL, - PRIMARY KEY (TaskDefId) -); +-- +-- Name: artifact_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE TABLE TaskEvent ( - id INT8 NOT NULL, - logTime TIMESTAMP, - taskId INT8, - type VARCHAR(255), - userId VARCHAR(255), - PRIMARY KEY (id) -); +ALTER TABLE ONLY artifact + ADD CONSTRAINT artifact_pkey PRIMARY KEY (id); -CREATE TABLE VariableInstanceLog ( - id INT8 NOT NULL, - log_date TIMESTAMP, - externalId VARCHAR(255), - oldValue VARCHAR(255), - processId VARCHAR(255), - processInstanceId INT8 NOT NULL, - value VARCHAR(255), - variableId VARCHAR(255), - variableInstanceId VARCHAR(255), - PRIMARY KEY (id) -); - -CREATE TABLE WorkItemInfo ( - workItemId INT8 NOT NULL, - creationDate TIMESTAMP, - name VARCHAR(255), - processInstanceId INT8 NOT NULL, - state INT8 NOT NULL, - OPTLOCK INT4, - workItemByteArray OID, --- workItemByteArray BYTEA, - PRIMARY KEY (workItemId) -); - -CREATE TABLE email_header ( - id INT8 NOT NULL, - body TEXT, - fromAddress VARCHAR(255), - language VARCHAR(255), - replyToAddress VARCHAR(255), - subject VARCHAR(255), - PRIMARY KEY (id) -); - -CREATE TABLE task_comment ( - id INT8 NOT NULL, - addedAt TIMESTAMP, - text TEXT, - addedBy_id VARCHAR(255), - TaskData_Comments_Id INT8, - PRIMARY KEY (id) -); -ALTER TABLE Attachment -ADD CONSTRAINT FK1C93543D937BFB5 -FOREIGN KEY (attachedBy_id) -REFERENCES OrganizationalEntity; - -ALTER TABLE Attachment -ADD CONSTRAINT FK1C9354333CA892A -FOREIGN KEY (TaskData_Attachments_Id) -REFERENCES Task; - -ALTER TABLE BooleanExpression -ADD CONSTRAINT FKE3D208C06C97C90E -FOREIGN KEY (Escalation_Constraints_Id) -REFERENCES Escalation; - -ALTER TABLE CorrelationPropertyInfo -ADD CONSTRAINT FK761452A5D87156ED -FOREIGN KEY (correlationKey_keyId) -REFERENCES CorrelationKeyInfo; - -ALTER TABLE Deadline -ADD CONSTRAINT FK21DF3E78A9FE0EF4 -FOREIGN KEY (Deadlines_StartDeadLine_Id) -REFERENCES Task; - -ALTER TABLE Deadline -ADD CONSTRAINT FK21DF3E78695E4DDB -FOREIGN KEY (Deadlines_EndDeadLine_Id) -REFERENCES Task; - -ALTER TABLE Delegation_delegates -ADD CONSTRAINT FK47485D5772B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; - -ALTER TABLE Delegation_delegates -ADD CONSTRAINT FK47485D57786553A5 -FOREIGN KEY (task_id) -REFERENCES Task; - -ALTER TABLE ErrorInfo -ADD CONSTRAINT FK8B1186B6724A467 -FOREIGN KEY (REQUEST_ID) -REFERENCES RequestInfo; - -ALTER TABLE Escalation -ADD CONSTRAINT FK67B2C6B5D1E5CC1 -FOREIGN KEY (Deadline_Escalation_Id) -REFERENCES Deadline; - -ALTER TABLE EventTypes -ADD CONSTRAINT FKB0E5621F7665489A -FOREIGN KEY (InstanceId) -REFERENCES ProcessInstanceInfo; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686BF4ACCD69 -FOREIGN KEY (Task_Subjects_Id) -REFERENCES Task; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686B424B187C -FOREIGN KEY (Task_Names_Id) -REFERENCES Task; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686BAB648139 -FOREIGN KEY (Task_Descriptions_Id) -REFERENCES Task; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686BB340A2AA -FOREIGN KEY (Reassignment_Documentation_Id) -REFERENCES Reassignment; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686BF0CDED35 -FOREIGN KEY (Notification_Subjects_Id) -REFERENCES Notification; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686BCC03ED3C -FOREIGN KEY (Notification_Names_Id) -REFERENCES Notification; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686B77C1C08A -FOREIGN KEY (Notification_Documentation_Id) -REFERENCES Notification; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686B18DDFE05 -FOREIGN KEY (Notification_Descriptions_Id) -REFERENCES Notification; - -ALTER TABLE I18NText -ADD CONSTRAINT FK2349686B78AF072A -FOREIGN KEY (Deadline_Documentation_Id) -REFERENCES Deadline; - -ALTER TABLE Notification -ADD CONSTRAINT FK2D45DD0BC0C0F29C -FOREIGN KEY (Escalation_Notifications_Id) -REFERENCES Escalation; - -ALTER TABLE Notification_BAs -ADD CONSTRAINT FK2DD68EE072B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; - -ALTER TABLE Notification_BAs -ADD CONSTRAINT FK2DD68EE093F2090B -FOREIGN KEY (task_id) -REFERENCES Notification; - -ALTER TABLE Notification_Recipients -ADD CONSTRAINT FK98FD214E72B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; - -ALTER TABLE Notification_Recipients -ADD CONSTRAINT FK98FD214E93F2090B -FOREIGN KEY (task_id) -REFERENCES Notification; - -ALTER TABLE Notification_email_header -ADD CONSTRAINT UK_F30FE3446CEA0510 UNIQUE (emailHeaders_id); - -ALTER TABLE Notification_email_header -ADD CONSTRAINT FKF30FE3448BED1339 -FOREIGN KEY (emailHeaders_id) -REFERENCES email_header; - -ALTER TABLE Notification_email_header -ADD CONSTRAINT FKF30FE344DD2D7416 -FOREIGN KEY (Notification_NotificationId) -REFERENCES Notification; - -ALTER TABLE PeopleAssignments_BAs -ADD CONSTRAINT FK9D8CF4EC72B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; - -ALTER TABLE PeopleAssignments_BAs -ADD CONSTRAINT FK9D8CF4EC786553A5 -FOREIGN KEY (task_id) -REFERENCES Task; - -ALTER TABLE PeopleAssignments_ExclOwners -ADD CONSTRAINT FKC77B97E472B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; - -ALTER TABLE PeopleAssignments_ExclOwners -ADD CONSTRAINT FKC77B97E4786553A5 -FOREIGN KEY (task_id) -REFERENCES Task; +-- +-- Name: context_mapping_info_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -ALTER TABLE PeopleAssignments_PotOwners -ADD CONSTRAINT FK1EE418D72B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; +ALTER TABLE ONLY context_mapping_info + ADD CONSTRAINT context_mapping_info_pkey PRIMARY KEY (mapping_id); -ALTER TABLE PeopleAssignments_PotOwners -ADD CONSTRAINT FK1EE418D786553A5 -FOREIGN KEY (task_id) -REFERENCES Task; -ALTER TABLE PeopleAssignments_Recipients -ADD CONSTRAINT FKC6F615C272B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; +-- +-- Name: correlation_key_info_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -ALTER TABLE PeopleAssignments_Recipients -ADD CONSTRAINT FKC6F615C2786553A5 -FOREIGN KEY (task_id) -REFERENCES Task; +ALTER TABLE ONLY correlation_key_info + ADD CONSTRAINT correlation_key_info_pkey PRIMARY KEY (key_id); -ALTER TABLE PeopleAssignments_Stakeholders -ADD CONSTRAINT FK482F79D572B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; -ALTER TABLE PeopleAssignments_Stakeholders -ADD CONSTRAINT FK482F79D5786553A5 -FOREIGN KEY (task_id) -REFERENCES Task; +-- +-- Name: correlation_property_info_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -ALTER TABLE Reassignment -ADD CONSTRAINT FK724D056062A1E871 -FOREIGN KEY (Escalation_Reassignments_Id) -REFERENCES Escalation; +ALTER TABLE ONLY correlation_property_info + ADD CONSTRAINT correlation_property_info_pkey PRIMARY KEY (property_id); -ALTER TABLE Reassignment_potentialOwners -ADD CONSTRAINT FK90B59CFF72B3A123 -FOREIGN KEY (entity_id) -REFERENCES OrganizationalEntity; -ALTER TABLE Reassignment_potentialOwners -ADD CONSTRAINT FK90B59CFF35D2FEE0 -FOREIGN KEY (task_id) -REFERENCES Reassignment; +-- +-- Name: node_instance_log_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -ALTER TABLE Task -ADD CONSTRAINT FK27A9A53C55C806 -FOREIGN KEY (taskInitiator_id) -REFERENCES OrganizationalEntity; +ALTER TABLE ONLY node_instance_log + ADD CONSTRAINT node_instance_log_pkey PRIMARY KEY (id); -ALTER TABLE Task -ADD CONSTRAINT FK27A9A5B723BE8B -FOREIGN KEY (actualOwner_id) -REFERENCES OrganizationalEntity; -ALTER TABLE Task -ADD CONSTRAINT FK27A9A55427E8F1 -FOREIGN KEY (createdBy_id) -REFERENCES OrganizationalEntity; +-- +-- Name: process_instance_info_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -ALTER TABLE task_comment -ADD CONSTRAINT FK61F475A57A3215D9 -FOREIGN KEY (addedBy_id) -REFERENCES OrganizationalEntity; +ALTER TABLE ONLY process_instance_info + ADD CONSTRAINT process_instance_info_pkey PRIMARY KEY (instance_id); -ALTER TABLE task_comment -ADD CONSTRAINT FK61F475A5F510CB46 -FOREIGN KEY (TaskData_Comments_Id) -REFERENCES Task; -CREATE SEQUENCE ATTACHMENT_ID_SEQ; +-- +-- Name: process_instance_log_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE SEQUENCE BAM_TASK_ID_SEQ; +ALTER TABLE ONLY process_instance_log + ADD CONSTRAINT process_instance_log_pkey PRIMARY KEY (id); -CREATE SEQUENCE BOOLEANEXPR_ID_SEQ; -CREATE SEQUENCE COMMENT_ID_SEQ; +-- +-- Name: process_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE SEQUENCE CONTENT_ID_SEQ; +ALTER TABLE ONLY process + ADD CONSTRAINT process_pkey PRIMARY KEY (id); -CREATE SEQUENCE CONTEXT_MAPPING_INFO_ID_SEQ; -CREATE SEQUENCE CORRELATION_KEY_ID_SEQ; +-- +-- Name: process_trigger_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE SEQUENCE CORRELATION_PROP_ID_SEQ; +ALTER TABLE ONLY process_trigger + ADD CONSTRAINT process_trigger_pkey PRIMARY KEY (id); -CREATE SEQUENCE DEADLINE_ID_SEQ; +-- +-- Name: session_info_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE SEQUENCE EMAILNOTIFHEAD_ID_SEQ; +ALTER TABLE ONLY session_info + ADD CONSTRAINT session_info_pkey PRIMARY KEY (id); -CREATE SEQUENCE ERROR_INFO_ID_SEQ; -CREATE SEQUENCE ESCALATION_ID_SEQ; +-- +-- Name: variable_instance_log_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE SEQUENCE I18NTEXT_ID_SEQ; +ALTER TABLE ONLY variable_instance_log + ADD CONSTRAINT variable_instance_log_pkey PRIMARY KEY (id); -CREATE SEQUENCE NODE_INST_LOG_ID_SEQ; -CREATE SEQUENCE NOTIFICATION_ID_SEQ; +-- +-- Name: work_item_info_pkey; Type: CONSTRAINT; Schema: public; Owner: jbpm; Tablespace: +-- -CREATE SEQUENCE PROCESS_INSTANCE_INFO_ID_SEQ; +ALTER TABLE ONLY work_item_info + ADD CONSTRAINT work_item_info_pkey PRIMARY KEY (work_item_id); -CREATE SEQUENCE PROC_INST_LOG_ID_SEQ; -CREATE SEQUENCE REASSIGNMENT_ID_SEQ; +-- +-- Name: fk_8p498uslw0dnuqbms6ifwcw0a; Type: FK CONSTRAINT; Schema: public; Owner: jbpm +-- -CREATE SEQUENCE REQUEST_INFO_ID_SEQ; +ALTER TABLE ONLY correlation_property_info + ADD CONSTRAINT fk_8p498uslw0dnuqbms6ifwcw0a FOREIGN KEY (correlation_key) REFERENCES correlation_key_info(key_id); -CREATE SEQUENCE SESSIONINFO_ID_SEQ; -CREATE SEQUENCE TASK_DEF_ID_SEQ; +-- +-- Name: fk_mofjkjce7y19e7uee8xc0ua6; Type: FK CONSTRAINT; Schema: public; Owner: jbpm +-- -CREATE SEQUENCE TASK_EVENT_ID_SEQ; +ALTER TABLE ONLY process_trigger + ADD CONSTRAINT fk_mofjkjce7y19e7uee8xc0ua6 FOREIGN KEY (process) REFERENCES process(id); -CREATE SEQUENCE TASK_ID_SEQ; -CREATE SEQUENCE VAR_INST_LOG_ID_SEQ; +-- +-- Name: fk_ryp64oh29vgawmqgodvnvuh2o; Type: FK CONSTRAINT; Schema: public; Owner: jbpm +-- -CREATE SEQUENCE WORKITEMINFO_ID_SEQ; +ALTER TABLE ONLY event_types + ADD CONSTRAINT fk_ryp64oh29vgawmqgodvnvuh2o FOREIGN KEY (instance_id) REFERENCES process_instance_info(instance_id); diff --git a/calamus-engine/src/main/resources/db/public/V001_001__baseline.sql b/calamus-engine/src/main/resources/db/public/V001_001__baseline.sql deleted file mode 100644 index 5270d2c..0000000 --- a/calamus-engine/src/main/resources/db/public/V001_001__baseline.sql +++ /dev/null @@ -1,41 +0,0 @@ -DROP SEQUENCE IF EXISTS calamus_seq; -CREATE SEQUENCE calamus_seq; - -DROP TABLE IF EXISTS artifact; -CREATE TABLE artifact ( - id BIGINT NOT NULL PRIMARY KEY, - group_id VARCHAR(100) NOT NULL, - artifact_id VARCHAR(100) NOT NULL, - version VARCHAR(100) NOT NULL, - classifier VARCHAR(100), - extension VARCHAR(100) NOT NULL, - level VARCHAR(100) NOT NULL, - git_hash CHAR(40) -); - -DROP TABLE IF EXISTS process; -CREATE TABLE process ( - id BIGINT NOT NULL PRIMARY KEY, - name VARCHAR(100) NOT NULL, - process_id VARCHAR(100) NOT NULL -); - -DROP TABLE IF EXISTS process_trigger; -CREATE TABLE process_trigger ( - id BIGINT NOT NULL PRIMARY KEY, - process BIGINT NOT NULL REFERENCES process, - mvel VARCHAR(1000) NOT NULL -); - -INSERT INTO process (id, name, process_id) -VALUES ((SELECT - nextval('calamus_seq')), 'Deploy', 'io.trygvis.calamus.Deploy'); - -INSERT INTO process_trigger (id, process, mvel) -VALUES ((SELECT - nextval('calamus_seq')), - (SELECT - id - FROM process - WHERE process_id = 'io.trygvis.calamus.Deploy'), - 'artifact.groupId == "demo"'); diff --git a/calamus-engine/src/main/resources/logback.xml b/calamus-engine/src/main/resources/logback.xml index 46502f3..328f104 100644 --- a/calamus-engine/src/main/resources/logback.xml +++ b/calamus-engine/src/main/resources/logback.xml @@ -6,10 +6,13 @@ + + + - - + + diff --git a/calamus-engine/src/test/java/io/trygvis/calamus/engine/MyTest.java b/calamus-engine/src/test/java/io/trygvis/calamus/engine/MyTest.java new file mode 100644 index 0000000..f6cb4c5 --- /dev/null +++ b/calamus-engine/src/test/java/io/trygvis/calamus/engine/MyTest.java @@ -0,0 +1,73 @@ +package io.trygvis.calamus.engine; + +import org.junit.Test; +import org.kie.api.runtime.KieSession; +import org.kie.internal.runtime.StatefulKnowledgeSession; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class MyTest { + + StatefulKnowledgeSession session; + +// @Before +// public void setUp() throws Exception { +// 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(); +// +// // create a new knowledge session that uses JPA to store the runtime state +// 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()); +// } + + @Test + public void testDeploy() { +/* + ProcessInstance processInstance = session.startProcess("io.trygvis.bpm.Deploy"); + +// assertProcessInstanceCompleted(processInstance.getId(), session); + + System.out.println("processInstance = " + processInstance); + System.out.println("processInstance.getProcessId() = " + processInstance.getProcessId()); + System.out.println("processInstance.getState() = " + processInstance.getState()); + + Process process = session.getKieBase().getProcess(processInstance.getProcessId()); + System.out.println("process = " + process); + System.out.println("process.getType() = " + process.getType()); +*/ + } + + public static void assertProcessInstanceCompleted(long processInstanceId, KieSession ksession) { + assertNull(ksession.getProcessInstance(processInstanceId)); + } + + public static void assertProcessInstanceAborted(long processInstanceId, KieSession ksession) { + assertNull(ksession.getProcessInstance(processInstanceId)); + } + + public static void assertProcessInstanceActive(long processInstanceId, KieSession ksession) { + assertNotNull(ksession.getProcessInstance(processInstanceId)); + } +} diff --git a/calamus-engine/src/test/java/io/trygvis/engine/MyTest.java b/calamus-engine/src/test/java/io/trygvis/engine/MyTest.java deleted file mode 100644 index 8c170ea..0000000 --- a/calamus-engine/src/test/java/io/trygvis/engine/MyTest.java +++ /dev/null @@ -1,90 +0,0 @@ -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.junit.Before; -import org.junit.Test; -import org.kie.api.KieBase; -import org.kie.api.definition.process.Process; -import org.kie.api.runtime.Environment; -import org.kie.api.runtime.EnvironmentName; -import org.kie.api.runtime.KieSession; -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; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -public class MyTest { - - StatefulKnowledgeSession session; - -// @Before -// public void setUp() throws Exception { -// 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(); -// -// // create a new knowledge session that uses JPA to store the runtime state -// 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()); -// } - - @Test - public void testDeploy() { -/* - ProcessInstance processInstance = session.startProcess("io.trygvis.bpm.Deploy"); - -// assertProcessInstanceCompleted(processInstance.getId(), session); - - System.out.println("processInstance = " + processInstance); - System.out.println("processInstance.getProcessId() = " + processInstance.getProcessId()); - System.out.println("processInstance.getState() = " + processInstance.getState()); - - Process process = session.getKieBase().getProcess(processInstance.getProcessId()); - System.out.println("process = " + process); - System.out.println("process.getType() = " + process.getType()); -*/ - } - - public static void assertProcessInstanceCompleted(long processInstanceId, KieSession ksession) { - assertNull(ksession.getProcessInstance(processInstanceId)); - } - - public static void assertProcessInstanceAborted(long processInstanceId, KieSession ksession) { - assertNull(ksession.getProcessInstance(processInstanceId)); - } - - public static void assertProcessInstanceActive(long processInstanceId, KieSession ksession) { - assertNotNull(ksession.getProcessInstance(processInstanceId)); - } -} -- cgit v1.2.3