Search in sources :

Example 96 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DeploymentDescriptorMerger method merge.

public DeploymentDescriptor merge(List<DeploymentDescriptor> descriptorHierarchy, MergeMode mode) {
    if (descriptorHierarchy == null || descriptorHierarchy.isEmpty()) {
        throw new IllegalArgumentException("Descriptor hierarchy list cannot be empty");
    }
    if (descriptorHierarchy.size() == 1) {
        return descriptorHierarchy.get(0);
    }
    Stack<DeploymentDescriptor> stack = new Stack<DeploymentDescriptor>();
    stack.addAll(descriptorHierarchy);
    if (mode == null) {
        mode = MergeMode.MERGE_COLLECTIONS;
    }
    while (stack.size() > 1) {
        DeploymentDescriptor master = stack.pop();
        DeploymentDescriptor slave = stack.pop();
        DeploymentDescriptor desc = merge(master, slave, mode);
        // add merged one to be next iteration slave
        stack.push(desc);
    }
    // last element from the stack is the one that contains all merged descriptors
    return stack.pop();
}
Also used : DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Stack(java.util.Stack)

Example 97 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DeploymentDescriptorMerger method merge.

public DeploymentDescriptor merge(DeploymentDescriptor master, DeploymentDescriptor slave, MergeMode mode) {
    if (master == null || slave == null) {
        throw new IllegalArgumentException("Descriptors to merge must be provided");
    }
    DeploymentDescriptor merged = null;
    DeploymentDescriptorBuilder builder = master.getBuilder();
    builder.setBuildHandler(new MergeModeBuildHandler(mode));
    switch(mode) {
        case KEEP_ALL:
            // do nothing as master wins
            merged = master;
            break;
        case OVERRIDE_ALL:
            // do nothing as slave wins
            merged = slave;
            break;
        case OVERRIDE_EMPTY:
            builder.auditMode(slave.getAuditMode());
            builder.auditPersistenceUnit(slave.getAuditPersistenceUnit());
            builder.persistenceMode(slave.getPersistenceMode());
            builder.persistenceUnit(slave.getPersistenceUnit());
            builder.runtimeStrategy(slave.getRuntimeStrategy());
            builder.setConfiguration(slave.getConfiguration());
            builder.setEnvironmentEntries(slave.getEnvironmentEntries());
            builder.setEventListeners(slave.getEventListeners());
            builder.setGlobals(slave.getGlobals());
            builder.setMarshalingStrategies(slave.getMarshallingStrategies());
            builder.setTaskEventListeners(slave.getTaskEventListeners());
            builder.setWorkItemHandlers(slave.getWorkItemHandlers());
            builder.setRequiredRoles(slave.getRequiredRoles());
            builder.setClasses(slave.getClasses());
            builder.setLimitSerializationClasses(slave.getLimitSerializationClasses());
            merged = builder.get();
            break;
        case MERGE_COLLECTIONS:
            builder.auditMode(slave.getAuditMode());
            builder.auditPersistenceUnit(slave.getAuditPersistenceUnit());
            builder.persistenceMode(slave.getPersistenceMode());
            builder.persistenceUnit(slave.getPersistenceUnit());
            builder.runtimeStrategy(slave.getRuntimeStrategy());
            for (ObjectModel model : slave.getEventListeners()) {
                builder.addEventListener(model);
            }
            for (ObjectModel model : slave.getMarshallingStrategies()) {
                builder.addMarshalingStrategy(model);
            }
            for (ObjectModel model : slave.getTaskEventListeners()) {
                builder.addTaskEventListener(model);
            }
            for (NamedObjectModel model : slave.getConfiguration()) {
                builder.addConfiguration(model);
            }
            for (NamedObjectModel model : slave.getEnvironmentEntries()) {
                builder.addEnvironmentEntry(model);
            }
            for (NamedObjectModel model : slave.getGlobals()) {
                builder.addGlobal(model);
            }
            for (NamedObjectModel model : slave.getWorkItemHandlers()) {
                builder.addWorkItemHandler(model);
            }
            for (String requiredRole : slave.getRequiredRoles()) {
                builder.addRequiredRole(requiredRole);
            }
            for (String clazz : slave.getClasses()) {
                builder.addClass(clazz);
            }
            Boolean slaveLimit = slave.getLimitSerializationClasses();
            Boolean masterLimit = master.getLimitSerializationClasses();
            if (slaveLimit != null && masterLimit != null && (!slaveLimit || !masterLimit)) {
                builder.setLimitSerializationClasses(false);
            }
            merged = builder.get();
            break;
        default:
            break;
    }
    return merged;
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorBuilder(org.kie.internal.runtime.conf.DeploymentDescriptorBuilder)

Example 98 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DefaultRegisterableItemsFactoryTest method testJmsAuditCacheInstance.

@Test
public void testJmsAuditCacheInstance() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.jms", "kjar-jms-audit", "1.0.0");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
    customDescriptor.getBuilder().auditMode(AuditMode.JMS);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).classLoader(this.getClass().getClassLoader()).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    assertNotNull(engine);
    AsyncAuditLogProducer asyncAuditLogProducer = null;
    KieSession kieSession = engine.getKieSession();
    for (ProcessEventListener listener : kieSession.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer);
    manager.close();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession kieSession2 = engine2.getKieSession();
    AsyncAuditLogProducer asyncAuditLogProducer2 = null;
    for (ProcessEventListener listener : kieSession2.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer2 = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer2);
    // check if the instance is the same (cached)
    assertEquals(asyncAuditLogProducer, asyncAuditLogProducer2);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) AsyncAuditLogProducer(org.jbpm.process.audit.jms.AsyncAuditLogProducer) KieSession(org.kie.api.runtime.KieSession) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractDeploymentDescriptorTest(org.jbpm.runtime.manager.impl.deploy.AbstractDeploymentDescriptorTest) Test(org.junit.Test)

Aggregations

DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)98 Test (org.junit.Test)55 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)43 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)34 HashMap (java.util.HashMap)27 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)26 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)23 KieServices (org.kie.api.KieServices)22 ArrayList (java.util.ArrayList)21 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)21 ReleaseId (org.kie.api.builder.ReleaseId)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 File (java.io.File)13 KieMavenRepository (org.kie.scanner.KieMavenRepository)12 FileOutputStream (java.io.FileOutputStream)11 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)11 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)10 InputStream (java.io.InputStream)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)8