use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class TimerMigrationManagerTest method testMigrateEventSubprocessTimerProcessInstance.
@Test(timeout = 10000)
public void testMigrateEventSubprocessTimerProcessInstance() throws Exception {
NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("Script Task 1 V2", 1);
createRuntimeManagers("migration/v1/BPMN2-EventSubprocessTimer-v1.bpmn2", "migration/v2/BPMN2-EventSubprocessTimer-v2.bpmn2", countdownListener);
assertNotNull(managerV1);
assertNotNull(managerV2);
RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance pi1 = ksession.startProcess(EVENT_SUBPROCESS_TIMER_ID_V1);
assertNotNull(pi1);
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
JPAAuditLogService auditService = new JPAAuditLogService(emf);
ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(EVENT_SUBPROCESS_TIMER_ID_V1, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
managerV1.disposeRuntimeEngine(runtime);
MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, EVENT_SUBPROCESS_TIMER_ID_V2);
MigrationManager migrationManager = new MigrationManager(migrationSpec);
MigrationReport report = migrationManager.migrate();
assertNotNull(report);
assertTrue(report.isSuccessful());
log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(EVENT_SUBPROCESS_TIMER_ID_V2, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
// wait till timer fires
countdownListener.waitTillCompleted();
log = auditService.findProcessInstance(pi1.getId());
auditService.dispose();
assertNotNull(log);
assertEquals(EVENT_SUBPROCESS_TIMER_ID_V2, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
assertEquals(ProcessInstance.STATE_ABORTED, log.getStatus().intValue());
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class TimerMigrationManagerTest method testMigrateTimerProcessInstanceRollback.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(timeout = 10000)
public void testMigrateTimerProcessInstanceRollback() throws Exception {
NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("Event", 1);
createRuntimeManagers("migration/v1/BPMN2-Timer-v1.bpmn2", "migration/v2/BPMN2-Timer-v2.bpmn2", countdownListener);
assertNotNull(managerV1);
assertNotNull(managerV2);
RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance pi1 = ksession.startProcess(TIMER_ID_V1);
assertNotNull(pi1);
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
JPAAuditLogService auditService = new JPAAuditLogService(emf);
ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(TIMER_ID_V1, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
managerV1.disposeRuntimeEngine(runtime);
MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, TIMER_ID_V2);
MigrationManager migrationManager = new MigrationManager(migrationSpec);
MigrationReport report = null;
try {
// explicitly without generic to cause error (class cast) in migration process to test rollback
Map erronousMapping = Collections.singletonMap("_3", 3);
migrationManager.migrate(erronousMapping);
} catch (MigrationException e) {
report = e.getReport();
}
assertNotNull(report);
assertFalse(report.isSuccessful());
log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(TIMER_ID_V1, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
// wait till timer fires
countdownListener.waitTillCompleted();
log = auditService.findProcessInstance(pi1.getId());
auditService.dispose();
assertNotNull(log);
assertEquals(TIMER_ID_V1, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class TimerMigrationManagerTest method setup.
@Before
public void setup() {
TestUtil.cleanupSingletonSessionId();
pds = TestUtil.setupPoolingDataSource();
emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.persistence.jpa");
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
userGroupCallback = new JBossUserGroupCallbackImpl(properties);
auditService = new JPAAuditLogService(emf);
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class TimerMigrationManagerTest method testMigrateTimerProcessInstance.
@Test(timeout = 10000)
public void testMigrateTimerProcessInstance() throws Exception {
NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("EventV2", 1);
createRuntimeManagers("migration/v1/BPMN2-Timer-v1.bpmn2", "migration/v2/BPMN2-Timer-v2.bpmn2", countdownListener);
assertNotNull(managerV1);
assertNotNull(managerV2);
RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance pi1 = ksession.startProcess(TIMER_ID_V1);
assertNotNull(pi1);
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
JPAAuditLogService auditService = new JPAAuditLogService(emf);
ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(TIMER_ID_V1, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
managerV1.disposeRuntimeEngine(runtime);
MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, TIMER_ID_V2);
MigrationManager migrationManager = new MigrationManager(migrationSpec);
MigrationReport report = migrationManager.migrate();
assertNotNull(report);
assertTrue(report.isSuccessful());
log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(TIMER_ID_V2, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
// wait till timer fires
countdownListener.waitTillCompleted();
log = auditService.findProcessInstance(pi1.getId());
auditService.dispose();
assertNotNull(log);
assertEquals(TIMER_ID_V2, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class MigrationManager method validate.
private void validate() {
if (migrationSpec == null) {
report.addEntry(Type.ERROR, "no process data given for migration");
return;
}
// source (active) process instance information
if (isEmpty(migrationSpec.getDeploymentId())) {
report.addEntry(Type.ERROR, "No deployment id set");
}
if (migrationSpec.getProcessInstanceId() == null) {
report.addEntry(Type.ERROR, "No process instance id set");
}
// target process information
if (isEmpty(migrationSpec.getToDeploymentId())) {
report.addEntry(Type.ERROR, "No target deployment id set");
}
if (isEmpty(migrationSpec.getToProcessId())) {
report.addEntry(Type.ERROR, "No target process id set");
}
// verify if given runtime manager exists - registered under source deployment id
if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getDeploymentId())) {
report.addEntry(Type.ERROR, "No deployment found for " + migrationSpec.getDeploymentId());
}
// verify if given runtime manager exists - registered under target deployment id
if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getToDeploymentId())) {
report.addEntry(Type.ERROR, "No target deployment found for " + migrationSpec.getToDeploymentId());
}
// verify if given target process id exists in target runtime manager
InternalRuntimeManager manager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId());
if (manager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId()) == null) {
report.addEntry(Type.ERROR, "No process found for " + migrationSpec.getToProcessId() + " in deployment " + migrationSpec.getToDeploymentId());
}
// verify that source and target runtime manager is of the same type - represent the same runtime strategy
InternalRuntimeManager sourceManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getDeploymentId());
if (!sourceManager.getClass().isAssignableFrom(manager.getClass())) {
report.addEntry(Type.ERROR, "Source (" + sourceManager.getClass().getName() + ") and target (" + manager.getClass().getName() + ") deployments are of different type (they represent different runtime strategies)");
}
String auditPu = manager.getDeploymentDescriptor().getAuditPersistenceUnit();
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(auditPu);
JPAAuditLogService auditService = new JPAAuditLogService(emf);
try {
ProcessInstanceLog log = auditService.findProcessInstance(migrationSpec.getProcessInstanceId());
if (log == null || log.getStatus() != ProcessInstance.STATE_ACTIVE) {
report.addEntry(Type.ERROR, "No process instance found or it is not active (id " + migrationSpec.getProcessInstanceId() + " in status " + (log == null ? "-1" : log.getStatus()));
}
} finally {
auditService.dispose();
}
}
Aggregations