Search in sources :

Example 6 with RuntimeEnvironmentBuilder

use of org.kie.api.runtime.manager.RuntimeEnvironmentBuilder in project jbpm by kiegroup.

the class KModuleDeploymentService method deploy.

@Override
public void deploy(DeploymentUnit unit) {
    try {
        super.deploy(unit);
        if (!(unit instanceof KModuleDeploymentUnit)) {
            throw new IllegalArgumentException("Invalid deployment unit provided - " + unit.getClass().getName());
        }
        KModuleDeploymentUnit kmoduleUnit = (KModuleDeploymentUnit) unit;
        DeployedUnitImpl deployedUnit = new DeployedUnitImpl(unit);
        deployedUnit.setActive(kmoduleUnit.isActive());
        // Create the release id
        KieContainer kieContainer = kmoduleUnit.getKieContainer();
        ReleaseId releaseId = null;
        if (kieContainer == null) {
            KieServices ks = KieServices.Factory.get();
            releaseId = ks.newReleaseId(kmoduleUnit.getGroupId(), kmoduleUnit.getArtifactId(), kmoduleUnit.getVersion());
            KieMavenRepository repository = getKieMavenRepository();
            repository.resolveArtifact(releaseId.toExternalForm());
            kieContainer = ks.newKieContainer(releaseId);
            kmoduleUnit.setKieContainer(kieContainer);
        }
        releaseId = kieContainer.getReleaseId();
        // retrieve the kbase name
        String kbaseName = kmoduleUnit.getKbaseName();
        if (StringUtils.isEmpty(kbaseName)) {
            KieBaseModel defaultKBaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
            if (defaultKBaseModel != null) {
                kbaseName = defaultKBaseModel.getName();
            } else {
                kbaseName = DEFAULT_KBASE_NAME;
            }
        }
        InternalKieModule module = (InternalKieModule) ((KieContainerImpl) kieContainer).getKieModuleForKBase(kbaseName);
        if (module == null) {
            throw new IllegalStateException("Cannot find kbase, either it does not exist or there are multiple default kbases in kmodule.xml");
        }
        KieBase kbase = kieContainer.getKieBase(kbaseName);
        Map<String, ProcessDescriptor> processDescriptors = new HashMap<String, ProcessDescriptor>();
        for (org.kie.api.definition.process.Process process : kbase.getProcesses()) {
            processDescriptors.put(process.getId(), ((ProcessDescriptor) process.getMetaData().get("ProcessDescriptor")).clone());
        }
        // TODO: add forms data?
        Collection<String> files = module.getFileNames();
        processResources(module, files, kieContainer, kmoduleUnit, deployedUnit, releaseId, processDescriptors);
        // process the files in the deployment
        if (module.getKieDependencies() != null) {
            Collection<InternalKieModule> dependencies = module.getKieDependencies().values();
            for (InternalKieModule depModule : dependencies) {
                logger.debug("Processing dependency module " + depModule.getReleaseId());
                files = depModule.getFileNames();
                processResources(depModule, files, kieContainer, kmoduleUnit, deployedUnit, depModule.getReleaseId(), processDescriptors);
            }
        }
        Collection<ReleaseId> dependencies = module.getJarDependencies(new DependencyFilter.ExcludeScopeFilter("test", "provided"));
        // process deployment dependencies
        if (dependencies != null && !dependencies.isEmpty()) {
            // Classes 2: classes added from project and dependencies added
            processClassloader(kieContainer, deployedUnit);
        }
        AuditEventBuilder auditLoggerBuilder = setupAuditLogger(identityProvider, unit.getIdentifier());
        RuntimeEnvironmentBuilder builder = boostrapRuntimeEnvironmentBuilder(kmoduleUnit, deployedUnit, kieContainer, kmoduleUnit.getMergeMode()).knowledgeBase(kbase).classLoader(kieContainer.getClassLoader());
        builder.registerableItemsFactory(getRegisterableItemsFactory(auditLoggerBuilder, kieContainer, kmoduleUnit));
        commonDeploy(unit, deployedUnit, builder.get(), kieContainer);
        kmoduleUnit.setDeployed(true);
    } catch (Throwable e) {
        logger.warn("Unexpected error while deploying unit {}", unit.getIdentifier(), e);
        // catch all possible errors to be able to report them to caller as RuntimeException
        throw new RuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) KieServices(org.kie.api.KieServices) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) KieBase(org.kie.api.KieBase) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieContainer(org.kie.api.runtime.KieContainer) DependencyFilter(org.appformer.maven.support.DependencyFilter) ReleaseId(org.kie.api.builder.ReleaseId) KieBaseModel(org.kie.api.builder.model.KieBaseModel) AuditEventBuilder(org.jbpm.process.audit.event.AuditEventBuilder) ProcessDescriptor(org.jbpm.kie.services.impl.bpmn2.ProcessDescriptor) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 7 with RuntimeEnvironmentBuilder

