Search in sources :

Example 1 with DeploymentDescriptorManager

use of org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager in project jbpm by kiegroup.

the class RuntimeEnvironmentBuilder method getDefault.

/**
 * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:
 * <ul>
 * 	<li>DefaultRuntimeEnvironment</li>
 * </ul>
 * This one is tailored to works smoothly with kjars as the notion of kbase and ksessions
 * @param releaseId <code>ReleaseId</code> that described the kjar
 * @param kbaseName name of the kbase defined in kmodule.xml stored in kjar
 * @param ksessionName name of the ksession define in kmodule.xml stored in kjar
 * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults
 *
 * @see DefaultRuntimeEnvironment
 */
public static RuntimeEnvironmentBuilder getDefault(ReleaseId releaseId, String kbaseName, String ksessionName) {
    KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
    repository.resolveArtifact(releaseId.toExternalForm());
    KieServices ks = KieServices.Factory.get();
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager();
    List<DeploymentDescriptor> descriptorHierarchy = DeploymentDescriptorManagerUtil.getDeploymentDescriptorHierarchy(descriptorManager, kieContainer);
    DeploymentDescriptorMerger merger = new DeploymentDescriptorMerger();
    DeploymentDescriptor descriptor = merger.merge(descriptorHierarchy, MergeMode.MERGE_COLLECTIONS);
    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);
    RuntimeEnvironmentBuilder builder = null;
    if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
        builder = getDefaultInMemory();
    } else {
        builder = getDefault();
    }
    Map<String, Object> contaxtParams = new HashMap<String, Object>();
    contaxtParams.put("classLoader", kieContainer.getClassLoader());
    // populate various properties of the builder
    if (descriptor.getPersistenceUnit() != null) {
        EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
        builder.entityManagerFactory(emf);
        contaxtParams.put("entityManagerFactory", emf);
    }
    // process object models that are globally configured (environment entries, session configuration)
    for (NamedObjectModel model : descriptor.getEnvironmentEntries()) {
        Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
        builder.addEnvironmentEntry(model.getName(), entry);
    }
    for (NamedObjectModel model : descriptor.getConfiguration()) {
        Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
        builder.addConfiguration(model.getName(), (String) entry);
    }
    ObjectMarshallingStrategy[] mStrategies = new ObjectMarshallingStrategy[descriptor.getMarshallingStrategies().size() + 1];
    int index = 0;
    for (ObjectModel model : descriptor.getMarshallingStrategies()) {
        Object strategy = getInstanceFromModel(model, kieContainer, contaxtParams);
        mStrategies[index] = (ObjectMarshallingStrategy) strategy;
        index++;
    }
    // lastly add the main default strategy
    mStrategies[index] = new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
    builder.addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, mStrategies);
    builder.addEnvironmentEntry("KieDeploymentDescriptor", descriptor).knowledgeBase(kbase).classLoader(kieContainer.getClassLoader()).registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
    return builder;
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) HashMap(java.util.HashMap) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager) KieServices(org.kie.api.KieServices) KieBaseModel(org.kie.api.builder.model.KieBaseModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) KieMavenRepository(org.kie.scanner.KieMavenRepository) DeploymentDescriptorMerger(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorMerger) KieContainer(org.kie.api.runtime.KieContainer) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 2 with DeploymentDescriptorManager

use of org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager in project jbpm by kiegroup.

the class DeploymentDescriptorManagerTest method testDeploymentDescriptorFromKieContainer.

