Search in sources :

Example 31 with JPAAuditLogService

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());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 32 with JPAAuditLogService

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());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Map(java.util.Map) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 33 with JPAAuditLogService

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);
}
Also used : JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) Properties(java.util.Properties) Before(org.junit.Before)

Example 34 with JPAAuditLogService

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());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 35 with JPAAuditLogService

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();
    }
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Aggregations

JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)35 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)20 KieSession (org.kie.api.runtime.KieSession)19 Test (org.junit.Test)18 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)15 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 ProcessInstanceLog (org.kie.api.runtime.manager.audit.ProcessInstanceLog)11 AuditLogService (org.jbpm.process.audit.AuditLogService)8 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)7 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)6 KieBase (org.kie.api.KieBase)6 HashMap (java.util.HashMap)5 EntityManagerFactory (javax.persistence.EntityManagerFactory)5 Environment (org.kie.api.runtime.Environment)5 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)4 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)4 AbstractAuditLogServiceTest.createKieSession (org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession)4 AbstractAuditLogger (org.jbpm.process.audit.AbstractAuditLogger)4