use of org.kie.api.runtime.manager.RuntimeEnvironmentBuilder in project jbpm by kiegroup.

the class JbpmJUnitTestCase method createKnowledgeBase.

protected KieBase createKnowledgeBase(Map<String, ResourceType> resources) {
    RuntimeEnvironmentBuilder builder = null;
    if (!setupDataSource) {
        builder = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder().addConfiguration("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName()).addConfiguration("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
    } else if (sessionPersistence) {
        builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder();
    } else {
        builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder();
    }
    builder.userGroupCallback(new JBossUserGroupCallbackImpl("classpath:/usergroups.properties"));
    for (Map.Entry<String, ResourceType> entry : resources.entrySet()) {
        builder.addAsset(ResourceFactory.newClassPathResource(entry.getKey()), entry.getValue());
    }
    environment = builder.get();
    return environment.getKieBase();
}
Also used : JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) ResourceType(org.kie.api.io.ResourceType) Map(java.util.Map) HashMap(java.util.HashMap) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder)

Example 8 with RuntimeEnvironmentBuilder

use of org.kie.api.runtime.manager.RuntimeEnvironmentBuilder in project jbpm by kiegroup.

the class RuntimeDataServiceTest method testGetTasksAssignedAsPotentialOwnerGroupFromCallback.

@Test
public void testGetTasksAssignedAsPotentialOwnerGroupFromCallback() {
    String id = "cdi-manager";
    AbstractAuditLogger auditLogger = AuditLoggerFactory.newJPAInstance();
    ServicesAwareAuditEventBuilder auditEventBuilder = new ServicesAwareAuditEventBuilder();
    auditEventBuilder.setIdentityProvider(new TestIdentifyProviderCDI());
    auditEventBuilder.setDeploymentUnitId(id);
    auditLogger.setBuilder(auditEventBuilder);
    RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).registerableItemsFactory(InjectableRegisterableItemsFactory.getFactory(beanManager, auditLogger));
    builder.addAsset(ResourceFactory.newClassPathResource("repo/processes/general/BPMN2-UserTasksAssignedToGroup.bpmn2"), ResourceType.BPMN2);
    RuntimeManager manager = managerFactory.newSingletonRuntimeManager(builder.get(), id);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Ready);
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwnerByStatus("katy", statuses, new QueryFilter());
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    ksession.abortProcessInstance(processInstance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ArrayList(java.util.ArrayList) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ServicesAwareAuditEventBuilder(org.jbpm.kie.services.impl.audit.ServicesAwareAuditEventBuilder) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 9 with RuntimeEnvironmentBuilder

use of org.kie.api.runtime.manager.RuntimeEnvironmentBuilder in project jbpm by kiegroup.

the class RuntimeDataServiceTest method testGetProcessInstanceHistory.

@Test
public void testGetProcessInstanceHistory() throws IOException {
    // BZ1048741
    assertNotNull(managerFactory);
    String id = "custom-manager";
    AbstractAuditLogger auditLogger = AuditLoggerFactory.newJPAInstance();
    ServicesAwareAuditEventBuilder auditEventBuilder = new ServicesAwareAuditEventBuilder();
    auditEventBuilder.setIdentityProvider(new TestIdentifyProviderCDI());
    auditEventBuilder.setDeploymentUnitId(id);
    auditLogger.setBuilder(auditEventBuilder);
    RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).registerableItemsFactory(InjectableRegisterableItemsFactory.getFactory(beanManager, auditLogger));
    builder.addAsset(ResourceFactory.newClassPathResource("repo/processes/general/hello.bpmn"), ResourceType.BPMN2);
    RuntimeManager manager = managerFactory.newSingletonRuntimeManager(builder.get(), id);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("hello");
    Collection<NodeInstanceDesc> nodeInstanceLogs = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
    // assert if logs are ordered by log.id ASC
    Iterator<NodeInstanceDesc> iterator = nodeInstanceLogs.iterator();
    NodeInstanceDesc log0 = iterator.next();
    assertEquals("End", log0.getName());
    NodeInstanceDesc log1 = iterator.next();
    assertEquals("Hello", log1.getName());
    NodeInstanceDesc log2 = iterator.next();
    assertEquals("Start", log2.getName());
    Collection<NodeInstanceDesc> fullNodeInstanceLogs = runtimeDataService.getProcessInstanceFullHistory(processInstance.getId(), new QueryContext());
    // assert if logs are ordered by log.date DESC, log.id DESC
    Iterator<NodeInstanceDesc> fullIterator = fullNodeInstanceLogs.iterator();
    NodeInstanceDesc fullLog0 = fullIterator.next();
    assertEquals("Start", fullLog0.getName());
    assertEquals(true, fullLog0.isCompleted());
    NodeInstanceDesc fullLog1 = fullIterator.next();
    assertEquals("Hello", fullLog1.getName());
    assertEquals(true, fullLog1.isCompleted());
    NodeInstanceDesc fullLog2 = fullIterator.next();
    assertEquals("End", fullLog2.getName());
    assertEquals(true, fullLog2.isCompleted());
    NodeInstanceDesc fullLog3 = fullIterator.next();
    assertEquals("End", fullLog3.getName());
    assertEquals(false, fullLog3.isCompleted());
    NodeInstanceDesc fullLog4 = fullIterator.next();
    assertEquals("Hello", fullLog4.getName());
    assertEquals(false, fullLog4.isCompleted());
    NodeInstanceDesc fullLog5 = fullIterator.next();
    assertEquals("Start", fullLog5.getName());
    assertEquals(false, fullLog5.isCompleted());
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) QueryContext(org.kie.api.runtime.query.QueryContext) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) ServicesAwareAuditEventBuilder(org.jbpm.kie.services.impl.audit.ServicesAwareAuditEventBuilder) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 10 with RuntimeEnvironmentBuilder

