Search in sources :

Example 1 with DeploymentDescriptorManager

use of org.jbpm.runtime.manager.impl.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 = descriptorManager.getDeploymentDescriptorHierarchy(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.jbpm.runtime.manager.impl.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.jbpm.runtime.manager.impl.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.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) PersistenceUnit(javax.persistence.PersistenceUnit)

Example 3 with DeploymentDescriptorManager

use of org.jbpm.runtime.manager.impl.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.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) UserGroupCallback(org.kie.api.task.UserGroupCallback) PostConstruct(javax.annotation.PostConstruct)

Example 4 with DeploymentDescriptorManager

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

the class KModuleDeploymentService method boostrapRuntimeEnvironmentBuilder.

/**
 * This creates and fills a {@link RuntimeEnvironmentBuilder} instance, which is later used when creating services.
 * </p>
 * A lot of the logic here is used to process the information in the {@link DeploymentDescriptor} instance, which is
 * part of the {@link DeploymentUnit}.
 *
 * @param deploymentUnit The {@link KModuleDeploymentUnit}, which is filled by the method
 * @param deployedUnit The {@link DeployedUnit}, which is also filled by the method
 * @param kieContainer The {@link KieContainer}, which contains information needed to fill the above two arguments
 * @param mode The {@link MergeMode} used to resolve conflicts in the {@link DeploymentDescriptor}.
 * @return A {@link RuntimeEnvironmentBuilder} instance ready for use
 */
protected RuntimeEnvironmentBuilder boostrapRuntimeEnvironmentBuilder(KModuleDeploymentUnit deploymentUnit, DeployedUnit deployedUnit, KieContainer kieContainer, MergeMode mode) {
    DeploymentDescriptor descriptor = deploymentUnit.getDeploymentDescriptor();
    if (descriptor == null || ((DeploymentDescriptorImpl) descriptor).isEmpty()) {
        // skip empty descriptors as its default can override settings
        DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
        List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
        descriptor = merger.merge(descriptorHierarchy, mode);
        deploymentUnit.setDeploymentDescriptor(descriptor);
    } else if (descriptor != null && !deploymentUnit.isDeployed()) {
        DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
        List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
        descriptorHierarchy.add(0, descriptor);
        descriptor = merger.merge(descriptorHierarchy, mode);
        deploymentUnit.setDeploymentDescriptor(descriptor);
    }
    // first set on unit the strategy
    deploymentUnit.setStrategy(descriptor.getRuntimeStrategy());
    // setting up runtime environment via builder
    RuntimeEnvironmentBuilder builder = null;
    if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
        builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder();
    } else {
        builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder();
    }
    // populate various properties of the builder
    EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
    builder.entityManagerFactory(emf);
    Map<String, Object> contaxtParams = new HashMap<String, Object>();
    contaxtParams.put("entityManagerFactory", emf);
    contaxtParams.put("classLoader", kieContainer.getClassLoader());
    // 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);
    builder.addEnvironmentEntry("KieContainer", kieContainer);
    if (executorService != null) {
        builder.addEnvironmentEntry("ExecutorService", executorService);
    }
    if (identityProvider != null) {
        builder.addEnvironmentEntry(EnvironmentName.IDENTITY_PROVIDER, identityProvider);
    }
    // populate all assets with roles for this deployment unit
    List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_VIEW);
    if (requiredRoles != null && !requiredRoles.isEmpty()) {
        for (DeployedAsset desc : deployedUnit.getDeployedAssets()) {
            if (desc instanceof ProcessAssetDesc) {
                ((ProcessAssetDesc) desc).setRoles(requiredRoles);
            }
        }
    }
    // Classes 3: classes added from descriptor
    List<String> remoteableClasses = descriptor.getClasses();
    if (remoteableClasses != null && !remoteableClasses.isEmpty()) {
        for (String className : remoteableClasses) {
            Class descriptorClass = null;
            try {
                descriptorClass = kieContainer.getClassLoader().loadClass(className);
                logger.debug("Loaded {} into the classpath from deployment descriptor {}", className, kieContainer.getReleaseId().toExternalForm());
            } catch (ClassNotFoundException cnfe) {
                throw new IllegalArgumentException("Class " + className + " not found in the project");
            } catch (NoClassDefFoundError e) {
                throw new IllegalArgumentException("Class " + className + " not found in the project");
            }
            addClassToDeployedUnit(descriptorClass, (DeployedUnitImpl) deployedUnit);
        }
    }
    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) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) EntityManagerFactory(javax.persistence.EntityManagerFactory) List(java.util.List)

Example 5 with DeploymentDescriptorManager

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

the class HumanTaskServiceProducer method configureHumanTaskConfigurator.

protected void configureHumanTaskConfigurator(HumanTaskConfigurator configurator) {
    configurator.environment(getEnvironment(identityProvider)).entityManagerFactory(emf).userGroupCallback(safeGet(userGroupCallback)).userInfo(safeGet(userInfo));
    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);
    }
    // next proceed with registration of further listeners as cdi injections
    try {
        for (TaskLifeCycleEventListener listener : taskListeners) {
            configurator.listener(listener);
            logger.debug("Registering listener {}", listener);
        }
    } catch (Exception e) {
        logger.debug("Cannot add listeners to task service due to {}", e.getMessage());
    }
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) EntityManagerFactory(javax.persistence.EntityManagerFactory) DeploymentDescriptorManager(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) AmbiguousResolutionException(javax.enterprise.inject.AmbiguousResolutionException) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Aggregations

DeploymentDescriptorManager (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager)6 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)4 HashMap (java.util.HashMap)2 SerializablePlaceholderResolverStrategy (org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy)2 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)2 BAMTaskEventListener (org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener)2 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)2 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)2 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)2 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 AmbiguousResolutionException (javax.enterprise.inject.AmbiguousResolutionException)1 Produces (javax.enterprise.inject.Produces)1 PersistenceUnit (javax.persistence.PersistenceUnit)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 ProcessAssetDesc (org.jbpm.kie.services.impl.model.ProcessAssetDesc)1 DeploymentDescriptorMerger (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorMerger)1 DeployedAsset (org.jbpm.services.api.model.DeployedAsset)1 Audit (org.jbpm.services.cdi.Audit)1