@Test
public void testDeploymentDescriptorFromKieContainer() {
    DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    DeploymentDescriptor descriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    descriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/simple.drl", SIMPLE_DRL);
    resources.put("src/main/resources/META-INF/kie-deployment-descriptor.xml", descriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    assertNotNull(kieContainer);
    List<DeploymentDescriptor> descriptorHierarchy = DeploymentDescriptorManagerUtil.getDeploymentDescriptorHierarchy(manager, kieContainer);
    assertNotNull(descriptorHierarchy);
    assertEquals(2, descriptorHierarchy.size());
    descriptor = descriptorHierarchy.get(0);
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(0, descriptor.getWorkItemHandlers().size());
    descriptor = descriptorHierarchy.get(1);
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(0, descriptor.getWorkItemHandlers().size());
}
Also used : HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager) DeploymentDescriptorImpl(org.kie.internal.runtime.manager.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 3 with DeploymentDescriptorManager

use of org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager in project jbpm by kiegroup.

the class DeploymentDescriptorManagerTest method testDeploymentDescriptorFromKieContainerNoDescInKjar.

@Test
public void testDeploymentDescriptorFromKieContainerNoDescInKjar() {
    DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/simple.drl", SIMPLE_DRL);
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    assertNotNull(kieContainer);
    List<DeploymentDescriptor> descriptorHierarchy = DeploymentDescriptorManagerUtil.getDeploymentDescriptorHierarchy(manager, kieContainer);
    assertNotNull(descriptorHierarchy);
    assertEquals(1, descriptorHierarchy.size());
    DeploymentDescriptor descriptor = descriptorHierarchy.get(0);
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(0, descriptor.getWorkItemHandlers().size());
}
Also used : HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 4 with DeploymentDescriptorManager

use of org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager in project jbpm by kiegroup.

the class AuditTransactionalCommandServiceEJBImpl method setEmf.

@PersistenceUnit(unitName = "org.jbpm.domain")
@Override
public void setEmf(EntityManagerFactory emf) {
    DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
    DeploymentDescriptor descriptor = manager.getDefaultDescriptor();
    if (!"org.jbpm.domain".equals(descriptor.getAuditPersistenceUnit())) {
        super.setEmf(EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit()));
    } else {
        super.setEmf(emf);
    }
}
Also used : DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager) PersistenceUnit(javax.persistence.PersistenceUnit)

Example 5 with DeploymentDescriptorManager

use of org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager in project jbpm by kiegroup.

the class TaskServiceEJBImpl method configureDelegate.

@PostConstruct
public void configureDelegate() {
    UserGroupCallback callback = UserDataServiceProvider.getUserGroupCallback();
    HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).userGroupCallback(callback);
    DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
    DeploymentDescriptor descriptor = manager.getDefaultDescriptor();
    // in case there is descriptor with enabled audit register then by default
    if (!descriptor.getAuditMode().equals(AuditMode.NONE)) {
        JPATaskLifeCycleEventListener listener = new JPATaskLifeCycleEventListener(false);
        BAMTaskEventListener bamListener = new BAMTaskEventListener(false);
        // if the audit persistence unit is different than default for the engine perform proper init
        if (!"org.jbpm.domain".equals(descriptor.getAuditPersistenceUnit())) {
            EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit());
            listener = new JPATaskLifeCycleEventListener(emf);
            bamListener = new BAMTaskEventListener(emf);
        }
        configurator.listener(listener);
        configurator.listener(bamListener);
    }
    delegate = (InternalTaskService) configurator.getTaskService();
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) HumanTaskConfigurator(org.jbpm.services.task.HumanTaskConfigurator) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) EntityManagerFactory(javax.persistence.EntityManagerFactory) DeploymentDescriptorManager(org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager) UserGroupCallback(org.kie.api.task.UserGroupCallback) PostConstruct(javax.annotation.PostConstruct)

Aggregations

DeploymentDescriptorManager (org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager)17 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)15 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)6 KieServices (org.kie.api.KieServices)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)5 ReleaseId (org.kie.api.builder.ReleaseId)5 KieContainer (org.kie.api.runtime.KieContainer)5 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)3 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)3 DeploymentDescriptorImpl (org.kie.internal.runtime.manager.deploy.DeploymentDescriptorImpl)3 SerializablePlaceholderResolverStrategy (org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy)2 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)2 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)2 MigrationManager (org.jbpm.runtime.manager.impl.migration.MigrationManager)2 MigrationReport (org.jbpm.runtime.manager.impl.migration.MigrationReport)2 MigrationSpec (org.jbpm.runtime.manager.impl.migration.MigrationSpec)2 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)2 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener)2