use of org.kie.api.runtime.manager.RuntimeEnvironmentBuilder in project jbpm by kiegroup.

the class HumanResourcesHiringTest method simpleExecutionTest.

@Test
public void simpleExecutionTest() {
    assertNotNull(managerFactory);
    String id = "custom-manager";
    AbstractAuditLogger auditLogger = AuditLoggerFactory.newJPAInstance();
    ServicesAwareAuditEventBuilder auditEventBuilder = new ServicesAwareAuditEventBuilder();
    auditEventBuilder.setIdentityProvider(new TestIdentifyProviderCDI());
    auditEventBuilder.setDeploymentUnitId(id);
    auditLogger.setBuilder(auditEventBuilder);
    RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).registerableItemsFactory(InjectableRegisterableItemsFactory.getFactory(beanManager, auditLogger));
    builder.addAsset(ResourceFactory.newClassPathResource("repo/processes/hr/hiring.bpmn2"), ResourceType.BPMN2);
    RuntimeManager manager = managerFactory.newSingletonRuntimeManager(builder.get(), id);
    testHiringProcess(manager, EmptyContext.get());
    manager.close();
}
Also used : RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TestIdentifyProviderCDI(org.jbpm.services.cdi.test.TestIdentifyProviderCDI) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ServicesAwareAuditEventBuilder(org.jbpm.kie.services.impl.audit.ServicesAwareAuditEventBuilder) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

RuntimeEnvironmentBuilder (org.kie.api.runtime.manager.RuntimeEnvironmentBuilder)10 HashMap (java.util.HashMap)5 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)3 ServicesAwareAuditEventBuilder (org.jbpm.kie.services.impl.audit.ServicesAwareAuditEventBuilder)3 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)3 AbstractAuditLogger (org.jbpm.process.audit.AbstractAuditLogger)3 Test (org.junit.Test)3 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)3 Map (java.util.Map)2 JBossUserGroupCallbackImpl (org.jbpm.services.task.identity.JBossUserGroupCallbackImpl)2 ResourceType (org.kie.api.io.ResourceType)2 KieSession (org.kie.api.runtime.KieSession)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 Date (java.util.Date)1 Properties (java.util.Properties)1 DependencyFilter (org.appformer.maven.support.DependencyFilter)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1