Search in sources :

Example 11 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class AbstractKieServicesBaseTest method configureServices.

protected void configureServices() {
    buildDatasource();
    emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.domain");
    identityProvider = new TestIdentityProvider();
    formManagerService = new FormManagerServiceImpl();
    // build definition service
    bpmn2Service = new BPMN2DataServiceImpl();
    queryService = new QueryServiceImpl();
    ((QueryServiceImpl) queryService).setIdentityProvider(identityProvider);
    ((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
    ((QueryServiceImpl) queryService).init();
    // build deployment service
    deploymentService = new KModuleDeploymentService();
    ((KModuleDeploymentService) deploymentService).setBpmn2Service(bpmn2Service);
    ((KModuleDeploymentService) deploymentService).setEmf(emf);
    ((KModuleDeploymentService) deploymentService).setIdentityProvider(identityProvider);
    ((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
    ((KModuleDeploymentService) deploymentService).setFormManagerService(formManagerService);
    TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).getTaskService();
    // build runtime data service
    runtimeDataService = new RuntimeDataServiceImpl();
    ((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
    ((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(identityProvider);
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
    ((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
    // set runtime data service as listener on deployment service
    ((KModuleDeploymentService) deploymentService).addListener(((RuntimeDataServiceImpl) runtimeDataService));
    ((KModuleDeploymentService) deploymentService).addListener(((BPMN2DataServiceImpl) bpmn2Service));
    ((KModuleDeploymentService) deploymentService).addListener(((QueryServiceImpl) queryService));
    // build process service
    processService = new ProcessServiceImpl();
    ((ProcessServiceImpl) processService).setDataService(runtimeDataService);
    ((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
    // build user task service
    userTaskService = new UserTaskServiceImpl();
    ((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
    ((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
}
Also used : FormManagerServiceImpl(org.jbpm.kie.services.impl.FormManagerServiceImpl) BPMN2DataServiceImpl(org.jbpm.kie.services.impl.bpmn2.BPMN2DataServiceImpl) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) RuntimeManagerFactoryImpl(org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl) ProcessServiceImpl(org.jbpm.kie.services.impl.ProcessServiceImpl) RuntimeDataServiceImpl(org.jbpm.kie.services.impl.RuntimeDataServiceImpl) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) TestIdentityProvider(org.jbpm.kie.services.test.TestIdentityProvider) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) UserTaskServiceImpl(org.jbpm.kie.services.impl.UserTaskServiceImpl) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl)

Example 12 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class SLATrackingCommand method execute.

@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
    ExecutionResults executionResults = new ExecutionResults();
    String emfName = (String) ctx.getData("EmfName");
    if (emfName == null) {
        emfName = "org.jbpm.domain";
    }
    String singleRun = (String) ctx.getData("SingleRun");
    if ("true".equalsIgnoreCase(singleRun)) {
        // disable rescheduling
        this.nextScheduleTimeAdd = -1;
    }
    String nextRun = (String) ctx.getData("NextRun");
    if (nextRun != null) {
        nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun);
    }
    // get hold of persistence and create instance of audit service
    EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(emfName);
    // collect parameters
    String forDeployment = (String) ctx.getData("ForDeployment");
    // SLA Violations on nodes
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("now", new Date());
    StringBuilder lookupQuery = new StringBuilder();
    lookupQuery.append("select log from NodeInstanceLog log where ");
    lookupQuery.append("log.nodeInstanceId in ( select nil.nodeInstanceId from NodeInstanceLog nil where nil.slaDueDate < :now and nil.slaCompliance = 1 ");
    lookupQuery.append("GROUP BY nil.nodeInstanceId ");
    lookupQuery.append("HAVING sum(nil.type) = 0) ");
    lookupQuery.append("and log.type = 0 ");
    if (forDeployment != null && !forDeployment.isEmpty()) {
        lookupQuery.append(" and log.externalId = :forDeployment");
        parameters.put("forDeployment", forDeployment);
    }
    TransactionalCommandService commandService = new TransactionalCommandService(emf);
    List<NodeInstanceLog> nodeInstancesViolations = commandService.execute(new QueryStringCommand<List<NodeInstanceLog>>(lookupQuery.toString(), parameters));
    logger.debug("Number of node instances with violated SLA {}", nodeInstancesViolations.size());
    if (!nodeInstancesViolations.isEmpty()) {
        logger.debug("Signaling process instances that have SLA violations on nodes");
        int nodeSignals = 0;
        for (NodeInstanceLog niLog : nodeInstancesViolations) {
            RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(niLog.getExternalId());
            if (runtimeManager == null) {
                logger.debug("No runtime manager found for {}, not able to send SLA violation signal", niLog.getExternalId());
                continue;
            }
            RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(niLog.getProcessInstanceId()));
            try {
                engine.getKieSession().signalEvent("slaViolation:" + niLog.getNodeInstanceId(), null, niLog.getProcessInstanceId());
                nodeSignals++;
            } catch (Exception e) {
                logger.warn("Unexpected error when signalig process instance {} about SLA violation {}", niLog.getProcessInstanceId(), e.getMessage(), e);
            } finally {
                runtimeManager.disposeRuntimeEngine(engine);
            }
        }
        logger.info("SLA Violations JOB :: Number of nodes successfully signaled is {}", nodeSignals);
        executionResults.setData("NodeSLASignals", nodeSignals);
    }
    // SLA Violations on process instances
    parameters = new HashMap<>();
    parameters.put("now", new Date());
    lookupQuery = new StringBuilder();
    lookupQuery.append("select log from ProcessInstanceLog log where log.slaDueDate < :now and log.slaCompliance = 1 ");
    if (forDeployment != null && !forDeployment.isEmpty()) {
        lookupQuery.append(" and log.externalId = :forDeployment");
        parameters.put("forDeployment", forDeployment);
    }
    List<ProcessInstanceLog> processInstancesViolations = commandService.execute(new QueryStringCommand<List<ProcessInstanceLog>>(lookupQuery.toString(), parameters));
    logger.debug("Number of node instances with violated SLA {}", nodeInstancesViolations.size());
    if (!processInstancesViolations.isEmpty()) {
        logger.debug("Signaling process instances that have SLA violations");
        int processSignals = 0;
        for (ProcessInstanceLog piLog : processInstancesViolations) {
            RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(piLog.getExternalId());
            if (runtimeManager == null) {
                logger.debug("No runtime manager found for {}, not able to send SLA violation signal", piLog.getExternalId());
                continue;
            }
            RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(piLog.getProcessInstanceId()));
            try {
                engine.getKieSession().signalEvent("slaViolation", null, piLog.getProcessInstanceId());
                processSignals++;
            } catch (Exception e) {
                logger.warn("Unexpected error when signalig process instance {} about SLA violation {}", piLog.getProcessInstanceId(), e.getMessage(), e);
            } finally {
                runtimeManager.disposeRuntimeEngine(engine);
            }
        }
        logger.info("SLA Violations JOB :: Number of process instances successfully signaled is {}", processSignals);
        executionResults.setData("ProcessSLASignals", processSignals);
    }
    return executionResults;
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) HashMap(java.util.HashMap) ExecutionResults(org.kie.api.executor.ExecutionResults) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) Date(java.util.Date) EntityManagerFactory(javax.persistence.EntityManagerFactory) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) List(java.util.List) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 13 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class JPAExecutorServiceProducer method produceQueryService.

@Produces
public ExecutorQueryService produceQueryService() {
    ExecutorQueryService queryService = new ExecutorQueryServiceImpl(true);
    TransactionalCommandService commandService = new TransactionalCommandService(emf);
    ((ExecutorQueryServiceImpl) queryService).setCommandService(commandService);
    return queryService;
}
Also used : TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) ExecutorQueryServiceImpl(org.jbpm.executor.impl.jpa.ExecutorQueryServiceImpl) ExecutorQueryService(org.kie.api.executor.ExecutorQueryService) Produces(javax.enterprise.inject.Produces)

Example 14 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class TransactionalCommandServiceProducer method produceAuditCommandService.

@Produces
@Audit
public TransactionalCommandService produceAuditCommandService() {
    DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
    DeploymentDescriptor descriptor = manager.getDefaultDescriptor();
    if (!"org.jbpm.domain".equals(descriptor.getAuditPersistenceUnit())) {
        return new TransactionalCommandService(EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit()));
    }
    return new TransactionalCommandService(emf);
}
Also used : DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) Audit(org.jbpm.services.cdi.Audit) Produces(javax.enterprise.inject.Produces)

Aggregations

TransactionalCommandService (org.jbpm.shared.services.impl.TransactionalCommandService)14 Produces (javax.enterprise.inject.Produces)4 DeploymentStore (org.jbpm.kie.services.impl.store.DeploymentStore)3 Before (org.junit.Before)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)2 FormManagerServiceImpl (org.jbpm.kie.services.impl.FormManagerServiceImpl)2 KModuleDeploymentService (org.jbpm.kie.services.impl.KModuleDeploymentService)2 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)2 ProcessServiceImpl (org.jbpm.kie.services.impl.ProcessServiceImpl)2 RuntimeDataServiceImpl (org.jbpm.kie.services.impl.RuntimeDataServiceImpl)2 UserTaskServiceImpl (org.jbpm.kie.services.impl.UserTaskServiceImpl)2 BPMN2DataServiceImpl (org.jbpm.kie.services.impl.bpmn2.BPMN2DataServiceImpl)2 QueryServiceImpl (org.jbpm.kie.services.impl.query.QueryServiceImpl)2 DeploymentSyncInvoker (org.jbpm.kie.services.impl.store.DeploymentSyncInvoker)2